LSH-Core
Deterministic firmware core for Controllino-based Labo Smart Home nodes
 
Loading...
Searching...
No Matches
saturating_time.hpp File Reference

Declares tiny helpers for elapsed-time arithmetic that must never wrap. More...

#include <stdint.h>
Include dependency graph for saturating_time.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

constexpr auto timeUtils::addElapsedTimeSaturated (uint16_t currentAge_ms, uint16_t elapsed_ms) -> uint16_t
 Add one elapsed-time delta to a 16-bit age without wrapping.
 

Detailed Description

Declares tiny helpers for elapsed-time arithmetic that must never wrap.

Author
Jacopo Labardi (labodj)

Copyright 2026 Jacopo Labardi

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ addElapsedTimeSaturated()

constexpr auto timeUtils::addElapsedTimeSaturated ( uint16_t  currentAge_ms,
uint16_t  elapsed_ms 
) -> uint16_t
inlineconstexpr

Add one elapsed-time delta to a 16-bit age without wrapping.

The firmware uses 16-bit "age" counters in several hot paths. Saturating the addition keeps those counters monotonic even after very long loop stalls, debugger pauses or temporary scheduling hiccups, while staying cheaper than carrying 32-bit timestamps through every object.

Parameters
currentAge_msAge already accumulated before the current loop pass.
elapsed_msAdditional milliseconds measured since the previous pass.
Returns
uint16_t Updated age, saturated at UINT16_MAX.
Here is the call graph for this function:
Here is the caller graph for this function: