Dining Philosophers Problem (DPP) example for the QP active object framework. Demonstrates: event-driven programming, hierarchical state machines in C++, modeling and graphical state machine design, code generation, preemptive multitasking, software tracing, power saving mode, direct event posting, publish-subscribe. More information available in the [[/users/QL/notebook|Quantum Leaps Notebook pages]]. See also [[http://www.state-machine.com|state-machine.com]].
main.cpp@5:15aad9bccbbd, 2012-09-05 (annotated)
- Committer:
- QL
- Date:
- Wed Sep 05 13:50:21 2012 +0000
- Revision:
- 5:15aad9bccbbd
- Parent:
- 4:6189d844a1a2
enabled the QK_PREEMPTIVE option
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 | 4:6189d844a1a2 | 3 | // Last Updated for Version: 4.5.02 |
QL | 4:6189d844a1a2 | 4 | // Date of the Last Update: Aug 11, 2012 |
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 | 4:6189d844a1a2 | 10 | // Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved. |
QL | 4:6189d844a1a2 | 11 | // |
QL | 4:6189d844a1a2 | 12 | // This program is open source software: you can redistribute it and/or |
QL | 4:6189d844a1a2 | 13 | // modify it under the terms of the GNU General Public License as published |
QL | 4:6189d844a1a2 | 14 | // by the Free Software Foundation, either version 2 of the License, or |
QL | 4:6189d844a1a2 | 15 | // (at your option) any later version. |
QL | 0:efb9ac8d1a88 | 16 | // |
QL | 4:6189d844a1a2 | 17 | // Alternatively, this program may be distributed and modified under the |
QL | 4:6189d844a1a2 | 18 | // terms of Quantum Leaps commercial licenses, which expressly supersede |
QL | 4:6189d844a1a2 | 19 | // the GNU General Public License and are specifically designed for |
QL | 4:6189d844a1a2 | 20 | // licensees interested in retaining the proprietary status of their code. |
QL | 0:efb9ac8d1a88 | 21 | // |
QL | 4:6189d844a1a2 | 22 | // This program is distributed in the hope that it will be useful, |
QL | 4:6189d844a1a2 | 23 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
QL | 4:6189d844a1a2 | 24 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
QL | 4:6189d844a1a2 | 25 | // GNU General Public License for more details. |
QL | 4:6189d844a1a2 | 26 | // |
QL | 4:6189d844a1a2 | 27 | // You should have received a copy of the GNU General Public License |
QL | 4:6189d844a1a2 | 28 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
QL | 0:efb9ac8d1a88 | 29 | // |
QL | 0:efb9ac8d1a88 | 30 | // Contact information: |
QL | 4:6189d844a1a2 | 31 | // Quantum Leaps Web sites: http://www.quantum-leaps.com |
QL | 4:6189d844a1a2 | 32 | // http://www.state-machine.com |
QL | 0:efb9ac8d1a88 | 33 | // e-mail: info@quantum-leaps.com |
QL | 0:efb9ac8d1a88 | 34 | ////////////////////////////////////////////////////////////////////////////// |
QL | 0:efb9ac8d1a88 | 35 | #include "qp_port.h" |
QL | 0:efb9ac8d1a88 | 36 | #include "dpp.h" |
QL | 0:efb9ac8d1a88 | 37 | #include "bsp.h" |
QL | 0:efb9ac8d1a88 | 38 | |
QL | 4:6189d844a1a2 | 39 | namespace DPP { |
QL | 0:efb9ac8d1a88 | 40 | |
QL | 0:efb9ac8d1a88 | 41 | //............................................................................ |
QL | 4:6189d844a1a2 | 42 | extern "C" int_t main(void) { |
QL | 4:6189d844a1a2 | 43 | static QP::QEvt const *tableQueueSto[N_PHILO]; |
QL | 4:6189d844a1a2 | 44 | static QP::QEvt const *philoQueueSto[N_PHILO][N_PHILO]; |
QL | 4:6189d844a1a2 | 45 | static QP::QSubscrList subscrSto[MAX_PUB_SIG]; |
QL | 4:6189d844a1a2 | 46 | static QF_MPOOL_EL(TableEvt) smlPoolSto[2U*N_PHILO]; // small pool |
QL | 4:6189d844a1a2 | 47 | |
QL | 4:6189d844a1a2 | 48 | QP::QF::init(); // initialize the framework and the underlying RT kernel |
QL | 3:81ceb3127876 | 49 | |
QL | 0:efb9ac8d1a88 | 50 | BSP_init(); // initialize the BSP |
QL | 3:81ceb3127876 | 51 | |
QL | 4:6189d844a1a2 | 52 | // object dictionaries... |
QL | 4:6189d844a1a2 | 53 | QS_OBJ_DICTIONARY(smlPoolSto); |
QL | 4:6189d844a1a2 | 54 | QS_OBJ_DICTIONARY(tableQueueSto); |
QL | 4:6189d844a1a2 | 55 | QS_OBJ_DICTIONARY(philoQueueSto[0]); |
QL | 4:6189d844a1a2 | 56 | QS_OBJ_DICTIONARY(philoQueueSto[1]); |
QL | 4:6189d844a1a2 | 57 | QS_OBJ_DICTIONARY(philoQueueSto[2]); |
QL | 4:6189d844a1a2 | 58 | QS_OBJ_DICTIONARY(philoQueueSto[3]); |
QL | 4:6189d844a1a2 | 59 | QS_OBJ_DICTIONARY(philoQueueSto[4]); |
QL | 3:81ceb3127876 | 60 | |
QL | 4:6189d844a1a2 | 61 | QP::QF::psInit(&subscrSto[0], Q_DIM(subscrSto)); // init publish-subscribe |
QL | 3:81ceb3127876 | 62 | |
QL | 0:efb9ac8d1a88 | 63 | // initialize event pools... |
QL | 4:6189d844a1a2 | 64 | QP::QF::poolInit(&smlPoolSto[0], sizeof(smlPoolSto), |
QL | 4:6189d844a1a2 | 65 | sizeof(smlPoolSto[0])); |
QL | 0:efb9ac8d1a88 | 66 | |
QL | 0:efb9ac8d1a88 | 67 | // start the active objects... |
QL | 4:6189d844a1a2 | 68 | for (uint8_t n = 0U; n < N_PHILO; ++n) { |
QL | 4:6189d844a1a2 | 69 | AO_Philo[n]->start(static_cast<uint8_t>(n + 1U), |
QL | 4:6189d844a1a2 | 70 | &philoQueueSto[n][0], Q_DIM(philoQueueSto[n]), |
QL | 4:6189d844a1a2 | 71 | static_cast<void *>(0), 0U); |
QL | 0:efb9ac8d1a88 | 72 | } |
QL | 4:6189d844a1a2 | 73 | AO_Table->start(static_cast<uint8_t>(N_PHILO + 1U), |
QL | 4:6189d844a1a2 | 74 | &tableQueueSto[0], Q_DIM(tableQueueSto), |
QL | 4:6189d844a1a2 | 75 | static_cast<void *>(0), 0U); |
QL | 4:6189d844a1a2 | 76 | |
QL | 0:efb9ac8d1a88 | 77 | |
QL | 4:6189d844a1a2 | 78 | return QP::QF::run(); // run the QF application |
QL | 4:6189d844a1a2 | 79 | } |
QL | 0:efb9ac8d1a88 | 80 | |
QL | 4:6189d844a1a2 | 81 | } // namespace DPP |