]> mj.ucw.cz Git - home-hw.git/blob - ssr/Inc/util.h
405098c869505bb5ae6780c5c1c1da12edba0ad2
[home-hw.git] / ssr / Inc / util.h
1 #include <stdint.h>
2 #include <stdbool.h>
3
4 typedef unsigned int uint;
5 typedef uint8_t byte;
6 typedef uint16_t u16;
7 typedef int16_t s16;
8 typedef uint32_t u32;
9 typedef int32_t s32;
10
11 #define MIN(x,y) ((x) < (y) ? (x) : (y))
12 #define MAX(x,y) ((x) > (y) ? (x) : (y))
13
14 static inline uint get_u16_le(byte *p)
15 {
16   return (p[1] << 8) | p[0];
17 }
18
19 static inline void put_u16_le(byte *p, u16 x)
20 {
21   p[0] = x;
22   p[1] = x >> 8;
23 }
24
25 static inline void put_u16_be(byte *p, u16 x)
26 {
27   p[0] = x >> 8;
28   p[1] = x;
29 }
30
31 static inline void put_u32_be(byte *p, u32 x)
32 {
33   p[0] = x >> 24;
34   p[1] = (x >> 16) & 0xff;
35   p[2] = (x >> 8) & 0xff;
36   p[3] = x & 0xff;
37 }
38
39 // debug.c
40
41 #undef DEBUG_SEMIHOSTING
42 #define DEBUG_USART USART1
43
44 void debug_printf(const char *fmt, ...);
45 void debug_puts(const char *s);
46 void debug_putc(int c);