QP/C++  5.9.7
qf.h File Reference

QF/C++ platform-independent public interface. More...

#include "qpset.h"

Go to the source code of this file.

Classes

class  QActive
 QActive active object (based on QP::QHsm implementation) More...
 
class  QMActive
 QMActive active object (based on QP::QMsm implementation) More...
 
class  QTimeEvt
 Time Event class. More...
 
class  QF
 QF services. More...
 
class  QTicker
 Ticker Active Object class. More...
 

Namespaces

 QP
 namespace associated with the QP/C++ framework
 

Macros

#define QF_EVENT_SIZ_SIZE   2
 Default value of the macro configurable value in qf_port.h.
 
#define QF_MAX_EPOOL   3
 Default value of the macro configurable value in qf_port.h.
 
#define QF_MAX_TICK_RATE   1
 Default value of the macro configurable value in qf_port.h.
 
#define QF_TIMEEVT_CTR_SIZE   2
 macro to override the default QTimeEvtCtr size. Valid values 1, 2, or 4; default 2
 
#define QF_CRIT_EXIT_NOP()   ((void)0)
 No-operation for exiting a critical section. More...
 
#define Q_NEW(evtT_, sig_)
 Allocate a dynamic event. More...
 
#define Q_NEW_X(e_, evtT_, margin_, sig_)
 Allocate a dynamic event (non-asserting version). More...
 
#define Q_NEW_REF(evtRef_, evtT_)   ((evtRef_) = static_cast<evtT_ const *>(QP::QF::newRef_(e, (evtRef_))))
 Create a new reference of the current event e */. More...
 
#define Q_DELETE_REF(evtRef_)
 Delete the event reference */. More...
 
#define TICK_X(tickRate_, sender_)   tickX_((tickRate_), (sender_))
 Invoke the system clock tick processing QP::QF::tickX_(). More...
 
#define PUBLISH(e_, sender_)   publish_((e_), (sender_))
 Invoke the event publishing facility QP::QF::publish_(). This macro. More...
 
#define POST(e_, sender_)   post_((e_), QP::QF_NO_MARGIN, (sender_))
 Invoke the direct event posting facility QP::QActive::post_(). More...
 
#define POST_X(e_, margin_, sender_)   post_((e_), (margin_), (sender_))
 Invoke the direct event posting facility QP::QActive::post_() without delivery guarantee. More...
 
#define TICK(sender_)   TICK_X(static_cast<uint8_t>(0), (sender_))
 Invoke the system clock tick processing for rate 0. More...
 

Typedefs

typedef uint16_t QEvtSize
 The data type to store the block-size defined based on the macro QF_EVENT_SIZ_SIZE. More...
 
typedef uint16_t QTimeEvtCtr
 type of the Time Event counter, which determines the dynamic range of the time delays measured in clock ticks. More...
 
typedef QPSet QSubscrList
 Subscriber List. More...
 

Variables

uint_fast16_t const QF_NO_MARGIN = static_cast<uint_fast16_t>(0xFFFF)
 special value of margin that causes asserting failure in case event allocation or event posting fails
 

Detailed Description

QF/C++ platform-independent public interface.

Definition in file qf.h.

Macro Definition Documentation

◆ QF_CRIT_EXIT_NOP

#define QF_CRIT_EXIT_NOP ( )    ((void)0)

No-operation for exiting a critical section.

Description
In some QF ports the critical section exit takes effect only on the next machine instruction. If this next instruction is another entry to a critical section, the critical section won't be really exited, but rather the two adjecent critical sections would be merged. The QF_CRIT_EXIT_NOP() macro contains minimal code required to prevent such merging of critical sections in such merging of critical sections in QF ports, in which it can occur.

Definition at line 636 of file qf.h.

◆ Q_NEW

#define Q_NEW (   evtT_,
  sig_ 
)
Value:
(static_cast<evtT_ *>(QP::QF::newX_( \
static_cast<uint_fast16_t>(sizeof(evtT_)), \
QP::QF_NO_MARGIN, (sig_))))
uint_fast16_t const QF_NO_MARGIN
special value of margin that causes asserting failure in case event allocation or event posting fails...
Definition: qf.h:594
static QEvt * newX_(uint_fast16_t const evtSize, uint_fast16_t const margin, enum_t const sig)
Internal QP implementation of the dynamic event allocator.
Definition: qf_dyn.cpp:129

Allocate a dynamic event.

Description
The macro calls the internal QF function QP::QF::newX_() with margin == QP::QF_NO_MARGIN, which causes an assertion when the event cannot be successfully allocated.
Parameters
[in]evtT_event type (class name) of the event to allocate
[in]sig_signal to assign to the newly allocated event
Returns
a valid event pointer cast to the type evtT_.
Note
If Q_EVT_CTOR is defined, the Q_NEW() macro becomes variadic and takes all the arguments needed by the constructor of the event class being allocated. The constructor is then called by means of the placement-new operator.
Usage
The following example illustrates dynamic allocation of an event:
extern QActive *AO_Table;
QP::QState Philo::hungry(Philo * const me, QP::QEvt const * const e) {
QP::QState status;
switch (e->sig) {
case Q_ENTRY_SIG: {
TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
pe->philoNum = PHILO_ID(me);
AO_Table->POST(pe, me);
status = Q_HANDLED();
break;
}
. . .
default: {
status = Q_SUPER(&QHsm::top);
break;
}
}
return status;
}

Definition at line 678 of file qf.h.

◆ Q_NEW_X

#define Q_NEW_X (   e_,
  evtT_,
  margin_,
  sig_ 
)
Value:
((e_) = static_cast<evtT_ *>(\
QP::QF::newX_(static_cast<uint_fast16_t>(sizeof(evtT_)),\
(margin_), (sig_))))
static QEvt * newX_(uint_fast16_t const evtSize, uint_fast16_t const margin, enum_t const sig)
Internal QP implementation of the dynamic event allocator.
Definition: qf_dyn.cpp:129

Allocate a dynamic event (non-asserting version).

Description
This macro allocates a new event and sets the pointer e_, while leaving at least margin_ of events still available in the pool
Parameters
[in]evtT_event type (class name) of the event to allocate
[in]margin_number of events that must remain available in the given pool after this allocation. The special value QP::QF_NO_MARGIN causes asserting failure in case event allocation fails.
[in]sig_signal to assign to the newly allocated event
Returns
an event pointer cast to the type evtT_ or NULL if the event cannot be allocated with the specified margin.
Note
If Q_EVT_CTOR is defined, the Q_NEW_X() macro becomes variadic and takes all the arguments needed by the constructor of the event class being allocated. The constructor is then called by means of the placement-new operator.
Usage
The following example illustrates dynamic allocation of an event:
extern QActive *AO_Table;
QP::QState Philo::hungry(Philo * const me, QP::QEvt const * const e) {
QP::QState status_;
switch (e->sig) {
case Q_ENTRY_SIG: {
TableEvt *te;
Q_NEW_X(te, TableEvt, 1U, HUNGRY_SIG, PHILO_ID(me));
if (te != static_cast<TableEvt *>(0)) {
AO_Table->POST_X(te, 1U, me);
}
status_ = Q_HANDLED();
break;
}
. . .
default: {
status = Q_SUPER(&QHsm::top);
break;
}
}
return status;
}

Definition at line 707 of file qf.h.

◆ Q_NEW_REF

#define Q_NEW_REF (   evtRef_,
  evtT_ 
)    ((evtRef_) = static_cast<evtT_ const *>(QP::QF::newRef_(e, (evtRef_))))

Create a new reference of the current event e */.

Description
The current event processed by an active object is available only for the duration of the run-to-completion (RTC) step. After that step, the current event is no longer available and the framework might recycle (garbage-collect) the event. The macro Q_NEW_REF() explicitly creates a new reference to the current event that can be stored and used beyond the current RTC step, until the reference is explicitly recycled by means of the macro Q_DELETE_REF().
Parameters
[in,out]evtRef_event reference to create
[in]evtT_event type (class name) of the event refrence
Usage
The example defer in the directory examples/win32/defer illustrates the use of Q_NEW_REF()
See also
Q_DELETE_REF()

Definition at line 732 of file qf.h.

◆ Q_DELETE_REF

#define Q_DELETE_REF (   evtRef_)
Value:
do { \
QP::QF::gc((evtRef_)); \
(evtRef_) = 0; \
} while (false)
static void gc(QEvt const *e)
Recycle a dynamic event.
Definition: qf_dyn.cpp:197

Delete the event reference */.

Description
Every event reference created with the macro Q_NEW_REF() needs to be eventually deleted by means of the macro Q_DELETE_REF() to avoid leaking the event.
Parameters
[in,out]evtRef_event reference to delete
Usage
The example defer in the directory examples/win32/defer illustrates the use of Q_DELETE_REF()
See also
Q_NEW_REF()

Definition at line 749 of file qf.h.

◆ TICK_X

#define TICK_X (   tickRate_,
  sender_ 
)    tickX_((tickRate_), (sender_))

Invoke the system clock tick processing QP::QF::tickX_().

Description
This macro is the recommended way of invoking clock tick processing, because it provides the vital information for software tracing and avoids any overhead when the tracing is disabled.
Parameters
[in]tickRateclock tick rate to be serviced through this call
[in]senderpointer to the sender object. This parameter is actually only used when QS software tracing is enabled (macro Q_SPY is defined)
Note
When QS software tracing is disabled, the macro calls QF_tickX_() without the sender parameter, so the overhead of passing this extra parameter is entirely avoided.
The pointer to the sender object is not necessarily a pointer to an active object. In fact, when #QF_TICK_X() is called from an interrupt, you would create a unique object just to unambiguously identify the ISR as the sender of the time events.
See also
QP::QF::tickX_()

Definition at line 781 of file qf.h.

◆ PUBLISH

#define PUBLISH (   e_,
  sender_ 
)    publish_((e_), (sender_))

Invoke the event publishing facility QP::QF::publish_(). This macro.

Description
This macro is the recommended way of publishing events, because it provides the vital information for software tracing and avoids any overhead when the tracing is disabled.
Parameters
[in]e_pointer to the posted event
[in]sender_pointer to the sender object. This parameter is actually only used when QS software tracing is enabled (macro Q_SPY is defined). When QS software tracing is disabled, the macro calls QF_publish_() without the sender_ parameter, so the overhead of passing this extra parameter is entirely avoided.
Note
The pointer to the sender object is not necessarily a pointer to an active object. In fact, if QF_PUBLISH() is called from an interrupt or other context, you can create a unique object just to unambiguously identify the publisher of the event.
See also
QP::QF::publish_()

Definition at line 804 of file qf.h.

◆ POST

#define POST (   e_,
  sender_ 
)    post_((e_), QP::QF_NO_MARGIN, (sender_))

Invoke the direct event posting facility QP::QActive::post_().

Description
This macro asserts if the queue overflows and cannot accept the event.
Parameters
[in]e_pointer to the event to post
[in]sender_pointer to the sender object.
Note
The sendedr_ parameter is actually only used when QS tracing is enabled (macro Q_SPY is defined). When QS software tracing is disenabled, the QACTIVE_POST() macro does not pass the sender_ parameter, so the overhead of passing this extra parameter is entirely avoided.
the pointer to the sender object is not necessarily a pointer to an active object. In fact, if QP::QActive::post() is called from an interrupt or other context, you can create a unique object just to unambiguously identify the sender of the event.
See also
QP::QActive::post_()

Definition at line 826 of file qf.h.

◆ POST_X

#define POST_X (   e_,
  margin_,
  sender_ 
)    post_((e_), (margin_), (sender_))

Invoke the direct event posting facility QP::QActive::post_() without delivery guarantee.

Description
This macro does not assert if the queue overflows and cannot accept the event with the specified margin of free slots remaining.
Parameters
[in]e_pointer to the event to post
[in]margin_the minimum free slots in the queue, which must still be available after posting the event. The special value QP::QF_NO_MARGIN causes asserting failure in case event posting fails.
[in]sender_pointer to the sender object.
Returns
'true' if the posting succeeded, and 'false' if the posting failed due to insufficient margin of free entries available in the queue.
Note
The sender_ parameter is actually only used when QS tracing is enabled (macro Q_SPY is defined). When QS software tracing is disabled, the QACTIVE_POST() macro does not pass the sender_ parameter, so the overhead of passing this extra parameter is entirely avoided.
The pointer to the sender object is not necessarily a pointer to an active object. In fact, if QP::QActive::post() is called from an interrupt or other context, you can create a unique object just to unambiguously identify the sender of the event.
Usage
extern QActive *AO_Table;
QP::QState Philo::hungry(Philo * const me, QP::QEvt const * const e) {
QP::QState status_;
switch (e->sig) {
case Q_ENTRY_SIG: {
TableEvt *te;
Q_NEW_X(te, TableEvt, 1U, HUNGRY_SIG, PHILO_ID(me));
if (te != static_cast<TableEvt *>(0)) {
AO_Table->POST_X(te, 1U, me);
}
status_ = Q_HANDLED();
break;
}
. . .
default: {
status = Q_SUPER(&QHsm::top);
break;
}
}
return status;
}

Definition at line 862 of file qf.h.

◆ TICK

#define TICK (   sender_)    TICK_X(static_cast<uint8_t>(0), (sender_))

Invoke the system clock tick processing for rate 0.

See also
TICK_X()

Definition at line 876 of file qf.h.