/****************************************************************************
*
* 文件名: usart_api.h
* 内容简述: 串口模块头文件。
*/

#ifndef __USART_H__
#define __USART_H__

#include "datatypes.h"
#include "nrf_drv_uart.h"

/***************************************************************/
#define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */

#define UART1_TX_BUF_SIZE	2048
#define UART1_RX_BUF_SIZE	2048

#define UART2_TX_BUF_SIZE	768
#define UART2_RX_BUF_SIZE	768

#define UART3_TX_BUF_SIZE	768
#define UART3_RX_BUF_SIZE	768

/** 
  * @brief Universal Synchronous Asynchronous Receiver Transmitter
  */
 
typedef struct
{
  __IO uint16_t SR;
  uint16_t  RESERVED0;
  __IO uint16_t DR;
  uint16_t  RESERVED1;
  __IO uint16_t BRR;
  uint16_t  RESERVED2;
  __IO uint16_t CR1;
  uint16_t  RESERVED3;
  __IO uint16_t CR2;
  uint16_t  RESERVED4;
  __IO uint16_t CR3;
  uint16_t  RESERVED5;
  __IO uint16_t GTPR;
  uint16_t  RESERVED6;
} USART_TypeDef;


/* 全局参数 */
typedef struct
{
	USART_TypeDef *uart;	/*  */	
	uint8_t *pTxBuf;			/* 发送缓冲区 */
	uint8_t *pRxBuf;			/* 接收缓冲区 */
	uint16_t usTxBufSize;		/* 发送缓冲区大小 */
	uint16_t usRxBufSize;		/* 接收缓冲区大小 */
	uint16_t usTxWrite;		/* 发送缓冲区写指针 */
	uint16_t usTxRead;		/* 发送缓冲区读指针 */
	uint16_t usRxWrite;		/* 接收缓冲区写指针 */
	uint16_t usRxRead;		/* 接收缓冲区读指针 */
	void (*SendOver)(void); 	/* 发送完毕的回调函数指针 */
	void (*ReciveNew)(void);	/* 串口收到数据的回调函数指针 */
}UART_T;


/* 定义端口号 */
typedef enum
{
	COM_MIN = 0x30,
	COM1 = 0x31,	/* COM1口, RS232 */
	COM2 = 0x32,	/* COM2口, RS232 */
	COM3 = 0x33, 	/* COM3口, RS485 */
	COM_MAX = 0xfe
}COM_NUM_ENUM;


/***************************************************************/
extern uint32_t ble_uart_string_send(uint8_t * p_string);
extern uint32_t ble_uart_string_len_send(uint8_t * p_string, uint16_t length);
/**@brief  Function for initializing the UART module.
 */
/**@snippet [UART Initialization] */
void uart_init(void);

void USART1_IRQHandler(void);
void USART2_IRQHandler(void);
void USART3_IRQHandler(void);

extern void comInit(void);
extern void comSendBuf(uint8_t _ucPort, uint8_t *_ucaBuf, uint16_t _usLen);
extern uint8_t comGetChar(uint8_t _ucPort, uint8_t *_pByte);

extern void Send(uint8_t dat);
extern void UART2_SendChar(uint8_t dat);
extern void UART2_SendString(uint8_t *dat);
extern void SendNewLine(void);
extern void SendString(uint8_t *dat);
extern void SendString_NewLine(uint8_t *dat);
extern void SendUsartxString_NewLine(uint8_t *dat);

#endif

/*********************************************end of file*********************************************/
