/*****************************************************************************
* Product: QEP-nano implemenation
* Last Updated for Version: 4.1.05
* Date of the Last Update: Oct 27, 2010
*
* Q u a n t u m L e a P s
* ---------------------------
* innovating embedded systems
*
* Copyright (C) 2002-2010 Quantum Leaps, LLC. All rights reserved.
*
* This software may be distributed and modified under the terms of the GNU
* General Public License version 2 (GPL) as published by the Free Software
* Foundation and appearing in the file GPL.TXT included in the packaging of
* this file. Please note that GPL Section 2[b] requires that all works based
* on this software must also be made publicly available under the terms of
* the GPL ("Copyleft").
*
* Alternatively, this software may be distributed and modified under the
* terms of Quantum Leaps commercial licenses, which expressly supersede
* the GPL and are specifically designed for licensees interested in
* retaining the proprietary status of their code.
*
* Contact information:
* Quantum Leaps Web site: http://www.quantum-leaps.com
* e-mail: info@quantum-leaps.com
*****************************************************************************/
#include "qpn_port.h" /* QP-nano port */
Q_SIG(me) = (QSignal)Q_ENTRY_SIG;
(void)(*me->state)(me); /* enter the target */
}
/*..........................................................................*/
#ifndef QK_PREEMPTIVE
void QFsm_dispatch(QFsm *me) {
#else
void QFsm_dispatch(QFsm *me) Q_REENTRANT {
#endif
QStateHandler s = me->state;
if ((*s)(me) == Q_RET_TRAN) { /* transition taken? */
Q_SIG(me) = (QSignal)Q_EXIT_SIG;
(void)(*s)(me); /* exit the source */
Q_SIG(me) = (QSignal)Q_ENTRY_SIG;
(void)(*me->state)(me); /* enter the target */
}
}
#endif /* Q_NFSM */
#ifndef Q_NHSM
/*..........................................................................*/
QState QHsm_top(QHsm *me) {
(void)me; /* supress the "unused argument" compiler warning */
return Q_IGNORED(); /* the top state ignores all events */
}
/*..........................................................................*/
void QHsm_init(QHsm *me) {
QStateHandler t;
/* 初始化状态机时必须转换到一个明确的状态 */
Q_ALLEGE((*me->state)(me) == Q_RET_TRAN);/* initial tran. must be taken */
/*从顶层状态开始,执行递归的进入操作
* 此时me->state已经为初始化后的目标状态
*/
t = (QStateHandler)&QHsm_top; /* an HSM starts in the top state */
do { /* drill into the target hierarchy... */
QStateHandler path[QEP_MAX_NEST_DEPTH_];
int8_t ip = (int8_t)0;