]> cloudbase.mooo.com Git - z180-stamp.git/blame - include/common.h
Card detect over cs pin: clean initialisation/power up
[z180-stamp.git] / include / common.h
CommitLineData
d684c216
L
1#ifndef COMMON_H
2#define COMMON_H
3
4#ifdef __AVR__
5#include <avr/io.h>
889202c4 6#include <avr/pgmspace.h>
8a7decea
L
7#include <util/delay.h>
8
9#define udelay(n) _delay_us(n)
d684c216 10
26331e24
L
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
d684c216
L
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
72f58822 31#endif /* __AVR__ */
d684c216
L
32
33#include <stdio.h>
34
35#ifdef __FLASH
36#define FLASH __flash
fc30b18e 37#define MEMX __memx
d684c216
L
38#else
39#define FLASH
fc30b18e 40#define MEMX
26331e24 41#endif
d684c216
L
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;
72f58822 54#endif /* __AVR__ */
d684c216
L
55
56#define S_10MS_TO (1<<0)
8a7decea
L
57#define S_MSG_PENDING (1<<1)
58#define S_CON_PENDING (1<<2)
d684c216 59
26331e24 60static inline
d684c216
L
61void my_puts(const char *s)
62{
63 fputs(s, stdout);
d684c216
L
64}
65
26331e24 66static inline
d684c216
L
67void my_puts_P(const char *s)
68{
61b0cfe9 69#ifdef __AVR__
d684c216 70 fputs_P(s, stdout);
72f58822 71#else
72f58822 72 fputs(s, stdout);
72f58822 73#endif /* __AVR__ */
61b0cfe9
L
74}
75
d684c216 76#endif /* COMMON_H */