doc/memos: RDM on a unified low-level timer-API#15046
doc/memos: RDM on a unified low-level timer-API#15046ngandrass wants to merge 1 commit intoRIOT-OS:masterfrom
Conversation
|
Suggested tags:
Suggested reviewers: |
|
I only briefly skimmed the first part of the RDM, but I have some feedback for the stated goal of the RDM. So far in RIOT, low level APIs where designed to match and reflect the properties of the underlying hardware as good as possible, so that implementations get lean and efficient. E.g.:
To be honest, I don't really like the idea of a low level unified API. I think this will result in:
IMO, if you want an unified API to access timer hardware, it should be based on top of the periph APIs. E.g. the The advantage of a unified API on top would be:
|
|
I think an overhaul of the timer API is a worthy endeavour. Right now the periph timer API seems like it was tailored to xtimer (or some other high level timer) with the focus on one-shot events and relative sets, up-counting only. The RTT API leaves out if functions not implemented by the hardware should be emulated in software or left out entirely (see discussion in #13630). I would leave out the RTC in this discussion / RDM. RTC can be implemented on top of an RTT if there is no hardware implementation. It behaves different than a simple timer / counter. The Watchdog also serves an entirely different purpose, let's leave this out of scope. I've also skimmed the RDM and it looks like so far there is only a description of what hardware timers there are, but no proposal yet as to how such a unified API would look. Keep in mind that this will be a large undertaking. |
A dynamic resource management for timers sounds like a recipe for disaster. The complexity of this is hardly ever needed, but paid by everyone in terms of increases RAM and ROM consumption, severe degeneration of real time capabilities, increased number of bugs and maintenance. Let's assume we have 3 timers. One is used for for a high level timer API to implement software timers, one is used to generate PWM, and one is used to generate periodic IRQs for a driver with strict accuracy requirements. Let's also assume that only one of the three hardware timers can be used for PWM and only one has the ability to natively generate periodic timeout IRQs. If we now use dynamic run time allocation, we have to reflect the abilities of each timer correctly and extend the request API to request timers with specific capabilities. Let's assume the PWM is currently unused and the a software timer is set, for which the now unused PWM-capabile timer is used. If aftwards PWM is needed, we would have to a) Wait until the software timer run on the PWM capible hardware timer expires. Also: Mixing the use of one hardware timer per
That's a good argument to extend the
I see no reason that prevents sharing code between both APIs. But if the APIs of |
|
First of all thank you both for your feedback! Allow me to leave my thoughts below. @maribu Sep 19, 2020, 8:12 AM GMT+2:
RTCs may not have "channels" but "alarms" which basically behave like compare channels. They can be armed to an absolute counter/time value and generate an interrupt once they are reached. On STM32 for example the RTCs feature two alarms, on TI MCUs even three, out of which only one can be used with @maribu Sep 19, 2020, 8:12 AM GMT+2:
You are absolutely right here. With the current API-design additional conversion functions would be necessary. However, fully replacing existing APIs is not the goal here. If one requires minimal latency, using @maribu Sep 19, 2020, 8:12 AM GMT+2:
On STM32 I faced the problem that the LP-timer is exposed hard-coded via @maribu Sep 19, 2020, 8:12 AM GMT+2:
Overflow callbacks, as I see it, are not covered by In addition, the callback function @maribu Sep 19, 2020, 8:12 AM GMT+2:
I'd again would like to outline that the goal is not to fully replace existing APIs but to provide an additional uniform API that offers all the described features (e.g. exposing all timers and channels, allowing usage of advanced timer functions, ...). If an application scenario requires the most direct and basic timer hardware access, existing APIs can still be used directly. Code of these can furthermore be reused inside the aspired unified API to provide all base functions, hereby eliminating the problem of code duplication and also keeping maintainability. Additional code would then only be required for the additional features.
True, but this would leave out all of the aspired enhancements described in the RDM. Current low-level timer-APIs are limited to the most basic set of features that is commonly found across all MCUs supported by RIOT. As addressed in the RDM, many timers actually do offer a lot of additional features that currently either need to be manually implemented by the application developer or are not usable at all. I would very much like to see a platform-independent way of using these as well as the ability to expose the full set of available timer peripherals. @benpicco Sep 20, 2020, 2:15 AM GMT+2
This actually is on my list of "long-term optimization wishes" ;D @benpicco Sep 20, 2020, 2:15 AM GMT+2
The fact that an RTC can be implemented on top of an RTT is IMHO an argument to actually keep the RTC within the scope of the RDM. It shows that the functionality is that similar, that an RTC can even run on top of an RTT. It therefore should be included in a unified API. Regarding the watchdogs: Yes, as stated later in the RDM I also consider them as out of scope for the API. @benpicco Sep 20, 2020, 2:15 AM GMT+2
See # 2. Demands on a Low-level Timer Subsystem and # 4. Low-level Timer API Design :) @benpicco Sep 20, 2020, 2:15 AM GMT+2
Sure thing! This is nothing that I want to rush. The purpose of this PR is to get the initial discussion going, not to get it merged and implemented next week. |
|
Many timers also provide a Capture functionality that is unfortunately not exposed by any RIOT API yet. Should this also be within the scope of this API? |
|
I see no reason not to extend I do understand the desire to unify But I really see no reason why uniform access to high speed timers, RTTs and RTCs should not be implemented on top. This could be done e.g. by using a translation layer between the merged |
|
Thank you all for spending time on this topic!
If you ask me: absolutely within scope! Did someone say PWM? :P
I think we can all agree that the question on whether a unified API makes sense can be mostly separated from the details on how exactly it is implemented in the end.
"every driver to manage unit conversions" of course sound like a bad idea. So why would you want to do that? Of course we want avoid that wherever possible. Common utility functions? Other solutions? A lot of this topic boils down to having a solid (wide and detailed) understanding of the hardware itself - and more importantly some form of collective agreement on this bigger picture. I see absolutely no reason to rush any of this. Proper discussion and thinking it through will take a lot of time but I think it will be well spent as long as the generated knowledge is well documented and preserved for the community. |
Not having to maintain and implement two functionally equivalent low level APIs for the very same features for every MCU family is IMO a requirement, not an implementation detail. And I find it hard to find any argument against this. The discussion about the general architecture was started by this RDM, which clearly wants the API implemented on per MCU family side by side to the existing timer APIs. If the RDM is updated to leave the discussion about the general architecture for later, I would be fine. Side note: I have nothing against discussion on whether a new low level timer API should replace all But lets please leave watch dog timers and PWM out of this. E.g. I see no reason why it shouldn't be allowed to implement PWM abusing I2S and DMA when a specific MCU has no PWM capable timer. To me, PWM has just as much to do with timers as QDEC has: They just happen to be mostly implemented reusing timer hardware. lt;dr: Let's limit this RDM to the discussion of requirements for level timer APIs and only consider "real" timer features (not watchdogs, not PWM, not QDEC). |
@maribu is right though. So we can have timers that can reach different frequencies with varying accuracy depending on the input clock. However, such timer request mechanism is orthogonal to a timer API, we can just leave that out of scope. |
Functionally equivalent parts don't need to be reimplemented. And no one want to just duplicate code here.
I don't say the RDM should be split for that. The arguments for and against abstract concepts and implementation details should be focused.
Perfectly fine. Just keep in mind that achieving the envisioned feature-set of the proposed solution will require extensions to all of the existing APIs. Many of them will share a lot of similarity, effectively leading to what you want to avoid: "re-implementing the wheel" and code duplication.
Regarding watch dogs: already stated in the RDM and the PR discussion.
I guess I have to adapt my definition of "real" then...
Well known. A topic that overlaps with clock configuration and will be tackled separately. For the the timer API these aspects are only important regarding documentation and scope.
Agree. |
That's all I asked for :-) |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
|
Ping @ngandrass |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
In order to continue the discussion from the recent RIOT-Summit...
Contribution description
This RDM gathers demands upon a robust unified low-level timer-API for RIOT-OS.
Based on these, requirements are derived and a potential implementation design
is proposed. Results from a survey of timer hardware peripherals are furthermore
included in the appendix section.
The goal with this effort is not to fully replace existing modules but to offer
a possibility to access timer hardware in a uniform and platform-independent
way, whenever desired.
Please note that this RDM is still in an early phase. In order to provide a
foundation to base discussions on, it currently is very verbose. The additional
content shall allow one to quickly get a glimpse of the topic and take part in
the discussion. Some of these sections are currently also part of the RDM in
order to illustrate our thoughts and steps taken so far. The final version shall
of course be a lot shorter and compact.
It should also be mentioned, that at the moment a prototypical implementation
for the STM32 family is being developed to be used for first evaluations and
benchmarks.
Testing procedure
Your feedback is very appreciated.
Please read the RDM and contribute to the discussion if you like! :)