tools.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #ifndef QUOTE
  15. #define QUOTE(name) #name
  16. #endif
  17. #ifndef STR
  18. #define STR(macro) QUOTE(macro)
  19. #endif
  20. #ifndef STR_OR_ALT
  21. #define STR_OR_ALT(str,alt) (str?str:alt)
  22. #endif
  23. #ifndef STR_OR_BLANK
  24. #define STR_OR_BLANK(p) p == NULL ? "" : p
  25. #endif
  26. #define ESP_LOG_DEBUG_EVENT(tag,e) ESP_LOGD(tag,"evt: " e)
  27. #ifndef FREE_AND_NULL
  28. #define FREE_AND_NULL(x) if(x) { free(x); x=NULL; }
  29. #endif
  30. #ifndef CASE_TO_STR
  31. #define CASE_TO_STR(x) case x: return STR(x); break;
  32. #endif
  33. #define ENUM_TO_STRING(g) \
  34. case g: \
  35. return STR(g); \
  36. break;
  37. void utf8_decode(char *src);
  38. void url_decode(char *url);
  39. void* malloc_init_external(size_t sz);
  40. void* clone_obj_psram(void * source, size_t source_sz);
  41. char* strdup_psram(const char * source);
  42. const char* str_or_unknown(const char * str);
  43. const char* str_or_null(const char * str);
  44. typedef void (*http_download_cb_t)(uint8_t* data, size_t len, void *context);
  45. void http_download(char *url, size_t max, http_download_cb_t callback, void *context);
  46. /* Use these to dynamically create tasks whose stack is on EXTRAM. Be aware that it
  47. * requires configNUM_THREAD_LOCAL_STORAGE_POINTERS to bet set to 2 at least (index 0
  48. * is used by pthread and this uses index 1, obviously
  49. */
  50. BaseType_t xTaskCreateEXTRAM( TaskFunction_t pvTaskCode,
  51. const char * const pcName,
  52. configSTACK_DEPTH_TYPE usStackDepth,
  53. void *pvParameters,
  54. UBaseType_t uxPriority,
  55. TaskHandle_t *pxCreatedTask);
  56. void vTaskDeleteEXTRAM(TaskHandle_t xTask);
  57. extern const char unknown_string_placeholder[];
  58. #ifdef __cplusplus
  59. }
  60. #endif