summaryrefslogtreecommitdiff
path: root/cesar/ce/rx/bitloading/fsm/src/fsm.c
blob: 5f27f653f4a203e6c96f30b8e196ee6d30c320a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ce/rx/bitloading/fsm/src/fsm.c
 * \brief   CE RX Bit loading FSM internal functions.
 * \ingroup ce_rx
 *
 * Functions to work with the FSM: init, transition.
 */
#include "common/std.h"

#include "ce/rx/bitloading/fsm/fsm.h"
#include "inc/tables.h"
#include "ce/rx/inc/trace.h"

void
ce_rx_bl_fsm_handle_event (ce_rx_t *ce_rx, sta_t *sta, ce_rx_bl_fsm_event_type_t e,
                           ce_rx_bitloading_fsm_event_param_t data)
{
    /* Check parameters. */
    dbg_assert (sta);
    ce_rx_bl_fsm_state_t fsm = sta->ce_rx_bt.fsm;
    dbg_assert (fsm < CE_RX_BL_FSM_STATE_NB);
    dbg_assert (e < CE_RX_BL_FSM_EVENT_TYPE_NB);

    CE_RX_TRACE_VERBOSE (FSM_HANDLING_EVENT, fsm, e);

    /* Get transition. */
    ce_rx_bl_fsm_transition_t tr = ce_rx_bl_fsm_transition_table[fsm][e];
    /* A non managed event is an error. */
    dbg_assert (tr);
    /* Run transition. */
    ce_rx_bl_fsm_branch_t br = tr (ce_rx, sta, data);
    dbg_assert (((br >> 16) & 0xff) == fsm);
    dbg_assert (((br >> 8) & 0xff) == e);
    sta->ce_rx_bt.fsm = br & 0xff;

    CE_RX_TRACE_VERBOSE (FSM_FROM_TO, fsm, e, sta->ce_rx_bt.fsm);
}