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