1 /*
2  * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include <esp_err.h>
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #if !defined(CONFIG_FREERTOS_UNICORE) || defined(CONFIG_APPTRACE_GCOV_ENABLE)
16 
17 /*
18  * Inter-processor call APIs
19  *
20  * FreeRTOS provides several APIs which can be used to communicate between different tasks, including tasks running on
21  * different CPUs. This module provides additional APIs to run some code on the other CPU. These APIs can only be used
22  * when FreeRTOS scheduler is running.
23  */
24 
25 /**
26  * @brief IPC Callback
27  *
28  * A callback of this type should be provided as an argument when calling esp_ipc_call() or esp_ipc_call_blocking().
29  */
30 typedef void (*esp_ipc_func_t)(void* arg);
31 
32 /**
33  * @brief Execute a callback on a given CPU
34  *
35  * Execute a given callback on a particular CPU. The callback must be of type "esp_ipc_func_t" and will be invoked in
36  * the context of the target CPU's IPC task.
37  *
38  * - This function will block the target CPU's IPC task has begun execution of the callback
39  * - If another IPC call is ongoing, this function will block until the ongoing IPC call completes
40  * - The stack size of the IPC task can be configured via the CONFIG_ESP_IPC_TASK_STACK_SIZE option
41  *
42  * @note In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
43  *
44  * @param[in]   cpu_id  CPU where the given function should be executed (0 or 1)
45  * @param[in]   func    Pointer to a function of type void func(void* arg) to be executed
46  * @param[in]   arg     Arbitrary argument of type void* to be passed into the function
47  *
48  * @return
49  *      - ESP_ERR_INVALID_ARG if cpu_id is invalid
50  *      - ESP_ERR_INVALID_STATE if the FreeRTOS scheduler is not running
51  *      - ESP_OK otherwise
52  */
53 esp_err_t esp_ipc_call(uint32_t cpu_id, esp_ipc_func_t func, void* arg);
54 
55 
56 /**
57  * @brief Execute a callback on a given CPU until and block until it completes
58  *
59  * This function is identical to esp_ipc_call() except that this function will block until the execution of the callback
60  * completes.
61  *
62  * @note    In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
63  *
64  * @param[in]   cpu_id  CPU where the given function should be executed (0 or 1)
65  * @param[in]   func    Pointer to a function of type void func(void* arg) to be executed
66  * @param[in]   arg     Arbitrary argument of type void* to be passed into the function
67  *
68  * @return
69  *      - ESP_ERR_INVALID_ARG if cpu_id is invalid
70  *      - ESP_ERR_INVALID_STATE if the FreeRTOS scheduler is not running
71  *      - ESP_OK otherwise
72  */
73 esp_err_t esp_ipc_call_blocking(uint32_t cpu_id, esp_ipc_func_t func, void* arg);
74 
75 #endif // !defined(CONFIG_FREERTOS_UNICORE) || defined(CONFIG_APPTRACE_GCOV_ENABLE)
76 
77 #ifdef __cplusplus
78 }
79 #endif
80