/******************************* (C) LiteMesh **********************************
 * @module  usart
 * @file    usart.h
 * @version 1.0.0
 * @date    XX.XX.XXXX
 * $brief   Template
 *******************************************************************************
 * @history     Version  Author         Comment
 * XX.XX.XXXX   1.0.0    Telenkov D.A.  First release.
 *******************************************************************************
 */

/* Define to prevent recursive  ----------------------------------------------*/
#ifndef USART_H
#define USART_H

#include <stdint.h>
#include "stm32f4xx.h"

#include "FreeRTOS.h"
#include "queue.h"
#include "semphr.h"

#include "common_config.h"

/**
  * @brief  
  */
#define USER_USART                USART1
#define USER_USART_BAUD           115200
#define	USER_USART_WORD_LEN       8
#define	USER_USART_PARITY         USART_Parity_No
#define USER_USART_STOP_BIT       USART_StopBits_1

#define UPS_USART                 USART2
#define UPS_USART_BAUD            2400
#define	UPS_USART_WORD_LEN        8
#define	UPS_USART_PARITY          USART_Parity_No
#define UPS_USART_STOP_BIT        USART_StopBits_1

#ifdef PORTGW_ENABLE
#define RS485_USART               USART3
#define RS485_USART_BAUD          115200
#define RS485_USART_WORD_LEN      8
#define RS485_USART_PARITY        USART_Parity_No
#define RS485_USART_STOP_BIT      USART_StopBits_1

/* Queue */
QueueHandle_t rs485TxQ, rs485RxQ;

uint32_t rs485_send_block(uint8_t *data, uint16_t len);
void rs485_enable_tx(void);
#endif

#ifdef DALLAS_SENSOR_ENABLE
#define DALLAS_SENSOR_1_USART              UART4
#define DALLAS_SENSOR_2_USART              UART5
#define DALLAS_SENSOR_UART_BAUD            115200
#define DALLAS_SENSOR_RST_UART_BAUD        9600
#define	DALLAS_SENSOR_UART_WORD_LEN        8
#define	DALLAS_SENSOR_UART_PARITY          USART_Parity_No
#define DALLAS_SENSOR_UART_STOP_BIT        USART_StopBits_1
#endif

void init_ups_rbuf(void);

void uart_hw_init(USART_TypeDef *uart, uint32_t baud, uint16_t wordlen, uint16_t parity, uint16_t stop);
void uart_config_reinit(USART_TypeDef *uart, uint32_t baud, uint16_t wordlen, uint16_t parity, uint16_t stop);

/**
  * @brief  
  */
void InitUSART(void);
   
/**
  * @brief  
  * @retval 
  */

int ups_getchar(unsigned int timeout);
void ups_putchar(uint16_t byte);
int ups_send_block(void *data, uint8_t len);


int service_getchar(unsigned int timeout);
void service_putchar(uint16_t byte);
int service_send_block(void *data, uint8_t len);

void putc_(void *p, char c);
void putchar_(uint8_t c);

#endif /* #ifndef USART_H */

/****************************** (C) LiteMesh ***************** end of file ****/
