TIMER

Introduction

RK3399 has 12 Timers (timer0-timer11), 12 SecureT imers (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.

The 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

1 . Defined in DTS files associated with the Timer configuration: 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";
};

Where defined Timer0 register and interrupt number and clock etc

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

_images/timer2.png

2 . Corresponding driver files : Kernel/drivers/clocksource/rockchip_timer.c

Corresponding registers and usage

1 . Register picture below

_images/timer3.png

2 . Use mode, 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

Control corresponding register:

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