From 7840f9c7dbbfcba9d7a56911a0d1c123415547b5 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 25 Feb 2020 20:57:36 +0100 Subject: [PATCH] Library: Compiler barrier, debug_flush() --- lib/dfu-bootloader.c | 3 +-- lib/util-debug.c | 8 ++++++++ lib/util.h | 8 ++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/dfu-bootloader.c b/lib/dfu-bootloader.c index 1d7e02e..3df8351 100644 --- a/lib/dfu-bootloader.c +++ b/lib/dfu-bootloader.c @@ -451,8 +451,7 @@ restart: ; DEBUG("DFU: Boot (sp=%08x pc=%08x)\n", (uint) sp, (uint) pc); #ifdef DEBUG_USART - while (!usart_get_flag(DEBUG_USART, USART_FLAG_TC)) - ; + debug_flush(); #endif debug_led(0); diff --git a/lib/util-debug.c b/lib/util-debug.c index 72a566e..d0914a6 100644 --- a/lib/util-debug.c +++ b/lib/util-debug.c @@ -80,6 +80,14 @@ void debug_putc(int c) #endif } +void debug_flush(void) +{ +#ifdef DEBUG_USART + while (!usart_get_flag(DEBUG_USART, USART_FLAG_TC)) + ; +#endif +} + void debug_puts(const char *s) { while (*s) diff --git a/lib/util.h b/lib/util.h index 6b9f4ba..18e3652 100644 --- a/lib/util.h +++ b/lib/util.h @@ -85,11 +85,19 @@ static inline void wait_for_interrupt(void) asm volatile ("wfi"); } +// A compiler memory barrier + +static inline void barrier(void) +{ + asm volatile ("" : : : "memory"); +} + // util-debug.c void debug_printf(const char *fmt, ...) __attribute__((format(printf,1,2))); void debug_puts(const char *s); void debug_putc(int c); +void debug_flush(void); void debug_led(bool light); void debug_led_toggle(void); -- 2.39.2