34#define QP_VERSION_STR "8.0.2"
35#define QP_VERSION 802U
37#define QP_RELEASE 0x6AEAB45DU
44#define Q_SIGNAL_SIZE 2U
48#define QF_MAX_ACTIVE 32U
51#if (QF_MAX_ACTIVE > 64U)
52#error QF_MAX_ACTIVE exceeds the maximum of 64U;
55#ifndef QF_MAX_TICK_RATE
56#define QF_MAX_TICK_RATE 1U
59#if (QF_MAX_TICK_RATE > 15U)
60#error QF_MAX_TICK_RATE exceeds the maximum of 15U;
64#define QF_MAX_EPOOL 3U
67#if (QF_MAX_EPOOL > 15U)
68#error QF_MAX_EPOOL exceeds the maximum of 15U;
71#ifndef QF_TIMEEVT_CTR_SIZE
72#define QF_TIMEEVT_CTR_SIZE 4U
75#if (QF_TIMEEVT_CTR_SIZE > 4U)
76#error QF_TIMEEVT_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U;
79#ifndef QF_EVENT_SIZ_SIZE
80#define QF_EVENT_SIZ_SIZE 2U
83#if (QF_EVENT_SIZ_SIZE > 4U)
84#error QF_EVENT_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U;
97#define Q_UNUSED_PAR(par_) ((void)(par_))
98#define Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0U]))
99#define Q_UINT2PTR_CAST(type_, uint_) ((type_ *)(uint_))
105#if (Q_SIGNAL_SIZE == 1U)
107#elif (Q_SIGNAL_SIZE == 2U)
109#elif (Q_SIGNAL_SIZE == 4U)
121#define QEVT_INITIALIZER(sig_) { (QSignal)(sig_), 0x00U, 0xE0U }
141#define QEVT_DYNAMIC ((uint8_t)0)
142#define Q_EVT_CAST(class_) ((class_ const *)(e))
175#define Q_STATE_CAST(handler_) ((QStateHandler)(handler_))
176#define Q_ACTION_CAST(action_) ((QActionHandler)(action_))
177#define Q_ACTION_NULL ((QActionHandler)0)
189#define Q_RET_SUPER ((QState)0U)
190#define Q_RET_UNHANDLED ((QState)1U)
193#define Q_RET_HANDLED ((QState)2U)
194#define Q_RET_IGNORED ((QState)3U)
197#define Q_RET_ENTRY ((QState)4U)
198#define Q_RET_EXIT ((QState)5U)
201#define Q_RET_NULL ((QState)6U)
204#define Q_RET_TRAN ((QState)7U)
205#define Q_RET_TRAN_INIT ((QState)8U)
208#define Q_RET_TRAN_HIST ((QState)9U)
211#define Q_EMPTY_SIG ((QSignal)0U)
212#define Q_ENTRY_SIG ((QSignal)1U)
213#define Q_EXIT_SIG ((QSignal)2U)
214#define Q_INIT_SIG ((QSignal)3U)
215#define Q_USER_SIG ((enum_t)4)
225 void (*
init)(
QAsm *
const me,
void const *
const e,
226 uint_fast8_t
const qsId);
228 uint_fast8_t
const qsId);
236 #define QASM_INIT(me_, par_, qsId_) \
237 (*((QAsm *)(me_))->vptr->init)((QAsm *)(me_), (par_), (qsId_))
238 #define QASM_DISPATCH(me_, e_, qsId_) \
239 (*((QAsm *)(me_))->vptr->dispatch)((QAsm *)(me_), (e_), (qsId_))
240 #define QASM_IS_IN(me_, state_) \
241 (*((QAsm *)(me_))->vptr->isIn)((QAsm *)(me_), (state_))
243 #define QASM_INIT(me_, par_, dummy) \
244 (*((QAsm *)(me_))->vptr->init)((QAsm *)(me_), (par_), 0U)
245 #define QASM_DISPATCH(me_, e_, dummy) \
246 (*((QAsm *)(me_))->vptr->dispatch)((QAsm *)(me_), (e_), 0U)
249#define Q_ASM_UPCAST(ptr_) ((QAsm *)(ptr_))
259void QHsm_ctor(
QHsm *
const me,
265 void const *
const e,
266 uint_fast8_t
const qsId);
271 QEvt const *
const e,
272 uint_fast8_t
const qsId);
286 QEvt const *
const e);
297#define Q_HSM_UPCAST(ptr_) ((QHsm *)(ptr_))
299#define Q_TRAN(target_) \
300 ((Q_ASM_UPCAST(me))->temp.fun = Q_STATE_CAST(target_), \
302#define Q_TRAN_HIST(hist_) \
303 ((Q_ASM_UPCAST(me))->temp.fun = (hist_), \
304 (QState)Q_RET_TRAN_HIST)
305#define Q_SUPER(super_) \
306 ((Q_ASM_UPCAST(me))->temp.fun = Q_STATE_CAST(super_), \
308#define Q_HANDLED() ((QState)Q_RET_HANDLED)
309#define Q_UNHANDLED() ((QState)Q_RET_UNHANDLED)
319void QMsm_ctor(
QMsm *
const me,
325 void const *
const e,
326 uint_fast8_t
const qsId);
331 QEvt const *
const e,
332 uint_fast8_t
const qsId);
350QMState const * QMsm_childStateObj(
QMsm const *
const me,
355#define Q_MSM_UPCAST(ptr_) ((QMsm *)(ptr_))
357 #define QM_ENTRY(state_) \
358 ((Q_ASM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_ENTRY)
359 #define QM_EXIT(state_) \
360 ((Q_ASM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_EXIT)
362 #define QM_ENTRY(dummy) ((QState)Q_RET_ENTRY)
363 #define QM_EXIT(dummy) ((QState)Q_RET_EXIT)
366#define QM_TRAN(tatbl_) ((Q_ASM_UPCAST(me))->temp.tatbl \
367 = (struct QMTranActTable const *)(tatbl_), (QState)Q_RET_TRAN)
369#define QM_TRAN_INIT(tatbl_) ((Q_ASM_UPCAST(me))->temp.tatbl \
370 = (struct QMTranActTable const *)(tatbl_), (QState)Q_RET_TRAN_INIT)
372#define QM_TRAN_HIST(history_, tatbl_) \
373 ((((Q_ASM_UPCAST(me))->state.obj = (history_)), \
374 ((Q_ASM_UPCAST(me))->temp.tatbl = \
375 (struct QMTranActTable const *)(tatbl_))), (QState)Q_RET_TRAN_HIST)
377#define QM_HANDLED() ((QState)Q_RET_HANDLED)
378#define QM_UNHANDLED() ((QState)Q_RET_UNHANDLED)
379#define QM_SUPER() ((QState)Q_RET_SUPER)
380#define QM_STATE_NULL ((QMState *)0)
387#if (QF_TIMEEVT_CTR_SIZE == 1U)
389#elif (QF_TIMEEVT_CTR_SIZE == 2U)
391#elif (QF_TIMEEVT_CTR_SIZE == 4U)
395#if (QF_MAX_ACTIVE <= 8U)
397#elif (8U < QF_MAX_ACTIVE) && (QF_MAX_ACTIVE <= 16U)
399#elif (16U < QF_MAX_ACTIVE)
418#if (QF_MAX_ACTIVE > 32)
425#if (QF_MAX_ACTIVE <= 32U)
426 return (me->
bits[0] == 0U);
428 return (me->
bits[0] == 0U) ? (me->
bits[1] == 0U) :
false;
434#if (QF_MAX_ACTIVE <= 32U)
435 return (me->
bits[0] != 0U);
437 return (me->
bits[0] != 0U) ? true : (me->
bits[1] != 0U);
443 uint_fast8_t
const n)
445#if (QF_MAX_ACTIVE <= 32U)
456 uint_fast8_t
const n)
458#if (QF_MAX_ACTIVE <= 32U)
472 uint_fast8_t
const n)
474#if (QF_MAX_ACTIVE <= 32U)
488#if (QF_MAX_ACTIVE <= 32U)
491 return (me->
bits[1] != 0U)
512#ifdef QACTIVE_THREAD_TYPE
516#ifdef QACTIVE_OS_OBJ_TYPE
520#ifdef QACTIVE_EQUEUE_TYPE
547 uint_fast16_t
const qLen,
549 uint_fast16_t
const stkSize,
550 void const *
const par);
552#ifdef QACTIVE_CAN_STOP
565 QEvt const *
const e,
566 uint_fast16_t
const margin,
567 void const *
const sender);
571 QEvt const *
const e);
583 QEvt const *
const e,
584 void const *
const sender,
585 uint_fast8_t
const qsId);
601 QEvt const *
const e);
610 uint_fast16_t
const num);
623void QMActive_ctor(
QMActive *
const me,
648 uint32_t
const nTicks,
656 uint32_t
const nTicks);
670 void const *
const sender);
682 void const *
const sender);
699void QTicker_ctor(
QTicker *
const me,
700 uint_fast8_t
const tickRate);
705 void const *
const par,
706 uint_fast8_t
const qsId);
709void QTicker_dispatch_(
711 QEvt const *
const e,
712 uint_fast8_t
const qsId);
717 void const *
const sender);
732uint_fast16_t QF_getQueueMin(uint_fast8_t
const prio);
740#ifdef QF_ON_CONTEXT_SW
747#define Q_PRIO(prio_, pthre_) ((QPrioSpec)((prio_) | ((pthre_) << 8U)))
748#define QF_NO_MARGIN ((uint_fast16_t)0xFFFFU)
755 void *
const poolSto,
756 uint_fast32_t
const poolSize,
757 uint_fast16_t
const evtSize);
767 uint_fast16_t
const evtSize,
768 uint_fast16_t
const margin,
776 QEvt const *
const e,
777 void const *
const evtRef);
786 #define Q_NEW(evtT_, sig_, ...) \
787 (evtT_##_init((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
788 QF_NO_MARGIN, (sig_)), __VA_ARGS__))
789 #define Q_NEW_X(evtT_, margin_, sig_, ...) \
790 (evtT_##_init((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
791 (margin_), (sig_)), __VA_ARGS__))
793 #define Q_NEW(evtT_, sig_) \
794 ((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
795 QF_NO_MARGIN, (enum_t)(sig_)))
796 #define Q_NEW_X(evtT_, margin_, sig_) \
797 ((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
798 (margin_), (enum_t)(sig_)))
801#define Q_NEW_REF(evtRef_, evtT_) \
802 ((evtRef_) = (evtT_ const *)QF_newRef_(e, (evtRef_)))
803#define Q_DELETE_REF(evtRef_) do { \
804 QF_deleteRef_((evtRef_)); \
805 (evtRef_) = (void *)0; \
809 #define QACTIVE_POST(me_, e_, sender_) \
810 ((void)QActive_post_((me_), (e_), QF_NO_MARGIN, (sender_)))
811 #define QACTIVE_POST_X(me_, e_, margin_, sender_) \
812 (QActive_post_((me_), (e_), (margin_), (sender_)))
813 #define QACTIVE_PUBLISH(e_, sender_) \
814 (QActive_publish_((e_), (void const *)(sender_), (sender_)->prio))
815 #define QTIMEEVT_TICK_X(tickRate_, sender_) (QTimeEvt_tick_((tickRate_), (sender_)))
816 #define QTICKER_TRIG(ticker_, sender_) (QTicker_trig_((ticker_), (sender_)))
818 #define QACTIVE_POST(me_, e_, dummy) \
819 ((void)QActive_post_((me_), (e_), QF_NO_MARGIN, (void *)0))
820 #define QACTIVE_POST_X(me_, e_, margin_, dummy) \
821 (QActive_post_((me_), (e_), (margin_), (void *)0))
822 #define QACTIVE_PUBLISH(e_, dummy) (QActive_publish_((e_), (void *)0, 0U))
823 #define QTIMEEVT_TICK_X(tickRate_, dummy) (QTimeEvt_tick_((tickRate_), (void *)0))
824 #define QTICKER_TRIG(ticker_, sender_) (QTicker_trig_((ticker_), (void *)0))
827#define QACTIVE_POST_LIFO(me_, e_) (QActive_postLIFO_((me_), (e_)))
828#define QTIMEEVT_TICK(sender_) QTIMEEVT_TICK_X(0U, (sender_))
830#ifndef QF_CRIT_EXIT_NOP
831 #define QF_CRIT_EXIT_NOP() ((void)0)
838 #error Memory isolation not supported in this QP edition, need SafeQP
void QF_poolInit(void *const poolSto, uint_fast32_t const poolSize, uint_fast16_t const evtSize)
void QF_gc(QEvt const *const e)
uint_fast16_t QF_poolGetMaxBlockSize(void)
uint_fast16_t QF_getPoolMin(uint_fast8_t const poolNum)
void QF_onContextSw(QActive *prev, QActive *next)
QEvt * QF_newX_(uint_fast16_t const evtSize, uint_fast16_t const margin, enum_t const sig)
void QF_gcFromISR(QEvt const *const e)
void QF_deleteRef_(void const *const evtRef)
QEvt const * QF_newRef_(QEvt const *const e, void const *const evtRef)
eXtended (blocking) thread of the QXK preemptive kernel
#define Q_UNUSED_PAR(par_)
Helper macro to clearly mark unused parameters of functions.
float float32_t
Alias for IEEE 754 32-bit floating point number.
void(* QXThreadHandler)(struct QXThread *const me)
Pointer to an extended-thread handler function.
uint32_t QPSetBits
Bitmask for the internal representation of QPSet elements.
QState(* QStateHandler)(void *const me, QEvt const *const e)
Pointer to a state-handler function.
QEvt const * QEvtPtr
Pointer to const event instances passed around in QP Framework.
uint32_t QTimeEvtCtr
Data type to store the block-size defined based on the macro QF_TIMEEVT_CTR_SIZE.
uint_fast8_t QF_LOG2(QPSetBits const bitmask)
Log-base-2 calculation when hardware acceleration is NOT provided (QF_LOG2 not defined)
int int_t
Alias for assertion-ID numbers in QP assertions and return from QF_run()
double float64_t
Alias for IEEE 754 64-bit floating point number.
uint_fast8_t QState
Type returned from state-handler functions.
char const QP_versionStr[24]
QState(* QActionHandler)(void *const me)
Pointer to an action-handler function.
uint16_t QSignal
The signal of event QEvt.
uint16_t QPrioSpec
Priority specification for Active Objects in QP.
#define QF_MAX_TICK_RATE
Maximum # clock tick rates in the system (0..15)
#define QF_MAX_ACTIVE
Maximum # Active Objects in the system (1..64)
#define QACTIVE_OS_OBJ_TYPE
QActive "OS-object" type used in various QP/C ports.
#define QACTIVE_EQUEUE_TYPE
QActive event queue type used in various QP/C ports.
#define QACTIVE_THREAD_TYPE
QActive "thread" type used in various QP/C ports.
Active object class (based on the QHsm implementation strategy)
QSubscrList * QActive_subscrList_
Static (one per-class) pointer to all subscriber AOs for a given event signal.
void QActive_unsubscribe(QActive const *const me, enum_t const sig)
void QActive_unregister_(QActive *const me)
QACTIVE_THREAD_TYPE thread
Port-dependent representation of the thread of the active object.
bool QActive_post_(QActive *const me, QEvt const *const e, uint_fast16_t const margin, void const *const sender)
QEvt const * QActive_get_(QActive *const me)
void QActive_postLIFO_(QActive *const me, QEvt const *const e)
void QActive_ctor(QActive *const me, QStateHandler const initial)
bool QActive_defer(QActive const *const me, struct QEQueue *const eq, QEvt const *const e)
void QActive_setAttr(QActive *const me, uint32_t attr1, void const *attr2)
enum_t QActive_maxPubSignal_
Static (one per-class) maximum published signal (the size of the subscrList_ array)
QACTIVE_OS_OBJ_TYPE osObject
Port-dependent per-thread object.
bool QActive_recall(QActive *const me, struct QEQueue *const eq)
QACTIVE_EQUEUE_TYPE eQueue
Port-dependent event-queue type (often QEQueue)
void QActive_publish_(QEvt const *const e, void const *const sender, uint_fast8_t const qsId)
void QActive_stop(QActive *const me)
void QActive_register_(QActive *const me)
QActive * QActive_registry_[QF_MAX_ACTIVE+1U]
Static (one per-class) array of registered active objects.
uint8_t prio
QF-priority [1..QF_MAX_ACTIVE] of this AO.
void QActive_subscribe(QActive const *const me, enum_t const sig)
void QActive_start(QActive *const me, QPrioSpec const prioSpec, QEvtPtr *const qSto, uint_fast16_t const qLen, void *const stkSto, uint_fast16_t const stkSize, void const *const par)
uint_fast16_t QActive_flushDeferred(QActive const *const me, struct QEQueue *const eq, uint_fast16_t const num)
void QActive_unsubscribeAll(QActive const *const me)
void QActive_psInit(QSubscrList *const subscrSto, enum_t const maxSignal)
uint8_t pthre
Preemption-threshold [1..QF_MAX_ACTIVE] of this AO.
void QActive_evtLoop_(QActive *const me)
Abstract State Machine class (state machine interface)
struct QAsmVtable const * vptr
Virtual pointer inherited by all QAsm subclasses (see also Object Orientation)
union QAsmAttr state
Current state (pointer to the current state-handler function)
union QAsmAttr temp
Temporary storage for target/act-table etc.
static void QAsm_ctor(QAsm *const me)
Virtual table for the QAsm class.
void(* init)(QAsm *const me, void const *const e, uint_fast8_t const qsId)
Virtual function to take the top-most initial transition in the state machine.
bool(* isIn)(QAsm *const me, QStateHandler const s)
Virtual function to check whether the state machine is in a given state.
QStateHandler(* getStateHandler)(QAsm *const me)
Virtual function to get the current state handler of the state machine.
void(* dispatch)(QAsm *const me, QEvt const *const e, uint_fast8_t const qsId)
Virtual function to dispatch an event to the state machine.
QSignal sig
Signal of the event (see Event Signal)
static QEvt * QEvt_init(QEvt *const me, uint8_t const dummy)
uint8_t volatile refCtr_
Event reference counter.
static void QEvt_ctor(QEvt *const me, enum_t const sig)
Hierarchical State Machine class (QHsm-style state machine implementation strategy)
static QStateHandler QHsm_state(QHsm const *const me)
Active object class (based on QMsm implementation strategy)
State object for the QMsm class (QM State Machine)
struct QMState const * superstate
QActionHandler const entryAction
QActionHandler const initAction
QActionHandler const exitAction
QStateHandler const stateHandler
Transition-Action Table for the QMsm State Machine.
QActionHandler const act[1]
Hierarchical State Machine class (QMsm-style state machine implementation strategy)
static QMState const * QMsm_stateObj(QMsm const *const me)
Set of Active Objects of up to QF_MAX_ACTIVE elements.
static uint_fast8_t QPSet_findMax(QPSet const *const me)
static bool QPSet_notEmpty(QPSet const *const me)
static bool QPSet_hasElement(QPSet const *const me, uint_fast8_t const n)
static void QPSet_setEmpty(QPSet *const me)
static void QPSet_insert(QPSet *const me, uint_fast8_t const n)
QPSetBits bits[((QF_MAX_ACTIVE+(8U *sizeof(QPSetBits))) - 1U)/(8U *sizeof(QPSetBits))]
Bitmask with a bit for each element.
static void QPSet_remove(QPSet *const me, uint_fast8_t const n)
static bool QPSet_isEmpty(QPSet const *const me)
Subscriber List (for publish-subscribe)
QPSet set
The set of AOs that subscribed to a given event signal.
"Ticker" Active Object class
void QTimeEvt_ctorX(QTimeEvt *const me, QActive *const act, enum_t const sig, uint_fast8_t const tickRate)
struct QTimeEvt *volatile next
Link to the next time event in the list.
QTimeEvtCtr volatile ctr
Down-counter of the time event.
bool QTimeEvt_noActive(uint_fast8_t const tickRate)
void QTimeEvt_tick1_(uint_fast8_t const tickRate, void const *const sender)
void QTimeEvt_armX(QTimeEvt *const me, uint32_t const nTicks, uint32_t const interval)
void QTimeEvt_tick_(uint_fast8_t const tickRate, void const *const sender)
QTimeEvt * QTimeEvt_expire_(QTimeEvt *const me, QTimeEvt *const prev_link, QActive const *const act, uint_fast8_t const tickRate)
QTimeEvtCtr interval
Interval for periodic time event (zero for one-shot time event)
QTimeEvtCtr QTimeEvt_currCtr(QTimeEvt const *const me)
QTimeEvt QTimeEvt_timeEvtHead_[QF_MAX_TICK_RATE]
Array of heads of linked lists of time events (one for every clock tick rate)
bool QTimeEvt_rearm(QTimeEvt *const me, uint32_t const nTicks)
bool QTimeEvt_wasDisarmed(QTimeEvt *const me)
bool QTimeEvt_disarm(QTimeEvt *const me)
void * act
Active object that receives the time events.
Attribute of for the QAsm class (Abstract State Machine)
QMTranActTable const * tatbl
struct QMState const * obj