Bouffalo SDK  1.0
Bouffalolab Software Development Kit
bflb_uart.h
Go to the documentation of this file.
1 #ifndef _BFLB_UART_H
2 #define _BFLB_UART_H
3 
4 #include "bflb_core.h"
5 
17 #define UART_DIRECTION_TX (1 << 0)
18 #define UART_DIRECTION_RX (1 << 1)
19 #define UART_DIRECTION_TXRX (UART_DIRECTION_TX | UART_DIRECTION_RX)
20 #define UART_DIRECTION_MASK UART_DIRECTION_TXRX
21 
28 #define UART_DATA_BITS_5 0
29 #define UART_DATA_BITS_6 1
30 #define UART_DATA_BITS_7 2
31 #define UART_DATA_BITS_8 3
32 
39 #define UART_STOP_BITS_0_5 0
40 #define UART_STOP_BITS_1 1
41 #define UART_STOP_BITS_1_5 2
42 #define UART_STOP_BITS_2 3
43 
50 #define UART_PARITY_NONE 0
51 #define UART_PARITY_ODD 1
52 #define UART_PARITY_EVEN 2
53 #define UART_PARITY_MARK 3
54 #define UART_PARITY_SPACE 4
55 
62 #define UART_LSB_FIRST 0
63 #define UART_MSB_FIRST 1
64 
71 #define UART_FLOWCTRL_NONE 0
72 #define UART_FLOWCTRL_RTS (1 << 0)
73 #define UART_FLOWCTRL_CTS (1 << 1)
74 #define UART_FLOWCTRL_RTS_CTS (UART_FLOWCTRL_RTS | UART_FLOWCTRL_CTS)
75 
82 #define UART_INTSTS_TX_END (1 << 0)
83 #define UART_INTSTS_RX_END (1 << 1)
84 #define UART_INTSTS_TX_FIFO (1 << 2)
85 #define UART_INTSTS_RX_FIFO (1 << 3)
86 #define UART_INTSTS_RTO (1 << 4)
87 #define UART_INTSTS_PCE (1 << 5)
88 #define UART_INTSTS_TX_FER (1 << 6)
89 #define UART_INTSTS_RX_FER (1 << 7)
90 #if !defined(BL602)
91 #define UART_INTSTS_RX_LSE (1 << 8)
92 #endif
93 #if !defined(BL602) && !defined(BL702)
94 #define UART_INTSTS_RX_BCR (1 << 9)
95 #define UART_INTSTS_RX_ADS (1 << 10)
96 #define UART_INTSTS_RX_AD5 (1 << 11)
97 #endif
98 
105 #define UART_INTCLR_TX_END (1 << 0)
106 #define UART_INTCLR_RX_END (1 << 1)
107 #define UART_INTCLR_RTO (1 << 4)
108 #define UART_INTCLR_PCE (1 << 5)
109 #if !defined(BL602)
110 #define UART_INTCLR_RX_LSE (1 << 8)
111 #endif
112 #if !defined(BL602) && !defined(BL702)
113 #define UART_INTCLR_RX_BCR (1 << 9)
114 #define UART_INTCLR_RX_ADS (1 << 10)
115 #define UART_INTCLR_RX_AD5 (1 << 11)
116 #endif
117 
124 #define UART_CMD_SET_BAUD_RATE (0x01)
125 #define UART_CMD_SET_DATA_BITS (0x02)
126 #define UART_CMD_SET_STOP_BITS (0x03)
127 #define UART_CMD_SET_PARITY_BITS (0x04)
128 #define UART_CMD_CLR_TX_FIFO (0x05)
129 #define UART_CMD_CLR_RX_FIFO (0x06)
130 #define UART_CMD_SET_RTO_VALUE (0x07)
131 #define UART_CMD_SET_RTS_VALUE (0x08)
132 #define UART_CMD_GET_TX_FIFO_CNT (0x09)
133 #define UART_CMD_GET_RX_FIFO_CNT (0x0a)
134 #define UART_CMD_SET_AUTO_BAUD (0x0b)
135 #define UART_CMD_GET_AUTO_BAUD (0x0c)
136 #define UART_CMD_SET_BREAK_VALUE (0x0d)
137 #define UART_CMD_SET_TX_LIN_VALUE (0x0e)
138 #define UART_CMD_SET_RX_LIN_VALUE (0x0f)
139 #define UART_CMD_SET_GLITCH_VALUE (0x10)
140 #define UART_CMD_SET_TX_RS485_EN (0x11)
141 #define UART_CMD_SET_TX_RS485_POLARITY (0x12)
142 #define UART_CMD_SET_ABR_ALLOWABLE_ERROR (0x13)
143 #define UART_CMD_SET_SW_RTS_CONTROL (0x14)
144 #define UART_CMD_IR_CONFIG (0x15)
145 #define UART_CMD_SET_TX_FREERUN (0x16)
146 #define UART_CMD_SET_TX_END_INTERRUPT (0x17)
147 #define UART_CMD_SET_RX_END_INTERRUPT (0x18)
148 #define UART_CMD_SET_TX_TRANSFER_LEN (0x19)
149 #define UART_CMD_SET_RX_TRANSFER_LEN (0x20)
150 #define UART_CMD_SET_TX_EN (0x21)
151 #define UART_CMD_SET_BCR_END_INTERRUPT (0x22)
152 #define UART_CMD_GET_BCR_COUNT (0x23)
153 #define UART_CMD_SET_CTS_EN (0x24)
154 #define UART_CMD_SET_TX_FIFO_THREHOLD (0x25)
155 #define UART_CMD_SET_RX_FIFO_THREHOLD (0x26)
156 
161 #define UART_AUTO_BAUD_START 0
162 #define UART_AUTO_BAUD_0X55 1
163 
165  bool tx_en;
166  bool rx_en;
169  uint16_t tx_pluse_start;
170  uint16_t tx_pluse_stop;
171  uint16_t rx_pluse_start;
172 };
173 
188  uint32_t baudrate;
189  uint8_t direction;
190  uint8_t data_bits;
191  uint8_t stop_bits;
192  uint8_t parity;
193  uint8_t bit_order;
194  uint8_t flow_ctrl;
197 };
198 
199 #ifdef __cplusplus
200 extern "C" {
201 #endif
202 
209 void bflb_uart_init(struct bflb_device_s *dev, const struct bflb_uart_config_s *config);
210 
216 void bflb_uart_deinit(struct bflb_device_s *dev);
217 
223 void bflb_uart_enable(struct bflb_device_s *dev);
224 
230 void bflb_uart_disable(struct bflb_device_s *dev);
231 
238 void bflb_uart_link_txdma(struct bflb_device_s *dev, bool enable);
239 
246 void bflb_uart_link_rxdma(struct bflb_device_s *dev, bool enable);
247 
255 int bflb_uart_putchar(struct bflb_device_s *dev, int ch);
256 
263 int bflb_uart_getchar(struct bflb_device_s *dev);
264 
273 int bflb_uart_put(struct bflb_device_s *dev, uint8_t *data, uint32_t len);
274 
283 int bflb_uart_put_block(struct bflb_device_s *dev, uint8_t *data, uint32_t len);
292 int bflb_uart_get(struct bflb_device_s *dev, uint8_t *data, uint32_t len);
293 
300 bool bflb_uart_txready(struct bflb_device_s *dev);
301 
308 bool bflb_uart_txempty(struct bflb_device_s *dev);
309 
316 bool bflb_uart_rxavailable(struct bflb_device_s *dev);
317 
324 void bflb_uart_txint_mask(struct bflb_device_s *dev, bool mask);
325 
332 void bflb_uart_rxint_mask(struct bflb_device_s *dev, bool mask);
333 
340 void bflb_uart_errint_mask(struct bflb_device_s *dev, bool mask);
341 
348 uint32_t bflb_uart_get_intstatus(struct bflb_device_s *dev);
349 
356 void bflb_uart_int_clear(struct bflb_device_s *dev, uint32_t int_clear);
357 
366 int bflb_uart_feature_control(struct bflb_device_s *dev, int cmd, size_t arg);
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 
380 #endif
void bflb_uart_link_txdma(struct bflb_device_s *dev, bool enable)
Enable uart tx dma.
uint16_t rx_pluse_start
Definition: bflb_uart.h:171
void bflb_uart_init(struct bflb_device_s *dev, const struct bflb_uart_config_s *config)
Initialize uart.
void bflb_uart_enable(struct bflb_device_s *dev)
Enable uart.
void bflb_uart_link_rxdma(struct bflb_device_s *dev, bool enable)
Enable uart rx dma.
int bflb_uart_putchar(struct bflb_device_s *dev, int ch)
Put one char on uart.
bool bflb_uart_txempty(struct bflb_device_s *dev)
Check if there is no data in tx fifo.
uint16_t tx_pluse_stop
Definition: bflb_uart.h:170
uint32_t baudrate
Definition: bflb_uart.h:188
void bflb_uart_rxint_mask(struct bflb_device_s *dev, bool mask)
Enable or disable uart rx fifo threhold interrupt.
void bflb_uart_errint_mask(struct bflb_device_s *dev, bool mask)
Enable or disable uart error interrupt.
int bflb_uart_getchar(struct bflb_device_s *dev)
Get char from uart.
int bflb_uart_get(struct bflb_device_s *dev, uint8_t *data, uint32_t len)
Get a block of data from uart. This is a asynchronous api.
uint32_t bflb_uart_get_intstatus(struct bflb_device_s *dev)
Get uart interrupt status.
UART configuration structure.
Definition: bflb_uart.h:187
int bflb_uart_put_block(struct bflb_device_s *dev, uint8_t *data, uint32_t len)
Put a block of data on uart.Block before sending done.
uint16_t tx_pluse_start
Definition: bflb_uart.h:169
int bflb_uart_put(struct bflb_device_s *dev, uint8_t *data, uint32_t len)
Put a block of data on uart.This is a poll api.
void bflb_uart_int_clear(struct bflb_device_s *dev, uint32_t int_clear)
Clear uart interrupt status.
void bflb_uart_deinit(struct bflb_device_s *dev)
Deinitialize uart.
void bflb_uart_txint_mask(struct bflb_device_s *dev, bool mask)
Enable or disable uart tx fifo threhold interrupt.
bool bflb_uart_rxavailable(struct bflb_device_s *dev)
Check if there is data in rx fifo.
uint8_t tx_fifo_threshold
Definition: bflb_uart.h:195
void bflb_uart_disable(struct bflb_device_s *dev)
Disable uart.
int bflb_uart_feature_control(struct bflb_device_s *dev, int cmd, size_t arg)
Control uart feature.
uint8_t rx_fifo_threshold
Definition: bflb_uart.h:196
bool bflb_uart_txready(struct bflb_device_s *dev)
Check if there is free space in tx fifo.