4.4.4. 测试指南

4.4.4.1. 测试环境

4.4.4.1.1. 硬件

  • FPGA验证版

  • USB转串口的线缆

  • 信号源(用于测试触发模式)

  • 示波器(用于观察引脚输出)

4.4.4.1.2. 软件

  • PC 端的串口终端软件,用于 PC 和 开发板进行串口通信

  • Luban-Lite 自带的 test_gptimer 命令行工具

4.4.4.1.3. 软件配置

在 Luban-Lite 根目录下执行 scons --menuconfig,进入 menuconfig 的功能配置界面,按如下选择打开 test_gptimer 命令行工具:

Drivers options --->
    Drivers examples --->
        [*]  Enable GPTimer driver test command

同时需要打开中断打印配置:

Rt-Thread options --->
    RT-Thread Components --->
                    Utilities --->
        [*] Enable ISR log.

4.4.4.2. 测试GPTimer

test_gptimer 命令的帮助信息如下:

aic> test_gptimer -h
Usage: test_gptimer [options]:
     -m, --mode     mode of timer, oneshot/period
     -c, --channel      the number of gptimer [0, 2]
     -s, --second       the second of timer (must > 0)
     -u, --microsecond  the microsecond of timer (must > 0)
     -g, --gptmode      he mode of gptimer, count/match
     -a, --triggermode  the trigger mode of gptimer, auto/rsi/fall/bil
     -f, --frequency    the frequncy of the gptimer (must > 0)
     -d, --debug        show the timeout log
     -h, --usage

Example: test_gptimer -m period -c 0 -s 1 -u 3 -g count -a auto -f 1000 -d
  • 使用举例1: 使用 GPTimer0 的单次自动计数模式,超时时间是 1 秒 3 微秒的定时器:

aic> test_gptimer -m oneshot -c 0 -s 1 -u 3 -g count -a auto -f 1000 -d
gptimer0: Create a timer of 1.000003 sec, Oneshot mode
aic> 0/0 gptimer0 timeout callback! Elapsed 1001154 us
  • 使用举例2: 使用 GPTimer0 的循环自动计数模式,超时时间是 1 秒 3 微秒的定时器:

aic> test_gptimer -m period -c 0 -s 1 -u 3 -g count -a auto -f 1000 -d
gptimer0: Create a timer of 1.000003 sec, Period mode
    Will loop 59 times
aic> 0/59 gptimer0 timeout callback! Elapsed 1001142 us
1/59 gptimer0 timeout callback! Elapsed 995703 us
2/59 gptimer0 timeout callback! Elapsed 995912 us
3/59 gptimer0 timeout callback! Elapsed 995923 us
4/59 gptimer0 timeout callback! Elapsed 995929 us
5/59 gptimer0 timeout callback! Elapsed 995922 us
6/59 gptimer0 timeout callback! Elapsed 995918 us
7/59 gptimer0 timeout callback! Elapsed 995915 us
8/59 gptimer0 timeout callback! Elapsed 995922 us
......
59/59 gptimer0 timeout callback! Elapsed 995797 us
aic />
  • 使用举例3: 使用 GPTimer0 的单次触发计数模式,超时时间是 1 秒 3 微秒的定时器:

设置为双边沿触发,使用信号源或其他方式,往 GPTimer 输入引脚产生一个信号变化,触发启动定时器。

aic> test_gptimer -m oneshot -c 0 -s 1 -u 3 -g count -a bil -f 1000 -d
gptimer0: Create a timer of 1.000003 sec, Oneshot mode
aic> 0/59 gptimer0 timeout callback! Elapsed 25708887
  • 使用举例4: 使用 GPTimer0 的单次自动输出模式,超时时间是 1 秒 3 微秒的定时器:

aic> test_gptimer -m oneshot -c 0 -s 1 -u 3 -g match -a auto -f 1000
gptimer0: Create a timer of 1.000003 sec, Oneshot mode
  • 使用举例5: 使用 GPTimer0 的循环自动输出模式,超时时间是 1 秒 3 微秒的定时器:

aic> test_gptimer -m period -c 0 -s 1 -u 3 -g match -a auto -f 1000
gptimer0: Create a timer of 1.000003 sec, Period mode

小技巧

  1. 因为 GPTimer 的精度是微秒级,所以 RTOS 的调度、调试信息输出都会干扰到定时器的精度,所以上述运行 log 看起来有一些误差,属于合理现象

  2. test_gptimer 命令默认不打印定时器的超时信息,需要使用 -d 参数打开log

  3. 输出模式下可以使用示波器观察波形

  4. 上述命令行中的循环计数模式只是为了演示效果,所以在持续大约 60 秒后会自动停止定时器,而循环输出模式则会不断输出直至配置为其他模式

  5. 触发模式下 log 打印的时间包含启动定时器到有信号触发的时间

  6. 为了简化 test_gptimer 命令,输出引脚的配置参数在 test_gptimer.c 中的结构体 g_outval 中,可自行修改

  7. GPTimer 达到比较值后默认继续计数,可在 test_gptimer.c 中的 g_cmpa(b)_act 变量修改为停止计数或清零计数