//$file${.::sporadic2.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//
// Model: real-time.qm
// File:  ${.::sporadic2.c}
//
// 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.
//
// Copyright (c) 2005 Quantum Leaps, LLC. All rights reserved.
//
//                 ____________________________________
//                /                                   /
//               /    GGGGGGG    PPPPPPPP   LL       /
//              /   GG     GG   PP     PP  LL       /
//             /   GG          PP     PP  LL       /
//            /   GG   GGGGG  PPPPPPPP   LL       /
//           /   GG      GG  PP         LL       /
//          /     GGGGGGG   PP         LLLLLLL  /
//         /___________________________________/
//
// 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>
// <info@state-machine.com>
//
//$endhead${.::sporadic2.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#include "qpc.h"               // QP/C real-time event framework
#include "bsp.h"               // Board Support Package
#include "app.h"               // Application interface

//$declare${AOs::Sporadic2} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

//${AOs::Sporadic2} ..........................................................
typedef struct Sporadic2 {
// protected:
    QMActive super;

// public:
} Sporadic2;

extern Sporadic2 Sporadic2_inst;

// protected:
static QState Sporadic2_initial(Sporadic2 * const me, void const * const par);
static QState Sporadic2_active  (Sporadic2 * const me, QEvt const * const e);
static QMState const Sporadic2_active_s = {
    QM_STATE_NULL, // superstate (top)
    Q_STATE_CAST(&Sporadic2_active),
    Q_ACTION_NULL, // no entry action
    Q_ACTION_NULL, // no exit action
    Q_ACTION_NULL  // no initial tran.
};
//$enddecl${AOs::Sporadic2} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

//Q_DEFINE_THIS_MODULE("sporadic2")

//$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// Check for the minimum required QP version
#if (QP_VERSION < 730U) || (QP_VERSION != ((QP_RELEASE^4294967295U)%0x2710U))
#error qpc version 7.3.0 or higher required
#endif
//$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$define${Shared::Sporadic2_ctor} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

//${Shared::Sporadic2_ctor} ..................................................
void Sporadic2_ctor(void) {
    Sporadic2 * const me = &Sporadic2_inst;
    QMActive_ctor(&me->super, Q_STATE_CAST(&Sporadic2_initial));
}
//$enddef${Shared::Sporadic2_ctor} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$define${Shared::AO_Sporadic2} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

//${Shared::AO_Sporadic2} ....................................................
QActive * const AO_Sporadic2 = (QActive *)&Sporadic2_inst;
//$enddef${Shared::AO_Sporadic2} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//$define${AOs::Sporadic2} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

//${AOs::Sporadic2} ..........................................................
Sporadic2 Sporadic2_inst;

//${AOs::Sporadic2::SM} ......................................................
static QState Sporadic2_initial(Sporadic2 * const me, void const * const par) {
    //${AOs::Sporadic2::SM::initial}
    Q_UNUSED_PAR(par);

    QS_FUN_DICTIONARY(&Sporadic2_active);

    static QMTranActTable const tatbl_ = { // tran-action table
        &Sporadic2_active_s, // target state
        {
            Q_ACTION_NULL // zero terminator
        }
    };
    return QM_TRAN_INIT(&tatbl_);
}

//${AOs::Sporadic2::SM::active} ..............................................
//${AOs::Sporadic2::SM::active}
static QState Sporadic2_active(Sporadic2 * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        //${AOs::Sporadic2::SM::active::SPORADIC_A}
        case SPORADIC_A_SIG: {
            Q_UNUSED_PAR(me);

            BSP_d5on();
            QACTIVE_POST(AO_Sporadic3, e, me); // Sporadic2 --> Sporadic3
            BSP_d5off();
            status_ = QM_HANDLED();
            break;
        }
        //${AOs::Sporadic2::SM::active::SPORADIC_B}
        case SPORADIC_B_SIG: {
            BSP_d5on();
            QACTIVE_POST(AO_Periodic1, BSP_getEvtPeriodic1(1U), me);
            BSP_d5off();

            for (uint16_t i = Q_EVT_CAST(SporadicSpecEvt)->toggles;
                 i > 0U; --i)
            {
                BSP_d5on();
                BSP_d5off();
            }
            status_ = QM_HANDLED();
            break;
        }
        default: {
            status_ = QM_SUPER();
            break;
        }
    }
    return status_;
}
//$enddef${AOs::Sporadic2} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
