Skip to content

Commit 6700f2f

Browse files
nordic-krchcarlescufi
authored andcommitted
drivers: clock_control: nrf: reimplementation including API updates
Reimplementation of clock control driver for nrf platform. It includes latest API changes: asynchronous starting and getting clock status. Additionally, it implements calibration algorithm which optionally skips calibration based on no temperature change. Internal temperature sensor is used for that. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent a5e4d36 commit 6700f2f

File tree

8 files changed

+755
-412
lines changed

8 files changed

+755
-412
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
/drivers/bluetooth/ @joerchan @jhedberg @Vudentz
118118
/drivers/can/ @alexanderwachter
119119
/drivers/can/*mcp2515* @karstenkoenig
120+
/drivers/clock_control/*nrf* @nordic-krch
120121
/drivers/counter/ @nordic-krch
121122
/drivers/counter/counter_cmos.c @gnuless
122123
/drivers/display/ @vanwinkeljan

drivers/clock_control/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_MCUX_PCC clock_control_mcux
77
zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_MCUX_SCG clock_control_mcux_scg.c)
88
zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_MCUX_SIM clock_control_mcux_sim.c)
99
zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_NRF nrf_power_clock.c)
10+
zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION nrf_clock_calibration.c)
1011
zephyr_sources_ifdef(CONFIG_CLOCK_CONTROL_RV32M1_PCC clock_control_rv32m1_pcc.c)
1112

1213
if(CONFIG_CLOCK_CONTROL_STM32_CUBE)

drivers/clock_control/Kconfig.nrf

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,57 @@ config CLOCK_CONTROL_NRF_K32SRC_EXT_FULL_SWING
4747

4848
endchoice
4949

50-
config CLOCK_CONTROL_NRF_K32SRC_BLOCKING
51-
bool "Blocking 32KHz crystal oscillator startup"
52-
depends on CLOCK_CONTROL_NRF_K32SRC_XTAL
50+
config CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION
51+
bool
52+
depends on !SOC_SERIES_NRF91X
53+
default y if CLOCK_CONTROL_NRF_K32SRC_RC
54+
55+
if CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION
56+
57+
config CLOCK_CONTROL_NRF_CALIBRATION_PERIOD
58+
int "Calibration opportunity period (in 250ms units)"
59+
default 16
60+
range 1 127
61+
help
62+
Periodically, calibration action is performed. Action includes
63+
temperature measurement followed by clock calibration. Calibration may
64+
be skipped if temperature change (compared to measurement of previous
65+
calibration) did not exceeded CLOCK_CONTROL_NRF_CALIBRATION_TEMP_DIFF
66+
and number of consecutive skips did not exceeded
67+
CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP.
68+
69+
config CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP
70+
int "Maximum number of calibration skips"
71+
default 1
72+
range 0 255
73+
help
74+
Calibration is skipped when temperature change since last calibration
75+
was less than configured threshold. If number of consecutive skips
76+
reaches configured value then calibration is performed
77+
unconditionally. Set to 0 to perform calibration periodically
78+
regardless of temperature change.
79+
80+
config CLOCK_CONTROL_NRF_CALIBRATION_TEMP_DIFF
81+
int "Temperature change triggering calibration (in 0.25 degree units)"
82+
default 2
5383
help
54-
Clock control driver will spin wait in CPU sleep until 32KHz
55-
crystal oscillator starts up. If not enabled, RC oscillator will
56-
initially start running and automatically switch to crystal when
57-
ready.
84+
Calibration is triggered if the temperature has changed by at least
85+
this amount since the last calibration.
86+
87+
config CLOCK_CONTROL_NRF_CALIBRATION_DEBUG
88+
bool "Calibration intrumentation"
89+
help
90+
Enables retrieving debug information like number of performed or
91+
skipped calibrations.
92+
93+
config CLOCK_CONTROL_NRF_USES_TEMP_SENSOR
94+
bool
95+
default y if CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP > 0 && \
96+
CLOCK_CONTROL_NRF_CALIBRATION_TEMP_DIFF > 0
97+
select TEMP_NRF5
98+
select SENSOR
99+
100+
endif # CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION
58101

59102
choice CLOCK_CONTROL_NRF_ACCURACY
60103
prompt "32KHz clock accuracy"

0 commit comments

Comments
 (0)