Deleted.

Committer:
QL
Date:
Mon Sep 26 03:32:15 2011 +0000
Revision:
3:4df7120f6f33
Parent:
2:27716f570c3d
4.2.04

Who changed what in which revision?

UserRevisionLine numberNew contents of line
QL 3:4df7120f6f33 1 //////////////////////////////////////////////////////////////////////////////
QL 3:4df7120f6f33 2 // Model: pelican.qm
QL 3:4df7120f6f33 3 // File: ./bsp.cpp
QL 3:4df7120f6f33 4 //
QL 3:4df7120f6f33 5 // This file has been generated automatically by QP Modeler (QM).
QL 3:4df7120f6f33 6 // DO NOT EDIT THIS FILE MANUALLY.
QL 3:4df7120f6f33 7 //
QL 3:4df7120f6f33 8 // Please visit www.state-machine.com/qm for more information.
QL 3:4df7120f6f33 9 //////////////////////////////////////////////////////////////////////////////
QL 3:4df7120f6f33 10 #include "qp_port.h"
QL 3:4df7120f6f33 11 #include "pelican.h"
QL 3:4df7120f6f33 12 #include "bsp.h"
QL 3:4df7120f6f33 13 #include "LPC17xx.h"
QL 3:4df7120f6f33 14
QL 3:4df7120f6f33 15 Q_DEFINE_THIS_FILE
QL 3:4df7120f6f33 16
QL 3:4df7120f6f33 17 // Local-scope objects -------------------------------------------------------
QL 3:4df7120f6f33 18 enum ISR_Priorities { // ISR priorities starting from the highest urgency
QL 3:4df7120f6f33 19 GPIOPORTA_PRIO,
QL 3:4df7120f6f33 20 SYSTICK_PRIO,
QL 3:4df7120f6f33 21 // ...
QL 3:4df7120f6f33 22 };
QL 3:4df7120f6f33 23
QL 3:4df7120f6f33 24 #define LED_PORT LPC_GPIO1
QL 3:4df7120f6f33 25 #define LED1_BIT (1U << 18)
QL 3:4df7120f6f33 26 #define LED2_BIT (1U << 20)
QL 3:4df7120f6f33 27 #define LED3_BIT (1U << 21)
QL 3:4df7120f6f33 28 #define LED4_BIT (1U << 23)
QL 3:4df7120f6f33 29
QL 3:4df7120f6f33 30 #ifdef Q_SPY
QL 3:4df7120f6f33 31 #include "mbed.h" // mbed is used only for the built-in serial
QL 3:4df7120f6f33 32
QL 3:4df7120f6f33 33 QSTimeCtr l_tickTime;
QL 3:4df7120f6f33 34 QSTimeCtr l_tickPeriod;
QL 3:4df7120f6f33 35 static uint8_t l_SysTick_Handler;
QL 3:4df7120f6f33 36
QL 3:4df7120f6f33 37 #define QSPY_BAUD_RATE 115200
QL 3:4df7120f6f33 38
QL 3:4df7120f6f33 39 enum AppRecords { // application-specific trace records
QL 3:4df7120f6f33 40 PELICAN_STAT = QS_USER
QL 3:4df7120f6f33 41 };
QL 3:4df7120f6f33 42
QL 3:4df7120f6f33 43 Serial l_qspy(USBTX, USBRX);
QL 3:4df7120f6f33 44 #endif
QL 3:4df7120f6f33 45
QL 3:4df7120f6f33 46 //............................................................................
QL 3:4df7120f6f33 47 extern "C" void SysTick_Handler(void) {
QL 3:4df7120f6f33 48 QK_ISR_ENTRY(); // inform the QK kernel of entering the ISR
QL 3:4df7120f6f33 49
QL 3:4df7120f6f33 50 #ifdef Q_SPY
QL 3:4df7120f6f33 51 uint32_t volatile dummy = SysTick->CTRL; // clear the COUNTFLAG in SysTick
QL 3:4df7120f6f33 52 l_tickTime += l_tickPeriod; // account for the clock rollover
QL 3:4df7120f6f33 53 #endif
QL 3:4df7120f6f33 54
QL 3:4df7120f6f33 55 QF::TICK(&l_SysTick_Handler); // process all armed time events
QL 3:4df7120f6f33 56
QL 3:4df7120f6f33 57 QK_ISR_EXIT(); // inform the QK kernel of exiting the ISR
QL 3:4df7120f6f33 58 }
QL 3:4df7120f6f33 59
QL 3:4df7120f6f33 60 //............................................................................
QL 3:4df7120f6f33 61 void BSP_init(void) {
QL 3:4df7120f6f33 62 SystemInit(); // initialize the clocking system
QL 3:4df7120f6f33 63
QL 3:4df7120f6f33 64 // set LED port to output
QL 3:4df7120f6f33 65 LED_PORT->FIODIR |= (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT);
QL 3:4df7120f6f33 66
QL 3:4df7120f6f33 67 // clear the LEDs
QL 3:4df7120f6f33 68 LED_PORT->FIOCLR = (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT);
QL 3:4df7120f6f33 69
QL 3:4df7120f6f33 70 if (QS_INIT((void *)0) == 0) { // initialize the QS software tracing
QL 3:4df7120f6f33 71 Q_ERROR();
QL 3:4df7120f6f33 72 }
QL 3:4df7120f6f33 73 QS_OBJ_DICTIONARY(&l_SysTick_Handler);
QL 3:4df7120f6f33 74 }
QL 3:4df7120f6f33 75 //............................................................................
QL 3:4df7120f6f33 76 void BSP_signalCars(BSP_CarsSignal sig) {
QL 3:4df7120f6f33 77 switch (sig) {
QL 3:4df7120f6f33 78 case CARS_RED:
QL 3:4df7120f6f33 79 LED_PORT->FIOSET = LED1_BIT; // turn the LED1 on
QL 3:4df7120f6f33 80 LED_PORT->FIOCLR = LED2_BIT | LED3_BIT; // turn the LED2&3 off
QL 3:4df7120f6f33 81 break;
QL 3:4df7120f6f33 82 case CARS_YELLOW:
QL 3:4df7120f6f33 83 LED_PORT->FIOSET = LED2_BIT; // turn the LED2 on
QL 3:4df7120f6f33 84 LED_PORT->FIOCLR = LED1_BIT | LED3_BIT; // turn the LED1&3 off
QL 3:4df7120f6f33 85 break;
QL 3:4df7120f6f33 86 case CARS_GREEN:
QL 3:4df7120f6f33 87 LED_PORT->FIOSET = LED3_BIT; // turn the LED3 on
QL 3:4df7120f6f33 88 LED_PORT->FIOCLR = LED1_BIT | LED2_BIT; // turn the LED1&2 off
QL 3:4df7120f6f33 89 break;
QL 3:4df7120f6f33 90 case CARS_BLANK:
QL 3:4df7120f6f33 91 LED_PORT->FIOCLR = LED1_BIT | LED2_BIT | LED3_BIT; //turn all off
QL 3:4df7120f6f33 92 break;
QL 3:4df7120f6f33 93 }
QL 3:4df7120f6f33 94 }
QL 3:4df7120f6f33 95 //............................................................................
QL 3:4df7120f6f33 96 void BSP_signalPeds(BSP_PedsSignal sig) {
QL 3:4df7120f6f33 97 switch (sig) {
QL 3:4df7120f6f33 98 case PEDS_DONT_WALK:
QL 3:4df7120f6f33 99 LED_PORT->FIOSET = LED4_BIT; // turn the LED4 on
QL 3:4df7120f6f33 100 break;
QL 3:4df7120f6f33 101 case PEDS_WALK:
QL 3:4df7120f6f33 102 LED_PORT->FIOCLR = LED4_BIT; // turn the LED4 off
QL 3:4df7120f6f33 103 break;
QL 3:4df7120f6f33 104 case PEDS_BLANK:
QL 3:4df7120f6f33 105 LED_PORT->FIOCLR = LED4_BIT; // turn the LED4 off
QL 3:4df7120f6f33 106 break;
QL 3:4df7120f6f33 107 }
QL 3:4df7120f6f33 108 }
QL 3:4df7120f6f33 109 //............................................................................
QL 3:4df7120f6f33 110 void BSP_showState(char const *state) {
QL 3:4df7120f6f33 111 QS_BEGIN(PELICAN_STAT, AO_Pelican) // application-specific record
QL 3:4df7120f6f33 112 QS_STR(state); // state string
QL 3:4df7120f6f33 113 QS_END()
QL 3:4df7120f6f33 114 }
QL 3:4df7120f6f33 115
QL 3:4df7120f6f33 116 //............................................................................
QL 3:4df7120f6f33 117 void QF::onStartup(void) {
QL 3:4df7120f6f33 118 // set up the SysTick timer to fire at BSP_TICKS_PER_SEC rate
QL 3:4df7120f6f33 119 SysTick_Config(SystemCoreClock / BSP_TICKS_PER_SEC);
QL 3:4df7120f6f33 120
QL 3:4df7120f6f33 121 // set priorities of all interrupts in the system...
QL 3:4df7120f6f33 122 NVIC_SetPriority(SysTick_IRQn, SYSTICK_PRIO);
QL 3:4df7120f6f33 123 NVIC_SetPriority(EINT0_IRQn, GPIOPORTA_PRIO);
QL 3:4df7120f6f33 124
QL 3:4df7120f6f33 125 NVIC_EnableIRQ(EINT0_IRQn);
QL 3:4df7120f6f33 126 }
QL 3:4df7120f6f33 127 //............................................................................
QL 3:4df7120f6f33 128 void QF::onCleanup(void) {
QL 3:4df7120f6f33 129 }
QL 3:4df7120f6f33 130 //............................................................................
QL 3:4df7120f6f33 131 void QK::onIdle(void) {
QL 3:4df7120f6f33 132 #ifdef Q_SPY
QL 3:4df7120f6f33 133 if (l_qspy.writeable()) {
QL 3:4df7120f6f33 134 QF_INT_LOCK(dummy);
QL 3:4df7120f6f33 135 uint16_t b = QS::getByte();
QL 3:4df7120f6f33 136 QF_INT_UNLOCK(dummy);
QL 3:4df7120f6f33 137 if (b != QS_EOD) {
QL 3:4df7120f6f33 138 l_qspy.putc((uint8_t)b);
QL 3:4df7120f6f33 139 }
QL 3:4df7120f6f33 140 }
QL 3:4df7120f6f33 141 #else
QL 3:4df7120f6f33 142 // put the CPU and peripherals to the low-power mode
QL 3:4df7120f6f33 143 // you might need to customize the clock management for your application,
QL 3:4df7120f6f33 144 // see the datasheet for your particular Cortex-M3 MCU.
QL 3:4df7120f6f33 145 __WFI();
QL 3:4df7120f6f33 146 #endif
QL 3:4df7120f6f33 147 }
QL 3:4df7120f6f33 148
QL 3:4df7120f6f33 149 //............................................................................
QL 3:4df7120f6f33 150 void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) {
QL 3:4df7120f6f33 151 (void)file; // avoid compiler warning
QL 3:4df7120f6f33 152 (void)line; // avoid compiler warning
QL 3:4df7120f6f33 153 QS_BEGIN_(QS_ASSERT, 0, 0)
QL 3:4df7120f6f33 154 QS_TIME_(); // time stamp
QL 3:4df7120f6f33 155 QS_U16_((uint16_t)line); // the line number
QL 3:4df7120f6f33 156 QS_STR_(file); // the file name
QL 3:4df7120f6f33 157 QS_END_()
QL 3:4df7120f6f33 158 QS_FLUSH();
QL 3:4df7120f6f33 159
QL 3:4df7120f6f33 160 QF_INT_LOCK(dummy); // make sure that all interrupts are disabled
QL 3:4df7120f6f33 161 // light up all LEDs
QL 3:4df7120f6f33 162 LED_PORT->FIOSET = (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT);
QL 3:4df7120f6f33 163
QL 3:4df7120f6f33 164 for (;;) { // NOTE: replace the loop with reset for final version
QL 3:4df7120f6f33 165 }
QL 3:4df7120f6f33 166 }
QL 3:4df7120f6f33 167
QL 3:4df7120f6f33 168 //----------------------------------------------------------------------------
QL 3:4df7120f6f33 169 #ifdef Q_SPY
QL 3:4df7120f6f33 170 //............................................................................
QL 3:4df7120f6f33 171 uint8_t QS::onStartup(void const *arg) {
QL 3:4df7120f6f33 172 static uint8_t qsBuf[6*256]; // buffer for Quantum Spy
QL 3:4df7120f6f33 173 initBuf(qsBuf, sizeof(qsBuf));
QL 3:4df7120f6f33 174
QL 3:4df7120f6f33 175 l_qspy.baud(QSPY_BAUD_RATE);
QL 3:4df7120f6f33 176
QL 3:4df7120f6f33 177 l_tickPeriod = SystemCoreClock / BSP_TICKS_PER_SEC;
QL 3:4df7120f6f33 178 l_tickTime = l_tickPeriod; // to start the timestamp at zero
QL 3:4df7120f6f33 179
QL 3:4df7120f6f33 180 // setup the QS filters...
QL 3:4df7120f6f33 181 QS_FILTER_ON(QS_ALL_RECORDS);
QL 3:4df7120f6f33 182
QL 3:4df7120f6f33 183 // QS_FILTER_OFF(QS_QEP_STATE_EMPTY);
QL 3:4df7120f6f33 184 // QS_FILTER_OFF(QS_QEP_STATE_ENTRY);
QL 3:4df7120f6f33 185 // QS_FILTER_OFF(QS_QEP_STATE_EXIT);
QL 3:4df7120f6f33 186 // QS_FILTER_OFF(QS_QEP_STATE_INIT);
QL 3:4df7120f6f33 187 // QS_FILTER_OFF(QS_QEP_INIT_TRAN);
QL 3:4df7120f6f33 188 // QS_FILTER_OFF(QS_QEP_INTERN_TRAN);
QL 3:4df7120f6f33 189 // QS_FILTER_OFF(QS_QEP_TRAN);
QL 3:4df7120f6f33 190 // QS_FILTER_OFF(QS_QEP_IGNORED);
QL 3:4df7120f6f33 191
QL 3:4df7120f6f33 192 // QS_FILTER_OFF(QS_QF_ACTIVE_ADD);
QL 3:4df7120f6f33 193 // QS_FILTER_OFF(QS_QF_ACTIVE_REMOVE);
QL 3:4df7120f6f33 194 // QS_FILTER_OFF(QS_QF_ACTIVE_SUBSCRIBE);
QL 3:4df7120f6f33 195 // QS_FILTER_OFF(QS_QF_ACTIVE_UNSUBSCRIBE);
QL 3:4df7120f6f33 196 // QS_FILTER_OFF(QS_QF_ACTIVE_POST_FIFO);
QL 3:4df7120f6f33 197 // QS_FILTER_OFF(QS_QF_ACTIVE_POST_LIFO);
QL 3:4df7120f6f33 198 // QS_FILTER_OFF(QS_QF_ACTIVE_GET);
QL 3:4df7120f6f33 199 // QS_FILTER_OFF(QS_QF_ACTIVE_GET_LAST);
QL 3:4df7120f6f33 200 // QS_FILTER_OFF(QS_QF_EQUEUE_INIT);
QL 3:4df7120f6f33 201 // QS_FILTER_OFF(QS_QF_EQUEUE_POST_FIFO);
QL 3:4df7120f6f33 202 // QS_FILTER_OFF(QS_QF_EQUEUE_POST_LIFO);
QL 3:4df7120f6f33 203 // QS_FILTER_OFF(QS_QF_EQUEUE_GET);
QL 3:4df7120f6f33 204 // QS_FILTER_OFF(QS_QF_EQUEUE_GET_LAST);
QL 3:4df7120f6f33 205 // QS_FILTER_OFF(QS_QF_MPOOL_INIT);
QL 3:4df7120f6f33 206 // QS_FILTER_OFF(QS_QF_MPOOL_GET);
QL 3:4df7120f6f33 207 // QS_FILTER_OFF(QS_QF_MPOOL_PUT);
QL 3:4df7120f6f33 208 // QS_FILTER_OFF(QS_QF_PUBLISH);
QL 3:4df7120f6f33 209 // QS_FILTER_OFF(QS_QF_NEW);
QL 3:4df7120f6f33 210 // QS_FILTER_OFF(QS_QF_GC_ATTEMPT);
QL 3:4df7120f6f33 211 // QS_FILTER_OFF(QS_QF_GC);
QL 3:4df7120f6f33 212 QS_FILTER_OFF(QS_QF_TICK);
QL 3:4df7120f6f33 213 // QS_FILTER_OFF(QS_QF_TIMEEVT_ARM);
QL 3:4df7120f6f33 214 // QS_FILTER_OFF(QS_QF_TIMEEVT_AUTO_DISARM);
QL 3:4df7120f6f33 215 // QS_FILTER_OFF(QS_QF_TIMEEVT_DISARM_ATTEMPT);
QL 3:4df7120f6f33 216 // QS_FILTER_OFF(QS_QF_TIMEEVT_DISARM);
QL 3:4df7120f6f33 217 // QS_FILTER_OFF(QS_QF_TIMEEVT_REARM);
QL 3:4df7120f6f33 218 // QS_FILTER_OFF(QS_QF_TIMEEVT_POST);
QL 3:4df7120f6f33 219 QS_FILTER_OFF(QS_QF_INT_LOCK);
QL 3:4df7120f6f33 220 QS_FILTER_OFF(QS_QF_INT_UNLOCK);
QL 3:4df7120f6f33 221 QS_FILTER_OFF(QS_QF_ISR_ENTRY);
QL 3:4df7120f6f33 222 QS_FILTER_OFF(QS_QF_ISR_EXIT);
QL 3:4df7120f6f33 223
QL 3:4df7120f6f33 224 // QS_FILTER_OFF(QS_QK_MUTEX_LOCK);
QL 3:4df7120f6f33 225 // QS_FILTER_OFF(QS_QK_MUTEX_UNLOCK);
QL 3:4df7120f6f33 226 // QS_FILTER_OFF(QS_QK_SCHEDULE);
QL 3:4df7120f6f33 227
QL 3:4df7120f6f33 228 return (uint8_t)1; // return success
QL 3:4df7120f6f33 229 }
QL 3:4df7120f6f33 230 //............................................................................
QL 3:4df7120f6f33 231 void QS::onCleanup(void) {
QL 3:4df7120f6f33 232 }
QL 3:4df7120f6f33 233 //............................................................................
QL 3:4df7120f6f33 234 QSTimeCtr QS::onGetTime(void) { // invoked with interrupts locked
QL 3:4df7120f6f33 235 if ((SysTick->CTRL & 0x00000100) == 0) { // COUNTFLAG no set?
QL 3:4df7120f6f33 236 return l_tickTime - (QSTimeCtr)SysTick->VAL;
QL 3:4df7120f6f33 237 }
QL 3:4df7120f6f33 238 else { // the rollover occured, but the SysTick_ISR did not run yet
QL 3:4df7120f6f33 239 return l_tickTime + l_tickPeriod - (QSTimeCtr)SysTick->VAL;
QL 3:4df7120f6f33 240 }
QL 3:4df7120f6f33 241 }
QL 3:4df7120f6f33 242 //............................................................................
QL 3:4df7120f6f33 243 void QS::onFlush(void) {
QL 3:4df7120f6f33 244 uint16_t b;
QL 3:4df7120f6f33 245 QF_INT_LOCK(dummy);
QL 3:4df7120f6f33 246 while ((b = QS::getByte()) != QS_EOD) {
QL 3:4df7120f6f33 247 while (!l_qspy.writeable()) { // wait until serial port is writable
QL 3:4df7120f6f33 248 }
QL 3:4df7120f6f33 249 l_qspy.putc((uint8_t)b);
QL 3:4df7120f6f33 250 }
QL 3:4df7120f6f33 251 QF_INT_UNLOCK(dummy);
QL 3:4df7120f6f33 252 }
QL 3:4df7120f6f33 253 #endif // Q_SPY
QL 3:4df7120f6f33 254 //----------------------------------------------------------------------------