Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 33 additions & 94 deletions nrfx/drivers/include/nrfx_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
#if defined(LFRC_PRESENT)
#include <hal/nrf_lfrc.h>
#endif
#if NRF_CLOCK_HAS_HFCLK
#include <nrfx_clock_hfclk.h>
#endif
#if NRF_CLOCK_HAS_XO
#include <nrfx_clock_xo.h>
#endif
#include <nrfx_clock_lfclk.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -58,19 +65,20 @@ extern "C" {
/** @brief Clock events. */
typedef enum
{
NRFX_CLOCK_EVT_HFCLK_STARTED = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_HF_STARTED_MASK), ///< HFCLK has been started.
#if NRF_CLOCK_HAS_HFCLK
NRFX_CLOCK_EVT_HFCLK_STARTED = NRFX_CLOCK_HFCLK_EVT_HFCLK_STARTED, ///< HFCLK has been started.
#else
NRFX_CLOCK_EVT_HFCLK_STARTED = NRFX_CLOCK_XO_EVT_HFCLK_STARTED, ///< HFCLK has been started.
#endif
#if NRF_CLOCK_HAS_PLL
NRFX_CLOCK_EVT_PLL_STARTED = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_PLL_STARTED_MASK), ///< PLL has been started.
NRFX_CLOCK_EVT_PLL_STARTED = NRFX_CLOCK_XO_EVT_PLL_STARTED, ///< PLL has been started.
#endif
NRFX_CLOCK_EVT_LFCLK_STARTED = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_LF_STARTED_MASK), ///< LFCLK has been started.
NRFX_CLOCK_EVT_LFCLK_STARTED = NRFX_CLOCK_LFCLK_EVT_LFCLK_STARTED, ///< LFCLK has been started.
#if NRF_CLOCK_HAS_CALIBRATION_TIMER
NRFX_CLOCK_EVT_CTTO = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_CTTO_MASK), ///< Calibration timeout.
NRFX_CLOCK_EVT_CTTO = NRFX_CLOCK_LFCLK_EVT_CTTO, ///< Calibration timeout.
#endif
#if NRF_CLOCK_HAS_CALIBRATION
NRFX_CLOCK_EVT_CAL_DONE = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_DONE_MASK), ///< Calibration has been done.
#elif NRFX_CHECK(NRF_LFRC_HAS_CALIBRATION)
NRFX_CLOCK_EVT_CAL_DONE = (NRFX_BITMASK_TO_BITPOS(NRF_LFRC_INT_CALDONE_MASK) + \
NRFX_CLOCK_LFRC_EVT_OFFSET), ///< Calibration has been done.
#if NRF_CLOCK_HAS_CALIBRATION || NRFX_CHECK(NRF_LFRC_HAS_CALIBRATION)
NRFX_CLOCK_EVT_CAL_DONE = NRFX_CLOCK_LFCLK_EVT_CAL_DONE, ///< Calibration has been done.
#endif
#if NRF_CLOCK_HAS_HFCLKAUDIO
NRFX_CLOCK_EVT_HFCLKAUDIO_STARTED = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_HFAUDIO_STARTED_MASK), ///< HFCLKAUDIO has been started.
Expand All @@ -82,9 +90,9 @@ typedef enum
NRFX_CLOCK_EVT_HFCLK192M_STARTED = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_HF192M_STARTED_MASK), ///< HFCLK192M has been started.
#endif
#if NRF_CLOCK_HAS_XO_TUNE
NRFX_CLOCK_EVT_XO_TUNED = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_XOTUNED_MASK), ///< XO tune has been done.
NRFX_CLOCK_EVT_XO_TUNE_ERROR = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_XOTUNEERROR_MASK), ///< XO is not tuned.
NRFX_CLOCK_EVT_XO_TUNE_FAILED = NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_XOTUNEFAILED_MASK), ///< XO tune operation failed.
NRFX_CLOCK_EVT_XO_TUNED = NRFX_CLOCK_XO_EVT_XO_TUNED, ///< XO tune has been done.
NRFX_CLOCK_EVT_XO_TUNE_ERROR = NRFX_CLOCK_XO_EVT_XO_TUNE_ERROR, ///< XO is not tuned.
NRFX_CLOCK_EVT_XO_TUNE_FAILED = NRFX_CLOCK_XO_EVT_XO_TUNE_FAILED, ///< XO tune operation failed.
#endif
} nrfx_clock_evt_type_t;

Expand Down Expand Up @@ -181,55 +189,6 @@ nrfx_err_t nrfx_clock_divider_set(nrf_clock_domain_t domain,
NRFX_STATIC_INLINE nrf_clock_hfclk_div_t nrfx_clock_divider_get(nrf_clock_domain_t domain);
#endif

/**
* @brief Function for starting the LFCLK.
*
* @note This function is deprecated. Use @ref nrfx_clock_start instead.
*/
NRFX_STATIC_INLINE void nrfx_clock_lfclk_start(void);

/**
* @brief Function for stopping the LFCLK.
*
* @note This function is deprecated. Use @ref nrfx_clock_stop instead.
*/
NRFX_STATIC_INLINE void nrfx_clock_lfclk_stop(void);

/**
* @brief Function for checking the LFCLK state.
*
* @note This function is deprecated. Use @ref nrfx_clock_is_running instead.
*
* @retval true The LFCLK is running.
* @retval false The LFCLK is not running.
*/
NRFX_STATIC_INLINE bool nrfx_clock_lfclk_is_running(void);

/**
* @brief Function for starting the high-accuracy source HFCLK.
*
* @note This function is deprecated. Use @ref nrfx_clock_start instead.
*/
NRFX_STATIC_INLINE void nrfx_clock_hfclk_start(void);

/**
* @brief Function for stopping the external high-accuracy source HFCLK.
*
* @note This function is deprecated. Use @ref nrfx_clock_stop instead.
*/
NRFX_STATIC_INLINE void nrfx_clock_hfclk_stop(void);

/**
* @brief Function for checking the HFCLK state.
*
* @note This function is deprecated. Use @ref nrfx_clock_is_running instead.
*
* @retval true The HFCLK is running (XTAL source).
* @retval false The HFCLK is not running.
*/
NRFX_STATIC_INLINE bool nrfx_clock_hfclk_is_running(void);


#if NRF_CLOCK_HAS_HFCLKAUDIO || defined(__NRFX_DOXYGEN__)
/**
* @brief Function for setting the HFCLKAUDIO configuration.
Expand Down Expand Up @@ -379,26 +338,6 @@ NRFX_STATIC_INLINE nrf_clock_hfclk_div_t nrfx_clock_divider_get(nrf_clock_domain
}
#endif // defined(CLOCK_FEATURE_HFCLK_DIVIDE_PRESENT) || NRF_CLOCK_HAS_HFCLK192M

NRFX_STATIC_INLINE void nrfx_clock_lfclk_start(void)
{
nrfx_clock_start(NRF_CLOCK_DOMAIN_LFCLK);
}

NRFX_STATIC_INLINE void nrfx_clock_lfclk_stop(void)
{
nrfx_clock_stop(NRF_CLOCK_DOMAIN_LFCLK);
}

NRFX_STATIC_INLINE void nrfx_clock_hfclk_start(void)
{
nrfx_clock_start(NRF_CLOCK_DOMAIN_HFCLK);
}

NRFX_STATIC_INLINE void nrfx_clock_hfclk_stop(void)
{
nrfx_clock_stop(NRF_CLOCK_DOMAIN_HFCLK);
}

NRFX_STATIC_INLINE uint32_t nrfx_clock_task_address_get(nrf_clock_task_t task)
{
return nrf_clock_task_address_get(NRF_CLOCK, task);
Expand All @@ -411,19 +350,19 @@ NRFX_STATIC_INLINE uint32_t nrfx_clock_event_address_get(nrf_clock_event_t event

NRFX_STATIC_INLINE bool nrfx_clock_is_running(nrf_clock_domain_t domain, void * p_clk_src)
{
return nrf_clock_is_running(NRF_CLOCK, domain, p_clk_src);
}

NRFX_STATIC_INLINE bool nrfx_clock_hfclk_is_running(void)
{
nrf_clock_hfclk_t clk_src;
bool ret = nrfx_clock_is_running(NRF_CLOCK_DOMAIN_HFCLK, &clk_src);
return (ret && (clk_src == NRF_CLOCK_HFCLK_HIGH_ACCURACY));
}

NRFX_STATIC_INLINE bool nrfx_clock_lfclk_is_running(void)
{
return nrfx_clock_is_running(NRF_CLOCK_DOMAIN_LFCLK, NULL);
switch(domain)
{
case NRF_CLOCK_DOMAIN_HFCLK:
#if NRF_CLOCK_HAS_HFCLK
return nrfx_clock_hfclk_running_check(p_clk_src);
#elif NRF_CLOCK_HAS_XO
return nrfx_clock_xo_running_check(p_clk_src);
#endif
case NRF_CLOCK_DOMAIN_LFCLK:
return nrfx_clock_lfclk_running_check(p_clk_src);
default:
return nrf_clock_is_running(NRF_CLOCK, domain, p_clk_src);
}
}

#if NRF_CLOCK_HAS_HFCLKAUDIO
Expand Down
69 changes: 69 additions & 0 deletions nrfx/drivers/include/nrfx_clock_hfclk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*$$$LICENCE_NORDIC_STANDARD<2025>$$$*/

#ifndef NRFX_CLOCK_HFCLK_H__
#define NRFX_CLOCK_HFCLK_H__

#include <hal/nrf_clock.h>

#define NRFX_CLOCK_HFCLK_EVT_HFCLK_STARTED NRFX_BITMASK_TO_BITPOS(NRF_CLOCK_INT_HF_STARTED_MASK)

/**
* @brief Clock event handler.
*
* @param[in] event Event.
*/
typedef void (*nrfx_clock_hfclk_event_handler_t)(void);

/**
* @brief Function for initializing internal structures in the nrfx_clock_hfclk module.
*
* After initialization, the module is in power off state (clock is not started).
*
* @param[in] event_handler Event handler provided by the user.
* If not provided, driver works in blocking mode.
*
* @retval NRFX_SUCCESS The procedure is successful.
* @retval NRFX_ERROR_ALREADY The driver is already initialized.
*/
nrfx_err_t nrfx_clock_hfclk_init(nrfx_clock_hfclk_event_handler_t event_handler);

/** @brief Function for uninitializing the clock module. */
void nrfx_clock_hfclk_uninit(void);

/** @brief Function for starting the hfclk clock domain. */
void nrfx_clock_hfclk_start(void);

/** @brief Function for stopping the hfclk clock domain. */
void nrfx_clock_hfclk_stop(void);

#if defined(CLOCK_FEATURE_HFCLK_DIVIDE_PRESENT)
/**
* @brief Function for setting the hfclk divider.
*
* @param[in] div New divider for the hfclk.
*
* @retval NRFX_SUCCESS Divider successfully set.
* @retval NRFX_ERROR_INVALID_PARAM Divider not supported by the specified domain.
*/
nrfx_err_t nrfx_clock_hfclk_divider_set(nrf_clock_hfclk_div_t div);
#endif

/**
* @brief Function for checking the hfclk state.
*
* @param[out] p_clk_src Pointer to a clock source that is running.
*
* @retval true The hfclk is running.
* @retval false The hfclk is not running.
*/
NRFX_STATIC_INLINE bool nrfx_clock_hfclk_running_check(nrf_clock_hfclk_t * p_clk_src);

void nrfx_clock_hfclk_irq_handler(void);

NRFX_STATIC_INLINE bool nrfx_clock_hfclk_running_check(nrf_clock_hfclk_t * p_clk_src)
{
bool ret = nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK, p_clk_src);
return (ret && (*p_clk_src == NRF_CLOCK_HFCLK_HIGH_ACCURACY));
}

#endif // NRFX_CLOCK_HFCLK_H__
Loading