Espressif ESP32-S2 Programming Manual page 1010

Table of Contents

Advertisement

Chapter 2. API Reference
Overview
A given function can be executed with a user allocated stack space which is independent of current task stack, this
mechanism can be used to save stack space wasted by tasks which call a common function with intensive stack usage
such as printf. The given function can be called inside the shared stack space which is a callback function deferred
by calling esp_execute_shared_stack_function(), passing that function as parameter
Usage
esp_execute_shared_stack_function()
which is used to protect if the same function shares its allocated stack, a pointer to the top of stack used to that
fuction, the size in bytes of stack and, a pointer to a user function where the shared stack space will reside, after
calling the function, the user defined function will be deferred as a callback where functions can be called using the
user allocated space without taking space from current task stack.
The usage may looks like the code below:
void
external_stack_function(void)
{
printf("Executing this printf from external stack!
}
//Let's suppose we wanting to call printf using a separated stack space
//allowing app to reduce its stack size.
void
app_main()
{
//Allocate a stack buffer, from heap or as a static form:
portSTACK_TYPE *shared_stack
assert(shared_stack
//Allocate a mutex to protect its usage:
SemaphoreHandle_t printf_lock
assert(printf_lock
//Call the desired function using the macro helper:
esp_execute_shared_stack_function(printf_lock,
vSemaphoreDelete(printf_lock);
free(shared_stack);
}
API Reference
Header File
components/esp_system/include/esp_expression_with_stack.h
Functions
void
esp_execute_shared_stack_function(SemaphoreHandle_t
Calls user defined shared stack space function.
Note if either lock, stack or stack size is invalid, the expression will be called using the current stack.
Parameters
• lock: Mutex object to protect in case of shared stack
• stack: Pointer to user alocated stack
Espressif Systems
takes four arguments, a mutex object allocated by the caller,
=
malloc(8192
!=
NULL);
=
xSemaphoreCreateMutex();
!=
NULL);
shared_stack,
8192,
external_stack_function);
stack_size,
999
Submit Document Feedback
\n");
*
sizeof(portSTACK_TYPE));
lock,
void *stack,
shared_stack_function
function)
size_t
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF