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