mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 20:21:04 +00:00
esp_common: added a macro to allow call functions using user allocated stack
This commit is contained in:
35
components/esp_common/include/esp_expression_with_stack.h
Normal file
35
components/esp_common/include/esp_expression_with_stack.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef __ESP_EXPRESSION_WITH_STACK_H
|
||||
#define __ESP_EXPRESSION_WITH_STACK_H
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
/**
|
||||
* @brief Executes a 1-line expression with a application alocated stack
|
||||
* @param lock Mutex object to protect in case of shared stack
|
||||
* @param stack Pointer to user alocated stack, it must points to its top
|
||||
* @param expression Expression or function to be executed using the stack
|
||||
*/
|
||||
#define EXECUTE_EXPRESSION_WITH_STACK(lock, stack, expression) \
|
||||
({ \
|
||||
if(lock) { \
|
||||
uint32_t backup; \
|
||||
xSemaphoreTake(lock, portMAX_DELAY); \
|
||||
switch_stack_enter(stack, &backup); \
|
||||
{ \
|
||||
expression; \
|
||||
} \
|
||||
switch_stack_exit(&backup); \
|
||||
xSemaphoreGive(lock); \
|
||||
} \
|
||||
})
|
||||
|
||||
/**
|
||||
* These functions are intended to be use by the macro above, and
|
||||
* Should never be called directly, otherwise crashes could
|
||||
* occur
|
||||
*/
|
||||
extern void switch_stack_enter(portSTACK_TYPE *stack, uint32_t *backup_stack);
|
||||
extern void switch_stack_exit(uint32_t *backup_stack);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user