dal-c library ← coverage

§ Coverage

src/sc_watchdog.c

1/*2 * sc_watchdog.c -- implementation. Blocks are tagged with the low-level3 * requirement they satisfy; see requirements/sc_watchdog.md.4 *5 * The elapsed count only ever advances while it is below `timeout`, so it6 * settles at `timeout` and the uint16_t increment can never wrap. The7 * tripped flag is written in exactly one place and cleared in exactly one8 * other (sc_watchdog_init); that is the whole latch.9 */10#include "sc_watchdog.h"11124sc_status_t sc_watchdog_config_valid(const sc_watchdog_config_t *cfg)13{14    sc_status_t status;15164    if (cfg == NULL)condition outcomes covered 2/217    {181        status = SC_ERR_NULL;                            /* LLR-WDG-1 */19    }203    else if (cfg->timeout == 0u)condition outcomes covered 2/221    {221        status = SC_ERR_PARAM;                           /* LLR-WDG-2 */23    }24    else25    {262        status = SC_OK;                                  /* LLR-WDG-3 */27    }28294    return status;30}313211sc_status_t sc_watchdog_init(sc_watchdog_state_t *state)33{34    sc_status_t status;353611    if (state == NULL)condition outcomes covered 2/237    {381        status = SC_ERR_NULL;                            /* LLR-WDG-4 */39    }40    else41    {4210        state->elapsed = 0u;                             /* LLR-WDG-5 */4310        state->tripped = false;4410        status = SC_OK;45    }464711    return status;48}49504void sc_watchdog_kick(sc_watchdog_state_t *state)51{524    if (state != NULL)                                   /* LLR-WDG-6 */condition outcomes covered 2/253    {543        state->elapsed = 0u;                             /* LLR-WDG-7: tripped left as-is */55    }564}575869sc_watchdog_verdict_t sc_watchdog_tick(const sc_watchdog_config_t *cfg,59                                       sc_watchdog_state_t *state)60{61    sc_watchdog_verdict_t verdict;626369    if ((cfg == NULL) || (state == NULL))condition outcomes covered 4/464    {652        verdict = SC_WATCHDOG_TRIPPED;                   /* LLR-WDG-8 */66    }67    else68    {6967        if (state->elapsed < cfg->timeout)              /* LLR-WDG-9 */condition outcomes covered 2/270        {7118            state->elapsed = (uint16_t)(state->elapsed + 1u);7218            if (state->elapsed >= cfg->timeout)          /* LLR-WDG-10: set, never cleared here */condition outcomes covered 2/273            {746                state->tripped = true;75            }76        }777867        verdict = state->tripped                         /* LLR-WDG-11 */79                ? SC_WATCHDOG_TRIPPED80                : SC_WATCHDOG_OK;81    }828369    return verdict;84}85866bool sc_watchdog_expired(const sc_watchdog_state_t *state)87{886    return (state != NULL) && state->tripped;            /* LLR-WDG-12 */condition outcomes covered 4/489}