网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 61IC中国电子在线 >> DSP >> 代码示例 >> TI DSP代码示例 >> C2000 >> 文章正文
  TMS320F2812 ECanBack2Back范例程序         ★★★ 【字体:
TMS320F2812 ECanBack2Back范例程序
作者:61IC    文章来源:本站原创    点击数:    更新时间:2007-1-16    

//
//      TMDX ALPHA RELEASE
//      Intended for product evaluation purposes
//
//###########################################################################
//
// FILE: Example_28xECanBack2Back.c
//
// TITLE: DSP28 eCAN Back-to-back transmission and reception in
//          SELF-TEST mode
//
// ASSUMPTIONS:
//
//          This program requires the DSP28 header files.  To compile the
//          program as is, it should reside in the DSP28/examples/ecan_back2back
//          sub-directory.
//
//          As supplied, this project is configured for "boot to H0" operation. 
//
// DESCRIPTION:
//
//          This test transmits data back-to-back at high speed without stopping.
//          The received data is verified. Any error is flagged.
//          MBX0 transmits to MBX16, MBX1 transmits to MBX17 and so on....
//          This program illustrates the use of self-test mode
//
//###########################################################################
//
//  Ver | dd mmm yyyy | Who  | Description of changes
// =====|=============|======|===============================================
//  0.58| 29 Jun 2002 | H.J. | From H.J.'s original source
//###########################################################################

// Step 0.  Include required header files
         // DSP28_Device.h: device specific definitions #include statements for
         // all of the peripheral .h definition files.
         // DSP28_Example.h is specific for the given example. 

#include "DSP28_Device.h"

// Prototype statements for functions found within this file.
void mailbox_check(int32 T1, int32 T2, int32 T3);
void mailbox_read(int16 i);

// Global variable for this example
Uint32  ErrorCount;
Uint32  MessageReceivedCount;

Uint32  TestMbox1 = 0;
Uint32  TestMbox2 = 0;
Uint32  TestMbox3 = 0;

void main(void)
{

    Uint16  j;

    // eCAN control registers require read/write access using 32-bits.  Thus we
    // will create a set of shadow registers for this example.  These shadow
    // registers will be used to make sure the access is 32-bits and not 16.
    struct ECAN_REGS ECanaShadow;

// Step 1. Initialize System Control registers, PLL, WatchDog, Clocks to default state:
   // For this example, this function is found in Example_WatchdogSysCtrl.c
 InitSysCtrl();

// Step 2. Select GPIO for the device or for the specific application:
   // This function is found in the DSP28_Gpio.c file.
   // InitGpio();  // Skip this and init GPIO for this example here

    // Configure CAN pins using GPIO regs here
    EALLOW;
    GpioMuxRegs.GPFMUX.bit.CANTXA_GPIOF6 = 1;
    GpioMuxRegs.GPFMUX.bit.CANRXA_GPIOF7 = 1;
    EDIS;

// Step 3. Initialize PIE vector table:
   // PIE not used for this example
 
// Step 4. Initialize all the Device Peripherals to a known state:
 // This function is found in DSP28_InitPeripherals.c
    // InitPeripherals();  // Not required for this example.
 
// Step 5. User specific functions, Reassign vectors (optional), Enable Interrupts:

    MessageReceivedCount = 0;
    ErrorCount = 0;
   
    // eCAN control registers require 32-bit access.
    // If you want to write to a single bit, the compiler may break this
    // access into a 16-bit access.  One solution, that is presented here,
    // is to use a shadow register to force the 32-bit access.
    
    // Read the entire register into a shadow register.  This access
    // will be 32-bits.  Change the desired bit and copy the value back
    // to the eCAN register with a 32-bit write.
  
    // Configure the eCAN RX and TX pins for eCAN transmissions
    EALLOW;
    ECanaShadow.CANTIOC.all = ECanaRegs.CANTIOC.all;
    ECanaShadow.CANTIOC.bit.TXFUNC = 1;
    ECanaRegs.CANTIOC.all = ECanaShadow.CANTIOC.all;

    ECanaShadow.CANRIOC.all = ECanaRegs.CANRIOC.all;
    ECanaShadow.CANRIOC.bit.RXFUNC = 1;
    ECanaRegs.CANRIOC.all = ECanaShadow.CANRIOC.all;
    EDIS;
    
    // Disable all Mailboxes
    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.
 ECanaRegs.CANME.all = 0;
 
 // Mailboxs can be written to 16-bits or 32-bits at a time
    // Write to the MSGID field of TRANSMIT mailboxes MBOX0 - 15
    ECanaMboxes.MBOX0.MID.all = 0x9555AAA0;
    ECanaMboxes.MBOX1.MID.all = 0x9555AAA1;
    ECanaMboxes.MBOX2.MID.all = 0x9555AAA2;
    ECanaMboxes.MBOX3.MID.all = 0x9555AAA3;
    ECanaMboxes.MBOX4.MID.all = 0x9555AAA4;
    ECanaMboxes.MBOX5.MID.all = 0x9555AAA5;
    ECanaMboxes.MBOX6.MID.all = 0x9555AAA6;
    ECanaMboxes.MBOX7.MID.all = 0x9555AAA7;
    ECanaMboxes.MBOX8.MID.all = 0x9555AAA8;
    ECanaMboxes.MBOX9.MID.all = 0x9555AAA9;
    ECanaMboxes.MBOX10.MID.all = 0x9555AAAA;
    ECanaMboxes.MBOX11.MID.all = 0x9555AAAB;
    ECanaMboxes.MBOX12.MID.all = 0x9555AAAC;
    ECanaMboxes.MBOX13.MID.all = 0x9555AAAD;
    ECanaMboxes.MBOX14.MID.all = 0x9555AAAE;
    ECanaMboxes.MBOX15.MID.all = 0x9555AAAF;
   
    // Write to the MSGID field of RECEIVE mailboxes MBOX16 - 31
    ECanaMboxes.MBOX16.MID.all = 0x9555AAA0;
    ECanaMboxes.MBOX17.MID.all = 0x9555AAA1;
    ECanaMboxes.MBOX18.MID.all = 0x9555AAA2;
    ECanaMboxes.MBOX19.MID.all = 0x9555AAA3;
    ECanaMboxes.MBOX20.MID.all = 0x9555AAA4;
    ECanaMboxes.MBOX21.MID.all = 0x9555AAA5;
    ECanaMboxes.MBOX22.MID.all = 0x9555AAA6;
    ECanaMboxes.MBOX23.MID.all = 0x9555AAA7;
    ECanaMboxes.MBOX24.MID.all = 0x9555AAA8;
    ECanaMboxes.MBOX25.MID.all = 0x9555AAA9;
    ECanaMboxes.MBOX26.MID.all = 0x9555AAAA;
    ECanaMboxes.MBOX27.MID.all = 0x9555AAAB;
    ECanaMboxes.MBOX28.MID.all = 0x9555AAAC;
    ECanaMboxes.MBOX29.MID.all = 0x9555AAAD;
    ECanaMboxes.MBOX30.MID.all = 0x9555AAAE;
    ECanaMboxes.MBOX31.MID.all = 0x9555AAAF;
       
    // Configure Mailboxes 0-15 as Tx, 16-31 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.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX1.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX2.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX3.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX4.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX5.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX6.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX7.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX8.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX9.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX10.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX11.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX12.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX13.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX14.MCF.bit.DLC = 8;
    ECanaMboxes.MBOX15.MCF.bit.DLC = 8;
   
    // No remote frame is requested
    ECanaMboxes.MBOX0.MCF.bit.RTR = 0;  // Since RTR bit is undefined upon reset,
    ECanaMboxes.MBOX1.MCF.bit.RTR = 0;  // it must be initialized to the proper
    ECanaMboxes.MBOX2.MCF.bit.RTR = 0;  // value
    ECanaMboxes.MBOX3.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX4.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX5.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX6.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX7.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX8.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX9.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX10.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX11.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX12.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX13.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX14.MCF.bit.RTR = 0;
    ECanaMboxes.MBOX15.MCF.bit.RTR = 0;
   
    // Write to the mailbox RAM field of MBOX0 - 15
    ECanaMboxes.MBOX0.MDRL.all = 0x9555AAA0;
 ECanaMboxes.MBOX0.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX1.MDRL.all = 0x9555AAA1;
 ECanaMboxes.MBOX1.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX2.MDRL.all = 0x9555AAA2;
 ECanaMboxes.MBOX2.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX3.MDRL.all = 0x9555AAA3;
 ECanaMboxes.MBOX3.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX4.MDRL.all = 0x9555AAA4;
 ECanaMboxes.MBOX4.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX5.MDRL.all = 0x9555AAA5;
 ECanaMboxes.MBOX5.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX6.MDRL.all = 0x9555AAA6;
 ECanaMboxes.MBOX6.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX7.MDRL.all = 0x9555AAA7;
 ECanaMboxes.MBOX7.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX8.MDRL.all = 0x9555AAA8;
 ECanaMboxes.MBOX8.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX9.MDRL.all = 0x9555AAA9;
 ECanaMboxes.MBOX9.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX10.MDRL.all = 0x9555AAAA;
 ECanaMboxes.MBOX10.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX11.MDRL.all = 0x9555AAAB;
 ECanaMboxes.MBOX11.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX12.MDRL.all = 0x9555AAAC;
 ECanaMboxes.MBOX12.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX13.MDRL.all = 0x9555AAAD;
 ECanaMboxes.MBOX13.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX14.MDRL.all = 0x9555AAAE;
 ECanaMboxes.MBOX14.MDRH.all = 0x89ABCDEF;
 
 ECanaMboxes.MBOX15.MDRL.all = 0x9555AAAF;
 ECanaMboxes.MBOX15.MDRH.all = 0x89ABCDEF; 

    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.  
 EALLOW;
 ECanaRegs.CANMIM.all = 0xFFFFFFFF;

    // Request permission to change the configuration registers
    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
 ECanaShadow.CANMC.bit.CCR = 1;           
 ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
    EDIS;
   
    // Wait until the CPU has been granted permission to change the
    // configuration registers
    do
    {
      ECanaShadow.CANES.all = ECanaRegs.CANES.all;
    } while(ECanaShadow.CANES.bit.CCE != 1 );  // Wait for CCE bit to be set..
   
    // Configure the eCAN timing
    EALLOW;
    ECanaShadow.CANBTC.all = ECanaRegs.CANBTC.all;
    ECanaShadow.CANBTC.bit.BRP = 9;      // (BRP + 1) = 10 feeds a 15 MHz CAN clock
    ECanaShadow.CANBTC.bit.TSEG2 = 5 ;         // to the CAN module. (150 / 10 = 15)
    ECanaShadow.CANBTC.bit.TSEG1 = 7;          // Bit time = 15
    ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;
   
    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
    ECanaShadow.CANMC.bit.CCR = 0 ;            // Set CCR = 0
    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
    EDIS;

    // Wait until the CPU no longer has permission to change the
    // configuration registers
    do
    {
      ECanaShadow.CANES.all = ECanaRegs.CANES.all;
    } while(ECanaShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..

    // 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.SCM = 1;             // eCAN mode (reqd to access 32 mailboxes)
    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
    EDIS;
   
    // Begin transmitting
    while(1)                               
    {
    
       ECanaRegs.CANTRS.all = 0x0000FFFF;            // Set TRS for all transmit mailboxes
       while(ECanaRegs.CANTA.all != 0x0000FFFF ) {}  // Wait for all TAn bits to be set..
       ECanaRegs.CANTA.all = 0x0000FFFF;             // Clear all TAn   
       MessageReceivedCount++;

       //Read from Receive mailboxes and begin checking for data */
       for(j=0; j<16; j++)                           // Read & check 16 mailboxes
    {
          mailbox_read(j);                                  // This func reads the indicated mailbox data
          mailbox_check(TestMbox1,TestMbox2,TestMbox3);     // Checks the received data
       } 
    }
}

// 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->MDRL.all; // = 0x9555AAAn (n is the MBX number)
  TestMbox2 = Mailbox->MDRH.all;  // = 0x89ABCDEF (a constant)
  TestMbox3 = Mailbox->MID.all;   // = 0x9555AAAn (n is the MBX number)
  
} // MID of a rcv MBX is transmitted as the MDRL data.

void mailbox_check(int32 T1, int32 T2, int32 T3)
{
 if((T1 != T3) || ( T2 != 0x89ABCDEF))
    {
   ErrorCount++;
    }
}


//===========================================================================
// No more.
//===========================================================================

               欢迎点击进入:TI德州中文网   (国内唯一针对TI应用的中文技术网站)    文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    TMS320F2812的SPWM原程序
    基于LabVIEW和TMS320F2812的…
    TMS320F2812的CAN调试成功经…
    基于TMS320F2812和μC/OS II…
    TMS320F2812 全局汇编函数
    TMS320F2812 CMD 文件各段含…
    基于TMS320F2812集中供电系统…
    TMS320F2812的CMD文件配置详…
    基于TMS320F2812的多轴伺服控…
    利用TMS320F2812 DSP&DRV592…
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    站长:61IC 湘ICP备05002478号