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