MilkV Duo RT-Thread HWtimer 对接

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
    
  • 23
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值