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