SimpleOTA client main
Shared core of the SimpleOTA Arduino and ESP-IDF clients
Loading...
Searching...
No Matches
sota_time.h
Go to the documentation of this file.
1
13#ifndef SOTA_TIME_H
14#define SOTA_TIME_H
15
16#include <stdint.h>
17
19#define SOTA_MAX_WAIT_TICKS (UINT32_MAX - 1u)
20
22static inline uint32_t sota_ms_to_ticks(uint64_t ms, uint32_t tick_hz)
23{
24 const uint64_t ticks = ms * (uint64_t)tick_hz / 1000u;
25 return ticks > SOTA_MAX_WAIT_TICKS ? SOTA_MAX_WAIT_TICKS : (uint32_t)ticks;
26}
27
29static inline uint32_t sota_s_to_ticks(uint32_t s, uint32_t tick_hz)
30{
31 return sota_ms_to_ticks((uint64_t)s * 1000u, tick_hz);
32}
33
34#endif /* SOTA_TIME_H */
#define SOTA_MAX_WAIT_TICKS
The longest finite wait.
Definition sota_time.h:19
static uint32_t sota_ms_to_ticks(uint64_t ms, uint32_t tick_hz)
Ticks for a duration in milliseconds, saturated to SOTA_MAX_WAIT_TICKS.
Definition sota_time.h:22
static uint32_t sota_s_to_ticks(uint32_t s, uint32_t tick_hz)
Ticks for a duration in seconds, saturated to SOTA_MAX_WAIT_TICKS.
Definition sota_time.h:29