TimerDevice

Discussion and questions about programming with Ultibo.
Koen
Posts: 29
Joined: Sat Apr 29, 2017 10:41 am

TimerDevice

Postby Koen » Wed May 16, 2018 8:49 am

I have been reading (again) the forum about fiq design https://ultibo.org/forum/viewtopic.php?f=10&t=306#p1255 and Nanosecond timer https://ultibo.org/forum/viewtopic.php?f=13&t=818&p=5175&hilit=Timer+Device#p5175, had a look at the sourcecode of ~/ultibo/core/fpc/source/rtl/ultibo/core/devices.pas and I am still not shure if I understand the timer device.
In the examplecode the calls to TimerDeviceSetRate, TimerDeviceSetInterval, TimerDeviceStart and TimerDeviceEvent all use TimerDeviceGetDefault as an argument. Are there any other timer devices? Can I use more then one TimerDevice?
I can see tree possible uses of the TimerDevice and registring an event but can I use all of them in one programm? I tried so but it did not work.
1. enable FIQ and set TIMER_EVENT_FLAG_INTERRUPT. There can only be one FIQ and it will be attached to CPU0. Any further attempt to create such timer will return with an error.
2. disable FIQ and set TIMER_EVENT_FLAG_INTERRUPT. Only one callback event possible?
3. disable FIQ and do NOT set TIMER_EVENT_FLAG_INTERRUPT.

Is it possible to have multiple events assigned to multiple timers?
What is the overhead using the different methods?
Any hint to documentation is welcome.
User avatar
Ultibo
Site Admin
Posts: 1980
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: TimerDevice

Postby Ultibo » Wed May 16, 2018 11:10 am

Koen wrote:Are there any other timer devices? Can I use more then one TimerDevice?

There are other timer devices in the Pi (at least in the Pi 2 and 3) but at present we have only written one driver which is for the ARM timer device as shown in the FIQ example because it is the most flexible of the available timers. See the Hardware Status page for the complete list.

All models of Pi have a System timer as well which always runs at 1MHz, the Pi 2 and 3 also have a Local timer and a Generic timer (per CPU) that go up to 19.2MHz.

Ultibo uses some of those internally for the clock and the thread scheduler so they are not available for use by applications but for the others we simply haven't written drivers because no one has expressed interest in them.

If you have a case where multiple timers would be required then please let us know, we only know what people want when they tell us.

So for the current examples using TimerDeviceGetDefault is fine because there is only one, if more are added then you would need to call TimerDeviceFindByName or TimerDeviceFindByDescripion.

Koen wrote:I can see tree possible uses of the TimerDevice and registring an event but can I use all of them in one programm? I tried so but it did not work.
1. enable FIQ and set TIMER_EVENT_FLAG_INTERRUPT. There can only be one FIQ and it will be attached to CPU0. Any further attempt to create such timer will return with an error.
2. disable FIQ and set TIMER_EVENT_FLAG_INTERRUPT. Only one callback event possible?
3. disable FIQ and do NOT set TIMER_EVENT_FLAG_INTERRUPT.

I think you are possibly mixing up two different things, the restriction of only one FIQ is a Broadcom SoC limitation that we have to obey no matter what.

The fact that interrupts (IRQ) and fast interrupts (FIQ) are only sent to CPU0 is also a Broadcom SoC limitation, on the Pi 2 or 3 it is now possible to tell the SoC which of the 4 CPUs all interrupts should go to but it can still be only one of them.

The limitation of registering multiple timer events when passing TIMER_EVENT_FLAG_INTERRUPT is an Ultibo limit simply because of the way the interrupt handler has to be structured in order to support calling the event this way.

Only being able to register one interrupt event should not be an issue really because you can make your event do multiple things even if they happen at different intervals. When registering a timer event one of the parameters is a block of Data which allows you to pass a record or an object (or anything really) that can be used in your event handler to keep track of the state.

Koen wrote:Is it possible to have multiple events assigned to multiple timers?

Yes you can register multiple events to multiple timers, if multiple timer devices are available.

The limitation on timer events is that there can only be one interrupt or repeating event (flag TIMER_EVENT_FLAG_INTERRUPT or TIMER_EVENT_FLAG_REPEAT) and an interrupt event must also be repeating.

You can queue multiple events to be called on a single timer if none of them are interrupt or repeating.

Koen wrote:What is the overhead using the different methods?

The interrupt method (either IRQ or FIQ) is the fastest so if you need to have your event called very quickly when the timer triggers that is the one to use but it also has the strictest limitations because your code will be called inside the interrupt handler.

The standard callback (not interrupt) is called on a worker thread so there are no limitations about what your code can do but it will not be real time because the event will not be called until the interrupt completes and the worker thread is scheduled to run.
Ultibo.org | Make something amazing
https://ultibo.org
Koen
Posts: 29
Joined: Sat Apr 29, 2017 10:41 am

Re: TimerDevice

Postby Koen » Thu May 17, 2018 4:52 am

Thank you. That confirms what I thought to have understood.
I also found the topic "timer" now. https://ultibo.org/forum/viewtopic.php?f=10&t=103#p250
No need for more explanation at the moment.
I am just trying to understand.

Return to “General”

Who is online

Users browsing this forum: No registered users and 0 guests