This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320C6457 SRIO发送大于4096字节时的分包操作问题

Other Parts Discussed in Thread: TMS320C6457

最近在做srio数据传输的驱动,选择的是direct I/O NWRITE 事务,tms320c6457 dspji将其tx0链接到rx0构成serdes回环。我在数据文档以及其他参考资料中看到srio的lsu一次写操作(nwrite)最多可以发送4096个字节,也就是byte_count的值可以是256,最大是4096.如果要一次发送5000个字节,该如何对分包操作进行编程呢?我用的方法是先将要发送的数组的元素的个数与byte_count做比较,然后利用for循环,将数据分成两个大包,单步调试的时候,数据能够正确发送,但是只要一全速运行,不管发送的数据是多少(10,100,1000,4096,5000或者10000)接受到的数据都会发生错误,有时还会一直running,想请ti工程师帮忙看下程序哪里出了错误!红色字体部分是我改的地方。。。假设发送5000个字节,则数组大小应为2500.

#include <csl_srio.h>
#include <csl_srioAux.h>
#include <csl_psc.h>
#include <soc.h>
#include <stdio.h>

/***********************************************************************
************************** LOCAL Definitions **************************
***********************************************************************/

/* Device Identifiers (8bit and 16bit) for the Source Application. */
#define LARGE_DEV_ID 0xBEEF
#define SMALL_DEV_ID 0xAB

/* RIO NWrite Command Identifier. */
#define SRIO_PKT_TYPE_NWRITE 0x54

/* SRIO Port Number which is being used. */
#define SRIO_PORT_NUMBER 0

/* Length of data being transferred. */
#define TRANESFER_SIZE 4096

/************************************************************************

************************** GLOBAL Definitions **************************
************************************************************************/

/* Global Source and Destination buffers. */
static Uint16 src[shuzudaxiao];
static Uint16 dst[shuzudaxiao];

/* Global SRIO Hardware Setup is used */
static CSL_SrioHwSetup setup = CSL_SRIO_HWSETUP_DEFAULTS;

/************************************************************************
************************** LSU Example Functions ***********************
************************************************************************/

/*
* ============================================================================
* @func delay
*
* @desc
* This routine is used to spin in a delay loop for delay iterations
* ============================================================================
*/
static void delay(Uint32 delay)
{
volatile Uint32 i, n;

n = 0;
for (i = 0; i < delay; i++)
{
n = n + 1;
}
}

void main (void)
{
volatile Uint32 index;

volatile Uint32 zijieshu,shang,yushu,baogeshu,i;
CSL_SrioContext context;
CSL_Status status;
CSL_SrioHandle hSrio;
CSL_SrioObj srioObj;
CSL_SrioParam srioParam;
CSL_SrioDirectIO_ConfigXfr lsu_conf = {0};
CSL_SrioPortData response;
CSL_SrioCntlSym cntrlSym;
CSL_SrioLsuCompStat completionCode;

/* Enable SRIO in PSC control module */
enableSRIO();

/* Initialization and Open of the SRIO */
status = CSL_srioInit (&context);
hSrio = CSL_srioOpen (&srioObj, 0, &srioParam, &status);
if (status != CSL_SOK)
{
printf("SRIO: ... Cannot open SRIO, failed\n");
return;
}

/* Create the setup structure */
srio_Create_Setup (&setup);

/* Setup the SRIO with the selected setup in the last step */
status = CSL_srioHwSetup (hSrio, &setup);
if (status != CSL_SOK)
{
printf("SRIO: ... Hardware setup, failed\n");
return;
}

/* Setup the source and destination */
for(index=0; index<TRANSFER_SIZE; index++)
{
src[index] = index ;
dst[index] = 0;
}

/* Make sure that the SRIO Port is Initialized. */
printf ("Debug: Waiting for SRIO Port %d to be initialized\n", SRIO_PORT_NUMBER);

/* Loop around till the PORT is initialized. */
response.index = SRIO_PORT_NUMBER;
do
{
delay(10000); //check the response every 100 cpu clcok = 100 ns
CSL_srioGetHwStatus (hSrio, CSL_SRIO_QUERY_SP_ERR_STAT, &response);
}while(response.data & 0x1);

/* Clear any errors... */
cntrlSym.portNum = (CSL_SrioPortNum)SRIO_PORT_NUMBER;
cntrlSym.stype0 = 0x2;
cntrlSym.par0 = 0x0;
cntrlSym.par1 = 0x1F;
cntrlSym.stype1 = 0x4;
cntrlSym.cmd = 0x4;
cntrlSym.emb = 0x0;
CSL_srioHwControl (hSrio, CSL_SRIO_CMD_CNTL_SYM_SET, &cntrlSym);

/* Read the Port Error Status register. */
response.index = SRIO_PORT_NUMBER;
CSL_srioGetHwStatus (hSrio, CSL_SRIO_QUERY_SP_ERR_STAT, &response);

/* Was there an error detected? */
if ((response.data & ~0x2) != 0)
{
/* Error was detected; we need to clear this before we can proceed... */
printf ("Error: Port %d has Input/Output Error... clearing\n", SRIO_PORT_NUMBER);

/* Clearing the errors... */
CSL_srioHwControl (hSrio, CSL_SRIO_CMD_SP_ERR_STAT_CLEAR, &response);
}

zijieshu=shuzudaxiao*2;

shang=zijieshu/TRANESFER_SIZE;

yushu=zijieshu%TRANESFER_SIZE;

if(TRANESFER_SIZE<=zijieshu)

{

       if(shang==0)

          baogeshu=shang;

       else

             baogeshu=shang+1;

       for(i=1;i<=baogeshu;i++)

       {

               

/***********************************************************************************
********************************* DATA Transfer ***********************************
***********************************************************************************/

/* Create an LSU configuration */
lsu_conf.srcNodeAddr = (Uint32)&src[0+2048(i-1)]; /* Source address */
lsu_conf.dstNodeAddr.addressHi = 0;
lsu_conf.dstNodeAddr.addressLo = (Uint32)&dst[0+2048(i-1)] /* Destination address */
lsu_conf.byteCnt = TRANSFER_SIZE; /* Size of data */
lsu_conf.idSize = 1; /* 16 bit device id */
lsu_conf.priority = 2; /* PKT priority is 2 */
lsu_conf.xambs = 0; /* Not an extended address */
lsu_conf.dstId = LARGE_DEV_ID; /* Destination ID */
lsu_conf.intrReq = 0; /* No interrupts */
lsu_conf.pktType = SRIO_PKT_TYPE_NWRITE;/* Write with no response */
lsu_conf.hopCount = 0; /* Valid for maintainance pkt */
lsu_conf.doorbellInfo = 0; /* Not a doorbell pkt */
lsu_conf.outPortId = SRIO_PORT_NUMBER; /* Tx on specified SRIO Port */

/* Configure the LSU and start transmission */
CSL_srioLsuSetup (hSrio, &lsu_conf, 0);

       }

}

/* Wait for the completion of transfer */
response.index = 0;
while (1)
{
/* Poll and check if the LSU has completed */
CSL_srioGetHwStatus (hSrio, CSL_SRIO_QUERY_LSU_BSY_STAT, &response);

/* Is the LSU not busy */
if (response.data == 0)
break;
}

/* Get the completion Code for the specific LSU. */
completionCode.portNum = CSL_SRIO_PORT_0;
CSL_srioLsuCompCodeStat(hSrio, &completionCode);
if (completionCode.lsuCompCode != 0x0)
{
/* Failed Transfer. */
printf ("Error: SRIO Write has a completion code of %d\n", completionCode.lsuCompCode);
return;
}

printf ("Debug: SRIO Transfer was completed; validating...\n");

/* Validate the received data to ensure data was transferred correctly. */
for(index=0; index<shuzudaxiao; index++)
{
if (src[index] != dst[index])
break;
}
if (index == shuzudaxiao)
printf("Debug: Data Transfer Validated\n");
else
printf("Error: Data Transfer Corrupted\n");
}