test_freertos_isinisrcontext.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. See if xPortInIsrContext works
  3. */
  4. #include <esp_types.h>
  5. #include <stdio.h>
  6. #include "sdkconfig.h"
  7. #include "freertos/FreeRTOS.h"
  8. #include "freertos/task.h"
  9. #include "freertos/semphr.h"
  10. #include "freertos/queue.h"
  11. #include "unity.h"
  12. #include "esp_intr_alloc.h"
  13. #include "esp_rom_sys.h"
  14. #include "esp_freertos_hooks.h"
  15. #if CONFIG_FREERTOS_CORETIMER_0
  16. static volatile int in_int_context, int_handled;
  17. static void testint(void)
  18. {
  19. esp_rom_printf("INT!\n");
  20. if (xPortInIsrContext()) {
  21. in_int_context++;
  22. }
  23. int_handled++;
  24. }
  25. static void testthread(void *arg)
  26. {
  27. in_int_context = 0;
  28. int_handled = 0;
  29. TEST_ASSERT(!xPortInIsrContext());
  30. esp_err_t err = esp_register_freertos_tick_hook_for_cpu(testint, xPortGetCoreID());
  31. TEST_ASSERT_EQUAL_HEX32(ESP_OK, err);
  32. vTaskDelay(100 / portTICK_PERIOD_MS);
  33. TEST_ASSERT(int_handled);
  34. TEST_ASSERT(in_int_context);
  35. esp_deregister_freertos_tick_hook_for_cpu(testint, xPortGetCoreID());
  36. vTaskDelete(NULL);
  37. }
  38. TEST_CASE("xPortInIsrContext test", "[freertos]")
  39. {
  40. xTaskCreatePinnedToCore(testthread, "tst", 4096, NULL, 3, NULL, 0);
  41. vTaskDelay(150 / portTICK_PERIOD_MS);
  42. #if portNUM_PROCESSORS == 2
  43. xTaskCreatePinnedToCore(testthread, "tst", 4096, NULL, 3, NULL, 1);
  44. vTaskDelay(150 / portTICK_PERIOD_MS);
  45. #endif
  46. }
  47. #endif