Skip to content

Commit

Permalink
kitty: fix issue with serial input
Browse files Browse the repository at this point in the history
The problem with always waiting on a event to say that we
have new serial input is that sometimes there isn't anything
new, although we have more data left to process.

The particular scenario is when MicroPython has not been
executed for a long time although we have had serial input
occur. This would have resulted in multiple new entries in
the shared queues, but only a single notification.
  • Loading branch information
Ivan-Velickovic committed Mar 13, 2024
1 parent 6d26c03 commit f9e0a7b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions examples/kitty/src/micropython/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ extern ring_handle_t serial_tx_ring;

// Receive single character, blocking until one is available.
int mp_hal_stdin_rx_chr(void) {
// Wait for notification from RX multiplexor.
mp_blocking_events = mp_event_source_serial;
co_switch(t_event);
mp_blocking_events = mp_event_source_none;
if (ring_empty(serial_rx_ring.used_ring)) {
// Wait for notification from RX multiplexor, but only if we
// do not already have data to process.
mp_blocking_events = mp_event_source_serial;
co_switch(t_event);
mp_blocking_events = mp_event_source_none;
}
// Dequeue buffer and return char
uintptr_t buffer = 0;
unsigned int buffer_len = 0;
Expand Down

0 comments on commit f9e0a7b

Please sign in to comment.