2020-11-09 12:57:45 -05:00

152 lines
4.5 KiB
C++

//.$file${.::blinky.cpp} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//
// Model: blinky.qm
// File: ${.::blinky.cpp}
//
// This code has been generated by QM 5.1.0 <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.
//
// 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.
//
//.$endhead${.::blinky.cpp} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#include "qpcpp.hpp"
#include <iostream>
#include <stdlib.h> // for exit()
using namespace std;
using namespace QP;
enum { BSP_TICKS_PER_SEC = 100 };
void BSP_ledOff(void) {
cout << "LED OFF" << endl;
}
void BSP_ledOn(void) {
cout << "LED ON" << endl;
}
extern "C" void Q_onAssert(char const * const module, int loc) {
cout << "Assertion failed in " << module << ':' << loc << endl;
exit(-1);
}
void QF::onStartup(void) {}
void QF::onCleanup(void) {}
void QP::QF_onClockTick(void) {
QF::TICK_X(0U, nullptr); // perform the QF clock tick processing
}
enum BlinkySignals {
TIMEOUT_SIG = Q_USER_SIG,
MAX_SIG
};
//=============== ask QM to declare the Blinky class ==================
//.$declare${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//.${AOs::Blinky} ............................................................
class Blinky : public QP::QActive {
private:
QP::QTimeEvt m_timeEvt;
public:
Blinky();
protected:
Q_STATE_DECL(initial);
Q_STATE_DECL(off);
Q_STATE_DECL(on);
};
//.$enddecl${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
static Blinky l_blinky;
QActive * const AO_Blinky = &l_blinky;
int main() {
// statically allocate event queue buffer for the Blinky AO
static QEvt const *blinky_queueSto[10];
QF::init(); // initialize the framework
AO_Blinky->start(1U, // priority
blinky_queueSto, Q_DIM(blinky_queueSto),
nullptr, 0U); // no stack
return QF::run(); // run the QF application
}
//================ ask QM to define the Blinky class ==================
//.$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//. Check for the minimum required QP version
#if (QP_VERSION < 680U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
#error qpcpp version 6.8.0 or higher required
#endif
//.$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//.$define${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//.${AOs::Blinky} ............................................................
//.${AOs::Blinky::Blinky} ....................................................
Blinky::Blinky()
: QActive(Q_STATE_CAST(&Blinky::initial)),
m_timeEvt(this, TIMEOUT_SIG, 0U)
{}
//.${AOs::Blinky::SM} ........................................................
Q_STATE_DEF(Blinky, initial) {
//.${AOs::Blinky::SM::initial}
m_timeEvt.armX(BSP_TICKS_PER_SEC/2, BSP_TICKS_PER_SEC/2);
(void)e; // unused parameter
QS_FUN_DICTIONARY(&Blinky::off);
QS_FUN_DICTIONARY(&Blinky::on);
return tran(&off);
}
//.${AOs::Blinky::SM::off} ...................................................
Q_STATE_DEF(Blinky, off) {
QP::QState status_;
switch (e->sig) {
//.${AOs::Blinky::SM::off}
case Q_ENTRY_SIG: {
BSP_ledOff();
status_ = Q_RET_HANDLED;
break;
}
//.${AOs::Blinky::SM::off::TIMEOUT}
case TIMEOUT_SIG: {
status_ = tran(&on);
break;
}
default: {
status_ = super(&top);
break;
}
}
return status_;
}
//.${AOs::Blinky::SM::on} ....................................................
Q_STATE_DEF(Blinky, on) {
QP::QState status_;
switch (e->sig) {
//.${AOs::Blinky::SM::on}
case Q_ENTRY_SIG: {
BSP_ledOn();
status_ = Q_RET_HANDLED;
break;
}
//.${AOs::Blinky::SM::on::TIMEOUT}
case TIMEOUT_SIG: {
status_ = tran(&off);
break;
}
default: {
status_ = super(&top);
break;
}
}
return status_;
}
//.$enddef${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^