Skip to content

Commit c04d2d6

Browse files
iabdalkaderdpgeorge
authored andcommitted
qemu/uart: Implement uart_rx_any function.
So it can be used for polling. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent be48920 commit c04d2d6

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

ports/qemu/uart.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ int uart_rx_chr(void) {
5757
return UART0->DR;
5858
}
5959

60+
int uart_rx_any(void) {
61+
return UART0->SR & UART_SR_RXNE;
62+
}
63+
6064
void uart_tx_strn(const char *buf, size_t len) {
6165
for (size_t i = 0; i < len; ++i) {
6266
UART0->DR = buf[i];
@@ -94,6 +98,10 @@ int uart_rx_chr(void) {
9498
return UART0->RXD;
9599
}
96100

101+
int uart_rx_any(void) {
102+
return UART0->RXDRDY ? 1 : 0;
103+
}
104+
97105
void uart_tx_strn(const char *buf, size_t len) {
98106
for (size_t i = 0; i < len; ++i) {
99107
UART0->TXD = buf[i];
@@ -130,6 +138,10 @@ int uart_rx_chr(void) {
130138
return UART0->DATA;
131139
}
132140

141+
int uart_rx_any(void) {
142+
return UART0->STATE & UART_STATE_RXFULL;
143+
}
144+
133145
void uart_tx_strn(const char *buf, size_t len) {
134146
for (size_t i = 0; i < len; ++i) {
135147
while (UART0->STATE & UART_STATE_TXFULL) {
@@ -170,6 +182,10 @@ int uart_rx_chr(void) {
170182
return UART1->URXD & 0xff;
171183
}
172184

185+
int uart_rx_any(void) {
186+
return !(UART1->UTS1 & UART_UTS1_RXEMPTY);
187+
}
188+
173189
void uart_tx_strn(const char *buf, size_t len) {
174190
for (size_t i = 0; i < len; ++i) {
175191
UART1->UTXD = buf[i];
@@ -200,6 +216,10 @@ int uart_rx_chr(void) {
200216
return UART_RX_NO_CHAR;
201217
}
202218

219+
int uart_rx_any(void) {
220+
return UART0->LSR & UART_LSR_DR;
221+
}
222+
203223
void uart_tx_strn(const char *buffer, size_t length) {
204224
for (size_t index = 0; index < length; index++) {
205225
while (!(UART0->LSR & UART_LSR_THRE)) {

ports/qemu/uart.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
void uart_init(void);
3535
int uart_rx_chr(void);
36+
int uart_rx_any(void);
3637
void uart_tx_strn(const char *buf, size_t len);
3738

3839
#endif // MICROPY_INCLUDED_QEMU_ARM_UART_H

0 commit comments

Comments
 (0)