test_freertos_isinisrcontext.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. See if xPortInIsrContext works
  3. */
  4. #include <esp_types.h>
  5. #include <stdio.h>
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/task.h"
  8. #include "freertos/semphr.h"
  9. #include "freertos/queue.h"
  10. #include "freertos/xtensa_api.h"
  11. #include "unity.h"
  12. #include "esp_intr_alloc.h"
  13. #include "xtensa/hal.h"
  14. static volatile int in_int_context, int_handled;
  15. static void testint(void *arg) {
  16. xthal_set_ccompare(1, xthal_get_ccount()+8000000000);
  17. ets_printf("INT!\n");
  18. if (xPortInIsrContext()) in_int_context++;
  19. int_handled++;
  20. }
  21. static void testthread(void *arg) {
  22. intr_handle_t handle;
  23. in_int_context=0;
  24. int_handled=0;
  25. TEST_ASSERT(!xPortInIsrContext());
  26. xthal_set_ccompare(1, xthal_get_ccount()+8000000);
  27. esp_err_t err = esp_intr_alloc(ETS_INTERNAL_TIMER1_INTR_SOURCE, 0, &testint, NULL, &handle);
  28. TEST_ASSERT_EQUAL_HEX32(ESP_OK, err);
  29. vTaskDelay(100 / portTICK_PERIOD_MS);
  30. TEST_ASSERT(int_handled);
  31. TEST_ASSERT(in_int_context);
  32. TEST_ASSERT_EQUAL_HEX32( ESP_OK, esp_intr_free(handle) );
  33. vTaskDelete(NULL);
  34. }
  35. TEST_CASE("xPortInIsrContext test", "[freertos]")
  36. {
  37. xTaskCreatePinnedToCore(testthread, "tst" , 4096, NULL, 3, NULL, 0);
  38. vTaskDelay(150 / portTICK_PERIOD_MS);
  39. #if portNUM_PROCESSORS == 2
  40. xTaskCreatePinnedToCore(testthread, "tst" , 4096, NULL, 3, NULL, 1);
  41. vTaskDelay(150 / portTICK_PERIOD_MS);
  42. #endif
  43. }