[examples][test]Perfect test function
This commit is contained in:
parent
dcf7bce2cc
commit
4fd6f2ef53
|
@ -8,7 +8,7 @@
|
|||
|
||||
static rt_err_t timer_timeout_cb(rt_device_t dev, rt_size_t size)
|
||||
{
|
||||
rt_kprintf("HT %d\n", rt_tick_get());
|
||||
rt_kprintf("enter hardware timer isr\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ int hwtimer(void)
|
|||
return -1;
|
||||
}
|
||||
|
||||
rt_device_set_rx_indicate(dev, timer_timeout_cb);
|
||||
/* 时间测量 */
|
||||
/* 计数时钟设置(默认1Mhz或支持的最小计数频率) */
|
||||
err = rt_device_control(dev, HWTIMER_CTRL_FREQ_SET, &freq);
|
||||
if (err != RT_EOK)
|
||||
|
@ -69,12 +69,34 @@ int hwtimer(void)
|
|||
rt_device_read(dev, 0, &val, sizeof(val));
|
||||
rt_kprintf("Read: Sec = %d, Usec = %d\n", val.sec, val.usec);
|
||||
|
||||
/* 定时执行回调函数 -- 单次模式 */
|
||||
/* 设置超时回调函数 */
|
||||
rt_device_set_rx_indicate(dev, timer_timeout_cb);
|
||||
|
||||
/* 单次模式 */
|
||||
mode = HWTIMER_MODE_PERIOD;
|
||||
err = rt_device_control(dev, HWTIMER_CTRL_MODE_SET, &mode);
|
||||
|
||||
/* 设置定时器超时值并启动定时器 */
|
||||
val.sec = t;
|
||||
val.usec = 0;
|
||||
rt_kprintf("SetTime: Sec %d, Usec %d\n", val.sec, val.usec);
|
||||
if (rt_device_write(dev, 0, &val, sizeof(val)) != sizeof(val))
|
||||
{
|
||||
rt_kprintf("SetTime Fail\n");
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
/* 等待回调函数执行 */
|
||||
rt_thread_delay((t + 1)*RT_TICK_PER_SECOND);
|
||||
|
||||
EXIT:
|
||||
err = rt_device_close(dev);
|
||||
rt_kprintf("Close %s\n", TIMER);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
FINSH_FUNCTION_EXPORT(hwtimer, "Test hardware timer");
|
||||
#ifdef FINSH_USING_MSH
|
||||
MSH_CMD_EXPORT(hwtimer, "Test hardware timer");
|
||||
#endif
|
||||
#endif /* RT_USING_HWTIMER */
|
||||
|
|
Loading…
Reference in New Issue