rsta2 / circle

A C++ bare metal environment for Raspberry Pi with USB (32 and 64 bit)

Home Page:https://circle-rpi.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GetClockTicks without wrap

ThexXTURBOXx opened this issue · comments

The current implementation of CTimer::GetClockTicks may wrap - as documented.
However - at least when using the physical counter - this could be simply avoided by also using the value of ARM_SYSTIMER_CHI which already exists bcm2835.h.
When using the physical counter, a simple implementation (inspired by LLD's kernel) could look like this:

u64 CKernel::GetClockTicksHiLo() {
  PeripheralEntry();

  u32 hi = read32(ARM_SYSTIMER_CHI);
  u32 lo = read32(ARM_SYSTIMER_CLO);

  // double check hi value didn't change when retrieving lo...
  if (hi != read32(ARM_SYSTIMER_CHI)) {
    hi = read32(ARM_SYSTIMER_CHI);
    lo = read32(ARM_SYSTIMER_CLO);
  }

  PeripheralExit();

  return static_cast<u64>(hi) << 32 | lo;
}

I am just pointing this out because I was wondering why something like this is not offered yet by circle.
It is probably because of a missing counterpart when not using the physical counter (?)
If you want me to create a PR, I can gladly do so.

PR #411 implements this feature and has been merged to the develop branch.

This function is in Circle 46.