esp_ipc.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. * Initialize inter-processor call module. This function is called automatically
  33. * on CPU start and should not be called from the application.
  34. *
  35. * This function start two tasks, one on each CPU. These tasks are started
  36. * with high priority. These tasks are normally inactive, waiting until one of
  37. * the esp_ipc_call_* functions to be used. One of these tasks will be
  38. * woken up to execute the callback provided to esp_ipc_call_nonblocking or
  39. * esp_ipc_call_blocking.
  40. */
  41. /** @cond */
  42. void esp_ipc_init();
  43. /** @endcond */
  44. /**
  45. * @brief Execute a function on the given CPU
  46. *
  47. * Run a given function on a particular CPU. The given function must accept a
  48. * void* argument and return void. The given function is run in the context of
  49. * the IPC task of the CPU specified by the cpu_id parameter. The calling task
  50. * will be blocked until the IPC task begins executing the given function. If
  51. * another IPC call is ongoing, the calling task will block until the other IPC
  52. * call completes. The stack size allocated for the IPC task can be configured
  53. * in the "Inter-Processor Call (IPC) task stack size" setting in menuconfig.
  54. * Increase this setting if the given function requires more stack than default.
  55. *
  56. * @note In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
  57. *
  58. * @param[in] cpu_id CPU where the given function should be executed (0 or 1)
  59. * @param[in] func Pointer to a function of type void func(void* arg) to be executed
  60. * @param[in] arg Arbitrary argument of type void* to be passed into the function
  61. *
  62. * @return
  63. * - ESP_ERR_INVALID_ARG if cpu_id is invalid
  64. * - ESP_ERR_INVALID_STATE if the FreeRTOS scheduler is not running
  65. * - ESP_OK otherwise
  66. */
  67. esp_err_t esp_ipc_call(uint32_t cpu_id, esp_ipc_func_t func, void* arg);
  68. /**
  69. * @brief Execute a function on the given CPU and blocks until it completes
  70. *
  71. * Run a given function on a particular CPU. The given function must accept a
  72. * void* argument and return void. The given function is run in the context of
  73. * the IPC task of the CPU specified by the cpu_id parameter. The calling task
  74. * will be blocked until the IPC task completes execution of the given function.
  75. * If another IPC call is ongoing, the calling task will block until the other
  76. * IPC call completes. The stack size allocated for the IPC task can be
  77. * configured in the "Inter-Processor Call (IPC) task stack size" setting in
  78. * menuconfig. Increase this setting if the given function requires more stack
  79. * than default.
  80. *
  81. * @note In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
  82. *
  83. * @param[in] cpu_id CPU where the given function should be executed (0 or 1)
  84. * @param[in] func Pointer to a function of type void func(void* arg) to be executed
  85. * @param[in] arg Arbitrary argument of type void* to be passed into the function
  86. *
  87. * @return
  88. * - ESP_ERR_INVALID_ARG if cpu_id is invalid
  89. * - ESP_ERR_INVALID_STATE if the FreeRTOS scheduler is not running
  90. * - ESP_OK otherwise
  91. */
  92. esp_err_t esp_ipc_call_blocking(uint32_t cpu_id, esp_ipc_func_t func, void* arg);
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif /* __ESP_IPC_H__ */