简体   繁体   中英

how to access the Freescale P2020's Alternate Time Base Registers 64-bit timer register in VxWorks

How is this register configurated and then read, in VxWorks? That is, what address is it at, and what address do I write to configure its rate of increment.

We aren't using RTP so there's no kernel space issue. Just need to write the rate to some control address, and then periodically read the 64-bit unsigned integer timer.

In our application, we need a high resolution, 64-bit timer that software will use to do general timing measurements.

Example code would be good.

It depends what your application wants to do with the timer and the environment in which it will be happening. I haven't works with that particular chip, so I can't tell you how to use the register.

If what you want is a timestamp-like function, where you can read the counter before and after an operation and do a difference between the two, then VxWorks board support packages provides that functionality via the sysTimestamp family of functions. See the documentation.

However, if sysTimestamp does not meet your requirements, but you still want to access the register to read the current time and your code runs in the kernel space (vs. user-space AKA RTP) then you simply need to define a function that will return the timestamp...

uint64 myTimestamp() {
   uint64 ts;
   ts = *read & massage the register*
     *deal with overflows, etc... *

   return ts;
}

If on the other hand, your application runs in the context of a RTP, things get more complicated since RTPs, much like processes in windows, don't have direct access to hardware functions.

One possibility is to map a page of physical kernel memory to the RTP so it can access the registers directly. Highly discouraged, since you've opened a hole in the protection mechanism of the system. You could also implement a custom system call specifically to read the timestamp register.

Both of these solutions require intermediate - advanced skills with vxWorks.

To access the timebase register you can write some assembly code to access it:

.global TBL_get
.global TBU_get
TBL_get:
    mfspr   r3, 268
    blr
TBU_get:
    mfspr   r3, 269
    blr

This access the lower bits then upper bits of time base register and return one parameter.

Don't forget to define the function in your .h file like that:

uint32 TBL_get (void);
uint32 TBU_get (void);

Then call the two functions and concatenate variables returned from your functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM