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]].
bsp.cpp@4:6189d844a1a2, 2012-09-04 (annotated)
- Committer:
- QL
- Date:
- Tue Sep 04 22:41:20 2012 +0000
- Revision:
- 4:6189d844a1a2
- Parent:
- 3:81ceb3127876
updated for QP 4.5.02
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
QL | 4:6189d844a1a2 | 1 | ////////////////////////////////////////////////////////////////////////////// |
QL | 4:6189d844a1a2 | 2 | // Product: DPP example, configurable Vanilla/QK kernel |
QL | 4:6189d844a1a2 | 3 | // Last Updated for Version: 4.5.02 |
QL | 4:6189d844a1a2 | 4 | // Date of the Last Update: Sep 04, 2012 |
QL | 4:6189d844a1a2 | 5 | // |
QL | 4:6189d844a1a2 | 6 | // Q u a n t u m L e a P s |
QL | 4:6189d844a1a2 | 7 | // --------------------------- |
QL | 4:6189d844a1a2 | 8 | // innovating embedded systems |
QL | 4:6189d844a1a2 | 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 | 4:6189d844a1a2 | 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 | 4:6189d844a1a2 | 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 | 4:6189d844a1a2 | 29 | // |
QL | 4:6189d844a1a2 | 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 | 4:6189d844a1a2 | 33 | // e-mail: info@quantum-leaps.com |
QL | 4:6189d844a1a2 | 34 | ////////////////////////////////////////////////////////////////////////////// |
QL | 4:6189d844a1a2 | 35 | #include "qp_port.h" |
QL | 4:6189d844a1a2 | 36 | #include "dpp.h" |
QL | 4:6189d844a1a2 | 37 | #include "bsp.h" |
QL | 4:6189d844a1a2 | 38 | #include "LPC17xx.h" |
QL | 4:6189d844a1a2 | 39 | #ifdef Q_SPY |
QL | 4:6189d844a1a2 | 40 | #include "mbed.h" // mbed is used only for the built-in serial |
QL | 4:6189d844a1a2 | 41 | #endif |
QL | 4:6189d844a1a2 | 42 | |
QL | 4:6189d844a1a2 | 43 | ////////////////////////////////////////////////////////////////////////////// |
QL | 4:6189d844a1a2 | 44 | namespace DPP { |
QL | 4:6189d844a1a2 | 45 | |
QL | 4:6189d844a1a2 | 46 | Q_DEFINE_THIS_FILE |
QL | 4:6189d844a1a2 | 47 | |
QL | 4:6189d844a1a2 | 48 | enum ISR_Priorities { // ISR priorities starting from the highest urgency |
QL | 4:6189d844a1a2 | 49 | GPIOPORTA_PRIO, |
QL | 4:6189d844a1a2 | 50 | SYSTICK_PRIO |
QL | 4:6189d844a1a2 | 51 | // ... |
QL | 4:6189d844a1a2 | 52 | }; |
QL | 4:6189d844a1a2 | 53 | |
QL | 4:6189d844a1a2 | 54 | // Local-scope objects ------------------------------------------------------- |
QL | 4:6189d844a1a2 | 55 | static uint32_t l_rnd; // random seed |
QL | 4:6189d844a1a2 | 56 | |
QL | 4:6189d844a1a2 | 57 | #define LED_PORT LPC_GPIO1 |
QL | 4:6189d844a1a2 | 58 | #define LED1_BIT (1U << 18) |
QL | 4:6189d844a1a2 | 59 | #define LED2_BIT (1U << 20) |
QL | 4:6189d844a1a2 | 60 | #define LED3_BIT (1U << 21) |
QL | 4:6189d844a1a2 | 61 | #define LED4_BIT (1U << 23) |
QL | 4:6189d844a1a2 | 62 | |
QL | 4:6189d844a1a2 | 63 | #ifdef Q_SPY |
QL | 4:6189d844a1a2 | 64 | QP::QSTimeCtr l_tickTime; |
QL | 4:6189d844a1a2 | 65 | QP::QSTimeCtr l_tickPeriod; |
QL | 4:6189d844a1a2 | 66 | static uint8_t l_SysTick_Handler; |
QL | 4:6189d844a1a2 | 67 | |
QL | 4:6189d844a1a2 | 68 | #define QSPY_BAUD_RATE 115200U |
QL | 4:6189d844a1a2 | 69 | |
QL | 4:6189d844a1a2 | 70 | enum AppRecords { // application-specific trace records |
QL | 4:6189d844a1a2 | 71 | PHILO_STAT = QP::QS_USER |
QL | 4:6189d844a1a2 | 72 | }; |
QL | 4:6189d844a1a2 | 73 | |
QL | 4:6189d844a1a2 | 74 | Serial l_qspy(USBTX, USBRX); |
QL | 4:6189d844a1a2 | 75 | #endif |
QL | 4:6189d844a1a2 | 76 | |
QL | 4:6189d844a1a2 | 77 | //............................................................................ |
QL | 4:6189d844a1a2 | 78 | extern "C" void SysTick_Handler(void) { |
QL | 4:6189d844a1a2 | 79 | QK_ISR_ENTRY(); // inform the QK kernel of entering the ISR |
QL | 4:6189d844a1a2 | 80 | |
QL | 4:6189d844a1a2 | 81 | #ifdef Q_SPY |
QL | 4:6189d844a1a2 | 82 | uint32_t volatile dummy = SysTick->CTRL; // clear the COUNTFLAG in SysTick |
QL | 4:6189d844a1a2 | 83 | l_tickTime += l_tickPeriod; // account for the clock rollover |
QL | 4:6189d844a1a2 | 84 | #endif |
QL | 4:6189d844a1a2 | 85 | |
QL | 4:6189d844a1a2 | 86 | QP::QF::TICK(&l_SysTick_Handler); // process all armed time events |
QL | 4:6189d844a1a2 | 87 | |
QL | 4:6189d844a1a2 | 88 | QK_ISR_EXIT(); // inform the QK kernel of exiting the ISR |
QL | 4:6189d844a1a2 | 89 | } |
QL | 4:6189d844a1a2 | 90 | |
QL | 4:6189d844a1a2 | 91 | //............................................................................ |
QL | 4:6189d844a1a2 | 92 | void BSP_init(void) { |
QL | 4:6189d844a1a2 | 93 | // set the system clock as specified in lm3s_config.h (20MHz from PLL) |
QL | 4:6189d844a1a2 | 94 | SystemInit(); |
QL | 4:6189d844a1a2 | 95 | |
QL | 4:6189d844a1a2 | 96 | // set LED port to output |
QL | 4:6189d844a1a2 | 97 | LED_PORT->FIODIR |= (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT); |
QL | 4:6189d844a1a2 | 98 | |
QL | 4:6189d844a1a2 | 99 | // clear the LEDs |
QL | 4:6189d844a1a2 | 100 | LED_PORT->FIOCLR = (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT); |
QL | 4:6189d844a1a2 | 101 | |
QL | 4:6189d844a1a2 | 102 | // initialize the QS software tracing... |
QL | 4:6189d844a1a2 | 103 | Q_ALLEGE(QS_INIT(static_cast<void *>(0))); |
QL | 4:6189d844a1a2 | 104 | QS_RESET(); |
QL | 4:6189d844a1a2 | 105 | QS_OBJ_DICTIONARY(&l_SysTick_Handler); |
QL | 4:6189d844a1a2 | 106 | } |
QL | 4:6189d844a1a2 | 107 | //............................................................................ |
QL | 4:6189d844a1a2 | 108 | void BSP_terminate(int16_t const result) { |
QL | 4:6189d844a1a2 | 109 | (void)result; |
QL | 4:6189d844a1a2 | 110 | } |
QL | 4:6189d844a1a2 | 111 | //............................................................................ |
QL | 4:6189d844a1a2 | 112 | void BSP_displayPhilStat(uint8_t const n, char_t const * const stat) { |
QL | 4:6189d844a1a2 | 113 | // represent LEDs in a const array for convenience |
QL | 4:6189d844a1a2 | 114 | static uint32_t const led[] = { LED1_BIT, LED2_BIT, LED3_BIT, LED4_BIT }; |
QL | 4:6189d844a1a2 | 115 | if (n < 3) { |
QL | 4:6189d844a1a2 | 116 | if (stat[0] == 'e') { |
QL | 4:6189d844a1a2 | 117 | LED_PORT->FIOSET = led[n]; |
QL | 4:6189d844a1a2 | 118 | } |
QL | 4:6189d844a1a2 | 119 | else { |
QL | 4:6189d844a1a2 | 120 | LED_PORT->FIOCLR = led[n]; |
QL | 4:6189d844a1a2 | 121 | } |
QL | 4:6189d844a1a2 | 122 | } |
QL | 4:6189d844a1a2 | 123 | |
QL | 4:6189d844a1a2 | 124 | QS_BEGIN(PHILO_STAT, AO_Philo[n]) // application-specific record begin |
QL | 4:6189d844a1a2 | 125 | QS_U8(1U, n); // Philosopher number |
QL | 4:6189d844a1a2 | 126 | QS_STR(stat); // Philosopher status |
QL | 4:6189d844a1a2 | 127 | QS_END() |
QL | 4:6189d844a1a2 | 128 | } |
QL | 4:6189d844a1a2 | 129 | //............................................................................ |
QL | 4:6189d844a1a2 | 130 | void BSP_displayPaused(uint8_t const paused) { |
QL | 4:6189d844a1a2 | 131 | (void)paused; |
QL | 4:6189d844a1a2 | 132 | } |
QL | 4:6189d844a1a2 | 133 | //............................................................................ |
QL | 4:6189d844a1a2 | 134 | uint32_t BSP_random(void) { // a very cheap pseudo-random-number generator |
QL | 4:6189d844a1a2 | 135 | // "Super-Duper" Linear Congruential Generator (LCG) |
QL | 4:6189d844a1a2 | 136 | // LCG(2^32, 3*7*11*13*23, 0, seed) |
QL | 4:6189d844a1a2 | 137 | // |
QL | 4:6189d844a1a2 | 138 | l_rnd = l_rnd * (3U*7U*11U*13U*23U); |
QL | 4:6189d844a1a2 | 139 | return l_rnd >> 8; |
QL | 4:6189d844a1a2 | 140 | } |
QL | 4:6189d844a1a2 | 141 | //............................................................................ |
QL | 4:6189d844a1a2 | 142 | void BSP_randomSeed(uint32_t const seed) { |
QL | 4:6189d844a1a2 | 143 | l_rnd = seed; |
QL | 4:6189d844a1a2 | 144 | } |
QL | 4:6189d844a1a2 | 145 | |
QL | 4:6189d844a1a2 | 146 | //............................................................................ |
QL | 4:6189d844a1a2 | 147 | extern "C" void Q_onAssert(char_t const * const file, int_t const line) { |
QL | 4:6189d844a1a2 | 148 | (void)file; // avoid compiler warning |
QL | 4:6189d844a1a2 | 149 | (void)line; // avoid compiler warning |
QL | 4:6189d844a1a2 | 150 | QF_INT_DISABLE(); // make sure that all interrupts are disabled |
QL | 4:6189d844a1a2 | 151 | // light up all LEDs |
QL | 4:6189d844a1a2 | 152 | LED_PORT->FIOSET = (LED1_BIT | LED2_BIT | LED3_BIT | LED4_BIT); |
QL | 4:6189d844a1a2 | 153 | |
QL | 4:6189d844a1a2 | 154 | for (;;) { // NOTE: replace the loop with reset for final version |
QL | 4:6189d844a1a2 | 155 | } |
QL | 4:6189d844a1a2 | 156 | } |
QL | 4:6189d844a1a2 | 157 | |
QL | 4:6189d844a1a2 | 158 | } // namespace DPP |
QL | 4:6189d844a1a2 | 159 | ////////////////////////////////////////////////////////////////////////////// |
QL | 4:6189d844a1a2 | 160 | |
QL | 4:6189d844a1a2 | 161 | namespace QP { |
QL | 4:6189d844a1a2 | 162 | |
QL | 4:6189d844a1a2 | 163 | //............................................................................ |
QL | 4:6189d844a1a2 | 164 | void QF::onStartup(void) { |
QL | 4:6189d844a1a2 | 165 | // set up the SysTick timer to fire at BSP_TICKS_PER_SEC rate |
QL | 4:6189d844a1a2 | 166 | (void)SysTick_Config(SystemCoreClock / DPP::BSP_TICKS_PER_SEC); |
QL | 4:6189d844a1a2 | 167 | |
QL | 4:6189d844a1a2 | 168 | // set priorities of all interrupts in the system... |
QL | 4:6189d844a1a2 | 169 | NVIC_SetPriority(SysTick_IRQn, DPP::SYSTICK_PRIO); |
QL | 4:6189d844a1a2 | 170 | NVIC_SetPriority(EINT0_IRQn, DPP::GPIOPORTA_PRIO); |
QL | 4:6189d844a1a2 | 171 | |
QL | 4:6189d844a1a2 | 172 | NVIC_EnableIRQ(EINT0_IRQn); |
QL | 4:6189d844a1a2 | 173 | } |
QL | 4:6189d844a1a2 | 174 | //............................................................................ |
QL | 4:6189d844a1a2 | 175 | void QF::onCleanup(void) { |
QL | 4:6189d844a1a2 | 176 | } |
QL | 4:6189d844a1a2 | 177 | //............................................................................ |
QL | 4:6189d844a1a2 | 178 | #ifdef QK_PREEMPTIVE |
QL | 4:6189d844a1a2 | 179 | |
QL | 4:6189d844a1a2 | 180 | void QK::onIdle(void) { |
QL | 4:6189d844a1a2 | 181 | |
QL | 4:6189d844a1a2 | 182 | QF_INT_DISABLE(); |
QL | 4:6189d844a1a2 | 183 | LED_PORT->FIOSET = LED4_BIT; // turn the LED4 on |
QL | 4:6189d844a1a2 | 184 | __NOP(); // delay a bit to see some light intensity |
QL | 4:6189d844a1a2 | 185 | __NOP(); |
QL | 4:6189d844a1a2 | 186 | __NOP(); |
QL | 4:6189d844a1a2 | 187 | __NOP(); |
QL | 4:6189d844a1a2 | 188 | LED_PORT->FIOCLR = LED4_BIT; // turn the LED4 off |
QL | 4:6189d844a1a2 | 189 | QF_INT_ENABLE(); |
QL | 4:6189d844a1a2 | 190 | |
QL | 4:6189d844a1a2 | 191 | #ifdef Q_SPY |
QL | 4:6189d844a1a2 | 192 | if (DPP::l_qspy.writeable()) { |
QL | 4:6189d844a1a2 | 193 | |
QL | 4:6189d844a1a2 | 194 | QF_INT_DISABLE(); |
QL | 4:6189d844a1a2 | 195 | uint16_t b = QS::getByte(); |
QL | 4:6189d844a1a2 | 196 | QF_INT_ENABLE(); |
QL | 4:6189d844a1a2 | 197 | |
QL | 4:6189d844a1a2 | 198 | if (b != QS_EOD) { |
QL | 4:6189d844a1a2 | 199 | DPP::l_qspy.putc((uint8_t)b); |
QL | 4:6189d844a1a2 | 200 | } |
QL | 4:6189d844a1a2 | 201 | } |
QL | 4:6189d844a1a2 | 202 | #else |
QL | 4:6189d844a1a2 | 203 | // Put the CPU and peripherals to the low-power mode. You might need to |
QL | 4:6189d844a1a2 | 204 | // customize the clock management for your application, see the datasheet |
QL | 4:6189d844a1a2 | 205 | // for your particular Cortex-M3 MCU. |
QL | 4:6189d844a1a2 | 206 | // |
QL | 4:6189d844a1a2 | 207 | // Specifially for the mbed board, see the articles: |
QL | 4:6189d844a1a2 | 208 | // * "Power Management" http://mbed.org/cookbook/Power-Management; and |
QL | 4:6189d844a1a2 | 209 | // * "Interface Powerdown" at |
QL | 4:6189d844a1a2 | 210 | // http://mbed.org/users/simon/notebook/interface-powerdown/ |
QL | 4:6189d844a1a2 | 211 | // |
QL | 4:6189d844a1a2 | 212 | __WFI(); |
QL | 4:6189d844a1a2 | 213 | #endif |
QL | 4:6189d844a1a2 | 214 | } |
QL | 4:6189d844a1a2 | 215 | |
QL | 4:6189d844a1a2 | 216 | #else // non-preemptive Vanilla kernel |
QL | 4:6189d844a1a2 | 217 | |
QL | 4:6189d844a1a2 | 218 | void QF::onIdle(void) { // NOTE: called with interrupts DISABLED |
QL | 4:6189d844a1a2 | 219 | |
QL | 4:6189d844a1a2 | 220 | LED_PORT->FIOSET = LED4_BIT; // turn the LED4 on |
QL | 4:6189d844a1a2 | 221 | __NOP(); // delay a bit to see some light intensity |
QL | 4:6189d844a1a2 | 222 | __NOP(); |
QL | 4:6189d844a1a2 | 223 | __NOP(); |
QL | 4:6189d844a1a2 | 224 | __NOP(); |
QL | 4:6189d844a1a2 | 225 | LED_PORT->FIOCLR = LED4_BIT; // turn the LED4 off |
QL | 4:6189d844a1a2 | 226 | |
QL | 4:6189d844a1a2 | 227 | #ifdef Q_SPY |
QL | 4:6189d844a1a2 | 228 | QF_INT_ENABLE(); |
QL | 4:6189d844a1a2 | 229 | if (DPP::l_qspy.writeable()) { |
QL | 4:6189d844a1a2 | 230 | |
QL | 4:6189d844a1a2 | 231 | QF_INT_DISABLE(); |
QL | 4:6189d844a1a2 | 232 | uint16_t b = QS::getByte(); |
QL | 4:6189d844a1a2 | 233 | QF_INT_ENABLE(); |
QL | 4:6189d844a1a2 | 234 | |
QL | 4:6189d844a1a2 | 235 | if (b != QS_EOD) { |
QL | 4:6189d844a1a2 | 236 | DPP::l_qspy.putc((uint8_t)b); |
QL | 4:6189d844a1a2 | 237 | } |
QL | 4:6189d844a1a2 | 238 | } |
QL | 4:6189d844a1a2 | 239 | #else |
QL | 4:6189d844a1a2 | 240 | // Put the CPU and peripherals to the low-power mode. You might need to |
QL | 4:6189d844a1a2 | 241 | // customize the clock management for your application, see the datasheet |
QL | 4:6189d844a1a2 | 242 | // for your particular Cortex-M3 MCU. |
QL | 4:6189d844a1a2 | 243 | // |
QL | 4:6189d844a1a2 | 244 | // Specifially for the mbed board, see the articles: |
QL | 4:6189d844a1a2 | 245 | // * "Power Management" http://mbed.org/cookbook/Power-Management; and |
QL | 4:6189d844a1a2 | 246 | // * "Interface Powerdown" at |
QL | 4:6189d844a1a2 | 247 | // http://mbed.org/users/simon/notebook/interface-powerdown/ |
QL | 4:6189d844a1a2 | 248 | // |
QL | 4:6189d844a1a2 | 249 | __WFI(); |
QL | 4:6189d844a1a2 | 250 | QF_INT_ENABLE(); |
QL | 4:6189d844a1a2 | 251 | #endif |
QL | 4:6189d844a1a2 | 252 | } |
QL | 4:6189d844a1a2 | 253 | |
QL | 4:6189d844a1a2 | 254 | #endif // QK_PREEMPTIVE |
QL | 4:6189d844a1a2 | 255 | |
QL | 4:6189d844a1a2 | 256 | //---------------------------------------------------------------------------- |
QL | 4:6189d844a1a2 | 257 | #ifdef Q_SPY |
QL | 4:6189d844a1a2 | 258 | //............................................................................ |
QL | 4:6189d844a1a2 | 259 | bool QS::onStartup(void const *arg) { |
QL | 4:6189d844a1a2 | 260 | static uint8_t qsBuf[6*256]; // buffer for Quantum Spy |
QL | 4:6189d844a1a2 | 261 | initBuf(qsBuf, sizeof(qsBuf)); |
QL | 4:6189d844a1a2 | 262 | |
QL | 4:6189d844a1a2 | 263 | DPP::l_qspy.baud(QSPY_BAUD_RATE); |
QL | 4:6189d844a1a2 | 264 | |
QL | 4:6189d844a1a2 | 265 | DPP::l_tickPeriod = SystemCoreClock / DPP::BSP_TICKS_PER_SEC; |
QL | 4:6189d844a1a2 | 266 | DPP::l_tickTime = DPP::l_tickPeriod; // to start the timestamp at zero |
QL | 4:6189d844a1a2 | 267 | |
QL | 4:6189d844a1a2 | 268 | // setup the QS filters... |
QL | 4:6189d844a1a2 | 269 | QS_FILTER_ON(QS_ALL_RECORDS); |
QL | 4:6189d844a1a2 | 270 | |
QL | 4:6189d844a1a2 | 271 | // QS_FILTER_OFF(QS_QEP_STATE_EMPTY); |
QL | 4:6189d844a1a2 | 272 | // QS_FILTER_OFF(QS_QEP_STATE_ENTRY); |
QL | 4:6189d844a1a2 | 273 | // QS_FILTER_OFF(QS_QEP_STATE_EXIT); |
QL | 4:6189d844a1a2 | 274 | // QS_FILTER_OFF(QS_QEP_STATE_INIT); |
QL | 4:6189d844a1a2 | 275 | // QS_FILTER_OFF(QS_QEP_INIT_TRAN); |
QL | 4:6189d844a1a2 | 276 | // QS_FILTER_OFF(QS_QEP_INTERN_TRAN); |
QL | 4:6189d844a1a2 | 277 | // QS_FILTER_OFF(QS_QEP_TRAN); |
QL | 4:6189d844a1a2 | 278 | // QS_FILTER_OFF(QS_QEP_IGNORED); |
QL | 4:6189d844a1a2 | 279 | |
QL | 4:6189d844a1a2 | 280 | // QS_FILTER_OFF(QS_QF_ACTIVE_ADD); |
QL | 4:6189d844a1a2 | 281 | // QS_FILTER_OFF(QS_QF_ACTIVE_REMOVE); |
QL | 4:6189d844a1a2 | 282 | // QS_FILTER_OFF(QS_QF_ACTIVE_SUBSCRIBE); |
QL | 4:6189d844a1a2 | 283 | // QS_FILTER_OFF(QS_QF_ACTIVE_UNSUBSCRIBE); |
QL | 4:6189d844a1a2 | 284 | // QS_FILTER_OFF(QS_QF_ACTIVE_POST_FIFO); |
QL | 4:6189d844a1a2 | 285 | // QS_FILTER_OFF(QS_QF_ACTIVE_POST_LIFO); |
QL | 4:6189d844a1a2 | 286 | // QS_FILTER_OFF(QS_QF_ACTIVE_GET); |
QL | 4:6189d844a1a2 | 287 | // QS_FILTER_OFF(QS_QF_ACTIVE_GET_LAST); |
QL | 4:6189d844a1a2 | 288 | // QS_FILTER_OFF(QS_QF_EQUEUE_INIT); |
QL | 4:6189d844a1a2 | 289 | // QS_FILTER_OFF(QS_QF_EQUEUE_POST_FIFO); |
QL | 4:6189d844a1a2 | 290 | // QS_FILTER_OFF(QS_QF_EQUEUE_POST_LIFO); |
QL | 4:6189d844a1a2 | 291 | // QS_FILTER_OFF(QS_QF_EQUEUE_GET); |
QL | 4:6189d844a1a2 | 292 | // QS_FILTER_OFF(QS_QF_EQUEUE_GET_LAST); |
QL | 4:6189d844a1a2 | 293 | // QS_FILTER_OFF(QS_QF_MPOOL_INIT); |
QL | 4:6189d844a1a2 | 294 | // QS_FILTER_OFF(QS_QF_MPOOL_GET); |
QL | 4:6189d844a1a2 | 295 | // QS_FILTER_OFF(QS_QF_MPOOL_PUT); |
QL | 4:6189d844a1a2 | 296 | // QS_FILTER_OFF(QS_QF_PUBLISH); |
QL | 4:6189d844a1a2 | 297 | // QS_FILTER_OFF(QS_QF_NEW); |
QL | 4:6189d844a1a2 | 298 | // QS_FILTER_OFF(QS_QF_GC_ATTEMPT); |
QL | 4:6189d844a1a2 | 299 | // QS_FILTER_OFF(QS_QF_GC); |
QL | 4:6189d844a1a2 | 300 | // QS_FILTER_OFF(QS_QF_TICK); |
QL | 4:6189d844a1a2 | 301 | // QS_FILTER_OFF(QS_QF_TIMEEVT_ARM); |
QL | 4:6189d844a1a2 | 302 | // QS_FILTER_OFF(QS_QF_TIMEEVT_AUTO_DISARM); |
QL | 4:6189d844a1a2 | 303 | // QS_FILTER_OFF(QS_QF_TIMEEVT_DISARM_ATTEMPT); |
QL | 4:6189d844a1a2 | 304 | // QS_FILTER_OFF(QS_QF_TIMEEVT_DISARM); |
QL | 4:6189d844a1a2 | 305 | // QS_FILTER_OFF(QS_QF_TIMEEVT_REARM); |
QL | 4:6189d844a1a2 | 306 | // QS_FILTER_OFF(QS_QF_TIMEEVT_POST); |
QL | 4:6189d844a1a2 | 307 | QS_FILTER_OFF(QS_QF_CRIT_ENTRY); |
QL | 4:6189d844a1a2 | 308 | QS_FILTER_OFF(QS_QF_CRIT_EXIT); |
QL | 4:6189d844a1a2 | 309 | QS_FILTER_OFF(QS_QF_ISR_ENTRY); |
QL | 4:6189d844a1a2 | 310 | QS_FILTER_OFF(QS_QF_ISR_EXIT); |
QL | 4:6189d844a1a2 | 311 | |
QL | 4:6189d844a1a2 | 312 | return true; // return success |
QL | 4:6189d844a1a2 | 313 | } |
QL | 4:6189d844a1a2 | 314 | //............................................................................ |
QL | 4:6189d844a1a2 | 315 | void QS::onCleanup(void) { |
QL | 4:6189d844a1a2 | 316 | } |
QL | 4:6189d844a1a2 | 317 | //............................................................................ |
QL | 4:6189d844a1a2 | 318 | QSTimeCtr QS::onGetTime(void) { // invoked with interrupts locked |
QL | 4:6189d844a1a2 | 319 | if ((SysTick->CTRL & 0x00000100U) == 0U) { // COUNTFLAG no set? |
QL | 4:6189d844a1a2 | 320 | return DPP::l_tickTime - (QSTimeCtr)SysTick->VAL; |
QL | 4:6189d844a1a2 | 321 | } |
QL | 4:6189d844a1a2 | 322 | else { // the rollover occured, but the SysTick_ISR did not run yet |
QL | 4:6189d844a1a2 | 323 | return DPP::l_tickTime + DPP::l_tickPeriod - (QSTimeCtr)SysTick->VAL; |
QL | 4:6189d844a1a2 | 324 | } |
QL | 4:6189d844a1a2 | 325 | } |
QL | 4:6189d844a1a2 | 326 | //............................................................................ |
QL | 4:6189d844a1a2 | 327 | void QS::onFlush(void) { |
QL | 4:6189d844a1a2 | 328 | uint16_t b; |
QL | 4:6189d844a1a2 | 329 | QF_INT_DISABLE(); |
QL | 4:6189d844a1a2 | 330 | while ((b = QS::getByte()) != QS_EOD) { |
QL | 4:6189d844a1a2 | 331 | while (!DPP::l_qspy.writeable()) { // wait until serial is writable |
QL | 4:6189d844a1a2 | 332 | } |
QL | 4:6189d844a1a2 | 333 | DPP::l_qspy.putc((uint8_t)b); |
QL | 4:6189d844a1a2 | 334 | } |
QL | 4:6189d844a1a2 | 335 | QF_INT_ENABLE(); |
QL | 4:6189d844a1a2 | 336 | } |
QL | 4:6189d844a1a2 | 337 | #endif // Q_SPY |
QL | 4:6189d844a1a2 | 338 | //---------------------------------------------------------------------------- |
QL | 4:6189d844a1a2 | 339 | |
QL | 4:6189d844a1a2 | 340 | } // namespace QP |