macros.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef KBF_ASSERT_H
  2. #define KBF_ASSERT_H
  3. #include <freertos/FreeRTOS.h>
  4. #include <freertos/task.h>
  5. #include <esp_err.h>
  6. #ifndef CHECK
  7. #define CHECK(x) do { \
  8. esp_err_t __err = (x); \
  9. if (__err != ESP_OK) { \
  10. ESP_LOGE("CHECK", "error check failed\n" \
  11. "\tat %s, line %d, in %s\n" \
  12. "\t\tline:\t%s\n\t\terror:\t%d (%s)", \
  13. __FILE__, __LINE__, __ASSERT_FUNC, #x, \
  14. __err, esp_err_to_name(__err)); \
  15. ESP_LOGE("CHECK", "aborting in 30 seconds..."); \
  16. vTaskDelay(30000 / portTICK_PERIOD_MS); \
  17. abort(); \
  18. } \
  19. } while (0)
  20. #else
  21. #error CHECK macro already defined
  22. #endif
  23. #ifndef ABORT
  24. #define ABORT(msg) do { \
  25. ESP_LOGE("ABORT", msg); \
  26. ESP_LOGE("ABORT", "aborting in 30 seconds..."); \
  27. vTaskDelay(30000 / portTICK_PERIOD_MS); \
  28. abort(); \
  29. } while (0)
  30. #else
  31. #error ABORT macro already defined
  32. #endif
  33. #endif