-
Notifications
You must be signed in to change notification settings - Fork 215
Changes durations in the time
module to use u64
instead of u32
#820
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
base: master
Are you sure you want to change the base?
Conversation
Interesting! I've not studied the ramifications of this change, but am curious if you've considered something like adding a 64b API to specific methods where someone would be more likely to want a long duration? With these being 32b machines, there will be some ramifications in terms of memory usage, code size, atomicity that we might want to consider here. Particularly, I'm thinking of places like bitbanging drivers that we've seen are already are a bit marginal. |
Yeah that's a good point. A better approach could be to add new types in the I have another project that's keeping me busy for the next month or so, but when I get back to this stuff, how about I go through and assess where |
Great! Yeah, or perhaps there's a reasonable way to use generics to accomplish something similar. Just to be clear - I'm not opposed to switching to 64b time types as this PR currently does, just want to make sure we understand the implications. |
Yeah generics may be more appropriate. I think assessing where this is used will be the first step, then we can decide where to go from there (add a generic parameter or a new |
…for durations instead of `u32` * This allows for delays and durations longer than 4 seconds in parts of the HAL where durations are stored or passed in nanoseconds. * Also ensures that the type defs in the `time` module are used throughout the HAL, as some places still imported and used `fugit` durations explicitly. * Replaces `fugit::ExtU32` in the prelude with `fugit::ExtU64`, and also adds `fugit::ExtU64Ceil`. examples: Updates applicable examples to use the HAL duration types instead of those directly from `fugit` * feather_m0: async_timer * metro_m4: async_timer
@ianrrees I largely finished my other project early, so I had some time to assess this situation. The only duration type actually used within the hal is Searching the HAL, the following methods take a
There are also two helper structs that are affected as well. These calculate a clock divider and number of clock cycles to acheive certain time durations given a clock rate.
Normally, passing a duration that is too long to something that accepts an Assuming this is something that can be resolved in EDIT: I filed an issue with As a side note, regarding both the Really, the |
Thanks for the excellent research and writeup, @kyp44 ! I'm curious to see what results from that Wouldn't worry too much about the The HAL API in general isn't set in stone, and personally I'm a big fan of readable code, so like the ideas of renaming that A low effort thought: it seems like this API is designed around an assumption that the pub trait InterruptDrivenTimer {
...
fn start<T: Into<NanosDurationU32>>(&mut self, timeout: T);
...
} Maybe we need separate methods which are a bit more explicit - something like the DelayNs API: fn start_ns(&mut self, timeout: u32);
fn start_ms(&mut self, timeout: u32); // 49 days should be enough... |
There is a synchronous version of the There seem to be two ways to specify delay/timer durations: one is the above, and the other is by passing I would propose the following, which I can work on:
Thoughts? |
That sounds like a good plan to me, thanks! |
Summary
Currently many time durations pass/stored throughout the HAL use nanoseconds for maximum precision. However these are stored using a
u32
for a maximum of about 4 seconds. Since delays/times longer than this could be useful and should be possible, this changes all type defs in thetime
module to useu64
instead, extending the maximum time (when stored as nanoseconds) to over 584 years.There were also several places in the HAL that import
fugit
duration types directly. These were changed to use the type defs in thetime
time module instead so that the entire HAL uses these exclusively.See the commit message for more details.
Note that the rate/frequency types defined in
time
still useu32
as rates above 4 GHz are not likely to be useful.Also note that this is a breaking change.
Checklist
#[allow]
certain lints where reasonable, but ideally justify those with a short comment.