2022-10-19 22:44:15 +08:00

95 lines
3.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __SWM320_UART_H__
#define __SWM320_UART_H__
typedef struct {
uint32_t Baudrate;
uint8_t DataBits; //<2F><><EFBFBD><EFBFBD>λλ<CEBB><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡֵUART_DATA_8BIT<49><54>UART_DATA_9BIT
uint8_t Parity; //<2F><>żУ<C5BC><D0A3>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>ȡֵUART_PARITY_NONE<4E><45>UART_PARITY_ODD<44><44>UART_PARITY_EVEN<45><4E>UART_PARITY_ONE<4E><45>UART_PARITY_ZERO
uint8_t StopBits; //ֹͣλλ<CEBB><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡֵUART_STOP_1BIT<49><54>UART_STOP_2BIT
uint8_t RXThreshold; //ȡֵ0--7
uint8_t RXThresholdIEn; //<2F><>RX FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD> > RXThresholdʱ<64><CAB1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
uint8_t TXThreshold; //ȡֵ0--7
uint8_t TXThresholdIEn; //<2F><>TX FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><DDB8><EFBFBD> <= TXThresholdʱ<64><CAB1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
uint8_t TimeoutTime; //<2F><>ʱʱ<CAB1><CAB1> = TimeoutTime/(Baudrate/10) <20><>
uint8_t TimeoutIEn; //<2F><>ʱ<EFBFBD>жϣ<D0B6>RX FIFO<46>ǿգ<C7BF><D5A3>ҳ<EFBFBD><D2B3><EFBFBD> TimeoutTime/(Baudrate/10) <20><>û<EFBFBD><C3BB><EFBFBD><EFBFBD>RX<52><58><EFBFBD>Ͻ<EFBFBD><CFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
} UART_InitStructure;
#define UART_DATA_8BIT 0
#define UART_DATA_9BIT 1
#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
#define UART_STOP_1BIT 0
#define UART_STOP_2BIT 1
#define UART_RTS_1BYTE 0
#define UART_RTS_2BYTE 1
#define UART_RTS_4BYTE 2
#define UART_RTS_6BYTE 3
#define UART_ABR_RES_OK 1
#define UART_ABR_RES_ERR 2
#define UART_ERR_FRAME 1
#define UART_ERR_PARITY 2
#define UART_ERR_NOISE 3
void UART_Init(UART_TypeDef * UARTx, UART_InitStructure * initStruct); //UART<52><54><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC>
void UART_Open(UART_TypeDef * UARTx);
void UART_Close(UART_TypeDef * UARTx);
void UART_WriteByte(UART_TypeDef * UARTx, uint32_t data); //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
uint32_t UART_ReadByte(UART_TypeDef * UARTx, uint32_t * data); //<2F><>ȡһ<C8A1><D2BB><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Valid
uint32_t UART_IsTXBusy(UART_TypeDef * UARTx);
uint32_t UART_IsRXFIFOEmpty(UART_TypeDef * UARTx); //<2F><><EFBFBD><EFBFBD>FIFO<46>Ƿ<EFBFBD><C7B7>գ<EFBFBD><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>UART_ReadByte()
uint32_t UART_IsTXFIFOFull(UART_TypeDef * UARTx); //<2F><><EFBFBD><EFBFBD>FIFO<46>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>UART_WriteByte()
void UART_SetBaudrate(UART_TypeDef * UARTx, uint32_t baudrate); //<2F><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>
uint32_t UART_GetBaudrate(UART_TypeDef * UARTx); //<2F><>ȡ<EFBFBD><C8A1>ǰʹ<C7B0>õIJ<C3B5><C4B2><EFBFBD><EFBFBD><EFBFBD>
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__