28 #include <avr/sleep.h> 29 #include <avr/eeprom.h> 30 #include <avr/interrupt.h> 31 #include <avr/pgmspace.h> 32 #include <avr/sfr_defs.h> 33 #include <util/delay_basic.h> 47 #define __UNIQUE(name) __CONCAT(name,__LINE__) 52 #define ROUND(x,y) (((x) + (y - 1)) / (y)) 62 #define BYTES(bits) ROUND(bits, CHARBITS) 68 # define UINT8_MAX ((uin8_t) 0xffU) 71 # define UINT16_MAX ((uint16_t) 0xffffU) 74 # define UINT32_MAX ((uint32_t) 0xffffffffUL) 77 # define INT_MIN INT16_MIN 78 # define INT_MAX INT16_MAX 81 # define INT8_MIN ((int8_t) 0x80) 82 # define INT8_MAX ((int8_t) 0x7f) 85 # define INT16_MIN ((int16_t) 0x8000) 86 # define INT16_MAX ((int16_t) 0x7fff) 89 # define INT32_MIN ((int32_t) 0x80000000L) 90 # define INT32_MAX ((int32_t) 0x7fffffffL) 93 # define INT_MIN INT16_MIN 94 # define INT_MAX INT16_MAX 101 # define NULL ((void*) 0) 152 #define LIKELY(x) __builtin_expect((x), true) 153 #define UNLIKELY(x) __builtin_expect((x), false) 158 #define UNUSED(x) (void) (x) 165 #define membersof(x) (sizeof(x) / sizeof(x[0])) 172 #if ((__GNUC__ == 4) && (__GNUC_MINOR__ <= 3)) 174 # define offsetof(t,m) \ 177 const t* __p = NULL; \ 181 # define __PROGMEM __attribute__((section(".progmem.data"))) 183 # define __PROGMEM PROGMEM 187 typedef const PROGMEM
class prog_str*
str_P;
197 static const char __c[] __PROGMEM = (s); \ 202 #define PSTR(s) STR_P(s) 203 #define __PSTR(s) STR_P(s) 208 return (
strcat_P(s1, (
const char*) s2));
226 return (
strcmp_P(s1, (
const char*) s2));
232 return (
strncmp_P(s1, (
const char*) s2, n));
238 return (
strcpy_P(s1, (
const char*) s2));
265 # if !defined(__GXX_EXPERIMENTAL_CXX0X__) 266 # define static_assert(condition,message) 274 #define I_CPU (F_CPU / 1000000L) 280 #define DELAY(us) _delay_loop_2((us) * (F_CPU / 4000000L)) 287 extern void (*
delay)(uint32_t ms);
294 extern void (*
sleep)(uint16_t s);
300 extern void (*
yield)();
305 #define nop() __asm__ __volatile__("nop") 312 #define barrier() __asm__ __volatile__("" ::: "memory") 318 inline uint8_t
lock() __attribute__((always_inline));
322 __asm__ __volatile__(
"cli" :::
"memory");
330 inline void unlock(uint8_t key) __attribute__((always_inline));
334 __asm__ __volatile__(
"" :::
"memory");
342 inline void __unlock(uint8_t* key) __attribute__((always_inline));
346 __asm__ __volatile__(
"" :::
"memory");
360 #define synchronized \ 361 for (uint8_t __key __attribute__((__cleanup__(__unlock))) = lock(), \ 375 inline uint8_t
lock(
condvar_t &cond) __attribute__((always_inline));
378 uint8_t key =
lock();
429 __attribute__((always_inline));
432 vp->
buf = (
void*) buf;
460 inline uint16_t
swap(uint16_t value) __attribute__((always_inline));
461 inline uint16_t
swap(uint16_t value)
463 asm volatile(
"mov __tmp_reg__, %A0" "\n\t" 464 "mov %A0, %B0" "\n\t" 465 "mov %B0, __tmp_reg__" "\n\t" 478 inline void swap(uint16_t* dest,
const uint16_t* src,
size_t size)
482 *dest++ =
swap(*src++);
493 void swap(T* dest,
const T* src)
495 swap((uint16_t*) dest, (
const uint16_t*) src,
sizeof(T) /
sizeof(uint16_t));
503 inline void swap(uint16_t* buf,
size_t size)
520 swap((uint16_t*) buf,
sizeof(T) /
sizeof(uint16_t));
528 inline int16_t
swap(int16_t value) __attribute__((always_inline));
529 inline int16_t
swap(int16_t value)
531 return ((int16_t)
swap((uint16_t) value));
540 inline void swap(int16_t* dest,
const int16_t* src,
size_t size)
544 *dest++ =
swap(*src++);
553 inline uint32_t
swap(uint32_t value) __attribute__((always_inline));
554 inline uint32_t
swap(uint32_t value)
556 asm volatile(
"mov __tmp_reg__, %A0" "\n\t" 557 "mov %A0, %D0" "\n\t" 558 "mov %D0, __tmp_reg__" "\n\t" 559 "mov __tmp_reg__, %B0" "\n\t" 560 "mov %B0, %C0" "\n\t" 561 "mov %C0, __tmp_reg__" "\n\t" 573 inline int32_t
swap(int32_t value) __attribute__((always_inline));
574 inline int32_t
swap(int32_t value)
576 return ((int32_t)
swap((uint32_t) value));
591 inline char tohex(uint8_t value) __attribute__((always_inline));
596 return (value - 10 +
'a');
597 return (value +
'0');
605 inline char toHEX(uint8_t value) __attribute__((always_inline));
610 return (value - 10 +
'A');
611 return (value +
'0');
int strncmp_P(const char *s1, str_P s2, size_t n)
uint16_t swap(uint16_t value)
iovec_t(void *buf=NULL, size_t size=0)
void(* delay)(uint32_t ms)
const class prog_str * str_P
size_t size
Size of buffer in bytes.
char * strcasestr_P(const char *s1, str_P s2)
int strcasecmp_P(const char *s1, str_P s2)
char toHEX(uint8_t value)
void * buf
Buffer pointer.
char * strcpy_P(char *s1, str_P s2)
str_P strchr_P(str_P s, int __val)
void __unlock(uint8_t *key)
void(* sleep)(uint16_t s)
char tohex(uint8_t value)
char * strcat_P(char *s1, str_P s2)
str_P strchrnul_P(str_P s, int __val)
void iovec_arg(iovec_t *&vp, const void *buf, size_t size)
void iovec_end(iovec_t *&vp)
size_t iovec_size(const iovec_t *vec)
int strcmp_P(const char *s1, str_P s2)