Part Number: TMS320C5545
Other Parts Discussed in Thread: CC8530
Tool/software: Code Composer Studio
Hi
I have a problem.
I am using c5545 to recieve I2S data from cc8530
and I already tried some example code ( CSL_I2S_DMAExample_Out)
I modified the code for my system.
Actually, in my system C5545 I2S will be worked as SLAVE.
But when I modified to SLAVE, DMA doesn't work.
when I chose Master, it worked.what is my problem?
This is part of my code.
Let me know what problem is
Thanks.
Int16 i2s_DMA_sample(void)
{
Int16 status = CSL_TEST_FAILED;
Int16 result;
CSL_I2sHandle hI2s;
I2S_Config hwConfig;
Uint16 looper;
/* Initialize data buffers */
for(looper=0; looper < CSL_I2S_DMA_BUF_LEN; looper++)
{
i2sDmaWriteLeftBuff[looper] = 0;
i2sDmaReadLeftBuff[looper] = 0;
i2sDmaWriteRightBuff[looper] = 0;
i2sDmaReadRightBuff[looper] = 0;
}
/* On C5535/C5515/C5517 DSP DMA swaps the words in the source buffer
before transferring it to the I2S registers. No data mismatch is
observed When the write and read operations are done in DMA mode
as the word swap occurs in both the operations.
There will be data mismatch if data write is in DMA mode
and read is in polling mode or vice versa.
To ensure that the data will be written to memory properly in DMA mode
words in the write buffer are swapped by software. During DMA transfer
DMA hardware again will do a word swap which will bring the data buffer
back to original values. Word swap is not required for read
buffer after read operation in DMA mode as I2S hardware will do
a word swap on the data before looping it back to receive registers.
This is peculiar behavior of the I2S HW in loopback mode
*/
/* Swap words in I2S write buffer */
result = DMA_swapWords((Uint16*)i2sDmaWriteLeftBuff, 2*CSL_I2S_DMA_BUF_LEN);
if(result != CSL_SOK)
{
printf ("DMA word swap API failed\n");
status = CSL_TEST_FAILED;
return (status);
}
result = DMA_swapWords((Uint16*)i2sDmaWriteRightBuff, 2*CSL_I2S_DMA_BUF_LEN);
if(result != CSL_SOK)
{
printf ("DMA word swap API failed\n");
status = CSL_TEST_FAILED;
return (status);
}
/** Open the device with instance 0 */
hI2s = I2S_open(I2S_INSTANCE0, DMA_POLLED, I2S_CHAN_STEREO);
if(NULL == hI2s)
{
status = CSL_TEST_FAILED;
return (status);
}
else
{
printf ("I2S Module Instance opened successfully\n");
}
result = SYS_setEBSR(CSL_EBSR_FIELD_SP0MODE,
CSL_EBSR_SP0MODE_1);
if(CSL_SOK != result)
{
printf("SYS_setEBSR failed\n");
return (result);
}
/** Set the value for the configure structure */
hwConfig.dataType = I2S_STEREO_ENABLE;
hwConfig.loopBackMode = I2S_LOOPBACK_ENABLE;
hwConfig.fsPol = I2S_FSPOL_LOW;
hwConfig.clkPol = I2S_FALLING_EDGE;
hwConfig.datadelay = I2S_DATADELAY_ONEBIT;
hwConfig.datapack = I2S_DATAPACK_DISABLE;
hwConfig.signext = I2S_SIGNEXT_DISABLE;
hwConfig.wordLen = I2S_WORDLEN_16;
hwConfig.i2sMode = I2S_SLAVE;
hwConfig.clkDiv = I2S_CLKDIV4;
hwConfig.fsDiv = I2S_FSDIV32;
hwConfig.FError = I2S_FSERROR_DISABLE;
hwConfig.OuError = I2S_OUERROR_DISABLE;
/** Configure hardware registers */
result = I2S_setup(hI2s, &hwConfig);
if(result != CSL_SOK)
{
status = CSL_TEST_FAILED;
return (status);
}
else
{
printf ("I2S Module Configured successfully\n");
}
/* Configure DMA channel for I2S write */
#if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514) || defined (CHIP_C5517) || defined(CHIP_C5535) || defined(CHIP_C5545))
dmaConfig.pingPongMode = CSL_DMA_PING_PONG_DISABLE;
#endif
dmaConfig.autoMode = CSL_DMA_AUTORELOAD_DISABLE;
dmaConfig.burstLen = CSL_DMA_TXBURST_1WORD;
dmaConfig.trigger = CSL_DMA_EVENT_TRIGGER;
dmaConfig.dmaEvt = CSL_DMA_EVT_I2S0_TX;
dmaConfig.dmaInt = CSL_DMA_INTERRUPT_DISABLE;
dmaConfig.chanDir = CSL_DMA_WRITE;
dmaConfig.trfType = CSL_DMA_TRANSFER_IO_MEMORY;
dmaConfig.dataLen = 4;
dmaConfig.srcAddr = (Uint32)i2sDmaWriteLeftBuff;
dmaConfig.destAddr = (Uint32)(0x2808);
dmaLeftTxHandle = CSL_configDmaForI2s(CSL_DMA_CHAN0);
if(dmaLeftTxHandle == NULL)
{
printf("DMA Config for I2S Write Failed!\n!");
return(CSL_TEST_FAILED);
}
I2S_transEnable(hI2s, TRUE);
status = DMA_start(dmaLeftTxHandle);
if(status != CSL_SOK)
{
printf("I2S Dma Write Failed!!\n");
return(result);
}
while(DMA_getStatus(dmaLeftTxHandle)); <- when I chose SLAVE, HERE IS THE STOP POINT.
/* Configure DMA channel for I2S write */
#if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514) || defined(CHIP_C5517) || defined(CHIP_C5535) || defined(CHIP_C5545))
dmaConfig.pingPongMode = CSL_DMA_PING_PONG_DISABLE;
#endif
dmaConfig.autoMode = CSL_DMA_AUTORELOAD_DISABLE;
dmaConfig.burstLen = CSL_DMA_TXBURST_1WORD;
dmaConfig.trigger = CSL_DMA_EVENT_TRIGGER;
dmaConfig.dmaEvt = CSL_DMA_EVT_I2S0_TX;
dmaConfig.dmaInt = CSL_DMA_INTERRUPT_DISABLE;
dmaConfig.chanDir = CSL_DMA_WRITE;
dmaConfig.trfType = CSL_DMA_TRANSFER_IO_MEMORY;
dmaConfig.dataLen = 4;
dmaConfig.srcAddr = (Uint32)i2sDmaWriteRightBuff;
dmaConfig.destAddr = (Uint32)(0x280C);
dmaRightTxHandle = CSL_configDmaForI2s(CSL_DMA_CHAN0);
if(dmaRightTxHandle == NULL)
{
printf("DMA Config for I2S Write Failed!\n!");
return(CSL_TEST_FAILED);
}
I2S_transEnable(hI2s, TRUE);
status = DMA_start(dmaRightTxHandle);
if(status != CSL_SOK)
{
printf("I2S Dma Write Failed!!\n");
return(result);
}
while(DMA_getStatus(dmaRightTxHandle));
/* Configure DMA channel for I2S Read */
#if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514) || defined(CHIP_C5517) || defined(CHIP_C5535) || defined(CHIP_C5545))
dmaConfig.pingPongMode = CSL_DMA_PING_PONG_DISABLE;
#endif
dmaConfig.autoMode = CSL_DMA_AUTORELOAD_DISABLE;
dmaConfig.burstLen = CSL_DMA_TXBURST_1WORD;
dmaConfig.trigger = CSL_DMA_EVENT_TRIGGER;
dmaConfig.dmaEvt = CSL_DMA_EVT_I2S0_RX;
dmaConfig.dmaInt = CSL_DMA_INTERRUPT_DISABLE;
dmaConfig.chanDir = CSL_DMA_READ;
dmaConfig.trfType = CSL_DMA_TRANSFER_IO_MEMORY;
dmaConfig.dataLen = 4;
dmaConfig.srcAddr = (Uint32)(0x2828);
dmaConfig.destAddr = (Uint32)i2sDmaReadLeftBuff;
dmaLeftRxHandle = CSL_configDmaForI2s(CSL_DMA_CHAN0);
if(dmaLeftRxHandle == NULL)
{
printf("DMA Config for I2S Read Failed!\n!");
return(CSL_TEST_FAILED);
}
status = DMA_start(dmaLeftRxHandle);
if(status != CSL_SOK)
{
printf("I2S Dma Read Failed!!\n");
return(result);
}
while(DMA_getStatus(dmaLeftRxHandle));
/* Configure DMA channel for I2S Read */
#if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514) || defined(CHIP_C5517) || defined(CHIP_C5535) || defined(CHIP_C5545))
dmaConfig.pingPongMode = CSL_DMA_PING_PONG_DISABLE;
#endif
dmaConfig.autoMode = CSL_DMA_AUTORELOAD_DISABLE;
dmaConfig.burstLen = CSL_DMA_TXBURST_1WORD;
dmaConfig.trigger = CSL_DMA_EVENT_TRIGGER;
dmaConfig.dmaEvt = CSL_DMA_EVT_I2S0_RX;
dmaConfig.dmaInt = CSL_DMA_INTERRUPT_DISABLE;
dmaConfig.chanDir = CSL_DMA_READ;
dmaConfig.trfType = CSL_DMA_TRANSFER_IO_MEMORY;
dmaConfig.dataLen = 4;
dmaConfig.srcAddr = (Uint32)(0x282C);
dmaConfig.destAddr = (Uint32)i2sDmaReadRightBuff;
dmaRightRxHandle = CSL_configDmaForI2s(CSL_DMA_CHAN0);
if(dmaRightRxHandle == NULL)
{
printf("DMA Config for I2S Read Failed!\n!");
return(CSL_TEST_FAILED);
}
I2S_transEnable(hI2s, TRUE);
status = DMA_start(dmaRightRxHandle);
if(status != CSL_SOK)
{
printf("I2S Dma Read Failed!!\n");
return(result);
}
while(DMA_getStatus(dmaRightRxHandle));
I2S_transEnable(hI2s, FALSE);
/** Reset the registers */
result = I2S_reset(hI2s);
if(result != CSL_SOK)
{
status = CSL_TEST_FAILED;
return (status);
}
else
{
printf ("I2S Reset Successful\n");
}
/** Close the operation */
result = I2S_close(hI2s);
if(result != CSL_SOK)
{
status = CSL_TEST_FAILED;
return (status);
}
else
{
printf ("I2S Close Successful\n");
}
/* Swap words in I2S write buffer
This will make the data in write buffer get back to original values
after that write buffer can be used for validating the read buffer
This sep is required only incase of comparing read and write buffers */
result = DMA_swapWords((Uint16*)i2sDmaWriteLeftBuff, 2*CSL_I2S_DMA_BUF_LEN);
if(result != CSL_SOK)
{
printf ("DMA word swap API failed\n");
status = CSL_TEST_FAILED;
return (status);
}
result = DMA_swapWords((Uint16*)i2sDmaWriteRightBuff, 2*CSL_I2S_DMA_BUF_LEN);
if(result != CSL_SOK)
{
printf ("DMA word swap API failed\n");
status = CSL_TEST_FAILED;
return (status);
}
/** Compare the read and write buffer */
for(looper=0; looper < CSL_I2S_DMA_BUF_LEN; looper++)
{
if(i2sDmaWriteLeftBuff[looper] != i2sDmaReadLeftBuff[looper])
{
printf("I2S Read & Write Buffers doesn't Match!!!\n");
status = CSL_TEST_FAILED;
return(status);
}
}
if(looper == CSL_I2S_DMA_BUF_LEN)
{
printf("I2S Read & Write Buffers Match!!!\n");
}
status = CSL_TEST_PASSED;
return (status);
}
/*
This is the main function to call sample program
*/
/////INSTRUMENTATION FOR BATCH TESTING -- Part 1 --
///// Define PaSs_StAtE variable for catching errors as program executes.
///// Define PaSs flag for holding final pass/fail result at program completion.
volatile Int16 PaSs_StAtE = 0x0001; // Init to 1. Reset to 0 at any monitored execution error.
volatile Int16 PaSs = 0x0000; // Init to 0. Updated later with PaSs_StAtE when and if
///// program flow reaches expected exit point(s).
/////
void main(void)
{
Int16 status;
printf("CSL I2S DMA MODE TEST!\n\n");
status = i2s_DMA_sample();
if(status != CSL_TEST_PASSED)
{
printf("\nCSL I2S DMA MODE TEST FAILED!!\n\n");
/////INSTRUMENTATION FOR BATCH TESTING -- Part 2 --
///// Reseting PaSs_StAtE to 0 if error detected here.
PaSs_StAtE = 0x0000; // Was intialized to 1 at declaration.
/////
}
else
{
printf("\nCSL I2S DMA MODE TEST PASSED!\n\n");
}
/////INSTRUMENTATION FOR BATCH TESTING -- Part 3 --
///// At program exit, copy "PaSs_StAtE" into "PaSs".
PaSs = PaSs_StAtE; //If flow gets here, override PaSs' initial 0 with
///// // pass/fail value determined during program execution.
///// Note: Program should next exit to C$$EXIT and halt, where DSS, under
///// control of a host PC script, will read and record the PaSs' value.
/////
while(1);
}