void QActive_postFIFO(QActive *me, QEvent const *e) { portBASE_TYPE err; QF_INT_LOCK_KEY_ #ifdef YYY QF_INT_LOCK_(); if (e->dynamic_ != (uint8_t)0) { ++((QEvent *)e)->dynamic_; } QF_INT_UNLOCK_(); #endif // err = xQueueSendToBack(me->eQueue, &e, (portTickType)0); #define XXX #ifdef XXX if (ulCriticalNesting == (unsigned portLONG)0) { /* task level? */ QF_INT_LOCK_(); if (e->dynamic_ != (uint8_t)0) { ++((QEvent *)e)->dynamic_; } QF_INT_UNLOCK_(); err = xQueueSendToBack(me->eQueue, &e, (portTickType)0); } else { /* must be ISR level */ portBASE_TYPE xHigherPriorityTaskWoken; err = xQueueSendToBackFromISR(me->eQueue, &e,&xHigherPriorityTaskWoken); } #endif Q_ASSERT(err == pdPASS); }
/*..........................................................................*/ void QF_tick(void) { /* see NOTE01 */ QTimeEvt *t; QF_INT_LOCK_KEY_ QF_INT_LOCK_(); QS_BEGIN_NOLOCK_(QS_QF_TICK, (void *)0, (void *)0) QS_TEC_(++QS_tickCtr_); /* the tick counter */ QS_END_NOLOCK_() 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_NOLOCK_(QS_QF_TIMEEVT_AUTO_DISARM, QS_teObj_, t) QS_OBJ_(t); /* this time event object */ QS_OBJ_(t->act); /* the active object */ QS_END_NOLOCK_() } QS_BEGIN_NOLOCK_(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_NOLOCK_() QF_INT_UNLOCK_();/* unlock interrupts before calling QF service */ /* postFIFO() asserts internally that the event was accepted */ QActive_postFIFO(t->act, (QEvent *)t); } else { static uint8_t volatile dummy; QF_INT_UNLOCK_(); dummy = (uint8_t)0; /* execute a few instructions, see NOTE02 */ } QF_INT_LOCK_(); /* lock interrupts again to advance the link */ t = t->next; }
/*..........................................................................*/ void QTimeEvt_arm_(QTimeEvt *me, QActive *act, QTimeEvtCtr nTicks) { QF_INT_LOCK_KEY_ Q_REQUIRE((nTicks > (QTimeEvtCtr)0) /* cannot arm a timer with 0 ticks */ && (((QEvent *)me)->sig >= (QSignal)Q_USER_SIG)/*valid signal */ && (me->prev == (QTimeEvt *)0) /* time evt must NOT be used */ && (act != (QActive *)0)); /* active object must be provided */ me->ctr = nTicks; me->prev = me; /* mark the timer in use */ me->act = act; QF_INT_LOCK_(); QS_BEGIN_NOLOCK_(QS_QF_TIMEEVT_ARM, QS_teObj_, me) QS_TIME_(); /* timestamp */ QS_OBJ_(me); /* this time event object */ QS_OBJ_(act); /* the active object */ QS_TEC_(nTicks); /* the number of ticks */ QS_TEC_(me->interval); /* the interval */ QS_END_NOLOCK_() me->next = QF_timeEvtListHead_; if (QF_timeEvtListHead_ != (QTimeEvt *)0) { QF_timeEvtListHead_->prev = me; } QF_timeEvtListHead_ = me; QF_INT_UNLOCK_(); }
/*..........................................................................*/ void QF_stop(void) { QF_INT_LOCK_KEY_ QF_INT_LOCK_(); _dos_setvect(uCOS, l_dosSpareISR); /* restore the original DOS vector */ QF_INT_UNLOCK_(); QF_onCleanup(); /* cleanup callback */ }
void QActive_postFIFO(QActive *me, QEvent const *e) { #else void QActive_postFIFO(QActive *me, QEvent const *e, void const *sender) { #endif QF_INT_LOCK_KEY_ QF_INT_LOCK_(); QS_BEGIN_NOLOCK_(QS_QF_ACTIVE_POST_FIFO, QS_aoObj_, me) QS_TIME_(); /* timestamp */ QS_OBJ_(sender); /* the sender object */ QS_SIG_(e->sig); /* the signal of the event */ QS_OBJ_(me); /* this active object (recipient) */ QS_U8_(EVT_POOL_ID(e)); /* the pool Id of the event */ QS_U8_(EVT_REF_CTR(e)); /* the ref count of the event */ QS_EQC_(0); /* number of free entries (unknown) */ QS_EQC_(0); /* min number of free entries (unknown) */ QS_END_NOLOCK_() if (EVT_POOL_ID(e) != (uint8_t)0) { /* is it a pool event? */ EVT_INC_REF_CTR(e); /* increment the reference counter */ } QF_INT_UNLOCK_(); Q_ALLEGE(OSQPost((OS_EVENT *)me->eQueue, (void *)e) == OS_NO_ERR); }
//............................................................................ void QF::stop(void) { QF_INT_LOCK_KEY_ QF_INT_LOCK_(); setvect(uCOS, l_dosSpareISR); // restore the original DOS vector QF_INT_UNLOCK_(); onCleanup(); // cleanup callback }
//............................................................................ void QActive::postLIFO(QEvent const *e) { QF_INT_LOCK_KEY_ QF_INT_LOCK_(); if (e->dynamic_ != (uint8_t)0) { ++((QEvent *)e)->dynamic_; } QF_INT_UNLOCK_(); Q_ALLEGE(OSQPostFront((OS_EVENT *)m_eQueue, (void *)e) == OS_NO_ERR); }
//............................................................................ // [SWC] Like GW in QF-C, make this routine return if all events are consumed. // Remove QF::onIdle(). void QF::run(void) { QF::onStartup(); // startup callback for (;;) { // the background loop QF_INT_LOCK_KEY_ QF_INT_LOCK_(); if (QF_readySet_.notEmpty()) { uint8_t p = QF_readySet_.findMax(); QActive *a = active_[p]; QF_INT_UNLOCK_(); QEvent const *e = a->get_(); // get the next event for this AO a->dispatch(e); // dispatch evt to the HSM gc(e); // determine if event is garbage and collect it if so } else { QF_INT_UNLOCK_(); break; } } }
/*..........................................................................*/ uint32_t QF_getPoolMargin(uint8_t poolId) { uint32_t margin; QF_INT_LOCK_KEY_ Q_REQUIRE(((uint8_t)1 <= poolId) && (poolId <= QF_maxPool_)); QF_INT_LOCK_(); margin = (uint32_t)QF_pool_[poolId - (uint8_t)1].nMin; QF_INT_UNLOCK_(); return margin; }
/*..........................................................................*/ void QF_run(void) { uint8_t p; QActive *a; QEvent const *e; QF_INT_LOCK_KEY_ QF_onStartup(); /* startup callback */ for (;;) { /* the background loop */ QF_INT_LOCK_(); #if (QF_MAX_ACTIVE <= 8) if (QPSet8_notEmpty(&QF_readySet_)) { QPSet8_findMax(&QF_readySet_, p); #else if (QPSet64_notEmpty(&QF_readySet_)) { QPSet64_findMax(&QF_readySet_, p); #endif a = QF_active_[p]; QF_INT_UNLOCK_(); e = QActive_get_(a); /* get the next event for this AO */ QF_ACTIVE_DISPATCH_(&a->super, e); /* dispatch to the AO */ QF_gc(e); /* determine if event is garbage and collect it if so */ } else { #ifndef QF_INT_KEY_TYPE QF_onIdle(); /* see NOTE01 */ #else QF_onIdle(intLockKey_); /* see NOTE01 */ #endif /* QF_INT_KEY_TYPE */ } } } /*..........................................................................*/ void QActive_start(QActive *me, uint8_t prio, QEvent const *qSto[], uint32_t qLen, void *stkSto, uint32_t stkSize, QEvent const *ie) { Q_REQUIRE(((uint8_t)0 < prio) && (prio <= (uint8_t)QF_MAX_ACTIVE) && (stkSto == (void *)0)); /* does not need per-actor stack */ (void)stkSize; /* avoid the "unused parameter" compiler warning */ QEQueue_init(&me->eQueue, qSto, (QEQueueCtr)qLen);/* initialize QEQueue */ me->prio = prio; /* set the QF priority of this active object */ QF_add_(me); /* make QF aware of this active object */ QF_ACTIVE_INIT_(&me->super, ie); /* execute initial transition */ QS_FLUSH(); /* flush the trace buffer to the host */ }
//............................................................................ void QF::gc(QEvent const *e) { if (e->dynamic_ != (uint8_t)0) { // is it a dynamic event? QF_INT_LOCK_KEY_ QF_INT_LOCK_(); if ((e->dynamic_ & 0x3F) > 1) { // isn't this the last reference? //lint -e1773 Attempt to cast away const --((QEvent *)e)->dynamic_; // decrement the reference counter // NOTE: cast the 'const' away, which is legitimate because // it's a dynamic event QS_BEGIN_NOLOCK_(QS_QF_GC_ATTEMPT, (void *)0, (void *)0) QS_TIME_(); // timestamp QS_SIG_(e->sig); // the signal of the event QS_U8_(e->dynamic_); // the dynamic attributes of the event QS_END_NOLOCK_() QF_INT_UNLOCK_(); } else { // this is the last reference to this event, recycle it uint8_t idx = (uint8_t)((e->dynamic_ >> 6) - 1); QS_BEGIN_NOLOCK_(QS_QF_GC, (void *)0, (void *)0) QS_TIME_(); // timestamp QS_SIG_(e->sig); // the signal of the event QS_U8_(e->dynamic_); // the dynamic attributes of the event QS_END_NOLOCK_() QF_INT_UNLOCK_(); Q_ASSERT(idx < QF_maxPool_); //lint -e1773 Attempt to cast away const QF_EPOOL_PUT_(QF_pool_[idx], (QEvent *)e); // cast 'const' away, // which is legitimate, because it's a pool event } }
/*..........................................................................*/ uint32_t QF_getQueueMargin(uint8_t prio) { uint32_t margin; QF_INT_LOCK_KEY_ Q_REQUIRE((prio <= (uint8_t)QF_MAX_ACTIVE) && (QF_active_[prio] != (QActive *)0)); QF_INT_LOCK_(); margin = (uint32_t)(QF_active_[prio]->eQueue__.nTot__ - QF_active_[prio]->eQueue__.nMax__); QF_INT_UNLOCK_(); return margin; }
void QActive_postFIFO(QActive *me, QEvent const *e) { #else void QActive_postFIFO(QActive *me, QEvent const *e, void const *sender) { #endif QF_INT_LOCK_KEY_ QF_INT_LOCK_(); QS_BEGIN_NOLOCK_(QS_QF_ACTIVE_POST_FIFO, QS_aoObj_, me) QS_TIME_(); /* timestamp */ QS_OBJ_(sender); /* the sender object */ QS_SIG_(e->sig); /* the signal of the event */ QS_OBJ_(me); /* this active object (recipient) */ QS_U8_(EVT_POOL_ID(e)); /* the pool Id of the event */ QS_U8_(EVT_REF_CTR(e)); /* the ref count of the event */ QS_EQC_(me->eQueue.nFree); /* number of free entries */ QS_EQC_(me->eQueue.nMin); /* min number of free entries */ QS_END_NOLOCK_() if (EVT_POOL_ID(e) != (uint8_t)0) { /* is it a pool event? */ EVT_INC_REF_CTR(e); /* increment the reference counter */ } if (me->eQueue.frontEvt == (QEvent *)0) { /* empty queue? */ me->eQueue.frontEvt = e; /* deliver event directly */ QACTIVE_EQUEUE_SIGNAL_(me); /* signal the event queue */ } else { /* queue is not empty, insert event into the ring-buffer */ /* the queue must be able to accept the event (cannot overflow) */ Q_ASSERT(me->eQueue.nFree != (QEQueueCtr)0); /* insert event into the ring buffer (FIFO) */ me->eQueue.ring[me->eQueue.head] = e; if (me->eQueue.head == (QEQueueCtr)0) { /* need to wrap the head? */ me->eQueue.head = me->eQueue.end; /* wrap around */ } --me->eQueue.head; --me->eQueue.nFree; /* update number of free events */ if (me->eQueue.nMin > me->eQueue.nFree) { me->eQueue.nMin = me->eQueue.nFree; /* update min so far */ } } QF_INT_UNLOCK_(); }
/*..........................................................................*/ void QF_add_(QActive *a) { uint8_t p = a->prio; QF_INT_LOCK_KEY_ Q_REQUIRE(((uint8_t)0 < p) && (p <= (uint8_t)QF_MAX_ACTIVE) && (QF_active_[p] == (QActive *)0)); QF_INT_LOCK_(); QF_active_[p] = a; /* registger the active object at this priority */ QS_BEGIN_NOLOCK_(QS_QF_ACTIVE_ADD, QS_aoObj_, a) QS_TIME_(); /* timestamp */ QS_OBJ_(a); /* the active object */ QS_U8_(p); /* the priority of the active object */ QS_END_NOLOCK_() QF_INT_UNLOCK_(); }
/*..........................................................................*/ void QF_remove_(QActive const *a) { uint8_t p = a->prio; QF_INT_LOCK_KEY_ Q_REQUIRE(((uint8_t)0 < p) && (p <= (uint8_t)QF_MAX_ACTIVE) && (QF_active_[p] == a)); QF_INT_LOCK_(); QF_active_[p] = (QActive *)0; /* free-up the priority level */ QS_BEGIN_NOLOCK_(QS_QF_ACTIVE_REMOVE, QS_aoObj_, a) QS_TIME_(); /* timestamp */ QS_OBJ_(a); /* the active object */ QS_U8_(p); /* the priority of the active object */ QS_END_NOLOCK_() QF_INT_UNLOCK_(); }
/*..........................................................................*/ void QEQueue_postLIFO(QEQueue *me, QEvent const *e) { QF_INT_LOCK_KEY_ QF_INT_LOCK_(); QS_BEGIN_NOLOCK_(QS_QF_EQUEUE_POST_LIFO, QS_eqObj_, me) QS_TIME_(); /* timestamp */ QS_SIG_(e->sig); /* the signal of this event */ QS_OBJ_(me); /* this queue object */ QS_U8_(e->dynamic_); /* the dynamic attribute of the event */ QS_EQC_(me->nFree); /* number of free entries */ QS_EQC_(me->nMin); /* min number of free entries */ QS_END_NOLOCK_() if (e->dynamic_ != (uint8_t)0) { /* is it a pool event? */ ++((QEvent *)e)->dynamic_; /* increment the reference counter */ /* NOTE: cast the 'const' away, which is legitimate because * it's a dynamic event */ } if (me->frontEvt != (QEvent *)0) { /* is the queue not empty? */ /* the queue must be able to accept the event (cannot overflow) */ Q_ASSERT(me->nFree != (QEQueueCtr)0); ++me->tail; if (me->tail == me->end) { /* need to wrap the tail? */ me->tail = (QEQueueCtr)0; /* wrap around */ } me->ring[me->tail] = me->frontEvt; /* buffer the old front evt */ --me->nFree; /* update number of free events */ if (me->nMin > me->nFree) { me->nMin = me->nFree; /* update minimum so far */ } } me->frontEvt = e; /* stick the new event to the front */ QF_INT_UNLOCK_(); }
/*..........................................................................*/ QEvent const *QActive_get_(QActive *me) { QEvent const *e; QF_INT_LOCK_KEY_ QF_INT_LOCK_(); QACTIVE_OSOBJECT_WAIT_(me); /* wait for event to arrive directly */ e = me->eQueue__.frontEvt__; if (me->eQueue__.nUsed__ != (QEQueueCtr)0) {/*any events in the buffer? */ /* remove from the tail */ me->eQueue__.frontEvt__ = me->eQueue__.ring__[me->eQueue__.tail__]; ++me->eQueue__.tail__; if (me->eQueue__.tail__ == me->eQueue__.end__) { /* wrap around? */ me->eQueue__.tail__ = (QEQueueCtr)0; /* wrap the tail */ } --me->eQueue__.nUsed__; /* one less event in the ring buffer */ QS_BEGIN_NOLOCK_(QS_QF_ACTIVE_GET, QS_aoObj_, me); QS_TIME_(); /* timestamp */ QS_SIG_(e->sig); /* the signal of this event */ QS_OBJ_(me); /* this active object */ QS_U8_(e->attrQF__); /* the QF attribute of the event */ QS_EQC_(me->eQueue__.nUsed__); /* number of used entries */ QS_END_NOLOCK_(); } else { me->eQueue__.frontEvt__ = (QEvent const *)0; /* queue becomes empty */ QACTIVE_OSOBJECT_ONIDLE_(me); QS_BEGIN_NOLOCK_(QS_QF_ACTIVE_GET_LAST, QS_aoObj_, me); QS_TIME_(); /* timestamp */ QS_SIG_(e->sig); /* the signal of this event */ QS_OBJ_(me); /* this active object */ QS_U8_(e->attrQF__); /* the QF attribute of the event */ QS_END_NOLOCK_(); } QF_INT_UNLOCK_(); return e; }
/*..........................................................................*/ void QActive_subscribe(QActive const *me, QSignal sig) { uint8_t p = me->prio; uint8_t i = Q_ROM_BYTE(QF_div8Lkup[p]); QF_INT_LOCK_KEY_ Q_REQUIRE(((QSignal)Q_USER_SIG <= sig) && (sig < QF_maxSignal_) && ((uint8_t)0 < p) && (p <= (uint8_t)QF_MAX_ACTIVE) && (QF_active_[p] == me)); QF_INT_LOCK_(); QS_BEGIN_NOLOCK_(QS_QF_ACTIVE_SUBSCRIBE, QS_aoObj_, me) QS_TIME_(); /* timestamp */ QS_SIG_(sig); /* the signal of this event */ QS_OBJ_(me); /* this active object */ QS_END_NOLOCK_() /* set the priority bit */ QF_subscrList_[sig].bits[i] |= Q_ROM_BYTE(QF_pwr2Lkup[p]); QF_INT_UNLOCK_(); }
/*..........................................................................*/ void QEQueue_postFIFO(QEQueue *me, QEvent const *e) { QF_INT_LOCK_KEY_ QF_INT_LOCK_(); QS_BEGIN_NOLOCK_(QS_QF_EQUEUE_POST_FIFO, QS_eqObj_, me) QS_TIME_(); /* timestamp */ QS_SIG_(e->sig); /* the signal of this event */ QS_OBJ_(me); /* this queue object */ QS_U8_(e->dynamic_); /* the dynamic attribute of the event */ QS_EQC_(me->nFree); /* number of free entries */ QS_EQC_(me->nMin); /* min number of free entries */ QS_END_NOLOCK_() if (e->dynamic_ != (uint8_t)0) { /* is it a pool event? */ ++((QEvent *)e)->dynamic_; /* increment the reference counter */ /* NOTE: cast the 'const' away, which is legitimate because * it's a dynamic event */ } if (me->frontEvt == (QEvent *)0) { /* is the queue empty? */ me->frontEvt = e; /* deliver event directly */ } else { /* queue is not empty, leave event in the ring-buffer */ /* the queue must be able to accept the event (cannot overflow) */ Q_ASSERT(me->nFree != (QEQueueCtr)0); me->ring[me->head] = e; /* insert event into the buffer (FIFO) */ if (me->head == (QEQueueCtr)0) { /* need to wrap the head? */ me->head = me->end; /* wrap around */ } --me->head; --me->nFree; /* update number of free events */ if (me->nMin > me->nFree) { me->nMin = me->nFree; /* update minimum so far */ } } QF_INT_UNLOCK_(); }
/* NOTE: disarm a timer (no harm in disarming an already disarmed timer) */ uint8_t QTimeEvt_disarm(QTimeEvt *me) { uint8_t wasArmed; QF_INT_LOCK_KEY_ QF_INT_LOCK_(); if (me->prev__ != (QTimeEvt *)0) { /* is the time event actually armed? */ wasArmed = (uint8_t)1; if (me == QF_timeEvtListHead_) { QF_timeEvtListHead_ = me->next__; } else { if (me->next__ != (QTimeEvt *)0) { /* not the last in the list? */ me->next__->prev__ = me->prev__; } me->prev__->next__ = me->next__; } me->prev__ = (QTimeEvt *)0; /* mark the time event as disarmed */ QS_BEGIN_NOLOCK_(QS_QF_TIMEEVT_DISARM, QS_teObj_, me); QS_TIME_(); /* timestamp */ QS_OBJ_(me); /* this time event object */ QS_OBJ_(me->act__); /* the active object */ QS_TEC_(me->ctr__); /* the number of ticks */ QS_TEC_(me->interval__); /* the interval */ QS_END_NOLOCK_(); } else { /* the time event was not armed */ wasArmed = (uint8_t)0; QS_BEGIN_NOLOCK_(QS_QF_TIMEEVT_DISARM_ATTEMPT, QS_teObj_, me); QS_TIME_(); /* timestamp */ QS_OBJ_(me); /* this time event object */ QS_OBJ_(me->act__); /* the active object */ QS_END_NOLOCK_(); } QF_INT_UNLOCK_(); return wasArmed; }
/*..........................................................................*/ void *QMPool_get(QMPool *me) { QFreeBlock *fb; QF_INT_LOCK_KEY_ QF_INT_LOCK_(); fb = (QFreeBlock *)me->free; /* get a free block or NULL */ if (fb != (QFreeBlock *)0) { /* free block available? */ me->free = fb->next; /* adjust list head to the next free block */ --me->nFree; /* one less free block */ if (me->nMin > me->nFree) { me->nMin = me->nFree; /* remember the minimum so far */ } } QS_BEGIN_NOLOCK_(QS_QF_MPOOL_GET, QS_mpObj_, me->start) QS_TIME_(); /* timestamp */ QS_OBJ_(me->start); /* the memory managed by this pool */ QS_MPC_(me->nFree); /* the number of free blocks in the pool */ QS_MPC_(me->nMin); /* min number of free blocks ever in the pool */ QS_END_NOLOCK_() QF_INT_UNLOCK_(); return fb; /* return the block or NULL pointer to the caller */ }
/*..........................................................................*/ void QF_stop(void) { QF_INT_LOCK_KEY_ QF_INT_LOCK_(); QF_INT_UNLOCK_(); QF_onCleanup(); /* cleanup callback */ }