]> mj.ucw.cz Git - home-hw.git/commitdiff
Library: Compiler barrier, debug_flush()
authorMartin Mares <mj@ucw.cz>
Tue, 25 Feb 2020 19:57:36 +0000 (20:57 +0100)
committerMartin Mares <mj@ucw.cz>
Tue, 25 Feb 2020 19:57:36 +0000 (20:57 +0100)
lib/dfu-bootloader.c
lib/util-debug.c
lib/util.h

index 1d7e02e5f8bc099a843e7ff923eba6027e7e2681..3df8351aad66e50098d281f6f519eea1cc0a3737 100644 (file)
@@ -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);
 
index 72a566eae40f49226514c9edf53cb5b7fba8dc93..d0914a669b4c1c050a9eac3f3d1e8ded79c075f6 100644 (file)
@@ -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)
index 6b9f4ba488dd94a54daab69a866ba7ce10253d2c..18e36524b422304b6ec1b0aa98e5bd0e8486dcc9 100644 (file)
@@ -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);