/*
 * uart.c
 *
 *  Created on: 2019. 5. 27.
 *      Author: parkyj
 */

#include "uart.h"

UARTQUEUE TerminalQueue;
UARTQUEUE WifiQueue;
void InitUartQueue(pUARTQUEUE pQueue)
{
    pQueue->data = pQueue->head = pQueue->tail = 0;
}
void PutDataToUartQueue(UART_HandleTypeDef *huart, uint8_t data)
{
    pUARTQUEUE pQueue = &TerminalQueue;
    if (pQueue->data >= QUEUE_BUFFER_LENGTH)
        GetDataFromUartQueue(huart);
    pQueue->Buffer[pQueue->head++] = data;
    if (pQueue->head == QUEUE_BUFFER_LENGTH) pQueue->head = 0;
    pQueue->data++;
}
void GetDataFromUartQueue(UART_HandleTypeDef *huart)
{
    UART_HandleTypeDef *dst = (huart->Instance == USART1 ? &hWifi:&hTerminal);
    pUARTQUEUE pQueue = &TerminalQueue;
    buf[uartindex++]  = *(pQueue->Buffer + pQueue->tail);
    pQueue->tail++;
    if (pQueue->tail >= QUEUE_BUFFER_LENGTH) pQueue->tail = 0;
    pQueue->data--;
    if(pQueue->data == 0)
        UartDataRecvSet(1);
    HAL_Delay(1);
}
void Uart1_Data_Send(uint8_t* data,uint8_t size){
    HAL_UART_Transmit_DMA(&huart1, data,size);
}
void Uart3_Data_Send(uint8_t* data,uint8_t size){
    HAL_UART_Transmit_DMA(&huart3, data,size);
}



