-
Notifications
You must be signed in to change notification settings - Fork 234
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
ClockManager "partial move" with RealTimeClock #724
Comments
I just found something very strange... Why does the rp-hal/rp2040-hal/src/rtc/mod.rs Line 68 in cfd6c12
|
Hi,
In some cases this is to (try to) prevent other parts of the firmware from changing the frequency/settings of the clock source. The clock related code is admittedly not yet very polished. On the other hand, this is a fairly complex topic to address as not all solutions are really practical for the common usecase the hal is used in (eg RTIC application, low power/deepsleep, some level of DFS) while still meeting the requirement from the hardware interms of clock state, stability, and dependencies. We welcome contributions that could help resolve (at least some of) the issues. |
Hi,
Indeed, it makes sense, but in this case it invalidates the ClockManager, and IMO that's not a good idea. I therefore see three solutions to this problem:
The last solution is the simplest, and the hal seems to work this way (for example, the |
I just found there is a similar idea in UsbBus... Line 441 in cfd6c12
Once again it invalidate your ClockManager, and you lost (forever) the |
The typical flow is to:
Taking ownership of the clock implicitly freezes the clock's settings. If a user desires the change the clock's config, they'd need to recover those clocks (by disabling or freeing the peripherals), do what ever they want with the clock, and then reenabling or reconstructing the peripheral(s). We could apply such pattern over all the drivers, but implementing this would be an endeavour going beyond my current time capacity. |
I don't totally agree with the idea of blocking clocks when a device is instantiated. In my mind, clocks remain independent of devices, and changing a clock doesn't necessarily impact the operation of the device. It might even be possible to disable (or reduce the speed of) a device if necessary (if only temporarily, as I think that's how it's presented in the datasheet). |
From my point of view, the API should prevent easy mistakes like forgetting to initialize a clock that's needed for a peripheral, or changing a clock that's in use by a peripheral by accident, eg. due to some copy & paste mistake. That goal is covered by the current API quite well. But then, the API should not prevent more advanced use cases where the clocks are intentionally changed while being in use. Ideally, such a facility should still only allow changes that are supported by the hardware. But if it is too difficult to distinguish between valid and invalid changes programmatically, adding more "dangerous" methods would be fine as well, as long as they are clearly recognizable as such. Eg. by giving them names like Currently, the only way to get around the API limitations is using |
Well, USB is a good example for that matter. If you stop the USB clock, you effectively break the communication with any connected host.
You can indeed stop or reduce the speed of a clock according to the datasheet. Changing the frequency of that clock, breaks an invariant and the driver's guaranties are rendered obsolete without any way to let the developer know about it. What I'd like to achieve is not necessarily a perfect API but at least something that prevents easy foot guns such as stopping or changing the frequency of a clock while a peripheral is in operation (eg changing the baudrate in the middle of a transmit/receive). |
Exactly! You deactivate the clocks, so the USB is stopped, and when you restart your clock the USB resumes. It seems to me that this is the very use case for I quite agree with @jannic that this seems a good compromise. There should be a system in the ClockManager that checks whether a clock is "busy". But under no circumstances should a clock be "owned" by another instance. So we could imagine having |
It doesn't
Indeed, what I refered to earlier is one solution to that.
I don't agree with that statement though. This seems to be a strong statement without strong reasons beyond
Indeed, that could be a satisfying "temporary" solution until something better is proposed. |
Sorry, English isn't my mother tongue, and in translation, certain terms can become a bit... excessive ^^. I honestly don't know how to create such a mechanism. But to avoid any breaking changes, I suggest modifying my PR and adding the |
Partial fix with #725 |
Hello,
I'm using the main version to put the rp2040 in deepsleep. All in all it works great, but I have a small problem.
When I create a
RealTimeClock
object I have to give it ownership over theRtcClock
in myClockManager
. From then on, I can no longer pass myClockManager
as a parameter (&mut
) to any function... Because the borrow checker tells me that the object ispartial move
.How can I get round this problem?
I used the example https://github.com/rp-rs/rp-hal/blob/cfd6c128a1688186f419e3bd60ce469ddeb7fb47/rp2040-hal/examples/rtc_irq_example.rs.
Here is a simplified code example.
I did try to make my own
ClockManager
, withOption<T>
for each field, but I find it a bit cumbersome and there are a lot of macros on the original!Can you help me ? Maybe there is something I don't understand with Rust ^^
Thanks !
The text was updated successfully, but these errors were encountered: