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