esp_ipc.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. typedef void (*esp_ipc_func_t)(void* arg);
  17. /**
  18. * @brief Inter-processor call APIs
  19. *
  20. * FreeRTOS provides several APIs which can be used to communicate between
  21. * different tasks, including tasks running on different CPUs.
  22. * This module provides additional APIs to run some code on the other CPU.
  23. *
  24. * These APIs can only be used when FreeRTOS scheduler is running.
  25. */
  26. /**
  27. * @brief Initialize inter-processor call module.
  28. *
  29. * This function start two tasks, one on each CPU. These tasks are started
  30. * with high priority. These tasks are normally inactive, waiting until one of
  31. * the esp_ipc_call_* functions to be used. One of these tasks will be
  32. * woken up to execute the callback provided to esp_ipc_call_nonblocking or
  33. * esp_ipc_call_blocking.
  34. */
  35. void esp_ipc_init();
  36. /**
  37. * @brief Execute function on the given CPU
  38. *
  39. * This will wake a high-priority task on CPU indicated by cpu_id argument,
  40. * and run func(arg) in the context of that task.
  41. * This function returns as soon as the high-priority task is woken up.
  42. * If another IPC call is already being executed, this function will also wait
  43. * for it to complete.
  44. *
  45. * In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
  46. *
  47. * @param cpu_id CPU where function should be executed (0 or 1)
  48. * @param func pointer to a function which should be executed
  49. * @param arg arbitrary argument to be passed into function
  50. *
  51. * @return ESP_ERR_INVALID_ARG if cpu_id is invalid
  52. * ESP_ERR_INVALID_STATE if FreeRTOS scheduler is not running
  53. * ESP_OK otherwise
  54. */
  55. esp_err_t esp_ipc_call(uint32_t cpu_id, esp_ipc_func_t func, void* arg);
  56. /**
  57. * @brief Execute function on the given CPU and wait for it to finish
  58. *
  59. * This will wake a high-priority task on CPU indicated by cpu_id argument,
  60. * and run func(arg) in the context of that task.
  61. * This function waits for func to return.
  62. *
  63. * In single-core mode, returns ESP_ERR_INVALID_ARG for cpu_id 1.
  64. *
  65. * @param cpu_id CPU where function should be executed (0 or 1)
  66. * @param func pointer to a function which should be executed
  67. * @param arg arbitrary argument to be passed into function
  68. *
  69. * @return ESP_ERR_INVALID_ARG if cpu_id is invalid
  70. * ESP_ERR_INVALID_STATE if 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. #endif /* __ESP_IPC_H__ */