nrfx_clock.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * Copyright (c) 2016 - 2019, 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. /**
  55. * @brief Clock events.
  56. */
  57. typedef enum
  58. {
  59. NRFX_CLOCK_EVT_HFCLK_STARTED, ///< HFCLK has been started.
  60. NRFX_CLOCK_EVT_LFCLK_STARTED, ///< LFCLK has been started.
  61. NRFX_CLOCK_EVT_CTTO, ///< Calibration timeout.
  62. NRFX_CLOCK_EVT_CAL_DONE ///< Calibration has been done.
  63. } nrfx_clock_evt_type_t;
  64. /**
  65. * @brief Clock event handler.
  66. *
  67. * @param[in] event Event.
  68. */
  69. typedef void (*nrfx_clock_event_handler_t)(nrfx_clock_evt_type_t event);
  70. /**
  71. * @brief Function for initializing internal structures in the nrfx_clock module.
  72. *
  73. * After initialization, the module is in power off state (clocks are not started).
  74. *
  75. * @param[in] event_handler Event handler provided by the user.
  76. * Must not be NULL.
  77. *
  78. * @retval NRFX_SUCCESS If the procedure was successful.
  79. * @retval NRFX_ERROR_ALREADY_INITIALIZED If the driver was already initialized.
  80. */
  81. nrfx_err_t nrfx_clock_init(nrfx_clock_event_handler_t event_handler);
  82. /**
  83. * @brief Function for enabling interrupts in the clock module.
  84. */
  85. void nrfx_clock_enable(void);
  86. /**
  87. * @brief Function for disabling interrupts in the clock module.
  88. */
  89. void nrfx_clock_disable(void);
  90. /**
  91. * @brief Function for uninitializing the clock module.
  92. */
  93. void nrfx_clock_uninit(void);
  94. /**
  95. * @brief Function for starting the LFCLK.
  96. */
  97. void nrfx_clock_lfclk_start(void);
  98. /**
  99. * @brief Function for stoping the LFCLK.
  100. */
  101. void nrfx_clock_lfclk_stop(void);
  102. /**
  103. * @brief Function for checking the LFCLK state.
  104. *
  105. * @retval true If the LFCLK is running.
  106. * @retval false If the LFCLK is not running.
  107. */
  108. __STATIC_INLINE bool nrfx_clock_lfclk_is_running(void);
  109. /**
  110. * @brief Function for starting the high-accuracy source HFCLK.
  111. */
  112. void nrfx_clock_hfclk_start(void);
  113. /**
  114. * @brief Function for stoping external high-accuracy source HFCLK.
  115. */
  116. void nrfx_clock_hfclk_stop(void);
  117. /**
  118. * @brief Function for checking the HFCLK state.
  119. *
  120. * @retval true If the HFCLK is running (XTAL source).
  121. * @retval false If the HFCLK is not running.
  122. */
  123. __STATIC_INLINE bool nrfx_clock_hfclk_is_running(void);
  124. /**
  125. * @brief Function for starting calibration of internal LFCLK.
  126. *
  127. * This function starts the calibration process. The process cannot be aborted. LFCLK and HFCLK
  128. * must be running before this function is called.
  129. *
  130. * @retval NRFX_SUCCESS If the procedure was successful.
  131. * @retval NRFX_ERROR_INVALID_STATE If the low-frequency of high-frequency clock is off.
  132. * @retval NRFX_ERROR_BUSY If calibration is in progress.
  133. */
  134. nrfx_err_t nrfx_clock_calibration_start(void);
  135. /**
  136. * @brief Function for checking if calibration is in progress.
  137. *
  138. * This function indicates that the system is in calibration phase.
  139. *
  140. * @retval NRFX_SUCCESS If the procedure was successful.
  141. * @retval NRFX_ERROR_BUSY If calibration is in progress.
  142. */
  143. nrfx_err_t nrfx_clock_is_calibrating(void);
  144. /**
  145. * @brief Function for starting calibration timer.
  146. * @param interval Time after which the CTTO event and interrupt will be generated (in 0.25 s units).
  147. */
  148. void nrfx_clock_calibration_timer_start(uint8_t interval);
  149. /**
  150. * @brief Function for stoping calibration timer.
  151. */
  152. void nrfx_clock_calibration_timer_stop(void);
  153. /**@brief Function for returning a requested task address for the clock driver module.
  154. *
  155. * @param[in] task One of the peripheral tasks.
  156. *
  157. * @return Task address.
  158. */
  159. __STATIC_INLINE uint32_t nrfx_clock_ppi_task_addr(nrf_clock_task_t task);
  160. /**@brief Function for returning a requested event address for the clock driver module.
  161. *
  162. * @param[in] event One of the peripheral events.
  163. *
  164. * @return Event address.
  165. */
  166. __STATIC_INLINE uint32_t nrfx_clock_ppi_event_addr(nrf_clock_event_t event);
  167. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  168. __STATIC_INLINE uint32_t nrfx_clock_ppi_task_addr(nrf_clock_task_t task)
  169. {
  170. return nrf_clock_task_address_get(task);
  171. }
  172. __STATIC_INLINE uint32_t nrfx_clock_ppi_event_addr(nrf_clock_event_t event)
  173. {
  174. return nrf_clock_event_address_get(event);
  175. }
  176. __STATIC_INLINE bool nrfx_clock_hfclk_is_running(void)
  177. {
  178. return nrf_clock_hf_is_running(NRF_CLOCK_HFCLK_HIGH_ACCURACY);
  179. }
  180. __STATIC_INLINE bool nrfx_clock_lfclk_is_running(void)
  181. {
  182. return nrf_clock_lf_is_running();
  183. }
  184. #endif //SUPPRESS_INLINE_IMPLEMENTATION
  185. void nrfx_clock_irq_handler(void);
  186. /** @} */
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif // NRFX_CLOCK_H__