Example program for the lwIP TCP/IP stack (library lwip_1_4_0_rc2) and the QP state machine framework (library qp). This program demonstrates use of lwIP in hard real-time applications, in which the TCP/IP stack is used to monitor and configure the embedded device as well as to provide remote user interface (e.g., by means of a web browser). In particular, the lwIP stack, which is not reentrant, is strictly encapsulated inside a dedicated QP state machine object (active object in QP), so interrupt locking around calls to lwIP is unnecessary. Also, the Ethernet interrupt service routine (ISR) runs very fast without performing any lengthy copy operations. All this means that hard-real-time processing can be done at the task level, especially when you use the preemptive QK kernel built into QP for executing your application. No external RTOS component is needed to achieve fully deterministic real-time response of active object tasks prioritized above the lwiP task. The lwIP-QP integration uses exclusively the event-driven lwIP API. The heavyweight Berkeley-like socket API requiring a blocking RTOS and is not used, which results in much better performance of the lwIP stack and less memory consumption. NOTE: This example compiles cleanly, but does not run just yet because the low-level Ethernet driver in the lwIP library needs to be completed. See comments in the lwip_1_4_0_rc2 library for more information.

Dependencies:   mbed

Committer:
QL
Date:
Sun Mar 27 16:50:21 2011 +0000
Revision:
0:84f3d3d7e5d9
0.9

Who changed what in which revision?

UserRevisionLine numberNew contents of line
QL 0:84f3d3d7e5d9 1 //////////////////////////////////////////////////////////////////////////////
QL 0:84f3d3d7e5d9 2 // Product: DPP application with lwIP
QL 0:84f3d3d7e5d9 3 // Last Updated for Version: 4.0.03
QL 0:84f3d3d7e5d9 4 // Date of the Last Update: Mar 16, 2009
QL 0:84f3d3d7e5d9 5 //
QL 0:84f3d3d7e5d9 6 // Q u a n t u m L e a P s
QL 0:84f3d3d7e5d9 7 // ---------------------------
QL 0:84f3d3d7e5d9 8 // innovating embedded systems
QL 0:84f3d3d7e5d9 9 //
QL 0:84f3d3d7e5d9 10 // Copyright (C) 2002-2009 Quantum Leaps, LLC. All rights reserved.
QL 0:84f3d3d7e5d9 11 //
QL 0:84f3d3d7e5d9 12 // This software may be distributed and modified under the terms of the GNU
QL 0:84f3d3d7e5d9 13 // General Public License version 2 (GPL) as published by the Free Software
QL 0:84f3d3d7e5d9 14 // Foundation and appearing in the file GPL.TXT included in the packaging of
QL 0:84f3d3d7e5d9 15 // this file. Please note that GPL Section 2[b] requires that all works based
QL 0:84f3d3d7e5d9 16 // on this software must also be made publicly available under the terms of
QL 0:84f3d3d7e5d9 17 // the GPL ("Copyleft").
QL 0:84f3d3d7e5d9 18 //
QL 0:84f3d3d7e5d9 19 // Alternatively, this software may be distributed and modified under the
QL 0:84f3d3d7e5d9 20 // terms of Quantum Leaps commercial licenses, which expressly supersede
QL 0:84f3d3d7e5d9 21 // the GPL and are specifically designed for licensees interested in
QL 0:84f3d3d7e5d9 22 // retaining the proprietary status of their code.
QL 0:84f3d3d7e5d9 23 //
QL 0:84f3d3d7e5d9 24 // Contact information:
QL 0:84f3d3d7e5d9 25 // Quantum Leaps Web site: http://www.quantum-leaps.com
QL 0:84f3d3d7e5d9 26 // e-mail: info@quantum-leaps.com
QL 0:84f3d3d7e5d9 27 //////////////////////////////////////////////////////////////////////////////
QL 0:84f3d3d7e5d9 28 #include "qp_port.h"
QL 0:84f3d3d7e5d9 29 #include "dpp.h"
QL 0:84f3d3d7e5d9 30 #include "bsp.h"
QL 0:84f3d3d7e5d9 31
QL 0:84f3d3d7e5d9 32 // Local-scope objects -------------------------------------------------------
QL 0:84f3d3d7e5d9 33 static QEvent const *l_tableQueueSto[N_PHILO];
QL 0:84f3d3d7e5d9 34 static QEvent const *l_philoQueueSto[N_PHILO][N_PHILO];
QL 0:84f3d3d7e5d9 35 static QEvent const *l_lwIPMgrQueueSto[10];
QL 0:84f3d3d7e5d9 36 static QSubscrList l_subscrSto[MAX_PUB_SIG];
QL 0:84f3d3d7e5d9 37
QL 0:84f3d3d7e5d9 38 static union SmallEvents {
QL 0:84f3d3d7e5d9 39 void *min_size;
QL 0:84f3d3d7e5d9 40 TableEvt te;
QL 0:84f3d3d7e5d9 41 // other event types to go into this pool
QL 0:84f3d3d7e5d9 42 } l_smlPoolSto[2*N_PHILO]; // storage for the small event pool
QL 0:84f3d3d7e5d9 43
QL 0:84f3d3d7e5d9 44 static union MediumEvent {
QL 0:84f3d3d7e5d9 45 void *min_size;
QL 0:84f3d3d7e5d9 46 QEvent qe;
QL 0:84f3d3d7e5d9 47 TextEvt te;
QL 0:84f3d3d7e5d9 48 // other event types to go into this pool
QL 0:84f3d3d7e5d9 49 } l_medPoolSto[4]; // storage for the medium event pool
QL 0:84f3d3d7e5d9 50
QL 0:84f3d3d7e5d9 51 //............................................................................
QL 0:84f3d3d7e5d9 52 int main(void) {
QL 0:84f3d3d7e5d9 53
QL 0:84f3d3d7e5d9 54 BSP_init(); // initialize the BSP
QL 0:84f3d3d7e5d9 55
QL 0:84f3d3d7e5d9 56 QF::init(); // initialize the framework and the underlying RT kernel
QL 0:84f3d3d7e5d9 57
QL 0:84f3d3d7e5d9 58 // object dictionaries...
QL 0:84f3d3d7e5d9 59 QS_OBJ_DICTIONARY(l_smlPoolSto);
QL 0:84f3d3d7e5d9 60 QS_OBJ_DICTIONARY(l_medPoolSto);
QL 0:84f3d3d7e5d9 61 QS_OBJ_DICTIONARY(l_lwIPMgrQueueSto);
QL 0:84f3d3d7e5d9 62 QS_OBJ_DICTIONARY(l_philoQueueSto[0]);
QL 0:84f3d3d7e5d9 63 QS_OBJ_DICTIONARY(l_philoQueueSto[1]);
QL 0:84f3d3d7e5d9 64 QS_OBJ_DICTIONARY(l_philoQueueSto[2]);
QL 0:84f3d3d7e5d9 65 QS_OBJ_DICTIONARY(l_philoQueueSto[3]);
QL 0:84f3d3d7e5d9 66 QS_OBJ_DICTIONARY(l_philoQueueSto[4]);
QL 0:84f3d3d7e5d9 67 QS_OBJ_DICTIONARY(l_tableQueueSto);
QL 0:84f3d3d7e5d9 68
QL 0:84f3d3d7e5d9 69 QF::psInit(l_subscrSto, Q_DIM(l_subscrSto)); // init publish-subscribe
QL 0:84f3d3d7e5d9 70
QL 0:84f3d3d7e5d9 71 // initialize event pools...
QL 0:84f3d3d7e5d9 72 QF::poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
QL 0:84f3d3d7e5d9 73 QF::poolInit(l_medPoolSto, sizeof(l_medPoolSto), sizeof(l_medPoolSto[0]));
QL 0:84f3d3d7e5d9 74
QL 0:84f3d3d7e5d9 75 // start the active objects...
QL 0:84f3d3d7e5d9 76 AO_LwIPMgr->start((uint8_t)1,
QL 0:84f3d3d7e5d9 77 l_lwIPMgrQueueSto, Q_DIM(l_lwIPMgrQueueSto),
QL 0:84f3d3d7e5d9 78 (void *)0, 0, (QEvent *)0);
QL 0:84f3d3d7e5d9 79 uint8_t n;
QL 0:84f3d3d7e5d9 80 for (n = 0; n < N_PHILO; ++n) {
QL 0:84f3d3d7e5d9 81 AO_Philo[n]->start((uint8_t)(n + 2),
QL 0:84f3d3d7e5d9 82 l_philoQueueSto[n], Q_DIM(l_philoQueueSto[n]),
QL 0:84f3d3d7e5d9 83 (void *)0, 0, (QEvent *)0);
QL 0:84f3d3d7e5d9 84 }
QL 0:84f3d3d7e5d9 85 AO_Table->start((uint8_t)(N_PHILO + 2),
QL 0:84f3d3d7e5d9 86 l_tableQueueSto, Q_DIM(l_tableQueueSto),
QL 0:84f3d3d7e5d9 87 (void *)0, 0, (QEvent *)0);
QL 0:84f3d3d7e5d9 88
QL 0:84f3d3d7e5d9 89 QF::run(); // run the QF application
QL 0:84f3d3d7e5d9 90
QL 0:84f3d3d7e5d9 91 return 0;
QL 0:84f3d3d7e5d9 92 }
QL 0:84f3d3d7e5d9 93