]> cloudbase.mooo.com Git - z180-stamp.git/blob - include/common.h
cli_readline.c: code cleanup (history search)
[z180-stamp.git] / include / common.h
1 /*
2 * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 */
6
7 #ifndef COMMON_H
8 #define COMMON_H
9
10 #include <stdio.h>
11 #include <stdint.h>
12
13 #ifdef __AVR__
14 #include <avr/io.h>
15 #include <avr/pgmspace.h>
16 #include <util/delay.h>
17
18 #define udelay(n) _delay_us(n)
19
20 struct bits {
21 uint8_t b0:1;
22 uint8_t b1:1;
23 uint8_t b2:1;
24 uint8_t b3:1;
25 uint8_t b4:1;
26 uint8_t b5:1;
27 uint8_t b6:1;
28 uint8_t b7:1;
29 } __attribute__((__packed__));
30
31 #define SBIT(port,pin) ((*(volatile struct bits*)&port).b##pin)
32
33 //TODO:
34 // Known to work: 4.8.4, 4.9.1
35 // Known to fail: 4.8.3, 4.9.0
36 #define GCC_BUG_61443 1
37
38 #else
39 // TODO: stm32
40 #endif /* __AVR__ */
41
42 #ifdef __FLASH
43 #define FLASH __flash
44 #define MEMX __memx
45 #else
46 #define FLASH
47 #define MEMX
48 #endif
49
50 #define stringify(s) tostring(s)
51 #define tostring(s) #s
52
53 #define FSTR(X) ((const FLASH char[]) { X } )
54 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
55
56 #define MIN(a,b) ({ typeof (a) _a = (a); \
57 typeof (b) _b = (b); \
58 _a < _b ? _a : _b; })
59 #define MAX(a,b) ({ typeof (a) _a = (a); \
60 typeof (b) _b = (b); \
61 _a > _b ? _a : _b; })
62
63 #ifdef __AVR__
64 #define Stat GPIOR0
65 #else
66 extern volatile uint_least8_t Stat;
67 #endif /* __AVR__ */
68
69 #define S_10MS_TO (1<<0)
70 #define S_MSG_PENDING (1<<1)
71 #define S_CON_PENDING (1<<2)
72
73 static inline
74 void my_puts(const char *s)
75 {
76 fputs(s, stdout);
77 }
78
79 static inline
80 void my_puts_P(const char *s)
81 {
82 #ifdef __AVR__
83 fputs_P(s, stdout);
84 #else
85 fputs(s, stdout);
86 #endif /* __AVR__ */
87 }
88
89 #endif /* COMMON_H */