|
QP/C
|
00001 /***************************************************************************** 00002 * Product: QP/C 00003 * Last Updated for Version: 4.5.04 00004 * Date of the Last Update: Feb 01, 2013 00005 * 00006 * Q u a n t u m L e a P s 00007 * --------------------------- 00008 * innovating embedded systems 00009 * 00010 * Copyright (C) 2002-2013 Quantum Leaps, LLC. All rights reserved. 00011 * 00012 * This program is open source software: you can redistribute it and/or 00013 * modify it under the terms of the GNU General Public License as published 00014 * by the Free Software Foundation, either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * Alternatively, this program may be distributed and modified under the 00018 * terms of Quantum Leaps commercial licenses, which expressly supersede 00019 * the GNU General Public License and are specifically designed for 00020 * licensees interested in retaining the proprietary status of their code. 00021 * 00022 * This program is distributed in the hope that it will be useful, 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 * GNU General Public License for more details. 00026 * 00027 * You should have received a copy of the GNU General Public License 00028 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00029 * 00030 * Contact information: 00031 * Quantum Leaps Web sites: http://www.quantum-leaps.com 00032 * http://www.state-machine.com 00033 * e-mail: info@quantum-leaps.com 00034 *****************************************************************************/ 00035 #ifndef qep_h 00036 #define qep_h 00037 00047 #include "qevt.h" /* QEP event processor needs the QEvt facility */ 00048 00049 00050 /****************************************************************************/ 00057 char_t const Q_ROM * Q_ROM_VAR QEP_getVersion(void); 00058 00059 /****************************************************************************/ 00060 00062 typedef uint8_t QState; 00063 00065 typedef QState (*QStateHandler)(void * const me, QEvt const * const e); 00066 00073 #define Q_STATE_CAST(handler_) ((QStateHandler)(handler_)) 00074 00075 /****************************************************************************/ 00092 typedef struct QFsmTag { 00093 QStateHandler state; 00094 QStateHandler temp; 00095 } QFsm; 00096 00109 #define QFsm_ctor(me_, initial_) do { \ 00110 (me_)->state = Q_STATE_CAST(0); \ 00111 (me_)->temp = (initial_); \ 00112 } while (0) 00113 00114 /****************************************************************************/ 00126 void QFsm_init(QFsm * const me, QEvt const * const e); 00127 00139 void QFsm_dispatch(QFsm * const me, QEvt const * const e); 00140 00141 00142 /****************************************************************************/ 00160 typedef struct QFsmTag QHsm; 00161 00162 00163 /* public methods */ 00164 00177 #define QHsm_ctor(me_, initial_) do { \ 00178 (me_)->state = Q_STATE_CAST(&QHsm_top); \ 00179 (me_)->temp = (initial_); \ 00180 } while (0) 00181 00184 #define QHsm_state(me_) (Q_STATE_CAST((me_)->state)) 00185 00197 void QHsm_init(QHsm * const me, QEvt const * const e); 00198 00210 void QHsm_dispatch(QHsm * const me, QEvt const * const e); 00211 00218 uint8_t QHsm_isIn(QHsm * const me, QStateHandler const state); 00219 00220 /* protected methods */ 00221 00230 QState QHsm_top(void const * const me, QEvt const * const e); 00231 00235 #define Q_RET_HANDLED ((QState)0) 00236 00245 #define Q_HANDLED() (Q_RET_HANDLED) 00246 00250 #define Q_RET_IGNORED ((QState)1) 00251 00259 #define Q_IGNORED() (Q_RET_IGNORED) 00260 00264 #define Q_RET_TRAN ((QState)2) 00265 00271 #define Q_TRAN(target_) \ 00272 (((QFsm *)me)->temp = Q_STATE_CAST(target_), Q_RET_TRAN) 00273 00277 #define Q_RET_SUPER ((QState)3) 00278 00283 #define Q_SUPER(super_) \ 00284 (((QHsm *)me)->temp = Q_STATE_CAST(super_), Q_RET_SUPER) 00285 00289 #define Q_RET_UNHANDLED ((QState)4) 00290 00295 #define Q_UNHANDLED() (Q_RET_UNHANDLED) 00296 00297 /****************************************************************************/ 00299 enum QReservedSignals { 00300 Q_ENTRY_SIG = 1, 00301 Q_EXIT_SIG, 00302 Q_INIT_SIG, 00303 Q_USER_SIG 00304 }; 00305 00306 #endif /* qep_h */
1.7.6.1