macros.h 803 B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef MACROS_H
  2. #define MACROS_H
  3. #include <avr/interrupt.h> //for cli() and sei()
  4. #define FORCE_INLINE __attribute__((always_inline)) inline
  5. #define _UNUSED __attribute__((unused))
  6. #ifndef CRITICAL_SECTION_START
  7. #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
  8. #define CRITICAL_SECTION_END SREG = _sreg;
  9. #endif //CRITICAL_SECTION_START
  10. // Macros to make a string from a macro
  11. #define STRINGIFY_(M) #M
  12. #define STRINGIFY(M) STRINGIFY_(M)
  13. // Macros for bit masks
  14. #undef _BV
  15. #define _BV(n) (1<<(n))
  16. #define TEST(n,b) (!!((n)&_BV(b)))
  17. #define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
  18. #ifndef SBI
  19. #define SBI(A,B) (A |= (1 << (B)))
  20. #endif
  21. #ifndef CBI
  22. #define CBI(A,B) (A &= ~(1 << (B)))
  23. #endif
  24. #define TBI(N,B) (N ^= _BV(B))
  25. #endif //MACROS_H