shithub: heymac-node

ref: ad1df2d2a01bd064e643287ff305673dfede3ce3
dir: /src/sx127x.c/

View raw version
/*$file${src::sx127x.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
/*
* Model: SX127xHsm.qm
* File:  ${src::sx127x.c}
*
* This code has been generated by QM 5.2.5 <www.state-machine.com/qm>.
* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This generated code is open source software: you can redistribute it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation.
*
* This code 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.
*
* NOTE:
* Alternatively, this generated code may be distributed under the terms
* of Quantum Leaps commercial licenses, which expressly supersede the GNU
* General Public License and are specifically designed for licensees
* interested in retaining the proprietary status of their code.
*
* Contact information:
* <www.state-machine.com/licensing>
* <[email protected]>
*/
/*$endhead${src::sx127x.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
#include "qpc.h"
#include "bsp.h"

Q_DEFINE_THIS_FILE

enum SX127x_Signals {
    _PHY_TMOUT_SIG = Q_USER_SIG,
    _PHY_RQST_SIG,
    _DIO_TX_DONE_SIG,
    _DIO_MODE_RDY_SIG,
    _DIO_VALID_HDR_SIG,
    _PHY_PRDC_SIG,
    _DIO_RX_TMOUT_SIG,
    _DIO_RX_DONE_SIG
}

/* Active object class -----------------------------------------------------*/

/*$declare${net.frst.heymac::ActionEvt} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/

/*${net.frst.heymac::ActionEvt} ............................................*/
typedef struct {
/* protected: */
    QEvt super;
} ActionEvt;
/*$enddecl${net.frst.heymac::ActionEvt} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

/*$declare${net.frst.heymac::SX127x} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/

/*${net.frst.heymac::SX127x} ...............................................*/
// HSM for SX127x LoRa Phy layer
typedef struct {
/* protected: */
    QHsm super;

/* private: */
    QTimeEvt timeEvt;

/* public: */
    QEQueue actionQueue;
} SX127x;

/* protected: */
static QState SX127x_initial(SX127x * const me, void const * const par);
static QState SX127x__initializing(SX127x * const me, QEvt const * const e);
static QState SX127x__scheduling(SX127x * const me, QEvt const * const e);
static QState SX127x__txing(SX127x * const me, QEvt const * const e);
static QState SX127x__lingering(SX127x * const me, QEvt const * const e);
static QState SX127x__sleeping(SX127x * const me, QEvt const * const e);
static QState SX127x__listening(SX127x * const me, QEvt const * const e);
static QState SX127x__rxing(SX127x * const me, QEvt const * const e);
/*$enddecl${net.frst.heymac::SX127x} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

#define LINGER_TIME  \
    (QTimeEvtCtr)((BSP_random() % BSP_TICKS_PER_SEC) + BSP_TICKS_PER_SEC)

/*$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
/* Check for the minimum required QP version */
#if (QP_VERSION < 700U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
#error qpc version 7.0.0 or higher required
#endif
/*$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

/*$define${net.frst.heymac::SX127x} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/

/*${net.frst.heymac::SX127x} ...............................................*/

/*${net.frst.heymac::SX127x::SM} ...........................................*/
static QState SX127x_initial(SX127x * const me, void const * const par) {
    /*${net.frst.heymac::SX127x::SM::initial} */
    QTimeEvt_armX(&me->timeEvt, BSP_TICKS_PER_SEC/2, BSP_TICKS_PER_SEC/2);
    return Q_TRAN(&SX127x__initializing);
}

/*${net.frst.heymac::SX127x::SM::_initializing} ............................*/
static QState SX127x__initializing(SX127x * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /*${net.frst.heymac::SX127x::SM::_initializing::_PHY_TMOUT} */
        case _PHY_TMOUT_SIG: {
            /*${net.frst.heymac::SX127x::SM::_initializing::_PHY_TMOUT::[sx127x.open()]} */
            if (true) {
                status_ = Q_TRAN(&SX127x__scheduling);
            }
            else {
                status_ = Q_UNHANDLED();
            }
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsm_top);
            break;
        }
    }
    return status_;
}

/*${net.frst.heymac::SX127x::SM::_scheduling} ..............................*/
static QState SX127x__scheduling(SX127x * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /*${net.frst.heymac::SX127x::SM::_scheduling::_PHY_TMOUT} */
        case _PHY_TMOUT_SIG: {
            /*${net.frst.heymac::SX127x::SM::_scheduling::_PHY_TMOUT::[true]} */
            if (true) {
                status_ = Q_TRAN(&SX127x__txing);
            }
            /*${net.frst.heymac::SX127x::SM::_scheduling::_PHY_TMOUT::[true]} */
            else if (true) {
                status_ = Q_TRAN(&SX127x__sleeping);
            }
            /*${net.frst.heymac::SX127x::SM::_scheduling::_PHY_TMOUT::[true]} */
            else if (true) {
                status_ = Q_TRAN(&SX127x__listening);
            }
            else {
                status_ = Q_UNHANDLED();
            }
            break;
        }
        /*${net.frst.heymac::SX127x::SM::_scheduling::_PHY_RQST} */
        case _PHY_RQST_SIG: {
            status_ = Q_HANDLED();
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsm_top);
            break;
        }
    }
    return status_;
}

/*${net.frst.heymac::SX127x::SM::_txing} ...................................*/
static QState SX127x__txing(SX127x * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /*${net.frst.heymac::SX127x::SM::_txing::_DIO_TX_DONE} */
        case _DIO_TX_DONE_SIG: {
            status_ = Q_TRAN(&SX127x__scheduling);
            break;
        }
        /*${net.frst.heymac::SX127x::SM::_txing::_PHY_TMOUT} */
        case _PHY_TMOUT_SIG: {
            status_ = Q_HANDLED();
            break;
        }
        /*${net.frst.heymac::SX127x::SM::_txing::_PHY_RQST} */
        case _PHY_RQST_SIG: {
            status_ = Q_HANDLED();
            break;
        }
        /*${net.frst.heymac::SX127x::SM::_txing::_DIO_MODE_RDY} */
        case _DIO_MODE_RDY_SIG: {
            status_ = Q_TRAN(&SX127x__scheduling);
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsm_top);
            break;
        }
    }
    return status_;
}

/*${net.frst.heymac::SX127x::SM::_lingering} ...............................*/
static QState SX127x__lingering(SX127x * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /*${net.frst.heymac::SX127x::SM::_lingering::_PHY_RQST} */
        case _PHY_RQST_SIG: {
            /*${net.frst.heymac::SX127x::SM::_lingering::_PHY_RQST::[_default_action]} */
            if (true) {
                status_ = Q_TRAN(&SX127x__scheduling);
            }
            /*${net.frst.heymac::SX127x::SM::_lingering::_PHY_RQST::[else]} */
            else {
                // not empty 2
                status_ = Q_HANDLED();
            }
            break;
        }
        /*${net.frst.heymac::SX127x::SM::_lingering::_PHY_TMOUT} */
        case _PHY_TMOUT_SIG: {
            status_ = Q_TRAN(&SX127x__scheduling);
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsm_top);
            break;
        }
    }
    return status_;
}

/*${net.frst.heymac::SX127x::SM::_lingering::_sleeping} ....................*/
static QState SX127x__sleeping(SX127x * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        default: {
            status_ = Q_SUPER(&SX127x__lingering);
            break;
        }
    }
    return status_;
}

/*${net.frst.heymac::SX127x::SM::_lingering::_listening} ...................*/
static QState SX127x__listening(SX127x * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /*${net.frst.heymac::SX127x::SM::_lingering::_listening::_DIO_VALID_HDR} */
        case _DIO_VALID_HDR_SIG: {
            status_ = Q_TRAN(&SX127x__rxing);
            break;
        }
        /*${net.frst.heymac::SX127x::SM::_lingering::_listening::_PHY_PRDC} */
        case _PHY_PRDC_SIG: {
            status_ = Q_HANDLED();
            break;
        }
        /*${net.frst.heymac::SX127x::SM::_lingering::_listening::_DIO_RX_TMOUT} */
        case _DIO_RX_TMOUT_SIG: {
            status_ = Q_TRAN(&SX127x__scheduling);
            break;
        }
        /*${net.frst.heymac::SX127x::SM::_lingering::_listening::_DIO_RX_DONE} */
        case _DIO_RX_DONE_SIG: {
            status_ = Q_TRAN(&SX127x__scheduling);
            break;
        }
        default: {
            status_ = Q_SUPER(&SX127x__lingering);
            break;
        }
    }
    return status_;
}

/*${net.frst.heymac::SX127x::SM::_lingering::_listening::_rxing} ...........*/
static QState SX127x__rxing(SX127x * const me, QEvt const * const e) {
    QState status_;
    switch (e->sig) {
        /*${net.frst.heymac::SX127x::SM::_lingering::_listening::_rxing::_PHY_RQST} */
        case _PHY_RQST_SIG: {
            status_ = Q_HANDLED();
            break;
        }
        default: {
            status_ = Q_SUPER(&SX127x__listening);
            break;
        }
    }
    return status_;
}
/*$enddef${net.frst.heymac::SX127x} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

/*$define${net.frst.heymac::ActionEvt} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
/*$enddef${net.frst.heymac::ActionEvt} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/