Skip to content

timerRestart does not restart timer #2944

Closed
@Javerre

Description

@Javerre

The implementation of timerRestart in esp32-hal-timers.c is as follows:

void timerRestart(hw_timer_t *timer) {
    timer->dev->config.enable = 0;
    timer->dev->config.enable = 1;
}

However, according to the ESP32 reference manual it appears this will have no net effect:

Counting can be enabled and disabled by setting and clearing TIMGn_Tx_EN. Clearing this bit essentially freezes the counter, causing it to neither count up nor count down; instead, it retains its value until TIMGn_Tx_EN is set again.

Clearing and resetting the timer enable bit as implemented above will have the effect of pausing the timer for a few cycles. This might be what is intended but I suspect not! My expectation was that calling timerRestart would cause the timer to restart, i.e. to start counting from the beginning. It appears from the reference manual that this is accomplished by reloading the timer instead:

To trigger a software instant reload, any value can be written to the register TIMGn_Tx_LOAD_REG; this will cause the counter value to change instantly

Which would imply the following code for timerRestart might be more appropriate:

void timerRestart(hw_timer_t *timer) {
    timer->dev->reload = 1;
    timer->dev->config.enable = 1;
}

Am I missing something here, or is this a bug? I need this functionality to implement a timeout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions