Timer

[English]

Timer API Status

API

BK7256

BK7256_cp1

bk_timer_driver_init()

Y

Y

bk_timer_driver_deinit()

Y

Y

bk_timer_start()

Y

Y

bk_timer_stop()

Y

Y

bk_timer_get_cnt()

Y

Y

bk_timer_enable()

Y

Y

bk_timer_disable()

Y

Y

bk_timer_get_period()

Y

Y

Timer API Reference

Header File

Functions

bk_err_t bk_timer_driver_init(void)

Init the timer driver.

This API init the resoure common to all timer channels:

  • Init timer driver control memory

This API should be called before any other timer APIs.

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_timer_driver_deinit(void)

Deinit the timer driver.

This API free all resource related to timer and power down all timer channels.

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_timer_start(timer_id_t timer_id, uint32_t time_ms, timer_isr_t callback)

Start the timer.

Attention

1. timer2 has been used for time cali

2. timer3 has been used for clock, but bk7271 use timer1

3. bk7271 has used timer0(10ms)

参数
  • timer_id – the timer ID to be started

  • time_ms – time delay value of the timer

  • callback – the timer call back function

返回

  • BK_OK: succeed

  • BK_ERR_TIMER_NOT_INIT: timer driver not init

  • BK_ERR_TIMER_ID: timer id is invalid

  • BK_ERR_TIMER_IS_RUNNING: timer id is running

  • others: other errors.

bk_err_t bk_timer_start_without_callback(timer_id_t timer_id, uint32_t time_ms)

Start the timer without set callback.

参数
  • timer_id – the timer ID to be started

  • timer_ms – time delay value of the timer

返回

  • BK_OK: succeed

  • others: others errors

bk_err_t bk_timer_stop(timer_id_t timer_id)

Stop the timer.

参数

timer_id – the timer ID to be stoped

返回

  • BK_OK: succeed

  • others: other errors.

uint32_t bk_timer_get_cnt(timer_id_t timer_id)

Get the current counter value.

Attention

1. The caller need to make sure the parameter timer_id is correct!

参数

timer_id – the timer id

返回

counter value

bk_err_t bk_timer_enable(timer_id_t timer_id)

Enable the timer.

参数

timer_id – the timer ID

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_timer_disable(timer_id_t timer_id)

Disable the timer.

参数

timer_id – the timer ID

返回

  • BK_OK: succeed

  • others: other errors.

uint32_t bk_timer_get_period(timer_id_t timer_id)

Get the counter value set by bk_timer_start()

参数

timer_id – the timer id

返回

counter value set by bk_timer_start()

uint32_t bk_timer_get_enable_status(void)

Get the timer enable status.

参数

timer_id – the timer id

返回

timer enable status

bool bk_timer_is_interrupt_triggered(timer_id_t timer_id)

Get whether the timer interrupt triggered.

参数

timer_id – the timer id

返回

the timer interrupt status

uint64_t bk_timer_get_time(timer_id_t timer_id, uint32_t div, uint32_t last_count, timer_value_unit_t unit_type)

Get the timer count value in ms or us.

参数
  • timer_id – the timer id

  • div – the divider of clock frequency

  • last_count – last count of the timer

  • timer_value_unit_t – the time unit, ms or us

返回

the timer value in micro seconds

bk_err_t bk_timer_delay_with_callback(timer_id_t timer_id, uint64_t time_us, timer_isr_t callback)

This function set the delay based on the current running counter, which is different from bk_timer_start.

参数
  • timer_id – the timer id

  • time_us – time delay value of the timer by us

  • callback – the timer delay call back function

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_timer_cancel(timer_id_t timer_id)

Cancel the timer delay task, reset timer and set ISR to NULL, it will not disable the timer, which is different from bk_timer_stop.

参数

timer_id – the timer id

返回

  • BK_OK: succeed

  • others: other errors.

Timer API Typedefs

Header File

Macros

BK_ERR_TIMER_ID

timer id is invalid

BK_ERR_TIMER_NOT_INIT

timer driver not init

BK_ERR_TIMER_IS_RUNNING

timer id is running

BK_ERR_TIMER_ID_ON_DEFCONFIG

timer id is error

Type Definitions

typedef void (*timer_isr_t)(timer_id_t timer_id)

Timer interrupt service routine.

Header File

Macros

TIMER_CLOCK_FREQ_26M
TIMER_CLOCK_FREQ_32K

Type Definitions

typedef uint8_t timer_unit_t

Timer uint id

Enumerations

enum timer_src_clk_t

Values:

enumerator TIMER_SCLK_CLK32

TIMER source clock dco

enumerator TIMER_SCLK_XTAL

TIMER source clock xtal 26M

enum sys_sel_timer_t

Values:

enumerator SYS_SEL_TIMER0
enumerator SYS_SEL_TIMER1
enum timer_id_t

Values:

enumerator TIMER_ID0

TIMER id 0

enumerator TIMER_ID1

TIMER id 1

enumerator TIMER_ID2

TIMER id 2

enumerator TIMER_ID3

TIMER id 3

enumerator TIMER_ID4

TIMER id 4

enumerator TIMER_ID5

TIMER id 5

enumerator TIMER_ID_MAX

TIMER id max

enum timer_value_unit_t

Values:

enumerator TIMER_UNIT_MS

TIMER unit type is ms

enumerator TIMER_UNIT_US

TIMER unit type is us