在zynq的裸机程序中计算程序运行耗时

可以利用ARM 内核中的Performance Monitor Unit(PMU,性能检测单元)来得到耗时的tick count。

转载别人的代码如下:

修改XTime_GetTime代码:

/**************************************************************************** 
* 
* Get the time from the Global Timer Counter Register. 
* 
* @param    Pointer to the location to be updated with the time. 
* 
* @return   None. 
* 
* @note     None. 
* 
****************************************************************************/  
void XTime_GetTime(XTime *Xtime)  
{  
    u32 low;  
    u32 high;  
  
    /* Reading Global Timer Counter Register */  
    do  
    {  
        high = Xil_In32(GLOBAL_TMR_BASEADDR + GTIMER_COUNTER_UPPER_OFFSET);  
        low = Xil_In32(GLOBAL_TMR_BASEADDR + GTIMER_COUNTER_LOWER_OFFSET);  
    } while(Xil_In32(GLOBAL_TMR_BASEADDR + GTIMER_COUNTER_UPPER_OFFSET) != high);  
  
    *Xtime = (((XTime) high) << 32) | (XTime) low;  
}  
测试代码:
#include <stdio.h>  
#include "sleep.h"  
#include "xil_io.h"  
#include "xtime_l.h"  
#include "xil_printf.h"  
#include "xpm_counter.h"  
#include "xparameters.h"  
  
#define COUNTS_PER_SECOND          (XPAR_CPU_CORTEXA9_CORE_CLOCK_FREQ_HZ / 2)  
  
int main()  
{  
    XTime tEnd, tCur;  
    u32 tUsed;  
  
    XTime_GetTime(&tCur);  
    usleep(1345);  
    XTime_GetTime(&tEnd);  
    tUsed = ((tEnd-tCur)*1000000)/(COUNTS_PER_SECOND);  
    xil_printf("time elapsed is %d us\r\n",tUsed);  
    while(1);   //等待  
  
    return 0;  
} 



  • 6
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值