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