]> cloudbase.mooo.com Git - z180-stamp.git/blob - include/common.h
commandtable, flags: int --> uint8_t/uint_fast8_t. Macro UNUSED for Parameters/Variables
[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 #define GCC_VERSION (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
14
15 #define USED __attribute__((used))
16 #define UNUSED __attribute__((unused))
17
18 #ifdef __AVR__
19 #include <avr/io.h>
20 #include <avr/pgmspace.h>
21 #include <util/delay.h>
22
23 #define udelay(n) _delay_us(n)
24
25 struct bits {
26 uint8_t b0:1;
27 uint8_t b1:1;
28 uint8_t b2:1;
29 uint8_t b3:1;
30 uint8_t b4:1;
31 uint8_t b5:1;
32 uint8_t b6:1;
33 uint8_t b7:1;
34 } __attribute__((__packed__));
35
36 #define SBIT(port,pin) ((*(volatile struct bits*)&port).b##pin)
37
38 //GCC bug PR61443
39 // Known to work: 4.8.4, 4.9.1
40 // Known to fail: 4.8.3, 4.9.0
41
42 #if (GCC_VERSION < 40804) || (GCC_VERSION == 40900)
43 #define GCC_BUG_61443 1
44 #endif /* PR61443 */
45
46 #else
47 // TODO: stm32
48 #endif /* __AVR__ */
49
50 #ifdef __FLASH
51 #define FLASH __flash
52 #define MEMX __memx
53 #else
54 #define FLASH
55 #define MEMX
56 #endif
57
58 #define stringify(s) tostring(s)
59 #define tostring(s) #s
60
61 #define FSTR(X) ((const FLASH char[]) { X } )
62 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
63
64 #define MIN(a,b) ({ typeof (a) _a = (a); \
65 typeof (b) _b = (b); \
66 _a < _b ? _a : _b; })
67 #define MAX(a,b) ({ typeof (a) _a = (a); \
68 typeof (b) _b = (b); \
69 _a > _b ? _a : _b; })
70
71 #ifdef __AVR__
72 #define Stat GPIOR0
73 #else
74 extern volatile uint_least8_t Stat;
75 #endif /* __AVR__ */
76
77 #define S_10MS_TO (1<<0)
78 #define S_MSG_PENDING (1<<1)
79 #define S_CON_PENDING (1<<2)
80
81 static inline
82 void my_puts(const char *s)
83 {
84 fputs(s, stdout);
85 }
86
87 static inline
88 void my_puts_P(const char *s)
89 {
90 #ifdef __AVR__
91 fputs_P(s, stdout);
92 #else
93 fputs(s, stdout);
94 #endif /* __AVR__ */
95 }
96
97 #endif /* COMMON_H */