27
27
28
28
/* UART test using ACV */
29
29
30
+ #include <unistd.h>
30
31
#include "spr-defs.h"
31
32
#include "support.h"
32
33
76
77
#define WAIT () {asm ("l.nop");asm ("l.nop");asm ("l.nop");asm ("l.nop");}
77
78
/* fails if there is an error */
78
79
#define NO_ERROR () { unsigned x = getreg (UART_LSR); if ((x & (LSR_BREAK|LSR_FE|LSR_PE|LSR_OE)) && !(x & LSR_ERR)) \
79
- printf ("LSR7 (0x%02x) ERR @ %i\n", x, __LINE__); ASSERT(!(x & LSR_ERR) && ((x & 0x60) != 0x40));}
80
+ { printf ("LSR7 (0x%02x) ERR @ %i\n", x, __LINE__); } ASSERT(!(x & LSR_ERR) && ((x & 0x60) != 0x40));}
80
81
#define MARK () printf ("Passed line %i\n", __LINE__)
81
82
82
83
#ifndef __LINE__
@@ -93,12 +94,12 @@ void fail (char *func, int line)
93
94
exit (1 );
94
95
}
95
96
96
- inline void setreg (unsigned long addr , unsigned char value )
97
+ static inline void setreg (unsigned long addr , unsigned char value )
97
98
{
98
99
* ((volatile unsigned char * )addr ) = value ;
99
100
}
100
101
101
- inline unsigned long getreg (unsigned long addr )
102
+ static inline unsigned long getreg (unsigned long addr )
102
103
{
103
104
return * ((volatile unsigned char * )addr );
104
105
}
@@ -148,7 +149,9 @@ void recv_char (int ch)
148
149
char r ;
149
150
report (ch );
150
151
/* Wait for rx fifo to be */
151
- while (!((x = getreg (UART_LSR )) & LSR_DR ));
152
+ while (!((x = getreg (UART_LSR )) & LSR_DR )) {
153
+ ;
154
+ }
152
155
if ((x & (LSR_BREAK |LSR_FE |LSR_PE |LSR_OE )) && !(x & LSR_ERR )) printf ("LSR7 (0x%02x) ERR @ recv_char\n" , x );
153
156
ASSERT (!(x & LSR_ERR ));
154
157
@@ -167,7 +170,9 @@ void send_char_no_wait (int ch)
167
170
void send_char (int ch )
168
171
{
169
172
report (ch );
170
- while (!(getreg (UART_LSR ) & LSR_TXFE ));
173
+ while (!(getreg (UART_LSR ) & LSR_TXFE )) {
174
+ ;
175
+ }
171
176
NO_ERROR ();
172
177
setreg (UART_THR , ch ); /* send character */
173
178
NO_ERROR ();
@@ -348,7 +353,9 @@ void send_recv_test ()
348
353
s = "test_" ;
349
354
while (* s ) {
350
355
/* Wait for tx fifo and tx to be empty */
351
- while (!(getreg (UART_LSR ) & LSR_TXE ));
356
+ while (!(getreg (UART_LSR ) & LSR_TXE )) {
357
+ ;
358
+ }
352
359
NO_ERROR ();
353
360
setreg (UART_THR , * s ); /* send character */
354
361
NO_ERROR ();
@@ -373,7 +380,9 @@ void send_recv_test ()
373
380
374
381
/* Receives and compares the string */
375
382
s = "recv" ;
376
- while (* s ) recv_char (* s ++ );
383
+ while (* s ) {
384
+ recv_char (* s ++ );
385
+ }
377
386
MARK ();
378
387
printf ("OK\n" );
379
388
}
@@ -401,7 +410,9 @@ void break_test ()
401
410
/* Receive a break */
402
411
send_char ('!' );
403
412
MARK ();
404
- while (!((x = getreg (UART_LSR )) & LSR_DR ));
413
+ while (!((x = getreg (UART_LSR )) & LSR_DR )) {
414
+ ;
415
+ }
405
416
/* we should receive zero character with broken frame and break bit should be set */
406
417
printf ("[%x]\n" , (LSR_DR | LSR_BREAK | LSR_ERR | LSR_TXFE | LSR_TXE ));
407
418
ASSERT (x == (LSR_DR | LSR_BREAK | LSR_ERR | LSR_TXFE | LSR_TXE ));
@@ -410,7 +421,9 @@ void break_test ()
410
421
411
422
/* Send a # to release break */
412
423
setreg (UART_THR , '#' );
413
- while (!(getreg (UART_LSR ) & LSR_DR ));
424
+ while (!(getreg (UART_LSR ) & LSR_DR )) {
425
+ ;
426
+ }
414
427
NO_ERROR (); /* BREAK bit should be cleared now */
415
428
ASSERT (getreg (UART_RBR ) == '$' );
416
429
MARK ();
@@ -419,7 +432,9 @@ void break_test ()
419
432
s = "ns" ;
420
433
while (* s ) send_char (* s ++ );
421
434
ASSERT (!(getreg (UART_LSR ) & LSR_DR ));
422
- while (!(getreg (UART_LSR ) & LSR_TXE )); /* Wait till we send everything */
435
+ while (!(getreg (UART_LSR ) & LSR_TXE )) {
436
+ ; /* Wait till we send everything */
437
+ }
423
438
/* this should break the * char, so it should not be received */
424
439
setreg (UART_THR , '*' );
425
440
setreg (UART_LCR , 0x3 | LCR_BREAK );
@@ -433,7 +448,9 @@ void break_test ()
433
448
434
449
/* Receive a break */
435
450
send_char ('#' );
436
- while (!((x = getreg (UART_LSR )) & LSR_DR ));
451
+ while (!((x = getreg (UART_LSR )) & LSR_DR )) {
452
+ ;
453
+ }
437
454
/* we should receive zero character with broken frame and break bit
438
455
should not be set, because we cleared it */
439
456
printf ("[%x:%x]\n" , x , (LSR_DR | LSR_BREAK |LSR_ERR | LSR_TXFE | LSR_TXE ));
@@ -442,7 +459,9 @@ void break_test ()
442
459
MARK ();
443
460
send_char ('?' );
444
461
MARK ();
445
- while (!(getreg (UART_LSR ) & LSR_DR ));
462
+ while (!(getreg (UART_LSR ) & LSR_DR )) {
463
+ ;
464
+ }
446
465
recv_char ('!' );
447
466
printf ("OK\n" );
448
467
}
@@ -513,18 +532,24 @@ void different_modes_test ()
513
532
514
533
/* Restore normal mode */
515
534
send_char ('T' );
516
- while (getreg (UART_LSR ) != 0x60 ); /* Wait for THR to be empty */
535
+ while (getreg (UART_LSR ) != 0x60 ) {
536
+ ; /* Wait for THR to be empty */
537
+ }
517
538
setreg (UART_LCR , LCR_DIVL );
518
539
setreg (UART_DLH , 2 >> 8 );
519
540
setreg (UART_DLL , 2 & 0xff );
520
541
setreg (UART_LCR , 0x03 ); /* 8N1 @ 2 */
521
542
MARK ();
522
- while (!(getreg (UART_LSR ) & 1 )); /* Receive 'x' char */
543
+ while (!(getreg (UART_LSR ) & 1 )) {
544
+ ; /* Receive 'x' char */
545
+ }
523
546
getreg (UART_RBR );
524
547
MARK ();
525
548
526
549
send_char ('T' );
527
- while (getreg (UART_LSR ) != 0x60 ); /* Wait for THR to be empty */
550
+ while (getreg (UART_LSR ) != 0x60 ) {
551
+ ; /* Wait for THR to be empty */
552
+ }
528
553
MARK ();
529
554
printf ("OK\n" );
530
555
}
@@ -546,22 +571,28 @@ void interrupt_test ()
546
571
setreg (UART_FCR , 0x01 ); /* Set trigger level = 1 char, fifo should not be reset */
547
572
setreg (UART_IER , 0x07 ); /* Enable interrupts: line status, THR empty, data ready */
548
573
549
- while (!int_cnt ); /* Clear previous THR interrupt */
574
+ while (!int_cnt ) {
575
+ ; /* Clear previous THR interrupt */
576
+ }
550
577
ASSERT (-- int_cnt == 0 );
551
578
ASSERT (int_iir == 0xc2 );
552
579
ASSERT ((int_lsr & 0xbe ) == 0x20 );
553
580
MARK ();
554
581
555
582
/* I am configured - start interrupt test */
556
583
send_char ('I' );
557
- while (!int_cnt ); /* Wait for THR to be empty */
584
+ while (!int_cnt ) {
585
+ ; /* Wait for THR to be empty */
586
+ }
558
587
ASSERT (-- int_cnt == 0 );
559
588
ASSERT (int_iir == 0xc2 );
560
589
ASSERT ((int_lsr & 0xbe ) == 0x20 );
561
590
MARK ();
562
591
563
592
int_rbr = '0' ;
564
- while (!int_cnt ); /* Wait for DR */
593
+ while (!int_cnt ) {
594
+ ; /* Wait for DR */
595
+ }
565
596
ASSERT (-- int_cnt == 0 );
566
597
ASSERT (int_iir == 0xc4 );
567
598
ASSERT (int_lsr == 0x61 );
@@ -572,14 +603,18 @@ void interrupt_test ()
572
603
573
604
/* Everything ok here, send me 4 more */
574
605
send_char ('I' );
575
- while (!int_cnt ); /* Wait for THR to be empty */
606
+ while (!int_cnt ) {
607
+ ; /* Wait for THR to be empty */
608
+ }
576
609
ASSERT (-- int_cnt == 0 );
577
610
ASSERT (int_iir == 0xc2 );
578
611
ASSERT ((int_lsr & 0xbe ) == 0x20 );
579
612
MARK ();
580
613
581
614
int_rbr = '1' ;
582
- while (!int_cnt ); /* Wait for DR */
615
+ while (!int_cnt ) {
616
+ ; /* Wait for DR */
617
+ }
583
618
ASSERT (-- int_cnt == 0 );
584
619
ASSERT (int_iir == 0xc4 );
585
620
ASSERT (int_lsr == 0x61 );
@@ -589,14 +624,18 @@ void interrupt_test ()
589
624
590
625
/* Everything ok here, send me 5 more */
591
626
send_char ('I' );
592
- while (!int_cnt ); /* Wait for THR to be empty */
627
+ while (!int_cnt ) {
628
+ ; /* Wait for THR to be empty */
629
+ }
593
630
ASSERT (-- int_cnt == 0 );
594
631
ASSERT (int_iir == 0xc2 );
595
632
ASSERT ((int_lsr & 0xbe ) == 0x20 );
596
633
MARK ();
597
634
598
635
int_rbr = '2' ;
599
- while (!int_cnt ); /* Wait for DR */
636
+ while (!int_cnt ) {
637
+ ; /* Wait for DR */
638
+ }
600
639
ASSERT (-- int_cnt == 0 );
601
640
ASSERT (int_iir == 0xc4 );
602
641
ASSERT (int_lsr == 0x61 );
@@ -606,7 +645,9 @@ void interrupt_test ()
606
645
607
646
/* Everything ok here, send me 7 more */
608
647
send_char ('I' );
609
- while (!int_cnt ); /* Wait for THR to be empty */
648
+ while (!int_cnt ) {
649
+ ; /* Wait for THR to be empty */
650
+ }
610
651
ASSERT (-- int_cnt == 0 );
611
652
ASSERT (int_iir == 0xc2 );
612
653
ASSERT ((int_lsr & 0xbe ) == 0x20 );
0 commit comments