-
Notifications
You must be signed in to change notification settings - Fork 202
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
WIP: Use typed clock tokens to configure peripherals #643
base: master
Are you sure you want to change the base?
Conversation
@RobinMcCorkell, I haven't looked at this PR at all, but it sounds like it will overlap with #450, which, believe it or not, is still in the works. We're actually pretty close to publishing it, but I've been short on time at the moment. In general, though, I would suggest starting a discussion topic about any big breaking changes |
That's quite likely, I'm happy to rebase this on top of that branch if it's close to completion. Are discussion topics different from GitHub Issues? There's been no traction on #642 since it was created, so I thought I'd publish some code and see what folks think. It was a useful learning exercise regardless. |
Yes, sorry for the delay on your issue. Most of the maintainers have been pretty busy lately. I think #450 will solve your issue. We have an RtcOsc type to represent the RTC oscillator. And we have plans to integrate it with the rest of the HAL. However, it's only for thumbv7em chips right now. What board are you working on? |
I'm on a thumbv6m chip, but I'm happy to help port the new clock code over once #450 is merged. The core of this PR (using a typed token to initialize the RTC/SERCOM instead of a raw frequency) is separate. |
I've done a port of the clocking v2 stuff here to thumb6m if you're interested in taking a look. I haven't brought in any of the recent updates from here though, but it's working for us quite well so far. |
@sakian and @RobinMcCorkell, #450 has now been merged. If you have a port of it for |
I tried to integrate the new v2 clocking API for thumbv7m with the existing clock API for thumbv6m, but I've hit a roadblock:
I don't know how the design for v2 was established, but I don't see the utility of a source clock token in the type signature of the RTC clock. On both these platforms, the RTC clock is a singleton, there is only ever one RTC clock (which can be configured in one of several ways). As a user of this API, I would like to refer to this singleton RTC clock with a single type, which leans towards the current thumbv6m API rather than the new v2 API. This PR is blocked until there is a way to reconcile these two APIs. |
I have a rough port to thumbv6, but haven't had time to update it since I last posted. I do plan to clean it up and submit a PR. @RobinMcCorkell I believe I ran into that issue as well and fixed in my branch. I'll take a look at how I implemented it when I get back infront of my computer. |
@RobinMcCorkell, in general, the A potential "solution" for a given application is to simply define a type alias type RtcOsc = rtcosc::RtcOsc<Xosc32kId>; Would that be sufficient for your use case? Also note that the |
@sakian, I just skimmed the D21 datasheet. Unfortunately, the |
@RobinMcCorkell, for more information on the design of The |
As per the documentation of "1:1 clocks" which I believe applies here:
This implies I should expect e.g. an A peripheral doesn't really care about the source clock, so let's abstract away from the
Right now, the v2 API requires consumers care about the source clock ID, which IMHO is not optimal. We need a layer of traits to abstract that away (assuming the actual clock struct is going to continue to be generic, in order to support the type-level clock hierarchy as per the docs). |
209eefb
to
a108b3a
Compare
I've pushed a new commit that demos how this might work with the new clocking API. Looking for comments on the approach @bradleyharden @sakian Instead of referencing the actual clock type in the peripheral, it now takes an additional This is kind of like the |
I probably I need to update the When we speak of 1:1 and 1:N clocks, we're talking about the relationship between a clock and it's consumers. You are correct that the RTC clock has a 1:1 relationship with the RTC peripheral. Because of that, the RTC peripheral can simply take ownership of the RTC clock for the duration of its existence. However, in D51 and E5x chips, the potential clock sources for the RTC clock are 1:N clocks. Specifically, they are the XOSC32K and OSCULP32K clocks, which can both be used in several places. To ensure correctness, all consumers of 1:N clocks must track the identity of their corresponding producers. That is why Now that I've done some work on the D21 clocking system, I know that things are a bit different for those chips. In your case, you have to enable a "generic clock" for the RTC, and you have to specify which generic clock generator to use. On D51 chips, "generic clocks" are called "peripheral channel clocks", so we call them On D21 chips, there is no need for an I think I know how to model this correctly in both cases, but I don't think we should make that change until #450 is ported to D21 chips. I've been working on that lately, so I don't think it will be too much longer. |
That makes sense, and aligns with this marker trait idea. Notice the trait implementations: unsafe impl<I: RtcSourceId> RtcClockMarker for RtcOsc<I> {
fn freq(&self) -> Hertz {
self.freq()
}
} I imagine that the D21 equivalent would look like: unsafe impl<G: GclkId> RtcClockMarker for Pclk<RtcId, G> {
fn freq(&self) -> Hertz {
self.freq()
}
} This is of course assuming that the RTC clock (as an Can you verify that what I'm saying is correct? And then, whether the |
a108b3a
to
f119c10
Compare
@RobinMcCorkell, the problem with your approach is that the struct Rtc<M, C>
where
M: RtcMode,
C: RtcClock, With this definition, a concrete instance of the The better way would be to pass on the corresponding To answer your other question, I don't think the
|
Summary
Require a clock token from the generic clock controller Instead of passing around the clock frequency and requiring the user to remember to configure the clocks.
Fixes #642.
Checklist
CHANGELOG.md
for the BSP or HAL updated