Skip to content

Commit f473052

Browse files
authored
Merge pull request beckus#30 from kousu/timer-hang
WIP: Fix slow event loop
2 parents bca71e0 + 4ac96ba commit f473052

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

hw/char/stm32_uart.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
/* See the README file for details on these settings. */
3333
//#define DEBUG_STM32_UART
34-
//#define STM32_UART_NO_BAUD_DELAY
34+
#define STM32_UART_NO_BAUD_DELAY
3535
//#define STM32_UART_ENABLE_OVERRUN
3636

3737
#ifdef DEBUG_STM32_UART
@@ -348,6 +348,9 @@ static void stm32_uart_rx_timer_expire(void *opaque) {
348348
Stm32Uart *s = (Stm32Uart *)opaque;
349349

350350
s->receiving = false;
351+
352+
uint64_t curr_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
353+
timer_mod(s->rx_timer, curr_time + s->ns_per_char);
351354
}
352355

353356
/* When the transmit delay is complete, mark the transmit as complete
@@ -452,12 +455,14 @@ static void stm32_uart_receive(void *opaque, const uint8_t *buf, int size)
452455
#ifdef STM32_UART_NO_BAUD_DELAY
453456
/* Do nothing - there is no delay before the module reports it can receive
454457
* the next character. */
455-
curr_time = curr_time; //Avoid "variable unused" compiler error
456458
#else
457459
/* Indicate the module is receiving and start the delay. */
458460
s->receiving = true;
459-
timer_mod(s->rx_timer, curr_time + s->ns_per_char);
460461
#endif
462+
/* Set timer in either case - main event loop must run again to
463+
* trigger next receive when using STM32_UART_NO_BAUD_DELAY. */
464+
curr_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
465+
timer_mod(s->rx_timer, curr_time + s->ns_per_char);
461466
}
462467
}
463468

0 commit comments

Comments
 (0)