Simple "Blinky" example for the QP active object framework
Fork of qp_dpp by
main.cpp@3:81ceb3127876, 2011-09-26 (annotated)
- Committer:
- QL
- Date:
- Mon Sep 26 02:21:01 2011 +0000
- Revision:
- 3:81ceb3127876
- Parent:
- 0:efb9ac8d1a88
- Child:
- 4:6189d844a1a2
Updated for QP 4.2.04
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
QL | 0:efb9ac8d1a88 | 1 | ////////////////////////////////////////////////////////////////////////////// |
QL | 0:efb9ac8d1a88 | 2 | // Product: DPP example |
QL | 3:81ceb3127876 | 3 | // Last Updated for Version: 4.2.00 |
QL | 3:81ceb3127876 | 4 | // Date of the Last Update: Jul 23, 2011 |
QL | 0:efb9ac8d1a88 | 5 | // |
QL | 0:efb9ac8d1a88 | 6 | // Q u a n t u m L e a P s |
QL | 0:efb9ac8d1a88 | 7 | // --------------------------- |
QL | 0:efb9ac8d1a88 | 8 | // innovating embedded systems |
QL | 0:efb9ac8d1a88 | 9 | // |
QL | 3:81ceb3127876 | 10 | // Copyright (C) 2002-2011 Quantum Leaps, LLC. All rights reserved. |
QL | 0:efb9ac8d1a88 | 11 | // |
QL | 0:efb9ac8d1a88 | 12 | // This software may be distributed and modified under the terms of the GNU |
QL | 0:efb9ac8d1a88 | 13 | // General Public License version 2 (GPL) as published by the Free Software |
QL | 0:efb9ac8d1a88 | 14 | // Foundation and appearing in the file GPL.TXT included in the packaging of |
QL | 0:efb9ac8d1a88 | 15 | // this file. Please note that GPL Section 2[b] requires that all works based |
QL | 0:efb9ac8d1a88 | 16 | // on this software must also be made publicly available under the terms of |
QL | 0:efb9ac8d1a88 | 17 | // the GPL ("Copyleft"). |
QL | 0:efb9ac8d1a88 | 18 | // |
QL | 0:efb9ac8d1a88 | 19 | // Alternatively, this software may be distributed and modified under the |
QL | 0:efb9ac8d1a88 | 20 | // terms of Quantum Leaps commercial licenses, which expressly supersede |
QL | 0:efb9ac8d1a88 | 21 | // the GPL and are specifically designed for licensees interested in |
QL | 0:efb9ac8d1a88 | 22 | // retaining the proprietary status of their code. |
QL | 0:efb9ac8d1a88 | 23 | // |
QL | 0:efb9ac8d1a88 | 24 | // Contact information: |
QL | 0:efb9ac8d1a88 | 25 | // Quantum Leaps Web site: http://www.quantum-leaps.com |
QL | 0:efb9ac8d1a88 | 26 | // e-mail: info@quantum-leaps.com |
QL | 0:efb9ac8d1a88 | 27 | ////////////////////////////////////////////////////////////////////////////// |
QL | 0:efb9ac8d1a88 | 28 | #include "qp_port.h" |
QL | 0:efb9ac8d1a88 | 29 | #include "dpp.h" |
QL | 0:efb9ac8d1a88 | 30 | #include "bsp.h" |
QL | 0:efb9ac8d1a88 | 31 | |
QL | 0:efb9ac8d1a88 | 32 | // Local-scope objects ------------------------------------------------------- |
QL | 0:efb9ac8d1a88 | 33 | static QEvent const *l_tableQueueSto[N_PHILO]; |
QL | 0:efb9ac8d1a88 | 34 | static QEvent const *l_philoQueueSto[N_PHILO][N_PHILO]; |
QL | 0:efb9ac8d1a88 | 35 | static QSubscrList l_subscrSto[MAX_PUB_SIG]; |
QL | 0:efb9ac8d1a88 | 36 | |
QL | 0:efb9ac8d1a88 | 37 | static union SmallEvents { |
QL | 3:81ceb3127876 | 38 | void *e0; // minimum event size |
QL | 3:81ceb3127876 | 39 | uint8_t e1[sizeof(TableEvt)]; |
QL | 3:81ceb3127876 | 40 | // ... other event types to go into this pool |
QL | 0:efb9ac8d1a88 | 41 | } l_smlPoolSto[2*N_PHILO]; // storage for the small event pool |
QL | 0:efb9ac8d1a88 | 42 | |
QL | 0:efb9ac8d1a88 | 43 | //............................................................................ |
QL | 3:81ceb3127876 | 44 | int main() { |
QL | 3:81ceb3127876 | 45 | |
QL | 0:efb9ac8d1a88 | 46 | BSP_init(); // initialize the BSP |
QL | 3:81ceb3127876 | 47 | |
QL | 0:efb9ac8d1a88 | 48 | QF::init(); // initialize the framework and the underlying RT kernel |
QL | 3:81ceb3127876 | 49 | |
QL | 0:efb9ac8d1a88 | 50 | // object dictionaries... |
QL | 0:efb9ac8d1a88 | 51 | QS_OBJ_DICTIONARY(l_smlPoolSto); |
QL | 0:efb9ac8d1a88 | 52 | QS_OBJ_DICTIONARY(l_tableQueueSto); |
QL | 0:efb9ac8d1a88 | 53 | QS_OBJ_DICTIONARY(l_philoQueueSto[0]); |
QL | 0:efb9ac8d1a88 | 54 | QS_OBJ_DICTIONARY(l_philoQueueSto[1]); |
QL | 0:efb9ac8d1a88 | 55 | QS_OBJ_DICTIONARY(l_philoQueueSto[2]); |
QL | 0:efb9ac8d1a88 | 56 | QS_OBJ_DICTIONARY(l_philoQueueSto[3]); |
QL | 0:efb9ac8d1a88 | 57 | QS_OBJ_DICTIONARY(l_philoQueueSto[4]); |
QL | 0:efb9ac8d1a88 | 58 | |
QL | 0:efb9ac8d1a88 | 59 | QF::psInit(l_subscrSto, Q_DIM(l_subscrSto)); // init publish-subscribe |
QL | 3:81ceb3127876 | 60 | |
QL | 0:efb9ac8d1a88 | 61 | // initialize event pools... |
QL | 0:efb9ac8d1a88 | 62 | QF::poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0])); |
QL | 0:efb9ac8d1a88 | 63 | |
QL | 0:efb9ac8d1a88 | 64 | // start the active objects... |
QL | 0:efb9ac8d1a88 | 65 | uint8_t n; |
QL | 0:efb9ac8d1a88 | 66 | for (n = 0; n < N_PHILO; ++n) { |
QL | 0:efb9ac8d1a88 | 67 | AO_Philo[n]->start((uint8_t)(n + 1), |
QL | 0:efb9ac8d1a88 | 68 | l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]), |
QL | 0:efb9ac8d1a88 | 69 | (void *)0, 0, (QEvent *)0); |
QL | 0:efb9ac8d1a88 | 70 | } |
QL | 0:efb9ac8d1a88 | 71 | AO_Table->start((uint8_t)(N_PHILO + 1), |
QL | 0:efb9ac8d1a88 | 72 | l_tableQueueSto, Q_DIM(l_tableQueueSto), |
QL | 0:efb9ac8d1a88 | 73 | (void *)0, 0, (QEvent *)0); |
QL | 0:efb9ac8d1a88 | 74 | |
QL | 0:efb9ac8d1a88 | 75 | QF::run(); // run the QF application |
QL | 0:efb9ac8d1a88 | 76 | |
QL | 0:efb9ac8d1a88 | 77 | return 0; |
QL | 0:efb9ac8d1a88 | 78 | } |