summaryrefslogtreecommitdiff
path: root/examples/test/hwtimer_test.c
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2021-03-31 14:15:21 +0800
committerGitHub <[email protected]>2021-03-31 14:15:21 +0800
commit259144b2e658d6bdc543afb6b2e88f5461a070b4 (patch)
tree7e4e1a241a70330b4f6a4e78d6549c9e68d4873d /examples/test/hwtimer_test.c
parent28ec21671cfd8992b3ad2d6ea48989968ad23e7c (diff)
parenta15040d3a9175b13486d756eafe0dd03645368da (diff)
Merge branch 'master' into master
Diffstat (limited to 'examples/test/hwtimer_test.c')
-rw-r--r--examples/test/hwtimer_test.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/examples/test/hwtimer_test.c b/examples/test/hwtimer_test.c
index 428373dde0..15d7aa830f 100644
--- a/examples/test/hwtimer_test.c
+++ b/examples/test/hwtimer_test.c
@@ -1,3 +1,12 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ */
+
#include <rtthread.h>
#include <rtdevice.h>
#include <finsh.h>
@@ -35,8 +44,8 @@ int hwtimer(void)
return -1;
}
- /* ʱ����� */
- /* ����ʱ������(Ĭ��1Mhz��֧�ֵ���С����Ƶ��) */
+ /* 时间测量 */
+ /* 计数时钟设置(默认1Mhz或支持的最小计数频率) */
err = rt_device_control(dev, HWTIMER_CTRL_FREQ_SET, &freq);
if (err != RT_EOK)
{
@@ -44,13 +53,13 @@ int hwtimer(void)
goto EXIT;
}
- /* ����ģʽ */
+ /* 周期模式 */
mode = HWTIMER_MODE_PERIOD;
err = rt_device_control(dev, HWTIMER_CTRL_MODE_SET, &mode);
tick = rt_tick_get();
rt_kprintf("Start Timer> Tick: %d\n", tick);
- /* ���ö�ʱ����ʱֵ��������ʱ�� */
+ /* 设置定时器超时值并启动定时器 */
val.sec = t;
val.usec = 0;
rt_kprintf("SetTime: Sec %d, Usec %d\n", val.sec, val.usec);
@@ -62,22 +71,22 @@ int hwtimer(void)
rt_kprintf("Sleep %d sec\n", t);
rt_thread_delay(t*RT_TICK_PER_SECOND);
- /* ֹͣ��ʱ�� */
+ /* 停止定时器 */
err = rt_device_control(dev, HWTIMER_CTRL_STOP, RT_NULL);
rt_kprintf("Timer Stoped\n");
- /* ��ȡ���� */
+ /* 读取计数 */
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);
@@ -87,7 +96,7 @@ int hwtimer(void)
goto EXIT;
}
- /* �ȴ��ص�����ִ�� */
+ /* 等待回调函数执行 */
rt_thread_delay((t + 1)*RT_TICK_PER_SECOND);
EXIT: