Collaboration diagram for Hardware Timer Driver:

Classes

struct  hw_timer_private_t
 

Macros

#define MAX_HW_TIMER1_INTERVAL   0x7fffff
 Maximum timer interval in ticks. More...
 
#define MIN_HW_TIMER1_INTERVAL_US   50U
 Minimum hardware interval in microseconds. More...
 
#define HW_TIMER2_CLKDIV   TIMER_CLKDIV_256
 
#define HW_TIMER2_CLK   (HW_TIMER_BASE_CLK >> HW_TIMER2_CLKDIV)
 
#define MAX_HW_TIMER1_INTERVAL   0x7fffffffU
 Maximum timer interval in ticks. More...
 
#define MIN_HW_TIMER1_INTERVAL_US   50U
 Minimum hardware interval in microseconds. More...
 
#define HW_TIMER2_CLK   HW_TIMER_BASE_CLK
 
#define HW_TIMER1_GROUP   0
 
#define HW_TIMER1_INDEX   0
 
#define MAX_HW_TIMER1_INTERVAL   0x7fffffff
 Maximum timer interval in ticks. More...
 
#define MIN_HW_TIMER1_INTERVAL_US   50U
 Minimum hardware interval in microseconds. More...
 
#define NOW()   hw_timer2_read()
 

Typedefs

typedef void(* hw_timer_callback_t) (void *arg)
 
typedef void(* hw_timer_callback_t) (void *arg)
 
typedef void(* hw_timer_callback_t) (void *arg)
 

Enumerations

enum  hw_timer_clkdiv_t {
  TIMER_CLKDIV_1 = 0, TIMER_CLKDIV_16 = 4, TIMER_CLKDIV_256 = 8, TIMER_CLKDIV_1,
  TIMER_CLKDIV_16, TIMER_CLKDIV_256, TIMER_CLKDIV_1 = 0, TIMER_CLKDIV_16 = 4,
  TIMER_CLKDIV_256 = 8
}
 
enum  hw_timer_intr_type_t {
  TIMER_EDGE_INT = 0, TIMER_LEVEL_INT = 1, TIMER_EDGE_INT, TIMER_LEVEL_INT,
  TIMER_EDGE_INT = 0, TIMER_LEVEL_INT = 1
}
 
enum  hw_timer_source_type_t {
  TIMER_FRC1_SOURCE = 0, TIMER_NMI_SOURCE = 1, TIMER_FRC1_SOURCE, TIMER_NMI_SOURCE,
  TIMER_FRC1_SOURCE = 0, TIMER_NMI_SOURCE = 1
}
 
enum  hw_timer_clkdiv_t {
  TIMER_CLKDIV_1 = 0, TIMER_CLKDIV_16 = 4, TIMER_CLKDIV_256 = 8, TIMER_CLKDIV_1,
  TIMER_CLKDIV_16, TIMER_CLKDIV_256, TIMER_CLKDIV_1 = 0, TIMER_CLKDIV_16 = 4,
  TIMER_CLKDIV_256 = 8
}
 
enum  hw_timer_intr_type_t {
  TIMER_EDGE_INT = 0, TIMER_LEVEL_INT = 1, TIMER_EDGE_INT, TIMER_LEVEL_INT,
  TIMER_EDGE_INT = 0, TIMER_LEVEL_INT = 1
}
 
enum  hw_timer_source_type_t {
  TIMER_FRC1_SOURCE = 0, TIMER_NMI_SOURCE = 1, TIMER_FRC1_SOURCE, TIMER_NMI_SOURCE,
  TIMER_FRC1_SOURCE = 0, TIMER_NMI_SOURCE = 1
}
 
enum  hw_timer_clkdiv_t {
  TIMER_CLKDIV_1 = 0, TIMER_CLKDIV_16 = 4, TIMER_CLKDIV_256 = 8, TIMER_CLKDIV_1,
  TIMER_CLKDIV_16, TIMER_CLKDIV_256, TIMER_CLKDIV_1 = 0, TIMER_CLKDIV_16 = 4,
  TIMER_CLKDIV_256 = 8
}
 
enum  hw_timer_intr_type_t {
  TIMER_EDGE_INT = 0, TIMER_LEVEL_INT = 1, TIMER_EDGE_INT, TIMER_LEVEL_INT,
  TIMER_EDGE_INT = 0, TIMER_LEVEL_INT = 1
}
 
enum  hw_timer_source_type_t {
  TIMER_FRC1_SOURCE = 0, TIMER_NMI_SOURCE = 1, TIMER_FRC1_SOURCE, TIMER_NMI_SOURCE,
  TIMER_FRC1_SOURCE = 0, TIMER_NMI_SOURCE = 1
}
 

Functions

void hw_timer1_attach_interrupt (hw_timer_source_type_t source_type, hw_timer_callback_t callback, void *arg)
 Attach an interrupt for the timer. More...
 
void hw_timer1_enable (hw_timer_clkdiv_t div, hw_timer_intr_type_t intr_type, bool auto_load)
 Enable the timer. More...
 
void hw_timer1_write (uint32_t ticks)
 Set the timer interval. More...
 
void hw_timer1_disable (void)
 Disable the timer. More...
 
void hw_timer1_detach_interrupt (void)
 Detach interrupt from the timer. More...
 
uint32_t hw_timer1_read (void)
 Get timer1 count. More...
 
uint32_t hw_timer2_read (void)
 Read current timer2 value. More...
 
void hw_timer2_set_alarm (uint32_t ticks)
 Set timer2 alarm count value. More...
 
void hw_timer_init (void)
 Initialise hardware timers. More...
 
uint32_t hw_timer_ticks ()
 Fetch 32-bit microsecond count. More...
 

Variables

struct hw_timer_private_t hw_timer_private
 

Detailed Description

Note
Timers are 64-bit but for compatibility limit to 31 bits

Macro Definition Documentation

◆ HW_TIMER1_GROUP

#define HW_TIMER1_GROUP   0

◆ HW_TIMER1_INDEX

#define HW_TIMER1_INDEX   0

◆ HW_TIMER2_CLK [1/2]

#define HW_TIMER2_CLK   HW_TIMER_BASE_CLK

◆ HW_TIMER2_CLK [2/2]

#define HW_TIMER2_CLK   (HW_TIMER_BASE_CLK >> HW_TIMER2_CLKDIV)

◆ HW_TIMER2_CLKDIV

#define HW_TIMER2_CLKDIV   TIMER_CLKDIV_256

◆ MAX_HW_TIMER1_INTERVAL [1/3]

#define MAX_HW_TIMER1_INTERVAL   0x7fffff

Maximum timer interval in ticks.

Note
The corresponding time interval depends on the prescaler in use:
    /1 - 0.1048s
    /16 - 1.677s
    /256 - 26.84s

◆ MAX_HW_TIMER1_INTERVAL [2/3]

#define MAX_HW_TIMER1_INTERVAL   0x7fffffffU

Maximum timer interval in ticks.

◆ MAX_HW_TIMER1_INTERVAL [3/3]

#define MAX_HW_TIMER1_INTERVAL   0x7fffffff

Maximum timer interval in ticks.

Note
The corresponding time interval depends on the prescaler in use:
    /1 - 26.84s
    /16 - 429.50s
    /256 - 6871.95s

ESP32 supports a wide range of prescalers and uses 54-bit counter value. Limiting the range 31 bits avoids issues with overflows and moving to 64-bit calculations.

◆ MIN_HW_TIMER1_INTERVAL_US [1/3]

#define MIN_HW_TIMER1_INTERVAL_US   50U

Minimum hardware interval in microseconds.

Note
Attempting to use repetitive interrupts below this level can lead to system instabliity and lockups, due to the software overhead in servicing the interrupts.

◆ MIN_HW_TIMER1_INTERVAL_US [2/3]

#define MIN_HW_TIMER1_INTERVAL_US   50U

Minimum hardware interval in microseconds.

Note
Attempting to use repetitive interrupts below this level can lead to system instabliity and lockups, due to the software overhead in servicing the interrupts.

◆ MIN_HW_TIMER1_INTERVAL_US [3/3]

#define MIN_HW_TIMER1_INTERVAL_US   50U

Minimum hardware interval in microseconds.

Note
Attempting to use repetitive interrupts below this level can lead to system instabliity and lockups, due to the software overhead in servicing the interrupts.

◆ NOW

#define NOW ( )    hw_timer2_read()

Typedef Documentation

◆ hw_timer_callback_t [1/3]

typedef void(* hw_timer_callback_t) (void *arg)

◆ hw_timer_callback_t [2/3]

typedef void(* hw_timer_callback_t) (void *arg)

◆ hw_timer_callback_t [3/3]

typedef void(* hw_timer_callback_t) (void *arg)

Enumeration Type Documentation

◆ hw_timer_clkdiv_t [1/3]

Enumerator
TIMER_CLKDIV_1 
TIMER_CLKDIV_16 
TIMER_CLKDIV_256 
TIMER_CLKDIV_1 
TIMER_CLKDIV_16 
TIMER_CLKDIV_256 
TIMER_CLKDIV_1 
TIMER_CLKDIV_16 
TIMER_CLKDIV_256 

◆ hw_timer_clkdiv_t [2/3]

Enumerator
TIMER_CLKDIV_1 
TIMER_CLKDIV_16 
TIMER_CLKDIV_256 
TIMER_CLKDIV_1 
TIMER_CLKDIV_16 
TIMER_CLKDIV_256 
TIMER_CLKDIV_1 
TIMER_CLKDIV_16 
TIMER_CLKDIV_256 

◆ hw_timer_clkdiv_t [3/3]

Enumerator
TIMER_CLKDIV_1 
TIMER_CLKDIV_16 
TIMER_CLKDIV_256 
TIMER_CLKDIV_1 
TIMER_CLKDIV_16 
TIMER_CLKDIV_256 
TIMER_CLKDIV_1 
TIMER_CLKDIV_16 
TIMER_CLKDIV_256 

◆ hw_timer_intr_type_t [1/3]

Enumerator
TIMER_EDGE_INT 
TIMER_LEVEL_INT 
TIMER_EDGE_INT 
TIMER_LEVEL_INT 
TIMER_EDGE_INT 
TIMER_LEVEL_INT 

◆ hw_timer_intr_type_t [2/3]

Enumerator
TIMER_EDGE_INT 
TIMER_LEVEL_INT 
TIMER_EDGE_INT 
TIMER_LEVEL_INT 
TIMER_EDGE_INT 
TIMER_LEVEL_INT 

◆ hw_timer_intr_type_t [3/3]

Enumerator
TIMER_EDGE_INT 
TIMER_LEVEL_INT 
TIMER_EDGE_INT 
TIMER_LEVEL_INT 
TIMER_EDGE_INT 
TIMER_LEVEL_INT 

◆ hw_timer_source_type_t [1/3]

Enumerator
TIMER_FRC1_SOURCE 
TIMER_NMI_SOURCE 
TIMER_FRC1_SOURCE 
TIMER_NMI_SOURCE 
TIMER_FRC1_SOURCE 
TIMER_NMI_SOURCE 

◆ hw_timer_source_type_t [2/3]

Enumerator
TIMER_FRC1_SOURCE 
TIMER_NMI_SOURCE 
TIMER_FRC1_SOURCE 
TIMER_NMI_SOURCE 
TIMER_FRC1_SOURCE 
TIMER_NMI_SOURCE 

◆ hw_timer_source_type_t [3/3]

Enumerator
TIMER_FRC1_SOURCE 
TIMER_NMI_SOURCE 
TIMER_FRC1_SOURCE 
TIMER_NMI_SOURCE 
TIMER_FRC1_SOURCE 
TIMER_NMI_SOURCE 

Function Documentation

◆ hw_timer1_attach_interrupt()

void hw_timer1_attach_interrupt ( hw_timer_source_type_t  source_type,
hw_timer_callback_t  callback,
void *  arg 
)

Attach an interrupt for the timer.

Parameters
source_type
callbackCallback function invoked via timer interrupt
argPassed to callback function
source_typeIgnored, uses APB clock source
callbackCallback function invoked via timer interrupt
argPassed to callback function

◆ hw_timer1_detach_interrupt()

void hw_timer1_detach_interrupt ( void  )

Detach interrupt from the timer.

◆ hw_timer1_disable()

void hw_timer1_disable ( void  )

Disable the timer.

◆ hw_timer1_enable()

void hw_timer1_enable ( hw_timer_clkdiv_t  div,
hw_timer_intr_type_t  intr_type,
bool  auto_load 
)
inline

Enable the timer.

Parameters
div
intr_type
auto_load
div
intr_typeIgnored, always level-triggered
auto_load

◆ hw_timer1_read()

uint32_t hw_timer1_read ( void  )

Get timer1 count.

Return values
uint32_tCurrent count value, counts from initial value down to 0

◆ hw_timer1_write()

void hw_timer1_write ( uint32_t  ticks)

Set the timer interval.

Set the timer interval and arm.

Parameters
ticks

◆ hw_timer2_read()

static uint32_t hw_timer2_read ( void  )

Read current timer2 value.

Return values
uint32_t

◆ hw_timer2_set_alarm()

void hw_timer2_set_alarm ( uint32_t  ticks)

Set timer2 alarm count value.

Parameters
ticks
Note
For internal use ONLY; used by software timers

◆ hw_timer_init()

void hw_timer_init ( void  )

Initialise hardware timers.

Note
Called by startup code

◆ hw_timer_ticks()

uint32_t hw_timer_ticks ( )

Fetch 32-bit microsecond count.

All timers reference from a single 64-bit counter. We use only the lower 32 bits here as it provides lowest latency and compatibility with existing API.

Variable Documentation

◆ hw_timer_private

struct hw_timer_private_t hw_timer_private