esp_common/shared_stack: modifed the stack switch procedure to a simpler way

esp_common/shared_stack: refactored the implemenation of shared stack function (still not working properly)

esp_expression_with_stack: refactored the shared stack function calling mechanism and updated the documentation
This commit is contained in:
Felipe Neves
2020-03-12 02:59:53 -03:00
committed by bot
parent 1fa7454f5e
commit 938a73756c
8 changed files with 110 additions and 104 deletions

View File

@@ -13,6 +13,7 @@
// limitations under the License.
#pragma once
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
@@ -23,56 +24,25 @@
extern "C" {
#endif
typedef void (*shared_stack_function)(void);
#define ESP_EXECUTE_EXPRESSION_WITH_STACK(lock, stack, stack_size, expression) \
esp_execute_shared_stack_function(lock, stack, stack_size, expression)
/**
* @brief Executes a 1-line expression with a application alocated stack
* @brief Calls user defined shared stack space function
* @param lock Mutex object to protect in case of shared stack
* @param stack Pointer to user alocated stack
* @param stack_size Size of current stack in bytes
* @param expression Expression or function to be executed using the stack
* @param function pointer to the shared stack function to be executed
* @note if either lock, stack or stack size is invalid, the expression will
* be called using the current stack.
*/
#define ESP_EXECUTE_EXPRESSION_WITH_STACK(lock, stack, stack_size, expression) \
({ \
assert(lock && stack && (stack_size >= CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE)); \
uint32_t backup; \
xSemaphoreTake(lock, portMAX_DELAY); \
StackType_t *top_of_stack = esp_switch_stack_setup(stack, stack_size); \
esp_switch_stack_enter(top_of_stack, &backup); \
{ \
expression; \
} \
esp_switch_stack_exit(&backup); \
StaticTask_t *current = (StaticTask_t *)xTaskGetCurrentTaskHandle(); \
/* pxDummy6 is the stack base of current thread defined in TCB_t */ \
/* place the watchpoint on current task stack after function execution*/ \
vPortSetStackWatchpoint(current->pxDummy6); \
xSemaphoreGive(lock); \
})
void esp_execute_shared_stack_function(SemaphoreHandle_t lock,
void *stack,
size_t stack_size,
shared_stack_function function);
/**
* @brief Fill stack frame with CPU-specifics value before use
* @param stack Caller allocated stack pointer
* @param stack_size Size of stack in bytes
* @return New pointer to the top of stack
* @note Application must not call this function directly
*/
StackType_t * esp_switch_stack_setup(StackType_t *stack, size_t stack_size);
/**
* @brief Changes CPU sp-register to use another stack space and save the previous one
* @param stack Caller allocated stack pointer
* @param backup_stack Pointer to a place to save the current stack
* @note Application must not call this function directly
*/
extern void esp_switch_stack_enter(StackType_t *stack, uint32_t *backup_stack);
/**
* @brief Restores the previous CPU sp-register
* @param backup_stack Pointer to the place where stack was saved
* @note Application must not call this function directly
*/
extern void esp_switch_stack_exit(uint32_t *backup_stack);
#ifdef __cplusplus
}