main.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Unlicense OR CC0-1.0
  5. */
  6. /*
  7. * This test checks that there are no orphan watchpoints are left on temporary stacks used by
  8. * esp_execute_shared_stack_function().
  9. */
  10. #include <assert.h>
  11. #include <stdio.h>
  12. #include "esp_expression_with_stack.h"
  13. #include "freertos/FreeRTOS.h"
  14. #include "freertos/task.h"
  15. #define TEST_TASK_STACK_SIZE 1024
  16. #define SHARED_STACK_SIZE 8192
  17. void external_stack_function(void)
  18. {
  19. printf("Executing this printf from external stack! \n");
  20. }
  21. /**
  22. * The two stacks are statically allocated so that we can later examine them and trip any potential remaining
  23. * watchpoints.
  24. */
  25. uint8_t static test_task_stack[TEST_TASK_STACK_SIZE];
  26. uint8_t static shared_stack[SHARED_STACK_SIZE];
  27. static void shared_stack_executer(void *arg)
  28. {
  29. SemaphoreHandle_t printf_lock = xSemaphoreCreateMutex();
  30. assert(printf_lock != NULL);
  31. //Call the desired function using the macro helper:
  32. esp_execute_shared_stack_function(printf_lock,
  33. shared_stack,
  34. sizeof(shared_stack),
  35. external_stack_function);
  36. vSemaphoreDelete(printf_lock);
  37. vTaskDelete(NULL);
  38. }
  39. void app_main(void)
  40. {
  41. StaticTask_t task_buffer;
  42. TaskHandle_t task_handle = xTaskCreateStatic(shared_stack_executer,
  43. "test_shared_test_task",
  44. sizeof(test_task_stack),
  45. NULL,
  46. tskIDLE_PRIORITY + 1,
  47. test_task_stack,
  48. &task_buffer);
  49. assert(task_handle);
  50. vTaskDelay(pdMS_TO_TICKS(500));
  51. // If any watchpoints have been left on the temporary stacks, we will trigger them here:
  52. for (int i = 0; i < sizeof(test_task_stack); i++) {
  53. test_task_stack[i] = 0;
  54. }
  55. for (int i = 0; i < sizeof(shared_stack); i++) {
  56. shared_stack[i] = 0;
  57. }
  58. printf("stacks clean\n");
  59. }