测试指南
测试环境:
- 硬件
-
开发板
-
USB 转串口的线缆
-
- 软件
-
PC 端的串口终端软件,用于 PC 和开发板进行串口通信
-
Luban-Lite 自带的
test_hrtimer
命令行工具
-
软件配置
在 Luban-Lite 根目录下执行 scons --menuconfig
,进入 menuconfig 的功能配置界面,按如下选择打开
test_hrtimer
命令行工具:
Drivers options ---> Drivers examples ---> [*] Enable HRTimer driver test command
测试 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: 使用 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
-
使用举例 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 19times 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 />
小技巧
-
因为 HRTimer 的精度是微秒级,所以 RTOS 的调度、调试信息输出都会干扰到定时器的精度,所以上述运行 log 看起来有一些误差,属于合理现象
-
test_hrtimer
命令默认不打印定时器的超时信息,需要使用-d
参数打开 log -
上述命令行中的 Period 定时器只是为了演示效果,所以在持续大约 60 秒后会自动停止定时器