00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "qep_pkg.h"
00029 #include "qassert.h"
00030
00031 Q_DEFINE_THIS_MODULE(qhsm_dis)
00032
00033
00039
00040 void QHsm_dispatch(QHsm *me, QEvent const *e) {
00041 QStateHandler path[QEP_MAX_NEST_DEPTH_];
00042 QStateHandler s;
00043 QStateHandler t;
00044 QState r;
00045 QS_INT_LOCK_KEY_
00046
00047 t = me->state;
00048
00049 QS_BEGIN_(QS_QEP_DISPATCH, QS_smObj_, me)
00050 QS_TIME_();
00051 QS_SIG_(e->sig);
00052 QS_OBJ_(me);
00053 QS_FUN_(t);
00054 QS_END_()
00055
00056 do {
00057 s = me->state;
00058 r = (*s)(me, e);
00059 } while (r == Q_RET_SUPER);
00060
00061 if (r == Q_RET_TRAN) {
00062 #ifdef Q_SPY
00063 QStateHandler src = s;
00064 #endif
00065 int8_t ip = (int8_t)(-1);
00066 int8_t iq;
00067
00068 path[0] = me->state;
00069 path[1] = t;
00070
00071 while (t != s) {
00072 if (QEP_TRIG_(t, Q_EXIT_SIG) == Q_RET_HANDLED) {
00073 QS_BEGIN_(QS_QEP_STATE_EXIT, QS_smObj_, me)
00074 QS_OBJ_(me);
00075 QS_FUN_(t);
00076 QS_END_()
00077
00078 (void)QEP_TRIG_(t, QEP_EMPTY_SIG_);
00079 }
00080 t = me->state;
00081 }
00082
00083 t = path[0];
00084
00085 if (s == t) {
00086 QEP_EXIT_(s)
00087 ip = (int8_t)0;
00088 }
00089 else {
00090 (void)QEP_TRIG_(t, QEP_EMPTY_SIG_);
00091 t = me->state;
00092 if (s == t) {
00093 ip = (int8_t)0;
00094 }
00095 else {
00096 (void)QEP_TRIG_(s, QEP_EMPTY_SIG_);
00097
00098 if (me->state == t) {
00099 QEP_EXIT_(s)
00100 ip = (int8_t)0;
00101 }
00102 else {
00103
00104 if (me->state == path[0]) {
00105 QEP_EXIT_(s)
00106 }
00107 else {
00108
00109
00110 iq = (int8_t)0;
00111 ip = (int8_t)1;
00112 path[1] = t;
00113 t = me->state;
00114
00115 r = QEP_TRIG_(path[1], QEP_EMPTY_SIG_);
00116 while (r == Q_RET_SUPER) {
00117 path[++ip] = me->state;
00118 if (me->state == s) {
00119 iq = (int8_t)1;
00120
00121 Q_ASSERT(ip < (int8_t)QEP_MAX_NEST_DEPTH_);
00122 --ip;
00123 r = Q_RET_HANDLED;
00124 }
00125 else {
00126 r = QEP_TRIG_(me->state, QEP_EMPTY_SIG_);
00127 }
00128 }
00129 if (iq == (int8_t)0) {
00130
00131
00132 Q_ASSERT(ip < (int8_t)QEP_MAX_NEST_DEPTH_);
00133
00134 QEP_EXIT_(s)
00135
00136
00137
00138
00139 iq = ip;
00140 r = Q_RET_IGNORED;
00141 do {
00142 if (t == path[iq]) {
00143 r = Q_RET_HANDLED;
00144 ip = (int8_t)(iq - 1);
00145 iq = (int8_t)(-1);
00146 }
00147 else {
00148 --iq;
00149 }
00150 } while (iq >= (int8_t)0);
00151
00152 if (r != Q_RET_HANDLED) {
00153
00154
00155
00156 r = Q_RET_IGNORED;
00157 do {
00158
00159 if (QEP_TRIG_(t, Q_EXIT_SIG)
00160 == Q_RET_HANDLED)
00161 {
00162 QS_BEGIN_(QS_QEP_STATE_EXIT,
00163 QS_smObj_, me)
00164 QS_OBJ_(me);
00165 QS_FUN_(t);
00166 QS_END_()
00167
00168 (void)QEP_TRIG_(t, QEP_EMPTY_SIG_);
00169 }
00170 t = me->state;
00171 iq = ip;
00172 do {
00173 if (t == path[iq]) {
00174
00175 ip = (int8_t)(iq - 1);
00176 iq = (int8_t)(-1);
00177 r = Q_RET_HANDLED;
00178 }
00179 else {
00180 --iq;
00181 }
00182 } while (iq >= (int8_t)0);
00183 } while (r != Q_RET_HANDLED);
00184 }
00185 }
00186 }
00187 }
00188 }
00189 }
00190
00191 for (; ip >= (int8_t)0; --ip) {
00192 QEP_ENTER_(path[ip])
00193 }
00194 t = path[0];
00195 me->state = t;
00196
00197
00198 while (QEP_TRIG_(t, Q_INIT_SIG) == Q_RET_TRAN) {
00199
00200 QS_BEGIN_(QS_QEP_STATE_INIT, QS_smObj_, me)
00201 QS_OBJ_(me);
00202 QS_FUN_(t);
00203 QS_FUN_(me->state);
00204 QS_END_()
00205
00206 ip = (int8_t)0;
00207 path[0] = me->state;
00208 (void)QEP_TRIG_(me->state, QEP_EMPTY_SIG_);
00209 while (me->state != t) {
00210 path[++ip] = me->state;
00211 (void)QEP_TRIG_(me->state, QEP_EMPTY_SIG_);
00212 }
00213 me->state = path[0];
00214
00215 Q_ASSERT(ip < (int8_t)QEP_MAX_NEST_DEPTH_);
00216
00217 do {
00218 QEP_ENTER_(path[ip])
00219 } while ((--ip) >= (int8_t)0);
00220
00221 t = path[0];
00222 }
00223
00224 QS_BEGIN_(QS_QEP_TRAN, QS_smObj_, me)
00225 QS_TIME_();
00226 QS_SIG_(e->sig);
00227 QS_OBJ_(me);
00228 QS_FUN_(src);
00229 QS_FUN_(t);
00230 QS_END_()
00231
00232 }
00233 else {
00234 #ifdef Q_SPY
00235 if (r == Q_RET_IGNORED) {
00236
00237 QS_BEGIN_(QS_QEP_IGNORED, QS_smObj_, me)
00238 QS_TIME_();
00239 QS_SIG_(e->sig);
00240 QS_OBJ_(me);
00241 QS_FUN_(t);
00242 QS_END_()
00243
00244 }
00245 else {
00246
00247 QS_BEGIN_(QS_QEP_INTERN_TRAN, QS_smObj_, me)
00248 QS_TIME_();
00249 QS_SIG_(e->sig);
00250 QS_OBJ_(me);
00251 QS_FUN_(s);
00252 QS_END_()
00253
00254 }
00255 #endif
00256 }
00257 me->state = t;
00258 }