-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add Duration and Instant support to Rust. #1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zephyrproject-rtos/zephyr#78306 incorporates this PR into Zephyr, notably the CI results can be seen there. |
ithinuel
approved these changes
Sep 12, 2024
The fugit crate implements tick-based timers, providing a `Duration` and `Instant` type that we can use for timeouts. This is an external crate, covered under the Apache-2.0 or MIT license. This will need to be vendored due to Rust policies. Signed-off-by: David Brown <david.brown@linaro.org>
The `zephyr-sys` crate contains all of the generated bindings to the C API in Zephyr. The `zephyr::sys` module wraps these abstractions in as thin of a way as possible, but still allowing them to be used without 'unsafe'. Although the interfaces are "safe", because they are just wrappers around C calls, most aren't directly useful without unsafe, and this crate provides higher-level abstractions around these underlying primitives. This commit adds a definition for `K_FOREVER`, and `K_NO_WAIT`, which are too complicated for bindgen to autogenerate bindings for. We will rely on a test to ensure that the values match those in the C headers. Signed-off-by: David Brown <david.brown@linaro.org>
Use specific instances of `fugit::Duration` and `fugit::Instant`, with the clock parameter based on the configured clock rate. As the fugit times are fixed, this precludes using these time types with dynamically changing clocks. With this, is a local Timeout type that simply wraps `k_timeout_t`. Having this wrapper allows us to implement `From` from each of the timeout types. The zephyr timeout type can support either durations or instants, as well as two magic times, forever and no wait. Forever and NoWait are implemented as singleton types that also have conversions. The `zephyr::time::sleep` function then can take anything that can be converted to this wrapped Timeout type, including Forever, and NoWait. This template will be used for future API calls that need a timeout. Signed-off-by: David Brown <david.brown@linaro.org>
Rewrite the doc comment for `zephyr::time`. A little bit of LLM help and this is much clearer. Signed-off-by: David Brown <david.brown@linaro.org>
Add a test to test that the time values in Rust (Duration and Instance) and up calculating the same results as the various macros used in the C code. Signed-off-by: David Brown <david.brown@linaro.org>
If we have printk enabled, use that to output the desperation panic message when panic is called from Rust code. Signed-off-by: David Brown <david.brown@linaro.org>
Too much rust code formatting leaks into my C. Fix these various whitespace errors. Signed-off-by: David Brown <david.brown@linaro.org>
When the panic happens, call into the Zephyr `k_panic()` handler instead of just spinning. This should halt the whole system, not just the current thread. Signed-off-by: David Brown <david.brown@linaro.org>
Add some additional comments to clarify that not all of the fields are used for all of the test types. Signed-off-by: David Brown <david.brown@linaro.org>
When debug assertions are enabled, ensure that the time conversions are sensible. If there is an overflow on time with the assertions disabled, just use Default, which will be zero. Signed-off-by: David Brown <david.brown@linaro.org>
Comment cleanups. Fix several minor typos in the comments. Signed-off-by: David Brown <david.brown@linaro.org>
Indicate that we have test in this module. CI will run these automatically when the module changes. Signed-off-by: David Brown <david.brown@linaro.org>
Now that we've added a test, test these as well. Signed-off-by: David Brown <david.brown@linaro.org>
This is the same code as zephyrproject-rtos/zephyr#78193, which as an approval from @sigvarthmh, and there is the one from ithinuel so I'll consider this as having two approvals. |
This was referenced Sep 24, 2024
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a migration of the open PR zephyrproject-rtos/zephyr#78193. To the module version. The only changes from that PR are the squashing a few of the fixup commits.