Timer

[中文]

1. Overview

Each timer group (Timer0/Timer1) has three 32-bit up counters driven by a shared 4-bit prescaler. Timers can raise periodic interrupts or act as hardware clocks.

See: Timer Driver Guide

2. Code Path

  • CLI: components/bk_cli/cli_timer.c

  • Driver: middleware/driver/timer/timer_driver.c

3. Configuration

Macros include CONFIG_TIMER (enable driver/CLI), CONFIG_TIMER_SUPPORT_ID_BITS (channel partition between CPUs), CONFIG_TIMER_US (microsecond delay APIs), and optional low-power callbacks.

4. Channel Mapping

No GPIO assignment required. Total of 6 channels:

  • CP: channels 0–2 (channel 2 feeds watchdog)

  • AP: channels 3–5

5. CLI Commands

Timer CLI commands

Command

Param

Description

timer {id} start {period}

id: channel (AP: 3–5); period: milliseconds

Enable timer; ISR triggers periodically

timer {id} read

id: channel

Read the counter value

timer {id} get_period

id: channel

Read the programmed period value

timer {id} stop

id: channel

Stop the timer and disable its interrupt

timer {id} enable

id: channel

Set the enable bit

timer {id} disable

id: channel

Clear the enable bit

6. Demo

Example flow on channel 3 (prefix with cpu1 for AP commands):

  • cpu1 timer 3 start 2000 – start timer; ISR logs every 2 seconds.

  • cpu1 timer 3 read – read counter.

  • cpu1 timer 3 get_period – view programmed period value.

  • cpu1 timer 3 stop – stop timer.

  • cpu1 timer 3 enable / disable – toggle counting.