|
9楼
![](static/image/common/ico_lz.png)
楼主 |
发表于 2015-5-5 11:04:04
|
只看该作者
好的,谢谢,我是参考QP-NANO的时候 想到这个问题的,是不是它也存在这样的问题,
以下是QP_NANO的 状态转换代码
void QFsm_dispatch_(QFsm *const me) {
if ((*me->state.fun)(me) == (QState)Q_RET_TRAN) { /* tran. taken? */
Q_SIG(me) = (QSignal)Q_EXIT_SIG;
(void)(*me->state.fun)(me); /* exit the source */
Q_SIG(me) = (QSignal)Q_ENTRY_SIG;
(void)(*me->temp.fun)(me); /* enter the target */
me->state.fun = me->temp.fun; /* record the new active state */
}
}
也没有对事情队列做处理,很可能会把上个状态的没有处理的直接带到下个状态,
由于个人水平的问题,所以很困惑
以下是我改了的代码,直接清队列
static void Fsm_dispatch(Active_t *me,Event_t const *e)
{
StateHandler_t s = me->fsm.state;
State_t r = (*s)(me,e);
if(r == RET_TRAN){
(void)(*s)(me,&ReservedEvt[EXIT_SIG]);
/*???if state transmit clear event pool*/
/*atom start*/
if(me->numUsed>0){
__disable_interrupt( );
me->head = 0; /*index to the event queue head*/
me->tail = 0; /*index to the event queue tail*/
me->numUsed= 0; /*number of events currently in queue*/
me->tickCtr= 0; /*time down counter*/
__enable_interrupt( );
}
/*atom end*/
(void)(*me->fsm.state)(me,&ReservedEvt[ENTRY_SIG]);
}
} |
|