esp_expression_with_stack: added watchpoint on stack parameter before use it

This commit is contained in:
Felipe Neves
2019-11-26 16:31:56 -03:00
parent 88dd15c806
commit 5e18cd4e13
2 changed files with 16 additions and 6 deletions

View File

@@ -17,22 +17,32 @@
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "esp_debug_helpers.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 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
*/
#define ESP_EXECUTE_EXPRESSION_WITH_STACK(lock, stack, expression) \
#define ESP_EXECUTE_EXPRESSION_WITH_STACK(lock, stack, stack_size, expression) \
({ \
if(lock) { \
if(lock && stack && stack_size) { \
uint32_t backup; \
int watchpoint_place=(int)stack; \
portSTACK_TYPE *top_of_stack = &stack[0] + \
(sizeof(stack_size * sizeof(portSTACK_TYPE)) / \
sizeof(portSTACK_TYPE)); \
watchpoint_place=(watchpoint_place+31)&(~31); \
xSemaphoreTake(lock, portMAX_DELAY); \
esp_switch_stack_enter(stack, &backup); \
esp_set_watchpoint(2, (char*)watchpoint_place, 32, ESP_WATCHPOINT_STORE);\
esp_switch_stack_enter(top_of_stack, &backup); \
{ \
expression; \
} \
esp_clear_watchpoint(2); \
esp_switch_stack_exit(&backup); \
xSemaphoreGive(lock); \
} \