periph_ctrl.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <stdint.h>
  8. #include "soc/periph_defs.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /**
  13. * @defgroup Reset and Clock Control APIs
  14. * @{
  15. */
  16. /**
  17. * @brief Acquire the RCC lock for a peripheral module
  18. *
  19. * @note User code protected by this macro should be as short as possible, because it's a critical section
  20. * @note This macro will increase the reference lock of that peripheral.
  21. * You can get the value before the increment from the `rc_name` local variable
  22. */
  23. #define PERIPH_RCC_ACQUIRE_ATOMIC(periph, rc_name) \
  24. for (uint8_t rc_name, i = 1, __DECLARE_RCC_RC_ATOMIC_ENV; \
  25. i ? (rc_name = periph_rcc_acquire_enter(periph), 1) : 0; \
  26. periph_rcc_acquire_exit(periph, rc_name), i--)
  27. /**
  28. * @brief Release the RCC lock for a peripheral module
  29. *
  30. * @note User code protected by this macro should be as short as possible, because it's a critical section
  31. * @note This macro will decrease the reference lock of that peripheral.
  32. * You can get the value after the decrease from the `rc_name` local variable
  33. */
  34. #define PERIPH_RCC_RELEASE_ATOMIC(periph, rc_name) \
  35. for (uint8_t rc_name, i = 1, __DECLARE_RCC_RC_ATOMIC_ENV; \
  36. i ? (rc_name = periph_rcc_release_enter(periph), 1) : 0; \
  37. periph_rcc_release_exit(periph, rc_name), i--)
  38. /**
  39. * @brief A simplified version of `PERIPH_RCC_ACQUIRE/RELEASE_ATOMIC`, without a reference count
  40. *
  41. * @note User code protected by this macro should be as short as possible, because it's a critical section
  42. */
  43. #define PERIPH_RCC_ATOMIC() \
  44. for (int i = 1, __DECLARE_RCC_ATOMIC_ENV; \
  45. i ? (periph_rcc_enter(), 1) : 0; \
  46. periph_rcc_exit(), i--)
  47. /** @cond */
  48. // The following functions are not intended to be used directly by the developers
  49. uint8_t periph_rcc_acquire_enter(periph_module_t periph);
  50. void periph_rcc_acquire_exit(periph_module_t periph, uint8_t ref_count);
  51. uint8_t periph_rcc_release_enter(periph_module_t periph);
  52. void periph_rcc_release_exit(periph_module_t periph, uint8_t ref_count);
  53. void periph_rcc_enter(void);
  54. void periph_rcc_exit(void);
  55. /** @endcond */
  56. /**
  57. * @}
  58. */
  59. /*************************************************************************************************************
  60. * @note The following APIs are no longer supported since ESP32P4, please use the RCC lock macros instead.
  61. *************************************************************************************************************/
  62. /**
  63. * @brief Enable peripheral module by un-gating the clock and de-asserting the reset signal.
  64. *
  65. * @param[in] periph Peripheral module
  66. *
  67. * @note If @c periph_module_enable() is called a number of times,
  68. * @c periph_module_disable() has to be called the same number of times,
  69. * in order to put the peripheral into disabled state.
  70. */
  71. void periph_module_enable(periph_module_t periph);
  72. /**
  73. * @brief Disable peripheral module by gating the clock and asserting the reset signal.
  74. *
  75. * @param[in] periph Peripheral module
  76. *
  77. * @note If @c periph_module_enable() is called a number of times,
  78. * @c periph_module_disable() has to be called the same number of times,
  79. * in order to put the peripheral into disabled state.
  80. */
  81. void periph_module_disable(periph_module_t periph);
  82. /**
  83. * @brief Reset peripheral module by asserting and de-asserting the reset signal.
  84. *
  85. * @param[in] periph Peripheral module
  86. *
  87. * @note Calling this function does not enable or disable the clock for the module.
  88. */
  89. void periph_module_reset(periph_module_t periph);
  90. /**
  91. * @brief Enable Wi-Fi and BT common module
  92. *
  93. * @note If @c wifi_bt_common_module_enable() is called a number of times,
  94. * @c wifi_bt_common_module_disable() has to be called the same number of times,
  95. * in order to put the peripheral into disabled state.
  96. */
  97. void wifi_bt_common_module_enable(void);
  98. /**
  99. * @brief Disable Wi-Fi and BT common module
  100. *
  101. * @note If @c wifi_bt_common_module_enable() is called a number of times,
  102. * @c wifi_bt_common_module_disable() has to be called the same number of times,
  103. * in order to put the peripheral into disabled state.
  104. */
  105. void wifi_bt_common_module_disable(void);
  106. /**
  107. * @brief Enable Wi-Fi module
  108. *
  109. * @note Calling this function will only enable Wi-Fi module.
  110. */
  111. void wifi_module_enable(void);
  112. /**
  113. * @brief Disable Wi-Fi module
  114. *
  115. * @note Calling this function will only disable Wi-Fi module.
  116. */
  117. void wifi_module_disable(void);
  118. #ifdef __cplusplus
  119. }
  120. #endif