Until recently, we were using the RTI counters as a 64-bit free-running counter for all timing in our TMS570LS3137-based system. We'd initialize the counter like so:
void ClockInit() {
RTIGCTRL_bit()->CNT0EN = 0; // Disable counter 0.
*RTICPUC0() = 0; // Increment RTIUC0 when RTIFRC0 rolls over.
*RTIFRC0() = 0; // Zero upper 32 bits.
*RTIUC0() = 0; // Zero lower 32 bits.
RTIGCTRL_bit()->COS = 0; // Don't let the clock run while debugger halted.
RTIGCTRL_bit()->CNT0EN = 1; // Enable counter 0.
}
We'd read the clock like so:
int64_t ClockTicks() {
return (static_cast<int64_t>(*RTIFRC0()) << 32) | *RTIUC0();
}
Every ~4 hours of operation, we'd see an odd backwards jump in time. After writing a test program, I noticed that occasionally the lower 32 bits would read 0, while the upper 32 bits hadn't incremented yet:
I'm guessing this is a result of setting RTICPUC0 to 0 rather than 0xFFFFFFFF. The documentation is not at all clear on what to put in RTICPUC0 to get a 64-bit counter - I assumed that since it specifically called out RTICPUC0 = 0 as causing the rollover frequency fRTIFRCx to be fRTICLK / 232 in section 13.2.1 of the TRM, that setting RTICPUC0 = 0 would work.
How can we get this counter to work correctly? Could you please update the errata and TRM to document the actual behavior of the chip?
Seth