📄 mbxramrw.c
字号:
/*********************************************************************
* Filename: MBXRAMRW.c *
* *
* Description: This code checks the integrity and correct *
* functionality of the mailbox RAM in the CAN module. *
* *
* This test writes patterns such as 0000h, FFFFh, 5555h, AAAAh to all
* the 32 mailboxes and reads them back for verification. *
* Any error is flagged.
*
* Last update: 12/24/2002 *
*********************************************************************/
#include "DSP28_Device.h"
#define COUNT 100000 // Mailbox RAM test will take place (COUNT) times..
long i;
long d;
long loopcount = 0; // Counts the # of times the loop actually ran
long errorcount = 0;
unsigned long TestMbox1 = 0;
void MBXrd(long d); /* This function reads from all 32 MBOXes */
void MBXwr(long d); /* This function writes to all 32 MBOXes */
void InitECan(void);
main()
{
/* Initialize the CAN module */
InitECan();
/* Enable all Mailboxes */
ECanaRegs.CANME.all = 0xFFFFFFFF;
/* Write to the mailbox RAM field of MBOX0 - 31 */
/* while(1) */ // Uncomment this line for infinite iterations
for(i=0; i < COUNT; i++) // Uncomment this line for finite iterations
{
d = 0xFFFFFFFF;
MBXwr(d);
MBXrd(d);
d = 0x00000000;
MBXwr(d);
MBXrd(d);
d = 0x55555555;
MBXwr(d);
MBXrd(d);
d = 0xAAAAAAAA;
MBXwr(d);
MBXrd(d);
loopcount++;
}
asm(" ESTOP0");
}
// Write the passed data to all 32 mailboxes
void MBXwr(long MBXdata)
{
int j;
volatile struct MBOX *Mailbox = (void *) 0x6100;
for(j=0; j<32; j++)
{
Mailbox->MDRH.all = MBXdata;
Mailbox->MDRL.all = MBXdata;
Mailbox = Mailbox + 1;
}
}
// Check if all 32 mailboxes contain the passed data
void MBXrd(long MBXdata)
{
int j;
volatile struct MBOX *Mailbox = (void *) 0x6100;
for(j=0; j<32; j++)
{
TestMbox1 = Mailbox->MDRL.all;
if (TestMbox1 != d)
{errorcount++;}
TestMbox1 = Mailbox->MDRH.all;
if (TestMbox1 != d)
{errorcount++;}
Mailbox = Mailbox + 1;
}
}
/* This code may be used to exercise and check the correct functionality
of the mailbox RAM */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -