void main(void) { Uint16 j; struct ECAN_REGS ECanaShadow; InitSysCtrl(); InitECanGpio(); DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); MessageReceivedCount = 0; ErrorCount = 0; PassCount = 0; InitECana(); // Initialize eCAN-A module // Write to the MSGID field of RECEIVE mailboxe MBOX16 ECanaMboxes.MBOX16.MSGID.all = 0x9555AAA0; // Configure Mailboxes 0 as Tx, 16 as Rx // Since this write is to the entire register (instead of a bit // field) a shadow register is not required. ECanaRegs.CANMD.all = 0xFFFF0000; // Enable all Mailboxes */ // Since this write is to the entire register (instead of a bit // field) a shadow register is not required. ECanaRegs.CANME.all = 0xFFFFFFFF; // Specify that 8 bits will be sent/received ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8; // Since this write is to the entire register (instead of a bit // field) a shadow register is not required. EALLOW; ECanaRegs.CANMIM.all = 0xFFFFFFFF; // 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 = 0; // Configure CAN for self-test mode ECanaRegs.CANMC.all = ECanaShadow.CANMC.all; EDIS; // Begin receiving for(;;) { //Read from Receive mailboxes and begin checking for data */ for(j=16; j<17; j++) // Read & check 16 mailboxes { mailbox_read(j); // This func reads the indicated mailbox data mailbox_check(TestMbox1,TestMbox2,TestMbox3); // Checks the received data } Delay_us(900000) ; } } // This function reads out the contents of the indicated // by the Mailbox number (MBXnbr). void mailbox_read(int16 MBXnbr) { volatile struct MBOX *Mailbox; Mailbox = &ECanaMboxes.MBOX0 + MBXnbr; TestMbox1 = Mailbox->MDL.all; // = 0x9555AAAn (n is the MBX number) TestMbox2 = Mailbox->MDH.all; // = 0x89ABCDEF (a constant) TestMbox3 = Mailbox->MSGID.all;// = 0x9555AAAn (n is the MBX number) } // MSGID of a rcv MBX is transmitted as the MDL data. void mailbox_check(int32 T1, int32 T2, int32 T3) { if((T1 != T3) || ( T2 != 0x89ABCDEF)) { ErrorCount++; } else { PassCount++; } }