1 #include <stdio.h>
2 #include "sdkconfig.h"
3 #include "freertos/FreeRTOS.h"
4 #include "freertos/task.h"
5 #include "freertos/semphr.h"
6 #include "unity.h"
7 #include "test_utils.h"
8 #include "esp_rom_sys.h"
9 #include "esp_ipc_isr.h"
10
11 #ifdef CONFIG_ESP_IPC_ISR_ENABLE
12
13 void esp_test_ipc_isr_asm(void* arg);
14
15 TEST_CASE("Test ipc_isr blocking IPC function calls a ASM function", "[ipc]")
16 {
17 int val = 0x5a5a;
18 esp_ipc_isr_asm_call_blocking(esp_test_ipc_isr_asm, &val);
19 TEST_ASSERT_EQUAL_HEX(val, 0xa5a5);
20 }
21
22 void esp_test_ipc_isr_get_other_core_id(void* arg);
23
24
25 TEST_CASE("Test ipc_isr blocking IPC function calls get_other_core_id", "[ipc]")
26 {
27 int val = 0x5a5a;
28 esp_ipc_isr_asm_call_blocking(esp_test_ipc_isr_get_other_core_id, &val);
29 TEST_ASSERT_EQUAL_HEX(val, 1);
30 }
31
32 TEST_CASE("Test ipc_isr exception in asm func leads to StoreProhibited not to Unhandled debug exception", "[ipc][reset=StoreProhibited,SW_CPU_RESET]")
33 {
34 esp_ipc_isr_asm_call_blocking(esp_test_ipc_isr_asm, NULL);
35 }
36
37 void esp_test_ipc_isr_get_cycle_count_other_cpu(void* arg);
38
39 TEST_CASE("Test ipc_isr blocking IPC function calls get_cycle_count_other_cpu", "[ipc]")
40 {
41 int val = 0x5a5a;
42 esp_ipc_isr_asm_call_blocking(esp_test_ipc_isr_get_cycle_count_other_cpu, &val);
43 esp_rom_printf("CCOUNT CPU0 = %d\n", cpu_ll_get_cycle_count());
44 esp_rom_printf("CCOUNT CPU1 = %d\n", val);
45 }
46
47 static bool volatile s_stop;
48
task_asm(void * arg)49 static void task_asm(void *arg)
50 {
51 xSemaphoreHandle *sema = (xSemaphoreHandle *) arg;
52 int val;
53 int counter = 0;
54 printf("task_asm\n");
55 while (s_stop == false) {
56 val = 0x5a5a;
57 esp_ipc_isr_asm_call_blocking(esp_test_ipc_isr_asm, &val);
58 TEST_ASSERT_EQUAL_HEX(val, 0xa5a5);
59 ++counter;
60 }
61 printf("task_asm counter = %d\n", counter);
62 TEST_ASSERT_GREATER_THAN(1000000, counter);
63 xSemaphoreGive(*sema);
64 vTaskDelete(NULL);
65 }
66
67 TEST_CASE("Test ipc_isr two tasks use IPC function calls", "[ipc]")
68 {
69 xSemaphoreHandle exit_sema[2];
70 exit_sema[0] = xSemaphoreCreateBinary();
71 exit_sema[1] = xSemaphoreCreateBinary();
72 s_stop = false;
73 printf("Test start\n");
74 xTaskCreatePinnedToCore(task_asm, "task_asm", 2048, &exit_sema[0], UNITY_FREERTOS_PRIORITY - 1, NULL, 0);
75 xTaskCreatePinnedToCore(task_asm, "task_asm", 2048, &exit_sema[1], UNITY_FREERTOS_PRIORITY - 1, NULL, 1);
76 vTaskDelay(5000 / portTICK_PERIOD_MS);
77 s_stop = true;
78 xSemaphoreTake(exit_sema[0], portMAX_DELAY);
79 xSemaphoreTake(exit_sema[1], portMAX_DELAY);
80 printf("Test end\n");
81
82 vSemaphoreDelete(exit_sema[0]);
83 vSemaphoreDelete(exit_sema[1]);
84 }
85 #endif /* CONFIG_ESP_IPC_ISR_ENABLE */
86