Jump to main content

# 1.2.1.2.1 Using the Library (G3-PLC)

For G3-PLC, SRV_PCOUP_Set_Config has to be called once the PLC driver is ready (binary loaded to PLC device) and before any transmission is requested.

Each transmission branch (main or auxiliary) is associated to a G3-PLC PHY band. For multi-band applications, SRV_PCOUP_Set_Config has to be called every time the band is changed.

G3-PLC example application using PLC PHY Coupling service

    #include "definitions.h"

    typedef enum
    {
        APP_STATE_INIT,
        APP_STATE_OPEN,
        APP_STATE_READY,
        APP_STATE_ERROR

    } APP_STATE;

    typedef struct
    {
        APP_STATE state;

        uint8_t plcBand;

        DRV_HANDLE drvPlcHandle;

    } APP_DATA;

    APP_DATA appData;

    static void APP_PLC_DataCfmCb(DRV_PLC_PHY_TRANSMISSION_CFM_OBJ *cfmObj, uintptr_t context)
    {
        /* Do whatever with transmission confirm */
    }

    static void APP_PLC_DataIndCb(DRV_PLC_PHY_RECEPTION_OBJ *indObj, uintptr_t context)
    {
        /* Do whatever with received frame indication */
    }

    void APP_Initialize (void)
    {
        /* Initialize application state */
        appData.state = APP_STATE_INIT;

        /* Get the default transmission branch */
        appData.plcBand = SRV_PCOUP_Get_Default_Phy_Band();
    }

    void APP_Tasks (void)
    {
        /* Check the application's current state. */
        switch (appData.state)
        {
            case APP_STATE_INIT:
            {
                /* Open PLC driver */
                appData.drvPlcHandle = DRV_PLC_PHY_Open(DRV_PLC_PHY_INDEX, NULL);

                if (appData.drvPlcHandle != DRV_HANDLE_INVALID)
                {
                    /* Register PLC callbacks */
                    DRV_PLC_PHY_DataIndCallbackRegister(appData.drvPlcHandle,
                            APP_PLC_DataIndCb, DRV_PLC_PHY_INDEX);
                    DRV_PLC_PHY_DataCfmCallbackRegister(appData.drvPlcHandle,
                            APP_PLC_DataCfmCb, DRV_PLC_PHY_INDEX);

                    /* Enable PLC Transmission */
                    DRV_PLC_PHY_Enable_TX(appData.drvPlcHandle, true);

                    /* Go to next state to wait until PLC Driver is ready */
                    appData.state = APP_STATE_OPEN;
                }
                else
                {
                    appData.state = APP_PLC_STATE_ERROR;
                }
                break;
            }

            case APP_STATE_OPEN:
            {
                /* Check PLC Driver status */
                if (DRV_PLC_PHY_Status(DRV_PLC_PHY_INDEX) == SYS_STATUS_READY)
                {
                    /* Apply PLC PHY Coupling configuration */
                    SRV_PCOUP_Set_Config(appData.drvPlcHandle, appData.plcBand);

                    /* At this point the PLC Transceiver is ready for transmission */
                    appData.state = APP_STATE_READY;
                }
            }
            break;

            case APP_STATE_READY:
            {
                /* Do whatever, request transmission or wait to receive something  */
                break;
            }

            /* The default state should never be executed. */
            default:
            {
                /* Handle error in application's state machine. */
                break;
            }
        }
    }

Rev: G