Skip to content

Fix dpp example #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,4 @@ Open any of the examples and upload to an ESP32.

- Typically `QF::run()` should be executed as a last instruction before QP takes charge of executing the framework. As such, it should not return and instead give control to the scheduler of the host. However, the ESP32 framework (esp-idf) already runs the scheduler [before](https://github.com/espressif/arduino-esp32/blob/8ee5f0a11e5423a018e0f89146e05074466274db/cores/esp32/main.cpp#L55) `void setup()` and `void loop()`. This means that instead of running `QF::run()` in a loop, it suffices to execute it once as the last instruction in `void setup()`.

## QPSY

[QSPY](https://www.state-machine.com/qtools/qspy.html) can be activated by defining `QS_ON`in `bsp.cpp` of both examples

Example of how to communicate with esp32 target with qspy enabled.

```bash
qspy -c YOUR_SERIAL_PORT -b 115200
```

## QView

DPP example can be tested with [QView™](https://www.state-machine.com/qtools/qview.html) example located in `examples/dpp_bsp-esp32/qview`. There are two bat scripts (Windows) which can run the QView scripts.


Note: QSpy must be running before using QView.




- No more QSpy on this port
46 changes: 34 additions & 12 deletions examples/blinky_bsp-esp32/blinky.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
//.$file${.::blinky.hpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//$file${.::blinky.hpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//
// Model: blinky_bsp-esp32.qm
// File: ${.::blinky.hpp}
//
// This code has been generated by QM 5.1.1 <www.state-machine.com/qm/>.
// This code has been generated by QM 7.0.1 <www.state-machine.com/qm>.
// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
//
// 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.
// Copyright (c) 2005 Quantum Leaps, LLC. All rights reserved.
//
// 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.
// ____________________________________
// / /
// / GGGGGGG PPPPPPPP LL /
// / GG GG PP PP LL /
// / GG PP PP LL /
// / GG GGGGG PPPPPPPP LL /
// / GG GG PP LL /
// / GGGGGGG PP LLLLLLL /
// /___________________________________/
//
//.$endhead${.::blinky.hpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This generated code is open-source software licensed under the GNU
// General Public License (GPL) as published by the Free Software Foundation
// (see <https://www.gnu.org/licenses>).
//
// NOTE:
// The GPL does NOT permit the incorporation of this code into proprietary
// programs. Please contact Quantum Leaps for commercial licensing options,
// which expressly supersede the GPL and are designed explicitly for
// closed-source distribution.
//
// Quantum Leaps contact information:
// <www.state-machine.com/licensing>
// <[email protected]>
//
//$endhead${.::blinky.hpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#ifndef BLINKY_HPP
#define BLINKY_HPP

Expand All @@ -25,9 +44,12 @@ enum BlinkySignals {
};

// genearate declarations of all opaque AO pointers
//.$declare${AOs::AO_Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//$declare${AOs::AO_Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

//${AOs::AO_Blinky} ..........................................................
extern QP::QActive * const AO_Blinky;
//.$enddecl${AOs::AO_Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$enddecl${AOs::AO_Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//...

#endif // BLINKY_HPP

117 changes: 76 additions & 41 deletions examples/blinky_bsp-esp32/blinky_bsp-esp32.ino
Original file line number Diff line number Diff line change
@@ -1,41 +1,69 @@
//.$file${.::blinky_bsp-esp32.ino} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//$file${.::blinky_bsp-esp32.ino} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//
// Model: blinky_bsp-esp32.qm
// File: ${.::blinky_bsp-esp32.ino}
//
// This code has been generated by QM 5.1.1 <www.state-machine.com/qm/>.
// This code has been generated by QM 7.0.1 <www.state-machine.com/qm>.
// DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
//
// 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.
// Copyright (c) 2005 Quantum Leaps, LLC. All rights reserved.
//
// 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.
// ____________________________________
// / /
// / GGGGGGG PPPPPPPP LL /
// / GG GG PP PP LL /
// / GG PP PP LL /
// / GG GGGGG PPPPPPPP LL /
// / GG GG PP LL /
// / GGGGGGG PP LLLLLLL /
// /___________________________________/
//
//.$endhead${.::blinky_bsp-esp32.ino} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This generated code is open-source software licensed under the GNU
// General Public License (GPL) as published by the Free Software Foundation
// (see <https://www.gnu.org/licenses>).
//
// NOTE:
// The GPL does NOT permit the incorporation of this code into proprietary
// programs. Please contact Quantum Leaps for commercial licensing options,
// which expressly supersede the GPL and are designed explicitly for
// closed-source distribution.
//
// Quantum Leaps contact information:
// <www.state-machine.com/licensing>
// <[email protected]>
//
//$endhead${.::blinky_bsp-esp32.ino} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#include "qpcpp.hpp" // QP-C++ framework
#include "blinky.hpp" // Blinky application interface
#include "bsp.hpp" // Board Support Package (BSP)

using namespace QP;
static constexpr unsigned stack_size = 1000;

static constexpr unsigned stack_size = 1700;
//............................................................................
void setup() {
QF::init(); // initialize the framework
BSP::init(); // initialize the BSP

// initialize event pools
static QF_MPOOL_EL(QP::QEvt) smlPoolSto[20];
QP::QF::poolInit(smlPoolSto, sizeof(smlPoolSto), sizeof(smlPoolSto[0]));

// initialize publish-subscribe
static QP::QSubscrList subscrSto[10];
QP::QActive::psInit(subscrSto, Q_DIM(subscrSto));

// statically allocate event queues for the AOs and start them...
static QEvt const *blinky_queueSto[30];
static QP::QEvtPtr blinky_queueSto[30];
static StackType_t stack[stack_size];
AO_Blinky->start(1U, // priority
blinky_queueSto, // queu storage for evets
blinky_queueSto, // queue storage for events
Q_DIM(blinky_queueSto), //len of queue
nullptr, // No static stack
stack_size);
QF::run(); // Normally QF Run is located in a loop
stack,
sizeof(stack));

QF::run(); // Normally QF Run is located in a loop
//but since using Arduino SDK not necessary
// Called once to call QF::OnStartup and produce the QS trace
}
Expand All @@ -46,8 +74,9 @@ void loop() {

//============================================================================
// generate declarations and definitions of all AO classes (state machines)...
//.$declare${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//.${AOs::Blinky} ............................................................
//$declare${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

//${AOs::Blinky} .............................................................
class Blinky : public QP::QActive {
private:
QP::QTimeEvt m_timeEvt;
Expand All @@ -62,26 +91,28 @@ protected:
Q_STATE_DECL(initial);
Q_STATE_DECL(off);
Q_STATE_DECL(on);
};
//.$enddecl${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//.$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//. Check for the minimum required QP version
#if (QP_VERSION < 690U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
#error qpcpp version 6.9.0 or higher required
}; // class Blinky
//$enddecl${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// Check for the minimum required QP version
#if (QP_VERSION < 730U) || (QP_VERSION != ((QP_RELEASE^4294967295U)%0x2710U))
#error qpcpp version 7.3.0 or higher required
#endif
//.$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//.$define${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//.${AOs::Blinky} ............................................................
//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$define${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

//${AOs::Blinky} .............................................................
Blinky Blinky::instance;
//.${AOs::Blinky::Blinky} ....................................................

//${AOs::Blinky::Blinky} .....................................................
Blinky::Blinky()
: QActive(Q_STATE_CAST(&Blinky::initial)),
m_timeEvt(this, TIMEOUT_SIG, 0U)
{}

//.${AOs::Blinky::SM} ........................................................
//${AOs::Blinky::SM} .........................................................
Q_STATE_DEF(Blinky, initial) {
//.${AOs::Blinky::SM::initial}
//${AOs::Blinky::SM::initial}
(void)e; // unused parameter
m_timeEvt.armX(BSP::TICKS_PER_SEC/2, BSP::TICKS_PER_SEC/2);

Expand All @@ -93,17 +124,18 @@ Q_STATE_DEF(Blinky, initial) {

return tran(&off);
}
//.${AOs::Blinky::SM::off} ...................................................

//${AOs::Blinky::SM::off} ....................................................
Q_STATE_DEF(Blinky, off) {
QP::QState status_;
switch (e->sig) {
//.${AOs::Blinky::SM::off}
//${AOs::Blinky::SM::off}
case Q_ENTRY_SIG: {
BSP::ledOff();
status_ = Q_RET_HANDLED;
break;
}
//.${AOs::Blinky::SM::off::TIMEOUT}
//${AOs::Blinky::SM::off::TIMEOUT}
case TIMEOUT_SIG: {
status_ = tran(&on);
break;
Expand All @@ -115,17 +147,18 @@ Q_STATE_DEF(Blinky, off) {
}
return status_;
}
//.${AOs::Blinky::SM::on} ....................................................

//${AOs::Blinky::SM::on} .....................................................
Q_STATE_DEF(Blinky, on) {
QP::QState status_;
switch (e->sig) {
//.${AOs::Blinky::SM::on}
//${AOs::Blinky::SM::on}
case Q_ENTRY_SIG: {
BSP::ledOn();
status_ = Q_RET_HANDLED;
break;
}
//.${AOs::Blinky::SM::on::TIMEOUT}
//${AOs::Blinky::SM::on::TIMEOUT}
case TIMEOUT_SIG: {
status_ = tran(&off);
break;
Expand All @@ -137,13 +170,15 @@ Q_STATE_DEF(Blinky, on) {
}
return status_;
}
//.$enddef${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$enddef${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//...

//============================================================================
// generate definitions of all AO opaque pointers...
//.$define${AOs::AO_Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//.${AOs::AO_Blinky} .........................................................
//$define${AOs::AO_Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

//${AOs::AO_Blinky} ..........................................................
QP::QActive * const AO_Blinky = &Blinky::instance;
//.$enddef${AOs::AO_Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$enddef${AOs::AO_Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//...

Loading
Loading