/*.$file${.::blinky.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
/*
* Model: blinky.qm
* File: ${.::blinky.c}
*
* This code has been generated by QM 4.6.0 .
* 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.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
#include "qpn.h" /* QP-nano framework API */
#include "safe_std.h" /* portable "safe" / facilities */
#include /* for exit() */
enum { BSP_TICKS_PER_SEC = 100 };
void BSP_init(void) {
PRINTF_S("Simple Blinky example\n"
"QP-nano version: %s\n"
"Press Ctrl-C to quit...\n",
QP_VERSION_STR);
}
void BSP_ledOff(void) { PRINTF_S("%s\n", "LED OFF"); }
void BSP_ledOn(void) { PRINTF_S("%s\n", "LED ON"); }
/* callback functions needed by the framework ------------------------------*/
void QF_onStartup(void) {}
void QF_onCleanup(void) {}
void QF_onClockTickISR(void) {
QF_tickXISR(0U); /* QF-nano clock tick processing for rate 0 */
}
Q_NORETURN Q_onAssert(char_t const Q_ROM * const module, int_t loc) {
FPRINTF_S(stderr, "Assertion failed in %s:%d", module, loc);
exit(-1);
}
/* ask QM to declare the Blinky class --------------------------------------*/
/*.$declare${AOs::Blinky_ctor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
/*.${AOs::Blinky_ctor} .....................................................*/
static void Blinky_ctor(void);
/*.$enddecl${AOs::Blinky_ctor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
/*.$declare${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
/*.${AOs::Blinky} ..........................................................*/
typedef struct Blinky {
/* protected: */
QActive super;
} Blinky;
/* protected: */
static QState Blinky_initial(Blinky * const me);
static QState Blinky_off(Blinky * const me);
static QState Blinky_on(Blinky * const me);
/*.$enddecl${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
/* the single instance of the Blinky active object -------------------------*/
Blinky AO_Blinky;
/* Local-scope objects -----------------------------------------------------*/
static QEvt l_blinkyQSto[10]; /* Event queue storage for Blinky */
/* QF_active[] array defines all active object control blocks --------------*/
QActiveCB const Q_ROM QF_active[] = {
{ (QActive *)0, (QEvt *)0, 0U },
{ (QActive *)&AO_Blinky, l_blinkyQSto, Q_DIM(l_blinkyQSto) }
};
/* the main function -------------------------------------------------------*/
int main(void) {
QF_init(Q_DIM(QF_active)); /* initialize the QF-nano framework */
BSP_init(); /* initialize the Board Support Package */
Blinky_ctor(); /* in C you must explicitly call the Blinky constructor */
return QF_run(); /* transfer control to QF-nano */
}
/* ask QM to define the Blinky class ---------------------------------------*/
/*.$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
/*. Check for the minimum required QP version */
#if (QP_VERSION < 650U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
#error qpn version 6.5.0 or higher required
#endif
/*.$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
/*.$define${AOs::Blinky_ctor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
/*.${AOs::Blinky_ctor} .....................................................*/
static void Blinky_ctor(void) {
Blinky * const me = &AO_Blinky;
QActive_ctor(&me->super, Q_STATE_CAST(&Blinky_initial));
}
/*.$enddef${AOs::Blinky_ctor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
/*.$define${AOs::Blinky} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
/*.${AOs::Blinky} ..........................................................*/
/*.${AOs::Blinky::SM} ......................................................*/
static QState Blinky_initial(Blinky * const me) {
/*.${AOs::Blinky::SM::initial} */
/* arm the private time event for tick rate 0
* to expire in 1/2s and periodically every 1/2 second
*/
QActive_armX(&me->super,
0U,
BSP_TICKS_PER_SEC/2U,
BSP_TICKS_PER_SEC/2U);
return Q_TRAN(&Blinky_off);
}
/*.${AOs::Blinky::SM::off} .................................................*/
static QState Blinky_off(Blinky * const me) {
QState status_;
switch (Q_SIG(me)) {
/*.${AOs::Blinky::SM::off} */
case Q_ENTRY_SIG: {
BSP_ledOff();
status_ = Q_HANDLED();
break;
}
/*.${AOs::Blinky::SM::off::Q_TIMEOUT} */
case Q_TIMEOUT_SIG: {
status_ = Q_TRAN(&Blinky_on);
break;
}
default: {
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*.${AOs::Blinky::SM::on} ..................................................*/
static QState Blinky_on(Blinky * const me) {
QState status_;
switch (Q_SIG(me)) {
/*.${AOs::Blinky::SM::on} */
case Q_ENTRY_SIG: {
BSP_ledOn();
status_ = Q_HANDLED();
break;
}
/*.${AOs::Blinky::SM::on::Q_TIMEOUT} */
case Q_TIMEOUT_SIG: {
status_ = Q_TRAN(&Blinky_off);
break;
}
default: {
status_ = Q_SUPER(&QHsm_top);
break;
}
}
return status_;
}
/*.$enddef${AOs::Blinky} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/