作者:付漢杰 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文章
5490瀏覽量
134499 -
MicroBlaze
+關注
關注
3文章
68瀏覽量
21577 -
Timer
+關注
關注
1文章
64瀏覽量
12810 -
AXI
+關注
關注
1文章
128瀏覽量
16684 -
時間戳
+關注
關注
0文章
15瀏覽量
2620
原文標題:AMD MicroBlaze中通過AXI Timer獲取時間戳
文章出處:【微信號:Hack電子,微信公眾號:Hack電子】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論