/*! \brief CAN Prepare Data to Receive * - Allocate one MOB in reception * - Start the reception */ void can_example_prepare_data_to_receive(void) { // Initialize channel 0 can_init(0, ((U32)&mob_ram_ch0[0]), CANIF_CHANNEL_MODE_NORMAL, can_out_callback_channel0); // Allocate one mob for RX pCANMOB_message2[0].handle = can_mob_alloc(0); can_rx(0, pCANMOB_message2[0].handle, pCANMOB_message2[0].req_type, pCANMOB_message2[0].can_msg); }
/*! \brief CAN Prepare Data to Send * - Allocate one MOB in transmission * - Fill the MOB with the correct DATA * - Start the transmission */ void can_example_prepare_data_to_send(void) { // Initialize channel 1 can_init(1, ((U32)&mob_ram_ch1[0]), CANIF_CHANNEL_MODE_NORMAL, can_out_callback_channel1); // Allocate one mob for TX pCANMOB_message0[0].handle = can_mob_alloc(1); // Check return if no mob are available if (pCANMOB_message0[0].handle==CAN_CMD_REFUSED) { while(true); } pCANMOB_message0[0].can_msg->data.u8[0] = ((adc_current_conversion&0xFF00)>>8); pCANMOB_message0[0].can_msg->data.u8[1] = (adc_current_conversion&0xFF); can_tx(1, pCANMOB_message0[0].handle, pCANMOB_message0[0].dlc, pCANMOB_message0[0].req_type, pCANMOB_message0[0].can_msg); }
/** Main function to configure the CAN, and begin transfers. */ int main(void) { /* Initialize the system clocks */ sysclk_init(); /* Setup the generic clock for CAN */ scif_gc_setup(AVR32_SCIF_GCLK_CANIF, SCIF_GCCTRL_OSC0, AVR32_SCIF_GC_NO_DIV_CLOCK, 0); /* Now enable the generic clock */ scif_gc_enable(AVR32_SCIF_GCLK_CANIF); init_dbg_rs232(FPBA_HZ); /* Disable all interrupts. */ Disable_global_interrupt(); /* Initialize interrupt vectors. */ INTC_init_interrupts(); static const gpio_map_t CAN_GPIO_MAP = { {AVR32_CANIF_RXLINE_0_0_PIN, AVR32_CANIF_RXLINE_0_0_FUNCTION}, {AVR32_CANIF_TXLINE_0_0_PIN, AVR32_CANIF_TXLINE_0_0_FUNCTION} }; /* Assign GPIO to CAN. */ gpio_enable_module(CAN_GPIO_MAP, sizeof(CAN_GPIO_MAP) / sizeof(CAN_GPIO_MAP[0])); /* Initialize channel 0 */ can_init(CAN_CHANNEL_EXAMPLE, ((uint32_t)&mob_ram_ch0[0]), CANIF_CHANNEL_MODE_LISTENING, can_out_callback_channel0); /* Enable all interrupts. */ Enable_global_interrupt(); print_dbg("\r\nUC3C CAN Examples 1\r\n"); print_dbg(CAN_Wakeup); /* Initialize CAN Channel 0 */ can_init(CAN_CHANNEL_EXAMPLE, ((uint32_t)&mob_ram_ch0[0]), CANIF_CHANNEL_MODE_NORMAL, can_out_callback_channel0); /* Allocate one mob for RX */ appli_rx_msg.handle = can_mob_alloc(CAN_CHANNEL_EXAMPLE); /* Initialize RX message */ can_rx(CAN_CHANNEL_EXAMPLE, appli_rx_msg.handle, appli_rx_msg.req_type, appli_rx_msg.can_msg); /* Enable Async Wake Up Mode */ pm_asyn_wake_up_enable(CAN_WAKEUP_MASK_EXAMPLE); /* ---------SLEEP MODE PROCEDURE------------- */ /* Disable CAN Channel 0 */ CANIF_disable(CAN_CHANNEL_EXAMPLE); /* Wait CAN Channel 0 is disabled */ while(!CANIF_channel_enable_status(CAN_CHANNEL_EXAMPLE)); /* Enable Wake-Up Mode */ CANIF_enable_wakeup(CAN_CHANNEL_EXAMPLE); /* Go to sleep mode. */ SLEEP(AVR32_PM_SMODE_STATIC); /* ---------SLEEP MODE PROCEDURE------------- */ print_dbg(CAN_WakeupD); /* Initialize again CAN Channel 0 */ can_init(CAN_CHANNEL_EXAMPLE, ((uint32_t)&mob_ram_ch0[0]), CANIF_CHANNEL_MODE_NORMAL, can_out_callback_channel0); /* Allocate one mob for RX */ appli_rx_msg.handle = can_mob_alloc(CAN_CHANNEL_EXAMPLE); /* Initialize RX message */ can_rx(CAN_CHANNEL_EXAMPLE, appli_rx_msg.handle, appli_rx_msg.req_type, appli_rx_msg.can_msg); for (;;) { /* Do nothing; interrupts handle the DAC conversions */ } }