X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/21a24f90c5aaaaf13f91716208b32cde163c5918..93ea25f2ec6e99ef5ba3068112eafab265087089:/include/common.h?ds=inline diff --git a/include/common.h b/include/common.h index a92f62c..1064bf3 100644 --- a/include/common.h +++ b/include/common.h @@ -1,25 +1,59 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0 + */ + #ifndef COMMON_H #define COMMON_H +#include +#include + +#define GCC_VERSION (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) + +#define USED __attribute__((used)) +#define UNUSED __attribute__((unused)) + #ifdef __AVR__ #include +#include +#include + +#define udelay(n) _delay_us(n) -//TODO: +struct bits { + uint8_t b0:1; + uint8_t b1:1; + uint8_t b2:1; + uint8_t b3:1; + uint8_t b4:1; + uint8_t b5:1; + uint8_t b6:1; + uint8_t b7:1; +} __attribute__((__packed__)); + +#define SBIT(port,pin) ((*(volatile struct bits*)&port).b##pin) + +//GCC bug PR61443 // Known to work: 4.8.4, 4.9.1 // Known to fail: 4.8.3, 4.9.0 + +#if (GCC_VERSION < 40804) || (GCC_VERSION == 40900) #define GCC_BUG_61443 1 +#endif /* PR61443 */ #else // TODO: stm32 #endif /* __AVR__ */ -#include - #ifdef __FLASH #define FLASH __flash +#define MEMX __memx #else #define FLASH -#endif +#define MEMX +#endif #define stringify(s) tostring(s) #define tostring(s) #s @@ -27,6 +61,12 @@ #define FSTR(X) ((const FLASH char[]) { X } ) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define MIN(a,b) ({ typeof (a) _a = (a); \ + typeof (b) _b = (b); \ + _a < _b ? _a : _b; }) +#define MAX(a,b) ({ typeof (a) _a = (a); \ + typeof (b) _b = (b); \ + _a > _b ? _a : _b; }) #ifdef __AVR__ #define Stat GPIOR0 @@ -34,28 +74,24 @@ extern volatile uint_least8_t Stat; #endif /* __AVR__ */ -#define S_10MS_TO (1<<0) -#define S_Z180_RUNNING (2<<0) +#define S_10MS_TO (1<<0) +#define S_MSG_PENDING (1<<1) +#define S_CON_PENDING (1<<2) -static inline +static inline void my_puts(const char *s) { fputs(s, stdout); } -#ifdef __AVR__ -static inline +static inline void my_puts_P(const char *s) { +#ifdef __AVR__ fputs_P(s, stdout); -} - #else -static inline -void my_puts_P(const char *s) -{ fputs(s, stdout); -} #endif /* __AVR__ */ -#endif /* COMMON_H */ +} +#endif /* COMMON_H */