先把内容贴上来再说,下一步接着来
这个是量子编程的学习心得的第一篇
先是qepn.c
格式还弄不好
研究好了重发一篇
/*****************************************************************************
* 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 */
#ifndef Q_NHSM
Q_DEFINE_THIS_MODULE(qepn)
#endif
/**
* \file
* \ingroup qepn qfn
* QEP-nano implementation.
*/
/** empty signal for internal use only */
#define QEP_EMPTY_SIG_ 0
/** maximum depth of state nesting (including the top level), must be >= 2 */
#define QEP_MAX_NEST_DEPTH_ 5
/*..........................................................................*/
/*lint -e970 -e971 */ /* ignore MISRA rules 13 and 14 in this function */
char const Q_ROM * Q_ROM_VAR QP_getVersion(void) {
static char const Q_ROM Q_ROM_VAR version[] = {
((QP_VERSION >> 12) & 0xF) + '0',
'.',
((QP_VERSION >> 8) & 0xF) + '0',
'.',
((QP_VERSION >> 4) & 0xF) + '0',
(QP_VERSION & 0xF) + '0',
'\0'
};
return version;
}
#ifndef Q_NFSM
/*..........................................................................*/
void QFsm_init(QFsm *me) {
(void)(*me->state)(me); /* execute the top-most initial transition */
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;
/*利用QEP_EMPTY_SIG_信号,从目标状态回溯到顶状态,
* QEP_EMPTY_SIG_信号除把状态转换到超状态,不做任何操作
* 保存回溯的路径到ip数组中,保存为逆序
* 即第一个数组元素为目标状态,上层状态其后
* 顶层状态并不包括在路径中
*/
path[0] = me->state;
Q_SIG(me) = (QSignal)QEP_EMPTY_SIG_;
(void)(*me->state)(me);
while (me->state != t) {
++ip;
path[ip] = me->state;
(void)(*me->state)(me);
}
/* 回到目标状态 */
me->state = path[0];
/* 确保深度在预定内 */