common.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #define _GNU_SOURCE 1
  3. #include "compiler.h"
  4. /* Standard C headers */
  5. #include <inttypes.h>
  6. #include <stdarg.h>
  7. #include <stdbool.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. /* Arduino headers */
  12. #include <Arduino.h>
  13. #include <FreeRTOS.h>
  14. /* ESP-IDF headers */
  15. #include <sdkconfig.h>
  16. #include <esp_err.h>
  17. #include <esp_event.h>
  18. #include <esp_log.h>
  19. #include "xmalloc.h"
  20. #ifndef MODULE
  21. # define MODULE ""
  22. #endif
  23. #if DEBUG
  24. # define CMSG(...) printf(__VA_ARGS__)
  25. #else
  26. # define CMSG(...) ((void)0)
  27. #endif
  28. #define MSG(...) CMSG(MODULE ": " __VA_ARGS__)
  29. /*
  30. * Hack to deal with the lack of this information in FreeRTOS proper
  31. */
  32. #define EVENT_BITS (configUSE_16_BIT_TICKS ? 8 : 24)
  33. #define EVENT_ALL_BITS ((1U << EVENT_BITS)-1)
  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);
  52. /*
  53. * Board version
  54. */
  55. extern_c uint8_t max80_board_version;
  56. /*
  57. * Time sync status
  58. */
  59. extern_c volatile bool time_net_sync_status;
  60. struct timeval;
  61. extern_c void time_net_sync(const struct timeval *tv);
  62. extern_c void print_time(const char *msg, const struct timeval *tv);