timebase register question - VxWorks

This is a discussion on timebase register question - VxWorks ; I'm perusing code used for timing purposes that's akin to: typedef unsigned int Uint32; static volatile Uint32 tblx=0; inline Uint32 getTimeBaseHard() { __asm__ (" mftb %0" : "=r" (tblx) ); return tblx; } What this does is read the timebase ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: timebase register question

  1. timebase register question


    I'm perusing code used for timing purposes that's akin to:

    typedef unsigned int Uint32;
    static volatile Uint32 tblx=0;

    inline Uint32 getTimeBaseHard()
    {
    __asm__ (" mftb %0" : "=r" (tblx) );
    return tblx;
    }

    What this does is read the timebase register. Trouble is, the source
    only returns the lower register. I'm trying to garner a feel for how
    adequate this approach is and is necessary to read the upper register
    (mftbu). I almost always run across the approach above.

    Ideally, the returned from function above would be multiplied by
    nanoseconds and that becomes my time or do I have to account for bus
    speed? An example is appreaciated.


  2. Re: timebase register question

    The timebase register runs at memory bus speed, so yes you have to
    account for that.

    Whether you need to include the upper register merely depends on how
    long your timing measurements have to be. I have a note in my code that
    does this that on a 66MHz bus the lower register wraps in about 4
    minutes. Here's my microsecond measurement code, which only uses the
    lower register.

    /************************************************** ***************************
    *
    * sysUsSince - return the elapsed time since a previous call (in
    microseconds)
    *
    * This routine reads the CPU's timebase register and calculates the
    time
    * difference between now and the start argument, allowing for rollover
    of the
    * timebase register. To read the current microsecond time count,
    specify a
    * start value of 0.
    *
    * NOTE: This value will wrap around after about 4 minutes, because we
    only
    * read 32 bits from the timebase register and it gets clocked at 66MHz.
    * If you need to measure longer times than this use tickGet() instead,
    which
    * gives you about 2.25 years until it wraps around.
    *
    * RETURNS: UINT32 microsecond time difference.
    */

    UINT32 sysUsSince
    (
    UINT32 start
    )
    {
    UINT32 now, delta;

    now = sysTimeBaseLGet() / ((MEMORY_BUS_SPEED / 4) / 1000000);
    if (now >= start)
    delta = now - start;
    else
    delta = 0xffffffff - (start - now - 1);

    return delta;
    }


+ Reply to Thread