mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
test/shared_stack_printf: improved printf with shared stack function test
This commit is contained in:
parent
dddcc2ede8
commit
3e9637a893
@ -8,25 +8,49 @@
|
|||||||
#include "test_utils.h"
|
#include "test_utils.h"
|
||||||
#include "esp_expression_with_stack.h"
|
#include "esp_expression_with_stack.h"
|
||||||
|
|
||||||
//makes sure this is not the task stack...
|
#define SHARED_STACK_SIZE 8192
|
||||||
|
|
||||||
|
static StackType_t *shared_stack_sp = NULL;
|
||||||
|
|
||||||
|
void external_stack_function(void)
|
||||||
|
{
|
||||||
|
printf("Executing this printf from external stack! sp=%p\n", get_sp());
|
||||||
|
shared_stack_sp = (StackType_t *)get_sp();
|
||||||
|
}
|
||||||
|
|
||||||
void another_external_stack_function(void)
|
void another_external_stack_function(void)
|
||||||
{
|
{
|
||||||
//We can even use Freertos resources inside of this context.
|
//We can even use Freertos resources inside of this context.
|
||||||
vTaskDelay(100);
|
vTaskDelay(100);
|
||||||
printf("Executing this another printf inside a function with external stack");
|
printf("Done!, sp=%p\n", get_sp());
|
||||||
|
shared_stack_sp = (StackType_t *)get_sp();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("test printf using shared buffer stack", "[newlib]")
|
TEST_CASE("test printf using shared buffer stack", "[newlib]")
|
||||||
{
|
{
|
||||||
portSTACK_TYPE *shared_stack = malloc(8192 * sizeof(portSTACK_TYPE));
|
portSTACK_TYPE *shared_stack = malloc(SHARED_STACK_SIZE);
|
||||||
|
|
||||||
TEST_ASSERT(shared_stack != NULL);
|
TEST_ASSERT(shared_stack != NULL);
|
||||||
|
|
||||||
SemaphoreHandle_t printf_lock = xSemaphoreCreateMutex();
|
SemaphoreHandle_t printf_lock = xSemaphoreCreateMutex();
|
||||||
TEST_ASSERT_NOT_NULL(printf_lock);
|
TEST_ASSERT_NOT_NULL(printf_lock);
|
||||||
|
|
||||||
ESP_EXECUTE_EXPRESSION_WITH_STACK(printf_lock, shared_stack,8192,printf("Executing this printf from external stack! \n"));
|
esp_execute_shared_stack_function(printf_lock,
|
||||||
ESP_EXECUTE_EXPRESSION_WITH_STACK(printf_lock, shared_stack,8192,another_external_stack_function());
|
shared_stack,
|
||||||
|
SHARED_STACK_SIZE,
|
||||||
|
external_stack_function);
|
||||||
|
|
||||||
|
TEST_ASSERT(((shared_stack_sp >= shared_stack_sp) &&
|
||||||
|
(shared_stack_sp < (shared_stack + SHARED_STACK_SIZE))));
|
||||||
|
|
||||||
|
esp_execute_shared_stack_function(printf_lock,
|
||||||
|
shared_stack,
|
||||||
|
SHARED_STACK_SIZE,
|
||||||
|
another_external_stack_function);
|
||||||
|
|
||||||
|
TEST_ASSERT(((shared_stack_sp >= shared_stack_sp) &&
|
||||||
|
(shared_stack_sp < (shared_stack + SHARED_STACK_SIZE))));
|
||||||
|
|
||||||
vSemaphoreDelete(printf_lock);
|
vSemaphoreDelete(printf_lock);
|
||||||
free(shared_stack);
|
free(shared_stack);
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,20 @@ esp_switch_stack_enter:
|
|||||||
esp_switch_stack_exit:
|
esp_switch_stack_exit:
|
||||||
|
|
||||||
#ifndef __XTENSA_CALL0_ABI__
|
#ifndef __XTENSA_CALL0_ABI__
|
||||||
entry sp, 0x10
|
movi a0, 0 /* no need to rotate window, it will be destroyed anyway */
|
||||||
|
movi a6, shared_stack
|
||||||
l32i a4, a2, 0 /* recover the original task stack */
|
l32i sp, a6, 0 /* load shared stack pointer */
|
||||||
mov a1, a4 /* put it on sp register again */
|
movi a12, shared_stack_callback
|
||||||
retw
|
l32i a12, a12, 0
|
||||||
|
callx4 a12 /* call user function */
|
||||||
|
movi a6, shared_stack_function_done
|
||||||
|
movi a7, 1
|
||||||
|
s32i a7, a6, 0 /* hint the function was finished */
|
||||||
|
movi a6, shared_stack_env
|
||||||
|
movi a7, 0
|
||||||
|
movi a12, longjmp
|
||||||
|
callx4 a12 /* jump to last clean state previously saved */
|
||||||
|
ret
|
||||||
#else
|
#else
|
||||||
#error "this code is written for Window ABI"
|
#error "this code is written for Window ABI"
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,7 +19,7 @@ System API
|
|||||||
High Resolution Timer <esp_timer>
|
High Resolution Timer <esp_timer>
|
||||||
:esp32: Himem (large external SPI RAM) API <himem>
|
:esp32: Himem (large external SPI RAM) API <himem>
|
||||||
:esp32: Inter-Processor Call <ipc>
|
:esp32: Inter-Processor Call <ipc>
|
||||||
Call function with external stack <esp_expression_with_stack>
|
Call function with external stack <esp_function_with_shared_stack>
|
||||||
Interrupt Allocation <intr_alloc>
|
Interrupt Allocation <intr_alloc>
|
||||||
Logging <log>
|
Logging <log>
|
||||||
Miscellaneous System APIs <system>
|
Miscellaneous System APIs <system>
|
||||||
|
Loading…
Reference in New Issue
Block a user