qemu/uart: Implement uart_rx_any function.

So it can be used for polling.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader
2025-10-11 14:41:13 +02:00
committed by Damien George
parent be4892097e
commit c04d2d691c
2 changed files with 21 additions and 0 deletions

View File

@@ -57,6 +57,10 @@ int uart_rx_chr(void) {
return UART0->DR;
}
int uart_rx_any(void) {
return UART0->SR & UART_SR_RXNE;
}
void uart_tx_strn(const char *buf, size_t len) {
for (size_t i = 0; i < len; ++i) {
UART0->DR = buf[i];
@@ -94,6 +98,10 @@ int uart_rx_chr(void) {
return UART0->RXD;
}
int uart_rx_any(void) {
return UART0->RXDRDY ? 1 : 0;
}
void uart_tx_strn(const char *buf, size_t len) {
for (size_t i = 0; i < len; ++i) {
UART0->TXD = buf[i];
@@ -130,6 +138,10 @@ int uart_rx_chr(void) {
return UART0->DATA;
}
int uart_rx_any(void) {
return UART0->STATE & UART_STATE_RXFULL;
}
void uart_tx_strn(const char *buf, size_t len) {
for (size_t i = 0; i < len; ++i) {
while (UART0->STATE & UART_STATE_TXFULL) {
@@ -170,6 +182,10 @@ int uart_rx_chr(void) {
return UART1->URXD & 0xff;
}
int uart_rx_any(void) {
return !(UART1->UTS1 & UART_UTS1_RXEMPTY);
}
void uart_tx_strn(const char *buf, size_t len) {
for (size_t i = 0; i < len; ++i) {
UART1->UTXD = buf[i];
@@ -200,6 +216,10 @@ int uart_rx_chr(void) {
return UART_RX_NO_CHAR;
}
int uart_rx_any(void) {
return UART0->LSR & UART_LSR_DR;
}
void uart_tx_strn(const char *buffer, size_t length) {
for (size_t index = 0; index < length; index++) {
while (!(UART0->LSR & UART_LSR_THRE)) {

View File

@@ -33,6 +33,7 @@
void uart_init(void);
int uart_rx_chr(void);
int uart_rx_any(void);
void uart_tx_strn(const char *buf, size_t len);
#endif // MICROPY_INCLUDED_QEMU_ARM_UART_H