Hardware Timer

API Reference

Header File

Functions

esp_err_t hw_timer_set_clkdiv(hw_timer_clkdiv_t clkdiv)

Set the frequency division coefficient of hardware timer.

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG Parameter error

  • ESP_FAIL hardware timer has been initialized

Parameters
  • clkdiv: frequency division coefficient

uint32_t hw_timer_get_clkdiv()

Get the frequency division coefficient of hardware timer.

Return

  • 0 TIMER_CLKDIV_1

  • 4 TIMER_CLKDIV_16

  • 8 TIMER_CLKDIV_256

esp_err_t hw_timer_set_intr_type(hw_timer_intr_type_t intr_type)

Set the interrupt type of hardware timer.

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG Parameter error

  • ESP_FAIL hardware timer has been initialized

Parameters
  • intr_type: interrupt type

uint32_t hw_timer_get_intr_type()

Get the interrupt type of hardware timer.

Return

  • 0 TIMER_EDGE_INT

  • 1 TIMER_LEVEL_INT

esp_err_t hw_timer_set_reload(bool reload)

Enable hardware timer reload.

Return

  • ESP_OK Success

  • ESP_FAIL hardware timer has been initialized

Parameters
  • reload: false, one-shot mode; true, reload mode

bool hw_timer_get_reload()

Get the hardware timer reload status.

Return

  • true reload mode

  • false one-shot mode

esp_err_t hw_timer_enable(bool en)

Enable hardware timer.

Return

  • ESP_OK Success

  • ESP_FAIL hardware timer has been initialized

Parameters
  • en: false, hardware timer disable; true, hardware timer enable

bool hw_timer_get_enable()

Get the hardware timer enable status.

Return

  • true hardware timer has been enabled

  • false hardware timer is not yet enabled

esp_err_t hw_timer_set_load_data(uint32_t load_data)

Set the hardware timer load value.

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG Parameter error

  • ESP_FAIL hardware timer has been initialized

Parameters
  • load_data: hardware timer load value

    • FRC1 hardware timer, range : less than 0x1000000

uint32_t hw_timer_get_load_data()

Get the hardware timer load value.

Return

load value

uint32_t hw_timer_get_count_data()

Get the hardware timer count value.

Return

count value

esp_err_t hw_timer_deinit(void)

deinit the hardware timer

Return

  • ESP_OK Success

  • ESP_FAIL hardware timer has not been initialized yet

esp_err_t hw_timer_init(hw_timer_callback_t callback, void *arg)

Initialize the hardware timer.

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG Parameter error

  • ESP_FAIL hardware timer has been initialized

Parameters
  • callback: user hardware timer callback function

  • arg: parameter for ISR handler

esp_err_t hw_timer_alarm_us(uint32_t value, bool reload)

Set a trigger timer us delay to enable this timer.

Return

  • ESP_OK Success

  • ESP_ERR_INVALID_ARG Parameter error

  • ESP_FAIL hardware timer has not been initialized yet

Parameters
  • value:

    • If reload is true, range : 50 ~ 0x199999

    • If reload is false, range : 10 ~ 0x199999

  • reload: false, one-shot mode; true, reload mode.

esp_err_t hw_timer_disarm(void)

disable this timer

Return

  • ESP_OK Success

  • ESP_FAIL hardware timer has not been initialized yet

Macros

TIMER_BASE_CLK

Type Definitions

typedef void (*hw_timer_callback_t)(void *arg)

Enumerations

enum hw_timer_clkdiv_t

Values:

TIMER_CLKDIV_1 = 0
TIMER_CLKDIV_16 = 4
TIMER_CLKDIV_256 = 8
enum hw_timer_intr_type_t

Values:

TIMER_EDGE_INT = 0
TIMER_LEVEL_INT = 1