22#ifndef SOTA_WDT_CALC_H
23#define SOTA_WDT_CALC_H
29#define SOTA_TRIAL_WDT_MARGIN_S 60u
39 uint64_t request_s = ((uint64_t)http_timeout_ms * 4u + 999u) / 1000u + 10u;
41 return request_s > UINT32_MAX ? UINT32_MAX : (uint32_t)request_s;
47 uint32_t tenth = confirm_sec / 10u;
48 return tenth > floor_sec ? tenth : floor_sec;
60 uint32_t cal_q13_19, uint32_t nominal_hz,
65 if (cal_q13_19 != 0) {
66 uint64_t us = seconds * 1000000u;
67 ticks = us > (UINT64_MAX >> 19) ? UINT64_MAX : (us << 19) / cal_q13_19;
69 ticks = seconds * (uint64_t)(nominal_hz ? nominal_hz : 1u);
71 *clamped = ticks > UINT32_MAX;
72 if (*clamped)
return UINT32_MAX;
73 return ticks < 2 ? 2u : (uint32_t)ticks;
static uint32_t sota_wdt_floor_sec(uint32_t http_timeout_ms)
Margin floor for a given HTTP timeout: SOTA_TRIAL_WDT_MARGIN_S, or more when one request can take lon...
Definition sota_wdt_calc.h:37
static uint32_t sota_wdt_stage_ticks(uint32_t confirm_sec, uint32_t floor_sec, uint32_t cal_q13_19, uint32_t nominal_hz, bool *clamped)
Stage-0 value, in slow-clock ticks, for the confirm timeout plus its margin.
Definition sota_wdt_calc.h:59
static uint32_t sota_wdt_margin_sec(uint32_t confirm_sec, uint32_t floor_sec)
Extra seconds on top of the confirm timeout.
Definition sota_wdt_calc.h:45
#define SOTA_TRIAL_WDT_MARGIN_S
Smallest extra seconds added to the confirm timeout.
Definition sota_wdt_calc.h:29