4.5 Code Example
The code example below shows the initialization flow as described in previous sections.
/**
* \brief Handler to manage confirmation of the last PLC transmission.
*
* \param px_msg_cfm Pointer to struct containing Tx Confirm paramters
*/
static void _handler_data_cfm(tx_cfm_t *px_msg_cfm)
{
}
/**
* \brief Handler to manage new received PLC message.
*
* \param px_msg Pointer to struct containing Rx Indication parameters and data
*/
static void _handler_data_ind(rx_msg_t *px_msg)
{
}
/**
* \brief Handler to manage PL360 Exceptions.
* This callback is also called after loading binary at initization.
*/
static void _handler_exception_event(atpl360_exception_t exception)
{
/* Initialize/restore PL360 custom configuration */
}
/**
* \brief Handler for Sleep Mode resume event.
*/
static void _handler_sleep_mode_resume_event(void)
{
/* Restore PL360 custom configuration */
}
/**
* \brief Handler to manage serial add-on event.
*/
static void _handler_serial_atpl360_event(uint8_t *px_serial_data, uint16_t us_len)
{
}
/**
* \brief Main code entry point.
*/
int main( void )
{
atpl360_dev_callbacks_t x_atpl360_cbs;
atpl360_hal_wrapper_t x_atpl360_hal_wrp;
uint8_t uc_ret;
/* ASF function to setup clocking. */
sysclk_init();
/* ASF library function to setup for the evaluation kit being used. */
board_init();
/* Init ATPL360 */
x_atpl360_hal_wrp.plc_init = hal_plc_init;
x_atpl360_hal_wrp.plc_reset = hal_plc_reset;
x_atpl360_hal_wrp.plc_set_stby_mode = hal_plc_set_stby_mode;
x_atpl360_hal_wrp.plc_set_handler = hal_plc_set_handler;
x_atpl360_hal_wrp.plc_send_boot_cmd = hal_plc_send_boot_cmd;
x_atpl360_hal_wrp.plc_write_read_cmd = hal_plc_send_wrrd_cmd;
x_atpl360_hal_wrp.plc_enable_int = hal_plc_enable_interrupt;
x_atpl360_hal_wrp.plc_delay = hal_plc_delay;
x_atpl360_hal_wrp.plc_get_thw = hal_plc_get_thw;
atpl360_init(&sx_atpl360_desc, &x_atpl360_hal_wrp);
/* Callback configuration. Set NULL as Not used */
x_atpl360_cbs.data_confirm = _handler_data_cfm;
x_atpl360_cbs.data_indication = _handler_data_ind;
x_atpl360_cbs.exception_event = _handler_exception_event;
x_atpl360_cbs.addons_event = _handler_serial_atpl360_event;
x_atpl360_cbs.sleep_mode_cb = _handler_sleep_mode_resume_event;
x_atpl360_cbs.debug_mode_cb = NULL;
sx_atpl360_desc.set_callbacks(&x_atpl360_cbs);
/* Enable ATPL360 */
uc_ret = atpl360_enable(ATPL360_BINARY_ADDRESS, ATPL360_BINARY_LEN);
if (uc_ret == ATPL360_ERROR) {
printf("\r\nmain: atpl360_enable call error!(%d)\r\n", uc_ret);
while (1) {
}
}
while (1) {
/* Check ATPL360 pending events */
atpl360_handle_events();
}
}