Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:7225ff529d1c, committed 2011-04-27
- Comitter:
- t_lark
- Date:
- Wed Apr 27 17:11:08 2011 +0000
- Commit message:
- .00000001
Changed in this revision
diff -r 000000000000 -r 7225ff529d1c bsp.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bsp.cpp Wed Apr 27 17:11:08 2011 +0000
@@ -0,0 +1,304 @@
+//////////////////////////////////////////////////////////////////////////////
+// Model: Network.qm
+// File: ./bsp.cpp
+//
+// This file has been generated automatically by QP Modeler (QM).
+// DO NOT EDIT THIS FILE MANUALLY.
+//
+// Please visit www.state-machine.com/qm for more information.
+//////////////////////////////////////////////////////////////////////////////
+#include "qp_port.h"
+#include "network.h"
+#include "bsp.h"
+#include "LPC17xx.h"
+
+Q_DEFINE_THIS_FILE
+
+// Local-scope objects -------------------------------------------------------
+enum ISR_Priorities { // ISR priorities starting from the highest urgency
+ GPIOPORTA_PRIO,
+ SYSTICK_PRIO,
+ // ...
+};
+
+#define LED_PORT LPC_GPIO1
+#define LED1_BIT (1U << 18)
+#define LED2_BIT (1U << 20)
+#define LED3_BIT (1U << 21)
+#define LED4_BIT (1U << 23)
+
+#ifdef Q_SPY
+ #include "mbed.h" // mbed is used only for the built-in serial
+
+ QSTimeCtr l_tickTime;
+ QSTimeCtr l_tickPeriod;
+
+ #define QSPY_BAUD_RATE 115200
+
+ enum AppRecords { // application-specific trace records
+ PELICAN_STAT = QS_USER,
+ IO_STAT
+ };
+
+ Serial l_qspy(USBTX, USBRX);
+#endif
+
+//............................................................................
+extern "C" void SysTick_Handler(void) {
+ QK_ISR_ENTRY(); // inform the QK kernel of entering the ISR
+
+#ifdef Q_SPY
+ uint32_t volatile dummy = SysTick->CTRL; // clear the COUNTFLAG in SysTick
+ l_tickTime += l_tickPeriod; // account for the clock rollover
+#endif
+
+ QF::tick(); // process all armed time events
+
+ QK_ISR_EXIT(); // inform the QK kernel of exiting the ISR
+}
+
+//............................................................................
+static N4S2 l_N4S2;
+
+
+DigitalIn N4S2 :: geomSenses[N_FACES] = {(p17), (p18), (p19), (p20)};
+DigitalOut N4S2 :: geomTxs[S_FACES] = {(p21), (p22)};
+
+SerialHalfDuplex N4S2 :: sPort1(p9,p10);//common n bus
+SerialHalfDuplex N4S2 :: sPort2(p13,p14);//common n bus
+SerialHalfDuplex N4S2 :: sPorts[S_FACES] = {sPort1,sPort2}; //seg ports
+SerialHalfDuplex N4S2 :: nPort(p28,p27);//common n bus
+
+DigitalOut N4S2 :: sPort1ETx(p11);
+DigitalOut N4S2 :: sPort2ETx(p12);
+DigitalOut N4S2 :: nPortETx(p29);
+DigitalOut N4S2 :: sPortETxs[S_FACES] = {sPort1ETx, sPort2ETx};
+
+DigitalOut N4S2 :: leds[] = {(LED1), (LED2), (LED3), (LED4)};
+
+
+//............................................................................
+void BSP_init(void) {
+ SystemInit(); // initialize the clocking system
+
+ // set LED port to output
+ LED_PORT->FIODIR |= (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT);
+
+ // clear the LEDs
+ LED_PORT->FIOCLR = (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT);
+
+ if (QS_INIT((void *)0) == 0) { // initialize the QS software tracing
+ Q_ERROR();
+ }
+}
+//............................................................................
+void BSP_signalCars(BSP_CarsSignal sig) {
+ /*
+ switch (sig) {
+ case CARS_RED:
+ LED_PORT->FIOSET = LED1_BIT; // turn the LED1 on
+ LED_PORT->FIOCLR = LED2_BIT | LED3_BIT; // turn the LED2&3 off
+ break;
+ case CARS_YELLOW:
+ LED_PORT->FIOSET = LED2_BIT; // turn the LED2 on
+ LED_PORT->FIOCLR = LED1_BIT | LED3_BIT; // turn the LED1&3 off
+ break;
+ case CARS_GREEN:
+ LED_PORT->FIOSET = LED3_BIT; // turn the LED3 on
+ LED_PORT->FIOCLR = LED1_BIT | LED2_BIT; // turn the LED1&2 off
+ break;
+ case CARS_BLANK:
+ LED_PORT->FIOCLR = LED1_BIT | LED2_BIT | LED3_BIT; //turn all off
+ break;
+ }*/
+}
+//............................................................................
+void BSP_signalPeds(BSP_PedsSignal sig) {
+ /*
+ switch (sig) {
+ case PEDS_DONT_WALK:
+ LED_PORT->FIOSET = LED4_BIT; // turn the LED4 on
+ break;
+ case PEDS_WALK:
+ LED_PORT->FIOCLR = LED4_BIT; // turn the LED4 off
+ break;
+ case PEDS_BLANK:
+ LED_PORT->FIOCLR = LED4_BIT; // turn the LED4 off
+ break;
+ }*/
+}
+//............................................................................
+void BSP_showState(char const *state) {
+ QS_BEGIN(PELICAN_STAT, AO_Pelican) // application-specific record
+ QS_STR(state); // state string
+ QS_END()
+}
+
+//............................................................................
+void BSP_signalSense(BSP_SenseSignal sig) {
+ switch (sig) {
+ case SENSE_1_CON:
+ LED_PORT->FIOSET = LED1_BIT; // turn the LED4 on
+ break;
+ case SENSE_1_DIS:
+ LED_PORT->FIOCLR = LED1_BIT; // turn the LED4 off
+ break;
+ }
+}
+
+//............................................................................
+void BSP_chk_io() {
+ QS_BEGIN(IO_STAT, AO_Poll) // application-specific record
+ QS_STR("chk_io_called");
+ static int prev[4] = {0,0,0,0};
+ for(int i=0;i<l_N4S2.N_FACES;i++){
+ int newVal = l_N4S2.geomSenses[i];
+ if(newVal == 0 && prev[i] !=0){
+ QF::publish(&sense1_N1_Down_Evt);
+ }else if(newVal != 0 && prev[i] ==0){
+ QF::publish(&sense1_N1_Up_Evt);
+ }
+ prev[i] = newVal;
+ }
+ QS_END()
+}
+
+//............................................................................
+void QF::onStartup(void) {
+ // set up the SysTick timer to fire at BSP_TICKS_PER_SEC rate
+ SysTick_Config(SystemCoreClock / BSP_TICKS_PER_SEC);
+
+ // set priorities of all interrupts in the system...
+ NVIC_SetPriority(SysTick_IRQn, SYSTICK_PRIO);
+ NVIC_SetPriority(EINT0_IRQn, GPIOPORTA_PRIO);
+
+ NVIC_EnableIRQ(EINT0_IRQn);
+}
+//............................................................................
+void QF::onCleanup(void) {
+}
+//............................................................................
+void QK::onIdle(void) {
+#ifdef Q_SPY
+ if (l_qspy.writeable()) {
+ QF_INT_LOCK(dummy);
+ uint16_t b = QS::getByte();
+ QF_INT_UNLOCK(dummy);
+ if (b != QS_EOD) {
+ l_qspy.putc((uint8_t)b);
+ }
+ }
+#else
+ // put the CPU and peripherals to the low-power mode
+ // you might need to customize the clock management for your application,
+ // see the datasheet for your particular Cortex-M3 MCU.
+ __WFI();
+#endif
+}
+
+//............................................................................
+void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
+ (void)file; // avoid compiler warning
+ (void)line; // avoid compiler warning
+ QS_BEGIN_(QS_ASSERT, 0, 0)
+ QS_TIME_(); // time stamp
+ QS_U16_((uint16_t)line); // the line number
+ QS_STR_(file); // the file name
+ QS_END_()
+ QS::onFlush();
+
+ QF_INT_LOCK(dummy); // make sure that all interrupts are disabled
+ // light up all LEDs
+ LED_PORT->FIOSET = (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT);
+
+ for (;;) { // NOTE: replace the loop with reset for final version
+ }
+}
+
+//----------------------------------------------------------------------------
+#ifdef Q_SPY
+//............................................................................
+uint8_t QS::onStartup(void const *arg) {
+ static uint8_t qsBuf[6*256]; // buffer for Quantum Spy
+ initBuf(qsBuf, sizeof(qsBuf));
+
+ l_qspy.baud(QSPY_BAUD_RATE);
+
+ l_tickPeriod = SystemCoreClock / BSP_TICKS_PER_SEC;
+ l_tickTime = l_tickPeriod; // to start the timestamp at zero
+
+ // setup the QS filters...
+ QS_FILTER_ON(QS_ALL_RECORDS);
+
+// QS_FILTER_OFF(QS_QEP_STATE_EMPTY);
+// QS_FILTER_OFF(QS_QEP_STATE_ENTRY);
+// QS_FILTER_OFF(QS_QEP_STATE_EXIT);
+// QS_FILTER_OFF(QS_QEP_STATE_INIT);
+// QS_FILTER_OFF(QS_QEP_INIT_TRAN);
+// QS_FILTER_OFF(QS_QEP_INTERN_TRAN);
+// QS_FILTER_OFF(QS_QEP_TRAN);
+// QS_FILTER_OFF(QS_QEP_IGNORED);
+
+// QS_FILTER_OFF(QS_QF_ACTIVE_ADD);
+// QS_FILTER_OFF(QS_QF_ACTIVE_REMOVE);
+// QS_FILTER_OFF(QS_QF_ACTIVE_SUBSCRIBE);
+// QS_FILTER_OFF(QS_QF_ACTIVE_UNSUBSCRIBE);
+// QS_FILTER_OFF(QS_QF_ACTIVE_POST_FIFO);
+// QS_FILTER_OFF(QS_QF_ACTIVE_POST_LIFO);
+// QS_FILTER_OFF(QS_QF_ACTIVE_GET);
+// QS_FILTER_OFF(QS_QF_ACTIVE_GET_LAST);
+// QS_FILTER_OFF(QS_QF_EQUEUE_INIT);
+// QS_FILTER_OFF(QS_QF_EQUEUE_POST_FIFO);
+// QS_FILTER_OFF(QS_QF_EQUEUE_POST_LIFO);
+// QS_FILTER_OFF(QS_QF_EQUEUE_GET);
+// QS_FILTER_OFF(QS_QF_EQUEUE_GET_LAST);
+// QS_FILTER_OFF(QS_QF_MPOOL_INIT);
+// QS_FILTER_OFF(QS_QF_MPOOL_GET);
+// QS_FILTER_OFF(QS_QF_MPOOL_PUT);
+// QS_FILTER_OFF(QS_QF_PUBLISH);
+// QS_FILTER_OFF(QS_QF_NEW);
+// QS_FILTER_OFF(QS_QF_GC_ATTEMPT);
+// QS_FILTER_OFF(QS_QF_GC);
+ QS_FILTER_OFF(QS_QF_TICK);
+// QS_FILTER_OFF(QS_QF_TIMEEVT_ARM);
+// QS_FILTER_OFF(QS_QF_TIMEEVT_AUTO_DISARM);
+// QS_FILTER_OFF(QS_QF_TIMEEVT_DISARM_ATTEMPT);
+// QS_FILTER_OFF(QS_QF_TIMEEVT_DISARM);
+// QS_FILTER_OFF(QS_QF_TIMEEVT_REARM);
+// QS_FILTER_OFF(QS_QF_TIMEEVT_POST);
+ QS_FILTER_OFF(QS_QF_INT_LOCK);
+ QS_FILTER_OFF(QS_QF_INT_UNLOCK);
+ QS_FILTER_OFF(QS_QF_ISR_ENTRY);
+ QS_FILTER_OFF(QS_QF_ISR_EXIT);
+
+// QS_FILTER_OFF(QS_QK_MUTEX_LOCK);
+// QS_FILTER_OFF(QS_QK_MUTEX_UNLOCK);
+// QS_FILTER_OFF(QS_QK_SCHEDULE);
+
+ return (uint8_t)1; // return success
+}
+//............................................................................
+void QS::onCleanup(void) {
+}
+//............................................................................
+QSTimeCtr QS::onGetTime(void) { // invoked with interrupts locked
+ if ((SysTick->CTRL & 0x00000100) == 0) { // COUNTFLAG no set?
+ return l_tickTime - (QSTimeCtr)SysTick->VAL;
+ }
+ else { // the rollover occured, but the SysTick_ISR did not run yet
+ return l_tickTime + l_tickPeriod - (QSTimeCtr)SysTick->VAL;
+ }
+}
+//............................................................................
+void QS::onFlush(void) {
+ uint16_t b;
+ QF_INT_LOCK(dummy);
+ while ((b = QS::getByte()) != QS_EOD) {
+ while (!l_qspy.writeable()) { // wait until serial port is writable
+ }
+ l_qspy.putc((uint8_t)b);
+ }
+ QF_INT_UNLOCK(dummy);
+}
+#endif // Q_SPY
+//----------------------------------------------------------------------------
diff -r 000000000000 -r 7225ff529d1c bsp.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bsp.h Wed Apr 27 17:11:08 2011 +0000
@@ -0,0 +1,67 @@
+//////////////////////////////////////////////////////////////////////////////
+// Model: Network.qm
+// File: ./bsp.h
+//
+// This file has been generated automatically by QP Modeler (QM).
+// DO NOT EDIT THIS FILE MANUALLY.
+//
+// Please visit www.state-machine.com/qm for more information.
+//////////////////////////////////////////////////////////////////////////////
+#ifndef bsp_h
+#define bsp_h
+
+#include "mbed.h"
+
+// System clock tick rate [Hz]
+#define BSP_TICKS_PER_SEC 100
+
+enum BSP_CarsSignal {
+ CARS_RED, CARS_YELLOW, CARS_GREEN, CARS_BLANK
+};
+
+enum BSP_PedsSignal {
+ PEDS_DONT_WALK, PEDS_WALK, PEDS_BLANK
+};
+
+enum BSP_SenseSignal {
+ SENSE_1_CON, SENSE_1_DIS, SENSE
+};
+
+void BSP_init(void);
+void BSP_signalCars(BSP_CarsSignal sig);
+void BSP_signalPeds(BSP_PedsSignal sig);
+void BSP_showState(char const *state);
+
+void BSP_signalSense(BSP_SenseSignal sig);
+
+void BSP_chk_io();
+
+
+class N4S2 {
+
+public:
+ static const int N_FACES = 4;
+ static const int S_FACES = 2;
+
+ static DigitalIn geomSenses[N_FACES]; // geomSenses [face], face = 1-4
+ static DigitalOut geomTxs[S_FACES]; // geomTxs [face], face = 1-*2*
+
+ static SerialHalfDuplex sPort1;
+ static SerialHalfDuplex sPort2;
+ static SerialHalfDuplex sPorts[2]; //seg ports in array format
+ static SerialHalfDuplex nPort;//common n bus
+
+ static DigitalOut sPort1ETx; // enable Tx for sPort 1
+ static DigitalOut sPort2ETx; // enable Tx for sPort 2
+ static DigitalOut nPortETx; // enable Tx for nPort
+ static DigitalOut sPortETxs[S_FACES]; //seg ports enables in array format
+
+ static DigitalOut leds[];
+
+ N4S2(){}
+
+
+protected:
+};
+
+#endif // bsp_h
diff -r 000000000000 -r 7225ff529d1c main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Apr 27 17:11:08 2011 +0000
@@ -0,0 +1,47 @@
+//////////////////////////////////////////////////////////////////////////////
+// Model: Network.qm
+// File: ./main.cpp
+//
+// This file has been generated automatically by QP Modeler (QM).
+// DO NOT EDIT THIS FILE MANUALLY.
+//
+// Please visit www.state-machine.com/qm for more information.
+//////////////////////////////////////////////////////////////////////////////
+#include "qp_port.h"
+#include "network.h"
+#include "bsp.h"
+
+// Local-scope objects -------------------------------------------------------
+static QEvent const *l_pelicanQueueSto[5];
+static QEvent const *l_pollQueueSto[5];
+static QEvent const *l_sense1_N1_Sto[5];
+
+static QSubscrList l_subscrSto[MAX_PUB_SIG];
+static union {
+ void *m0;
+ QEvent m1;
+} l_smlPoolSto[10]; // storage for the small event pool
+
+//............................................................................
+int main(void) {
+ BSP_init(); // initialize the BSP
+ QF::init(); // initialize the framework and the underlying RT kernel
+ // object dictionaries...
+ QS_OBJ_DICTIONARY(l_smlPoolSto);
+ QS_OBJ_DICTIONARY(l_pelicanQueueSto);
+ QS_OBJ_DICTIONARY(l_pollQueueSto);
+ QS_OBJ_DICTIONARY(l_sense1_N1_Sto);
+
+ 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]));
+
+ // start the active objects...
+ //AO_Pelican ->start(3, l_pelicanQueueSto, Q_DIM(l_pelicanQueueSto));
+ AO_Poll ->start(1, l_pollQueueSto, Q_DIM(l_pollQueueSto));
+ AO_Sense1_N1->start(2, l_sense1_N1_Sto, Q_DIM(l_sense1_N1_Sto));//1st param is priority
+
+ QF::run(); // run the QF application
+
+ return 0;
+}
diff -r 000000000000 -r 7225ff529d1c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Apr 27 17:11:08 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912
diff -r 000000000000 -r 7225ff529d1c network.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/network.cpp Wed Apr 27 17:11:08 2011 +0000
@@ -0,0 +1,520 @@
+//////////////////////////////////////////////////////////////////////////////
+// Model: Network.qm
+// File: ./network.cpp
+//
+// This file has been generated automatically by QP Modeler (QM).
+// DO NOT EDIT THIS FILE MANUALLY.
+//
+// Please visit www.state-machine.com/qm for more information.
+//////////////////////////////////////////////////////////////////////////////
+#include "qp_port.h"
+#include "bsp.h"
+#include "network.h"
+
+Q_DEFINE_THIS_FILE
+
+enum PelicanTimeouts { // various timeouts in ticks
+ CARS_GREEN_MIN_TOUT = BSP_TICKS_PER_SEC * 8, // min green for cars
+ CARS_YELLOW_TOUT = BSP_TICKS_PER_SEC * 3, // yellow for cars
+ PEDS_WALK_TOUT = BSP_TICKS_PER_SEC * 3, // walking time for peds
+ PEDS_FLASH_TOUT = BSP_TICKS_PER_SEC / 5, // flashing timeout for peds
+ PEDS_FLASH_NUM = 5*2, // number of flashes for peds
+ OFF_FLASH_TOUT = BSP_TICKS_PER_SEC / 2 // flashing timeout when off
+};
+
+enum SenseTimeouts { // various timeouts in ticks
+ SENSE1_N1_TOUT = BSP_TICKS_PER_SEC * 3,
+ TOGGLE_TOUT = BSP_TICKS_PER_SEC/5
+};
+
+enum PollTimeouts { // various timeouts in ticks
+ POLL_TOUT = BSP_TICKS_PER_SEC /10, // poll wait
+};
+
+// Pelican class -------------------------------------------------------------
+// $(components::Pelican) ....................................................
+class Pelican : public QActive {
+private:
+ QTimeEvt m_timeout;
+ uint8_t m_flashCtr;
+
+public:
+ Pelican() : QActive((QStateHandler)&Pelican::initial), m_timeout(TIMEOUT_SIG) {
+ }
+
+protected:
+ static QState initial(Pelican *me, QEvent const *e);
+ static QState operational(Pelican *me, QEvent const *e);
+ static QState carsEnabled(Pelican *me, QEvent const *e);
+ static QState carsGreen(Pelican *me, QEvent const *e);
+ static QState carsGreenNoPed(Pelican *me, QEvent const *e);
+ static QState carsGreenInt(Pelican *me, QEvent const *e);
+ static QState carsGreenPedWait(Pelican *me, QEvent const *e);
+ static QState carsYellow(Pelican *me, QEvent const *e);
+ static QState pedsEnabled(Pelican *me, QEvent const *e);
+ static QState pedsWalk(Pelican *me, QEvent const *e);
+ static QState pedsFlash(Pelican *me, QEvent const *e);
+ static QState offline(Pelican *me, QEvent const *e);
+};
+// $(components::Sense1_N1) ..................................................
+class Sense1_N1 : public QActive {
+private:
+ QTimeEvt m_timeout;
+
+public:
+ Sense1_N1();
+
+protected:
+ static QState initial(Sense1_N1 *me, QEvent const *e);
+ static QState disconnected(Sense1_N1 *me, QEvent const *e);
+ static QState connected(Sense1_N1 *me, QEvent const *e);
+ static QState toggle_sense(Sense1_N1 *me, QEvent const *e);
+ static QState detect_down(Sense1_N1 *me, QEvent const *e);
+};
+// $(components::Poll) .......................................................
+class Poll : public QActive {
+private:
+ QTimeEvt m_timeout;
+
+public:
+ Poll();
+
+protected:
+ static QState initial(Poll *me, QEvent const *e);
+ static QState poll(Poll *me, QEvent const *e);
+};
+
+// Local objects -------------------------------------------------------------
+static Pelican l_Pelican; // the single instance of Pelican active object
+static Sense1_N1 l_Sense1_N1; // the single instance of Pelican active
+static Poll l_Poll; // the single instance of Poll
+
+
+// Global objects ------------------------------------------------------------
+QActive * const AO_Pelican = &l_Pelican; // the opaque pointer
+QActive * const AO_Sense1_N1 = &l_Sense1_N1; // the opaque pointer
+QActive * const AO_Poll = &l_Poll; // the opaque pointer
+
+// Pelican class definition --------------------------------------------------
+// $(components::Pelican) ....................................................
+
+// $(components::Pelican::Statechart) ........................................
+// @(/1/0/3/0)
+QState Pelican::initial(Pelican *me, QEvent const *e) {
+ me->subscribe(PEDS_WAITING_SIG);
+
+ QS_OBJ_DICTIONARY(&l_Pelican);
+ QS_OBJ_DICTIONARY(&l_Pelican.m_timeout);
+
+ QS_FUN_DICTIONARY(&QHsm::top);
+ QS_FUN_DICTIONARY(&Pelican::initial);
+ QS_FUN_DICTIONARY(&Pelican::offline);
+ QS_FUN_DICTIONARY(&Pelican::operational);
+ QS_FUN_DICTIONARY(&Pelican::carsEnabled);
+ QS_FUN_DICTIONARY(&Pelican::carsGreen);
+ QS_FUN_DICTIONARY(&Pelican::carsGreenNoPed);
+ QS_FUN_DICTIONARY(&Pelican::carsGreenPedWait);
+ QS_FUN_DICTIONARY(&Pelican::carsGreenInt);
+ QS_FUN_DICTIONARY(&Pelican::carsYellow);
+ QS_FUN_DICTIONARY(&Pelican::pedsEnabled);
+ QS_FUN_DICTIONARY(&Pelican::pedsWalk);
+ QS_FUN_DICTIONARY(&Pelican::pedsFlash);
+
+ QS_SIG_DICTIONARY(PEDS_WAITING_SIG, 0); // global signals
+ QS_SIG_DICTIONARY(ON_SIG, 0);
+ QS_SIG_DICTIONARY(OFF_SIG, 0);
+
+ QS_SIG_DICTIONARY(TIMEOUT_SIG, &l_Pelican); // just for Pelican
+ return Q_TRAN(&Pelican::operational);
+}
+// $(components::Pelican::Statechart::operational) ...........................
+QState Pelican::operational(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/1)
+ case Q_ENTRY_SIG: {
+ BSP_signalCars(CARS_RED);
+ BSP_signalPeds(PEDS_DONT_WALK);
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/0)
+ case Q_INIT_SIG: {
+ return Q_TRAN(&Pelican::carsEnabled);
+ }
+ // @(/1/0/3/1/1)
+ case OFF_SIG: {
+ return Q_TRAN(&Pelican::offline);
+ }
+ }
+ return Q_SUPER(&QHsm::top);
+}
+// $(components::Pelican::Statechart::operational::carsEnabled) ..............
+QState Pelican::carsEnabled(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/1/2)
+ case Q_EXIT_SIG: {
+ BSP_signalCars(CARS_RED);
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/2/0)
+ case Q_INIT_SIG: {
+ return Q_TRAN(&Pelican::carsGreen);
+ }
+ }
+ return Q_SUPER(&Pelican::operational);
+}
+// $(components::Pelican::Statechart::operational::carsEnabled::carsGreen) ...
+QState Pelican::carsGreen(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/1/2/1)
+ case Q_ENTRY_SIG: {
+ BSP_signalCars(CARS_GREEN);
+ me->m_timeout.postIn(me, CARS_GREEN_MIN_TOUT);
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/2/1)
+ case Q_EXIT_SIG: {
+ me->m_timeout.disarm();
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/2/1/0)
+ case Q_INIT_SIG: {
+ return Q_TRAN(&Pelican::carsGreenNoPed);
+ }
+ }
+ return Q_SUPER(&Pelican::carsEnabled);
+}
+// $(components::Pelican::Statechart::operational::carsEnabled::carsGreen::carsGreenNoPed)
+QState Pelican::carsGreenNoPed(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/1/2/1/1)
+ case Q_ENTRY_SIG: {
+ BSP_showState("carsGreenNoPed");
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/2/1/1/0)
+ case PEDS_WAITING_SIG: {
+ return Q_TRAN(&Pelican::carsGreenPedWait);
+ }
+ // @(/1/0/3/1/2/1/1/1)
+ case TIMEOUT_SIG: {
+ return Q_TRAN(&Pelican::carsGreenInt);
+ }
+ }
+ return Q_SUPER(&Pelican::carsGreen);
+}
+// $(components::Pelican::Statechart::operational::carsEnabled::carsGreen::carsGreenInt)
+QState Pelican::carsGreenInt(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/1/2/1/2)
+ case Q_ENTRY_SIG: {
+ BSP_showState("carsGreenInt");
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/2/1/2/0)
+ case PEDS_WAITING_SIG: {
+ return Q_TRAN(&Pelican::carsYellow);
+ }
+ }
+ return Q_SUPER(&Pelican::carsGreen);
+}
+// $(components::Pelican::Statechart::operational::carsEnabled::carsGreen::carsGreenPedWait)
+QState Pelican::carsGreenPedWait(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/1/2/1/3)
+ case Q_ENTRY_SIG: {
+ BSP_showState("carsGreenPedWait");
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/2/1/3/0)
+ case TIMEOUT_SIG: {
+ return Q_TRAN(&Pelican::carsYellow);
+ }
+ }
+ return Q_SUPER(&Pelican::carsGreen);
+}
+// $(components::Pelican::Statechart::operational::carsEnabled::carsYellow) ..
+QState Pelican::carsYellow(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/1/2/2)
+ case Q_ENTRY_SIG: {
+ BSP_showState("carsYellow");
+ BSP_signalCars(CARS_YELLOW);
+ me->m_timeout.postIn(me, CARS_YELLOW_TOUT);
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/2/2)
+ case Q_EXIT_SIG: {
+ me->m_timeout.disarm();
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/2/2/0)
+ case TIMEOUT_SIG: {
+ return Q_TRAN(&Pelican::pedsEnabled);
+ }
+ }
+ return Q_SUPER(&Pelican::carsEnabled);
+}
+// $(components::Pelican::Statechart::operational::pedsEnabled) ..............
+QState Pelican::pedsEnabled(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/1/3)
+ case Q_EXIT_SIG: {
+ BSP_signalPeds(PEDS_DONT_WALK);
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/3/0)
+ case Q_INIT_SIG: {
+ return Q_TRAN(&Pelican::pedsWalk);
+ }
+ }
+ return Q_SUPER(&Pelican::operational);
+}
+// $(components::Pelican::Statechart::operational::pedsEnabled::pedsWalk) ....
+QState Pelican::pedsWalk(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/1/3/1)
+ case Q_ENTRY_SIG: {
+ BSP_showState("pedsWalk");
+ BSP_signalPeds(PEDS_WALK);
+ me->m_timeout.postIn(me, PEDS_WALK_TOUT);
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/3/1)
+ case Q_EXIT_SIG: {
+ me->m_timeout.disarm();
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/3/1/0)
+ case TIMEOUT_SIG: {
+ return Q_TRAN(&Pelican::pedsFlash);
+ }
+ }
+ return Q_SUPER(&Pelican::pedsEnabled);
+}
+// $(components::Pelican::Statechart::operational::pedsEnabled::pedsFlash) ...
+QState Pelican::pedsFlash(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/1/3/2)
+ case Q_ENTRY_SIG: {
+ BSP_showState("pedsFlash");
+ me->m_timeout.postEvery(me, PEDS_FLASH_TOUT);
+ me->m_flashCtr = PEDS_FLASH_NUM*2 + 1;
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/3/2)
+ case Q_EXIT_SIG: {
+ me->m_timeout.disarm();
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/3/2/0)
+ case TIMEOUT_SIG: {
+ // @(/1/0/3/1/3/2/0/0)
+ if (me->m_flashCtr != 0) {
+ --me->m_flashCtr;
+ // @(/1/0/3/1/3/2/0/0/0)
+ if ((me->m_flashCtr & 1) == 0) {
+ BSP_signalPeds(PEDS_DONT_WALK);
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/1/3/2/0/0/1)
+ else {
+ BSP_signalPeds(PEDS_BLANK);
+ return Q_HANDLED();
+ }
+ }
+ // @(/1/0/3/1/3/2/0/1)
+ else {
+ return Q_TRAN(&Pelican::carsEnabled);
+ }
+ }
+ }
+ return Q_SUPER(&Pelican::pedsEnabled);
+}
+// $(components::Pelican::Statechart::offline) ...............................
+QState Pelican::offline(Pelican *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/0/3/2)
+ case Q_ENTRY_SIG: {
+ BSP_showState("offline");
+ me->m_timeout.postEvery(me, OFF_FLASH_TOUT);
+ me->m_flashCtr = 0;
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/2)
+ case Q_EXIT_SIG: {
+ me->m_timeout.disarm();
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/2/0)
+ case TIMEOUT_SIG: {
+ me->m_flashCtr ^= 1;
+ // @(/1/0/3/2/0/0)
+ if ((me->m_flashCtr & 1) == 0) {
+ BSP_signalCars(CARS_RED);
+ BSP_signalPeds(PEDS_DONT_WALK);
+ return Q_HANDLED();
+ }
+ // @(/1/0/3/2/0/1)
+ else {
+ BSP_signalCars(CARS_BLANK);
+ BSP_signalPeds(PEDS_BLANK);
+ return Q_HANDLED();
+ }
+ }
+ // @(/1/0/3/2/1)
+ case ON_SIG: {
+ return Q_TRAN(&Pelican::operational);
+ }
+ }
+ return Q_SUPER(&QHsm::top);
+}
+
+// $(components::Sense1_N1) ..................................................
+// $(components::Sense1_N1::Sense1_N1) .......................................
+Sense1_N1::Sense1_N1() : QActive((QStateHandler)&Sense1_N1::initial), m_timeout(TIMEOUT_SIG) {
+}
+// $(components::Sense1_N1::Statechart) ......................................
+// @(/1/2/2/0)
+QState Sense1_N1::initial(Sense1_N1 *me, QEvent const *e) {
+ me->subscribe(SENSE1_N1_UP_SIG);
+ me->subscribe(SENSE1_N1_DOWN_SIG);
+ me->subscribe(SENSE_N1_SIG);
+
+ QS_OBJ_DICTIONARY(&l_Sense1_N1);
+ QS_OBJ_DICTIONARY(&l_Sense1_N1.m_timeout);
+
+ QS_FUN_DICTIONARY(&QHsm::top);
+ QS_FUN_DICTIONARY(&Sense1_N1::initial);
+ QS_FUN_DICTIONARY(&Sense1_N1::disconnected);
+ QS_FUN_DICTIONARY(&Sense1_N1::connected);
+ QS_FUN_DICTIONARY(&Sense1_N1::toggle_sense);
+ QS_FUN_DICTIONARY(&Sense1_N1::detect_down);
+
+ QS_SIG_DICTIONARY(SENSE1_N1_UP_SIG, 0); // global signals
+ QS_SIG_DICTIONARY(SENSE1_N1_DOWN_SIG,0);
+ QS_SIG_DICTIONARY(SENSE_N1_SIG,0);
+
+ QS_SIG_DICTIONARY(TIMEOUT_SIG, &l_Sense1_N1); // just for Sense1_N1
+ return Q_TRAN(&Sense1_N1::disconnected);
+}
+// $(components::Sense1_N1::Statechart::disconnected) ........................
+QState Sense1_N1::disconnected(Sense1_N1 *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/2/2/1)
+ case Q_ENTRY_SIG: {
+ BSP_signalSense(SENSE_1_DIS);
+ return Q_HANDLED();
+ }
+ // @(/1/2/2/1/0)
+ case SENSE1_N1_UP_SIG: {
+ return Q_TRAN(&Sense1_N1::connected);
+ }
+ }
+ return Q_SUPER(&QHsm::top);
+}
+// $(components::Sense1_N1::Statechart::connected) ...........................
+QState Sense1_N1::connected(Sense1_N1 *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/2/2/2)
+ case Q_ENTRY_SIG: {
+ BSP_signalSense(SENSE_1_CON);
+ return Q_HANDLED();
+ }
+ // @(/1/2/2/2/0)
+ case SENSE1_N1_DOWN_SIG: {
+ return Q_TRAN(&Sense1_N1::disconnected);
+ }
+ // @(/1/2/2/2/1)
+ case SENSE_N1_SIG: {
+ return Q_TRAN(&Sense1_N1::toggle_sense);
+ }
+ }
+ return Q_SUPER(&QHsm::top);
+}
+// $(components::Sense1_N1::Statechart::toggle_sense) ........................
+QState Sense1_N1::toggle_sense(Sense1_N1 *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/2/2/3)
+ case Q_ENTRY_SIG: {
+ me->m_timeout.postIn(me, TOGGLE_TOUT);
+ return Q_HANDLED();
+ }
+ // @(/1/2/2/3)
+ case Q_EXIT_SIG: {
+ me->m_timeout.disarm();
+ return Q_HANDLED();
+ }
+ // @(/1/2/2/3/0)
+ case TIMEOUT_SIG: {
+ return Q_TRAN(&Sense1_N1::connected);
+ }
+ // @(/1/2/2/3/1)
+ case SENSE1_N1_DOWN_SIG: {
+ return Q_TRAN(&Sense1_N1::detect_down);
+ }
+ }
+ return Q_SUPER(&QHsm::top);
+}
+// $(components::Sense1_N1::Statechart::detect_down) .........................
+QState Sense1_N1::detect_down(Sense1_N1 *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/2/2/4)
+ case Q_ENTRY_SIG: {
+ me->m_timeout.postIn(me, TOGGLE_TOUT);
+ return Q_HANDLED();
+ }
+ // @(/1/2/2/4)
+ case Q_EXIT_SIG: {
+ me->m_timeout.disarm();
+ return Q_HANDLED();
+ }
+ // @(/1/2/2/4/0)
+ case TIMEOUT_SIG: {
+ return Q_TRAN(&Sense1_N1::disconnected);
+ }
+ // @(/1/2/2/4/1)
+ case SENSE1_N1_UP_SIG: {
+ return Q_TRAN(&Sense1_N1::connected);
+ }
+ }
+ return Q_SUPER(&QHsm::top);
+}
+
+// $(components::Poll) .......................................................
+// $(components::Poll::Poll) .................................................
+Poll::Poll() : QActive((QStateHandler)&Poll::initial), m_timeout(TIMEOUT_SIG) {
+}
+// $(components::Poll::Statechart) ...........................................
+// @(/1/1/2/0)
+QState Poll::initial(Poll *me, QEvent const *e) {
+ QS_OBJ_DICTIONARY(&l_Poll);
+ QS_OBJ_DICTIONARY(&l_Poll.m_timeout);
+
+
+ QS_FUN_DICTIONARY(&QHsm::top);
+ QS_FUN_DICTIONARY(&Poll::initial);
+ QS_FUN_DICTIONARY(&Poll::poll);
+
+
+ QS_SIG_DICTIONARY(TIMEOUT_SIG, &l_Poll); // just for Ped
+
+ me->m_timeout.postEvery(me, POLL_TOUT);
+
+ return Q_TRAN(&Poll::poll);
+}
+// $(components::Poll::Statechart::poll) .....................................
+QState Poll::poll(Poll *me, QEvent const *e) {
+ switch (e->sig) {
+ // @(/1/1/2/1)
+ case Q_EXIT_SIG: {
+ BSP_chk_io();
+ return Q_HANDLED();
+ }
+ // @(/1/1/2/1/0)
+ case TIMEOUT_SIG: {
+ return Q_TRAN(&Poll::poll);
+ }
+ }
+ return Q_SUPER(&QHsm::top);
+}
+
diff -r 000000000000 -r 7225ff529d1c network.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/network.h Wed Apr 27 17:11:08 2011 +0000
@@ -0,0 +1,35 @@
+//////////////////////////////////////////////////////////////////////////////
+// Model: Network.qm
+// File: ./network.h
+//
+// This file has been generated automatically by QP Modeler (QM).
+// DO NOT EDIT THIS FILE MANUALLY.
+//
+// Please visit www.state-machine.com/qm for more information.
+//////////////////////////////////////////////////////////////////////////////
+#ifndef network_h
+#define network_h
+
+enum PelicanSignals {
+ PEDS_WAITING_SIG = Q_USER_SIG,
+ SENSE1_N1_UP_SIG, //the sense1 signal goes high
+ SENSE1_N1_DOWN_SIG,//the sense signal goes low
+ SENSE_N1_SIG,//indicates to senses on N1 bus to look out for a toggle
+ MAX_PUB_SIG, // the last published signal
+
+ ON_SIG,
+ OFF_SIG,
+ TIMEOUT_SIG,
+ MAX_SIG
+};
+
+static QEvent const sense1_N1_Up_Evt = { SENSE1_N1_UP_SIG, 0 };
+static QEvent const sense1_N1_Down_Evt = { SENSE1_N1_DOWN_SIG, 0 };
+static QEvent const sense_N1_Evt = { SENSE_N1_SIG, 0 };
+
+// active objects ..................................................
+extern QActive * const AO_Pelican; // "opaque" pointer to Pelican AO
+extern QActive * const AO_Poll; // "opaque" pointer to IO Poll AO
+extern QActive * const AO_Sense1_N1; // "opaque" pointer to Ped AO
+
+#endif // network_h
diff -r 000000000000 -r 7225ff529d1c qp.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qp.lib Wed Apr 27 17:11:08 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/QL/code/qp/#156463fbfae6
diff -r 000000000000 -r 7225ff529d1c qp_config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qp_config.h Wed Apr 27 17:11:08 2011 +0000 @@ -0,0 +1,30 @@ +////////////////////////////////////////////////////////////////////////////// +// Model: Network.qm +// File: ./qp_config.h +// +// This file has been generated automatically by QP Modeler (QM). +// DO NOT EDIT THIS FILE MANUALLY. +// +// Please visit www.state-machine.com/qm for more information. +////////////////////////////////////////////////////////////////////////////// +#ifndef qp_config_h +#define qp_config_h + +// enable the Q-SPY software tracing instrumentation +#define Q_SPY + +// enable preemptive QK kernel (cooperative kernel is used when not defined) +#define QK_PREEMPTIVE + +// The maximum number of active objects in the application (could be up to 63) +#define QF_MAX_ACTIVE 16 + +// Uncomment the following macros only if you want to change the given default +//#define Q_SIGNAL_SIZE 1 +//#define QF_EVENT_SIZ_SIZE 2 +//#define QF_EQUEUE_CTR_SIZE 1 +//#define QF_MPOOL_SIZ_SIZE 2 +//#define QF_MPOOL_CTR_SIZE 2 +//#define QF_TIMEEVT_CTR_SIZE 2 + +#endif // qp_config_h