// TI Release: 28xx eCAN programming example // Release Date: Fri Aug 4 2017 // Copyright: // Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // /********************************************************************* * Filename: RXLOOP.c * * * * Description: This is a simple example of how data may be received * * All mailboxes in CAN-A are configured as receive mailboxes. Each mailbox * has a different ID. All mailboxes in node B are allowed to transmit * in a sequence to mailboxes in node A. Once the cycle is complete, * the cycle is started all over again. * This program loops forever. The # of times the receive loop is executed * is stored in the RXCOUNT value. * *********************************************************************/ // // Included Files // #include "DSP28x_Project.h" // Device Headerfile and Examples Include File long RXCOUNT = 0; long i; Uint32 TestMbox1 = 0; Uint32 TestMbox2 = 0; Uint32 TestMbox3 = 0; void MBXwrA(void); // This function initializes all 32 MBOXes of CAN-A main() { /* Create a shadow register structure for the CAN control registers. This is needed, since, only 32-bit access is allowed to these registers. 16-bit access to these registers could potentially corrupt the register contents. This is especially true while writing to a bit (or group of bits) among bits 16 - 31 */ struct ECAN_REGS ECanaShadow; // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP280x_SysCtrl.c file. InitSysCtrl(); /* Initialize the CAN module */ InitECan(); InitECanGpio(); EALLOW; /* Zero out (or initialize) the entire MBX RAM area */ MBXwrA(); /* Write to the MSGID field 0f CAN-A - MBX number is written as its MSGID */ ECanaMboxes.MBOX0.MSGID.all = 0x9555AAA0; /* Configure CAN-A Mailboxes as Receive mailboxes */ ECanaShadow.CANMD.all = ECanaRegs.CANMD.all; ECanaShadow.CANMD.all = 0xFFFFFFFF; ECanaRegs.CANMD.all = ECanaShadow.CANMD.all; /* Enable Mailboxes */ ECanaShadow.CANME.all = ECanaRegs.CANME.all; ECanaShadow.CANME.all = 0xFFFFFFFF; ECanaRegs.CANME.all = ECanaShadow.CANME.all; /* Begin receiving */ while(1) { while(ECanaRegs.CANRMP.all != 0x00000001) { } // Wait for all RMPn to be set.. ECanaRegs.CANRMP.all = 0x00000001; // Clear all RMPn bits and start RXCOUNT++ ; // all over again... if(RXCOUNT==1000){break;} } } /* Zero-out the MBX RAM of CAN-A */ void MBXwrA() { int j; volatile struct MBOX *Mailbox = (void *) 0x6100; for(j=0; j<32; j++) { Mailbox->MSGID.all = 0; Mailbox->MSGCTRL.all = 0; Mailbox->MDH.all = 0; Mailbox->MDL.all = 0; Mailbox = Mailbox + 1; } } /* Note: If writing only to the 11-bit identifier as by "ECanaMboxes.MBOX1.MSGID.bit.STDMSGID = 1;", IDE, AME & AAM bit fields also need to be initialized. Otherwise, they may assume random values. This could be done by just initializing the entire register to zero first and then writing the STD MSG ID. */