MilkV Duo RT-Thread HWtimer 对接
参考官方datasheet
针对 RT-Thread 设备驱动,需要对接以下方法
static const struct rt_hwtimer_ops _hwtimer_ops = {
.init = _hwtimer_init,
.start = _hwtimer_start,
.stop = _hwtimer_stop,
.count_get = _hwtimer_count_get,
.control = _hwtimer_control
};
基于操作寄存器的 hwtimer 驱动来自于 sophgo/cvi_alios_open
本文主要记录一些需要注意的细节:
-
datasheet 中指明:系统 Timer 可选 25MHz /32KHz 计数时钟。使用 reg_timer_clk_sel 做选择。因此驱动中只有两个定时器频率可选,当前默认使用 25MHz
-
大小核中断号不一致,当前官方datasheet中的中断表为大核中断号,小核中断号在 Milk-V Duo Official buildroot SDK 文件中查看:duo-buildroot-sdk/freertos/cvitek/hal/cv180x/config/intr_conf.h
-
由于小核只有Timer47有对应的中断号,因此只对接了Timer47的设备驱动,大核具备Timer0~7完整的中断号,因此小核 board/Kconfig 文件添加如下:
menuconfig BSP_USING_HWTIMER bool "Enable HWTIMER" default n select RT_USING_HWTIMER if BSP_USING_HWTIMER config BSP_USING_TIMER4 bool "Enable HWTIMER4" default n config BSP_USING_TIMER5 bool "Enable HWTIMER5" default n config BSP_USING_TIMER6 bool "Enable HWTIMER6" default n config BSP_USING_TIMER7 bool "Enable HWTIMER7" default n if SOC_TYPE_CV180X config TIMER_IRQ_BASE int default 51 endif if SOC_TYPE_SG2002 config TIMER_IRQ_BASE int default 55 endif endif
大核 board/Kconfig 文件添加如下:
menuconfig BSP_USING_HWTIMER bool "Enable HWTIMER" default n select RT_USING_HWTIMER if BSP_USING_HWTIMER config BSP_USING_TIMER0 bool "Enable HWTIMER0" default n config BSP_USING_TIMER1 bool "Enable HWTIMER1" default n config BSP_USING_TIMER2 bool "Enable HWTIMER2" default n config BSP_USING_TIMER3 bool "Enable HWTIMER4" default n config BSP_USING_TIMER4 bool "Enable HWTIMER4" default n config BSP_USING_TIMER5 bool "Enable HWTIMER5" default n config BSP_USING_TIMER6 bool "Enable HWTIMER6" default n config BSP_USING_TIMER7 bool "Enable HWTIMER7" default n if SOC_TYPE_CV180X config TIMER_IRQ_BASE int default 80 endif if SOC_TYPE_SG2002 config TIMER_IRQ_BASE int default 79 endif endif