]> mj.ucw.cz Git - home-hw.git/blobdiff - lib/util.h
README
[home-hw.git] / lib / util.h
index b37c527f603f9003373c97bd4f85d0f753f4ac70..18e36524b422304b6ec1b0aa98e5bd0e8486dcc9 100644 (file)
@@ -24,6 +24,7 @@ typedef int32_t s32;
 #define MIN(x,y) ((x) < (y) ? (x) : (y))
 #define MAX(x,y) ((x) > (y) ? (x) : (y))
 #define CLAMP(x,min,max) ({ typeof(x) _t=x; (_t < min) ? min : (_t > max) ? max : _t; })
+#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof((ary)[0]))
 
 #define UNUSED __attribute__((unused))
 
@@ -77,11 +78,26 @@ static inline void put_u32_le(byte *p, u32 x)
        p[0] = x & 0xff;
 }
 
+// CPU instructions not covered by libopencm3
+
+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, ...);
+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);