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