2019-11-15 03:07:57 -05:00
|
|
|
#include <stdio.h>
|
2020-01-06 15:28:37 -05:00
|
|
|
#include <string.h>
|
2019-11-15 03:07:57 -05:00
|
|
|
#include "unity.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "freertos/semphr.h"
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#include "test_utils.h"
|
|
|
|
#include "esp_expression_with_stack.h"
|
|
|
|
|
2020-03-31 12:58:02 -04:00
|
|
|
#define SHARED_STACK_SIZE 8192
|
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
static StackType_t *shared_stack_sp = NULL;
|
2020-03-31 12:58:02 -04:00
|
|
|
|
2020-03-12 01:59:53 -04:00
|
|
|
void external_stack_function(void)
|
|
|
|
{
|
|
|
|
printf("Executing this printf from external stack! sp=%p\n", get_sp());
|
2020-03-31 12:58:02 -04:00
|
|
|
shared_stack_sp = (StackType_t *)get_sp();
|
2020-03-12 01:59:53 -04:00
|
|
|
}
|
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
void another_external_stack_function(void)
|
2019-11-15 03:07:57 -05:00
|
|
|
{
|
2019-12-04 09:25:02 -05:00
|
|
|
//We can even use Freertos resources inside of this context.
|
2020-04-01 11:10:13 -04:00
|
|
|
printf("We can even use FreeRTOS resources... yielding, sp=%p\n", get_sp());
|
|
|
|
taskYIELD();
|
2020-03-31 12:58:02 -04:00
|
|
|
shared_stack_sp = (StackType_t *)get_sp();
|
2019-11-15 03:07:57 -05:00
|
|
|
}
|
|
|
|
|
2020-12-22 03:46:38 -05:00
|
|
|
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C3)
|
|
|
|
|
2019-11-15 03:07:57 -05:00
|
|
|
TEST_CASE("test printf using shared buffer stack", "[newlib]")
|
|
|
|
{
|
2020-03-31 12:58:02 -04:00
|
|
|
portSTACK_TYPE *shared_stack = malloc(SHARED_STACK_SIZE);
|
2019-11-15 03:45:18 -05:00
|
|
|
|
2020-04-01 11:10:13 -04:00
|
|
|
TEST_ASSERT_NOT_NULL(shared_stack);
|
2019-11-15 03:45:18 -05:00
|
|
|
|
2019-11-15 03:07:57 -05:00
|
|
|
SemaphoreHandle_t printf_lock = xSemaphoreCreateMutex();
|
2019-12-20 11:27:30 -05:00
|
|
|
TEST_ASSERT_NOT_NULL(printf_lock);
|
2020-04-01 11:10:13 -04:00
|
|
|
printf("current task sp: %p\n", get_sp());
|
2020-03-12 01:59:53 -04:00
|
|
|
printf("shared_stack: %p\n", (void *)shared_stack);
|
2020-04-01 11:10:13 -04:00
|
|
|
printf("shared_stack expected top: %p\n", (void *)(shared_stack + SHARED_STACK_SIZE));
|
|
|
|
|
2019-12-20 11:27:30 -05:00
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
esp_execute_shared_stack_function(printf_lock,
|
2020-03-31 12:58:02 -04:00
|
|
|
shared_stack,
|
|
|
|
SHARED_STACK_SIZE,
|
|
|
|
external_stack_function);
|
2020-11-10 02:40:01 -05:00
|
|
|
|
|
|
|
TEST_ASSERT(((shared_stack_sp >= shared_stack) &&
|
2020-03-31 12:58:02 -04:00
|
|
|
(shared_stack_sp < (shared_stack + SHARED_STACK_SIZE))));
|
2020-11-10 02:40:01 -05:00
|
|
|
|
|
|
|
esp_execute_shared_stack_function(printf_lock,
|
2020-03-31 12:58:02 -04:00
|
|
|
shared_stack,
|
|
|
|
SHARED_STACK_SIZE,
|
2020-11-10 02:40:01 -05:00
|
|
|
another_external_stack_function);
|
|
|
|
|
|
|
|
TEST_ASSERT(((shared_stack_sp >= shared_stack) &&
|
2020-03-31 12:58:02 -04:00
|
|
|
(shared_stack_sp < (shared_stack + SHARED_STACK_SIZE))));
|
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
vSemaphoreDelete(printf_lock);
|
2019-11-15 03:45:18 -05:00
|
|
|
free(shared_stack);
|
2019-11-15 03:07:57 -05:00
|
|
|
}
|
2020-12-22 03:46:38 -05:00
|
|
|
|
|
|
|
#endif
|