esp_ipc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef __ESP_IPC_H__
  14. #define __ESP_IPC_H__
  15. #include <esp_err.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /** @cond */
  20. typedef void (*esp_ipc_func_t)(void* arg);
  21. /** @endcond */
  22. /*
  23. * Inter-processor call APIs
  24. *
  25. * FreeRTOS provides several APIs which can be used to communicate between
  26. * different tasks, including tasks running on different CPUs.
  27. * This module provides additional APIs to run some code on the other CPU.
  28. *
  29. * These APIs can only be used when FreeRTOS scheduler is running.
  30. */
  31. /**
  32. * @brief Execute a function on the given CPU
  33. *
  34. * Run a given function on a particular CPU. The given function must accept a
  35. * void* argument and return void. The given function is run in the context of
  36. * the IPC task of the CPU specified by the cpu_id parameter. The calling task
  37. * will be blocked until the IPC task begins executing the given function. If
  38. * another IPC call is ongoing, the calling task will block until the other IPC
  39. * call completes. The stack size allocated for the IPC task can be configured
  40. * in the "Inter-Processor Call (IPC) task stack size" setting in menuconfig.
  41. * Increase this setting if the given function requires more stack than default.
  42. *
  43. * @note In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
  44. *
  45. * @param[in] cpu_id CPU where the given function should be executed (0 or 1)
  46. * @param[in] func Pointer to a function of type void func(void* arg) to be executed
  47. * @param[in] arg Arbitrary argument of type void* to be passed into the function
  48. *
  49. * @return
  50. * - ESP_ERR_INVALID_ARG if cpu_id is invalid
  51. * - ESP_ERR_INVALID_STATE if the FreeRTOS scheduler is not running
  52. * - ESP_OK otherwise
  53. */
  54. esp_err_t esp_ipc_call(uint32_t cpu_id, esp_ipc_func_t func, void* arg);
  55. /**
  56. * @brief Execute a function on the given CPU and blocks until it completes
  57. *
  58. * Run a given function on a particular CPU. The given function must accept a
  59. * void* argument and return void. The given function is run in the context of
  60. * the IPC task of the CPU specified by the cpu_id parameter. The calling task
  61. * will be blocked until the IPC task completes execution of the given function.
  62. * If another IPC call is ongoing, the calling task will block until the other
  63. * IPC call completes. The stack size allocated for the IPC task can be
  64. * configured in the "Inter-Processor Call (IPC) task stack size" setting in
  65. * menuconfig. Increase this setting if the given function requires more stack
  66. * than default.
  67. *
  68. * @note In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
  69. *
  70. * @param[in] cpu_id CPU where the given function should be executed (0 or 1)
  71. * @param[in] func Pointer to a function of type void func(void* arg) to be executed
  72. * @param[in] arg Arbitrary argument of type void* to be passed into the function
  73. *
  74. * @return
  75. * - ESP_ERR_INVALID_ARG if cpu_id is invalid
  76. * - ESP_ERR_INVALID_STATE if the FreeRTOS scheduler is not running
  77. * - ESP_OK otherwise
  78. */
  79. esp_err_t esp_ipc_call_blocking(uint32_t cpu_id, esp_ipc_func_t func, void* arg);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif /* __ESP_IPC_H__ */