QP/C
Functions | Variables
qf_psini.c File Reference

QF_subscrList_, QF_maxSignal_ definitions, and QF_psInit() implementation. More...

#include "qf_pkg.h"

Go to the source code of this file.

Functions

void QF_psInit (QSubscrList *const subscrSto, uint32_t const maxSignal)
 Publish-subscribe initialization.

Variables

QSubscrListQF_subscrList_
enum_t QF_maxSignal_

Detailed Description

QF_subscrList_, QF_maxSignal_ definitions, and QF_psInit() implementation.

Definition in file qf_psini.c.


Function Documentation

void QF_psInit ( QSubscrList *const  subscrSto,
uint32_t const  maxSignal 
)

Publish-subscribe initialization.

This function initializes the publish-subscribe facilities of QF and must be called exactly once before any subscriptions/publications occur in the application. The arguments are as follows: subscrSto is a pointer to the array of subscriber-lists. maxSignal is the dimension of this array and at the same time the maximum signal that can be published or subscribed.

The array of subscriber-lists is indexed by signals and provides mapping between the signals and subscriber-lists. The subscriber-lists are bitmasks of type QSubscrList, each bit in the bit mask corresponding to the unique priority of an active object. The size of the QSubscrList bit mask depends on the value of the QF_MAX_ACTIVE macro.

Note:
The publish-subscribe facilities are optional, meaning that you might choose not to use publish-subscribe. In that case calling QF_psInit() and using up memory for the subscriber-lists is unnecessary.
See also:
QSubscrList

The following example shows the typical initialization sequence of QF:

/* allocate storage for active objects, event queues, event pools,
* subscriber lists, and stacks.
*/
static QEvent const *l_tableQueueSto[N_PHILO];
static QEvent const *l_philoQueueSto[N_PHILO][N_PHILO];
static QSubscrList   l_subscrSto[MAX_PUB_SIG];

static union SmallEvent {
    void *min_size;
    TableEvt te;
    /* other event types to go into this pool */
} l_smlPoolSto[2*N_PHILO];              /* storage for the small event pool */

/*..........................................................................*/
int main(int argc, char *argv[]) {
    uint8_t n;

    Philo_ctor();             /* instantiate all Philosopher active objects */
    Table_ctor();                    /* instantiate the Table active object */

    BSP_init(argc, argv);           /* initialize the Board Support Package */

    QF_init();     /* initialize the framework and the underlying RT kernel */

    QF_psInit(l_subscrSto, Q_DIM(l_subscrSto));   /* init publish-subscribe */

                                               /* initialize event pools... */
    QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));

    for (n = 0; n < N_PHILO; ++n) {          /* start the active objects... */
        QActive_start(AO_Philo[n], (uint8_t)(n + 1),
                      l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
                      (void *)0, 0, (QEvent *)0);
    }
    QActive_start(AO_Table, (uint8_t)(N_PHILO + 1),
                  l_tableQueueSto, Q_DIM(l_tableQueueSto),
                  (void *)0, 0, (QEvent *)0);
    QF_run();                                     /* run the QF application */

    return 0;
}

Definition at line 49 of file qf_psini.c.

References QF_maxSignal_.


Variable Documentation

the maximum published signal

Definition at line 46 of file qf_psini.c.

Referenced by QActive_subscribe(), QActive_unsubscribe(), QActive_unsubscribeAll(), QF_psInit(), and QF_publish().

the subscriber list array

Definition at line 45 of file qf_psini.c.

Referenced by QActive_subscribe(), QActive_unsubscribe(), QActive_unsubscribeAll(), and QF_publish().