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 (one PLC PHY binary for each band), SRV_PCOUP_Set_Config has to be called every time the band is changed (PLC PHY binary reloaded).

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;
    
    SRV_PLC_PCOUP_BRANCH plcBranch;

    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.plcBranch = SRV_PCOUP_Get_Default_Branch();
}

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.plcBranch);

                /* 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;
        }
    }
}