drivers: clock_control: nrf54h-common: add utility to obtain LFOSC acc
Add a utility function to obtain LFOSC accuracy in PPM from BICR. Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
parent
5415c42dd4
commit
d5041aecec
2 changed files with 47 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "clock_control_nrf2_common.h"
|
||||
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
|
||||
#include <hal/nrf_bicr.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(clock_control_nrf2, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
|
||||
|
|
@ -19,6 +20,8 @@ LOG_MODULE_REGISTER(clock_control_nrf2, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
|
|||
(idx * sizeof(array[0])) - \
|
||||
offsetof(type, array[0]))
|
||||
|
||||
#define BICR (NRF_BICR_Type *)DT_REG_ADDR(DT_NODELABEL(bicr))
|
||||
|
||||
/*
|
||||
* Definition of `struct clock_config_generic`.
|
||||
* Used to access `clock_config_*` structures in a common way.
|
||||
|
|
@ -83,6 +86,40 @@ static inline uint8_t get_index_of_highest_bit(uint32_t value)
|
|||
return value ? (uint8_t)(31 - __builtin_clz(value)) : 0;
|
||||
}
|
||||
|
||||
int lfosc_get_accuracy(uint16_t *accuracy)
|
||||
{
|
||||
switch (nrf_bicr_lfosc_accuracy_get(BICR)) {
|
||||
case NRF_BICR_LFOSC_ACCURACY_500PPM:
|
||||
*accuracy = 500U;
|
||||
break;
|
||||
case NRF_BICR_LFOSC_ACCURACY_250PPM:
|
||||
*accuracy = 250U;
|
||||
break;
|
||||
case NRF_BICR_LFOSC_ACCURACY_150PPM:
|
||||
*accuracy = 150U;
|
||||
break;
|
||||
case NRF_BICR_LFOSC_ACCURACY_100PPM:
|
||||
*accuracy = 100U;
|
||||
break;
|
||||
case NRF_BICR_LFOSC_ACCURACY_75PPM:
|
||||
*accuracy = 75U;
|
||||
break;
|
||||
case NRF_BICR_LFOSC_ACCURACY_50PPM:
|
||||
*accuracy = 50U;
|
||||
break;
|
||||
case NRF_BICR_LFOSC_ACCURACY_30PPM:
|
||||
*accuracy = 30U;
|
||||
break;
|
||||
case NRF_BICR_LFOSC_ACCURACY_20PPM:
|
||||
*accuracy = 20U;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clock_config_init(void *clk_cfg, uint8_t onoff_cnt, k_work_handler_t update_work_handler)
|
||||
{
|
||||
struct clock_config_generic *cfg = clk_cfg;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,16 @@ struct clock_onoff {
|
|||
struct clock_onoff onoff[_onoff_cnt]; \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtain LFOSC accuracy in ppm.
|
||||
*
|
||||
* @param[out] accuracy Accuracy in ppm.
|
||||
*
|
||||
* @retval 0 On success
|
||||
* @retval -EINVAL If accuracy is not configured.
|
||||
*/
|
||||
int lfosc_get_accuracy(uint16_t *accuracy);
|
||||
|
||||
/**
|
||||
* @brief Initializes a clock configuration structure.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue