common.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. /* Standard C headers */
  3. #include <inttypes.h>
  4. #include <stdarg.h>
  5. #include <stdbool.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. /* Arduino headers */
  10. #include <Arduino.h>
  11. #include <FreeRTOS.h>
  12. /* ESP-IDF headers */
  13. #include <sdkconfig.h>
  14. #include <esp_err.h>
  15. #include <esp_event.h>
  16. #include <esp_log.h>
  17. #ifdef __cplusplus
  18. # define extern_c extern "C"
  19. # define EXTERN_C(...) extern "C" { __VA_ARGS__ }
  20. #else
  21. # define extern_c extern
  22. # define EXTERN_C(...) __VA_ARGS__
  23. #endif
  24. #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
  25. #ifndef MODULE
  26. # define MODULE ""
  27. #endif
  28. #if DEBUG
  29. # define CMSG(...) printf(__VA_ARGS__)
  30. #else
  31. # define CMSG(...) ((void)0)
  32. #endif
  33. #define MSG(...) CMSG(MODULE ": " __VA_ARGS__)
  34. /*
  35. * Common types for callbacks
  36. */
  37. typedef void *token_t;
  38. typedef int (*read_func_t)(token_t token, void *buf, size_t len);
  39. typedef int (*write_func_t)(token_t token, const void *buf, size_t len);
  40. /*
  41. * Sleep thread...
  42. */
  43. static inline void suspend(void)
  44. {
  45. vTaskSuspend(NULL);
  46. }
  47. /*
  48. * Reboot system
  49. */
  50. extern_c void reboot_now(void);
  51. extern_c int reboot_delayed(void);