SimpleOTA client v1.0.0
Shared core of the SimpleOTA Arduino and ESP-IDF clients
Loading...
Searching...
No Matches
sota_wdt_calc.h File Reference

Deadline maths for the chip watchdog that resets a hung trial. More...

Go to the source code of this file.

Macros

#define SOTA_TRIAL_WDT_MARGIN_S   60u
 Smallest extra seconds added to the confirm timeout.
 

Functions

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 longer.
 
static uint32_t sota_wdt_margin_sec (uint32_t confirm_sec, uint32_t floor_sec)
 Extra seconds on top of the confirm timeout.
 
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.
 

Detailed Description

Deadline maths for the chip watchdog that resets a hung trial.

During a SimpleOTA trial the RTC (or LP) watchdog runs on the chip's slow clock, so it still fires when a hang stops the confirm timer. It resets the chip, and the bootloader then returns to the previous image, or, without bootloader rollback, the engine rolls back the trial that booted after a watchdog. It waits for the confirm timeout plus a margin: the larger of a floor and 10 percent of the confirm timeout.

The floor covers one request, so the confirm timeout's own rollback, which may be waiting behind that request, still runs first and reports confirm_timeout.

No platform types, so the host tests can include this header. The hardware calls belong to the platform port.

Function Documentation

◆ sota_wdt_floor_sec()

static uint32_t sota_wdt_floor_sec ( uint32_t  http_timeout_ms)
inlinestatic

Margin floor for a given HTTP timeout: SOTA_TRIAL_WDT_MARGIN_S, or more when one request can take longer.

A request waits up to the timeout to connect, send, receive the headers and read the body, so four timeouts, plus 10 s.

◆ sota_wdt_stage_ticks()

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 
)
inlinestatic

Stage-0 value, in slow-clock ticks, for the confirm timeout plus its margin.

cal_q13_19 is the cached slow-clock calibration (microseconds per tick, Q13.19); when it is 0, nominal_hz is used. The stage register is 32 bits: *clamped is set when the deadline does not fit, and the value saturates (about 8 hours at the usual internal slow clock, about 13 on the S2).