Skip to content

Commit b61eb12

Browse files
committed
NRFX-8013: drivers: Separate LFCLK driver from clock driver.
Signed-off-by: Michal Frankiewicz <[email protected]>
1 parent 7a42b25 commit b61eb12

File tree

5 files changed

+771
-214
lines changed

5 files changed

+771
-214
lines changed

nrfx/drivers/include/nrfx_clock.h

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#if NRF_CLOCK_HAS_XO
4747
#include <nrfx_clock_xo.h>
4848
#endif
49+
#include <nrfx_clock_lfclk.h>
4950

5051
#ifdef __cplusplus
5152
extern "C" {
@@ -72,15 +73,12 @@ typedef enum
7273
#if NRF_CLOCK_HAS_PLL
7374
NRFX_CLOCK_EVT_PLL_STARTED = NRFX_CLOCK_XO_EVT_PLL_STARTED, ///< PLL has been started.
7475
#endif
75-
NRFX_CLOCK_EVT_LFCLK_STARTED = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_LF_STARTED_MASK), ///< LFCLK has been started.
76+
NRFX_CLOCK_EVT_LFCLK_STARTED = NRFX_CLOCK_LFCLK_EVT_LFCLK_STARTED, ///< LFCLK has been started.
7677
#if NRF_CLOCK_HAS_CALIBRATION_TIMER
77-
NRFX_CLOCK_EVT_CTTO = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_CTTO_MASK), ///< Calibration timeout.
78+
NRFX_CLOCK_EVT_CTTO = NRFX_CLOCK_LFCLK_EVT_CTTO, ///< Calibration timeout.
7879
#endif
79-
#if NRF_CLOCK_HAS_CALIBRATION
80-
NRFX_CLOCK_EVT_CAL_DONE = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_DONE_MASK), ///< Calibration has been done.
81-
#elif NRFX_CHECK(NRF_LFRC_HAS_CALIBRATION)
82-
NRFX_CLOCK_EVT_CAL_DONE = (NRFX_BITMASK_TO_BITPOS(NRF_LFRC_INT_CALDONE_MASK) + \
83-
NRFX_CLOCK_LFRC_EVT_OFFSET), ///< Calibration has been done.
80+
#if NRF_CLOCK_HAS_CALIBRATION || NRFX_CHECK(NRF_LFRC_HAS_CALIBRATION)
81+
NRFX_CLOCK_EVT_CAL_DONE = NRFX_CLOCK_LFCLK_EVT_CAL_DONE, ///< Calibration has been done.
8482
#endif
8583
#if NRF_CLOCK_HAS_HFCLKAUDIO
8684
NRFX_CLOCK_EVT_HFCLKAUDIO_STARTED = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_HFAUDIO_STARTED_MASK), ///< HFCLKAUDIO has been started.
@@ -191,30 +189,6 @@ nrfx_err_t nrfx_clock_divider_set(nrf_clock_domain_t domain,
191189
NRFX_STATIC_INLINE nrf_clock_hfclk_div_t nrfx_clock_divider_get(nrf_clock_domain_t domain);
192190
#endif
193191

194-
/**
195-
* @brief Function for starting the LFCLK.
196-
*
197-
* @note This function is deprecated. Use @ref nrfx_clock_start instead.
198-
*/
199-
NRFX_STATIC_INLINE void nrfx_clock_lfclk_start(void);
200-
201-
/**
202-
* @brief Function for stopping the LFCLK.
203-
*
204-
* @note This function is deprecated. Use @ref nrfx_clock_stop instead.
205-
*/
206-
NRFX_STATIC_INLINE void nrfx_clock_lfclk_stop(void);
207-
208-
/**
209-
* @brief Function for checking the LFCLK state.
210-
*
211-
* @note This function is deprecated. Use @ref nrfx_clock_is_running instead.
212-
*
213-
* @retval true The LFCLK is running.
214-
* @retval false The LFCLK is not running.
215-
*/
216-
NRFX_STATIC_INLINE bool nrfx_clock_lfclk_is_running(void);
217-
218192
#if NRF_CLOCK_HAS_HFCLKAUDIO || defined(__NRFX_DOXYGEN__)
219193
/**
220194
* @brief Function for setting the HFCLKAUDIO configuration.
@@ -364,16 +338,6 @@ NRFX_STATIC_INLINE nrf_clock_hfclk_div_t nrfx_clock_divider_get(nrf_clock_domain
364338
}
365339
#endif // defined(CLOCK_FEATURE_HFCLK_DIVIDE_PRESENT) || NRF_CLOCK_HAS_HFCLK192M
366340

367-
NRFX_STATIC_INLINE void nrfx_clock_lfclk_start(void)
368-
{
369-
nrfx_clock_start(NRF_CLOCK_DOMAIN_LFCLK);
370-
}
371-
372-
NRFX_STATIC_INLINE void nrfx_clock_lfclk_stop(void)
373-
{
374-
nrfx_clock_stop(NRF_CLOCK_DOMAIN_LFCLK);
375-
}
376-
377341
NRFX_STATIC_INLINE uint32_t nrfx_clock_task_address_get(nrf_clock_task_t task)
378342
{
379343
return nrf_clock_task_address_get(NRF_CLOCK, task);
@@ -394,16 +358,13 @@ NRFX_STATIC_INLINE bool nrfx_clock_is_running(nrf_clock_domain_t domain, void *
394358
#elif NRF_CLOCK_HAS_XO
395359
return nrfx_clock_xo_running_check(p_clk_src);
396360
#endif
361+
case NRF_CLOCK_DOMAIN_LFCLK:
362+
return nrfx_clock_lfclk_running_check(p_clk_src);
397363
default:
398364
return nrf_clock_is_running(NRF_CLOCK, domain, p_clk_src);
399365
}
400366
}
401367

402-
NRFX_STATIC_INLINE bool nrfx_clock_lfclk_is_running(void)
403-
{
404-
return nrfx_clock_is_running(NRF_CLOCK_DOMAIN_LFCLK, NULL);
405-
}
406-
407368
#if NRF_CLOCK_HAS_HFCLKAUDIO
408369

409370
NRFX_STATIC_INLINE void nrfx_clock_hfclkaudio_config_set(uint16_t freq_value)
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
* Copyright (c) 2016 - 2025, Nordic Semiconductor ASA
3+
* All rights reserved.
4+
*
5+
* SPDX-License-Identifier: BSD-3-Clause
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice, this
11+
* list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above copyright
14+
* notice, this list of conditions and the following disclaimer in the
15+
* documentation and/or other materials provided with the distribution.
16+
*
17+
* 3. Nittner the name of the copyright holder nor the names of its
18+
* contributors may be used to endorse or promote products derived from this
19+
* software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
#ifndef NRFX_CLOCK_LFCLK_H__
35+
#define NRFX_CLOCK_LFCLK_H__
36+
37+
#include <nrfx.h>
38+
#include <hal/nrf_clock.h>
39+
40+
#if defined(LFRC_PRESENT)
41+
#include <hal/nrf_lfrc.h>
42+
#endif
43+
44+
#ifdef __cplusplus
45+
extern "C" {
46+
#endif
47+
48+
/**
49+
* @defgroup nrfx_clock_lfclk LFCLK driver
50+
* @{
51+
* @ingroup nrf_clock_lfclk
52+
* @brief LFCLK clock driver.
53+
*/
54+
55+
/** @brief Symbol specifying driver event offset for LFRC hardware events. */
56+
#define NRFX_CLOCK_LFCLK_LFRC_EVT_OFFSET 32
57+
58+
/** @brief Clock events. */
59+
typedef enum
60+
{
61+
NRFX_CLOCK_LFCLK_EVT_LFCLK_STARTED = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_LF_STARTED_MASK), ///< LFCLK has been started.
62+
#if NRF_CLOCK_HAS_CALIBRATION_TIMER
63+
NRFX_CLOCK_LFCLK_EVT_CTTO = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_CTTO_MASK), ///< Calibration timeout.
64+
#endif
65+
#if NRF_CLOCK_HAS_CALIBRATION
66+
NRFX_CLOCK_LFCLK_EVT_CAL_DONE = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_DONE_MASK), ///< Calibration has been done.
67+
#elif NRFX_CHECK(NRF_LFRC_HAS_CALIBRATION)
68+
NRFX_CLOCK_LFCLK_EVT_CAL_DONE = (NRFX_BITMASK_TO_BITPOS(NRF_LFRC_INT_CALDONE_MASK) + \
69+
NRFX_CLOCK_LFCLK_LFRC_EVT_OFFSET), ///< Calibration has been done.
70+
#endif
71+
72+
73+
} nrfx_clock_lfclk_evt_type_t;
74+
//TODO check if all commens and functions are lfclk specific
75+
/**
76+
* @brief Lfclk event handler.
77+
*
78+
* @param[in] event Event.
79+
*/
80+
typedef void (*nrfx_clock_lfclk_event_handler_t)(nrfx_clock_lfclk_evt_type_t event);
81+
82+
/**
83+
* @brief Function for initializing internal structures in the nrfx_clock_lfclk module.
84+
*
85+
* After initialization, the module is in power off state (clocks are not started).
86+
*
87+
* @param[in] event_handler Event handler provided by the user.
88+
* If not provided, driver works in blocking mode.
89+
*
90+
* @retval NRFX_SUCCESS The procedure is successful.
91+
* @retval NRFX_ERROR_ALREADY The driver is already initialized.
92+
*/
93+
nrfx_err_t nrfx_clock_lfclk_init(nrfx_clock_lfclk_event_handler_t event_handler);
94+
95+
/** @brief Function for uninitializing the lfclk module. */
96+
void nrfx_clock_lfclk_uninit(void);
97+
98+
/**
99+
* @brief Function for checking if the lfclk driver is initialized.
100+
*
101+
* @retval true Driver is already initialized.
102+
* @retval false Driver is not initialized.
103+
*/
104+
bool nrfx_clock_lfclk_init_check(void);
105+
106+
/**
107+
* @brief Function for starting the LFCLK.
108+
*/
109+
void nrfx_clock_lfclk_start(void);
110+
111+
/**
112+
* @brief Function for stopping the LFCLK.
113+
*/
114+
void nrfx_clock_lfclk_stop(void);
115+
116+
/**
117+
* @brief Function for checking the LFCLK state.
118+
*
119+
* XTAL source is assumed for domains with multiple sources.
120+
*
121+
* @param[out] p_clk_src Pointer to a clock source that is running. Set to NULL if not needed.
122+
*
123+
* @retval true The clock domain is running.
124+
* @retval false The clock domain is not running.
125+
*/
126+
NRFX_STATIC_INLINE bool nrfx_clock_lfclk_running_check(nrf_clock_lfclk_t * p_clk_src);
127+
128+
#if ((NRF_CLOCK_HAS_CALIBRATION || NRFX_CHECK(NRF_LFRC_HAS_CALIBRATION)) && \
129+
NRFX_CHECK(NRFX_CLOCK_CONFIG_LF_CAL_ENABLED)) || defined(__NRFX_DOXYGEN__)
130+
/**
131+
* @brief Function for starting the calibration of internal LFCLK.
132+
*
133+
* This function starts the calibration process. The process cannot be aborted. LFCLK and (HFCLK or XO)
134+
* must be running before this function is called.
135+
*
136+
* @retval NRFX_SUCCESS The procedure is successful.
137+
* @retval NRFX_ERROR_INVALID_STATE The low-frequency or high-frequency clock is off.
138+
* @retval NRFX_ERROR_BUSY Clock is in the calibration phase.
139+
*/
140+
nrfx_err_t nrfx_clock_lfclk_calibration_start(void);
141+
142+
/**
143+
* @brief Function for checking if calibration is in progress.
144+
*
145+
* This function indicates that the system is in calibration phase.
146+
*
147+
* @retval NRFX_SUCCESS The procedure is successful.
148+
* @retval NRFX_ERROR_BUSY Clock is in the calibration phase.
149+
*/
150+
nrfx_err_t nrfx_clock_lfclk_calibrating_check(void);
151+
152+
#if (NRF_CLOCK_HAS_CALIBRATION_TIMER && NRFX_CHECK(NRFX_CLOCK_CONFIG_CT_ENABLED)) || \
153+
defined(__NRFX_DOXYGEN__)
154+
/**
155+
* @brief Function for starting calibration timer.
156+
*
157+
* @param[in] interval Time after which the CTTO event and interrupt will be generated (in 0.25 s units).
158+
*/
159+
void nrfx_clock_lfclk_calibration_timer_start(uint8_t interval);
160+
161+
/** @brief Function for stopping the calibration timer. */
162+
void nrfx_clock_lfclk_calibration_timer_stop(void);
163+
#endif
164+
#endif /* ((NRF_CLOCK_HAS_CALIBRATION || NRFX_CHECK(NRF_LFRC_HAS_CALIBRATION)) && \
165+
NRFX_CHECK(NRFX_CLOCK_CONFIG_LF_CAL_ENABLED)) || defined(__NRFX_DOXYGEN__) */
166+
167+
#ifndef NRFX_DECLARE_ONLY
168+
169+
NRFX_STATIC_INLINE bool nrfx_clock_lfclk_running_check(nrf_clock_lfclk_t * p_clk_src)
170+
{
171+
return nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_LFCLK, (void*)p_clk_src);
172+
}
173+
174+
#endif // NRFX_DECLARE_ONLY
175+
176+
/** @} */
177+
178+
void nrfx_clock_lfclk_irq_handler(void);
179+
180+
#ifdef __cplusplus
181+
}
182+
#endif
183+
184+
#endif // NRFX_CLOCK_LFCLK_H__

0 commit comments

Comments
 (0)