Skip to content

Commit c461a22

Browse files
author
QL
committed
6.5.1
1 parent 9311f36 commit c461a22

File tree

23 files changed

+2316
-1191
lines changed

23 files changed

+2316
-1191
lines changed

README.md

Lines changed: 87 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,121 @@ Please refer to the companion webiste to this project at:
44
https://www.state-machine.com/arduino
55

66
----
7-
#Software Installation on Windows
7+
# Software Installation
88

99
The QP adaptation for Arduino is distributed in a single ZIP
10-
archive qp-<ver>_arduino-1.8.x.zip, where <ver> stands for version of
11-
the QP frameworks.
12-
13-
You need to unzip the qp-<ver>_arduino-1.8.x.zip archive into your
14-
Arduino-Sketchbook folder. To find out where your Sketchbook folder is,
15-
or to configure a different location for your Sketchbook folder, you
16-
need to open the Arduino IDE and select File | Preferences menu. The
17-
sketchbook location will be shown at the top of the Preferences dialog
18-
box. Once you identify the Sketchbook folder, you simply unzip the whole
19-
archive to your Sketchbook.
10+
archive `qp-<ver>_arduino-1.8.x.zip`, where `<ver>` stands for
11+
the version of the QP frameworks.
12+
13+
You need to unzip the `qp-<ver>_arduino-1.8.x.zip` archive into your
14+
Arduino `<Sketchbook>` folder. To find out where your `<Sketchbook>` folder
15+
is, or to configure a different location for your `<Sketchbook>` folder,
16+
you need to open the Arduino IDE and select `File|Preferences` menu.
17+
The Sketchbook location will be shown at the top of the Preferences
18+
dialog box. Once you identify the `<Sketchbook>` folder, you simply unzip
19+
the whole `qp-<ver>_arduino-1.8.x.zip` archive to this folder.
2020

2121
----
22-
#Provided Libraries
22+
# Provided Libraries
2323

24-
The archive qp-<ver>_arduino-1.8.x.zip contains two external libraries
24+
The archive `qp-<ver>_arduino-1.8.x.zip` contains two external libraries
2525
for Arduino:
2626

27-
- qpcpp_sam -- QP/C++ framework for SAM-based Arduinos (ARM Cortex-M)
28-
- qpn_avr -- QP-nano framework for AVR based Arduinos
27+
- `qpcpp_sam` -- QP/C++ framework for SAM-based Arduinos
28+
- `qpn_avr` -- QP-nano framework for AVR-based Arduinos
29+
30+
After the installation, your Arduino `<Sketchbook>` folder should look
31+
as follows:
32+
33+
<Sketchbook>/ - your Arduino Sketchbook folder
34+
|
35+
+-libraries/ - libraries folder
36+
| +-qpcpp_sam/ - QP/C++ library for SAM-based Arduinos
37+
| | +-examples/ - QP/C++ library examples
38+
| | | +-blinky/ - Blinky example
39+
| | | | +-blinky.ino - Blinky code (generated)
40+
| | | | +-blinky.qm - Blinky model (for QM tool)
41+
| | +-src/ - QP/C++ library source code
42+
| | | +-qpcpp.h - QP/C++ library header file
43+
| | | +-... - QP/C++ library sources
44+
| | +-library.properties - QP/C++ library properties
45+
| |
46+
| +-qpn_avr/ - QP-nano library for AVR-based Arduinos
47+
| | +-examples/ - QP-nano library examples
48+
| | | +-blinky/ - Blinky example
49+
| | | | +-blinky.ino - Blinky code (generated)
50+
| | | | +-blinky.qm - Blinky model (for QM tool)
51+
| | | +-dpp/ - Dining Philosophers Problem (DPP)
52+
| | | | +-dpp.ino - DPP code (generated)
53+
| | | | +-dpp.qm - DPP model (for QM tool)
54+
| | | +-pelican/ - PEdestrian LIghtr CONtrolled crossing
55+
| | | | +-pelican.ino - PELICAN code (generated)
56+
| | | | +-pelican.qm - PELICAN model (for QM tool)
57+
| | +-src/ - QP-nano library source code
58+
| | | +-qpn.h - QP-nano library header file
59+
| | | +-... - QP-nano library sources
60+
| | +-library.properties - QP-nano library properties
61+
|
62+
+-README.md - this file
63+
+-QP-Arduino-Playground - web link to QP on Arduino Playground
64+
+-QP-Arduino_GPL_Exception.txt - GPL exception for QP on Arduino
2965

3066

3167
----
32-
#Working with the Examples
68+
# Working with the Examples
3369

34-
Each QP library contains the examples sub-directory, which contans the
35-
QM model file and the generated code. The intended way of working with
36-
the examples is to use the QM modeling tool to modify the state diagrams
37-
and the code, and to use the Arduino IDE only to build and upload
38-
the code to the Arduino board(s).
39-
70+
Assumming that you have installed the QP libraries in your `<Sketchbook>`
71+
folder, the examples provided in each QP library show up in the Arduino
72+
IDE under the menu:
4073

41-
> NOTE: The preferences in the Arduino IDE should be set up to
42-
"Use external editor" so that the IDE will update the code each time
43-
it is re-generated by the QM modeling tool.
74+
`File|Examples|Examples from Custom Libraries`
4475

76+
The intended way of working with the examples is to use the
77+
[QM modeling tool](https://www.state-machine.com/qm/) to modify the
78+
**models** (`.qm` files) and then to **generate code** from these
79+
models. In this scenario, the Arduino IDE is used only to build and
80+
upload the code to the Arduino board(s).
4581

46-
When you unzip the archive into your Sketchbook directory, the examples
47-
provided in each QP library shows up in the Arduino IDE under the menu:
82+
> **NOTE:** The preferences in the Arduino IDE should be set up to
83+
**Use external editor** so that the IDE will update the code each time
84+
it is re-generated by the QM modeling tool.
4885

49-
File|Examples|Examples from Custom Libraries
5086

87+
----
88+
# Example Documentation
89+
90+
Each example model has documentation, which you can view in the QM tool.
91+
The model documentation shows in the Property Editor when the model item
92+
is active.
93+
5194

5295
----
53-
#Licensing
96+
# Licensing
5497

5598
The QP real-time embedded frameworks for Arduino are licensed under the
56-
modified GPLv3 license with the QP-Arduino Exception (see file
57-
QP-Arduino_GPL_Exception.txt in the root of the archive). Specifically,
58-
the Exception removes the requirement to expose your propriatory source
59-
code as long as you deploy it on an Arduino-Certified board.
99+
modified GPLv3 license with the
100+
[QP-Arduino Exception](https://www.state-machine.com/licensing/QP-Arduino_GPL_Exception.txt)
101+
(see also the file QP-Arduino_GPL_Exception.txt in the root of the archive).
102+
Specifically, the Exception removes the requirement to expose your
103+
propriatory source code as long as you deploy it on an Arduino-Certified
104+
board.
60105

61-
The QM graphical modeling tool is freeware. The QM tool is provided
62-
under the terms of a simple End-User License Agreement (EULA).
106+
The [QM model-based design tool](https://www.state-machine.com/qm/) is freeware.
107+
The QM tool is provided under the terms of a simple
108+
[End-User License Agreement (EULA)](https://www.state-machine.com/qm/license.html).
63109

64110

65111
----
66-
#Documentation
112+
# Companion Web Page
67113

68-
Please refer to the companion webiste to this project at:
114+
Please refer to the companion web page to this project at:
69115

70116
https://www.state-machine.com/arduino
71117

72118

73-
Support Questions
74-
=================
119+
----
120+
# Support Questions
121+
75122
Please submit any questions or comments to the free QP support forum at:
123+
76124
https://sourceforge.net/p/qpc/discussion/668726

libraries/qpcpp_sam/examples/blinky/blinky.ino

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,16 @@ enum BlinkySignals {
2727
};
2828

2929
enum {
30-
BSP_TICKS_PER_SEC = 100,
30+
TICKS_PER_SEC = 100 // number of system clock ticks per second
3131
};
3232

33-
void BSP_ledOff(void) {
34-
digitalWrite(LED_BUILTIN, LOW);
35-
}
36-
void BSP_ledOn(void) {
37-
digitalWrite(LED_BUILTIN, HIGH);
38-
}
39-
4033
//============================================================================
41-
// declare all AO classes...
42-
//$declare${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
43-
//${AOs::Blinky} .............................................................
44-
class Blinky : public QP::QActive {
45-
private:
46-
QP::QTimeEvt m_timeEvt;
47-
48-
public:
49-
Blinky();
50-
51-
protected:
52-
Q_STATE_DECL(initial);
53-
Q_STATE_DECL(off);
54-
Q_STATE_DECL(on);
55-
};
56-
//$enddecl${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
// genearate declarations of all opaque AO pointers
35+
//$declare${AOs::AO_Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
36+
extern QP::QActive * const AO_Blinky;
37+
//$enddecl${AOs::AO_Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5738
//...
5839

59-
static Blinky l_blinky;
60-
QActive * const AO_Blinky = &l_blinky;
61-
6240
//............................................................................
6341
void setup() {
6442
QF::init(); // initialize the framework
@@ -105,7 +83,7 @@ void QF::onStartup(void) {
10583
| TC_CMR_WAVSEL_UP_RC // count-up with trigger on RC compare
10684
| TC_CMR_TCCLKS_TIMER_CLOCK4); // internal Clock4
10785
TC_SetRC(TIMER, TIMER_CHANNEL,
108-
TIMER_CLCK_HZ / BSP_TICKS_PER_SEC); // set the RC compare value
86+
TIMER_CLCK_HZ / TICKS_PER_SEC); // set the RC compare value
10987
TC_Start(TIMER, TIMER_CHANNEL);
11088
// enable interrrupt for RC compare
11189
TIMER->TC_CHANNEL[TIMER_CHANNEL].TC_IER = TC_IER_CPCS;
@@ -135,13 +113,31 @@ void QV::onIdle(void) { // called with interrupts DISABLED
135113
extern "C" void Q_onAssert(char const * const module, int loc) {
136114
// implement the error-handling policy for your application!!!
137115
QF_INT_DISABLE(); // disable all interrupts
138-
BSP_ledOn();
116+
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on
139117
for (;;) { // sit in an endless loop for now
140118
}
141119
}
142120

143121
//============================================================================
144-
// define all AO classes (state machine)...
122+
// generate declarations and definitions of all AO classes (state machines)...
123+
//$declare${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
124+
//${AOs::Blinky} .............................................................
125+
class Blinky : public QP::QActive {
126+
private:
127+
QP::QTimeEvt m_timeEvt;
128+
129+
public:
130+
static Blinky instance;
131+
132+
public:
133+
Blinky();
134+
135+
protected:
136+
Q_STATE_DECL(initial);
137+
Q_STATE_DECL(off);
138+
Q_STATE_DECL(on);
139+
};
140+
//$enddecl${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145141
//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
146142
// Check for the minimum required QP version
147143
#if (QP_VERSION < 650U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
@@ -150,6 +146,7 @@ extern "C" void Q_onAssert(char const * const module, int loc) {
150146
//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151147
//$define${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
152148
//${AOs::Blinky} .............................................................
149+
Blinky Blinky::instance;
153150
//${AOs::Blinky::Blinky} .....................................................
154151
Blinky::Blinky()
155152
: QActive(Q_STATE_CAST(&Blinky::initial)),
@@ -159,7 +156,7 @@ Blinky::Blinky()
159156
//${AOs::Blinky::SM} .........................................................
160157
Q_STATE_DEF(Blinky, initial) {
161158
//${AOs::Blinky::SM::initial}
162-
m_timeEvt.armX(BSP_TICKS_PER_SEC/2, BSP_TICKS_PER_SEC/2);
159+
m_timeEvt.armX(TICKS_PER_SEC/2, TICKS_PER_SEC/2);
163160
(void)e; // unused parameter
164161
return tran(&off);
165162
}
@@ -169,7 +166,7 @@ Q_STATE_DEF(Blinky, off) {
169166
switch (e->sig) {
170167
//${AOs::Blinky::SM::off}
171168
case Q_ENTRY_SIG: {
172-
BSP_ledOff();
169+
digitalWrite(LED_BUILTIN, LOW); // turn the LED off
173170
status_ = Q_RET_HANDLED;
174171
break;
175172
}
@@ -191,7 +188,7 @@ Q_STATE_DEF(Blinky, on) {
191188
switch (e->sig) {
192189
//${AOs::Blinky::SM::on}
193190
case Q_ENTRY_SIG: {
194-
BSP_ledOn();
191+
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on
195192
status_ = Q_RET_HANDLED;
196193
break;
197194
}
@@ -209,3 +206,11 @@ Q_STATE_DEF(Blinky, on) {
209206
}
210207
//$enddef${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
211208
//...
209+
210+
//============================================================================
211+
// generate definitions of all AO opaque pointers...
212+
//$define${AOs::AO_Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
213+
//${AOs::AO_Blinky} ..........................................................
214+
QP::QActive * const AO_Blinky = &Blinky::instance;
215+
//$enddef${AOs::AO_Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
216+
//...

0 commit comments

Comments
 (0)