esp_ipc_isr.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "sdkconfig.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #ifdef CONFIG_ESP_IPC_ISR_ENABLE
  12. /**
  13. * @brief IPC ISR Callback
  14. *
  15. * The callback must be written:
  16. * - in assembly for XTENSA chips (such as ESP32, ESP32S3).
  17. * - in C or assembly for RISCV chips (such as ESP32P4).
  18. *
  19. * A callback of this type should be provided as an argument when calling esp_ipc_isr_call() or
  20. * esp_ipc_isr_call_blocking().
  21. */
  22. typedef void (*esp_ipc_isr_func_t)(void* arg);
  23. /**
  24. * @brief Execute an ISR callback on the other CPU
  25. *
  26. * Execute a given callback on the other CPU in the context of a High Priority Interrupt.
  27. *
  28. * - This function will busy-wait in a critical section until the other CPU has started execution of the callback
  29. * - The callback must be written:
  30. * - in assembly for XTENSA chips (such as ESP32, ESP32S3).
  31. * The function is invoked using a CALLX0 instruction and can use only a2, a3, a4 registers.
  32. * See :doc:`IPC in Interrupt Context </api-reference/system/ipc>` doc for more details.
  33. * - in C or assembly for RISCV chips (such as ESP32P4).
  34. *
  35. * @note This function is not available in single-core mode.
  36. *
  37. * @param[in] func Pointer to a function of type void func(void* arg) to be executed
  38. * @param[in] arg Arbitrary argument of type void* to be passed into the function
  39. */
  40. void esp_ipc_isr_call(esp_ipc_isr_func_t func, void* arg) ;
  41. /**
  42. * @brief Execute an ISR callback on the other CPU
  43. * See esp_ipc_isr_call().
  44. */
  45. #define esp_ipc_isr_asm_call(func, arg) esp_ipc_isr_call(func, arg)
  46. /**
  47. * @brief Execute an ISR callback on the other CPU and busy-wait until it completes
  48. *
  49. * This function is identical to esp_ipc_isr_call() except that this function will busy-wait until the execution of
  50. * the callback completes.
  51. *
  52. * @note This function is not available in single-core mode.
  53. *
  54. * @param[in] func Pointer to a function of type void func(void* arg) to be executed
  55. * @param[in] arg Arbitrary argument of type void* to be passed into the function
  56. */
  57. void esp_ipc_isr_call_blocking(esp_ipc_isr_func_t func, void* arg);
  58. /**
  59. * @brief Execute an ISR callback on the other CPU and busy-wait until it completes
  60. * See esp_ipc_isr_call_blocking().
  61. */
  62. #define esp_ipc_isr_asm_call_blocking(func, arg) esp_ipc_isr_call_blocking(func, arg)
  63. /**
  64. * @brief Stall the other CPU
  65. *
  66. * This function will stall the other CPU. The other CPU is stalled by busy-waiting in the context of a High Priority
  67. * Interrupt. The other CPU will not be resumed until esp_ipc_isr_release_other_cpu() is called.
  68. *
  69. * - This function is internally implemented using IPC ISR
  70. * - This function is used for DPORT workaround.
  71. * - If the stall feature is paused using esp_ipc_isr_stall_pause(), this function will have no effect
  72. *
  73. * @note This function is not available in single-core mode.
  74. * @note It is the caller's responsibility to avoid deadlocking on spinlocks
  75. */
  76. void esp_ipc_isr_stall_other_cpu(void);
  77. /**
  78. * @brief Release the other CPU
  79. *
  80. * This function will release the other CPU that was previously stalled from calling esp_ipc_isr_stall_other_cpu()
  81. *
  82. * - This function is used for DPORT workaround.
  83. * - If the stall feature is paused using esp_ipc_isr_stall_pause(), this function will have no effect
  84. *
  85. * @note This function is not available in single-core mode.
  86. */
  87. void esp_ipc_isr_release_other_cpu(void);
  88. /**
  89. * @brief Puase the CPU stall feature
  90. *
  91. * This function will pause the CPU stall feature. Once paused, calls to esp_ipc_isr_stall_other_cpu() and
  92. * esp_ipc_isr_release_other_cpu() will have no effect. If a IPC ISR call is already in progress, this function will
  93. * busy-wait until the call completes before pausing the CPU stall feature.
  94. */
  95. void esp_ipc_isr_stall_pause(void);
  96. /**
  97. * @brief Abort a CPU stall
  98. *
  99. * This function will abort any stalling routine of the other CPU due to a pervious call to
  100. * esp_ipc_isr_stall_other_cpu(). This function aborts the stall in a non-recoverable manner, thus should only be called
  101. * in case of a panic().
  102. *
  103. * - This function is used in panic handling code
  104. */
  105. void esp_ipc_isr_stall_abort(void);
  106. /**
  107. * @brief Resume the CPU stall feature
  108. *
  109. * This function will resume the CPU stall feature that was previously paused by calling esp_ipc_isr_stall_pause(). Once
  110. * resumed, calls to esp_ipc_isr_stall_other_cpu() and esp_ipc_isr_release_other_cpu() will have effect again.
  111. */
  112. void esp_ipc_isr_stall_resume(void);
  113. #else // CONFIG_ESP_IPC_ISR_ENABLE
  114. #define esp_ipc_isr_stall_other_cpu()
  115. #define esp_ipc_isr_release_other_cpu()
  116. #define esp_ipc_isr_stall_pause()
  117. #define esp_ipc_isr_stall_abort()
  118. #define esp_ipc_isr_stall_resume()
  119. #endif // CONFIG_ESP_IPC_ISR_ENABLE
  120. #ifdef __cplusplus
  121. }
  122. #endif