]>
Commit | Line | Data |
---|---|---|
35edb766 L |
1 | /* |
2 | * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de> | |
3 | * | |
a1595a8e | 4 | * SPDX-License-Identifier: GPL-2.0 |
35edb766 L |
5 | */ |
6 | ||
d684c216 L |
7 | #ifndef COMMON_H |
8 | #define COMMON_H | |
9 | ||
a1595a8e L |
10 | #include <stdio.h> |
11 | #include <stdint.h> | |
12 | ||
587f9485 L |
13 | #define GCC_VERSION (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) |
14 | ||
d684c216 L |
15 | #ifdef __AVR__ |
16 | #include <avr/io.h> | |
889202c4 | 17 | #include <avr/pgmspace.h> |
8a7decea L |
18 | #include <util/delay.h> |
19 | ||
20 | #define udelay(n) _delay_us(n) | |
d684c216 | 21 | |
26331e24 L |
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 | ||
587f9485 | 35 | //GCC bug PR61443 |
d684c216 L |
36 | // Known to work: 4.8.4, 4.9.1 |
37 | // Known to fail: 4.8.3, 4.9.0 | |
587f9485 L |
38 | |
39 | #if (GCC_VERSION < 40804) || (GCC_VERSION == 40900) | |
d684c216 | 40 | #define GCC_BUG_61443 1 |
587f9485 | 41 | #endif /* PR61443 */ |
d684c216 L |
42 | |
43 | #else | |
44 | // TODO: stm32 | |
72f58822 | 45 | #endif /* __AVR__ */ |
d684c216 | 46 | |
d684c216 L |
47 | #ifdef __FLASH |
48 | #define FLASH __flash | |
fc30b18e | 49 | #define MEMX __memx |
d684c216 L |
50 | #else |
51 | #define FLASH | |
fc30b18e | 52 | #define MEMX |
26331e24 | 53 | #endif |
d684c216 L |
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 | ||
d264541a L |
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; }) | |
d684c216 L |
67 | |
68 | #ifdef __AVR__ | |
69 | #define Stat GPIOR0 | |
70 | #else | |
71 | extern volatile uint_least8_t Stat; | |
72f58822 | 72 | #endif /* __AVR__ */ |
d684c216 | 73 | |
35edb766 | 74 | #define S_10MS_TO (1<<0) |
8a7decea L |
75 | #define S_MSG_PENDING (1<<1) |
76 | #define S_CON_PENDING (1<<2) | |
d684c216 | 77 | |
26331e24 | 78 | static inline |
d684c216 L |
79 | void my_puts(const char *s) |
80 | { | |
81 | fputs(s, stdout); | |
d684c216 L |
82 | } |
83 | ||
26331e24 | 84 | static inline |
d684c216 L |
85 | void my_puts_P(const char *s) |
86 | { | |
61b0cfe9 | 87 | #ifdef __AVR__ |
d684c216 | 88 | fputs_P(s, stdout); |
72f58822 | 89 | #else |
72f58822 | 90 | fputs(s, stdout); |
72f58822 | 91 | #endif /* __AVR__ */ |
61b0cfe9 L |
92 | } |
93 | ||
d684c216 | 94 | #endif /* COMMON_H */ |