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.
bsp.cpp
00001 ////////////////////////////////////////////////////////////////////////////// 00002 // Model: Network.qm 00003 // File: ./bsp.cpp 00004 // 00005 // This file has been generated automatically by QP Modeler (QM). 00006 // DO NOT EDIT THIS FILE MANUALLY. 00007 // 00008 // Please visit www.state-machine.com/qm for more information. 00009 ////////////////////////////////////////////////////////////////////////////// 00010 #include "qp_port.h" 00011 #include "network.h" 00012 #include "bsp.h" 00013 #include "LPC17xx.h" 00014 00015 Q_DEFINE_THIS_FILE 00016 00017 // Local-scope objects ------------------------------------------------------- 00018 enum ISR_Priorities { // ISR priorities starting from the highest urgency 00019 GPIOPORTA_PRIO, 00020 SYSTICK_PRIO, 00021 // ... 00022 }; 00023 00024 #define LED_PORT LPC_GPIO1 00025 #define LED1_BIT (1U << 18) 00026 #define LED2_BIT (1U << 20) 00027 #define LED3_BIT (1U << 21) 00028 #define LED4_BIT (1U << 23) 00029 00030 #ifdef Q_SPY 00031 #include "mbed.h" // mbed is used only for the built-in serial 00032 00033 QSTimeCtr l_tickTime; 00034 QSTimeCtr l_tickPeriod; 00035 00036 #define QSPY_BAUD_RATE 115200 00037 00038 enum AppRecords { // application-specific trace records 00039 PELICAN_STAT = QS_USER, 00040 IO_STAT 00041 }; 00042 00043 Serial l_qspy(USBTX, USBRX); 00044 #endif 00045 00046 //............................................................................ 00047 extern "C" void SysTick_Handler(void) { 00048 QK_ISR_ENTRY(); // inform the QK kernel of entering the ISR 00049 00050 #ifdef Q_SPY 00051 uint32_t volatile dummy = SysTick->CTRL; // clear the COUNTFLAG in SysTick 00052 l_tickTime += l_tickPeriod; // account for the clock rollover 00053 #endif 00054 00055 QF::tick(); // process all armed time events 00056 00057 QK_ISR_EXIT(); // inform the QK kernel of exiting the ISR 00058 } 00059 00060 //............................................................................ 00061 static N4S2 l_N4S2; 00062 00063 00064 DigitalIn N4S2 :: geomSenses[N_FACES] = {(p17), (p18), (p19), (p20)}; 00065 DigitalOut N4S2 :: geomTxs[S_FACES] = {(p21), (p22)}; 00066 00067 SerialHalfDuplex N4S2 :: sPort1(p9,p10);//common n bus 00068 SerialHalfDuplex N4S2 :: sPort2(p13,p14);//common n bus 00069 SerialHalfDuplex N4S2 :: sPorts[S_FACES] = {sPort1,sPort2}; //seg ports 00070 SerialHalfDuplex N4S2 :: nPort(p28,p27);//common n bus 00071 00072 DigitalOut N4S2 :: sPort1ETx(p11); 00073 DigitalOut N4S2 :: sPort2ETx(p12); 00074 DigitalOut N4S2 :: nPortETx(p29); 00075 DigitalOut N4S2 :: sPortETxs[S_FACES] = {sPort1ETx, sPort2ETx}; 00076 00077 DigitalOut N4S2 :: leds[] = {(LED1), (LED2), (LED3), (LED4)}; 00078 00079 00080 //............................................................................ 00081 void BSP_init(void) { 00082 SystemInit(); // initialize the clocking system 00083 00084 // set LED port to output 00085 LED_PORT->FIODIR |= (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT); 00086 00087 // clear the LEDs 00088 LED_PORT->FIOCLR = (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT); 00089 00090 if (QS_INIT((void *)0) == 0) { // initialize the QS software tracing 00091 Q_ERROR(); 00092 } 00093 } 00094 //............................................................................ 00095 void BSP_signalCars(BSP_CarsSignal sig) { 00096 /* 00097 switch (sig) { 00098 case CARS_RED: 00099 LED_PORT->FIOSET = LED1_BIT; // turn the LED1 on 00100 LED_PORT->FIOCLR = LED2_BIT | LED3_BIT; // turn the LED2&3 off 00101 break; 00102 case CARS_YELLOW: 00103 LED_PORT->FIOSET = LED2_BIT; // turn the LED2 on 00104 LED_PORT->FIOCLR = LED1_BIT | LED3_BIT; // turn the LED1&3 off 00105 break; 00106 case CARS_GREEN: 00107 LED_PORT->FIOSET = LED3_BIT; // turn the LED3 on 00108 LED_PORT->FIOCLR = LED1_BIT | LED2_BIT; // turn the LED1&2 off 00109 break; 00110 case CARS_BLANK: 00111 LED_PORT->FIOCLR = LED1_BIT | LED2_BIT | LED3_BIT; //turn all off 00112 break; 00113 }*/ 00114 } 00115 //............................................................................ 00116 void BSP_signalPeds(BSP_PedsSignal sig) { 00117 /* 00118 switch (sig) { 00119 case PEDS_DONT_WALK: 00120 LED_PORT->FIOSET = LED4_BIT; // turn the LED4 on 00121 break; 00122 case PEDS_WALK: 00123 LED_PORT->FIOCLR = LED4_BIT; // turn the LED4 off 00124 break; 00125 case PEDS_BLANK: 00126 LED_PORT->FIOCLR = LED4_BIT; // turn the LED4 off 00127 break; 00128 }*/ 00129 } 00130 //............................................................................ 00131 void BSP_showState(char const *state) { 00132 QS_BEGIN(PELICAN_STAT, AO_Pelican) // application-specific record 00133 QS_STR(state); // state string 00134 QS_END() 00135 } 00136 00137 //............................................................................ 00138 void BSP_signalSense(BSP_SenseSignal sig) { 00139 switch (sig) { 00140 case SENSE_1_CON: 00141 LED_PORT->FIOSET = LED1_BIT; // turn the LED4 on 00142 break; 00143 case SENSE_1_DIS: 00144 LED_PORT->FIOCLR = LED1_BIT; // turn the LED4 off 00145 break; 00146 } 00147 } 00148 00149 //............................................................................ 00150 void BSP_chk_io() { 00151 QS_BEGIN(IO_STAT, AO_Poll) // application-specific record 00152 QS_STR("chk_io_called"); 00153 static int prev[4] = {0,0,0,0}; 00154 for(int i=0;i<l_N4S2.N_FACES;i++){ 00155 int newVal = l_N4S2.geomSenses[i]; 00156 if(newVal == 0 && prev[i] !=0){ 00157 QF::publish(&sense1_N1_Down_Evt); 00158 }else if(newVal != 0 && prev[i] ==0){ 00159 QF::publish(&sense1_N1_Up_Evt); 00160 } 00161 prev[i] = newVal; 00162 } 00163 QS_END() 00164 } 00165 00166 //............................................................................ 00167 void QF::onStartup(void) { 00168 // set up the SysTick timer to fire at BSP_TICKS_PER_SEC rate 00169 SysTick_Config(SystemCoreClock / BSP_TICKS_PER_SEC); 00170 00171 // set priorities of all interrupts in the system... 00172 NVIC_SetPriority(SysTick_IRQn, SYSTICK_PRIO); 00173 NVIC_SetPriority(EINT0_IRQn, GPIOPORTA_PRIO); 00174 00175 NVIC_EnableIRQ(EINT0_IRQn); 00176 } 00177 //............................................................................ 00178 void QF::onCleanup(void) { 00179 } 00180 //............................................................................ 00181 void QK::onIdle(void) { 00182 #ifdef Q_SPY 00183 if (l_qspy.writeable()) { 00184 QF_INT_LOCK(dummy); 00185 uint16_t b = QS::getByte(); 00186 QF_INT_UNLOCK(dummy); 00187 if (b != QS_EOD) { 00188 l_qspy.putc((uint8_t)b); 00189 } 00190 } 00191 #else 00192 // put the CPU and peripherals to the low-power mode 00193 // you might need to customize the clock management for your application, 00194 // see the datasheet for your particular Cortex-M3 MCU. 00195 __WFI(); 00196 #endif 00197 } 00198 00199 //............................................................................ 00200 void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line) { 00201 (void)file; // avoid compiler warning 00202 (void)line; // avoid compiler warning 00203 QS_BEGIN_(QS_ASSERT, 0, 0) 00204 QS_TIME_(); // time stamp 00205 QS_U16_((uint16_t)line); // the line number 00206 QS_STR_(file); // the file name 00207 QS_END_() 00208 QS::onFlush(); 00209 00210 QF_INT_LOCK(dummy); // make sure that all interrupts are disabled 00211 // light up all LEDs 00212 LED_PORT->FIOSET = (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT); 00213 00214 for (;;) { // NOTE: replace the loop with reset for final version 00215 } 00216 } 00217 00218 //---------------------------------------------------------------------------- 00219 #ifdef Q_SPY 00220 //............................................................................ 00221 uint8_t QS::onStartup(void const *arg) { 00222 static uint8_t qsBuf[6*256]; // buffer for Quantum Spy 00223 initBuf(qsBuf, sizeof(qsBuf)); 00224 00225 l_qspy.baud(QSPY_BAUD_RATE); 00226 00227 l_tickPeriod = SystemCoreClock / BSP_TICKS_PER_SEC; 00228 l_tickTime = l_tickPeriod; // to start the timestamp at zero 00229 00230 // setup the QS filters... 00231 QS_FILTER_ON(QS_ALL_RECORDS); 00232 00233 // QS_FILTER_OFF(QS_QEP_STATE_EMPTY); 00234 // QS_FILTER_OFF(QS_QEP_STATE_ENTRY); 00235 // QS_FILTER_OFF(QS_QEP_STATE_EXIT); 00236 // QS_FILTER_OFF(QS_QEP_STATE_INIT); 00237 // QS_FILTER_OFF(QS_QEP_INIT_TRAN); 00238 // QS_FILTER_OFF(QS_QEP_INTERN_TRAN); 00239 // QS_FILTER_OFF(QS_QEP_TRAN); 00240 // QS_FILTER_OFF(QS_QEP_IGNORED); 00241 00242 // QS_FILTER_OFF(QS_QF_ACTIVE_ADD); 00243 // QS_FILTER_OFF(QS_QF_ACTIVE_REMOVE); 00244 // QS_FILTER_OFF(QS_QF_ACTIVE_SUBSCRIBE); 00245 // QS_FILTER_OFF(QS_QF_ACTIVE_UNSUBSCRIBE); 00246 // QS_FILTER_OFF(QS_QF_ACTIVE_POST_FIFO); 00247 // QS_FILTER_OFF(QS_QF_ACTIVE_POST_LIFO); 00248 // QS_FILTER_OFF(QS_QF_ACTIVE_GET); 00249 // QS_FILTER_OFF(QS_QF_ACTIVE_GET_LAST); 00250 // QS_FILTER_OFF(QS_QF_EQUEUE_INIT); 00251 // QS_FILTER_OFF(QS_QF_EQUEUE_POST_FIFO); 00252 // QS_FILTER_OFF(QS_QF_EQUEUE_POST_LIFO); 00253 // QS_FILTER_OFF(QS_QF_EQUEUE_GET); 00254 // QS_FILTER_OFF(QS_QF_EQUEUE_GET_LAST); 00255 // QS_FILTER_OFF(QS_QF_MPOOL_INIT); 00256 // QS_FILTER_OFF(QS_QF_MPOOL_GET); 00257 // QS_FILTER_OFF(QS_QF_MPOOL_PUT); 00258 // QS_FILTER_OFF(QS_QF_PUBLISH); 00259 // QS_FILTER_OFF(QS_QF_NEW); 00260 // QS_FILTER_OFF(QS_QF_GC_ATTEMPT); 00261 // QS_FILTER_OFF(QS_QF_GC); 00262 QS_FILTER_OFF(QS_QF_TICK); 00263 // QS_FILTER_OFF(QS_QF_TIMEEVT_ARM); 00264 // QS_FILTER_OFF(QS_QF_TIMEEVT_AUTO_DISARM); 00265 // QS_FILTER_OFF(QS_QF_TIMEEVT_DISARM_ATTEMPT); 00266 // QS_FILTER_OFF(QS_QF_TIMEEVT_DISARM); 00267 // QS_FILTER_OFF(QS_QF_TIMEEVT_REARM); 00268 // QS_FILTER_OFF(QS_QF_TIMEEVT_POST); 00269 QS_FILTER_OFF(QS_QF_INT_LOCK); 00270 QS_FILTER_OFF(QS_QF_INT_UNLOCK); 00271 QS_FILTER_OFF(QS_QF_ISR_ENTRY); 00272 QS_FILTER_OFF(QS_QF_ISR_EXIT); 00273 00274 // QS_FILTER_OFF(QS_QK_MUTEX_LOCK); 00275 // QS_FILTER_OFF(QS_QK_MUTEX_UNLOCK); 00276 // QS_FILTER_OFF(QS_QK_SCHEDULE); 00277 00278 return (uint8_t)1; // return success 00279 } 00280 //............................................................................ 00281 void QS::onCleanup(void) { 00282 } 00283 //............................................................................ 00284 QSTimeCtr QS::onGetTime(void) { // invoked with interrupts locked 00285 if ((SysTick->CTRL & 0x00000100) == 0) { // COUNTFLAG no set? 00286 return l_tickTime - (QSTimeCtr)SysTick->VAL; 00287 } 00288 else { // the rollover occured, but the SysTick_ISR did not run yet 00289 return l_tickTime + l_tickPeriod - (QSTimeCtr)SysTick->VAL; 00290 } 00291 } 00292 //............................................................................ 00293 void QS::onFlush(void) { 00294 uint16_t b; 00295 QF_INT_LOCK(dummy); 00296 while ((b = QS::getByte()) != QS_EOD) { 00297 while (!l_qspy.writeable()) { // wait until serial port is writable 00298 } 00299 l_qspy.putc((uint8_t)b); 00300 } 00301 QF_INT_UNLOCK(dummy); 00302 } 00303 #endif // Q_SPY 00304 //----------------------------------------------------------------------------
Generated on Tue Aug 2 2022 11:35:56 by
1.7.2