1
1
// IRQs: USART1, USART2, USART3, UART5
2
2
3
- #define FIFO_SIZE 0x400
3
+ #define FIFO_SIZE 0x400U
4
4
typedef struct uart_ring {
5
5
volatile uint16_t w_ptr_tx ;
6
6
volatile uint16_t r_ptr_tx ;
@@ -81,7 +81,7 @@ void uart_ring_process(uart_ring *q) {
81
81
if (q -> w_ptr_tx != q -> r_ptr_tx ) {
82
82
if ((sr & USART_SR_TXE ) != 0 ) {
83
83
q -> uart -> DR = q -> elems_tx [q -> r_ptr_tx ];
84
- q -> r_ptr_tx = (q -> r_ptr_tx + 1 ) % FIFO_SIZE ;
84
+ q -> r_ptr_tx = (q -> r_ptr_tx + 1U ) % FIFO_SIZE ;
85
85
}
86
86
// there could be more to send
87
87
q -> uart -> CR1 |= USART_CR1_TXEIE ;
@@ -93,7 +93,7 @@ void uart_ring_process(uart_ring *q) {
93
93
if ((sr & USART_SR_RXNE ) || (sr & USART_SR_ORE )) {
94
94
uint8_t c = q -> uart -> DR ; // TODO: can drop packets
95
95
if (q != & esp_ring ) {
96
- uint16_t next_w_ptr = (q -> w_ptr_rx + 1 ) % FIFO_SIZE ;
96
+ uint16_t next_w_ptr = (q -> w_ptr_rx + 1U ) % FIFO_SIZE ;
97
97
if (next_w_ptr != q -> r_ptr_rx ) {
98
98
q -> elems_rx [q -> w_ptr_rx ] = c ;
99
99
q -> w_ptr_rx = next_w_ptr ;
@@ -124,7 +124,7 @@ bool getc(uart_ring *q, char *elem) {
124
124
enter_critical_section ();
125
125
if (q -> w_ptr_rx != q -> r_ptr_rx ) {
126
126
if (elem != NULL ) * elem = q -> elems_rx [q -> r_ptr_rx ];
127
- q -> r_ptr_rx = (q -> r_ptr_rx + 1 ) % FIFO_SIZE ;
127
+ q -> r_ptr_rx = (q -> r_ptr_rx + 1U ) % FIFO_SIZE ;
128
128
ret = true;
129
129
}
130
130
exit_critical_section ();
@@ -137,7 +137,7 @@ bool injectc(uart_ring *q, char elem) {
137
137
uint16_t next_w_ptr ;
138
138
139
139
enter_critical_section ();
140
- next_w_ptr = (q -> w_ptr_rx + 1 ) % FIFO_SIZE ;
140
+ next_w_ptr = (q -> w_ptr_rx + 1U ) % FIFO_SIZE ;
141
141
if (next_w_ptr != q -> r_ptr_rx ) {
142
142
q -> elems_rx [q -> w_ptr_rx ] = elem ;
143
143
q -> w_ptr_rx = next_w_ptr ;
@@ -153,7 +153,7 @@ bool putc(uart_ring *q, char elem) {
153
153
uint16_t next_w_ptr ;
154
154
155
155
enter_critical_section ();
156
- next_w_ptr = (q -> w_ptr_tx + 1 ) % FIFO_SIZE ;
156
+ next_w_ptr = (q -> w_ptr_tx + 1U ) % FIFO_SIZE ;
157
157
if (next_w_ptr != q -> r_ptr_tx ) {
158
158
q -> elems_tx [q -> w_ptr_tx ] = elem ;
159
159
q -> w_ptr_tx = next_w_ptr ;
@@ -195,10 +195,10 @@ void clear_uart_buff(uart_ring *q) {
195
195
196
196
// ***************************** start UART code *****************************
197
197
198
- #define __DIV (_PCLK_ , _BAUD_ ) (((_PCLK_) * 25 ) / (4 * (_BAUD_)))
199
- #define __DIVMANT (_PCLK_ , _BAUD_ ) (__DIV((_PCLK_), (_BAUD_)) / 100 )
200
- #define __DIVFRAQ (_PCLK_ , _BAUD_ ) ((((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100 )) * 16 ) + 50 ) / 100 )
201
- #define __USART_BRR (_PCLK_ , _BAUD_ ) ((__DIVMANT((_PCLK_), (_BAUD_)) << 4) | (__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0F ))
198
+ #define __DIV (_PCLK_ , _BAUD_ ) (((_PCLK_) * 25U ) / (4U * (_BAUD_)))
199
+ #define __DIVMANT (_PCLK_ , _BAUD_ ) (__DIV((_PCLK_), (_BAUD_)) / 100U )
200
+ #define __DIVFRAQ (_PCLK_ , _BAUD_ ) ((((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100U )) * 16U ) + 50U ) / 100U )
201
+ #define __USART_BRR (_PCLK_ , _BAUD_ ) ((__DIVMANT((_PCLK_), (_BAUD_)) << 4) | (__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU ))
202
202
203
203
void uart_set_baud (USART_TypeDef * u , unsigned int baud ) {
204
204
if (u == USART1 ) {
@@ -226,7 +226,7 @@ void uart_dma_drain(void) {
226
226
unsigned int i ;
227
227
for (i = 0 ; i < (USART1_DMA_LEN - DMA2_Stream5 -> NDTR ); i ++ ) {
228
228
char c = usart1_dma [i ];
229
- uint16_t next_w_ptr = (q -> w_ptr_rx + 1 ) % FIFO_SIZE ;
229
+ uint16_t next_w_ptr = (q -> w_ptr_rx + 1U ) % FIFO_SIZE ;
230
230
if (next_w_ptr != q -> r_ptr_rx ) {
231
231
q -> elems_rx [q -> w_ptr_rx ] = c ;
232
232
q -> w_ptr_rx = next_w_ptr ;
@@ -322,11 +322,11 @@ void putui(uint32_t i) {
322
322
str [idx ] = '\0' ;
323
323
idx -- ;
324
324
do {
325
- str [idx ] = (i_copy % 10 ) + 0x30 ;
325
+ str [idx ] = (i_copy % 10U ) + 0x30U ;
326
326
idx -- ;
327
327
i_copy /= 10 ;
328
- } while (i_copy != 0 );
329
- puts (str + idx + 1 );
328
+ } while (i_copy != 0U );
329
+ puts (str + idx + 1U );
330
330
}
331
331
332
332
void puth (unsigned int i ) {
0 commit comments