Skip to content

Commit a700035

Browse files
Felipe Nevesespressif-bot
authored andcommitted
test/shared_stack_printf: improved printf with shared stack function test
1 parent 938a737 commit a700035

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

components/newlib/test/test_shared_stack_printf.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
#include "test_utils.h"
99
#include "esp_expression_with_stack.h"
1010

11+
#define SHARED_STACK_SIZE 8192
12+
13+
static StackType_t *shared_stack_sp = NULL;
14+
1115
void external_stack_function(void)
1216
{
1317
printf("Executing this printf from external stack! sp=%p\n", get_sp());
18+
shared_stack_sp = (StackType_t *)get_sp();
1419
}
1520

1621
void another_external_stack_function(void)
@@ -19,11 +24,12 @@ void another_external_stack_function(void)
1924
printf("We can even use FreeRTOS resources delaying..., sp=%p\n", get_sp());
2025
vTaskDelay(100);
2126
printf("Done!, sp=%p\n", get_sp());
27+
shared_stack_sp = (StackType_t *)get_sp();
2228
}
2329

2430
TEST_CASE("test printf using shared buffer stack", "[newlib]")
2531
{
26-
portSTACK_TYPE *shared_stack = malloc(8192);
32+
portSTACK_TYPE *shared_stack = malloc(SHARED_STACK_SIZE);
2733

2834
TEST_ASSERT(shared_stack != NULL);
2935

@@ -32,8 +38,22 @@ TEST_CASE("test printf using shared buffer stack", "[newlib]")
3238
printf("SP: %p\n", get_sp());
3339
printf("shared_stack: %p\n", (void *)shared_stack);
3440

35-
esp_execute_shared_stack_function(printf_lock, shared_stack,8192,external_stack_function);
36-
esp_execute_shared_stack_function(printf_lock, shared_stack,8192,another_external_stack_function);
41+
esp_execute_shared_stack_function(printf_lock,
42+
shared_stack,
43+
SHARED_STACK_SIZE,
44+
external_stack_function);
45+
46+
TEST_ASSERT(((shared_stack_sp >= shared_stack_sp) &&
47+
(shared_stack_sp < (shared_stack + SHARED_STACK_SIZE))));
48+
49+
esp_execute_shared_stack_function(printf_lock,
50+
shared_stack,
51+
SHARED_STACK_SIZE,
52+
another_external_stack_function);
53+
54+
TEST_ASSERT(((shared_stack_sp >= shared_stack_sp) &&
55+
(shared_stack_sp < (shared_stack + SHARED_STACK_SIZE))));
56+
3757
vSemaphoreDelete(printf_lock);
3858
free(shared_stack);
3959
}

components/xtensa/expression_with_stack_xtensa_asm.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ esp_shared_stack_invoke_function:
3939
movi a7, 1
4040
s32i a7, a6, 0 /* hint the function was finished */
4141
movi a6, shared_stack_env
42-
movi a7, 0
43-
call4 longjmp /* jump to last clean state previously saved */
42+
movi a7, 0
43+
movi a12, longjmp
44+
callx4 a12 /* jump to last clean state previously saved */
4445
ret
4546
#else
4647
#error "this code is written for Window ABI"

docs/en/api-reference/system/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ System API
1919
High Resolution Timer <esp_timer>
2020
:esp32: Himem (large external SPI RAM) API <himem>
2121
:esp32: Inter-Processor Call <ipc>
22-
Call function with external stack <esp_expression_with_stack>
22+
Call function with external stack <esp_function_with_shared_stack>
2323
Interrupt Allocation <intr_alloc>
2424
Logging <log>
2525
Miscellaneous System APIs <system>

0 commit comments

Comments
 (0)