-
Notifications
You must be signed in to change notification settings - Fork 182
Open
Description
The time retrieval function for Clock::now() relies on the platform-defined function mocpp_tick_ms(). For ESP-IDF, this function is defined as follows:
unsigned long mocpp_tick_ms_espidf() {
auto ticks_now = xTaskGetTickCount();
MicroOcpp::mocpp_millis_count += ((ticks_now - MicroOcpp::mocpp_ticks_count) * 1000UL) / configTICK_RATE_HZ;
MicroOcpp::mocpp_ticks_count = ticks_now;
return MicroOcpp::mocpp_millis_count;
}
While the frequency of xTaskGetTickCount() is configurable (defaults to 1000), on the Xtensa architecture unsigned long and TickType_t are both defined as 32-bits. This means that, regardless of the tick counter configuration, a value like mocpp_millis_count will overflow after ~49.7 days of continuous operation.
Clock::now() does not account for this rollover and simply calculates the difference, allowing a potentially negative time difference to be applied to the internal clock.
Metadata
Metadata
Assignees
Labels
No labels