wangt13
wangt13

Reputation: 1265

How can I get timer in microsecond in ARMv8 system?

I am writing a part of kernel code in ARMv8 RTOS.
I am trying to do a function like gettimeofday() in Linux, which can return system time in second and microsecond.
But I failed to do that. ARMv8 support PL031, I think it is working at freq. of 1Hz, I cannot get the time in microsecond.
I am NOT sure if I am reading/doing something wrong with PL031, is there any way in ARMv8 to get system time in microsecond?

Upvotes: 1

Views: 1155

Answers (1)

user3124812
user3124812

Reputation: 1986

ARMv8 has 'generic timer' for such a purpose.

You could find description in "ARM Architecture Reference Manual. ARMv8, for ARMv8-A architecture profile" (search for "Generic Timer").

There is also Programmer's Guides for that (link)

The catch is that you need to write CNTFRQ_EL0 register with a system frequency value. This 'frequency' register is not filled by hardware and has limitations of exception level.
But since you doing your RTOS, that should not be an issue.

By reading CNTPCT_EL0 you could get 'system ticks' that could be, with a help of 'frequency', converted to time.

Upvotes: 1

Related Questions