33#define QP_VERSION_STR "8.0.3"
34#define QP_VERSION 803U
36#define QP_RELEASE 0x6ABEE96CU
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))
172#define Q_STATE_CAST(handler_) ((QStateHandler)(handler_))
173#define Q_ACTION_CAST(action_) ((QActionHandler)(action_))
174#define Q_ACTION_NULL ((QActionHandler)0)
186#define Q_RET_SUPER ((QState)0U)
187#define Q_RET_UNHANDLED ((QState)1U)
190#define Q_RET_HANDLED ((QState)2U)
191#define Q_RET_IGNORED ((QState)3U)
194#define Q_RET_ENTRY ((QState)4U)
195#define Q_RET_EXIT ((QState)5U)
198#define Q_RET_NULL ((QState)6U)
201#define Q_RET_TRAN ((QState)7U)
202#define Q_RET_TRAN_INIT ((QState)8U)
205#define Q_RET_TRAN_HIST ((QState)9U)
208#define Q_EMPTY_SIG ((QSignal)0U)
209#define Q_ENTRY_SIG ((QSignal)1U)
210#define Q_EXIT_SIG ((QSignal)2U)
211#define Q_INIT_SIG ((QSignal)3U)
212#define Q_USER_SIG ((enum_t)4)
222 void (*
init)(
QAsm *
const me,
void const *
const e,
223 uint_fast8_t
const qsId);
225 uint_fast8_t
const qsId);
233 #define QASM_INIT(me_, par_, qsId_) \
234 (*((QAsm *)(me_))->vptr->init)((QAsm *)(me_), (par_), (qsId_))
235 #define QASM_DISPATCH(me_, e_, qsId_) \
236 (*((QAsm *)(me_))->vptr->dispatch)((QAsm *)(me_), (e_), (qsId_))
237 #define QASM_IS_IN(me_, stateHndl_) \
238 (*((QAsm *)(me_))->vptr->isIn)((QAsm *)(me_), (stateHndl_))
240 #define QASM_INIT(me_, par_, dummy) \
241 (*((QAsm *)(me_))->vptr->init)((QAsm *)(me_), (par_), 0U)
242 #define QASM_DISPATCH(me_, e_, dummy) \
243 (*((QAsm *)(me_))->vptr->dispatch)((QAsm *)(me_), (e_), 0U)
246#define Q_ASM_UPCAST(ptr_) ((QAsm *)(ptr_))
256void QHsm_ctor(
QHsm *
const me,
262 void const *
const e,
263 uint_fast8_t
const qsId);
268 QEvt const *
const e,
269 uint_fast8_t
const qsId);
283 QEvt const *
const e);
294#define Q_HSM_UPCAST(ptr_) ((QHsm *)(ptr_))
296#define Q_TRAN(target_) \
297 ((Q_ASM_UPCAST(me))->temp.fun = Q_STATE_CAST(target_), \
299#define Q_TRAN_HIST(hist_) \
300 ((Q_ASM_UPCAST(me))->temp.fun = (hist_), \
301 (QState)Q_RET_TRAN_HIST)
302#define Q_SUPER(super_) \
303 ((Q_ASM_UPCAST(me))->temp.fun = Q_STATE_CAST(super_), \
305#define Q_HANDLED() ((QState)Q_RET_HANDLED)
306#define Q_UNHANDLED() ((QState)Q_RET_UNHANDLED)
322 void const *
const e,
323 uint_fast8_t
const qsId);
328 QEvt const *
const e,
329 uint_fast8_t
const qsId);
347QMState const * QMsm_childStateObj(
QMsm const *
const me,
352#define Q_MSM_UPCAST(ptr_) ((QMsm *)(ptr_))
354 #define QM_ENTRY(state_) \
355 ((Q_ASM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_ENTRY)
356 #define QM_EXIT(state_) \
357 ((Q_ASM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_EXIT)
359 #define QM_ENTRY(dummy) ((QState)Q_RET_ENTRY)
360 #define QM_EXIT(dummy) ((QState)Q_RET_EXIT)
363#define QM_TRAN(tatbl_) ((Q_ASM_UPCAST(me))->temp.tatbl \
364 = (struct QMTranActTable const *)(tatbl_), (QState)Q_RET_TRAN)
366#define QM_TRAN_INIT(tatbl_) ((Q_ASM_UPCAST(me))->temp.tatbl \
367 = (struct QMTranActTable const *)(tatbl_), (QState)Q_RET_TRAN_INIT)
369#define QM_TRAN_HIST(history_, tatbl_) \
370 ((((Q_ASM_UPCAST(me))->state.obj = (history_)), \
371 ((Q_ASM_UPCAST(me))->temp.tatbl = \
372 (struct QMTranActTable const *)(tatbl_))), (QState)Q_RET_TRAN_HIST)
374#define QM_HANDLED() ((QState)Q_RET_HANDLED)
375#define QM_UNHANDLED() ((QState)Q_RET_UNHANDLED)
376#define QM_SUPER() ((QState)Q_RET_SUPER)
377#define QM_STATE_NULL ((QMState *)0)
384#if (QF_TIMEEVT_CTR_SIZE == 1U)
386#elif (QF_TIMEEVT_CTR_SIZE == 2U)
388#elif (QF_TIMEEVT_CTR_SIZE == 4U)
392#if (QF_MAX_ACTIVE <= 8U)
394#elif (8U < QF_MAX_ACTIVE) && (QF_MAX_ACTIVE <= 16U)
396#elif (16U < QF_MAX_ACTIVE)
415#if (QF_MAX_ACTIVE > 32)
422#if (QF_MAX_ACTIVE <= 32U)
423 return (me->
bits[0] == 0U);
425 return (me->
bits[0] == 0U) ? (me->
bits[1] == 0U) :
false;
431#if (QF_MAX_ACTIVE <= 32U)
432 return (me->
bits[0] != 0U);
434 return (me->
bits[0] != 0U) ? true : (me->
bits[1] != 0U);
440 uint_fast8_t
const n)
442#if (QF_MAX_ACTIVE <= 32U)
453 uint_fast8_t
const n)
455#if (QF_MAX_ACTIVE <= 32U)
469 uint_fast8_t
const n)
471#if (QF_MAX_ACTIVE <= 32U)
485#if (QF_MAX_ACTIVE <= 32U)
488 return (me->
bits[1] != 0U)
509#ifdef QACTIVE_THREAD_TYPE
513#ifdef QACTIVE_OS_OBJ_TYPE
517#ifdef QACTIVE_EQUEUE_TYPE
544 uint_fast16_t
const qLen,
546 uint_fast16_t
const stkSize,
547 void const *
const par);
549#ifdef QACTIVE_CAN_STOP
562 QEvt const *
const e,
563 uint_fast16_t
const margin,
564 void const *
const sender);
568 QEvt const *
const e);
580 QEvt const *
const e,
581 void const *
const sender,
582 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);
737#ifdef QF_ON_CONTEXT_SW
744#define Q_PRIO(prio_, pthre_) ((QPrioSpec)((prio_) | ((pthre_) << 8U)))
745#define QF_NO_MARGIN ((uint_fast16_t)0xFFFFU)
752 void *
const poolSto,
753 uint_fast32_t
const poolSize,
754 uint_fast16_t
const evtSize);
764 uint_fast16_t
const evtSize,
765 uint_fast16_t
const margin,
773 QEvt const *
const e,
774 void const *
const evtRef);
783 #define Q_NEW(evtT_, sig_, ...) \
784 (evtT_##_init((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
785 QF_NO_MARGIN, (sig_)), __VA_ARGS__))
786 #define Q_NEW_X(evtT_, margin_, sig_, ...) \
787 (evtT_##_init((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
788 (margin_), (sig_)), __VA_ARGS__))
790 #define Q_NEW(evtT_, sig_) \
791 ((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
792 QF_NO_MARGIN, (enum_t)(sig_)))
793 #define Q_NEW_X(evtT_, margin_, sig_) \
794 ((evtT_ *)QF_newX_((uint_fast16_t)sizeof(evtT_), \
795 (margin_), (enum_t)(sig_)))
798#define Q_NEW_REF(evtRef_, evtT_) \
799 ((evtRef_) = (evtT_ const *)QF_newRef_(e, (evtRef_)))
800#define Q_DELETE_REF(evtRef_) do { \
801 QF_deleteRef_((evtRef_)); \
802 (evtRef_) = (void *)0; \
806 #define QACTIVE_POST(me_, e_, sender_) \
807 ((void)QActive_post_((me_), (e_), QF_NO_MARGIN, (sender_)))
808 #define QACTIVE_POST_X(me_, e_, margin_, sender_) \
809 (QActive_post_((me_), (e_), (margin_), (sender_)))
810 #define QACTIVE_PUBLISH(e_, sender_) \
811 (QActive_publish_((e_), (void const *)(sender_), (sender_)->prio))
812 #define QTIMEEVT_TICK_X(tickRate_, sender_) (QTimeEvt_tick_((tickRate_), (sender_)))
813 #define QTICKER_TRIG(ticker_, sender_) (QTicker_trig_((ticker_), (sender_)))
815 #define QACTIVE_POST(me_, e_, dummy) \
816 ((void)QActive_post_((me_), (e_), QF_NO_MARGIN, (void *)0))
817 #define QACTIVE_POST_X(me_, e_, margin_, dummy) \
818 (QActive_post_((me_), (e_), (margin_), (void *)0))
819 #define QACTIVE_PUBLISH(e_, dummy) (QActive_publish_((e_), (void *)0, 0U))
820 #define QTIMEEVT_TICK_X(tickRate_, dummy) (QTimeEvt_tick_((tickRate_), (void *)0))
821 #define QTICKER_TRIG(ticker_, sender_) (QTicker_trig_((ticker_), (void *)0))
824#define QACTIVE_POST_LIFO(me_, e_) (QActive_postLIFO_((me_), (e_)))
825#define QTIMEEVT_TICK(sender_) QTIMEEVT_TICK_X(0U, (sender_))
827#ifndef QF_CRIT_EXIT_NOP
828 #define QF_CRIT_EXIT_NOP() ((void)0)
835 #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.
eXtended (blocking) thread of the QXK preemptive kernel
#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_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)
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)
enum_t QActive_maxPubSignal_
Static (one per-class) maximum published signal (the size of the subscrList_ array)
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.
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)
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.
QTimeEvt QTimeEvt_timeEvtHead_[QF_MAX_TICK_RATE]
Static 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)
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.
Attribute of for the QAsm class (Abstract State Machine)
QMTranActTable const * tatbl
struct QMState const * obj