esp_expression_with_stack.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef __ESP_EXPRESSION_WITH_STACK_H
  2. #define __ESP_EXPRESSION_WITH_STACK_H
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/semphr.h"
  5. /**
  6. * @brief Executes a 1-line expression with a application alocated stack
  7. * @param lock Mutex object to protect in case of shared stack
  8. * @param stack Pointer to user alocated stack, it must points to its top
  9. * @param expression Expression or function to be executed using the stack
  10. */
  11. #define ESP_EXECUTE_EXPRESSION_WITH_STACK(lock, stack, expression) \
  12. ({ \
  13. if(lock) { \
  14. uint32_t backup; \
  15. xSemaphoreTake(lock, portMAX_DELAY); \
  16. esp_switch_stack_enter(stack, &backup); \
  17. { \
  18. expression; \
  19. } \
  20. esp_switch_stack_exit(&backup); \
  21. xSemaphoreGive(lock); \
  22. } \
  23. })
  24. /**
  25. * These functions are intended to be use by the macro above, and
  26. * Should never be called directly, otherwise crashes could
  27. * occur
  28. */
  29. extern void esp_switch_stack_enter(portSTACK_TYPE *stack, uint32_t *backup_stack);
  30. extern void esp_switch_stack_exit(uint32_t *backup_stack);
  31. #endif