1.1.2 Initialization
In the code of the example project phy_plc_and_go, the initialization of
the PLC is performed during the first states of the state machine running in the PLC
task APP_PLC_Tasks().
PLC Hardware Initialization
APP_PLC_STATE_IDLEinitializes the variables related to the coupling stageAPP_PLC_STATE_INITopens the PLC driver to load the PLC_PHY binary
The PLC & Go application loads by default the configuration to use the default coupling stage of the evaluation kit. If other coupling configuration is required, it can be easily modified in PLC_PHY module of the project graph in MPLAB Code Configurator:
Callback Setting
The state APP_PLC_STATE_OPEN configures the PLC_PHY callbacks to manage
the different events coming from the PLC_PHY module, applies the initial configuration
and enables the PVDD monitor, required to transmit with the PLC_PHY module.
The callbacks to manage different events are:
- Data_indication event is managed by
APP_PLC_DataIndCb()function to process all the PLC messages received - Data_confirm event is managed by
APP_PLC_DataCfmCb()function to process the results of sending a PLC message - Exception events are managed by
APP_PLC_ExceptionCb()function - PLC disable sleep mode event is
managed by
APP_PLC_SleepModeDisableCb()function to restart the configuration - PVDD monitor events are managed by
APP_PLC_PVDDMonitorCb()function
case APP_PLC_STATE_OPEN:
{
/* Check PLC transceiver */
if (DRV_PLC_PHY_Status(DRV_PLC_PHY_INDEX_0) == SYS_STATUS_READY)
{
/* Configure PLC callbacks */
DRV_PLC_PHY_ExceptionCallbackRegister(appPlc.drvPl360Handle, APP_PLC_ExceptionCb, DRV_PLC_PHY_INDEX_0);
DRV_PLC_PHY_DataCfmCallbackRegister(appPlc.drvPl360Handle, APP_PLC_DataCfmCb, DRV_PLC_PHY_INDEX_0);
DRV_PLC_PHY_DataIndCallbackRegister(appPlc.drvPl360Handle, APP_PLC_DataIndCb, DRV_PLC_PHY_INDEX_0);
DRV_PLC_PHY_SleepDisableCallbackRegister(appPlc.drvPl360Handle, APP_PLC_SleepModeDisableCb, DRV_PLC_PHY_INDEX_0);
/* Apply PLC initial configuration */
APP_PLC_SetInitialConfiguration();
/* Enable PLC PVDD Monitor Service: ADC channel 0 */
SRV_PVDDMON_RegisterCallback(APP_PLC_PVDDMonitorCb, 0);
PLC_PHY Module Enabling
When the callbacks are set, the PLC_PHY module binary is already loaded from Flash memory and its integrity is checked. However, transmission is not allowed until the PVDD Monitor Service starts:
/* Enable PLC PVDD Monitor Service: ADC channel 0 */
SRV_PVDDMON_RegisterCallback(APP_PLC_PVDDMonitorCb, 0);
SRV_PVDDMON_Start(SRV_PVDDMON_CMP_MODE_OUT);
