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