X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/89adce76dd02f2076ec6de1c6b434bc1f29512f4..1157e75889d3d6d23d1e2514f401cd5b354bd149:/include/common.h diff --git a/include/common.h b/include/common.h index ef5af12..10c4417 100644 --- a/include/common.h +++ b/include/common.h @@ -1,8 +1,31 @@ +/* + * (C) Copyright 2014 Leo C. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + #ifndef COMMON_H #define COMMON_H #ifdef __AVR__ #include +#include +#include + +#define udelay(n) _delay_us(n) + +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) //TODO: // Known to work: 4.8.4, 4.9.1 @@ -21,7 +44,7 @@ #else #define FLASH #define MEMX -#endif +#endif #define stringify(s) tostring(s) #define tostring(s) #s @@ -29,6 +52,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 @@ -36,17 +65,17 @@ extern volatile uint_least8_t Stat; #endif /* __AVR__ */ -#define S_10MS_TO (1<<0) -#define S_MSG_PENDING (2<<0) -#define S_CON_PENDING (3<<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); } -static inline +static inline void my_puts_P(const char *s) { #ifdef __AVR__ @@ -57,4 +86,3 @@ void my_puts_P(const char *s) } #endif /* COMMON_H */ -