/*..........................................................................*/ QState Missile_flying(Missile *me, QEvt const *e) { switch (e->sig) { case TIME_TICK_SIG: { ObjectImageEvt *oie; if (me->x + GAME_MISSILE_SPEED_X < GAME_SCREEN_WIDTH) { me->x += GAME_MISSILE_SPEED_X; /*tell the Tunnel to draw the Missile and test for wall hits*/ oie = Q_NEW(ObjectImageEvt, MISSILE_IMG_SIG); oie->x = me->x; oie->y = me->y; oie->bmp = MISSILE_BMP; QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); } else { /* Missile outside the range, make it ready to fire again*/ return Q_TRAN(&Missile_armed); } return Q_HANDLED(); } case HIT_WALL_SIG: { return Q_TRAN(&Missile_exploding); } case DESTROYED_MINE_SIG: { /* tell the Ship the score for destroing this Mine */ QACTIVE_POST(AO_Ship, e, me); /* re-arm immediately & let the destroyed Mine do the exploding */ return Q_TRAN(&Missile_armed); } } return Q_SUPER(&QHsm_top); }
/* ${AOs::Ship::SM::active::exploding} */ static QState Ship_exploding(Ship * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${AOs::Ship::SM::active::exploding::TIME_TICK} */ case TIME_TICK_SIG: { /* ${AOs::Ship::SM::active::exploding::TIME_TICK::[me->exp_ctr<1~]} */ if (me->exp_ctr < 15U) { ObjectImageEvt *oie; ++me->exp_ctr; /* tell the Tunnel to draw the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); oie->x = me->x; /* x of explosion */ oie->y = (int8_t)((int)me->y - 4U + SHIP_HEIGHT); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* ${AOs::Ship::SM::active::exploding::TIME_TICK::[else]} */ else { static QMTranActTable const tatbl_ = { /* transition-action table */ &Ship_parked_s, { Q_ACTION_CAST(0) /* zero terminator */ } }; ScoreEvt *gameOver = Q_NEW(ScoreEvt, GAME_OVER_SIG); gameOver->score = me->score; QACTIVE_POST(AO_Tunnel, (QEvt *)gameOver, me); status_ = QM_TRAN(&tatbl_); } break; }
static QState Ship_exploding(Ship * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/2/1/4/1/4/0) */ case TIME_TICK_SIG: { /* @(/2/1/4/1/4/0/0) */ if (me->exp_ctr < 15U) { ObjectImageEvt *oie; ++me->exp_ctr; /* tell the Tunnel to draw the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); oie->x = me->x; /* x of explosion */ oie->y = (int8_t)((int)me->y - 4U + SHIP_HEIGHT); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* @(/2/1/4/1/4/0/1) */ else { ScoreEvt *gameOver = Q_NEW(ScoreEvt, GAME_OVER_SIG); gameOver->score = me->score; QACTIVE_POST(AO_Tunnel, (QEvt *)gameOver, me); status_ = QM_TRAN(&Ship_parked_s, &QMsm_emptyAction_[0]); } break; }
void QF_publish_(QEvt const * const e, void const * const sender) #endif { QF_CRIT_STAT_ /* make sure that the published signal is within the configured range */ Q_REQUIRE(e->sig < (QSignal)QF_maxSignal_); QF_CRIT_ENTRY_(); QS_BEGIN_NOCRIT_(QS_QF_PUBLISH, (void *)0, (void *)0) QS_TIME_(); /* the timestamp */ QS_OBJ_(sender); /* the sender object */ QS_SIG_(e->sig); /* the signal of the event */ QS_2U8_(e->poolId_, e->refCtr_);/* pool Id & ref Count of the event */ QS_END_NOCRIT_() if (e->poolId_ != (uint8_t)0) { /* is it a dynamic event? */ QF_EVT_REF_CTR_INC_(e); /* increment reference counter, NOTE01 */ } QF_CRIT_EXIT_(); #if (QF_MAX_ACTIVE <= 8) { uint8_t tmp = QF_subscrList_[e->sig].bits[0]; while (tmp != (uint8_t)0) { uint8_t p = QF_LOG2(tmp); tmp &= Q_ROM_BYTE(QF_invPwr2Lkup[p]); /* clear subscriber bit */ Q_ASSERT(QF_active_[p] != (QActive *)0); /* must be registered */ /* QACTIVE_POST() asserts internally if the queue overflows */ QACTIVE_POST(QF_active_[p], e, sender); } } #else { uint_t i = (uint_t)Q_DIM(QF_subscrList_[0].bits); do { /* go through all bytes in the subscription list */ uint8_t tmp; --i; tmp = QF_PTR_AT_(QF_subscrList_, e->sig).bits[i]; while (tmp != (uint8_t)0) { uint8_t p = QF_LOG2(tmp); tmp &= Q_ROM_BYTE(QF_invPwr2Lkup[p]);/*clear subscriber bit */ p = (uint8_t)(p + (uint8_t)(i << 3));/* adjust the priority */ Q_ASSERT(QF_active_[p] != (QActive *)0);/*must be registered*/ /* QACTIVE_POST() asserts internally if the queue overflows */ QACTIVE_POST(QF_active_[p], e, sender); } } while (i != (uint_t)0); } #endif QF_gc(e); /* run the garbage collector, see NOTE01 */ }
/*..........................................................................*/ QState Cruncher_processing(Cruncher * const me, QEvt const * const e) { QState status; switch (e->sig) { case Q_ENTRY_SIG: { ReminderEvt *reminder = Q_NEW(ReminderEvt, CRUNCH_SIG); reminder->iter = 0; QACTIVE_POST((QActive *)me, (QEvt const *)reminder, me); me->sum = 0.0; status = Q_HANDLED(); break; } case CRUNCH_SIG: { uint32_t i = ((ReminderEvt const *)e)->iter; uint32_t n = i; i += 100; for (; n < i; ++n) { if ((n & 1) == 0) { me->sum += 1.0/(2*n + 1); } else { me->sum -= 1.0/(2*n + 1); } } if (i < 0x07000000) { ReminderEvt *reminder = Q_NEW(ReminderEvt, CRUNCH_SIG); reminder->iter = i; QACTIVE_POST((QActive *)me, (QEvt const *)reminder, me); status = Q_HANDLED(); } else { printf("pi=%16.14f\n", 4.0*me->sum); status = Q_TRAN(&Cruncher_processing); } break; } case ECHO_SIG: { printf("Echo! pi=%16.14f\n", 4.0*me->sum); status = Q_HANDLED(); break; } case TERMINATE_SIG: { status = Q_TRAN(&Cruncher_final); break; } default: { status = Q_SUPER(&QHsm_top); break; } } return status; }
/*..........................................................................*/ QState Missile_exploding(Missile *me, QEvt const *e) { switch (e->sig) { case Q_ENTRY_SIG: { me->exp_ctr = 0; return Q_HANDLED(); } case TIME_TICK_SIG: { if ((me->x >= GAME_SPEED_X) && (me->exp_ctr < 15)) { ObjectImageEvt *oie; ++me->exp_ctr; /* advance the explosion counter */ me->x -= GAME_SPEED_X; /* move the explosion by one step */ /* tell the Tunnel to render the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->x + 3; /* x-pos of explosion */ oie->y = (int8_t)((int)me->y - 4); /* y-pos */ oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); } else { /* explosion finished or moved outside the game */ return Q_TRAN(&Missile_armed); } return Q_HANDLED(); }
/*${AOs::Philo::SM::hungry} ................................................*/ QState Philo_hungry(Philo * const me) { QState status_; switch (Q_SIG(me)) { /*${AOs::Philo::SM::hungry} */ case Q_ENTRY_SIG: { QACTIVE_POST(&AO_Table, HUNGRY_SIG, me->num); status_ = Q_HANDLED(); break; } /*${AOs::Philo::SM::hungry::EAT} */ case EAT_SIG: { status_ = Q_TRAN(&Philo_eating); break; } /*${AOs::Philo::SM::hungry::DONE} */ case DONE_SIG: { Q_ERROR(); /* this event should never arrive in this state */ status_ = Q_HANDLED(); break; } default: { status_ = Q_SUPER(&QHsm_top); break; } } return status_; }
/*${AOs::Philo::SM::eating} ................................................*/ QState Philo_eating(Philo * const me) { QState status_; switch (Q_SIG(me)) { /*${AOs::Philo::SM::eating} */ case Q_ENTRY_SIG: { me->tickCtr = EAT_TIME; status_ = Q_HANDLED(); break; } /*${AOs::Philo::SM::eating} */ case Q_EXIT_SIG: { me->tickCtr = 0U; QACTIVE_POST(QF_ACTIVE_CAST(&AO_Table), DONE_SIG, me->num); status_ = Q_HANDLED(); break; } /*${AOs::Philo::SM::eating::Q_TIMEOUT} */ case Q_TIMEOUT_SIG: { status_ = Q_TRAN(&Philo_thinking); break; } /*${AOs::Philo::SM::eating::EAT, DONE} */ case EAT_SIG: /* intentionally fall through */ case DONE_SIG: { Q_ERROR(); /* these events should never arrive in this state */ status_ = Q_HANDLED(); break; } default: { status_ = Q_SUPER(&QHsm_top); break; } } return status_; }
/* @(/2/1/4/1/4) ...........................................................*/ static QState Ship_exploding(Ship * const me, QEvt const * const e) { QState status; switch (e->sig) { /* @(/2/1/4/1/4) */ case Q_ENTRY_SIG: { me->exp_ctr = 0U; status = Q_HANDLED(); break; } /* @(/2/1/4/1/4/0) */ case TIME_TICK_SIG: { /* @(/2/1/4/1/4/0/0) */ if (me->exp_ctr < 15U) { ++me->exp_ctr; /* tell the Tunnel to draw the current stage of Explosion */ QACTIVE_POST(AO_Tunnel, (QEvt *)Q_NEW(ObjectImageEvt, EXPLOSION_SIG, me->x, (int8_t)((int)me->y - 4 + SHIP_HEIGHT), EXPLOSION0_BMP + (me->exp_ctr >> 2)), me); status = Q_HANDLED(); } /* @(/2/1/4/1/4/0/1) */ else { QACTIVE_POST(AO_Tunnel, (QEvt *)Q_NEW(ScoreEvt, GAME_OVER_SIG, me->score), me); status = Q_TRAN(&Ship_parked); } break; }
/* ${AOs::Mine2::SM::used::exploding} */ static QState Mine2_exploding(Mine2 * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${AOs::Mine2::SM::used::exploding::TIME_TICK} */ case TIME_TICK_SIG: { /* ${AOs::Mine2::SM::used::exploding::TIME_TICK::[stillonscreen?]} */ if ((me->x >= GAME_SPEED_X) && (me->exp_ctr < 15U)) { ObjectImageEvt *oie; ++me->exp_ctr; /* advance the explosion counter */ me->x -= GAME_SPEED_X; /* move explosion by 1 step */ /* tell the Game to render the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->x + 1U; /* x of explosion */ oie->y = (int8_t)((int)me->y - 4 + 2); /* y of explosion */ oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* ${AOs::Mine2::SM::used::exploding::TIME_TICK::[else]} */ else { static struct { QMState const *target; QActionHandler act[2]; } const tatbl_ = { /* transition-action table */ &Mine2_unused_s, /* target state */ { Q_ACTION_CAST(&Mine2_used_x), /* exit */ Q_ACTION_CAST(0) /* zero terminator */ } }; status_ = QM_TRAN(&tatbl_); } break; }
//;0x0124 IRQ9 void INT_Excep_IRQ9(void) { QF_ISR_ENTRY(); /* inform the QF Vanilla kernel about entering the ISR */ QACTIVE_POST(AO_Philo[1], Q_NEW(QEvt, MAX_PUB_SIG), /* for testing... */ &QS_Excep_IRQ9); QF_ISR_EXIT(); /* inform the QF Vanilla kernel about exiting the ISR */ }
/* ${AOs::Missile::SM::exploding} */ static QState Missile_exploding(Missile * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${AOs::Missile::SM::exploding::TIME_TICK} */ case TIME_TICK_SIG: { /* ${AOs::Missile::SM::exploding::TIME_TICK::[(me->x>=GAME_SPEED_X)&&(me->exp~} */ if ((me->x >= GAME_SPEED_X) && (me->exp_ctr < 15U)) { ObjectImageEvt *oie; ++me->exp_ctr; /* advance the explosion counter */ me->x -= GAME_SPEED_X; /* move the explosion by one step */ /* tell the Tunnel to render the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->x + 3U; /* x-pos of explosion */ oie->y = (int8_t)((int)me->y - 4U); /* y-pos */ oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* ${AOs::Missile::SM::exploding::TIME_TICK::[else]} */ else { static QMTranActTable const tatbl_ = { /* transition-action table */ &Missile_armed_s, { Q_ACTION_CAST(0) /* zero terminator */ } }; status_ = QM_TRAN(&tatbl_); } break; }
/*..........................................................................*/ QState Mine2_exploding(Mine2 *me, QEvt const *e) { switch (e->sig) { case Q_ENTRY_SIG: { me->exp_ctr = 0; return Q_HANDLED(); } case TIME_TICK_SIG: { if ((me->x >= GAME_SPEED_X) && (me->exp_ctr < 15)) { ObjectImageEvt *oie; ++me->exp_ctr; /* advance the explosion counter */ me->x -= GAME_SPEED_X; /* move explosion by 1 step */ /* tell the Game to render the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->x + 1; /* x of explosion */ oie->y = (int8_t)((int)me->y - 4 + 2); /* y of explosion */ oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); } else { return Q_TRAN(&Mine2_unused); } return Q_HANDLED(); }
/* @(/2/0/2/2) .............................................................*/ QState Philo_hungry(Philo *me, QEvent const *e) { switch (e->sig) { /* @(/2/0/2/2) */ case Q_ENTRY_SIG: { TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG); pe->philoNum = PHILO_ID(me); QACTIVE_POST(AO_Table, (QEvent const *)pe, me); return Q_HANDLED(); } /* @(/2/0/2/2/0) */ case EAT_SIG: { /* @(/2/0/2/2/0/0) */ if (((TableEvt const *)e)->philoNum == PHILO_ID(me)) { BSP_busyDelay(); return Q_TRAN(&Philo_eating); } break; } /* @(/2/0/2/2/1) */ case TERMINATE_SIG: /* intentionally fall through */ case DONE_SIG: { Q_ERROR(); return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/* @(/2/4/3/2) .............................................................*/ static QState Mine2_used_x(Mine2 * const me) { /* tell the Tunnel that this mine is becoming disabled */ MineEvt *mev = Q_NEW(MineEvt, MINE_DISABLED_SIG); mev->id = MINE_ID(me); QACTIVE_POST(AO_Tunnel, (QEvt *)mev, me); return QM_EXIT(&Mine2_used_s); }
//;0x0128 IRQ10 void INT_Excep_IRQ10(void) { QK_ISR_ENTRY(); /* inform the QK kernel about entering the ISR */ QACTIVE_POST(AO_Table, Q_NEW(QEvt, MAX_PUB_SIG), /* for testing... */ &QS_Excep_IRQ10); QK_ISR_EXIT(); /* inform the QK kernel about exiting the ISR */ }
void QF_tick(void) { /* see NOTE01 */ #else void QF_tick(void const *sender) { #endif QTimeEvt *t; QF_CRIT_STAT_ QF_CRIT_ENTRY_(); QS_BEGIN_NOCRIT_(QS_QF_TICK, (void *)0, (void *)0) QS_TEC_((QTimeEvtCtr)(++QS_tickCtr_)); /* the tick counter */ QS_END_NOCRIT_() t = QF_timeEvtListHead_; while (t != (QTimeEvt *)0) { --t->ctr; if (t->ctr == (QTimeEvtCtr)0) { /* is time evt about to expire? */ if (t->interval != (QTimeEvtCtr)0) { /* is it periodic timeout? */ t->ctr = t->interval; /* rearm the time event */ } else { /* one-shot timeout, disarm by removing it from the list */ if (t == QF_timeEvtListHead_) { QF_timeEvtListHead_ = t->next; } else { if (t->next != (QTimeEvt *)0) { /* not the last event? */ t->next->prev = t->prev; } t->prev->next = t->next; } t->prev = (QTimeEvt *)0; /* mark the event disarmed */ QS_BEGIN_NOCRIT_(QS_QF_TIMEEVT_AUTO_DISARM, QS_teObj_, t) QS_OBJ_(t); /* this time event object */ QS_OBJ_(t->act); /* the active object */ QS_END_NOCRIT_() } QS_BEGIN_NOCRIT_(QS_QF_TIMEEVT_POST, QS_teObj_, t) QS_TIME_(); /* timestamp */ QS_OBJ_(t); /* the time event object */ QS_SIG_(t->super.sig); /* signal of this time event */ QS_OBJ_(t->act); /* the active object */ QS_END_NOCRIT_() QF_CRIT_EXIT_();/* exit crit. section before calling QF service */ /* QACTIVE_POST() asserts internally if the queue overflows */ QACTIVE_POST(t->act, &t->super, sender); } else { static uint8_t volatile dummy; QF_CRIT_EXIT_(); dummy = (uint8_t)0; /* execute a few instructions, see NOTE02 */ } QF_CRIT_ENTRY_(); /* enter crit. section again to advance the link */ t = t->next; }
static QState Ped_wait(Ped * const me) { QState status_; switch (Q_SIG(me)) { /* @(/1/1/1/1/0) */ case Q_TIMEOUT_SIG: { --me->retryCtr; /* @(/1/1/1/1/0/0) */ if (me->retryCtr != 0U) { QActive_armX((QActive *)me, 0U, WAIT_TOUT); QACTIVE_POST((QActive *)&AO_Pelican, PEDS_WAITING_SIG); status_ = QM_HANDLED(); } /* @(/1/1/1/1/0/1) */ else { static QActionHandler const act_[] = { Q_ACTION_CAST(&Ped_off_e), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Ped_off_s, &act_[0]); } break; } default: { status_ = QM_SUPER(); break; } } return status_; }
static QState Mine2_exploding(Mine2 * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/2/4/3/2/2/0) */ case TIME_TICK_SIG: { /* @(/2/4/3/2/2/0/0) */ if ((me->x >= GAME_SPEED_X) && (me->exp_ctr < 15U)) { ObjectImageEvt *oie; ++me->exp_ctr; /* advance the explosion counter */ me->x -= GAME_SPEED_X; /* move explosion by 1 step */ /* tell the Game to render the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->x + 1U; /* x of explosion */ oie->y = (int8_t)((int)me->y - 4 + 2); /* y of explosion */ oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* @(/2/4/3/2/2/0/1) */ else { static QActionHandler const act_[] = { Q_ACTION_CAST(&Mine2_used_x), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Mine2_unused_s, &act_[0]); } break; }
/*..........................................................................*/ QState Cruncher_processing(Cruncher * const me) { QState status; switch (Q_SIG(me)) { case Q_ENTRY_SIG: { QACTIVE_POST(&me->super, CRUNCH_SIG, 0); me->sum = 0.0; status = Q_HANDLED(); break; } case CRUNCH_SIG: { uint32_t i = Q_PAR(me); uint32_t n = i; i += 100U; for (; n < i; ++n) { if ((n & 1) == 0) { me->sum += 1.0/(2*n + 1); } else { me->sum -= 1.0/(2*n + 1); } } if (i < 0x07000000U) { QACTIVE_POST(&me->super, CRUNCH_SIG, i); status = Q_HANDLED(); } else { BSP_result(me->sum); status = Q_TRAN(&Cruncher_processing); } break; } case ECHO_SIG: { BSP_echo(me->sum); status = Q_HANDLED(); break; } case TERMINATE_SIG: { status = Q_TRAN(&Cruncher_final); break; } default: { status = Q_SUPER(&QHsm_top); break; } } return status; }
/**@brief Function for handling the Apple Notification Service client. * * @details This function is called for all events in the Apple Notification client that * are passed to the application. * * @param[in] p_evt Event received from the Apple Notification Service client. */ static void on_ancs_c_evt(ble_ancs_c_evt_t * p_evt) { uint32_t err_code = NRF_SUCCESS; switch (p_evt->evt_type) { case BLE_ANCS_C_EVT_DISCOVERY_COMPLETE: QS_BEGIN(TRACE_ANCS_EVT, &l_SD) QS_U8(0, p_evt->evt_type); QS_END() QS_START_TX(); err_code = ble_ancs_c_handles_assign(&m_ancs_c,p_evt->conn_handle , &p_evt->service); APP_ERROR_CHECK(err_code); #if 0 apple_notification_setup(); #else QACTIVE_POST(AO_ble, ANCS_SIG, p_evt->evt_type); #endif break; case BLE_ANCS_C_EVT_NOTIF: { struct AncsNotification* status = &l_Ble.ancs_status[p_evt->notif.category_id]; status->flags = p_evt->notif.evt_flags; status->category_count = p_evt->notif.category_count; QS_BEGIN(TRACE_ANCS_EVT, &l_SD) QS_U8(0, p_evt->evt_type); QS_U8(0, p_evt->notif.evt_id); QS_MEM((uint8_t*)&status->flags, sizeof(status->flags)); QS_END() QS_START_TX(); QACTIVE_POST(AO_ble, ANCS_SIG , ((uint32_t)p_evt->notif.evt_id << 24) //Add/Mod/Remove | 0 // flags might not fit into 8 bits if compiler doesn't pack | ((uint16_t)p_evt->notif.category_id << 8)//email, etc | p_evt->evt_type); } break; //case BLE_ANCS_C_EVT_NOTIF_ATTRIBUTE: //title, message, date, etc default: QS_BEGIN(TRACE_ANCS_EVT, &l_SD) QS_U8(0, p_evt->evt_type); QS_END() QS_START_TX(); break; } }
/*${AOs::FlashMgr::SM::Active::BusyFlash} ..................................*/ static QState FlashMgr_BusyFlash(FlashMgr * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${AOs::FlashMgr::SM::Active::BusyFlash} */ case Q_ENTRY_SIG: { /* Arm the timer so if the message can't be processed for some reason, we can get * back to idle state. This timer may be re-armed if some messages require more * time to process than others. */ QTimeEvt_rearm( /* Re-arm timer on entry */ &me->flashTimerEvt, SEC_TO_TICKS( HL_MAX_TOUT_SEC_FLASH_FW ) ); FLASH_Unlock();/* Always unlock the flash on entry since we'll be doing stuff to it */ /* Reset all the variables that keep track of FW upgrades on entry so they are * guaranteed to be cleared when we start any new operation */ memset( me->flashSectorsToErase, 0, sizeof(me->flashSectorsToErase) ); me->flashSectorsToEraseIndex = 0; me->flashSectorsToEraseNum = 0; me->fwPacketCurr = 0; me->fwPacketExp = 0; me->retryCurr = 0; status_ = Q_HANDLED(); break; } /* ${AOs::FlashMgr::SM::Active::BusyFlash} */ case Q_EXIT_SIG: { QTimeEvt_disarm(&me->flashTimerEvt); /* Disarm timer on exit */ FLASH_Lock(); /* Always lock the flash on exit */ /* Always send a flash status event to the CommMgr AO with the current error code */ FlashStatusEvt *evt = Q_NEW(FlashStatusEvt, FLASH_OP_DONE_SIG); evt->errorCode = me->errorCode; QACTIVE_POST(AO_CommMgr, (QEvt *)(evt), AO_FlashMgr); status_ = Q_HANDLED(); break; } /* ${AOs::FlashMgr::SM::Active::BusyFlash::FLASH_TIMEOUT} */ case FLASH_TIMEOUT_SIG: { ERR_printf("Timeout trying to process flash request, error: 0x%08x\n", me->errorCode); status_ = Q_TRAN(&FlashMgr_Idle); break; } /* ${AOs::FlashMgr::SM::Active::BusyFlash::FLASH_ERROR} */ case FLASH_ERROR_SIG: { ERR_printf("Unable to to process flash request. Error: 0x%08x\n", me->errorCode); status_ = Q_TRAN(&FlashMgr_Idle); break; } default: { status_ = Q_SUPER(&FlashMgr_Active); break; } } return status_; }
/*..........................................................................*/ void BSP_onKeyboardInput(uint8_t key) { switch (key) { case 'e': { static QEvt const echoEvt = { ECHO_SIG, 0U, 0U }; QACTIVE_POST((QActive *)&l_cruncher, &echoEvt, (void *)0); break; } case '\033': { /* ESC pressed? */ /* NOTE: this constant event is statically pre-allocated. * It can be posted/published as any other event. */ static QEvt const terminateEvt = { TERMINATE_SIG, 0U, 0U }; QACTIVE_POST((QActive *)&l_cruncher, &terminateEvt, (void *)0); break; } } }
/* @(/2/1/4/1/3) ...........................................................*/ static QState Ship_flying_e(Ship * const me) { ScoreEvt *sev; me->score = 0U; /* reset the score */ sev = Q_NEW(ScoreEvt, SCORE_SIG); sev->score = me->score; QACTIVE_POST(AO_Tunnel, (QEvt *)sev, me); return QM_ENTRY(&Ship_flying_s); }
/*..........................................................................*/ void GPIOPortA_IRQHandler(void) { QK_ISR_ENTRY(); /* inform QK about entering an ISR */ QACTIVE_POST(AO_Table, Q_NEW(QEvt, MAX_PUB_SIG), /* for testing... */ &l_GPIOPortA_IRQHandler); QK_ISR_EXIT(); /* inform QK about exiting an ISR */ }
void EXTI0_IRQHandler(void) { QK_ISR_ENTRY(); /* inform QK-nano about ISR entry */ EXTI->PR = 0x1; /* set the EXTI->PR[0] to clear the EXTI_SWIER[0] bit */ /* for testing */ QACTIVE_POST(AO_Table, Q_NEW(QEvent, MAX_PUB_SIG), (void *)0); QK_ISR_EXIT(); /* inform QK-nano about ISR exit */ }
/* example ISR handler for CMSIS-RTX */ void GPIOPortA_IRQHandler(void); /* prototype */ void GPIOPortA_IRQHandler(void) { QACTIVE_POST(AO_Blinky, Q_NEW(QEvt, DUMMY_SIG), /* for testing... */ (void *)0); /* NOTE: * There is no need to explicitly pend the PendSV exception, because * RTX handles this when signaling the task. (See OS_PEND_IRQ() macro * in RTX source code). */ }
/*..........................................................................*/ QK_ISR(auto_psv) _INT0Interrupt() { static QEvt const eat_evt = { EAT_SIG, 0U, 0U }; _INT0IF = 0; QACTIVE_POST(AO_Table, &eat_evt, &l_INT0Interrupt); QK_ISR_EXIT(); /* inform QK-nano about exiting the ISR */ }
/*..........................................................................*/ static void moveShipUp(void) { ObjectPosEvt *ope; if (l_ship_pos > 0U) { --l_ship_pos; } ope = Q_NEW(ObjectPosEvt, PLAYER_SHIP_MOVE_SIG); ope->x = (uint8_t)GAME_SHIP_X; ope->y = (uint8_t)l_ship_pos; QACTIVE_POST(AO_Ship, (QEvt *)ope, &l_mouse); }
//............................................................................ static void moveShipDown(void) { ObjectPosEvt *ope; if (l_ship_pos < (GAME_SCREEN_HEIGHT - 3U)) { ++l_ship_pos; } ope = Q_NEW(ObjectPosEvt, PLAYER_SHIP_MOVE_SIG); ope->x = (uint8_t)GAME_SHIP_X; ope->y = (uint8_t)l_ship_pos; QACTIVE_POST(AO_Ship, (QEvt *)ope, &l_mouse); }