Updated: April 19, 2023 |
Sensor timestamps can be based on a reference time provided by an external clock library.
You may provide your own external clock library that provides a reference time for sensor timestamps. To do so, you must:
... sensor_error_t reference_clock_open(sensor_unit_t unit) { ... return SENSOR_EOK; } ...
... sensor_error_t reference_clock_close(sensor_unit_t unit) { ... return SENSOR_EOK; } ...
... sensor_error_t reference_clock_get_time(sensor_unit_t unit, int64_t *timestamp) { ... static const int64_t NS_PER_SECOND = 1000000000; ... struct timespec tp; if (clock_gettime(CLOCK_REALTIME, &tp) == -1) { return SENSOR_EINVAL; } *timestamp = (tp.tv_sec * NS_PER_SECOND + tp.tv_nsec) / 1000; return SENSOR_EOK; } ...
For example:
... sensor_ext_reference_clock_t reference_clock_defs = { reference_clock_open, reference_clock_get_time, reference_clock_close }; ...
The Sensor service dynamically loads this structure to retrieve the function pointers so that it can interface with your external clock library.
See the Sensor configuration file section in the Sensor Framework Services guide.
You can configure each sensor to use a different external clock library, or multiple sensors to share one external clock library. You may provide multiple external clock libraries.