How to use the 64bit timer as a 32bit counter (overflow at 0xFFFFFFFF), but keep alarm function available

AloyseTech
Posts: 22
Joined: Mon Jul 22, 2019 2:29 pm

How to use the 64bit timer as a 32bit counter (overflow at 0xFFFFFFFF), but keep alarm function available

Postby AloyseTech » Fri Nov 22, 2019 3:22 pm

Hi,

For a time constrained application I need a freerunning 32bit microsecond time base timer to trigger alarm at given 32bit timestamp.

Currently I use the two 64bit timers of a timer group as follow :
The first timer is used to generate one shot alarm at a given absolute 32bit timestamp. The second timer is setup at the same speed with auto-reload and with an alarm at 0xFFFFFFFF (32bit max). When the second timer IRQ is triggered, I set the first timer counter back to 0 (simulate overflow). The second counter is automatically reset thanks to auto-reload, but I still re-enable the alarm for the next overflow.

Is there a better way to do this? I'm afraid this solution add overhead and that I might miss an alarm set for example at 0xFFFFFFFF on the first timer. I don't know how to ensure the 2 timers are in sync.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: How to use the 64bit timer as a 32bit counter (overflow at 0xFFFFFFFF), but keep alarm function available

Postby WiFive » Fri Nov 22, 2019 9:03 pm

I don't understand the advantage of the 32-bit rollover

AloyseTech
Posts: 22
Joined: Mon Jul 22, 2019 2:29 pm

Re: How to use the 64bit timer as a 32bit counter (overflow at 0xFFFFFFFF), but keep alarm function available

Postby AloyseTech » Fri Nov 22, 2019 9:26 pm

WiFive wrote:
Fri Nov 22, 2019 9:03 pm
I don't understand the advantage of the 32-bit rollover
I’m connected to a system which expect 32bit timestamp and send me 32bit alarm. I can send a 32bit timestamp easily from the 64bit timer, but I can’t set a 64bit alarm from a 32bit one. The remote system expect that my time base rollover at 32bit.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: How to use the 64bit timer as a 32bit counter (overflow at 0xFFFFFFFF), but keep alarm function available

Postby WiFive » Fri Nov 22, 2019 10:41 pm

When you send the timestamp you ignore the high 32 bits and when you receive the alarm you add them as an offset. The lower 32 bits should always be in sync.

Code: Select all

alarm_64 = alarm_32 + counter & 0xffffffff00000000ull + (alarm < counter & 0xffffffff)?1ull <<32:0;

Who is online

Users browsing this forum: Bing [Bot] and 103 guests