10.1.1 Initialization Function

The PL360 Host Controller must always be initialized when the system starts the execution. The following function initializes the hardware parameters and configures the controller descriptor:

void atpl360_init(atpl360_descriptor_t *const descr, atpl360_hal_wrapper_t *px_hal_wrapper);

Parameters:

descrPointer to component descriptor
px_hal_wrapperPointer to HAL wrapper structure
This function performs the following actions:
  • Sets the handlers for the PLC interruption
  • Initializes the PLC SPI service
  • And, if necessary, initializes add-on interfaces

The component descriptor offers the customer a set of functions to get access to the PL360 device. It is defined as a structure of function pointers as follows:

typedef struct atpl360_descriptor {
	pf_set_callbacks_t set_callbacks;
	pf_send_data_t send_data;
	pf_mng_get_cfg_t get_config;
	pf_mng_set_cfg_t set_config;
	pf_addons_event_t send_addons_cmd;
} atpl360_descriptor_t;

where:

  • set_callbacks function is used to set upper layers’ functions to be executed when a PL360 Host Controller event is reported. For further information, refer to the Setting Callbacks chapter.
  • send_data function provides a mechanism to send a PLC message through the PL360 device. For further G3 information, refer to the G3 PHY-DATA.request chapter. For further PRIME information, refer to the PRIME PHY-DATA.request chapter.
  • get_config function provides a read access method to get PL360 internal data. For further information, refer to the Get Configuration chapter.
  • set_config function provides a write access method to set PL360 internal data. For further information, refer to the Set Configuration chapter.
  • send_addons_cmd function provides a mechanism to connect PLC Microchip tools to the PL360 device. All information received from these tools must be redirected to this function in order to pass the information to the PL360 Host Controller.

Function pointers are defined as follows:

typedef void (*pf_set_callbacks_t)(atpl360_dev_callbacks_t *dev_cb);
typedef uint8_t (*pf_send_data_t)(tx_msg_t *px_msg);
typedef bool (*pf_mng_get_cfg_t)(uint16_t us_param_id, void *px_value, uint8_t uc_len, bool b_sync);
typedef bool (*pf_mng_set_cfg_t)(uint16_t us_param_id, void *px_value, uint16_t us_len);
typedef void (*pf_addons_event_t)(uint8_t *px_msg, uint16_t us_len);

The PL360 Host Controller also needs to have access to hardware peripherals. A HAL wrapper structure is used to separate this hardware and software dependency.

typedef struct atpl360_hal_wrapper {
	pf_plc_init_t plc_init;
	pf_plc_reset_t plc_reset;
	pf_plc_set_stby_mode_t plc_set_stby_mode;      
	pf_plc_set_handler_t plc_set_handler;
	pf_plc_bootloader_cmd_t plc_send_boot_cmd;
	pf_plc_write_read_cmd_t plc_write_read_cmd;
	pf_plc_enable_int_t plc_enable_int;
	pf_plc_delay_t plc_delay;
	pf_plc_get_thw_t plc_get_thw;
} atpl360_hal_wrapper_t;
Microchip provides a set of example functions to get hardware access. It depends on the communication stack in use.
  • G3: Refer to pplc_if.c and pplc_if.h files, located in the path: asf/sam/services/plc/pplc_if/atpl360
  • PRIME: Refer to hal_plc.c and hal_plc.h files, located in the path: asf/thirdparty/prime_ng/hal