Skip to content

Commit 7109c7b

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'feature/ipc_allows_recursion_calls_v5.5' into 'release/v5.5'
feat(ipc): Allow IPC recursion calls in esp_ipc_call (v5.5) See merge request espressif/esp-idf!41938
2 parents fba0edd + 37ebf67 commit 7109c7b

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

components/esp_system/esp_ipc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,14 @@ static esp_err_t esp_ipc_call_and_wait(uint32_t cpu_id, esp_ipc_func_t func, voi
130130
return ESP_ERR_INVALID_STATE;
131131
}
132132

133-
#ifdef CONFIG_ESP_IPC_USES_CALLERS_PRIORITY
134133
TaskHandle_t task_handler = xTaskGetCurrentTaskHandle();
134+
// It checks the recursion call: esp_ipc_call_... -> ipc_task -> esp_ipc_call_...
135+
if (task_handler == s_ipc_task_handle[cpu_id]) {
136+
// If the caller task is already the ipc_task, we can run the callback function immediately
137+
func(arg);
138+
return ESP_OK;
139+
}
140+
#ifdef CONFIG_ESP_IPC_USES_CALLERS_PRIORITY
135141
UBaseType_t priority_of_current_task = uxTaskPriorityGet(task_handler);
136142
UBaseType_t priority_of_running_ipc_task = uxTaskPriorityGet(s_ipc_task_handle[cpu_id]);
137143
if (priority_of_running_ipc_task < priority_of_current_task) {

components/esp_system/test_apps/esp_system_unity_tests/main/test_ipc.c

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -209,4 +209,83 @@ TEST_CASE("Test ipc call nonblocking when FreeRTOS Scheduler is suspended", "[ip
209209
xTaskResumeAll();
210210
#endif
211211
}
212+
213+
static void test_func_ipc_cb5(void *arg)
214+
{
215+
static int recursion_count = 0;
216+
int cpu = ((recursion_count++) >> 1) & 1;
217+
esp_rom_printf("ipc_task(%d) -> esp_ipc_call(%d) -> test_func_ipc_cb4\n", cpu, cpu);
218+
esp_ipc_call(cpu, test_func_ipc_cb4, arg);
219+
}
220+
221+
static void test_func_ipc_cb6(void *arg)
222+
{
223+
static int recursion_count = 0;
224+
int cpu = ((recursion_count++) >> 1) & 1;
225+
esp_rom_printf("ipc_task(%d) -> esp_ipc_call_blocking(%d) -> test_func_ipc_cb4\n", cpu, cpu);
226+
esp_ipc_call_blocking(cpu, test_func_ipc_cb4, arg);
227+
}
228+
229+
TEST_CASE("Test recursion IPC call", "[ipc]")
230+
{
231+
int val;
232+
esp_rom_printf("esp_ipc_call -> esp_ipc_call:\n");
233+
/*
234+
esp_ipc_call(0) -> test_func_ipc_cb5 -> ipc_task(0) -> esp_ipc_call(0) -> test_func_ipc_cb4
235+
esp_ipc_call(1) -> test_func_ipc_cb5 -> ipc_task(0) -> esp_ipc_call(0) -> test_func_ipc_cb4
236+
esp_ipc_call(0) -> test_func_ipc_cb5 -> ipc_task(1) -> esp_ipc_call(1) -> test_func_ipc_cb4
237+
esp_ipc_call(1) -> test_func_ipc_cb5 -> ipc_task(1) -> esp_ipc_call(1) -> test_func_ipc_cb4
238+
*/
239+
for (int cpu = 0; cpu < CONFIG_FREERTOS_NUMBER_OF_CORES * 2; ++cpu) {
240+
val = 0x5a5a;
241+
esp_rom_printf("esp_ipc_call(%d) -> test_func_ipc_cb5 -> ", cpu % CONFIG_FREERTOS_NUMBER_OF_CORES);
242+
esp_ipc_call(cpu % CONFIG_FREERTOS_NUMBER_OF_CORES, test_func_ipc_cb5, &val);
243+
vTaskDelay(10 / portTICK_PERIOD_MS);
244+
TEST_ASSERT_EQUAL_HEX(val, 0x5a5a + 1);
245+
}
246+
247+
esp_rom_printf("esp_ipc_call_blocking -> esp_ipc_call test:\n");
248+
/*
249+
esp_ipc_call_blocking(0) -> test_func_ipc_cb5 -> ipc_task(0) -> esp_ipc_call(0) -> test_func_ipc_cb4
250+
esp_ipc_call_blocking(1) -> test_func_ipc_cb5 -> ipc_task(0) -> esp_ipc_call(0) -> test_func_ipc_cb4
251+
esp_ipc_call_blocking(0) -> test_func_ipc_cb5 -> ipc_task(1) -> esp_ipc_call(1) -> test_func_ipc_cb4
252+
esp_ipc_call_blocking(1) -> test_func_ipc_cb5 -> ipc_task(1) -> esp_ipc_call(1) -> test_func_ipc_cb4
253+
*/
254+
for (int cpu = 0; cpu < CONFIG_FREERTOS_NUMBER_OF_CORES * 2; ++cpu) {
255+
val = 0xa5a5;
256+
esp_rom_printf("esp_ipc_call_blocking(%d) -> test_func_ipc_cb5 -> ", cpu % CONFIG_FREERTOS_NUMBER_OF_CORES);
257+
esp_ipc_call_blocking(cpu % CONFIG_FREERTOS_NUMBER_OF_CORES, test_func_ipc_cb5, &val);
258+
TEST_ASSERT_EQUAL_HEX(val, 0xa5a5 + 1);
259+
}
260+
261+
esp_rom_printf("esp_ipc_call -> esp_ipc_call_blocking:\n");
262+
/*
263+
esp_ipc_call(0) -> test_func_ipc_cb6 -> ipc_task(0) -> esp_ipc_call_blocking(0) -> test_func_ipc_cb4
264+
esp_ipc_call(1) -> test_func_ipc_cb6 -> ipc_task(0) -> esp_ipc_call_blocking(0) -> test_func_ipc_cb4
265+
esp_ipc_call(0) -> test_func_ipc_cb6 -> ipc_task(1) -> esp_ipc_call_blocking(1) -> test_func_ipc_cb4
266+
esp_ipc_call(1) -> test_func_ipc_cb6 -> ipc_task(1) -> esp_ipc_call_blocking(1) -> test_func_ipc_cb4
267+
*/
268+
for (int cpu = 0; cpu < CONFIG_FREERTOS_NUMBER_OF_CORES * 2; ++cpu) {
269+
val = 0x5a5a;
270+
esp_rom_printf("esp_ipc_call(%d) -> test_func_ipc_cb6 -> ", cpu % CONFIG_FREERTOS_NUMBER_OF_CORES);
271+
esp_ipc_call(cpu % CONFIG_FREERTOS_NUMBER_OF_CORES, test_func_ipc_cb6, &val);
272+
vTaskDelay(10 / portTICK_PERIOD_MS);
273+
TEST_ASSERT_EQUAL_HEX(val, 0x5a5a + 1);
274+
}
275+
276+
esp_rom_printf("esp_ipc_call_blocking -> esp_ipc_call_blocking test:\n");
277+
/*
278+
esp_ipc_call_blocking(0) -> test_func_ipc_cb6 -> ipc_task(0) -> esp_ipc_call_blocking(0) -> test_func_ipc_cb4
279+
esp_ipc_call_blocking(1) -> test_func_ipc_cb6 -> ipc_task(0) -> esp_ipc_call_blocking(0) -> test_func_ipc_cb4
280+
esp_ipc_call_blocking(0) -> test_func_ipc_cb6 -> ipc_task(1) -> esp_ipc_call_blocking(1) -> test_func_ipc_cb4
281+
esp_ipc_call_blocking(1) -> test_func_ipc_cb6 -> ipc_task(1) -> esp_ipc_call_blocking(1) -> test_func_ipc_cb4
282+
*/
283+
for (int cpu = 0; cpu < CONFIG_FREERTOS_NUMBER_OF_CORES * 2; ++cpu) {
284+
val = 0xa5a5;
285+
esp_rom_printf("esp_ipc_call_blocking(%d) -> test_func_ipc_cb6 -> ", cpu % CONFIG_FREERTOS_NUMBER_OF_CORES);
286+
esp_ipc_call_blocking(cpu % CONFIG_FREERTOS_NUMBER_OF_CORES, test_func_ipc_cb6, &val);
287+
TEST_ASSERT_EQUAL_HEX(val, 0xa5a5 + 1);
288+
}
289+
}
290+
212291
#endif /* !CONFIG_FREERTOS_UNICORE */

0 commit comments

Comments
 (0)