作者:付汉杰 hankf@amd.com
1. 硬件的Vivado Block design设计中,添加AXI Timer
2. 包含AXI Timer的头文件
#include "xtmrctr.h"
3. 定义timer的参数和全局变量
/* * The following constants map to the XPAR parameters created in the * xparameters.h file. They are only defined here such that a user can easily * change all the needed parameters in one place. */ #define TMRCTR_DEVICE_ID XPAR_TMRCTR_0_DEVICE_ID /* * This example only uses the 1st of the 2 timer counters contained in a * single timer counter hardware device */ #define TIMER_COUNTER_0 0 // #define XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ 100000000U 100 000 000U #define TMRCTR_DEVICE_FREQ_MS (XPAR_TMRCTR_0_CLOCK_FREQ_HZ/1000) #define TMRCTR_DEVICE_FREQ_US (TMRCTR_DEVICE_FREQ_MS/1000) #define TMRCTR_DEVICE_PERIOD_NS ( (1000*1000*1000)/XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ ) XTmrCtrTimerCounter;/*TheinstanceoftheTmrctrDevice*/
4. 初始化AXI Timer
调用TmrCtrPolledInit()初始化AXI Timer, 也初始化了全局变量TimerCounter。
TmrCtrPolledInit(TMRCTR_DEVICE_ID,TIMER_COUNTER_0);
其中TmrCtrPolledInit()来自于xtmrctr_polled_example.c中的TmrCtrPolledExample(),可以在BSP中从AXI Timer的“Import Example”中导入。
5. 通过XTmrCtr_GetValue获取时间戳
通过XTmrCtr_GetValue获取时间戳,是以时钟周期为单位的。可以转化成微妙、毫秒、秒等单位。
time_begin = XTmrCtr_GetValue(TmrCtrInstancePtr, TmrCtrNumber); for (i=0; i<100000; i++ ) { g_iLoopTest++; } time_end = XTmrCtr_GetValue(TmrCtrInstancePtr, TIMER_COUNTER_0); if( time_end < time_begin ){ time_diff = 0xffffffff - time_begin; time_diff = time_diff + time_end + 1; } else { time_diff = time_end - time_begin; } time_diff_us = time_diff/TMRCTR_DEVICE_FREQ_US; xil_printf("100K loop: %x : Timer diff: 0x%08x = %d Cycles, %d us, %d ms at %s : %d ", g_iLoopTest, time_diff, time_diff, time_diff_us, time_diff_us/1000, __
-
amd
+关注
关注
25文章
5466浏览量
134083 -
MicroBlaze
+关注
关注
3文章
68浏览量
21548 -
Timer
+关注
关注
1文章
64浏览量
12784 -
AXI
+关注
关注
1文章
127浏览量
16622 -
时间戳
+关注
关注
0文章
15浏览量
2593
原文标题:AMD MicroBlaze中通过AXI Timer获取时间戳
文章出处:【微信号:Hack电子,微信公众号:Hack电子】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
相关推荐
评论