common.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. * Kill thread; vTaskDelete(NULL) *should* never return...
  49. */
  50. static inline no_return exit_task(void)
  51. {
  52. vTaskDelete(NULL);
  53. while (1) {
  54. /* vTaskDelete() returned!? */
  55. vTaskSuspend(NULL);
  56. }
  57. }
  58. /*
  59. * Reboot system
  60. */
  61. extern_c void reboot_now(void);
  62. extern_c int reboot_delayed(void);
  63. /*
  64. * Main MAC address from efuses
  65. */
  66. extern_c uint8_t efuse_default_mac[6];
  67. /*
  68. * Time sync status
  69. */
  70. extern_c volatile bool time_net_sync_status;
  71. struct timeval;
  72. extern_c void time_net_sync(const struct timeval *tv);
  73. extern_c void print_time(const char *msg, const struct timeval *tv);