Changeset cbc3587 in mainline
- Timestamp:
- 2018-09-21T21:01:00Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 631281d
- Parents:
- 8591b31
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/drivers/ns16550/ns16550.c
r8591b31 rcbc3587 47 47 #define LSR_TH_READY 0x20 48 48 49 #define RETRY_CNT 100000 50 51 #define NOTHING \ 52 do { \ 53 } while(0) 54 55 #define WHILE_CNT_AND_COND_DO(cnt, expr, statement) \ 56 do { \ 57 for (volatile unsigned i = 0; i < (cnt); i++) \ 58 if ((expr)) \ 59 statement; \ 60 else \ 61 break; \ 62 } while (0) 63 49 64 static uint8_t ns16550_reg_read(ns16550_instance_t *inst, ns16550_reg_t reg) 50 65 { … … 78 93 } 79 94 80 /** <Clear input buffer. */95 /** Clear input buffer. */ 81 96 static void ns16550_clear_buffer(ns16550_instance_t *instance) 82 97 { 83 while (ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY) 84 (void) ns16550_reg_read(instance, NS16550_REG_RBR); 98 WHILE_CNT_AND_COND_DO(RETRY_CNT, 99 ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_DATA_READY, 100 (void) ns16550_reg_read(instance, NS16550_REG_RBR)); 85 101 } 86 102 87 103 static void ns16550_sendb(ns16550_instance_t *instance, uint8_t byte) 88 104 { 89 while (!(ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_TH_READY)) 90 ; 105 WHILE_CNT_AND_COND_DO(RETRY_CNT, 106 !(ns16550_reg_read(instance, NS16550_REG_LSR) & LSR_TH_READY), 107 NOTHING); 108 91 109 ns16550_reg_write(instance, NS16550_REG_THR, byte); 92 110 }
Note:
See TracChangeset
for help on using the changeset viewer.