测试环境
硬件
软件配置
- PC端的串口终端软件,用于PC和开发板进行串口通信
- Luban-Lite自带的
test_hrtimer
命令行工具
软件配置
在 Luban-Lite 根目录下执行 scons --menuconfig
,进入menuconfig的功能配置界面,按如下选择打开 test_hrtimer
命令行工具:
Drivers options --->
Drivers examples --->
[*] Enable HRTimer driver test command
1
2
3
2
3
测试HRTimer
test_hrtimer
命令支持创建两类Timer:
Oneshot类型(默认):只触发一次超时,然后该Timer会被注销
Period类型:可以循环触发超时,对应参数
-m period
test_hrtimer
命令的帮助信息如下:
aic /> test_hrtimer -h
Usage: test_hrtimer [options]:
-m, --mode mode of timer, oneshot/period
-c, --channel the number of hrtimer [0, 2]
-s, --second the second of timer (must > 0)
-u, --microsecond the microsecond of timer (must > 0)
-d, --debug show the timeout log
-h, --usage
Example: test_hrtimer -m oneshot -c 0 -s 2 -u 3
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
- 使用举例1: 使用HRTimer0启动一个Oneshot(默认类型)定时器,超时时间是 2秒4微秒的定时器:
aic /> test_hrtimer -c 0 -s 2 -u 4 -d
hrtimer0: Create a timer of 2.000004 sec, Oneshot mode
aic /> 0/0 hrtimer0 timeout callback! Elapsed 2000012 us
1
2
3
2
3
- 使用举例2: 使用HRTimer0启动一个Period(默认类型)定时器,超时时间是 3秒123微秒的定时器:
aic /> test_hrtimer -c 0 -s 3 -u 123 -d -m period
hrtimer0: Create a timer of 3.000123 sec, Period mode
Will loop 19 times
aic /> 0/19 hrtimer0 timeout callback! Elapsed 3000129 us
1/19 hrtimer0 timeout callback! Elapsed 2995773 us
2/19 hrtimer0 timeout callback! Elapsed 2995775 us
3/19 hrtimer0 timeout callback! Elapsed 2995775 us
4/19 hrtimer0 timeout callback! Elapsed 2995775 us
5/19 hrtimer0 timeout callback! Elapsed 2995776 us
6/19 hrtimer0 timeout callback! Elapsed 2995775 us
7/19 hrtimer0 timeout callback! Elapsed 2995776 us
8/19 hrtimer0 timeout callback! Elapsed 2995776 us
9/19 hrtimer0 timeout callback! Elapsed 2995776 us
10/19 hrtimer0 timeout callback! Elapsed 2995776 us
11/19 hrtimer0 timeout callback! Elapsed 2995688 us
12/19 hrtimer0 timeout callback! Elapsed 2995689 us
13/19 hrtimer0 timeout callback! Elapsed 2995689 us
14/19 hrtimer0 timeout callback! Elapsed 2995689 us
15/19 hrtimer0 timeout callback! Elapsed 2995689 us
16/19 hrtimer0 timeout callback! Elapsed 2995689 us
17/19 hrtimer0 timeout callback! Elapsed 2995689 us
18/19 hrtimer0 timeout callback! Elapsed 2995689 us
19/19 hrtimer0 timeout callback! Elapsed 2995689 us
aic />
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
TIP
- 因为HRTimer的精度是微秒级,所以RTOS的调度、调试信息输出都会干扰到定时器的精度,所以上述运行log看起来有一些误差,属于合理现象
test_hrtimer
命令默认不打印定时器的超时信息,需要使用-d
参数打开log- 上述命令行中的Period定时器只是为了演示效果,所以在持续大约60秒后会自动停止定时器