tools.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Tools
  3. *
  4. * Philippe G. 2019, philippe_44@outlook.com
  5. *
  6. * This software is released under the MIT License.
  7. * https://opensource.org/licenses/MIT
  8. *
  9. */
  10. #pragma once
  11. #include "freertos/FreeRTOS.h"
  12. #include "freertos/task.h"
  13. #include "cJSON.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #ifndef QUOTE
  18. #define QUOTE(name) #name
  19. #endif
  20. #ifndef STR
  21. #define STR(macro) QUOTE(macro)
  22. #endif
  23. #ifndef STR_OR_ALT
  24. #define STR_OR_ALT(str,alt) (str?str:alt)
  25. #endif
  26. #ifndef STR_OR_BLANK
  27. #define STR_OR_BLANK(p) p == NULL ? "" : p
  28. #endif
  29. #define ESP_LOG_DEBUG_EVENT(tag,e) ESP_LOGD(tag,"evt: " e)
  30. #ifndef FREE_AND_NULL
  31. #define FREE_AND_NULL(x) if(x) { free(x); x=NULL; }
  32. #endif
  33. #ifndef CASE_TO_STR
  34. #define CASE_TO_STR(x) case x: return STR(x); break;
  35. #endif
  36. #define ENUM_TO_STRING(g) \
  37. case g: \
  38. return STR(g); \
  39. break;
  40. void utf8_decode(char *src);
  41. void url_decode(char *url);
  42. void* malloc_init_external(size_t sz);
  43. void* clone_obj_psram(void * source, size_t source_sz);
  44. char* strdup_psram(const char * source);
  45. const char* str_or_unknown(const char * str);
  46. const char* str_or_null(const char * str);
  47. void dump_json_content(const char* prefix, cJSON* json, int level);
  48. #ifndef gettime_ms
  49. // body is provided somewhere else...
  50. uint32_t _gettime_ms_(void);
  51. #define gettime_ms _gettime_ms_
  52. #endif
  53. typedef void (*http_download_cb_t)(uint8_t* data, size_t len, void *context);
  54. void http_download(char *url, size_t max, http_download_cb_t callback, void *context);
  55. /* Use these to dynamically create tasks whose stack is on EXTRAM. Be aware that it
  56. * requires configNUM_THREAD_LOCAL_STORAGE_POINTERS to bet set to 2 at least (index 0
  57. * is used by pthread and this uses index 1, obviously
  58. */
  59. BaseType_t xTaskCreateEXTRAM( TaskFunction_t pvTaskCode,
  60. const char * const pcName,
  61. configSTACK_DEPTH_TYPE usStackDepth,
  62. void *pvParameters,
  63. UBaseType_t uxPriority,
  64. TaskHandle_t *pxCreatedTask);
  65. void vTaskDeleteEXTRAM(TaskHandle_t xTask);
  66. extern const char unknown_string_placeholder[];
  67. #ifdef __cplusplus
  68. }
  69. #endif