project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp: Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem. sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately. sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades. sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for fastboot. Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
2.1 KiB
2.1 KiB
定时器设备
功能
- 时间测量
- 周期或单次执行回调函数
编译
- 在rtconfig.h添加
#define RT_USING_HWTIMER
使用流程
- 以读写方式打开设备
- 设置超时回调函数(如果需要)
- 根据需要设置定时模式(单次/周期)
- 设置计数频率(可选)
- 写入超时值,定时器随即启动
- 停止定时器(可选)
- 关闭设备(如果需要)
应用参考 [hwtimer_test] (/examples/test/hwtimer_test.c)
驱动编写指南
操作接口
struct rt_hwtimer_ops
{
void (*init)(struct rt_hwtimer_device *timer, rt_uint32_t state);
rt_err_t (*start)(struct rt_hwtimer_device *timer, rt_uint32_t cnt, rt_hwtimer_mode_t mode);
void (*stop)(struct rt_hwtimer_device *timer);
rt_uint32_t (*count_get)(struct rt_hwtimer_device *timer);
rt_err_t (*control)(struct rt_hwtimer_device *timer, rt_uint32_t cmd, void *args);
};
- init - state <1 打开设备 0 关闭设备>
- start - cnt <超时值> - mode <单次/周期>
- stop - <停止计数>
- count_get - <读取计数器值>
- control - <设置计数频率 >
定时器特征信息
struct rt_hwtimer_info
{
rt_int32_t maxfreq;
rt_int32_t minfreq;
rt_uint32_t maxcnt;
rt_uint8_t cntmode;
};
- maxfreq <设备支持的最大计数频率>
- minfreq <设备支持的最小计数频率>
- maxcnt <计数器最大计数值>
- cntmode <递增计数/递减计数>
注册设备
static rt_hwtimer_t _timer0;
int stm32_hwtimer_init(void)
{
_timer0.info = &_info;
_timer0.ops = &_ops;
rt_device_hwtimer_register(&_timer0, "timer0", TIM2);
return 0;
}
定时器中断
void timer_irq_handler(void)
{
//其它操作
rt_device_hwtimer_isr(&_timer0);
}
注意事项
可能出现定时误差
误差原因:
假设计数器最大值0xFFFF,计数频率1Mhz,定时时间1秒又1微秒。
由于定时器一次最多只能计时到65535us,对于1000001us的定时要求。 可以50000us定时20次完成,此时将会出现计算误差1us。