statetbl.c

来自「事件驱动程序设计很好的框架」· C语言 代码 · 共 49 行

C
49
字号
/****************************************************************************** Product: Generic State-Table event processor* Date of the Last Update:  Oct 22, 2007** Copyright (C) 2002-2007 Miro Samek. All rights reserved.** Contact information:* e-mail: miro@quantum-leaps.com*****************************************************************************/#include "bsp.h"          /* for the C99-standard exact-width integer types */#include "statetbl.h"              /* see also embedded-systems-friendly assertions in Chapter 6 */#include <assert.h>/*..........................................................................*/void StateTable_ctor(StateTable *me,                     Tran const *table, uint8_t n_states, uint8_t n_signals,                     Tran initial){    me->state_table = table;    me->n_states    = n_states;    me->n_signals   = n_signals;    me->initial     = initial;}/*..........................................................................*/void StateTable_init(StateTable *me) {    me->state = me->n_states;    (*me->initial)(me, (Event *)0);          /* top-most initial transition */    assert(me->state < me->n_states);/* the initial tran. must change state */}/*..........................................................................*/void StateTable_dispatch(StateTable *me, Event const *e) {    Tran t;    assert(e->sig < me->n_signals);          /* require the signal in range */    t = me->state_table[me->state*me->n_signals + e->sig];    (*t)(me, e);                         /* execute the transition function */    assert(me->state < me->n_states);   /* ensure that state stays in range */}/*..........................................................................*/void StateTable_empty(StateTable *me, Event const *e) {    (void)me;               /* void compiler warning about unused parameter */    (void)e;                /* void compiler warning about unused parameter */}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?