rupertr
Posts: 11
Joined: Fri Sep 07, 2012 2:21 am

System Timers

Thu Sep 20, 2012 6:42 am

Hi all.

I've written myself a little bare metals program to explore some of the memory available to the cpu via the uart. I can do things like dump the registers to memory on launch, view chunks of memory, push data to memory, etc.
However I've come across something strange with the System Timers. I've noticed that the System Timer Compare 0 and 2 (0x2000300c and 0x20003014) are constantly ticking over and I have no idea why. Perhaps it's something to do with the GPU?

Any ideas?
Thanks,
- Rupert

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5171
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: System Timers

Thu Sep 20, 2012 1:15 pm

Yes, the GPU uses two timers. You should be able to use the other two.

rupertr
Posts: 11
Joined: Fri Sep 07, 2012 2:21 am

Re: System Timers

Thu Sep 20, 2012 1:20 pm

Awesome, that explains that, thanks dom!
Don't suppose you could enlighten us a little further as to what the GPU is using them for? Just curious :)

Pieter-Jan5000
Posts: 40
Joined: Tue Jun 12, 2012 7:20 pm
Contact: Website

Re: System Timers

Tue Oct 16, 2012 4:39 pm

so 1 and 3 are to be used by normal (C / C++) programs? No risk of breaking anything? I'm running raspbian linux ...
http://www.pieter-jan.com/

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5171
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: System Timers

Thu Oct 18, 2012 1:52 pm

rupertr wrote:Awesome, that explains that, thanks dom!
Don't suppose you could enlighten us a little further as to what the GPU is using them for? Just curious :)
Timer 0 is used for the GPU RTOS (threadx) as the timer tick (100 interrupts / second).
Timer 2 is used for lightweight timers than can call callbacks with microsecond (*) resolution.

(*) subject to inetrrupt latency.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5171
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: System Timers

Thu Oct 18, 2012 1:56 pm

Pieter-Jan5000 wrote:so 1 and 3 are to be used by normal (C / C++) programs? No risk of breaking anything? I'm running raspbian linux ...
Yes. Unless someone else also writes something useful using them and you want to run both apps together.

What do you need it for? If you just need to measure time, then gettimeofday effectively reads the system timer, and has microsecond resolution.

Pieter-Jan5000
Posts: 40
Joined: Tue Jun 12, 2012 7:20 pm
Contact: Website

Re: System Timers

Thu Oct 18, 2012 2:02 pm

I'm designing a PID controller for which I need an accurate timing for the integration (d action requires constant timing interval). I was looking into the ARM timer for this, but in the peripheral manual they referred to the system timers for accurate timing.

I'll try the gettimeofday however it feels a bit hacky ...
http://www.pieter-jan.com/

Serac
Posts: 124
Joined: Wed Jul 18, 2012 2:49 pm

Re: System Timers

Thu Oct 18, 2012 3:06 pm

Pieter-Jan5000 wrote:I'll try the gettimeofday however it feels a bit hacky ...
How precise does the time need to be ?

For portable code I'd suggest you use the POSIX clock_gettime() call rather than gettimeofday() - The latter, whilst part of the POSIX specification, POSIX.1-2008 marks gettimeofday() as obsolete (according to the man page).

Pieter-Jan5000
Posts: 40
Joined: Tue Jun 12, 2012 7:20 pm
Contact: Website

Re: System Timers

Fri Oct 19, 2012 5:59 pm

clock_gettime() was good enough for me. Not as good as a timer, but good enough. Thx!
http://www.pieter-jan.com/

Return to “Bare metal, Assembly language”