static void can_configuration(void) { can_base_type can_base_struct; can_baudrate_type can_baudrate_struct; can_filter_init_type can_filter_init_struct; crm_periph_clock_enable(CRM_CAN1_PERIPH_CLOCK, TRUE); crm_periph_clock_enable(CRM_CAN2_PERIPH_CLOCK, TRUE); /* can1 base init */ can_default_para_init(&can_base_struct); can_base_struct.mode_selection = CAN_MODE_COMMUNICATE; can_base_struct.ttc_enable = FALSE; can_base_struct.aebo_enable = TRUE; can_base_struct.aed_enable = TRUE; can_base_struct.prsf_enable = FALSE; can_base_struct.mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED; can_base_struct.mmssr_selection = CAN_SENDING_BY_ID; can_base_init(CAN1, &can_base_struct); /* can2 base init */ can_base_init(CAN2, &can_base_struct); /* can baudrate, set baudrate = pclk/(baudrate_div *(3 + bts1_size + bts2_size)) */ can_baudrate_struct.baudrate_div = 10; can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; can_baudrate_struct.bts2_size = CAN_BTS2_3TQ; /* can1 baudrate = (240/2)MHz/(10 *(3 + 7 + 2)) = 1MHz */ can_baudrate_set(CAN1, &can_baudrate_struct); /* can2 baudrate = (240/2)MHz/(10 *(3 + 7 + 2)) = 1MHz */ can_baudrate_set(CAN2, &can_baudrate_struct); /* can1 filter init */ can_filter_init_struct.filter_activate_enable = TRUE; can_filter_init_struct.filter_mode = CAN_FILTER_MODE_ID_MASK; can_filter_init_struct.filter_fifo = CAN_FILTER_FIFO0; can_filter_init_struct.filter_number = 0; can_filter_init_struct.filter_bit = CAN_FILTER_32BIT; can_filter_init_struct.filter_id_high = 0; can_filter_init_struct.filter_id_low = 0; can_filter_init_struct.filter_mask_high = 0; can_filter_init_struct.filter_mask_low = 0; can_filter_init(CAN1, &can_filter_init_struct); /* can1 filter init */ can_filter_init(CAN2, &can_filter_init_struct); /* can interrupt config */ nvic_irq_enable(USBFS_L_CAN1_RX0_IRQn, 0x00, 0x00); nvic_irq_enable(CAN1_SE_IRQn, 0x00, 0x00); nvic_irq_enable(CAN2_RX0_IRQn, 0x00, 0x01); nvic_irq_enable(CAN2_SE_IRQn, 0x00, 0x01); can_interrupt_enable(CAN1, CAN_RF0MIEN_INT, TRUE); can_interrupt_enable(CAN1, CAN_ETRIEN_INT, TRUE); can_interrupt_enable(CAN1, CAN_EOIEN_INT, TRUE); can_interrupt_enable(CAN2, CAN_RF1MIEN_INT, TRUE); can_interrupt_enable(CAN2, CAN_ETRIEN_INT, TRUE); can_interrupt_enable(CAN2, CAN_EOIEN_INT, TRUE); } |