Skip to content

Commit 1095cb4

Browse files
kapi-norlubos
authored andcommitted
drivers: sensor: migrate simulated sensors to DEVICE_API
Upstream Zephyr moved device API structs into per-class iterable linker sections and made the sensor accessors resolve the API through DEVICE_API_GET(sensor, dev). With CONFIG_DEVICE_API_ASSERT enabled (default when CONFIG_ASSERT=y) this asserts that dev->api points inside the _sensor_driver_api section, otherwise it fails at runtime with "device API is not sensor". The Nordic sensor_sim and sensor_stub drivers still declared their API as a plain "static const struct sensor_driver_api", so the struct was not placed in that section and the assert fired the first time the CAF sensor manager called sensor_sample_fetch(). This broke the caf_sensor_manager.core test (sensor_sim) and the caf_sensor_manager sample (sensor_stub) on qemu_cortex_m3 after the upmerge. Declared both driver APIs with DEVICE_API(sensor, ...), matching the idiom used by all upstream sensor drivers, so the API lands in the _sensor_driver_api iterable section and passes the runtime check. Ref: NCSDK-40421 Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
1 parent 522130a commit 1095cb4

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/sensor/sensor_sim/sensor_sim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static int sensor_sim_channel_get(const struct device *dev,
519519
return 0;
520520
}
521521

522-
static const struct sensor_driver_api sensor_sim_api_funcs = {
522+
static DEVICE_API(sensor, sensor_sim_api_funcs) = {
523523
.sample_fetch = sensor_sim_sample_fetch,
524524
.channel_get = sensor_sim_channel_get,
525525
#if defined(CONFIG_SENSOR_SIM_TRIGGER)

drivers/sensor/sensor_stub/sensor_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int sensor_stub_init(const struct device *dev)
6262
extern int _CONCAT(DT_STRING_TOKEN(DT_DRV_INST(_idx), generator), _init)( \
6363
const struct device *dev); \
6464
\
65-
static const struct sensor_driver_api sensor_stub_api_funcs_##_idx = { \
65+
static DEVICE_API(sensor, sensor_stub_api_funcs_##_idx) = { \
6666
.sample_fetch = _CONCAT(DT_STRING_TOKEN(DT_DRV_INST(_idx), generator), _fetch), \
6767
.channel_get = _CONCAT(DT_STRING_TOKEN(DT_DRV_INST(_idx), generator), _get) \
6868
}; \

0 commit comments

Comments
 (0)