-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbsp.cpp
More file actions
301 lines (255 loc) · 10.7 KB
/
Copy pathbsp.cpp
File metadata and controls
301 lines (255 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
//////////////////////////////////////////////////////////////////////////////
// Product: DPP example, configurable Vanilla/QK kernel
// Last Updated for Version: 4.5.02
// Date of the Last Update: Sep 04, 2012
//
// Q u a n t u m L e a P s
// ---------------------------
// innovating embedded systems
//
// Copyright (C) 2002-2012 Quantum Leaps, LLC. All rights reserved.
//
// This program is open source software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// Alternatively, this program may be distributed and modified under the
// terms of Quantum Leaps commercial licenses, which expressly supersede
// the GNU General Public License and are specifically designed for
// licensees interested in retaining the proprietary status of their code.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Contact information:
// Quantum Leaps Web sites: http://www.quantum-leaps.com
// http://www.state-machine.com
// e-mail: info@quantum-leaps.com
//////////////////////////////////////////////////////////////////////////////
#include "bsp.h"
#include "mbed.h" // mbed is used only for the built-in serial
#include "LogUtil.h"
//////////////////////////////////////////////////////////////////////////////
namespace BSP {
Q_DEFINE_THIS_FILE
enum ISR_Priorities { // ISR priorities starting from the highest urgency
SYSTICK_PRIO
// ...
};
static DigitalOut myLed(LED2);
#ifdef Q_SPY
QP::QSTimeCtr l_tickTime;
QP::QSTimeCtr l_tickPeriod;
static uint8_t l_SysTick_Handler;
#define QSPY_BAUD_RATE 9600U
enum AppRecords { // application-specific trace records
PHILO_STAT = QP::QS_USER
};
Serial l_qspy(SERIAL_TX, SERIAL_RX);
#endif
//............................................................................
extern "C" void SysTick_Handler(void) __attribute__((__interrupt__));
extern "C" void SysTick_Handler(void)
{
QK_ISR_ENTRY(); // inform the QK kernel of entering the ISR
LOG("<<=====Sys Tick====>>\r\n");
#ifdef Q_SPY
uint32_t volatile dummy = SysTick->CTRL; // clear the COUNTFLAG in SysTick
l_tickTime += l_tickPeriod; // account for the clock rollover
#endif
//QP::QF::TICK(&l_SysTick_Handler); // process all armed time events
static QP::QEvt const tickEvt = QEVT_INITIALIZER(TIME_TICK_SIG);
QP::QF::PUBLISH(&tickEvt,&l_SysTick_Handler);
QK_ISR_EXIT(); // inform the QK kernel of exiting the ISR
LOG("<<=====Sys Tick performed====>>\r\n");
}
//............................................................................
void BSP_init(void) {
// set the system clock as specified in lm3s_config.h (20MHz from PLL)
//SystemInit();
//SystemCoreClockUpdate();
//SetSysClock();
// initialize the QS software tracing...
Q_ALLEGE(QS_INIT(static_cast<void *>(0)));
QS_RESET();
QS_OBJ_DICTIONARY(&l_SysTick_Handler);
}
//............................................................................
void BSP_terminate(int16_t const result) {
(void)result;
}
//............................................................................
//............................................................................
//............................................................................
//............................................................................
//............................................................................
extern "C" void Q_onAssert(char_t const * const file, int_t const line) {
(void)file; // avoid compiler warning
(void)line; // avoid compiler warning
QF_INT_DISABLE(); // make sure that all interrupts are disabled
// light up all LEDs
for (;;) { // NOTE: replace the loop with reset for final version
LOG("assertion error\r\n");
__NOP();
__NOP();
}
}
} // namespace DPP
//////////////////////////////////////////////////////////////////////////////
namespace QP {
//............................................................................
void QF::onStartup(void) {
// set up the SysTick timer to fire at BSP_TICKS_PER_SEC rate
// set priorities of all interrupts in the system...
(void)SysTick_Config((SystemCoreClock - 2) / BSP::BSP_TICKS_PER_SEC);
NVIC_SetPriority(SysTick_IRQn, BSP::SYSTICK_PRIO);
//NVIC_SetPriority(EINT0_IRQn, BSP::GPIOPORTA_PRIO);
//NVIC_EnableIRQ(SysTick_IRQn);
}
//............................................................................
void QF::onCleanup(void) {
}
//............................................................................
#ifdef QK_PREEMPTIVE
void QK::onIdle(void) {
QF_INT_DISABLE();
BSP::myLed = 1; // turn the LED4 on
__NOP(); // delay a bit to see some light intensity
__NOP();
__NOP();
__NOP();
BSP::myLed = 0; // turn the LED4 off
QF_INT_ENABLE();
#ifdef Q_SPY
if (BSP::l_qspy.writeable()) {
QF_INT_DISABLE();
uint16_t b = QS::getByte();
QF_INT_ENABLE();
if (b != QS_EOD) {
BSP::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.
//
// Specifially for the mbed board, see the articles:
// * "Power Management" http://mbed.org/cookbook/Power-Management; and
// * "Interface Powerdown" at
// http://mbed.org/users/simon/notebook/interface-powerdown/
//
//__WFI();
#endif
}
#else // non-preemptive Vanilla kernel
void QF::onIdle(void) { // NOTE: called with interrupts DISABLED
#ifdef Q_SPY
QF_INT_ENABLE();
if (BSP::l_qspy.writeable()) {
QF_INT_DISABLE();
uint16_t b = QS::getByte();
QF_INT_ENABLE();
if (b != QS_EOD) {
BSP::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.
//
// Specifially for the mbed board, see the articles:
// * "Power Management" http://mbed.org/cookbook/Power-Management; and
// * "Interface Powerdown" at
// http://mbed.org/users/simon/notebook/interface-powerdown/
//
__WFI();
QF_INT_ENABLE();
#endif
}
#endif // QK_PREEMPTIVE
//----------------------------------------------------------------------------
#ifdef Q_SPY
//............................................................................
bool QS::onStartup(void const *arg) {
static uint8_t qsBuf[6*256]; // buffer for Quantum Spy
initBuf(qsBuf, sizeof(qsBuf));
BSP::l_qspy.baud(QSPY_BAUD_RATE);
BSP::l_tickPeriod = SystemCoreClock / BSP::BSP_TICKS_PER_SEC;
BSP::l_tickTime = BSP::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_CRIT_ENTRY);
// QS_FILTER_OFF(QS_QF_CRIT_EXIT);
// QS_FILTER_OFF(QS_QF_ISR_ENTRY);
// QS_FILTER_OFF(QS_QF_ISR_EXIT);
return true; // return success
}
//............................................................................
void QS::onCleanup(void) {
}
//............................................................................
QSTimeCtr QS::onGetTime(void) { // invoked with interrupts locked
if ((SysTick->CTRL & 0x00000100U) == 0U) { // COUNTFLAG no set?
return BSP::l_tickTime - (QSTimeCtr)SysTick->VAL;
}
else { // the rollover occured, but the SysTick_ISR did not run yet
return BSP::l_tickTime + BSP::l_tickPeriod - (QSTimeCtr)SysTick->VAL;
}
}
//............................................................................
void QS::onFlush(void) {
uint16_t b;
QF_INT_DISABLE();
while ((b = QS::getByte()) != QS_EOD) {
while (!BSP::l_qspy.writeable()) { // wait until serial is writable
}
BSP::l_qspy.putc((uint8_t)b);
}
QF_INT_ENABLE();
}
#endif // Q_SPY
//----------------------------------------------------------------------------
} // namespace QP