Skip to content

Commit 757554d

Browse files
committed
6.9.3
Added blinky2 example to libraries/qpcpp_sam/examples, updated Readme.md
1 parent 82ebc10 commit 757554d

File tree

4 files changed

+582
-6
lines changed

4 files changed

+582
-6
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ as follows:
5252
| | | +-blinky/ - Blinky example
5353
| | | | +-blinky.ino - Blinky code (generated)
5454
| | | | +-blinky.qm - Blinky model (for QM tool)
55+
| | | +-blinky2/ - Blinky2 example for blinking two LEDs
56+
| | | | +-blinky2.ino - Blinky2 code (generated)
57+
| | | | +-blinky2.qm - Blinky2 model (for QM tool)
5558
| | | +-blinky_bsp/ - Blinky example with Board Support Package
5659
| | | | +-blinky_bsp.ino - Blinky code (generated)
5760
| | | | +-blinky_bsp.qm - Blinky model (for QM tool)
@@ -67,20 +70,19 @@ as follows:
6770
| +-qpn_avr/ - QP-nano library for AVR-based Arduinos
6871
| | +-... (now obsolete, for backgwards compatibility only)
6972
| |
70-
| +-qm/ - QM modeling tool for Windows
73+
| +-qm/ - QM modeling tool (for Windows, Linux, or macOS)
7174
| | +-bin/ - QM binaries (executable and DLLs)
72-
| | | +-qm.exe - QM executable for Windows
75+
| | | +-qm.exe - QM executable (for Windows)
7376
| | +-Resources/ - QM resources
7477
| | | +-...
7578
|
7679
+-README.md - this file
7780
+-QP-Arduino_GPL_Exception.txt - GPL exception for QP on Arduino
7881

7982

80-
NOTE: The QP-Arduino archive contains QM for Windows only. But QM is also
81-
available for Linux and MacOS hosts. If you wish to work on those operating
82-
systems, you will need to install QM separately, as described at:
83-
https://www.state-machine.com/qm/gs.html
83+
NOTE: The QP-Arduino archive contains QM for the platform of your choice
84+
(Windows, Linux or macOS), but this requires downloading the corresponding
85+
version of the QP-Arduino integration.
8486

8587

8688
----
Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
//.$file${.::blinky2.ino} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2+
//
3+
// Model: blinky2.qm
4+
// File: ${.::blinky2.ino}
5+
//
6+
// This code has been generated by QM 5.1.3 <www.state-machine.com/qm/>.
7+
// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
8+
//
9+
// This program is open source software: you can redistribute it and/or
10+
// modify it under the terms of the GNU General Public License as published
11+
// by the Free Software Foundation.
12+
//
13+
// This program is distributed in the hope that it will be useful, but
14+
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16+
// for more details.
17+
//
18+
//.$endhead${.::blinky2.ino} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
#include "qpcpp.hpp" // QP-C++ framework
20+
21+
using namespace QP;
22+
23+
enum BlinkySignals {
24+
TIMEOUT_SIG = Q_USER_SIG,
25+
MAX_SIG
26+
};
27+
28+
enum {
29+
TICKS_PER_SEC = 100, // number of system clock ticks per second
30+
LED2_PIN = 12,
31+
};
32+
33+
//============================================================================
34+
// genearate declarations of all opaque AO pointers
35+
//.$declare${AOs::AO_Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
36+
extern QP::QActive * const AO_Blinky;
37+
//.$enddecl${AOs::AO_Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
//.$declare${AOs::AO_Blinky2} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
39+
extern QP::QActive * const AO_Blinky2;
40+
//.$enddecl${AOs::AO_Blinky2} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41+
//...
42+
43+
//............................................................................
44+
void setup() {
45+
QF::init(); // initialize the framework
46+
47+
// initialize the hardware used in this sketch...
48+
// NOTE: interrupts are configured and started later in QF::onStartup()
49+
pinMode(LED_BUILTIN, OUTPUT);
50+
pinMode(LED2_PIN, OUTPUT);
51+
52+
// statically allocate event queue buffer for the Blinky AO
53+
static QEvt const *blinky_queueSto[10];
54+
AO_Blinky->start(1U, // priority
55+
blinky_queueSto, Q_DIM(blinky_queueSto),
56+
(void *)0, 0U); // no stack
57+
58+
static QEvt const *blinky2_queueSto[10];
59+
AO_Blinky2->start(2U, // priority
60+
blinky2_queueSto, Q_DIM(blinky2_queueSto),
61+
(void *)0, 0U); // no stack
62+
}
63+
64+
//............................................................................
65+
void loop() {
66+
QF::run(); // run the QF/C++ framework
67+
}
68+
69+
//============================================================================
70+
// QF callbacks...
71+
72+
// ATSAM3X timer used for the system clock tick
73+
// NOTE: re-define the macros to use a different timer/channel
74+
#define TIMER TC1
75+
#define TIMER_CLCK_HZ 650000
76+
#define TIMER_CHANNEL 0
77+
#define TIMER_IRQn TC3_IRQn
78+
#define TIMER_HANDLER TC3_Handler
79+
80+
// interrupts.................................................................
81+
void TIMER_HANDLER(void) {
82+
TC_GetStatus(TIMER, TIMER_CHANNEL); // clear the interrupt source
83+
QF::TICK_X(0, (void *)0); // process time events for tick rate 0
84+
}
85+
//............................................................................
86+
void QF::onStartup(void) {
87+
// configure the timer-counter channel........
88+
pmc_set_writeprotect(false); // disable write protection
89+
pmc_enable_periph_clk(TIMER_IRQn); // enable peripheral clock
90+
TC_Configure(TIMER, TIMER_CHANNEL,
91+
TC_CMR_WAVE // WAVE mode
92+
| TC_CMR_WAVSEL_UP_RC // count-up with trigger on RC compare
93+
| TC_CMR_TCCLKS_TIMER_CLOCK4); // internal Clock4
94+
TC_SetRC(TIMER, TIMER_CHANNEL,
95+
TIMER_CLCK_HZ / TICKS_PER_SEC); // set the RC compare value
96+
TC_Start(TIMER, TIMER_CHANNEL);
97+
// enable interrrupt for RC compare
98+
TIMER->TC_CHANNEL[TIMER_CHANNEL].TC_IER = TC_IER_CPCS;
99+
TIMER->TC_CHANNEL[TIMER_CHANNEL].TC_IDR = ~TC_IER_CPCS;
100+
pmc_set_writeprotect(true); // enable write protection
101+
102+
// explicitly set the NVIC priorities for all kernel AWARE interrupts
103+
NVIC_SetPriority(TIMER_IRQn, QF_AWARE_ISR_CMSIS_PRI);
104+
// ...
105+
106+
// enable the interrupt in the NVIC
107+
NVIC_EnableIRQ(TIMER_IRQn);
108+
// ...
109+
}
110+
//............................................................................
111+
void QV::onIdle(void) { // called with interrupts DISABLED
112+
#ifdef NDEBUG
113+
// Put the CPU and peripherals to the low-power mode. You might
114+
// need to customize the clock management for your application,
115+
// see the datasheet for your particular MCU.
116+
QV_CPU_SLEEP(); // atomically go to sleep and enable interrupts
117+
#else
118+
QF_INT_ENABLE(); // simply re-enable interrupts
119+
#endif
120+
}
121+
//............................................................................
122+
extern "C" Q_NORETURN Q_onAssert(char const * const module, int location) {
123+
//
124+
// NOTE: add here your application-specific error handling
125+
//
126+
(void)module;
127+
(void)location;
128+
129+
QF_INT_DISABLE(); // disable all interrupts
130+
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on
131+
for (;;) { // sit in an endless loop for now
132+
}
133+
}
134+
135+
//============================================================================
136+
// generate declarations and definitions of all AO classes (state machines)...
137+
//.$declare${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
138+
//.${AOs::Blinky} ............................................................
139+
class Blinky : public QP::QActive {
140+
private:
141+
QP::QTimeEvt m_timeEvt;
142+
143+
public:
144+
static Blinky instance;
145+
146+
public:
147+
Blinky();
148+
149+
protected:
150+
Q_STATE_DECL(initial);
151+
Q_STATE_DECL(off);
152+
Q_STATE_DECL(on);
153+
};
154+
//.$enddecl${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155+
//.$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
156+
//. Check for the minimum required QP version
157+
#if (QP_VERSION < 690U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
158+
#error qpcpp version 6.9.0 or higher required
159+
#endif
160+
//.$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
161+
//.$define${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
162+
//.${AOs::Blinky} ............................................................
163+
Blinky Blinky::instance;
164+
//.${AOs::Blinky::Blinky} ....................................................
165+
Blinky::Blinky()
166+
: QActive(Q_STATE_CAST(&Blinky::initial)),
167+
m_timeEvt(this, TIMEOUT_SIG, 0U)
168+
{}
169+
170+
//.${AOs::Blinky::SM} ........................................................
171+
Q_STATE_DEF(Blinky, initial) {
172+
//.${AOs::Blinky::SM::initial}
173+
m_timeEvt.armX(TICKS_PER_SEC/2, TICKS_PER_SEC/2);
174+
(void)e; // unused parameter
175+
return tran(&off);
176+
}
177+
//.${AOs::Blinky::SM::off} ...................................................
178+
Q_STATE_DEF(Blinky, off) {
179+
QP::QState status_;
180+
switch (e->sig) {
181+
//.${AOs::Blinky::SM::off}
182+
case Q_ENTRY_SIG: {
183+
digitalWrite(LED_BUILTIN, LOW); // turn the LED off
184+
status_ = Q_RET_HANDLED;
185+
break;
186+
}
187+
//.${AOs::Blinky::SM::off::TIMEOUT}
188+
case TIMEOUT_SIG: {
189+
status_ = tran(&on);
190+
break;
191+
}
192+
default: {
193+
status_ = super(&top);
194+
break;
195+
}
196+
}
197+
return status_;
198+
}
199+
//.${AOs::Blinky::SM::on} ....................................................
200+
Q_STATE_DEF(Blinky, on) {
201+
QP::QState status_;
202+
switch (e->sig) {
203+
//.${AOs::Blinky::SM::on}
204+
case Q_ENTRY_SIG: {
205+
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on
206+
status_ = Q_RET_HANDLED;
207+
break;
208+
}
209+
//.${AOs::Blinky::SM::on::TIMEOUT}
210+
case TIMEOUT_SIG: {
211+
status_ = tran(&off);
212+
break;
213+
}
214+
default: {
215+
status_ = super(&top);
216+
break;
217+
}
218+
}
219+
return status_;
220+
}
221+
//.$enddef${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
222+
//...
223+
224+
//============================================================================
225+
// generate definitions of all AO opaque pointers...
226+
//.$define${AOs::AO_Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
227+
//.${AOs::AO_Blinky} .........................................................
228+
QP::QActive * const AO_Blinky = &Blinky::instance;
229+
//.$enddef${AOs::AO_Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
230+
//...
231+
232+
//============================================================================
233+
// generate declarations and definitions of all AO classes (state machines)...
234+
//.$declare${AOs::Blinky2} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
235+
//.${AOs::Blinky2} ...........................................................
236+
class Blinky2 : public QP::QActive {
237+
private:
238+
QP::QTimeEvt m_timeEvt;
239+
240+
public:
241+
static Blinky2 instance;
242+
243+
public:
244+
Blinky2();
245+
246+
protected:
247+
Q_STATE_DECL(initial);
248+
Q_STATE_DECL(off);
249+
Q_STATE_DECL(on);
250+
};
251+
//.$enddecl${AOs::Blinky2} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
252+
//.$define${AOs::Blinky2} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
253+
//.${AOs::Blinky2} ...........................................................
254+
Blinky2 Blinky2::instance;
255+
//.${AOs::Blinky2::Blinky2} ..................................................
256+
Blinky2::Blinky2()
257+
: QActive(Q_STATE_CAST(&Blinky2::initial)),
258+
m_timeEvt(this, TIMEOUT_SIG, 0U)
259+
{}
260+
261+
//.${AOs::Blinky2::SM} .......................................................
262+
Q_STATE_DEF(Blinky2, initial) {
263+
//.${AOs::Blinky2::SM::initial}
264+
m_timeEvt.armX(TICKS_PER_SEC/3, TICKS_PER_SEC/3);
265+
(void)e; // unused parameter
266+
return tran(&off);
267+
}
268+
//.${AOs::Blinky2::SM::off} ..................................................
269+
Q_STATE_DEF(Blinky2, off) {
270+
QP::QState status_;
271+
switch (e->sig) {
272+
//.${AOs::Blinky2::SM::off}
273+
case Q_ENTRY_SIG: {
274+
digitalWrite(LED2_PIN, LOW); // turn the LED off
275+
status_ = Q_RET_HANDLED;
276+
break;
277+
}
278+
//.${AOs::Blinky2::SM::off::TIMEOUT}
279+
case TIMEOUT_SIG: {
280+
status_ = tran(&on);
281+
break;
282+
}
283+
default: {
284+
status_ = super(&top);
285+
break;
286+
}
287+
}
288+
return status_;
289+
}
290+
//.${AOs::Blinky2::SM::on} ...................................................
291+
Q_STATE_DEF(Blinky2, on) {
292+
QP::QState status_;
293+
switch (e->sig) {
294+
//.${AOs::Blinky2::SM::on}
295+
case Q_ENTRY_SIG: {
296+
digitalWrite(LED2_PIN, HIGH); // turn the LED on
297+
status_ = Q_RET_HANDLED;
298+
break;
299+
}
300+
//.${AOs::Blinky2::SM::on::TIMEOUT}
301+
case TIMEOUT_SIG: {
302+
status_ = tran(&off);
303+
break;
304+
}
305+
default: {
306+
status_ = super(&top);
307+
break;
308+
}
309+
}
310+
return status_;
311+
}
312+
//.$enddef${AOs::Blinky2} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
313+
//...
314+
315+
//============================================================================
316+
// generate definitions of all AO opaque pointers...
317+
//.$define${AOs::AO_Blinky2} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
318+
//.${AOs::AO_Blinky2} ........................................................
319+
QP::QActive * const AO_Blinky2 = &Blinky2::instance;
320+
//.$enddef${AOs::AO_Blinky2} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
321+
//...

0 commit comments

Comments
 (0)