32
32
33
33
#include "uart16550.h"
34
34
35
- #define COM1_BASE 0x3F8
36
- #define COM1_IRQ 4U
37
- #define RX_FIFO_SIZE 256
38
- #define TX_FIFO_SIZE 65536
35
+ #define COM1_BASE 0x3F8U
36
+ #define COM1_IRQ 4U
37
+ #define RX_FIFO_SIZE 256U
38
+ #define TX_FIFO_SIZE 65536U
39
39
40
40
#define vuart_lock_init (vu ) spinlock_init(&((vu)->lock))
41
41
#define vuart_lock (vu ) spinlock_obtain(&((vu)->lock))
45
45
46
46
static void fifo_reset (struct fifo * fifo )
47
47
{
48
- fifo -> rindex = 0 ;
49
- fifo -> windex = 0 ;
50
- fifo -> num = 0 ;
48
+ fifo -> rindex = 0U ;
49
+ fifo -> windex = 0U ;
50
+ fifo -> num = 0U ;
51
51
}
52
52
53
- static void fifo_init (struct fifo * fifo , int sz )
53
+ static void fifo_init (struct fifo * fifo , uint32_t sz )
54
54
{
55
55
fifo -> buf = calloc (1U , sz );
56
56
ASSERT (fifo -> buf != NULL , "" );
@@ -62,29 +62,29 @@ static void fifo_putchar(struct fifo *fifo, char ch)
62
62
{
63
63
fifo -> buf [fifo -> windex ] = ch ;
64
64
if (fifo -> num < fifo -> size ) {
65
- fifo -> windex = (fifo -> windex + 1 ) % fifo -> size ;
65
+ fifo -> windex = (fifo -> windex + 1U ) % fifo -> size ;
66
66
fifo -> num ++ ;
67
67
} else {
68
- fifo -> rindex = (fifo -> rindex + 1 ) % fifo -> size ;
69
- fifo -> windex = (fifo -> windex + 1 ) % fifo -> size ;
68
+ fifo -> rindex = (fifo -> rindex + 1U ) % fifo -> size ;
69
+ fifo -> windex = (fifo -> windex + 1U ) % fifo -> size ;
70
70
}
71
71
}
72
72
73
73
static char fifo_getchar (struct fifo * fifo )
74
74
{
75
75
char c ;
76
76
77
- if (fifo -> num > 0 ) {
77
+ if (fifo -> num > 0U ) {
78
78
c = fifo -> buf [fifo -> rindex ];
79
- fifo -> rindex = (fifo -> rindex + 1 ) % fifo -> size ;
79
+ fifo -> rindex = (fifo -> rindex + 1U ) % fifo -> size ;
80
80
fifo -> num -- ;
81
81
return c ;
82
82
} else {
83
83
return -1 ;
84
84
}
85
85
}
86
86
87
- static int fifo_numchars (struct fifo * fifo )
87
+ static uint32_t fifo_numchars (struct fifo * fifo )
88
88
{
89
89
return fifo -> num ;
90
90
}
@@ -98,11 +98,12 @@ static int fifo_numchars(struct fifo *fifo)
98
98
*/
99
99
static uint8_t vuart_intr_reason (struct vuart * vu )
100
100
{
101
- if (((vu -> lsr & LSR_OE ) != 0 ) && ((vu -> ier & IER_ELSI ) != 0 )) {
101
+ if (((vu -> lsr & LSR_OE ) != 0U ) && ((vu -> ier & IER_ELSI ) != 0U )) {
102
102
return IIR_RLS ;
103
- } else if ((fifo_numchars (& vu -> rxfifo ) > 0 ) && ((vu -> ier & IER_ERBFI ) != 0 )) {
103
+ } else if ((fifo_numchars (& vu -> rxfifo ) > 0U ) &&
104
+ ((vu -> ier & IER_ERBFI ) != 0U )) {
104
105
return IIR_RXTOUT ;
105
- } else if (vu -> thre_int_pending && ((vu -> ier & IER_ETBEI ) != 0 )) {
106
+ } else if (vu -> thre_int_pending && ((vu -> ier & IER_ETBEI ) != 0U )) {
106
107
return IIR_TXRDY ;
107
108
} else {
108
109
return IIR_NOPEND ;
@@ -145,7 +146,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr, struct vm *vm,
145
146
/*
146
147
* Take care of the special case DLAB accesses first
147
148
*/
148
- if ((vu -> lcr & LCR_DLAB ) != 0 ) {
149
+ if ((vu -> lcr & LCR_DLAB ) != 0U ) {
149
150
if (offset == UART16550_DLL ) {
150
151
vu -> dll = value_u8 ;
151
152
goto done ;
@@ -159,7 +160,7 @@ static void vuart_write(__unused struct vm_io_handler *hdlr, struct vm *vm,
159
160
160
161
switch (offset ) {
161
162
case UART16550_THR :
162
- fifo_putchar (& vu -> txfifo , value_u8 );
163
+ fifo_putchar (& vu -> txfifo , ( char ) value_u8 );
163
164
vu -> thre_int_pending = true;
164
165
break ;
165
166
case UART16550_IER :
@@ -231,7 +232,7 @@ static uint32_t vuart_read(__unused struct vm_io_handler *hdlr, struct vm *vm,
231
232
/*
232
233
* Take care of the special case DLAB accesses first
233
234
*/
234
- if ((vu -> lcr & LCR_DLAB ) != 0 ) {
235
+ if ((vu -> lcr & LCR_DLAB ) != 0U ) {
235
236
if (offset == UART16550_DLL ) {
236
237
reg = vu -> dll ;
237
238
goto done ;
@@ -245,13 +246,13 @@ static uint32_t vuart_read(__unused struct vm_io_handler *hdlr, struct vm *vm,
245
246
switch (offset ) {
246
247
case UART16550_RBR :
247
248
vu -> lsr &= ~LSR_OE ;
248
- reg = fifo_getchar (& vu -> rxfifo );
249
+ reg = ( uint8_t ) fifo_getchar (& vu -> rxfifo );
249
250
break ;
250
251
case UART16550_IER :
251
252
reg = vu -> ier ;
252
253
break ;
253
254
case UART16550_IIR :
254
- iir = ((vu -> fcr & FCR_FIFOE ) != 0 ) ? IIR_FIFO_MASK : 0 ;
255
+ iir = ((vu -> fcr & FCR_FIFOE ) != 0U ) ? IIR_FIFO_MASK : 0U ;
255
256
intr_reason = vuart_intr_reason (vu );
256
257
/*
257
258
* Deal with side effects of reading the IIR register
@@ -272,7 +273,7 @@ static uint32_t vuart_read(__unused struct vm_io_handler *hdlr, struct vm *vm,
272
273
/* Transmitter is always ready for more data */
273
274
vu -> lsr |= LSR_TEMT | LSR_THRE ;
274
275
/* Check for new receive data */
275
- if (fifo_numchars (& vu -> rxfifo ) > 0 ) {
276
+ if (fifo_numchars (& vu -> rxfifo ) > 0U ) {
276
277
vu -> lsr |= LSR_DR ;
277
278
} else {
278
279
vu -> lsr &= ~LSR_DR ;
@@ -283,13 +284,13 @@ static uint32_t vuart_read(__unused struct vm_io_handler *hdlr, struct vm *vm,
283
284
break ;
284
285
case UART16550_MSR :
285
286
/* ignore modem I*/
286
- reg = 0 ;
287
+ reg = 0U ;
287
288
break ;
288
289
case UART16550_SCR :
289
290
reg = vu -> scr ;
290
291
break ;
291
292
default :
292
- reg = 0xFF ;
293
+ reg = 0xFFU ;
293
294
break ;
294
295
}
295
296
done :
@@ -315,7 +316,7 @@ static void vuart_register_io_handler(struct vm *vm)
315
316
void vuart_console_tx_chars (struct vuart * vu )
316
317
{
317
318
vuart_lock (vu );
318
- while (fifo_numchars (& vu -> txfifo ) > 0 ) {
319
+ while (fifo_numchars (& vu -> txfifo ) > 0U ) {
319
320
printf ("%c" , fifo_getchar (& vu -> txfifo ));
320
321
}
321
322
vuart_unlock (vu );
@@ -363,7 +364,7 @@ struct vuart *vuart_console_active(void)
363
364
void * vuart_init (struct vm * vm )
364
365
{
365
366
struct vuart * vu ;
366
- uint16_t divisor ;
367
+ uint32_t divisor ;
367
368
368
369
vu = calloc (1U , sizeof (struct vuart ));
369
370
ASSERT (vu != NULL , "" );
0 commit comments