dal-c library ← coverage

§ Coverage

src/sc_hysteresis.c

1/*2 * sc_hysteresis.c -- implementation.3 *4 * Each block is tagged with the low-level requirement it satisfies; see5 * requirements/sc_hysteresis.md for the full text and traceability.6 */7#include "sc_hysteresis.h"893sc_status_t sc_hysteresis_config_valid(const sc_hysteresis_config_t *cfg)10{11    sc_status_t status;12133    if (cfg == NULL)condition outcomes covered 2/214    {151        status = SC_ERR_NULL;                 /* LLR-HYS-7 */16    }172    else if (cfg->high_threshold < cfg->low_threshold)condition outcomes covered 2/218    {191        status = SC_ERR_PARAM;                /* LLR-HYS-8 */20    }21    else22    {231        status = SC_OK;                       /* LLR-HYS-9 */24    }25263    return status;27}282911sc_status_t sc_hysteresis_init(sc_hysteresis_state_t *state)30{31    sc_status_t status;323311    if (state == NULL)condition outcomes covered 2/234    {351        status = SC_ERR_NULL;                 /* LLR-HYS-10 */36    }37    else38    {3910        state->asserted = false;             /* LLR-HYS-1  */4010        status = SC_OK;41    }424311    return status;44}454622bool sc_hysteresis_update(const sc_hysteresis_config_t *cfg,47                          sc_hysteresis_state_t *state,48                          int32_t input)49{50    bool result;515222    if ((cfg == NULL) || (state == NULL))condition outcomes covered 4/453    {542        result = false;                      /* LLR-HYS-5: null-safe        */55    }56    else57    {5820        if ((state->asserted == false) && (input >= cfg->high_threshold))condition outcomes covered 4/459        {609            state->asserted = true;          /* LLR-HYS-2: rising edge      */61        }6211        else if ((state->asserted == true) && (input <= cfg->low_threshold))condition outcomes covered 4/463        {643            state->asserted = false;         /* LLR-HYS-3: falling edge     */65        }66        else67        {68            /* LLR-HYS-4: input is between the thresholds -- hold */69        }707120        result = state->asserted;            /* LLR-HYS-6: output = state   */72    }737422    return result;75}76773bool sc_hysteresis_output(const sc_hysteresis_state_t *state)78{79    bool result;80813    if (state == NULL)condition outcomes covered 2/282    {831        result = false;                      /* LLR-HYS-11 */84    }85    else86    {872        result = state->asserted;            /* LLR-HYS-12 */88    }89903    return result;91}