QP is an event-driven, RTOS-like, active object framework for microcontrollers, such as mbed. The QP framework provides thread-safe execution of active objects (concurrent state machines) and support both manual and automatic coding of UML statecharts in readable, production-quality C or C++. Automatic code generation of QP code is supported by the free QM modeling tool.

Dependents:   qp_hangman qp_dpp qp_blinky

QP/C++ (Quantum Platform in C++) is a lightweight, open source active object (actor) framework for building responsive and modular real-time embedded applications as systems of asynchronous event-driven active objects (actors). The QP/C++ framework is a member of a larger family consisting of QP/C++, QP/C, and QP-nano frameworks, which are all strictly quality controlled, thoroughly documented, and available under GPLv3 with a special Exception for mbed (see http://www.state-machine.com/licensing/QP-mbed_GPL_Exception.txt).

The behavior of active objects is specified in QP/C++ by means of hierarchical state machines (UML statecharts). The framework supports manual coding of UML state machines in C++ as well as automatic code generation by means of the free QM modeling tool (http://www.state-machine.com/qm).

Please see the "QP/C++ Reference Manual" (http://www.state-machine.com/qpcpp) for more information.

Revision:
6:01d57c81e96a
Parent:
0:064c79e7311a
Child:
7:bf92d3a6625e
--- a/qp.cpp	Sun Sep 25 18:10:41 2011 +0000
+++ b/qp.cpp	Mon Sep 26 01:42:32 2011 +0000
@@ -1,7 +1,7 @@
 //////////////////////////////////////////////////////////////////////////////
 // Product: QP/C++, selectabel Vanilla/QK kernels
-// Last Updated for QP ver: 4.1.06 (modified to fit in one file)
-// Date of the Last Update: Feb 08, 2011
+// Last Updated for QP ver: 4.2.04 (modified to fit in one file)
+// Date of the Last Update: Sep 25, 2011
 //
 //                    Q u a n t u m     L e a P s
 //                    ---------------------------
@@ -27,6 +27,10 @@
 //////////////////////////////////////////////////////////////////////////////
 #include "qp_port.h"                                                // QP port
 
+#ifdef Q_USE_NAMESPACE
+namespace QP {
+#endif
+
 Q_DEFINE_THIS_MODULE(qp)
 
 // "qep_pkg.h" ===============================================================
@@ -42,7 +46,7 @@
 #define QEP_TRIG_(state_, sig_) \
     ((*(state_))(this, &QEP_reservedEvt_[sig_]))
 
-/// helper macro to trigger entry action in an HSM
+/// helper macro to trigger exit action in an HSM
 #define QEP_EXIT_(state_) \
     if (QEP_TRIG_(state_, Q_EXIT_SIG) == Q_RET_HANDLED) { \
         QS_BEGIN_(QS_QEP_STATE_EXIT, QS::smObj_, this) \
@@ -51,7 +55,7 @@
         QS_END_() \
     }
 
-/// helper macro to trigger exit action in an HSM
+/// helper macro to trigger entry action in an HSM
 #define QEP_ENTER_(state_) \
     if (QEP_TRIG_(state_, Q_ENTRY_SIG) == Q_RET_HANDLED) { \
         QS_BEGIN_(QS_QEP_STATE_ENTRY, QS::smObj_, this) \
@@ -63,21 +67,28 @@
 // "qep.cpp" =================================================================
 // Package-scope objects -----------------------------------------------------
 QEvent const QEP_reservedEvt_[] = {
-    { (QSignal)QEP_EMPTY_SIG_, (uint8_t)0 },
-    { (QSignal)Q_ENTRY_SIG,    (uint8_t)0 },
-    { (QSignal)Q_EXIT_SIG,     (uint8_t)0 },
-    { (QSignal)Q_INIT_SIG,     (uint8_t)0 }
+#ifdef Q_EVT_CTOR
+    (QSignal)QEP_EMPTY_SIG_,
+    (QSignal)Q_ENTRY_SIG,
+    (QSignal)Q_EXIT_SIG,
+    (QSignal)Q_INIT_SIG
+#else
+    {(QSignal)QEP_EMPTY_SIG_, (uint8_t)0, (uint8_t)0},
+    {(QSignal)Q_ENTRY_SIG,    (uint8_t)0, (uint8_t)0},
+    {(QSignal)Q_EXIT_SIG,     (uint8_t)0, (uint8_t)0},
+    {(QSignal)Q_INIT_SIG,     (uint8_t)0, (uint8_t)0}
+#endif
 };
 //............................................................................
-//lint -e970 -e971               ignore MISRA rules 13 and 14 in this function
+//lint -e970 -e971 -e778         ignore MISRA rules 13 and 14 in this function
 char const Q_ROM * Q_ROM_VAR QEP::getVersion(void) {
     static char const Q_ROM Q_ROM_VAR version[] = {
-        ((QP_VERSION >> 12) & 0xF) + '0',
+        (char)(((QP_VERSION >> 12U) & 0xFU) + (uint8_t)'0'),
         '.',
-        ((QP_VERSION >>  8) & 0xF) + '0',
+        (char)(((QP_VERSION >>  8U) & 0xFU) + (uint8_t)'0'),
         '.',
-        ((QP_VERSION >>  4) & 0xF) + '0',
-        (QP_VERSION         & 0xF) + '0',
+        (char)(((QP_VERSION >>  4U) & 0xFU) + (uint8_t)'0'),
+        (char)((QP_VERSION          & 0xFU) + (uint8_t)'0'),
         '\0'
     };
     return version;
@@ -402,7 +413,7 @@
 
 // package-scope objects -----------------------------------------------------
 extern QTimeEvt *QF_timeEvtListHead_;  ///< head of linked list of time events
-extern QF_EPOOL_TYPE_ QF_pool_[3];                 ///< allocate 3 event pools
+extern QF_EPOOL_TYPE_ QF_pool_[QF_MAX_EPOOL];        ///< allocate event pools
 extern uint8_t QF_maxPool_;                  ///< # of initialized event pools
 extern QSubscrList *QF_subscrList_;             ///< the subscriber list array
 extern QSignal QF_maxSignal_;                ///< the maximum published signal
@@ -414,12 +425,25 @@
     QFreeBlock *m_next;
 };
 
+/// \brief access to the poolId of an event \a e_
+#define EVT_POOL_ID(e_)     ((e_)->poolId_)
+
+/// \brief access to the refCtr of an event \a e_
+#define EVT_REF_CTR(e_)     ((e_)->refCtr_)
+
+/// \brief increment the refCtr of an event \a e_
+#define EVT_INC_REF_CTR(e_) (++((QEvent *)(e_))->refCtr_)
+
+/// \brief decrement the refCtr of an event \a e_
+#define EVT_DEC_REF_CTR(e_) (--((QEvent *)(e_))->refCtr_)
+
 // "qa_defer.cpp" ============================================================
+//............................................................................
 void QActive::defer(QEQueue *eq, QEvent const *e) {
     eq->postFIFO(e);
 }
 //............................................................................
-QEvent const *QActive::recall(QEQueue *eq) {
+uint8_t QActive::recall(QEQueue *eq) {
     QEvent const *e = eq->get();    // try to get an event from deferred queue
     if (e != (QEvent *)0) {                                // event available?
 
@@ -428,48 +452,53 @@
         QF_INT_LOCK_KEY_
         QF_INT_LOCK_();
 
-        if (e->dynamic_ != (uint8_t)0) {             // is it a dynamic event?
+        if (EVT_POOL_ID(e) != (uint8_t)0) {          // is it a dynamic event?
 
             // after posting to the AO's queue the event must be referenced
             // at least twice: once in the deferred event queue (eq->get()
             // did NOT decrement the reference counter) and once in the
             // AO's event queue.
-            Q_ASSERT((e->dynamic_ & 0x3F) > 1);
+            Q_ASSERT(EVT_REF_CTR(e) > (uint8_t)1);
 
             // we need to decrement the reference counter once, to account
             // for removing the event from the deferred event queue.
             //
-            //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
+            EVT_DEC_REF_CTR(e);             // decrement the reference counter
         }
 
         QF_INT_UNLOCK_();
 
+        return (uint8_t)1;                                   // event recalled
     }
-    return e;  // pass the recalled event to the caller (NULL if not recalled)
+    else {
+        return (uint8_t)0;                               // event not recalled
+    }
 }
 
 // "qa_fifo.cpp" =============================================================
+//............................................................................
+#ifndef Q_SPY
 void QActive::postFIFO(QEvent const *e) {
+#else
+void QActive::postFIFO(QEvent const *e, void const *sender) {
+#endif
+
     QF_INT_LOCK_KEY_
     QF_INT_LOCK_();
 
     QS_BEGIN_NOLOCK_(QS_QF_ACTIVE_POST_FIFO, QS::aoObj_, this)
         QS_TIME_();                                               // timestamp
+        QS_OBJ_(sender);                                  // the sender object
         QS_SIG_(e->sig);                            // the signal of the event
         QS_OBJ_(this);                                   // this active object
-        QS_U8_(e->dynamic_);                  // the QF attribute of the event
+        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_(m_eQueue.m_nFree);                   // number of free entries
         QS_EQC_(m_eQueue.m_nMin);                // min number of free entries
     QS_END_NOLOCK_()
 
-    if (e->dynamic_ != (uint8_t)0) {                 // is it a dynamic event?
-        //lint -e1773                               Attempt to cast away const
-        ++((QEvent *)e)->dynamic_;          // increment the reference counter
-                   // NOTE: cast the 'const' away, which is legitimate because
-                   // it's a dynamic event
+    if (EVT_POOL_ID(e) != (uint8_t)0) {              // is it a dynamic event?
+        EVT_INC_REF_CTR(e);                 // increment the reference counter
     }
 
     if (m_eQueue.m_frontEvt == (QEvent *)0) {           // is the queue empty?
@@ -516,7 +545,8 @@
             QS_TIME_();                                           // timestamp
             QS_SIG_(e->sig);                       // the signal of this event
             QS_OBJ_(this);                               // this active object
-            QS_U8_(e->dynamic_);        // the dynamic attributes of the event
+            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_(m_eQueue.m_nFree);               // number of free entries
         QS_END_NOLOCK_()
     }
@@ -528,7 +558,8 @@
             QS_TIME_();                                           // timestamp
             QS_SIG_(e->sig);                       // the signal of this event
             QS_OBJ_(this);                               // this active object
-            QS_U8_(e->dynamic_);        // the dynamic attributes of the event
+            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_END_NOLOCK_()
     }
     QF_INT_UNLOCK_();
@@ -556,16 +587,14 @@
         QS_TIME_();                                               // timestamp
         QS_SIG_(e->sig);                           // the signal of this event
         QS_OBJ_(this);                                   // this active object
-        QS_U8_(e->dynamic_);            // the dynamic attributes of the event
+        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_(m_eQueue.m_nFree);                   // number of free entries
         QS_EQC_(m_eQueue.m_nMin);                // min number of free entries
     QS_END_NOLOCK_()
 
-    if (e->dynamic_ != (uint8_t)0) {                    // is it a pool event?
-        //lint -e1773                               Attempt to cast away const
-        ++((QEvent *)e)->dynamic_;          // increment the reference counter
-                   // NOTE: cast the 'const' away, which is legitimate because
-                   // it's a dynamic event
+    if (EVT_POOL_ID(e) != (uint8_t)0) {              // is it a dynamic event?
+        EVT_INC_REF_CTR(e);                 // increment the reference counter
     }
 
     if (m_eQueue.m_frontEvt == (QEvent *)0) {           // is the queue empty?
@@ -675,16 +704,14 @@
         QS_TIME_();                                               // timestamp
         QS_SIG_(e->sig);                           // the signal of this event
         QS_OBJ_(this);                                    // this queue object
-        QS_U8_(e->dynamic_);            // the dynamic attributes of the event
+        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_(m_nFree);                            // number of free entries
         QS_EQC_(m_nMin);                         // min number of free entries
     QS_END_NOLOCK_()
 
-    if (e->dynamic_ != (uint8_t)0) {                    // is it a pool event?
-        //lint -e1773                               Attempt to cast away const
-        ++((QEvent *)e)->dynamic_;          // increment the reference counter
-                   // NOTE: cast the 'const' away, which is legitimate because
-                   // it's a dynamic event
+    if (EVT_POOL_ID(e) != (uint8_t)0) {              // is it a dynamic event?
+        EVT_INC_REF_CTR(e);                 // increment the reference counter
     }
 
     if (m_frontEvt == (QEvent *)0) {                    // is the queue empty?
@@ -733,7 +760,8 @@
                 QS_TIME_();                                       // timestamp
                 QS_SIG_(e->sig);                   // the signal of this event
                 QS_OBJ_(this);                            // this queue object
-                QS_U8_(e->dynamic_);    // the dynamic attributes of the event
+                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_(m_nFree);                    // number of free entries
             QS_END_NOLOCK_()
         }
@@ -744,7 +772,8 @@
                 QS_TIME_();                                       // timestamp
                 QS_SIG_(e->sig);                   // the signal of this event
                 QS_OBJ_(this);                            // this queue object
-                QS_U8_(e->dynamic_);     // the dynamic attribute of the event
+                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_END_NOLOCK_()
         }
     }
@@ -778,16 +807,14 @@
         QS_TIME_();                                               // timestamp
         QS_SIG_(e->sig);                           // the signal of this event
         QS_OBJ_(this);                                    // this queue object
-        QS_U8_(e->dynamic_);             // the dynamic attribute of the event
+        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_(m_nFree);                            // number of free entries
         QS_EQC_(m_nMin);                         // min number of free entries
     QS_END_NOLOCK_()
 
-    if (e->dynamic_ != (uint8_t)0) {                 // is it a dynamic event?
-        //lint -e1773                               Attempt to cast away const
-        ++((QEvent *)e)->dynamic_;          // increment the reference counter
-                   // NOTE: cast the 'const' away, which is legitimate because
-                   // it's a dynamic event
+    if (EVT_POOL_ID(e) != (uint8_t)0) {              // is it a dynamic event?
+        EVT_INC_REF_CTR(e);                 // increment the reference counter
     }
 
     if (m_frontEvt != (QEvent *)0) {                // is the queue not empty?
@@ -821,12 +848,12 @@
 //lint -e970 -e971               ignore MISRA rules 13 and 14 in this function
 const char Q_ROM * Q_ROM_VAR QF::getVersion(void) {
     static char const Q_ROM Q_ROM_VAR version[] = {
-        ((QP_VERSION >> 12) & 0xF) + '0',
+        (char)(((QP_VERSION >> 12U) & 0xFU) + (uint8_t)'0'),
         '.',
-        ((QP_VERSION >>  8) & 0xF) + '0',
+        (char)(((QP_VERSION >>  8U) & 0xFU) + (uint8_t)'0'),
         '.',
-        ((QP_VERSION >>  4) & 0xF) + '0',
-        (QP_VERSION         & 0xF) + '0',
+        (char)(((QP_VERSION >>  4U) & 0xFU) + (uint8_t)'0'),
+        (char)((QP_VERSION          & 0xFU) + (uint8_t)'0'),
         '\0'
     };
     return version;
@@ -874,38 +901,41 @@
 
 // "qf_gc.cpp" ===============================================================
 void QF::gc(QEvent const *e) {
-    if (e->dynamic_ != (uint8_t)0) {                 // is it a dynamic event?
+    if (EVT_POOL_ID(e) != (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
+        if (EVT_REF_CTR(e) > (uint8_t)1) {   // isn't this the last reference?
+            EVT_DEC_REF_CTR(e);                   // decrement the ref counter
 
             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_U8_(EVT_POOL_ID(e));            // the pool Id of the event
+                QS_U8_(EVT_REF_CTR(e));          // the ref count 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);
+            uint8_t idx = (uint8_t)(EVT_POOL_ID(e) - 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_U8_(EVT_POOL_ID(e));            // the pool Id of the event
+                QS_U8_(EVT_REF_CTR(e));          // the ref count of the event
             QS_END_NOLOCK_()
 
             QF_INT_UNLOCK_();
 
             Q_ASSERT(idx < QF_maxPool_);
 
+#ifdef Q_EVT_CTOR
+            //lint -e1773                           Attempt to cast away const
+            ((QEvent *)e)->~QEvent();     // call the xtor, cast 'const' away,
+                             // which is legitimate, because it's a pool event
+#endif
             //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
@@ -936,10 +966,10 @@
 // "qf_new.cpp" ==============================================================
 QEvent *QF::new_(uint16_t evtSize, QSignal sig) {
                     // find the pool id that fits the requested event size ...
-    uint8_t id = (uint8_t)0;
-    while (evtSize > QF_EPOOL_EVENT_SIZE_(QF_pool_[id])) {
-        ++id;
-        Q_ASSERT(id < QF_maxPool_);      // cannot run out of registered pools
+    uint8_t idx = (uint8_t)0;
+    while (evtSize > QF_EPOOL_EVENT_SIZE_(QF_pool_[idx])) {
+        ++idx;
+        Q_ASSERT(idx < QF_maxPool_);     // cannot run out of registered pools
     }
 
     QS_INT_LOCK_KEY_
@@ -950,20 +980,19 @@
     QS_END_()
 
     QEvent *e;
-    QF_EPOOL_GET_(QF_pool_[id], e);
+    QF_EPOOL_GET_(QF_pool_[idx], e);
     Q_ASSERT(e != (QEvent *)0);             // pool must not run out of events
 
     e->sig = sig;                                 // set signal for this event
+    EVT_POOL_ID(e) = (uint8_t)(idx + 1);     // store the pool ID in the event
+    EVT_REF_CTR(e) = (uint8_t)0;             // set the reference counter to 0
 
-                                 // store the dynamic attributes of the event:
-                                 // the pool ID and the reference counter == 0
-    e->dynamic_ = (uint8_t)((id + 1) << 6);
     return e;
 }
 
 // "qf_pool.cpp" =============================================================
 // Package-scope objects -----------------------------------------------------
-QF_EPOOL_TYPE_ QF_pool_[3];                          // allocate 3 event pools
+QF_EPOOL_TYPE_ QF_pool_[QF_MAX_EPOOL];             // allocate the event pools
 uint8_t QF_maxPool_;                      // number of initialized event pools
 
 //............................................................................
@@ -989,7 +1018,11 @@
 }
 
 // "qf_pspub.cpp" ============================================================
+#ifndef Q_SPY
 void QF::publish(QEvent const *e) {
+#else
+void QF::publish(QEvent const *e, void const *sender) {
+#endif
          // make sure that the published signal is within the configured range
     Q_REQUIRE(e->sig < QF_maxSignal_);
 
@@ -998,15 +1031,14 @@
 
     QS_BEGIN_NOLOCK_(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_U8_(e->dynamic_);            // the dynamic attributes of the event
+        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_END_NOLOCK_()
 
-    if (e->dynamic_ != (uint8_t)0) {                 // is it a dynamic event?
-        //lint -e1773                               Attempt to cast away const
-        ++((QEvent *)e)->dynamic_;      // increment reference counter, NOTE01
-                   // NOTE: cast the 'const' away, which is legitimate because
-                   // it's a dynamic event */
+    if (EVT_POOL_ID(e) != (uint8_t)0) {              // is it a dynamic event?
+        EVT_INC_REF_CTR(e);         // increment the reference counter, NOTE01
     }
     QF_INT_UNLOCK_();
 
@@ -1017,7 +1049,8 @@
         tmp &= Q_ROM_BYTE(QF_invPwr2Lkup[p]);      // clear the subscriber bit
         Q_ASSERT(active_[p] != (QActive *)0);            // must be registered
 
-        active_[p]->postFIFO(e);  // internally asserts if the queue overflows
+                           // POST() asserts internally if the queue overflows
+        active_[p]->POST(e, sender);
     }
 #else
     uint8_t i = Q_DIM(QF_subscrList_[0].m_bits);// number of bytes in the list
@@ -1030,8 +1063,8 @@
             p = (uint8_t)(p + (i << 3));                // adjust the priority
             Q_ASSERT(active_[p] != (QActive *)0);        // must be registered
 
-                       // postFIFO() internally asserts if the queue overflows
-            active_[p]->postFIFO(e);
+                           // POST() asserts internally if the queue overflows
+            active_[p]->POST(e, sender);
         }
     } while (i != (uint8_t)0);
 #endif
@@ -1078,7 +1111,12 @@
 };
 
 // "qf_tick.cpp" =============================================================
+#ifndef Q_SPY
 void QF::tick(void) {                                            // see NOTE01
+#else
+void QF::tick(void const *sender) {
+#endif
+
     QF_INT_LOCK_KEY_
     QF_INT_LOCK_();
 
@@ -1120,8 +1158,8 @@
 
             QF_INT_UNLOCK_();   // unlock interrupts before calling QF service
 
-                  // postFIFO() asserts internally that the event was accepted
-            t->m_act->postFIFO(t);
+                           // POST() asserts internally if the queue overflows
+            t->m_act->POST(t, sender);
         }
         else {
             QF_INT_UNLOCK_();
@@ -1181,15 +1219,7 @@
               && ((QMPoolSize)(blockSize + (QMPoolSize)sizeof(QFreeBlock))
                     > blockSize));
 
-    //lint -e923                       ignore MISRA Rule 45 in this expression
-    uint32_t corr = ((uint32_t)poolSto
-                      & ((uint32_t)sizeof(QFreeBlock) - (uint32_t)1));
-    if (corr != (uint32_t)0) {                            // alignment needed?
-        corr = (uint32_t)sizeof(QFreeBlock) - corr; // amount to align poolSto
-        poolSize -= corr;                    // reduce the available pool size
-    }
-    //lint -e826   align the head of free list at the free block-size boundary
-    m_free = (void *)((uint8_t *)poolSto + corr);
+    m_free = poolSto;
 
                 // round up the blockSize to fit an integer number of pointers
     m_blockSize = (QMPoolSize)sizeof(QFreeBlock);       // start with just one
@@ -1283,15 +1313,43 @@
 
 // "qte_ctor.cpp" ============================================================
 QTimeEvt::QTimeEvt(QSignal s)
-    : m_prev((QTimeEvt *)0),
-      m_next((QTimeEvt *)0),
-      m_act((QActive *)0),
-      m_ctr((QTimeEvtCtr)0),
-      m_interval((QTimeEvtCtr)0)
+  :
+#ifdef Q_EVT_CTOR
+    QEvent(s),
+#endif
+    m_prev((QTimeEvt *)0),
+    m_next((QTimeEvt *)0),
+    m_act((QActive *)0),
+    m_ctr((QTimeEvtCtr)0),
+    m_interval((QTimeEvtCtr)0)
 {
     Q_REQUIRE(s >= (QSignal)Q_USER_SIG);                       // valid signal
     sig = s;
-    dynamic_ = (uint8_t)0;            // time event must be static, see NOTE01
+    EVT_POOL_ID(this) = (uint8_t)0;   // time event must be static, see NOTE01
+}
+
+// "qte_ctr.cpp" =============================================================
+QTimeEvtCtr QTimeEvt::ctr(void) {
+    QTimeEvtCtr ctr;
+    QF_INT_LOCK_KEY_
+    QF_INT_LOCK_();
+    if (m_prev != (QTimeEvt *)0) {        // is the time event actually armed?
+        ctr = m_ctr;
+    }
+    else {                                     // the time event was not armed
+        ctr = (QTimeEvtCtr)0;
+    }
+
+    QS_BEGIN_NOLOCK_(QS_QF_TIMEEVT_CTR, QS::teObj_, this)
+        QS_TIME_();                                               // timestamp
+        QS_OBJ_(this);                               // this time event object
+        QS_OBJ_(m_act);                                   // the active object
+        QS_TEC_(ctr);                                   // the current counter
+        QS_TEC_(m_interval);                                   // the interval
+    QS_END_NOLOCK_()
+
+    QF_INT_UNLOCK_();
+    return ctr;
 }
 
 // "qte_darm.cpp" ============================================================
@@ -1418,27 +1476,45 @@
 #endif
 
 // "qk.cpp" ==================================================================
+#ifdef Q_USE_NAMESPACE
+}                                                              // namespace QP
+#endif
+
 // Public-scope objects ------------------------------------------------------
-#if (QF_MAX_ACTIVE <= 8)
+extern "C" {
+#if (QF_MAX_ACTIVE <= 8U)
+#ifdef Q_USE_NAMESPACE
+    QP::QPSet8  volatile QK_readySet_;                      // ready set of QK
+#else
     QPSet8  volatile QK_readySet_;                          // ready set of QK
+#endif
+#else
+#ifdef Q_USE_NAMESPACE
+    QP::QPSet64 volatile QK_readySet_;                      // ready set of QK
 #else
     QPSet64 volatile QK_readySet_;                          // ready set of QK
 #endif
+#endif
                                          // start with the QK scheduler locked
 uint8_t volatile QK_currPrio_ = (uint8_t)(QF_MAX_ACTIVE + 1);
 uint8_t volatile QK_intNest_;                 // start with nesting level of 0
 
+}                                                                // extern "C"
+
+#ifdef Q_USE_NAMESPACE
+namespace QP {
+#endif
 
 //............................................................................
 //lint -e970 -e971               ignore MISRA rules 13 and 14 in this function
 char const Q_ROM * Q_ROM_VAR QK::getVersion(void) {
     static char const Q_ROM Q_ROM_VAR version[] = {
-        ((QP_VERSION >> 12) & 0xF) + '0',
+        (char)(((QP_VERSION >> 12U) & 0xFU) + (uint8_t)'0'),
         '.',
-        ((QP_VERSION >>  8) & 0xF) + '0',
+        (char)(((QP_VERSION >>  8U) & 0xFU) + (uint8_t)'0'),
         '.',
-        ((QP_VERSION >>  4) & 0xF) + '0',
-        (QP_VERSION         & 0xF) + '0',
+        (char)(((QP_VERSION >>  4U) & 0xFU) + (uint8_t)'0'),
+        (char)((QP_VERSION          & 0xFU) + (uint8_t)'0'),
         '\0'
     };
     return version;
@@ -1496,13 +1572,26 @@
 }
 
 // "qk_sched" ================================================================
+
+#ifdef Q_USE_NAMESPACE
+}                                                              // namespace QP
+#endif
+
 //............................................................................
-// NOTE: the QK scheduler is entered and exited with interrupts LOCKED
+// NOTE: the QK scheduler is entered and exited with interrupts LOCKED.
+// QK_schedule_() is extern "C", so it does not belong to the QP namespace.
+//
+extern "C" {
+
 #ifndef QF_INT_KEY_TYPE
 void QK_schedule_(void) {
 #else
 void QK_schedule_(QF_INT_KEY_TYPE intLockKey_) {
 #endif
+
+#ifdef Q_USE_NAMESPACE
+    using namespace QP;
+#endif
                          // the QK scheduler must be called at task level only
     Q_REQUIRE(QK_intNest_ == (uint8_t)0);
 
@@ -1566,6 +1655,12 @@
     }
 }
 
+}                                                                // extern "C"
+
+#ifdef Q_USE_NAMESPACE
+namespace QP {
+#endif
+
 // "qk_mutex.cpp" ============================================================
 #ifndef QK_NO_MUTEX
 
@@ -1790,12 +1885,12 @@
 //lint -e970 -e971               ignore MISRA rules 13 and 14 in this function
 char const Q_ROM * Q_ROM_VAR QS::getVersion(void) {
     static char const Q_ROM Q_ROM_VAR version[] = {
-        ((QP_VERSION >> 12) & 0xF) + '0',
+        (char)(((QP_VERSION >> 12U) & 0xFU) + (uint8_t)'0'),
         '.',
-        ((QP_VERSION >>  8) & 0xF) + '0',
+        (char)(((QP_VERSION >>  8U) & 0xFU) + (uint8_t)'0'),
         '.',
-        ((QP_VERSION >>  4) & 0xF) + '0',
-        (QP_VERSION         & 0xF) + '0',
+        (char)(((QP_VERSION >>  4U) & 0xFU) + (uint8_t)'0'),
+        (char)((QP_VERSION          & 0xFU) + (uint8_t)'0'),
         '\0'
     };
     return version;
@@ -2062,6 +2157,37 @@
     QS_INSERT_BYTE((uint8_t)0)
 }
 
+// "qs_u64.cpp" ==============================================================
+#if (QS_OBJ_PTR_SIZE == 8) || (QS_FUN_PTR_SIZE == 8)
+
+//............................................................................
+void QS::u64_(uint64_t d) {
+    QS_INSERT_ESC_BYTE((uint8_t)d)
+    d >>= 8;
+    QS_INSERT_ESC_BYTE((uint8_t)d)
+    d >>= 8;
+    QS_INSERT_ESC_BYTE((uint8_t)d)
+    d >>= 8;
+    QS_INSERT_ESC_BYTE((uint8_t)d)
+    d >>= 8;
+    QS_INSERT_ESC_BYTE((uint8_t)d)
+    d >>= 8;
+    QS_INSERT_ESC_BYTE((uint8_t)d)
+    d >>= 8;
+    QS_INSERT_ESC_BYTE((uint8_t)d)
+    d >>= 8;
+    QS_INSERT_ESC_BYTE((uint8_t)d)
+}
+//............................................................................
+void QS::u64(uint8_t format, uint64_t d) {
+    QS_INSERT_ESC_BYTE(format)
+    u64_(d);
+}
+
+#endif
+
 #endif                                                                // Q_SPY
 
-
+#ifdef Q_USE_NAMESPACE
+}                                                              // namespace QP
+#endif