snickerdoodle Platform Controller
firmware for STM32F0 platform controller
sd_uart.h
Go to the documentation of this file.
1 
46 #ifndef __SD_UART_H
47 #define __SD_UART_H
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
57 //#define CIRCBUFF 0x000001
58 //#define DOUBBUFF 0x000002
59 //#define BUFFTYPE CIRCBUFF
60 
65 #define SD_UART_ERROR_NONE ((uint32_t)0x00)
66 #define SD_UART_ERROR_PARITY ((uint32_t)0x01)
67 #define SD_UART_ERROR_FRAMING ((uint32_t)0x02)
68 #define SD_UART_ERROR_NOISE ((uint32_t)0x04)
69 #define SD_UART_ERROR_OVERRUN ((uint32_t)0x08)
70 
82 #define __SD_UART_ERROR_IT(__HANDLE__) ((__HANDLE__)->Instance->ISR & ((uint32_t)0x0F))
83 
93 #define __SD_UART_CLEAR_ERROR_IT(__HANDLE__) ((__HANDLE__)->Instance->ICR = ((uint32_t)0x0F))
94 
103 extern struct sd_uart_dev uart1_dev;
104 extern struct sd_uart_dev uart2_dev;
120  SD_UART_SUCCESS = 0x4A0D,
125 };
126 
133  SD_UART_READY,
134  SD_UART_BUSY,
136 };
137 
142 struct sd_uart_dev {
143  UART_HandleTypeDef *uart;
144 #if BUFFTYPE == CIRCBUFF
145  struct sd_cbuf *rx_buff;
146 #elif BUFFTYPE == DOUBBUFF
148 #endif
149  enum sd_uart_state state;
150  uint8_t error;
151 };
152 
161 void sd_usart1_init (void);
162 void sd_usart2_init (void);
163 void sd_usart3_init (void);
164 enum sd_uart_err sd_uart_rx_init (struct sd_uart_dev *dev,
165 #if BUFFTYPE == CIRCBUFF
166  struct sd_cbuf *rx_buff);
167 #elif BUFFTYPE == DOUBBUFF
168  struct sd_doub_buff *rx_buff);
169 #endif
170 enum sd_uart_err sd_uart_transmit (struct sd_uart_dev *dev,
171  uint8_t *buf,
172  uint32_t len,
173  uint32_t timeout);
174 void sd_uart_irqhandler (struct sd_uart_dev *dev);
183 #ifdef __cplusplus
184 }
185 #endif
186 #else
187 #error "Multiple inclusion of sd_uart.h"
188 #endif /* __SD_UART_H */
189 
190 /*
191  * END OF FILE [sd_uart.h]
192  */
struct sd_cbuf * rx_buff
Definition: sd_uart.h:142
Definition: sd_uart.h:131
enum sd_uart_err sd_uart_transmit(struct sd_uart_dev *dev, uint8_t *buf, uint32_t len, uint32_t timeout)
Transmit Data In Blocking Mode.
Definition: sd_uart.c:436
Character buffer structure.
Definition: sd_buffer.h:102
sd_uart_err
UART error enumeration.
Definition: sd_uart.h:116
UART_HandleTypeDef * uart
Definition: sd_uart.h:140
Double character buffer structure.
Definition: sd_buffer.h:89
UART device structure.
Definition: sd_uart.h:139
void sd_uart_irqhandler(struct sd_uart_dev *dev)
UART Interrupt Handler Handle interrupt events on the UART peripheral.
Definition: sd_uart.c:361
uint32_t len
Definition: sd_buffer.h:93
Definition: sd_uart.h:117
struct sd_uart_dev uart2_dev
Definition: sd_uart.c:82
struct sd_uart_dev uart1_dev
Definition: sd_uart.c:81
enum sd_uart_state state
Definition: sd_uart.h:146
void sd_usart1_init(void)
USART 1 Initialization.
Definition: sd_uart.c:102
Definition: sd_uart.h:121
Definition: sd_uart.h:130
Definition: sd_uart.h:120
Definition: sd_uart.h:129
Definition: sd_uart.h:118
sd_uart_state
UART state enumeration.
Definition: sd_uart.h:128
Definition: sd_uart.h:132
void sd_usart2_init(void)
USART 2 Initialization.
Definition: sd_uart.c:124
void sd_usart3_init(void)
USART 3 Initialization.
Definition: sd_uart.c:146
Definition: sd_uart.h:119
uint8_t error
Definition: sd_uart.h:147
enum sd_uart_err sd_uart_rx_init(struct sd_uart_dev *dev, struct sd_cbuf *rx_buff)
UART Receive Interrupt Initialization Enable and prepare the UART to receive on interrupt.
Definition: sd_uart.c:317