QP/C  6.9.3
Real-Time Embedded Framework
qep.h
Go to the documentation of this file.
1 
40 #ifndef QEP_H
41 #define QEP_H
42 
43 /****************************************************************************/
48 #define QP_VERSION 693U
49 
54 #define QP_VERSION_STR "6.9.3"
55 
57 #define QP_RELEASE 0x8295AA8AU
58 
59 
60 /****************************************************************************/
61 /* typedefs for basic numerical types; MISRA-C 2004 rule 6.3(req). */
62 
70 typedef char char_t;
71 
73 typedef int int_t;
74 
76 typedef unsigned uint_t;
77 
79 typedef int enum_t;
80 
88 typedef float float32_t;
89 
97 typedef double float64_t;
98 
100 extern char_t const QP_versionStr[7];
101 
102 /****************************************************************************/
103 #ifndef Q_SIGNAL_SIZE
104 
113  #define Q_SIGNAL_SIZE 2U
114 #endif
115 #if (Q_SIGNAL_SIZE == 1U)
116  typedef uint8_t QSignal;
117 #elif (Q_SIGNAL_SIZE == 2U)
128  typedef uint16_t QSignal;
129 #elif (Q_SIGNAL_SIZE == 4U)
130  typedef uint32_t QSignal;
131 #else
132  #error "Q_SIGNAL_SIZE defined incorrectly, expected 1U, 2U, or 4U"
133 #endif
134 
135 
136 /****************************************************************************/
151 typedef struct {
154  uint8_t volatile refCtr_;
155 } QEvt;
156 
157 #ifdef Q_EVT_CTOR /* Shall the constructor for the QEvt class be provided? */
158 
162 QEvt *QEvt_ctor(QEvt * const me, enum_t const sig);
163 
164 #endif
165 
166 /****************************************************************************/
180 #define Q_HSM_UPCAST(ptr_) ((QHsm *)(ptr_))
181 
190 #define Q_EVT_CAST(class_) ((class_ const *)e)
191 
199 #define Q_UINT2PTR_CAST(type_, uintptr_) ((type_ *)(uintptr_))
200 
201 
202 /****************************************************************************/
205 
206 /* forward declaration */
207 typedef struct QXThread QXThread;
208 
210 typedef QState (*QStateHandler)(void * const me, QEvt const * const e);
211 
213 typedef QState (*QActionHandler)(void * const me);
214 
216 typedef void (*QXThreadHandler)(QXThread * const me);
217 
228 #define Q_STATE_CAST(handler_) ((QStateHandler)(handler_))
229 
237 #define Q_ACTION_CAST(action_) ((QActionHandler)(action_))
238 
239 /* forward declarations... */
240 struct QMState;
241 struct QHsmVtable;
242 typedef struct QMTranActTable QMTranActTable;
243 
250 union QHsmAttr {
254  struct QMState const *obj;
256 };
257 
258 /****************************************************************************/
282 typedef struct {
283  struct QHsmVtable const *vptr;
284  union QHsmAttr state;
285  union QHsmAttr temp;
286 } QHsm;
287 
289 struct QHsmVtable {
290 #ifdef Q_SPY
292  void (*init)(QHsm * const me, void const * const e,
293  uint_fast8_t const qs_id);
294 
296  void (*dispatch)(QHsm * const me, QEvt const * const e,
297  uint_fast8_t const qs_id);
298 
301 #else
302  void (*init)(QHsm * const me, void const * const e);
303  void (*dispatch)(QHsm * const me, QEvt const * const e);
304 #endif /* Q_SPY */
305 
306 };
307 
308 /* QHsm public operations... */
309 
310 #ifdef Q_SPY
327  #define QHSM_INIT(me_, par_, qs_id_) do { \
328  Q_ASSERT((me_)->vptr); \
329  (*(me_)->vptr->init)((me_), (par_), (qs_id_)); \
330  } while (false)
331 
333  void QHsm_init_(QHsm * const me, void const * const e,
334  uint_fast8_t const qs_id);
335 #else
336 
337  #define QHSM_INIT(me_, par_, dummy) do { \
338  Q_ASSERT((me_)->vptr); \
339  (*(me_)->vptr->init)((me_), (par_)); \
340  } while (false)
341 
343  void QHsm_init_(QHsm * const me, void const * const e);
344 
345 #endif /* Q_SPY */
346 
347 
348 #ifdef Q_SPY
361  #define QHSM_DISPATCH(me_, e_, qs_id_) \
362  ((*(me_)->vptr->dispatch)((me_), (e_), (qs_id_)))
363 
365  void QHsm_dispatch_(QHsm * const me, QEvt const * const e,
366  uint_fast8_t const qs_id);
367 
370 #else
371 
372  #define QHSM_DISPATCH(me_, e_, dummy) \
373  ((*(me_)->vptr->dispatch)((me_), (e_)))
374 
376  void QHsm_dispatch_(QHsm * const me, QEvt const * const e);
377 
378 #endif /* Q_SPY */
379 
388 #define QHsm_state(me_) (Q_STATE_CAST(Q_HSM_UPCAST(me_)->state.fun))
389 
399 #define QHsm_childState(me_, parent_) \
400  QHsm_childState_(Q_HSM_UPCAST(me_), Q_STATE_CAST(parent_))
401 
406 bool QHsm_isIn(QHsm * const me, QStateHandler const state);
407 
408 /* QHsm protected operations... */
412 void QHsm_ctor(QHsm * const me, QStateHandler initial);
413 
417 QState QHsm_top(void const * const me, QEvt const * const e);
418 
419 /* QHsm private operations... */
424  QStateHandler const parent);
425 
426 
427 /****************************************************************************/
450 typedef struct {
452 } QMsm;
453 
466 struct QMState {
467  struct QMState const *superstate;
472 };
473 typedef struct QMState QMState;
474 
477  struct QMState const *target;
478  QActionHandler const act[1];
479 };
480 
481 /* QMsm public operations... */
490 #define QMsm_stateObj(me_) (Q_HSM_UPCAST(me_)->state.obj)
491 
501 #define QMsm_childStateObj(me_, parent_) \
502  QMsm_childStateObj_(Q_HSM_UPCAST(me_), (parent_))
503 
507 QMState const *QMsm_childStateObj_(QMsm const * const me,
508  QMState const * const parent);
509 
514 bool QMsm_isInState(QMsm const * const me, QMState const * const state);
515 
516 /* QMsm protected operations... */
520 void QMsm_ctor(QMsm * const me, QStateHandler initial);
521 
522 /* QMsm private operations... */
526 #ifdef Q_SPY
527 void QMsm_init_(QHsm * const me, void const * const e,
528  uint_fast8_t const qs_id);
529 #else
530 void QMsm_init_(QHsm * const me, void const * const e);
531 #endif
532 
536 #ifdef Q_SPY
537 void QMsm_dispatch_(QHsm * const me, QEvt const * const e,
538  uint_fast8_t const qs_id);
539 #else
540 void QMsm_dispatch_(QHsm * const me, QEvt const * const e);
541 #endif
542 
546 #ifdef Q_SPY
548 #endif
549 
554 #define Q_TRAN(target_) \
555  ((Q_HSM_UPCAST(me))->temp.fun = Q_STATE_CAST(target_), (QState)Q_RET_TRAN)
556 
563 #define Q_TRAN_HIST(hist_) \
564  ((Q_HSM_UPCAST(me))->temp.fun = (hist_), (QState)Q_RET_TRAN_HIST)
565 
572 #define Q_SUPER(super_) \
573  ((Q_HSM_UPCAST(me))->temp.fun = Q_STATE_CAST(super_), (QState)Q_RET_SUPER)
574 
578 #define Q_HANDLED() ((QState)Q_RET_HANDLED)
579 
584 #define Q_UNHANDLED() ((QState)Q_RET_UNHANDLED)
585 
589 #define Q_ACTION_NULL ((QActionHandler)0)
590 
591 
592 /****************************************************************************/
597 enum {
598  /* unhandled and need to "bubble up" */
603  /* handled and do not need to "bubble up" */
607  /* entry/exit */
611  /* no side effects */
614  /* transitions need to execute transition-action table in ::QMsm */
619  /* transitions that additionally clobber me->state */
622 };
623 
624 #ifdef Q_SPY
628  #define QM_ENTRY(state_) \
629  ((Q_HSM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_ENTRY)
630 
634  #define QM_EXIT(state_) \
635  ((Q_HSM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_EXIT)
636 
637 #else
638  #define QM_ENTRY(dummy) ((QState)Q_RET_ENTRY)
639 
640  #define QM_EXIT(dummy) ((QState)Q_RET_EXIT)
641 
642 #endif /* Q_SPY */
643 
647 #define QM_SM_EXIT(state_) \
648  ((Q_HSM_UPCAST(me))->temp.obj = (state_), (QState)Q_RET_EXIT)
649 
653 #define QM_TRAN(tatbl_) ((Q_HSM_UPCAST(me))->temp.tatbl \
654  = (QMTranActTable *)(tatbl_), (QState)Q_RET_TRAN)
655 
659 #define QM_TRAN_INIT(tatbl_) ((Q_HSM_UPCAST(me))->temp.tatbl \
660  = (QMTranActTable *)(tatbl_), (QState)Q_RET_TRAN_INIT)
661 
665 #define QM_TRAN_HIST(history_, tatbl_) \
666  ((((Q_HSM_UPCAST(me))->state.obj = (history_)), \
667  ((Q_HSM_UPCAST(me))->temp.tatbl = (QMTranActTable *)(tatbl_))), \
668  (QState)Q_RET_TRAN_HIST)
669 
673 #define QM_TRAN_EP(tatbl_) ((Q_HSM_UPCAST(me))->temp.tatbl \
674  = (struct QMTranActTable *)(tatbl_), (QState)Q_RET_TRAN_EP)
675 
679 #define QM_TRAN_XP(xp_, tatbl_) \
680  ((((Q_HSM_UPCAST(me))->state.act = (xp_)), \
681  ((Q_HSM_UPCAST(me))->temp.tatbl = (QMTranActTable *)(tatbl_))), \
682  (QState)Q_RET_TRAN_XP)
683 
687 #define QM_HANDLED() ((QState)Q_RET_HANDLED)
688 
694 #define QM_UNHANDLED() ((QState)Q_RET_UNHANDLED)
695 
699 #define QM_SUPER() ((QState)Q_RET_SUPER)
700 
704 #define QM_SUPER_SUB(host_) \
705  ((Q_HSM_UPCAST(me))->temp.obj = (host_), (QState)Q_RET_SUPER_SUB)
706 
710 #define QM_STATE_NULL ((QMState *)0)
711 
713 enum {
717  Q_USER_SIG
718 };
719 
720 #endif /* QEP_H */
721 
unsigned int uint16_t
Definition: 16bit/stdint.h:30
unsigned long int uint32_t
Definition: 16bit/stdint.h:31
unsigned char uint8_t
Definition: 16bit/stdint.h:29
unsigned int uint_fast8_t
Definition: 16bit/stdint.h:36
char char_t
Definition: qassert.h:77
@ Q_RET_ENTRY
Definition: qep.h:608
@ Q_RET_HANDLED
Definition: qep.h:604
@ Q_RET_TRAN_XP
Definition: qep.h:621
@ Q_RET_IGNORED
Definition: qep.h:605
@ Q_RET_TRAN_INIT
Definition: qep.h:616
@ Q_RET_TRAN
Definition: qep.h:615
@ Q_RET_UNHANDLED
Definition: qep.h:601
@ Q_RET_SUPER
Definition: qep.h:599
@ Q_RET_NULL
Definition: qep.h:612
@ Q_RET_TRAN_HIST
Definition: qep.h:620
@ Q_RET_SUPER_SUB
Definition: qep.h:600
@ Q_RET_TRAN_EP
Definition: qep.h:617
@ Q_RET_EXIT
Definition: qep.h:609
struct QMState const * superstate
Definition: qep.h:467
unsigned uint_t
Definition: qep.h:76
QActionHandler const act[1]
Definition: qep.h:478
char char_t
Definition: qep.h:70
QMTranActTable const * tatbl
Definition: qep.h:255
float float32_t
Definition: qep.h:88
char_t const QP_versionStr[7]
Definition: qep_hsm.c:53
QState(* QStateHandler)(void *const me, QEvt const *const e)
Definition: qep.h:210
QActionHandler const entryAction
Definition: qep.h:469
int int_t
Definition: qep.h:73
void QHsm_init_(QHsm *const me, void const *const e, uint_fast8_t const qs_id)
Definition: qep_hsm.c:158
QActionHandler const initAction
Definition: qep.h:471
QActionHandler const exitAction
Definition: qep.h:470
struct QMState const * target
Definition: qep.h:477
QStateHandler const stateHandler
Definition: qep.h:468
double float64_t
Definition: qep.h:97
QStateHandler QHsm_getStateHandler_(QHsm *const me)
Definition: qep_hsm.c:583
int enum_t
Definition: qep.h:79
uint_fast8_t QState
Definition: qep.h:204
QXThreadHandler thr
Definition: qep.h:253
QStateHandler fun
Definition: qep.h:251
void(* QXThreadHandler)(QXThread *const me)
Definition: qep.h:216
@ Q_INIT_SIG
Definition: qep.h:716
@ Q_USER_SIG
Definition: qep.h:717
@ Q_EXIT_SIG
Definition: qep.h:715
@ Q_ENTRY_SIG
Definition: qep.h:714
struct QMState const * obj
Definition: qep.h:254
QState(* QActionHandler)(void *const me)
Definition: qep.h:213
void QHsm_dispatch_(QHsm *const me, QEvt const *const e, uint_fast8_t const qs_id)
Definition: qep_hsm.c:271
uint16_t QSignal
Definition: qep.h:128
QActionHandler act
Definition: qep.h:252
Definition: qep.h:466
Definition: qep.h:250
Definition: qep.h:151
QSignal sig
Definition: qep.h:152
uint8_t poolId_
Definition: qep.h:153
uint8_t volatile refCtr_
Definition: qep.h:154
Definition: qep.h:282
bool QHsm_isIn(QHsm *const me, QStateHandler const state)
Definition: qep_hsm.c:602
void QHsm_ctor(QHsm *const me, QStateHandler initial)
Definition: qep_hsm.c:133
QStateHandler QHsm_childState_(QHsm *const me, QStateHandler const parent)
Definition: qep_hsm.c:648
QState QHsm_top(void const *const me, QEvt const *const e)
Definition: qep_hsm.c:250
void(* init)(QHsm *const me, void const *const e, uint_fast8_t const qs_id)
Definition: qep.h:292
void(* dispatch)(QHsm *const me, QEvt const *const e, uint_fast8_t const qs_id)
Definition: qep.h:296
QStateHandler(* getStateHandler)(QHsm *const me)
Definition: qep.h:300
Definition: qep.h:450
QHsm super
Definition: qep.h:451
QStateHandler QMsm_getStateHandler_(QHsm *const me)
Definition: qep_msm.c:419
QMState const * QMsm_childStateObj_(QMsm const *const me, QMState const *const parent)
Definition: qep_msm.c:673
void QMsm_init_(QHsm *const me, void const *const e, uint_fast8_t const qs_id)
Definition: qep_msm.c:163
void QMsm_dispatch_(QHsm *const me, QEvt const *const e, uint_fast8_t const qs_id)
Definition: qep_msm.c:228
bool QMsm_isInState(QMsm const *const me, QMState const *const state)
Definition: qep_msm.c:642
void QMsm_ctor(QMsm *const me, QStateHandler initial)
Definition: qep_msm.c:135