简体   繁体   English

如何访问飞思卡尔P2020的交替时基寄存器的64位定时器寄存器中的VxWorks

[英]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? 在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. 我们没有使用RTP,所以没有内核空间问题。 Just need to write the rate to some control address, and then periodically read the 64-bit unsigned integer timer. 只需要将速率写入某个控制地址,然后定期读取64位无符号整数计时器。

In our application, we need a high resolution, 64-bit timer that software will use to do general timing measurements. 在我们的应用中,我们需要一个高分辨率的64位定时器,软件将使用该定时器来进行常规的定时测量。

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. 如果您想要的是类似时间戳的功能,您可以在操作前后读取计数器并在两者之间进行区别,则VxWorks板级支持包将通过sysTimestamp系列功能来提供该功能。 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... 但是,如果sysTimestamp不满足您的要求,但是您仍然希望访问寄存器以读取当前时间, 并且您的代码在内核空间中运行(与用户空间AKA RTP相对),那么您只需要定义一个函数即可返回时间戳记...

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. 另一方面,如果您的应用程序在RTP上下文中运行,则事情会变得更加复杂,因为RTP与Windows中的进程非常相似,无法直接访问硬件功能。

One possibility is to map a page of physical kernel memory to the RTP so it can access the registers directly. 一种可能是将物理内核内存页面映射到RTP,以便它可以直接访问寄存器。 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. 这两种解决方案都要求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: 不要忘记在.h文件中定义函数,如下所示:

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

Then call the two functions and concatenate variables returned from your functions. 然后调用这两个函数并连接从函数返回的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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