soc_hal.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2020 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 <stdint.h>
  15. #include <stdbool.h>
  16. #include "esp_err.h"
  17. #include "soc/soc_caps.h"
  18. #include "hal/cpu_hal.h"
  19. #include "hal/soc_ll.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #if SOC_CPU_CORES_NUM > 1
  24. // Utility functions for multicore targets
  25. #define __SOC_HAL_PERFORM_ON_OTHER_CORES(action) { \
  26. for (uint32_t i = 0, cur = cpu_hal_get_core_id(); i < SOC_CPU_CORES_NUM; i++) { \
  27. if (i != cur) { \
  28. action(i); \
  29. } \
  30. } \
  31. }
  32. #define SOC_HAL_STALL_OTHER_CORES() __SOC_HAL_PERFORM_ON_OTHER_CORES(soc_hal_stall_core);
  33. #define SOC_HAL_UNSTALL_OTHER_CORES() __SOC_HAL_PERFORM_ON_OTHER_CORES(soc_hal_unstall_core);
  34. #define SOC_HAL_RESET_OTHER_CORES() __SOC_HAL_PERFORM_ON_OTHER_CORES(soc_hal_reset_core);
  35. /**
  36. * Stall the specified CPU core.
  37. *
  38. * @note Has no effect if the core is already stalled - does not return an
  39. * ESP_ERR_INVALID_STATE.
  40. *
  41. * @param core core to stall [0..SOC_CPU_CORES_NUM - 1]
  42. */
  43. void soc_hal_stall_core(int core);
  44. /**
  45. * Unstall the specified CPU core.
  46. *
  47. * @note Has no effect if the core is already unstalled - does not return an
  48. * ESP_ERR_INVALID_STATE.
  49. *
  50. * @param core core to unstall [0..SOC_CPU_CORES_NUM - 1]
  51. */
  52. void soc_hal_unstall_core(int core);
  53. #endif // SOC_CPU_CORES_NUM > 1
  54. /**
  55. * Reset the specified core.
  56. *
  57. * @param core core to reset [0..SOC_CPU_CORES_NUM - 1]
  58. */
  59. #define soc_hal_reset_core(core) soc_ll_reset_core((core))
  60. #ifdef __cplusplus
  61. }
  62. #endif