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