|
QP-nano
|
00001 /***************************************************************************** 00002 * Product: QP-nano 00003 * Last Updated for Version: 4.5.04 00004 * Date of the Last Update: Feb 02, 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 qepn_h 00036 #define qepn_h 00037 00048 /****************************************************************************/ 00055 #define QP_VERSION 0x4504U 00056 00057 /****************************************************************************/ 00058 #ifndef Q_ROM /* if NOT defined, provide the default definition */ 00059 00073 #define Q_ROM 00074 #endif 00075 #ifndef Q_ROM_VAR /* if NOT defined, provide the default definition */ 00076 00091 #define Q_ROM_VAR 00092 #endif 00093 #ifndef Q_REENTRANT /* if NOT defined, provide the default definition */ 00094 00107 #define Q_REENTRANT 00108 #endif 00109 00110 /****************************************************************************/ 00112 #define Q_DIM(array_) (sizeof(array_) / sizeof(array_[0])) 00113 00114 /****************************************************************************/ 00115 /* typedefs for basic numerical types; MISRA-C 2004 rule 6.3(req). */ 00122 typedef char char_t; 00123 00125 typedef float float32_t; 00126 00128 typedef double float64_t; 00129 00138 #define Q_UINT2PTR_CAST(type_, uint_) ((type_ *)(uint_)) 00139 00140 /****************************************************************************/ 00147 char_t const Q_ROM * Q_ROM_VAR QP_getVersion(void); 00148 00151 typedef uint8_t QSignal; 00152 00153 /****************************************************************************/ 00154 #ifndef Q_PARAM_SIZE 00155 00158 #define Q_PARAM_SIZE 0 00159 #endif 00160 #if (Q_PARAM_SIZE == 0) 00161 #elif (Q_PARAM_SIZE == 1) 00162 00172 typedef uint8_t QParam; 00173 #elif (Q_PARAM_SIZE == 2) 00174 typedef uint16_t QParam; 00175 #elif (Q_PARAM_SIZE == 4) 00176 typedef uint32_t QParam; 00177 #else 00178 #error "Q_PARAM_SIZE defined incorrectly, expected 0, 1, 2, or 4" 00179 #endif 00180 00187 typedef struct QEvtTag { 00188 QSignal sig; 00189 #if (Q_PARAM_SIZE != 0) 00190 QParam par; 00191 #endif 00192 } QEvt; 00193 00194 /****************************************************************************/ 00196 enum QReservedSignals { 00197 Q_ENTRY_SIG = 1, 00198 Q_EXIT_SIG, 00199 Q_INIT_SIG, 00200 Q_TIMEOUT_SIG, 00201 Q_USER_SIG 00202 }; 00203 00204 /****************************************************************************/ 00205 00207 typedef uint8_t QState; 00208 00210 typedef QState (*QStateHandler)(void *me); 00211 00218 #define Q_STATE_CAST(handler_) ((QStateHandler)(handler_)) 00219 00236 typedef struct QFsmTag { 00237 QStateHandler state; 00238 QStateHandler temp; 00239 QEvt evt; 00240 } QFsm; 00241 00246 #define Q_SIG(me_) (((QFsm *)(me_))->evt.sig) 00247 00248 #if (Q_PARAM_SIZE != 0) 00249 00254 #define Q_PAR(me_) (((QFsm *)(me_))->evt.par) 00255 #endif 00256 00257 #ifndef Q_NFSM 00258 00266 #define QFsm_ctor(me_, initial_) do { \ 00267 (me_)->state = Q_STATE_CAST(0); \ 00268 (me_)->temp = (initial_); \ 00269 } while (0) 00270 00279 void QFsm_init(QFsm * const me); 00280 00281 #ifndef QK_PREEMPTIVE 00282 00289 void QFsm_dispatch(QFsm * const me); 00290 #else 00291 void QFsm_dispatch(QFsm * const me) Q_REENTRANT; 00292 #endif 00293 00294 #endif /* Q_NFSM */ 00295 00296 00300 #define Q_RET_HANDLED ((QState)0) 00301 00307 #define Q_HANDLED() (Q_RET_HANDLED) 00308 00312 #define Q_RET_IGNORED ((QState)1) 00313 00321 #define Q_IGNORED() (Q_RET_IGNORED) 00322 00326 #define Q_RET_TRAN ((QState)2) 00327 00333 #define Q_TRAN(target_) \ 00334 (((QFsm *)me)->temp = Q_STATE_CAST(target_), Q_RET_TRAN) 00335 00339 #define Q_RET_SUPER ((QState)3) 00340 00345 #define Q_SUPER(super_) \ 00346 (((QHsm *)me)->temp = Q_STATE_CAST(super_), Q_RET_SUPER) 00347 00351 #define Q_RET_UNHANDLED ((QState)4) 00352 00359 #define Q_UNHANDLED() (Q_RET_UNHANDLED) 00360 00361 00362 /****************************************************************************/ 00363 #ifndef Q_NHSM 00364 00381 typedef struct QFsmTag QHsm; 00382 00383 /* public methods */ 00391 #define QHsm_ctor(me_, initial_) do { \ 00392 (me_)->state = Q_STATE_CAST(&QHsm_top); \ 00393 (me_)->temp = (initial_); \ 00394 } while (0) 00395 00398 #define QHsm_state(me_) (Q_STATE_CAST((me_)->state)) 00399 00408 void QHsm_init(QHsm * const me); 00409 00410 #ifndef QK_PREEMPTIVE 00411 00418 void QHsm_dispatch(QHsm * const me); 00419 #else 00420 void QHsm_dispatch(QHsm * const me) Q_REENTRANT; 00421 #endif 00422 00423 /* protected methods... */ 00424 00433 QState QHsm_top(void const * const me); 00434 00435 #endif /* Q_NHSM */ 00436 00437 #include "qassert.h" /* include the QP-nano assertions (for DbC) */ 00438 00439 /****************************************************************************/ 00440 #ifndef Q_NQEVENT 00441 typedef QEvt QEvent; 00442 #endif 00443 00444 #endif /* qepn_h */
1.7.6.1