1.2.1.2.2 Using The Library (PRIME)
For PRIME, SRV_PCOUP_Set_Channel_Config has to be called once the PLC Driver is ready (binary loaded to PLC Device) and before any transmission is requested.
Additionally, SRV_PCOUP_Set_Channel_Config has to be called every time the PRIME channel is changed (PLC_ID_CHANNEL_CFG PIB).
PRIME 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; DRV_PLC_PHY_CHANNEL plcChannel; 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 */ } static void APP_PLC_SetChannel() { DRV_PLC_PHY_PIB_OBJ pibObj; /* Set channel configuration */ pibObj.id = PLC_ID_CHANNEL_CFG; pibObj.length = 1; pibObj.pData = &appData.plcChannel; DRV_PLC_PHY_PIBSet(appData.drvPlcHandle, &pibObj); /* Apply PLC PHY Coupling configuration for the selected channel */ SRV_PCOUP_Set_Channel_Config(appPlc.drvPlcHandle, appData.plcChannel); } void APP_Initialize (void) { /* Initialize application state */ appData.state = APP_STATE_INIT; /* Get the default PRIME channel */ appData.plcChannel = SRV_PCOUP_Get_Default_Channel(); } 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) { /* Set channel and PLC PHY Coupling configuration */ APP_PLC_SetChannel(); /* 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; } } }