common.h 815 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef COMMON_H
  2. #define COMMON_H
  3. #include "at32f403a_407.h"
  4. #if defined ( __GNUC__ )
  5. #ifdef __packed
  6. #undef __packed
  7. #endif
  8. #define __packed __attribute__(( packed ))
  9. #endif
  10. #ifdef DEBUG
  11. /*
  12. #ifdef PRINTF_STDLIB
  13. #include <stdio.h>
  14. #endif
  15. #ifdef PRINTF_CUSTOM
  16. #include "tinystdio.h"
  17. #endif
  18. #undef DBG
  19. */
  20. #define DBG
  21. #else
  22. #undef DBG
  23. #define DBG if (0)
  24. #endif
  25. // https://stackoverflow.com/questions/4415524/common-array-length-macro-for-c
  26. #define array_len(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
  27. #define _strc(x, y) x ## y
  28. #define strc(x, y) _strc(x, y)
  29. #define _str(x) #x
  30. #define str(x) _str(x)
  31. //#define MAX(x, y) (((x) > (y)) ? (x) : (y))
  32. //#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  33. #define isInterrupt() ((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0)
  34. #endif /* COMMON_H */