esp_ipc.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #pragma once
  14. #include <esp_err.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #if !defined(CONFIG_FREERTOS_UNICORE) || defined(CONFIG_APPTRACE_GCOV_ENABLE)
  19. /*
  20. * Inter-processor call APIs
  21. *
  22. * FreeRTOS provides several APIs which can be used to communicate between different tasks, including tasks running on
  23. * different CPUs. This module provides additional APIs to run some code on the other CPU. These APIs can only be used
  24. * when FreeRTOS scheduler is running.
  25. */
  26. /**
  27. * @brief IPC Callback
  28. *
  29. * A callback of this type should be provided as an argument when calling esp_ipc_call() or esp_ipc_call_blocking().
  30. */
  31. typedef void (*esp_ipc_func_t)(void* arg);
  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. * @brief Execute a callback on a given CPU until and block until it completes
  56. *
  57. * This function is identical to esp_ipc_call() except that this function will block until the execution of the callback
  58. * completes.
  59. *
  60. * @note In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
  61. *
  62. * @param[in] cpu_id CPU where the given function should be executed (0 or 1)
  63. * @param[in] func Pointer to a function of type void func(void* arg) to be executed
  64. * @param[in] arg Arbitrary argument of type void* to be passed into the function
  65. *
  66. * @return
  67. * - ESP_ERR_INVALID_ARG if cpu_id is invalid
  68. * - ESP_ERR_INVALID_STATE if the FreeRTOS scheduler is not running
  69. * - ESP_OK otherwise
  70. */
  71. esp_err_t esp_ipc_call_blocking(uint32_t cpu_id, esp_ipc_func_t func, void* arg);
  72. #endif // !defined(CONFIG_FREERTOS_UNICORE) || defined(CONFIG_APPTRACE_GCOV_ENABLE)
  73. #ifdef __cplusplus
  74. }
  75. #endif