Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

TMS570LS3137: 64Bit Timer counter

$
0
0

Part Number:TMS570LS3137

Hello,

I'm trying to get a 64bit timer counter going. 

Right now, I'm just configuring the counter0 as an upcounter at 45Mhz, and each time it overflows, manually writing counter1's FRCx, and returning the 64bit value as follows:

void rtiNotification(uint32 notification)
{
    switch (notification) {
    case rtiNOTIFICATION_COUNTER0:
        ++rtiREG1->CNT[1].FRCx;
        break;
    }
}

uint64_t getTime() {
    _disable_IRQ();
    uint32_t frcLow = rtiREG1->CNT[0].FRCx;
    uint32_t frcHigh = rtiREG1->CNT[1].FRCx;

    _enable_IRQ();
    return (uint64_t) (((uint64_t)frcHigh << 32) | (uint64_t)frcLow);
}
// resolution per tick = 1/f * NsInSec
#define RES (uint64_t) (1.0/45000000 * 1000000000)  
void delay(uint64_t delay_ns) {
    if (delay_ns > RES) {
        uint64_t start = getTime();
        uint64_t ticks = (uint64_t)(delay_ns/RES);

        while ((getTime() - start) < ticks);
    }
}

int main(void)
{
    rtiInit();
    rtiEnableNotification(rtiNOTIFICATION_COUNTER0);
    _enable_IRQ();
    rtiSetPeriod(0, 0xffffffff);
    rtiStartCounter(rtiCOUNTER_BLOCK0);

    while (1) {
        delay(30000000000);   // 30 sec in nanosecs
        ledToggle();
        //pinToggle();
    }
}

questions:

* is there a better way to do this?

* Saw this in the datasheet that confused me a little bit, please explain in simpler words (I'm having a hard time what this does)?

RTI Up Counter 0 Register (RTIUC0)

Description: Up counter 0. This register holds the current value of the up counter 0 and prescales the RTI clock. It will be only updated by a previous read of free running counter 0 (RTIFRC0). This method of updating effectively gives a 64-bit read of both counters, without having the problem of a counter being updated between two consecutive reads on up counter 0 (RTIUC0) and free running counter 0 (RTIFRC0). A read of this counter returns the value of the counter at the time RTIFRC0 was read. A write to this counter presets it with a value. The counter then increments from this written value upwards

Thank you for your support!

KB


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>