#include "system.h"<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
#include "alt_types.h"
#include "stdio.h"
#include "unistd.h"
#include "sys/alt_timestamp.h"//timestamp需要头同文件
int main (void)
{
alt_u32 freq;
alt_u32 time1,time2,time3;
alt_u32 Past_time1,Past_time2;
freq= alt_timestamp_freq();//获得timestamp的时钟频率
printf("%d\n",freq);
if(alt_timestamp_start()<0)//启动timestampe的计数,每次调用都会对snapshot寄存器清零
printf("No timestamp device available\n");
else
{
time1 = alt_timestamp();//获取当前sanpshot寄存器的值
usleep(1000);
time2 = alt_timestamp();//
usleep(3000);
time3 = alt_timestamp();
Past_time1 = (time2-time1)/(ALT_CPU_FREQ/1000000);
printf("%d\n",Past_time1);
Past_time2 = (time3-time2)/(ALT_CPU_FREQ/1000000);
printf("%d\n",Past_time2);
}
while(1);
}
总结:
1. 硬件需要:要有可写周期寄存器,要有sanpshot寄存器,
2. 包含sys/alt_timestamp.h头文件
3. 启动函数:alt_timestamp_start();返回值为负说明系统没有timestamp
4. 获取sanpshot寄存器的值根据两次获取的寄存器值的差来计算程序经过的时间,注意单位为SOPC中设定timer的最小计时时间。
用户1314276 2010-8-3 17:32