Пример #1
0
/**
 * initializes the I2C bus
 * @return 0 on success
 */
int Com_CAN_Init() {
	int i;

	InitECanGpio();

	InitECan();

    // Configure the eCAN for self test mode
    // Enable the enhanced features of the eCAN.
    //EALLOW;
    //ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
    //ECanaShadow.CANMC.bit.STM = 1;    // Configure CAN for self-test mode
    //ECanaShadow.CANMC.bit. = 1;    // Configure CAN for self-test mode
    //ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
    //EDIS;

    // reset all timestamps
    for(i = 0; i < 32; i++) {
    	volatile Uint32* mots;

    	mots = &ECanaMOTSRegs.MOTS0 + i;
    	*mots = 0;
    }

	Com_CAN_InitReceiveMBoxes();
	Com_CAN_InitTransmitMBoxes();

	return 0;
}
Пример #2
0
void CAN_init(){
	struct ECAN_REGS ECanaShadow;
	//CAN_INFO_ARRAY[ID].upon_sent_isr = send_isr;
	//CAN_INFO_ARRAY[ID].upon_receive_isr = receive_isr;
	// Step 1. Initialize System Control:
	// PLL, WatchDog, enable Peripheral Clocks
	// This function is found in the F2806x_SysCtrl.c file.
	// Should be commented out in regular usage. For normal usage initializing the system should be done elsewhere not in the CAN code.
	// For testing purposes this is uncommented to initialize the system.
	   InitSysCtrl();

	// Step 2. Initalize GPIO:
	// Configure CAN pins using GPIO regs here
	// This function is found in F2806x_ECan.c
	   InitECanGpio();

	// Step 3. Clear all interrupts and initialize PIE vector table:
	// Disable CPU interrupts
	   DINT;

	// Disable CPU interrupts and clear all CPU interrupt flags:
	   IER = 0x0000;
	   IFR = 0x0000;

	   EALLOW;
	   //Direct ECANA0 interrupts to the proper isr
	   PieVectTable.ECAN0INTA = &ecan_isr;
	   EDIS;

	// Enable the PIE Vector Table
	   PieCtrlRegs.PIECTRL.bit.ENPIE = 1;

   // Step 4. Initialize CAN module
	   InitECana();

	   EALLOW;
	   //Allow all mailboxes to send interrupts
	   ECanaRegs.CANMIM.all = 0xFFFFFFFF;
	   //Disable all other system interrupts (not recommended)
	   //Only enable level 0 interrupts
	   //BY DEFAULT using level 0 CAN interrupts
	   ECanaRegs.CANGIM.all = 0x00000001;
	   // EALLOW;
	    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
	    ECanaShadow.CANMC.bit.STM = 1;    // Configure CAN for self-test mode
	    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
	    //EDIS;
	   EDIS;

	   //CAN interrupts are part of IER 9
	    IER |= M_INT9;

	    //Enable ECAN interrupt 0 in PIE
	    PieCtrlRegs.PIEIER9.bit.INTx5 = 1;

	    // Enable global Interrupts and higher priority real-time debug events:
	    EINT;   // Enable Global interrupt INTM
	    ERTM;   // Enable Global realtime interrupt DBGM
}