TIMER

Introduction

RK3399 has 12 Timers (Timer0-Timer11), 12 Secure Timers (Stimer0~Stimer11) and 2 Timers (Pmutimer0~Pmutimer1), we mainly use the Timers (Timer0-Timer11) clock frequency is 24MHZ, the working mode has free-running and user-defined count mode.

Framework

_images/timer1.png

Working mode

User-defined count: Timer loads the initial value to registers TIMERn_LOAD_COUNT3 and TIMER_LOADn_COUNT2. When the time accumulative value is in registers TIMERn_LOAD_COUNT1 and TIMERn_LOAD_COUNT0, it will not be loaded into the counting register automatically. The user needs to re-close the counter and then reset the counter to continue working.

Free-running : Timer loads the initial value into registers TIMER_LOAD_COUNT3 and TIMER_LOAD_COUNT2. When the time accumulative value is in registers TIMERn_LOAD_COUNT1 and TIMERn_LOAD_COUNT0, Timer will always automatically load the count register.

Software configuration

The Timer configuration is defined in kernel/arch/arm64/boot/dts/rockchip/rk3399.dtsi:

rktimer: rktimer@ff850000 {
    compatible = "rockchip,rk3399-timer";
    reg = <0x0 0xff850000 0x0 0x1000>;
    interrupts = <GIC_SPI 81 IRQ_TYPE_LEVEL_HIGH 0>;
    clocks = <&cru PCLK_TIMER0>, <&cru SCLK_TIMER00>;
    clock-names = "pclk", "timer";
};

The interrupt Numbers for other Timers are shown in the picture below:

_images/timer2.png

Corresponding driver files is in Kernel/drivers/clocksource/rockchip_timer.c

Registers and usage

  1. Register picture:

    _images/timer3.png

  2. view the corresponding register

    root@rk3399_firefly_box:/ # io -4 0xff85001c  //View the status of the current control register
    ff85001c:  00000007
    
    root@rk3399_firefly_box:/ # io -4 0xff850000  //Check the current value of the register
    ff850000:  0001639f
    
  3. Control corresponding register:

    root@rk3399_firefly_box:/ # io -4 -w 0xff85001c 0x06  //Turn off time counting