dal-c library ← coverage

§ Coverage

src/sc_sm.c

1/*2 * sc_sm.c -- implementation. Blocks are tagged with the low-level3 * requirement they satisfy; see requirements/sc_sm.md.4 */5#include "sc_sm.h"674sc_status_t sc_sm_config_valid(const sc_sm_config_t *cfg)8{9    sc_status_t status;10114    if ((cfg == NULL) || (cfg->table == NULL))condition outcomes covered 4/412    {132        status = SC_ERR_NULL;                        /* LLR-SM-7 */14    }152    else if (cfg->n == 0u)condition outcomes covered 2/216    {171        status = SC_ERR_PARAM;                       /* LLR-SM-8 */18    }19    else20    {211        status = SC_OK;                              /* LLR-SM-9 */22    }23244    return status;25}26278sc_status_t sc_sm_init(sc_sm_state_t *state, const sc_sm_config_t *cfg)28{29    sc_status_t status;30318    if ((state == NULL) || (cfg == NULL))condition outcomes covered 4/432    {332        status = SC_ERR_NULL;                        /* LLR-SM-6 */34    }35    else36    {376        state->state = cfg->initial;                 /* LLR-SM-1 */386        status = SC_OK;39    }40418    return status;42}434411uint16_t sc_sm_state(const sc_sm_state_t *state)45{46    uint16_t result;474811    if (state == NULL)condition outcomes covered 2/249    {501        result = (uint16_t)0xFFFFu;                  /* LLR-SM-10 */51    }52    else53    {5410        result = state->state;                      /* LLR-SM-11 */55    }565711    return result;58}596015bool sc_sm_dispatch(const sc_sm_config_t *cfg,61                    sc_sm_state_t *state,62                    uint16_t event,63                    void *ctx)64{6515    bool fired = false;666715    if ((cfg == NULL) || (state == NULL))condition outcomes covered 4/468    {692        fired = false;                              /* LLR-SM-5 */70    }71    else72    {73        uint16_t i;7445        for (i = 0u; i < cfg->n; i++)               /* LLR-SM-2: bounded scan */condition outcomes covered 2/275        {7642            const sc_sm_transition *t = &cfg->table[i];7742            if ((t->from == state->state) && (t->event == event))condition outcomes covered 4/478            {7910                if (t->action != NULL)condition outcomes covered 2/280                {819                    t->action(ctx);                 /* LLR-SM-3: run action */82                }8310                state->state = t->to;               /* LLR-SM-4: move */8410                fired = true;8510                break;                              /* first match wins */86            }87        }88    }899015    return fired;91}