2018-12-24 17:17:27 +08:00
|
|
|
|
#ifndef __SWM320_UART_H__
|
|
|
|
|
#define __SWM320_UART_H__
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
uint32_t Baudrate;
|
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
uint8_t DataBits; //数据位位数,可取值UART_DATA_8BIT、UART_DATA_9BIT
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
uint8_t Parity; //奇偶校验位,可取值UART_PARITY_NONE、UART_PARITY_ODD、UART_PARITY_EVEN、UART_PARITY_ONE、UART_PARITY_ZERO
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
uint8_t StopBits; //停止位位数,可取值UART_STOP_1BIT、UART_STOP_2BIT
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
uint8_t RXThreshold; //取值0--7
|
|
|
|
|
uint8_t RXThresholdIEn; //当RX FIFO中数据个数 > RXThreshold时触发中断
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
uint8_t TXThreshold; //取值0--7
|
|
|
|
|
uint8_t TXThresholdIEn; //当TX FIFO中数据个数 <= TXThreshold时触发中断
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
uint8_t TimeoutTime; //超时时长 = TimeoutTime/(Baudrate/10) 秒
|
|
|
|
|
uint8_t TimeoutIEn; //超时中断,RX FIFO非空,且超过 TimeoutTime/(Baudrate/10) 秒没有在RX线上接收到数据时触发中断
|
2018-12-24 17:17:27 +08:00
|
|
|
|
} UART_InitStructure;
|
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
#define UART_DATA_8BIT 0
|
|
|
|
|
#define UART_DATA_9BIT 1
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
#define UART_PARITY_NONE 0
|
|
|
|
|
#define UART_PARITY_ODD 1
|
|
|
|
|
#define UART_PARITY_EVEN 3
|
|
|
|
|
#define UART_PARITY_ONE 5
|
|
|
|
|
#define UART_PARITY_ZERO 7
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
#define UART_STOP_1BIT 0
|
|
|
|
|
#define UART_STOP_2BIT 1
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
#define UART_RTS_1BYTE 0
|
|
|
|
|
#define UART_RTS_2BYTE 1
|
|
|
|
|
#define UART_RTS_4BYTE 2
|
|
|
|
|
#define UART_RTS_6BYTE 3
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
#define UART_ABR_RES_OK 1
|
|
|
|
|
#define UART_ABR_RES_ERR 2
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
#define UART_ERR_FRAME 1
|
|
|
|
|
#define UART_ERR_PARITY 2
|
|
|
|
|
#define UART_ERR_NOISE 3
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
void UART_Init(UART_TypeDef *UARTx, UART_InitStructure *initStruct); //UART串口初始化
|
2018-12-24 17:17:27 +08:00
|
|
|
|
void UART_Open(UART_TypeDef *UARTx);
|
|
|
|
|
void UART_Close(UART_TypeDef *UARTx);
|
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
void UART_WriteByte(UART_TypeDef *UARTx, uint32_t data); //发送一个字节数据
|
|
|
|
|
uint32_t UART_ReadByte(UART_TypeDef *UARTx, uint32_t *data); //读取一个字节数据,并指出数据是否Valid
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
|
|
|
|
uint32_t UART_IsTXBusy(UART_TypeDef *UARTx);
|
2021-09-30 17:55:16 +08:00
|
|
|
|
uint32_t UART_IsRXFIFOEmpty(UART_TypeDef *UARTx); //接收FIFO是否空,如果不空则可以继续UART_ReadByte()
|
|
|
|
|
uint32_t UART_IsTXFIFOFull(UART_TypeDef *UARTx); //发送FIFO是否满,如果不满则可以继续UART_WriteByte()
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
2021-09-30 17:55:16 +08:00
|
|
|
|
void UART_SetBaudrate(UART_TypeDef *UARTx, uint32_t baudrate); //设置波特率
|
|
|
|
|
uint32_t UART_GetBaudrate(UART_TypeDef *UARTx); //获取当前使用的波特率
|
2018-12-24 17:17:27 +08:00
|
|
|
|
|
|
|
|
|
void UART_CTSConfig(UART_TypeDef *UARTx, uint32_t enable, uint32_t polarity);
|
|
|
|
|
uint32_t UART_CTSLineState(UART_TypeDef *UARTx);
|
|
|
|
|
|
|
|
|
|
void UART_RTSConfig(UART_TypeDef *UARTx, uint32_t enable, uint32_t polarity, uint32_t threshold);
|
|
|
|
|
uint32_t UART_RTSLineState(UART_TypeDef *UARTx);
|
|
|
|
|
|
|
|
|
|
void UART_LINConfig(UART_TypeDef *UARTx, uint32_t detectedIEn, uint32_t generatedIEn);
|
|
|
|
|
void UART_LINGenerate(UART_TypeDef *UARTx);
|
|
|
|
|
uint32_t UART_LINIsDetected(UART_TypeDef *UARTx);
|
|
|
|
|
uint32_t UART_LINIsGenerated(UART_TypeDef *UARTx);
|
|
|
|
|
|
|
|
|
|
void UART_ABRStart(UART_TypeDef *UARTx, uint32_t detectChar);
|
|
|
|
|
uint32_t UART_ABRIsDone(UART_TypeDef *UARTx);
|
|
|
|
|
|
|
|
|
|
void UART_INTRXThresholdEn(UART_TypeDef *UARTx);
|
|
|
|
|
void UART_INTRXThresholdDis(UART_TypeDef *UARTx);
|
|
|
|
|
uint32_t UART_INTRXThresholdStat(UART_TypeDef *UARTx);
|
|
|
|
|
void UART_INTTXThresholdEn(UART_TypeDef *UARTx);
|
|
|
|
|
void UART_INTTXThresholdDis(UART_TypeDef *UARTx);
|
|
|
|
|
uint32_t UART_INTTXThresholdStat(UART_TypeDef *UARTx);
|
|
|
|
|
void UART_INTTimeoutEn(UART_TypeDef *UARTx);
|
|
|
|
|
void UART_INTTimeoutDis(UART_TypeDef *UARTx);
|
|
|
|
|
uint32_t UART_INTTimeoutStat(UART_TypeDef *UARTx);
|
|
|
|
|
|
|
|
|
|
void UART_INTTXDoneEn(UART_TypeDef *UARTx);
|
|
|
|
|
void UART_INTTXDoneDis(UART_TypeDef *UARTx);
|
|
|
|
|
uint32_t UART_INTTXDoneStat(UART_TypeDef *UARTx);
|
|
|
|
|
|
|
|
|
|
#endif //__SWM320_UART_H__
|