Skip to content

Commit 7ca70ed

Browse files
iabdalkaderdpgeorge
authored andcommitted
qemu/mphalport: Implement stdin poll and mp-hal ticks functions.
Using the newly added `uart_rx_any()` and system ticks functions. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent abbe883 commit 7ca70ed

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

ports/qemu/mphalport.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,23 @@
2525
*/
2626

2727
#include "py/mphal.h"
28+
#include "py/stream.h"
2829
#include "shared/runtime/semihosting_arm.h"
2930
#include "uart.h"
3031

3132
// UART is better behaved with redirection under qemu-system-arm, so prefer that for stdio.
3233
#define USE_UART (1)
3334
#define USE_SEMIHOSTING (0)
3435

36+
uintptr_t ticks_ms(void);
37+
uintptr_t ticks_us(void);
38+
3539
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
36-
// Not implemented.
40+
#if USE_UART
41+
if ((poll_flags & MP_STREAM_POLL_RD) && uart_rx_any()) {
42+
return MP_STREAM_POLL_RD;
43+
}
44+
#endif
3745
return 0;
3846
}
3947

@@ -64,3 +72,27 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
6472
#endif
6573
return len;
6674
}
75+
76+
mp_uint_t mp_hal_ticks_ms(void) {
77+
return ticks_ms();
78+
}
79+
80+
mp_uint_t mp_hal_ticks_us(void) {
81+
return ticks_us();
82+
}
83+
84+
void mp_hal_delay_ms(mp_uint_t ms) {
85+
mp_uint_t start = mp_hal_ticks_ms();
86+
while (mp_hal_ticks_ms() - start < ms) {
87+
}
88+
}
89+
90+
void mp_hal_delay_us(mp_uint_t us) {
91+
mp_uint_t start = mp_hal_ticks_us();
92+
while (mp_hal_ticks_us() - start < us) {
93+
}
94+
}
95+
96+
mp_uint_t mp_hal_ticks_cpu(void) {
97+
return 0;
98+
}

0 commit comments

Comments
 (0)