You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

38 lines
820 B

  1. #ifndef UTIL_H
  2. #define UTIL_H
  3. #include "config.h"
  4. /* Convert from ascii hex digit to number */
  5. uint8_t from_hex(uint8_t ch);
  6. extern const uint8_t hex[16];
  7. int32_t hex_to_u16(char x[4]);
  8. /* Array length */
  9. #define array_len(x) (sizeof(x)/sizeof(x[0]))
  10. /* ISR disable/enable with saving of previous state */
  11. #define __int_top() int __sr_save
  12. #define __int_disable() __sr_save=SR; SRbits.IPL=7
  13. #define __int_enable() SR=__sr_save
  14. #define disable_int(x) do { \
  15. __int_top(); \
  16. __int_disable(); \
  17. x; \
  18. __int_enable(); } while(0)
  19. /* Misc */
  20. #define max(a,b) \
  21. ({ typeof (a) _a = (a); \
  22. typeof (b) _b = (b); \
  23. _a > _b ? _a : _b; })
  24. #define min(a,b) \
  25. ({ typeof (a) _a = (a); \
  26. typeof (b) _b = (b); \
  27. _a < _b ? _a : _b; })
  28. #define clamp(a,v,b) min(b,max(v,a))
  29. #endif