Calc is the model of the Calculator described in Chapter 4 of PSiCC2
Calculator state machine
BSP_clear();
(void)e; /* unused parameter */
BSP_message("on-ENTRY;");
BSP_message("on-EXIT;");
BSP_message("on-INIT;");
BSP_clear();
BSP_message("ready-ENTRY;");
BSP_message("ready-EXIT;");
BSP_message("ready-INIT;");
BSP_clear();
BSP_clear();
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
BSP_clear();
BSP_insert((int)'0');
BSP_insert((int)'.');
me->op1 = BSP_get_value();
me->oper = Q_EVT_CAST(CalcEvt)->key_code;
BSP_message("result-ENTRY;");
BSP_message("result-EXIT;");
BSP_message("begin-ENTRY;");
BSP_message("begin-EXIT;");
Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS
else
me->op1 = BSP_get_value();
me->oper = Q_EVT_CAST(CalcEvt)->key_code;
BSP_message("opEntered-ENTRY;");
BSP_message("opEntered-EXIT;");
BSP_clear();
BSP_clear();
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
BSP_clear();
BSP_insert((int)'0');
BSP_insert((int)'.');
Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS
else
BSP_message("error-ENTRY;");
BSP_message("error-EXIT;");
else
BSP_eval(me->op1, me->oper, BSP_get_value())
else
BSP_eval(me->op1, me->oper, BSP_get_value())
BSP_message("final-ENTRY;");
BSP_exit();
BSP_message("operand-ENTRY;");
BSP_message("operand-EXIT;");
BSP_message("EP:zero;");
BSP_message("EP:intgr;");
BSP_message("EP:frac;");
BSP_message("EP:neg;");
BSP_message("zero-ENTRY;");
BSP_message("zero-EXIT;");
;
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
BSP_insert((int)'0');
BSP_insert((int)'.');
BSP_message("intgr-ENTRY;");
BSP_message("intgr-EXIT;");
BSP_insert((int)'.');
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
BSP_message("frac-ENTRY;");
BSP_message("frac-EXIT;");
;
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
BSP_message("neg-ENTRY;");
BSP_negate();
BSP_message("neg-EXIT;");
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);
else
Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS
;
constructor
Calc *me = &l_calc;
QMsm_ctor(&me->super, Q_STATE_CAST(&Calc_initial));
#ifndef calc1_sub_h
#define calc1_sub_h
enum CalcSignals {
C_SIG = Q_USER_SIG,
CE_SIG,
DIGIT_0_SIG,
DIGIT_1_9_SIG,
POINT_SIG,
OPER_SIG,
EQUALS_SIG,
OFF_SIG
};
$declare(Events::CalcEvt)
$declare(SMs::Calc_ctor)
extern QMsm * const the_calc; /* "opaque" pointer to calculator MSM */
#endif /* calc1_sub_h */
#include "qep_port.h" /* QEP/C interface */
#include "bsp.h" /* board support package */
#include "calc1_sub.h" /* application */
$declare(SMs::Calc)
static Calc l_calc; /* the only instance of the Calc class */
/* global-scope definitions ---------------------------------------*/
QMsm * const the_calc = &l_calc.super; /* "opaque" pointer to MSM */
$define(SMs::Calc_ctor)
$define(SMs::Calc)