qep.h

Go to the documentation of this file.
00001 
00002 // Product: QEP/C++ platform-independent public interface
00003 // Last Updated for Version: 4.0.02
00004 // Date of the Last Update:  Nov 11, 2008
00005 //
00006 //                    Q u a n t u m     L e a P s
00007 //                    ---------------------------
00008 //                    innovating embedded systems
00009 //
00010 // Copyright (C) 2002-2008 Quantum Leaps, LLC. All rights reserved.
00011 //
00012 // This software may be distributed and modified under the terms of the GNU
00013 // General Public License version 2 (GPL) as published by the Free Software
00014 // Foundation and appearing in the file GPL.TXT included in the packaging of
00015 // this file. Please note that GPL Section 2[b] requires that all works based
00016 // on this software must also be made publicly available under the terms of
00017 // the GPL ("Copyleft").
00018 //
00019 // Alternatively, this software may be distributed and modified under the
00020 // terms of Quantum Leaps commercial licenses, which expressly supersede
00021 // the GPL and are specifically designed for licensees interested in
00022 // retaining the proprietary status of their code.
00023 //
00024 // Contact information:
00025 // Quantum Leaps Web site:  http://www.quantum-leaps.com
00026 // e-mail:                  info@quantum-leaps.com
00028 #ifndef qep_h
00029 #define qep_h
00030 
00037 
00038 #include "qevent.h"           // QEP event processor needs the QEvent facility
00039 
00042 class QEP {
00043 public:
00049     static char const Q_ROM * Q_ROM_VAR getVersion(void);
00050 };
00051 
00053 
00055 typedef uint8_t QState;
00056 
00058 typedef QState (*QStateHandler)(void *me, QEvent const *e);
00059 
00060 
00076 class QFsm {
00077 protected:
00078     QStateHandler m_state;          
00079 
00080 public:
00081 
00093     void init(QEvent const *e = (QEvent *)0);
00094 
00104     void dispatch(QEvent const *e);
00105 
00106 protected:
00107 
00119     QFsm(QStateHandler initial) : m_state(initial) {}
00120 };
00121 
00136 class QHsm {
00137 protected:
00138     QStateHandler m_state;          
00139 
00140 public:
00141 
00151     void init(QEvent const *e = (QEvent *)0);
00152 
00162     void dispatch(QEvent const *e);
00163 
00169     uint8_t isIn(QStateHandler state);
00170 
00171 protected:
00172 
00185     QHsm(QStateHandler initial) : m_state(initial) {}
00186 
00194     static QState top(QHsm *me, QEvent const *e);
00195 };
00196 
00199 #define Q_RET_IGNORED       ((QState)1)
00200 
00207 #define Q_IGNORED()         (Q_RET_IGNORED)
00208 
00211 #define Q_RET_HANDLED       ((QState)0)
00212 
00220 #define Q_HANDLED()         (Q_RET_HANDLED)
00221 
00224 #define Q_RET_TRAN          ((QState)2)
00225 
00230 //lint -e960 -e1924 ignore MISRA Rule 42 (comma operator) and C-style cast
00231 #define Q_TRAN(target_)  \
00232     (me->m_state = (QStateHandler)(target_), Q_RET_TRAN)
00233 
00236 #define Q_RET_SUPER         ((QState)3)
00237 
00241 //lint -e960 -e1924 ignore MISRA Rule 42 (comma operator) and C-style cast
00242 #define Q_SUPER(super_)  \
00243     (me->m_state = (QStateHandler)(super_),  Q_RET_SUPER)
00244 
00245 
00248 enum QReservedSignals {
00249     Q_ENTRY_SIG = 1,                             
00250     Q_EXIT_SIG,                                   
00251     Q_INIT_SIG,                     
00252     Q_USER_SIG                              
00253 };
00254 
00256 // QS software tracing integration, only if enabled
00257 #ifdef Q_SPY                                   // QS software tracing enabled?
00258     #ifndef qs_h
00259     #include "qs_port.h"                                    // include QS port
00260     #endif                                                             // qs_h
00261 
00262     #if (Q_SIGNAL_SIZE == 1)
00263 
00267         #define QS_SIG_(sig_)       QS::u8_(sig_)
00268     #elif (Q_SIGNAL_SIZE == 2)
00269         #define QS_SIG_(sig_)       QS::u16_(sig_)
00270     #elif (Q_SIGNAL_SIZE == 4)
00271         #define QS_SIG_(sig_)       QS::u32_(sig_)
00272     #endif
00273 
00274 #else
00275     #ifndef qs_dummy_h
00276     #include "qs_dummy.h"                   // disable the QS software tracing
00277     #endif
00278 #endif                                                                // Q_SPY
00279 
00280 #endif                                                                // qep_h

Generated on Sat Nov 15 13:53:46 2008 for QP/C++ by  doxygen 1.5.4