33#define QP_VERSION_STR "8.0.4"
34#define QP_VERSION 804U
36#define QP_RELEASE 0x6A9FC8ABU
43#define Q_SIGNAL_SIZE 2U
47#define QF_MAX_ACTIVE 32U
50#if (QF_MAX_ACTIVE > 64U)
51#error QF_MAX_ACTIVE exceeds the maximum of 64U;
54#ifndef QF_MAX_TICK_RATE
55#define QF_MAX_TICK_RATE 1U
58#if (QF_MAX_TICK_RATE > 15U)
59#error QF_MAX_TICK_RATE exceeds the maximum of 15U;
63#define QF_MAX_EPOOL 3U
66#if (QF_MAX_EPOOL > 15U)
67#error QF_MAX_EPOOL exceeds the maximum of 15U;
70#ifndef QF_TIMEEVT_CTR_SIZE
71#define QF_TIMEEVT_CTR_SIZE 4U
74#if (QF_TIMEEVT_CTR_SIZE > 4U)
75#error QF_TIMEEVT_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U;
78#ifndef QF_EVENT_SIZ_SIZE
79#define QF_EVENT_SIZ_SIZE 2U
82#if (QF_EVENT_SIZ_SIZE > 4U)
83#error QF_EVENT_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U;
94#define Q_UNUSED_PAR(par_) ((void)(par_))
95#define Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0U]))
96#define Q_UINT2PTR_CAST(type_, uint_) ((type_ *)(uint_))
102#if (Q_SIGNAL_SIZE == 1U)
104#elif (Q_SIGNAL_SIZE == 2U)
106#elif (Q_SIGNAL_SIZE == 4U)
118#define QEVT_INITIALIZER(sig_) { (QSignal)(sig_), 0x00U, 0xE0U }
138#define QEVT_DYNAMIC ((uint8_t)0)
139#define Q_EVT_CAST(class_) ((class_ const *)(e))
173#define Q_STATE_CAST(handler_) ((QStateHandler)(handler_))
174#define Q_ACTION_CAST(action_) ((QActionHandler)(action_))
175#define Q_ACTION_NULL ((QActionHandler)0)
187#define Q_RET_SUPER ((QState)0U)
188#define Q_RET_UNHANDLED ((QState)1U)
191#define Q_RET_HANDLED ((QState)2U)
192#define Q_RET_IGNORED ((QState)3U)
195#define Q_RET_ENTRY ((QState)4U)
196#define Q_RET_EXIT ((QState)5U)
199#define Q_RET_NULL ((QState)6U)
202#define Q_RET_TRAN ((QState)7U)
203#define Q_RET_TRAN_INIT ((QState)8U)
206#define Q_RET_TRAN_HIST ((QState)9U)
209#define Q_EMPTY_SIG ((QSignal)0U)
210#define Q_ENTRY_SIG ((QSignal)1U)
211#define Q_EXIT_SIG ((QSignal)2U)
212#define Q_INIT_SIG ((QSignal)3U)
213#define Q_USER_SIG ((enum_t)4)
223 void (*
init)(
QAsm *
const me,
void const *
const e,
224 uint_fast8_t
const qsId);
226 uint_fast8_t
const qsId);
234 #define QASM_INIT(me_, par_, qsId_) \
235 (*((QAsm *)(me_))->vptr->init)((QAsm *)(me_), (par_), (qsId_))
236 #define QASM_DISPATCH(me_, e_, qsId_) \
237 (*((QAsm *)(me_))->vptr->dispatch)((QAsm *)(me_), (e_), (qsId_))
238 #define QASM_IS_IN(me_, stateHndl_) \
239 (*((QAsm *)(me_))->vptr->isIn)((QAsm *)(me_), (stateHndl_))
241 #define QASM_INIT(me_, par_, dummy) \
242 (*((QAsm *)(me_))->vptr->init)((QAsm *)(me_), (par_), 0U)
243 #define QASM_DISPATCH(me_, e_, dummy) \
244 (*((QAsm *)(me_))->vptr->dispatch)((QAsm *)(me_), (e_), 0U)
247#define Q_ASM_UPCAST(ptr_) ((QAsm *)(ptr_))
257void QHsm_ctor(
QHsm *
const me,
263 void const *
const e,
264 uint_fast8_t
const qsId);
269 QEvt const *
const e,
270 uint_fast8_t
const qsId);
284 QEvt const *
const e);
295#define Q_HSM_UPCAST(ptr_) ((QHsm *)(ptr_))
297#define Q_TRAN(target_) \
298 ((Q_ASM_UPCAST(me))->temp.fun = Q_STATE_CAST(target_), \
300#define Q_TRAN_HIST(hist_) \
301 ((Q_ASM_UPCAST(me))->temp.fun = (hist_), \
302 (QState)Q_RET_TRAN_HIST)
303#define Q_SUPER(super_) \
304 ((Q_ASM_UPCAST(me))->temp.fun = Q_STATE_CAST(super_), \
306#define Q_HANDLED() ((QState)Q_RET_HANDLED)
307#define Q_UNHANDLED() ((QState)Q_RET_UNHANDLED)
323 void const *
const e,
324 uint_fast8_t
const qsId);
329 QEvt const *
const e,
330 uint_fast8_t
const qsId);
348QMState const * QMsm_childStateObj(
QMsm const *
const me,
353#define Q_MSM_UPCAST(ptr_) ((QMsm *)(ptr_))
355 #define QM_ENTRY(state_) \
356 ((Q_ASM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_ENTRY)
357 #define QM_EXIT(state_) \
358 ((Q_ASM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_EXIT)
360 #define QM_ENTRY(dummy) ((QState)Q_RET_ENTRY)
361 #define QM_EXIT(dummy) ((QState)Q_RET_EXIT)
364#define QM_TRAN(tatbl_) ((Q_ASM_UPCAST(me))->temp.tatbl \
365 = (struct QMTranActTable const *)(tatbl_), (QState)Q_RET_TRAN)
367#define QM_TRAN_INIT(tatbl_) ((Q_ASM_UPCAST(me))->temp.tatbl \
368 = (struct QMTranActTable const *)(tatbl_), (QState)Q_RET_TRAN_INIT)
370#define QM_TRAN_HIST(history_, tatbl_) \
371 ((((Q_ASM_UPCAST(me))->state.obj = (history_)), \
372 ((Q_ASM_UPCAST(me))->temp.tatbl = \
373 (struct QMTranActTable const *)(tatbl_))), (QState)Q_RET_TRAN_HIST)
375#define QM_HANDLED() ((QState)Q_RET_HANDLED)
376#define QM_UNHANDLED() ((QState)Q_RET_UNHANDLED)
377#define QM_SUPER() ((QState)Q_RET_SUPER)
378#define QM_STATE_NULL ((QMState *)0)
385#if (QF_TIMEEVT_CTR_SIZE == 1U)
387#elif (QF_TIMEEVT_CTR_SIZE == 2U)
389#elif (QF_TIMEEVT_CTR_SIZE == 4U)
393#if (QF_MAX_ACTIVE <= 8U)
395#elif (8U < QF_MAX_ACTIVE) && (QF_MAX_ACTIVE <= 16U)
397#elif (16U < QF_MAX_ACTIVE)
416#if (QF_MAX_ACTIVE > 32)
423#if (QF_MAX_ACTIVE <= 32U)
424 return (me->
bits[0] == 0U);
426 return (me->
bits[0] == 0U) ? (me->
bits[1] == 0U) :
false;
432#if (QF_MAX_ACTIVE <= 32U)
433 return (me->
bits[0] != 0U);
435 return (me->
bits[0] != 0U) ? true : (me->
bits[1] != 0U);
441 uint_fast8_t
const n)
443#if (QF_MAX_ACTIVE <= 32U)
454 uint_fast8_t
const n)
456#if (QF_MAX_ACTIVE <= 32U)
470 uint_fast8_t
const n)
472#if (QF_MAX_ACTIVE <= 32U)
486#if (QF_MAX_ACTIVE <= 32U)
489 return (me->
bits[1] != 0U)
510#ifdef QACTIVE_THREAD_TYPE
514#ifdef QACTIVE_OS_OBJ_TYPE
518#ifdef QACTIVE_EQUEUE_TYPE
536 uint_fast16_t
const qLen,
538 uint_fast16_t
const stkSize,
539 void const *
const par);
541#ifdef QACTIVE_CAN_STOP
554 QEvt const *
const e,
555 uint_fast16_t
const margin,
556 void const *
const sender);
560 QEvt const *
const e);
572 QEvt const *
const e,
573 void const *
const sender,
574 uint_fast8_t
const qsId);
593 QEvt const *
const e);
602 uint_fast16_t
const num);
615void QMActive_ctor(
QMActive *
const me,
640 uint32_t
const nTicks,
648 uint32_t
const nTicks);
662 void const *
const sender);
674 void const *
const sender);
688void QTicker_ctor(
QTicker *
const me,
689 uint_fast8_t
const tickRate);
694 void const *
const par,
695 uint_fast8_t
const qsId);
698void QTicker_dispatch_(
700 QEvt const *
const e,
701 uint_fast8_t
const qsId);
706 void const *
const sender);
726#ifdef QF_ON_CONTEXT_SW
733#define Q_PRIO(prio_, pthre_) ((QPrioSpec)((prio_) | ((pthre_) << 8U)))
734#define QF_NO_MARGIN ((uint_fast16_t)0xFFFFU)
741 void *
const poolSto,
742 uint_fast32_t
const poolSize,
743 uint_fast16_t
const evtSize);
753 uint_fast16_t
const evtSize,
754 uint_fast16_t
const margin,
762 QEvt const *
const e,
763 void const *
const evtRef);
772 #define Q_NEW(evtT_, sig_, ...) \
773 (evtT_##_init((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
774 QF_NO_MARGIN, (sig_)), __VA_ARGS__))
775 #define Q_NEW_X(evtT_, margin_, sig_, ...) \
776 (evtT_##_init((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
777 (margin_), (sig_)), __VA_ARGS__))
779 #define Q_NEW(evtT_, sig_) \
780 ((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
781 QF_NO_MARGIN, (enum_t)(sig_)))
782 #define Q_NEW_X(evtT_, margin_, sig_) \
783 ((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
784 (margin_), (enum_t)(sig_)))
787#define Q_NEW_REF(evtRef_, evtT_) \
788 ((evtRef_) = (evtT_ const *)QF_newRef_(e, (evtRef_)))
789#define Q_DELETE_REF(evtRef_) do { \
790 QF_deleteRef_((evtRef_)); \
791 (evtRef_) = (void *)0; \
795 #define QACTIVE_POST(me_, e_, sender_) \
796 ((void)QActive_post_((me_), (e_), QF_NO_MARGIN, (sender_)))
797 #define QACTIVE_POST_X(me_, e_, margin_, sender_) \
798 (QActive_post_((me_), (e_), (margin_), (sender_)))
799 #define QACTIVE_PUBLISH(e_, sender_) \
800 (QActive_publish_((e_), (void const *)(sender_), (sender_)->prio))
801 #define QTIMEEVT_TICK_X(tickRate_, sender_) (QTimeEvt_tick_((tickRate_), (sender_)))
802 #define QTICKER_TRIG(ticker_, sender_) (QTicker_trig_((ticker_), (sender_)))
804 #define QACTIVE_POST(me_, e_, dummy) \
805 ((void)QActive_post_((me_), (e_), QF_NO_MARGIN, (void *)0))
806 #define QACTIVE_POST_X(me_, e_, margin_, dummy) \
807 (QActive_post_((me_), (e_), (margin_), (void *)0))
808 #define QACTIVE_PUBLISH(e_, dummy) (QActive_publish_((e_), (void *)0, 0U))
809 #define QTIMEEVT_TICK_X(tickRate_, dummy) (QTimeEvt_tick_((tickRate_), (void *)0))
810 #define QTICKER_TRIG(ticker_, sender_) (QTicker_trig_((ticker_), (void *)0))
813#define QACTIVE_POST_LIFO(me_, e_) (QActive_postLIFO_((me_), (e_)))
814#define QTIMEEVT_TICK(sender_) QTIMEEVT_TICK_X(0U, (sender_))
816#ifndef QF_CRIT_EXIT_NOP
817 #define QF_CRIT_EXIT_NOP() ((void)0)
824 #error Memory isolation not supported in this QP edition, need SafeQP
void QF_onStartup(void)
Startup QF callback.
void QF_poolInit(void *const poolSto, uint_fast32_t const poolSize, uint_fast16_t const evtSize)
Event pool initialization for dynamic allocation of events.
void QF_onCleanup(void)
Cleanup QF callback.
void QF_gc(QEvt const *const e)
Recycle a mutable (mutable) event.
uint_fast16_t QF_poolGetMaxBlockSize(void)
Obtain the block size of any registered event pools.
uint_fast16_t QF_getPoolMin(uint_fast8_t const poolNum)
Obtain the minimum of free entries of the given event pool.
void QF_onContextSw(QActive *prev, QActive *next)
QF context switch callback used in built-in kernels (QV/QK/QXK)
QEvt * QF_newX_(uint_fast16_t const evtSize, uint_fast16_t const margin, enum_t const sig)
Internal QF implementation of creating new mutable (dynamic) event.
void QF_gcFromISR(QEvt const *const e)
void QF_deleteRef_(void const *const evtRef)
Internal QF implementation of deleting event reference.
QEvt const * QF_newRef_(QEvt const *const e, void const *const evtRef)
Internal QF implementation of creating new event reference.
#define Q_UNUSED_PAR(par_)
Helper macro to clearly mark unused parameters of functions.
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()
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_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)
void QActive_unsubscribe(QActive const *const me, enum_t const sig)
Unsubscribes from the delivery of signal sig to the active object.
void QActive_unregister_(QActive *const me)
Un-register the active object from the framework.
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)
Posts an event e directly to the event queue of the active object using the First-In-First-Out (FIFO)...
QEvt const * QActive_get_(QActive *const me)
Get an event from the event queue of an active object.
void QActive_postLIFO_(QActive *const me, QEvt const *const e)
Posts an event e directly to the event queue of the active object using the Last-In-First-Out (LIFO) ...
void QActive_ctor(QActive *const me, QStateHandler const initial)
QActive constructor (abstract base class)
bool QActive_defer(QActive const *const me, struct QEQueue *const eq, QEvt const *const e)
Defer an event to a given separate event queue.
void QActive_setAttr(QActive *const me, uint32_t attr1, void const *attr2)
uint_fast16_t QActive_getQueueMin(uint_fast8_t const prio)
This function returns the minimum of free entries of the given event queue.
QACTIVE_OS_OBJ_TYPE osObject
Port-dependent per-thread object.
bool QActive_recall(QActive *const me, struct QEQueue *const eq)
Recall a deferred event from a given event queue.
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)
Publish event to all subscribers of a given signal e->sig
void QActive_stop(QActive *const me)
Stops execution of an active object and removes it from the framework's supervision.
void QActive_register_(QActive *const me)
Register this active object to be managed by the framework.
uint8_t prio
QF-priority [1..QF_MAX_ACTIVE] of this AO.
void QActive_subscribe(QActive const *const me, enum_t const sig)
Subscribes for delivery of signal sig to the active object.
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)
Starts execution of an active object and registers the object with the framework.
uint_fast16_t QActive_flushDeferred(QActive const *const me, struct QEQueue *const eq, uint_fast16_t const num)
Flush the specified number of events from the deferred queue eq
void QActive_unsubscribeAll(QActive const *const me)
Unsubscribes from the delivery of all signals to the active object.
void QActive_psInit(QSubscrList *const subscrSto, enum_t const maxSignal)
Publish event to all subscribers of a given signal e->sig
uint8_t pthre
Preemption-threshold [1..QF_MAX_ACTIVE] of this AO.
void QActive_evtLoop_(QActive *const me)
Event loop thread routine for executing an active object act (defined some in QP ports)
Abstract State Machine class (state machine interface)
struct QAsmVtable const * vptr
Virtual pointer inherited by all QAsm subclasses (see also SAS_QP_OO)
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)
Constructor of the QAsm base class.
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 stateHndl)
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)
Event without parameters initialization.
uint8_t volatile refCtr_
Event reference counter.
static void QEvt_ctor(QEvt *const me, enum_t const sig)
uint8_t poolNum_
Event pool number of this event.
Hierarchical State Machine class (QHsm-style state machine implementation strategy)
static QStateHandler QHsm_state(QHsm const *const me)
Obtain the current active state from a HSM (read only)
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)
void QMsm_init_(QAsm *const me, void const *const e, uint_fast8_t const qsId)
Implementation of the top-most initial transition in QMsm.
bool QMsm_isIn_(QAsm *const me, QStateHandler const stateHndl)
Tests if a given state is part of the current active state configuration.
QStateHandler QMsm_getStateHandler_(QAsm *const me)
Implementation of getting the state handler in a QMsm subclass.
static QMState const * QMsm_stateObj(QMsm const *const me)
Obtain the current state from a MSM (read only)
void QMsm_dispatch_(QAsm *const me, QEvt const *const e, uint_fast8_t const qsId)
Implementation of dispatching events to a QMsm.
void QMsm_ctor(QMsm *const me, QStateHandler const initial)
Constructor of QMsm.
Set of Active Objects of up to QF_MAX_ACTIVE elements.
static uint_fast8_t QPSet_findMax(QPSet const *const me)
Find the maximum element in the set–returns zero if the set is empty.
static bool QPSet_notEmpty(QPSet const *const me)
Find out whether the priority-set is NOT empty.
static bool QPSet_hasElement(QPSet const *const me, uint_fast8_t const n)
Find out whether the priority-set has element n
static void QPSet_setEmpty(QPSet *const me)
Make the priority set empty.
static void QPSet_insert(QPSet *const me, uint_fast8_t const n)
Insert element n into the priority-set (n = 1..QF_MAX_ACTIVE)
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)
Remove element n from the priority-set (n = 1..QF_MAX_ACTIVE)
static bool QPSet_isEmpty(QPSet const *const me)
Find out whether the priority-set is empty.
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)
The "extended" constructor to initialize a Time Event.
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)
Check if any time events are active at a given clock tick rate.
void QTimeEvt_tick1_(uint_fast8_t const tickRate, void const *const sender)
Processes one clock tick for QUTest.
void QTimeEvt_armX(QTimeEvt *const me, uint32_t const nTicks, uint32_t const interval)
Arm a time event (extended version for one shot or periodic time event)
void QTimeEvt_tick_(uint_fast8_t const tickRate, void const *const sender)
Processes all armed time events at every clock tick.
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)
Get the current value of the down-counter of a time event.
bool QTimeEvt_rearm(QTimeEvt *const me, uint32_t const nTicks)
Rearm a time event.
bool QTimeEvt_wasDisarmed(QTimeEvt *const me)
Check the "was disarmed" status of a time event.
bool QTimeEvt_disarm(QTimeEvt *const me)
Disarm a time event.
void * act
Active object that receives the time events.
eXtended (blocking) thread of the QXK preemptive kernel
Attribute of for the QAsm class (Abstract State Machine)
QMTranActTable const * tatbl
struct QMState const * obj