#ifndef UTIL_H #define UTIL_H #include "config.h" /* Convert from ascii hex digit to number */ uint8_t from_hex(uint8_t ch); extern const uint8_t hex[16]; int32_t hex_to_u16(char x[4]); /* Array length */ #define array_len(x) (sizeof(x)/sizeof(x[0])) /* ISR disable/enable with saving of previous state */ #define __int_top() int __sr_save #define __int_disable() __sr_save=SR; SRbits.IPL=7 #define __int_enable() SR=__sr_save #define disable_int(x) do { \ __int_top(); \ __int_disable(); \ x; \ __int_enable(); } while(0) /* Misc */ #define max(a,b) \ ({ typeof (a) _a = (a); \ typeof (b) _b = (b); \ _a > _b ? _a : _b; }) #define min(a,b) \ ({ typeof (a) _a = (a); \ typeof (b) _b = (b); \ _a < _b ? _a : _b; }) #define clamp(a,v,b) min(b,max(v,a)) #define abs(a) \ ({ typeof (a) _a = (a); \ _a < 0 ? -_a : _a; }) #endif