Skip to content

Commit 0612dd4

Browse files
gmarullcarlescufi
authored andcommitted
drivers: clock_control: nrf: fix temperature sensor usage
The temperature sensor was only needed when CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP > 0. Implementation did not reflect this dependency correctly, and sensor sampling code was always compiled. Also removed CONFIG_MULTITHREADING checks, since this driver is only compiled if CONFIG_MULTITHREADING=y. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 0cd311c commit 0612dd4

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

drivers/clock_control/nrf_clock_calibration.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,21 @@ static void cal_lf_callback(struct onoff_manager *mgr,
4848
static struct onoff_client cli;
4949
static struct onoff_manager *mgrs;
5050

51+
/* Temperature sensor is only needed if
52+
* CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP > 0, since a value of 0
53+
* indicates performing calibration periodically regardless of temperature
54+
* change.
55+
*/
56+
#define USE_TEMP_SENSOR \
57+
(CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP > 0)
58+
59+
#if USE_TEMP_SENSOR
5160
static const struct device *const temp_sensor =
5261
DEVICE_DT_GET_OR_NULL(DT_INST(0, nordic_nrf_temp));
5362

5463
static void measure_temperature(struct k_work *work);
5564
static K_WORK_DEFINE(temp_measure_work, measure_temperature);
65+
#endif /* USE_TEMP_SENSOR */
5666

5767
static void timeout_handler(struct k_timer *timer);
5868
static K_TIMER_DEFINE(backoff_timer, timeout_handler, NULL);
@@ -155,13 +165,18 @@ static void cal_hf_callback(struct onoff_manager *mgr,
155165
struct onoff_client *cli,
156166
uint32_t state, int res)
157167
{
158-
if ((temp_sensor == NULL) || !IS_ENABLED(CONFIG_MULTITHREADING)) {
168+
#if USE_TEMP_SENSOR
169+
if (!device_is_ready(temp_sensor)) {
159170
start_hw_cal();
160171
} else {
161172
k_work_submit(&temp_measure_work);
162173
}
174+
#else
175+
start_hw_cal();
176+
#endif /* USE_TEMP_SENSOR */
163177
}
164178

179+
#if USE_TEMP_SENSOR
165180
/* Convert sensor value to 0.25'C units. */
166181
static inline int16_t sensor_value_to_temp_unit(struct sensor_value *val)
167182
{
@@ -218,6 +233,7 @@ static void measure_temperature(struct k_work *work)
218233
LOG_DBG("Calibration %s. Temperature diff: %d (in 0.25'C units).",
219234
started ? "started" : "skipped", diff);
220235
}
236+
#endif /* USE_TEMP_SENSOR */
221237

222238
void z_nrf_clock_calibration_init(struct onoff_manager *onoff_mgrs)
223239
{
@@ -226,20 +242,6 @@ void z_nrf_clock_calibration_init(struct onoff_manager *onoff_mgrs)
226242
total_skips_cnt = 0;
227243
}
228244

229-
#if CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP
230-
static int temp_sensor_init(const struct device *arg)
231-
{
232-
if ((temp_sensor != NULL) && !device_is_ready(temp_sensor)) {
233-
LOG_ERR("Temperature sensor not ready");
234-
return -ENODEV;
235-
}
236-
237-
return 0;
238-
}
239-
240-
SYS_INIT(temp_sensor_init, APPLICATION, 0);
241-
#endif /* CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_MAX_SKIP */
242-
243245
static void start_unconditional_cal_process(void)
244246
{
245247
calib_skip_cnt = 0;

0 commit comments

Comments
 (0)