1 
2 #ifndef __UART_H__
3 #define __UART_H__
4 
5 #include <rthw.h>
6 #include <rtthread.h>
7 #include "cy_device_headers.h"
8 #include "board.h"
9 #include "cy_pdl.h"
10 
11 #define UART_RX_BUFFER_SIZE         128u
12 #define UART_TX_BUFFER_SIZE         128u
13 
14 #define UART_ENABLE_IRQ(n)          NVIC_EnableIRQ((n))
15 #define UART_DISABLE_IRQ(n)         NVIC_DisableIRQ((n))
16 
17 struct uart_int_rx
18 {
19     rt_uint8_t  rx_buffer[UART_RX_BUFFER_SIZE];
20     rt_uint32_t read_index, save_index;
21 };
22 
23 struct uart_int_tx
24 {
25     rt_uint8_t  tx_buffer[UART_TX_BUFFER_SIZE];
26     rt_uint32_t write_index, save_index;
27 };
28 
29 struct uart_device
30 {
31     CySCB_Type* scb_device;
32     /* uart config */
33     cy_stc_scb_uart_config_t const *uart_config;
34     /* uart context */
35     cy_stc_scb_uart_context_t *uart_context;
36     /* uart interrupt */
37     const cy_stc_sysint_t *uart_int;
38     /* irq number */
39     IRQn_Type rx_irq;
40     IRQn_Type tx_irq;
41 
42     /* rx structure */
43     struct uart_int_rx* int_rx;
44     /* tx structure */
45     struct uart_int_tx* int_tx;
46 };
47 
48 void rt_hw_uart_init(void);
49 
50 #endif
51