-
Notifications
You must be signed in to change notification settings - Fork 8.4k
drivers: sensor: Add sensor clock API support #80189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: sensor: Add sensor clock API support #80189
Conversation
|
Hello @CienetmarkChen, and thank you very much for your first pull request to the Zephyr project! |
04a9e31 to
930b227
Compare
|
@CienetmarkChen Can you elaborate on the problem you're trying to solve with this PR? I am not sure I understand. Thanks! |
|
Hi kartben, RFC: #63651 |
930b227 to
9784107
Compare
yperess
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update existing drivers which use the async API to leverage this sensor_clock?
1ae0322 to
39b9f0a
Compare
yperess
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@teburd @MaureenHelm this seems good to me now, when you can, could you take a look?
|
I think this is ok, though because we're doing cycles solely, its quite possible to roll-over quickly in some cases. E.g. a 32bit cycle counter going at 1ghz (e.g. imxrt1176 cm7 core) will roll over every... ~4 seconds. I don't know if this is something we need to care about yet, but certainly some issue should be noted that this might be an issue that needs addressing. |
Yeah, I think we need to have a how-to guide for designing your sensor clocks. Like if your system clock is running 1gHz with a 32 bit counter but your sensors only run at 400Hz, having an external clock that's closer to 400Hz makes a lot of sense to avoid that roll-over. |
|
@MaureenHelm Any blocker here? |
|
Can this merge? It's getting stale and there's more work building on top of it. |
let's page @MaureenHelm once more then :) |
MaureenHelm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update existing drivers which use the async API to leverage this sensor_clock?
There are a few existing drivers missing this update (ADI and ST)
|
@MaureenHelm would you be able to take another pass at this one? I believe they've addressed your concerns. |
MaureenHelm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I didn't catch this before, but the sample needs an README.rst. Everything else looks good.
|
We should link this PR to #63651 |
This commit introduces a new Sensor Clock API, enabling the retrieval of cycle counts and conversion to nanoseconds based on the system or external clock. The API includes: - `sensor_clock_get_cycles()` to get the current cycle count from the sensor clock. - `sensor_clock_cycles_to_ns()` to convert cycles to nanoseconds using the clock's frequency. The implementation supports both system clocks and external clocks defined in the device tree, making the sensor clock integration more flexible for various sensor use cases. Signed-off-by: Mark Chen <[email protected]>
fb6f4ae
5e0e68f to
fb6f4ae
Compare
Hi @MaureenHelm , |
kartben
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @MaureenHelm for spotting the missing README :)
|
Hi @CienetmarkChen! To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge. Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁 |
| rc = sensor_clock_get_cycles(&cycles); | ||
| if (rc != 0) { | ||
| LOG_ERR("Failed to get sensor clock cycles"); | ||
| rtio_iodev_sqe_err(drv_data->streaming_sqe, err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This driver no longer builds due to use of err instead of what I assume was meant to be rc. Will open PR to fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zephyr/drivers/sensor/tdk/icm42688/icm42688_rtio_stream.c:305:61: error: 'err' undeclared (first use in this function)
305 | rtio_iodev_sqe_err(drv_data->streaming_sqe, err);
| ^~~
This commit introduces a new Sensor Clock API, enabling the retrieval of cycle counts and conversion to nanoseconds based on the system or external clock. The API includes:
sensor_clock_get_cycles()to get the current cycle count from the sensor clock.sensor_clock_cycles_to_ns()to convert cycles to nanoseconds using the clock's frequency.The implementation supports both system clocks and external clocks defined in the device tree, making the sensor clock integration more flexible for various sensor use cases.