nrfx_clock.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /**
  2. * Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NRFX_CLOCK_H__
  41. #define NRFX_CLOCK_H__
  42. #include <nrfx.h>
  43. #include <hal/nrf_clock.h>
  44. #include <nrfx_power_clock.h>
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /**
  49. * @defgroup nrfx_clock CLOCK driver
  50. * @{
  51. * @ingroup nrf_clock
  52. * @brief CLOCK peripheral driver.
  53. */
  54. /** @brief Clock events. */
  55. typedef enum
  56. {
  57. NRFX_CLOCK_EVT_HFCLK_STARTED, ///< HFCLK has been started.
  58. NRFX_CLOCK_EVT_LFCLK_STARTED, ///< LFCLK has been started.
  59. NRFX_CLOCK_EVT_CTTO, ///< Calibration timeout.
  60. NRFX_CLOCK_EVT_CAL_DONE ///< Calibration has been done.
  61. } nrfx_clock_evt_type_t;
  62. /**
  63. * @brief Clock event handler.
  64. *
  65. * @param[in] event Event.
  66. */
  67. typedef void (*nrfx_clock_event_handler_t)(nrfx_clock_evt_type_t event);
  68. /**
  69. * @brief Function for initializing internal structures in the nrfx_clock module.
  70. *
  71. * After initialization, the module is in power off state (clocks are not started).
  72. *
  73. * @param[in] event_handler Event handler provided by the user.
  74. * Must not be NULL.
  75. *
  76. * @retval NRFX_SUCCESS The procedure is successful.
  77. * @retval NRFX_ERROR_ALREADY_INITIALIZED The driver is already initialized.
  78. */
  79. nrfx_err_t nrfx_clock_init(nrfx_clock_event_handler_t event_handler);
  80. /** @brief Function for enabling interrupts in the clock module. */
  81. void nrfx_clock_enable(void);
  82. /** @brief Function for disabling interrupts in the clock module. */
  83. void nrfx_clock_disable(void);
  84. /** @brief Function for uninitializing the clock module. */
  85. void nrfx_clock_uninit(void);
  86. /** @brief Function for starting the LFCLK. */
  87. void nrfx_clock_lfclk_start(void);
  88. /** @brief Function for stopping the LFCLK. */
  89. void nrfx_clock_lfclk_stop(void);
  90. /**
  91. * @brief Function for checking the LFCLK state.
  92. *
  93. * @retval true The LFCLK is running.
  94. * @retval false The LFCLK is not running.
  95. */
  96. __STATIC_INLINE bool nrfx_clock_lfclk_is_running(void);
  97. /** @brief Function for starting the high-accuracy source HFCLK. */
  98. void nrfx_clock_hfclk_start(void);
  99. /** @brief Function for stopping the external high-accuracy source HFCLK. */
  100. void nrfx_clock_hfclk_stop(void);
  101. /**
  102. * @brief Function for checking the HFCLK state.
  103. *
  104. * @retval true The HFCLK is running (XTAL source).
  105. * @retval false The HFCLK is not running.
  106. */
  107. __STATIC_INLINE bool nrfx_clock_hfclk_is_running(void);
  108. /**
  109. * @brief Function for starting the calibration of internal LFCLK.
  110. *
  111. * This function starts the calibration process. The process cannot be aborted. LFCLK and HFCLK
  112. * must be running before this function is called.
  113. *
  114. * @retval NRFX_SUCCESS The procedure is successful.
  115. * @retval NRFX_ERROR_INVALID_STATE The low-frequency of high-frequency clock is off.
  116. * @retval NRFX_ERROR_BUSY Clock is in the calibration phase.
  117. */
  118. nrfx_err_t nrfx_clock_calibration_start(void);
  119. /**
  120. * @brief Function for checking if calibration is in progress.
  121. *
  122. * This function indicates that the system is in calibration phase.
  123. *
  124. * @retval NRFX_SUCCESS The procedure is successful.
  125. * @retval NRFX_ERROR_BUSY Clock is in the calibration phase.
  126. */
  127. nrfx_err_t nrfx_clock_is_calibrating(void);
  128. /**
  129. * @brief Function for starting calibration timer.
  130. *
  131. * @param[in] interval Time after which the CTTO event and interrupt will be generated (in 0.25 s units).
  132. */
  133. void nrfx_clock_calibration_timer_start(uint8_t interval);
  134. /** @brief Function for stopping the calibration timer. */
  135. void nrfx_clock_calibration_timer_stop(void);
  136. /**@brief Function for returning a requested task address for the clock driver module.
  137. *
  138. * @param[in] task One of the peripheral tasks.
  139. *
  140. * @return Task address.
  141. */
  142. __STATIC_INLINE uint32_t nrfx_clock_ppi_task_addr(nrf_clock_task_t task);
  143. /**@brief Function for returning a requested event address for the clock driver module.
  144. *
  145. * @param[in] event One of the peripheral events.
  146. *
  147. * @return Event address.
  148. */
  149. __STATIC_INLINE uint32_t nrfx_clock_ppi_event_addr(nrf_clock_event_t event);
  150. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  151. __STATIC_INLINE uint32_t nrfx_clock_ppi_task_addr(nrf_clock_task_t task)
  152. {
  153. return nrf_clock_task_address_get(task);
  154. }
  155. __STATIC_INLINE uint32_t nrfx_clock_ppi_event_addr(nrf_clock_event_t event)
  156. {
  157. return nrf_clock_event_address_get(event);
  158. }
  159. __STATIC_INLINE bool nrfx_clock_hfclk_is_running(void)
  160. {
  161. return nrf_clock_hf_is_running(NRF_CLOCK_HFCLK_HIGH_ACCURACY);
  162. }
  163. __STATIC_INLINE bool nrfx_clock_lfclk_is_running(void)
  164. {
  165. return nrf_clock_lf_is_running();
  166. }
  167. #endif //SUPPRESS_INLINE_IMPLEMENTATION
  168. /** @} */
  169. void nrfx_clock_irq_handler(void);
  170. #ifdef __cplusplus
  171. }
  172. #endif
  173. #endif // NRFX_CLOCK_H__