源码:
#include "sys_common.h"
#include "system.h"
/* USER CODE BEGIN (1) */
#include "can.h"
#include "esm.h"
#include "sys_core.h"
#define D_COUNT 8
uint32 cnt=0, error =0, tx_done =0;
uint8 tx_data[D_COUNT][8] = {0};
uint8 rx_data[D_COUNT][8] = {0};
uint8 *tx_ptr = &tx_data[0][0];
uint8 *rx_ptr = &rx_data[0][0];
uint8 *dptr=0;
void dumpSomeData();
/* USER CODE END */
/* USER CODE BEGIN (2) */
/* USER CODE END */
void main(void)
{
/* USER CODE BEGIN (3) */
/* enable irq interrupt in Cortex R4 */
_enable_interrupt_();
dumpSomeData();
canInit();
canEnableErrorNotification(canREG1);
canEnableErrorNotification(canREG2);
for(cnt=0;cnt
{
canTransmit(canREG1, canMESSAGE_BOX1, tx_ptr); /* transmitting 8 different chunks 1 by 1 */
//canMessageNotification(canREG1,canMESSAGE_BOX1);
//canMessageNotification(canREG2,canMESSAGE_BOX1);//原例程只是定义了这个函数,但是没有调用,这里是我自己写上去的
while(tx_done == 0){}; /* ... wait until transmit request is through */
tx_done=0;
tx_ptr +=8; /* next chunk ...*/
}
tx_ptr = &tx_data[0][0];
rx_ptr = &rx_data[0][0];
for(cnt=0;cnt<63;cnt++)
{
if(*tx_ptr++ != *rx_ptr++)
{
error++; /* data error */
}
}
while(1){}; /* wait forever after tx-rx complete. */
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
/* writing some data to ram */
void dumpSomeData()//dump(内存信息)转储
{
uint32 tmp = 0x11;
cnt = (D_COUNT*8)-1;
dptr = &tx_data[0][0];
*dptr = tmp;
while(cnt--)
{
tmp = *dptr++;
*dptr = tmp + 0x11;
}
}
/* can interrupt notification */
/* Note-You need to remove canMessageNotification from notification.c to avoid redefinition */
void canMessageNotification(canBASE_t *node, uint32 messageBox)
{
/* node 1 - transfer request */
if(node==canREG1)
{
tx_done=1; /* confirm transfer request */
}
/* node 2 - receive complete */
if(node==canREG2)
{
while(!canIsRxMessageArrived(canREG2, canMESSAGE_BOX1));
canGetData(canREG2, canMESSAGE_BOX1, rx_ptr); /* copy to RAM */
rx_ptr +=8;
}
/* Note: since only message box 1 is used on both nodes we dont check it here.*/
}
/* USER CODE END */
源码:
#include "sys_common.h"
#include "system.h"
/* USER CODE BEGIN (1) */
#include "can.h"
#include "esm.h"
#include "sys_core.h"
#define D_COUNT 8
uint32 cnt=0, error =0, tx_done =0;
uint8 tx_data[D_COUNT][8] = {0};
uint8 rx_data[D_COUNT][8] = {0};
uint8 *tx_ptr = &tx_data[0][0];
uint8 *rx_ptr = &rx_data[0][0];
uint8 *dptr=0;
void dumpSomeData();
/* USER CODE END */
/* USER CODE BEGIN (2) */
/* USER CODE END */
void main(void)
{
/* USER CODE BEGIN (3) */
/* enable irq interrupt in Cortex R4 */
_enable_interrupt_();
dumpSomeData();
canInit();
canEnableErrorNotification(canREG1);
canEnableErrorNotification(canREG2);
for(cnt=0;cnt
{
canTransmit(canREG1, canMESSAGE_BOX1, tx_ptr); /* transmitting 8 different chunks 1 by 1 */
//canMessageNotification(canREG1,canMESSAGE_BOX1);
//canMessageNotification(canREG2,canMESSAGE_BOX1);//原例程只是定义了这个函数,但是没有调用,这里是我自己写上去的
while(tx_done == 0){}; /* ... wait until transmit request is through */
tx_done=0;
tx_ptr +=8; /* next chunk ...*/
}
tx_ptr = &tx_data[0][0];
rx_ptr = &rx_data[0][0];
for(cnt=0;cnt<63;cnt++)
{
if(*tx_ptr++ != *rx_ptr++)
{
error++; /* data error */
}
}
while(1){}; /* wait forever after tx-rx complete. */
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
/* writing some data to ram */
void dumpSomeData()//dump(内存信息)转储
{
uint32 tmp = 0x11;
cnt = (D_COUNT*8)-1;
dptr = &tx_data[0][0];
*dptr = tmp;
while(cnt--)
{
tmp = *dptr++;
*dptr = tmp + 0x11;
}
}
/* can interrupt notification */
/* Note-You need to remove canMessageNotification from notification.c to avoid redefinition */
void canMessageNotification(canBASE_t *node, uint32 messageBox)
{
/* node 1 - transfer request */
if(node==canREG1)
{
tx_done=1; /* confirm transfer request */
}
/* node 2 - receive complete */
if(node==canREG2)
{
while(!canIsRxMessageArrived(canREG2, canMESSAGE_BOX1));
canGetData(canREG2, canMESSAGE_BOX1, rx_ptr); /* copy to RAM */
rx_ptr +=8;
}
/* Note: since only message box 1 is used on both nodes we dont check it here.*/
}
/* USER CODE END */
举报