1.5.1.1 Initialization

In the code of the MAC-RT PLC & Go example application, the G3 MAC RT driver initialization is performed during the first states of the state machine implemented in the function APP_PLC_Tasks:
  • APP_PLC_STATE_IDLE initializes the variables related to the transmission coupling stage.
  • APP_PLC_STATE_INIT opens the G3 MAC RT driver to load the G3-PLC MAC-RT binary. If this state is reached because of a frequency band change (APP_PLC_STATE_SET_BAND), the G3 MAC RT driver needs to be initialized first. Just before opening the driver, the G3 MAC RT driver initialization callback is set. This callback will be called when G3 MAC RT is ready (G3-PLC MAC-RT binary loaded completely and validated) and it is used to configure the initial PLC PHY and MAC-RT parameters (PIBs), including:
    • Transmission coupling parameters. This is always required. It can be done using the function SRV_PCOUP_Set_Config.
    • The MAC header used for transmission is initialized. PAN ID (MAC_RT_PIB_PAN_ID) and short address (MAC_RT_PIB_SHORT_ADDRESS) are set in the G3-PLC MAC-RT. PAN ID is configured by CONF_PAN_ID and short address is chosen randomly. The destination address is broadcast by default (MAC_RT_SHORT_ADDRESS_BROADCAST). The source/destination address and the PAN ID can be configured later through the console menu.
    • Static notching (MAC_RT_PIB_TONE_MASK) only if APP_PLC_STATIC_NOTCHING_ENABLE is not 0. Each carrier corresponding to the frequency band can be notched (no energy is sent in those carriers). Each carrier is represented by one bit (1: carrier used; 0: carrier notched). By default it is all 1's in the PLC device (static notching disabled). The same Tone Mask must be set in both transmitter and receiver, otherwise they don't understand each other.
    • The PLC PHY version is read.
  • APP_PLC_STATE_OPEN waits for the G3 MAC RT driver to be ready (G3-PLC MAC-RT binary loaded completely and validated). Once the G3 MAC RT driver is ready:
    • The G3 MAC RT driver and PVDD monitor service callbacks are set in order to receive different events:
      • Reception parameters event is managed by the APP_PLC_RxParamsIndCallback function to indicate the parameters of the PLC messages received.
      • Data indication event is managed by the APP_PLC_DataIndCallback function to process all the PLC messages received. The parameters of the received message will be reported first in APP_PLC_RxParamsIndCallback.
      • Data confirm event is managed by the APP_PLC_DataCfmCallback function to process the results of PLC transmissions.
      • Exception events are managed by the APP_PLC_ExceptionCallback function.
      • PLC sleep mode disable event is managed by the APP_PLC_SleepModeDisableCallback function to restart the configuration once sleep mode is disabled.
      • PVDD monitor events are managed by the APP_PLC_PVDDMonitorCallback function to enable/disable the PLC transmission.
    • The PVDD monitor service is started, needed to enable/disable the transmission of the PL460 device using the TXEN pin. The PVDD voltage is monitored and PLC transmission is disabled in case the voltage is not in the expected range, to avoid PL460 damage. If the PVDD voltage is in the expected range, PLC transmission is enabled.
            case APP_PLC_STATE_OPEN:
            {
                /* Check PLC transceiver */
                if (DRV_G3_MACRT_Status(DRV_G3_MACRT_INDEX_0) == DRV_G3_MACRT_STATE_READY)
                {
                    /* Configure PLC callbacks */
                    DRV_G3_MACRT_ExceptionCallbackRegister(appPlc.drvPlcHandle, APP_PLC_ExceptionCallback);
                    DRV_G3_MACRT_TxCfmCallbackRegister(appPlc.drvPlcHandle, APP_PLC_DataCfmCallback);
                    DRV_G3_MACRT_DataIndCallbackRegister(appPlc.drvPlcHandle, APP_PLC_DataIndCallback);
                    DRV_G3_MACRT_RxParamsIndCallbackRegister(appPlc.drvPlcHandle, APP_PLC_RxParamsIndCallback);
                    DRV_G3_MACRT_SleepIndCallbackRegister(appPlc.drvPlcHandle, APP_PLC_SleepModeDisableCallback);
                    
                    /* Enable PLC Transmission */
                    DRV_G3_MACRT_EnableTX(appPlc.drvPlcHandle, true);
                    
                    /* Enable PLC PVDD Monitor Service */
                    SRV_PVDDMON_CallbackRegister(APP_PLC_PVDDMonitorCallback, 0);
                    SRV_PVDDMON_Start(SRV_PVDDMON_CMP_MODE_OUT);
                
                    /* Init Timer to handle blinking led */
                    appPlc.tmr1Handle = SYS_TIME_CallbackRegisterMS(APP_PLC_Timer1_Callback, 0, LED_BLINK_RATE_MS, SYS_TIME_PERIODIC);
                    
                    /* Set PLC state */
                    appPlc.state = APP_PLC_STATE_WAITING;
                }
            }
            break;