Chapter 2. API Reference
esp_err_t timer_isr_callback_add(timer_group_t group_num, timer_idx_t timer_num, timer_isr_t
isr_handler, void *arg, int intr_alloc_flags)
Add ISR handle callback for the corresponding timer.
The callback should return a bool value to determine whether need to do YIELD at the end of the ISR.
Note This ISR handler will be called from an ISR. This ISR handler do not need to handle interrupt status,
and should be kept short. If you want to realize some specific applications or write the whole ISR, you
can call timer_isr_register(…) to register ISR.
Parameters
• group_num: Timer group number
• timer_num: Timer index of timer group
• isr_handler: Interrupt handler function, it is a callback function.
• arg: Parameter for handler function
• intr_alloc_flags: Flags used to allocate the interrupt. One or multiple (ORred)
ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
If the intr_alloc_flags value ESP_INTR_FLAG_IRAM is set, the handler function must be declared with
IRAM_ATTR attribute and can only call functions in IRAM or ROM. It cannot call other timer APIs.
Return
• ESP_OK Success
• ESP_ERR_INVALID_ARG Parameter error
esp_err_t timer_isr_callback_remove(timer_group_t group_num, timer_idx_t timer_num)
Remove ISR handle callback for the corresponding timer.
Return
• ESP_OK Success
• ESP_ERR_INVALID_ARG Parameter error
Parameters
• group_num: Timer group number
• timer_num: Timer index of timer group
esp_err_t timer_isr_register(timer_group_t group_num, timer_idx_t timer_num, void (*fn))void *
, void *arg, int intr_alloc_flags, timer_isr_handle_t *handleRegister Timer interrupt handler, the handler is an
ISR. The handler will be attached to the same CPU core that this function is running on.
If the intr_alloc_flags value ESP_INTR_FLAG_IRAM is set, the handler function must be declared with
IRAM_ATTR attribute and can only call functions in IRAM or ROM. It cannot call other timer APIs. Use
direct register access to configure timers from inside the ISR in this case.
Note If use this function to reigster ISR, you need to write the whole ISR. In the interrupt handler, you need to
call timer_spinlock_take(..) before your handling, and call timer_spinlock_give(…) after your handling.
Parameters
• group_num: Timer group number
• timer_num: Timer index of timer group
• fn: Interrupt handler function.
• arg: Parameter for handler function
• intr_alloc_flags: Flags used to allocate the interrupt. One or multiple (ORred)
ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
• handle: Pointer to return handle. If non-NULL, a handle for the interrupt will be returned here.
Return
• ESP_OK Success
• ESP_ERR_INVALID_ARG Parameter error
esp_err_t timer_init(timer_group_t group_num, timer_idx_t timer_num, const timer_config_t *config)
Initializes and configure the timer.
Return
• ESP_OK Success
• ESP_ERR_INVALID_ARG Parameter error
Parameters
Espressif Systems 243
Submit Document Feedback
Release v4.4