c6701芯片获取软件运行时间的函数,想要通过ccs软件获取软件中某段程序运行时间,应该怎么弄
1个回答
展开全部
#include <csl_timer.h>
TIMER_Handle hTimer0;
TIMER_Config TimerConfig =
{
TIMER_CTL_RMK
(
TIMER_CTL_SPND_EMUSTOP,
TIMER_CTL_INVINP_NO,
TIMER_CTL_CLKSRC_CPUOVR8, //定时器的频率是CPU频率的1/8
TIMER_CTL_CP_PULSE,
TIMER_CTL_HLD_NO, //时钟有效
TIMER_CTL_GO_NO, //时钟没有开启
TIMER_CTL_PWID_TWO,
TIMER_CTL_DATOUT_1,
TIMER_CTL_INVOUT_YES,
TIMER_CTL_FUNC_TOUT
),
0xffffffff, //定时器计数值,一旦达到该值就会产生中断,该计数值可以最大计数57秒不中断
0x0 //计数器初值
};
void Timer0_Cnt()
{
float timecnt,timeval;
hTimer0 = TIMER_open(TIMER_DEV0,TIMER_OPEN_RESET); //打开定时器0,返回操作句柄
TIMER_config(hTimer0,&TimerConfig); //使用配置结构体配置定时器0
TIMER_start(hTimer0); //开始计数
/***********此处为要计时的程序段***********/
timecnt = TIMER_getCount(hTimer0); //获取定时器的计数值
TIMER_pause(hTimer0); //停止计数
timeval = (float)(timecnt*8/600000000); //将计数值转化为时间值
printf("The time spended is %fs",timeval); //打印程序运行时间
}
TIMER_Handle hTimer0;
TIMER_Config TimerConfig =
{
TIMER_CTL_RMK
(
TIMER_CTL_SPND_EMUSTOP,
TIMER_CTL_INVINP_NO,
TIMER_CTL_CLKSRC_CPUOVR8, //定时器的频率是CPU频率的1/8
TIMER_CTL_CP_PULSE,
TIMER_CTL_HLD_NO, //时钟有效
TIMER_CTL_GO_NO, //时钟没有开启
TIMER_CTL_PWID_TWO,
TIMER_CTL_DATOUT_1,
TIMER_CTL_INVOUT_YES,
TIMER_CTL_FUNC_TOUT
),
0xffffffff, //定时器计数值,一旦达到该值就会产生中断,该计数值可以最大计数57秒不中断
0x0 //计数器初值
};
void Timer0_Cnt()
{
float timecnt,timeval;
hTimer0 = TIMER_open(TIMER_DEV0,TIMER_OPEN_RESET); //打开定时器0,返回操作句柄
TIMER_config(hTimer0,&TimerConfig); //使用配置结构体配置定时器0
TIMER_start(hTimer0); //开始计数
/***********此处为要计时的程序段***********/
timecnt = TIMER_getCount(hTimer0); //获取定时器的计数值
TIMER_pause(hTimer0); //停止计数
timeval = (float)(timecnt*8/600000000); //将计数值转化为时间值
printf("The time spended is %fs",timeval); //打印程序运行时间
}
追问
有比较简便的方法吗,感觉好复杂,直接用系统函数可以吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询