(ADSC-589) EPPI receive of the digital output from AD7768 has a problem. (Random 1´s and 0´s)

Hello , 

I am trying to receive the digital output from the AD7768  through EPPI ports of ADSC-589 DSP processor and i am receiving bad output data. 

AD7768-8 channel ADC

Fast Mode-(256 kSPS maximum, 110.8 kHz input bandwidth, 51.5 mW per channel)

DCLK=4MHz

DYRD=8KHz

Number of sample= 1K 

Data length= 32BIT

SC589 EPPI

SetITU Mode-General_Purpose Mode

FS Mode- Mode 1

EPPI Data Length= 8 BIT

DMA Transfer Size=32 BIT

External Clock and Frame Sync from AD7768

Horizontal Delay= 0

Samples Per Line=31

Horizontal Count=32

EPPI Set Pack=True

DMA Config

*pREG_DMA28_ADDRSTART=&PingPong;


*pREG_DMA28_CFG = 0x00;


*pREG_DMA28_XCNT=0X200;


*pREG_DMA28_XMOD=0X01;


*pREG_DMA28_CFG |= 0x1;

Example Output;

Rx=1010000
Rx=10100
Rx=10101
Rx=1000101
Rx=1010101
Rx=1000001
Rx=0
Rx=100
Rx=1010000
Rx=10100
Rx=1010101
Rx=1000101
Rx=10000
Rx=1010100
Rx=0
Rx=100
Rx=1010000
Rx=10100
Rx=10101
Rx=1000101
Rx=100
Rx=1
Rx=0
Rx=100
Rx=1010000
Rx=10100
Rx=101
Rx=10101
Rx=101
Rx=1000001
Rx=0
Rx=100
Rx=1010000
Rx=10100
Rx=101
Rx=10101
Rx=10000
Rx=1000001
Rx=0
Rx=100
Rx=1010000

Is this the correct format to configure the DMA and EPPI ?

/*****************************************************************************
 * EPPI_Rxdata.c
 *****************************************************************************/

#include <sys/platform.h>
#include "adi_initialize.h"

#define BUFFER_SIZE 512

#if defined (__ECC__)
#pragma align 32
#endif

uint32_t PPI_RxBuffer[BUFFER_SIZE];


#include <sys/platform.h>

#include <stdio.h>
#include <drivers/ppi/adi_ppi.h>

#if !defined (__ADSPBF609_FAMILY__) && !defined (__ADSPBF707_FAMILY__) && !defined (__ADSP215xx__)
#error "This test is only designed for BF707, BF609 and SC5xx families"
#endif

#if 0
/*
 * Enable this code if you want to shut off the cache
 */
uint32_t adi_cache_gEnable  = 0u;
#endif


#define EPPI_RECEIVER

#ifdef EPPI_RECEIVER

#define TEST_NUM 1

#endif

volatile uint64_t  nTest;

volatile uint64_t *pTest = (volatile uint64_t *) 0x00241440; // SHARC1 multiprocessor space, L1 block 2, address 0xB0000

/* interrupt mode transceiver test array, all direction permutations */
void *PingPong[] = {&PPI_RxBuffer};

/* driver handle */
static ADI_EPPI_HANDLE phPpi;
/*
 * Eppi memory  This includes the memory used by the DMA service, so having it aligned on cache boundaries
 * can help if there are any cache related issues being flushed out (all puns intended)
 *
 * Alternatively, can place this buffer in non-cacheable memory
 * Depending on your target (ARM-A5, SHARC-XI) the declarations to accomplish any of this will vary (of course,
 * standards are great and everyone should have one)
 *
 */


#include <services/gpio/adi_gpio.h>
#if defined (__ADSPARM__)
/* Some variables in this code sketch are set for demonstration purposes
 * but not used. These variables are expected to be used in real
 * applications.
 */

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif


#define GPIO_MEMORY_SIZE (ADI_GPIO_CALLBACK_MEM_SIZE)

/* allocate memory for the GPIO service */
static uint8_t gpioMemory[GPIO_MEMORY_SIZE];



#if 0
#if defined (__ECC__)
#pragma align 32
#endif
#endif
uint8_t EppiMemory[ADI_EPPI_MEMORY_SIZE]; /* __attribute__ ((section (".l2_uncached_data")));  */
#if 0
#if defined (__ADSPARM__)
__attribute__ ((aligned (32)))
#endif
#endif
;
ADI_GPIO_RESULT result1;
/* callback flags */
volatile bool bCallbackFlag = false;
volatile bool bCallbackTestEndFlag = false;

/* test buffers pointers */
volatile uint8_t *pSubmit[TEST_NUM];
volatile uint8_t *pGet[TEST_NUM*2];
volatile uint8_t GetIndex;
volatile void *pBuf;

ADI_EPPI_DMA_TRANSFER_SIZE  eDMASize;
int32_t						xMod;
int32_t						yMod;

/* test device by passing in function pointer to case case and test parameters */
uint32_t TestDevice(uint32_t DeviceNum, uint32_t (*pTestFunction)(void **, uint32_t), void *pTestArray[], uint32_t NumTests);
uint32_t OpenDevice(uint32_t DeviceNum);
uint32_t ConfigureDevice(void);
void ResetTestParameters(void);

void PPI_Callback(void *pCBParam, uint32_t nEvent, void *pArg);
extern void ConfigSoftSwitches(void);
/* Test case functions */
uint32_t CallbackModeRxBuffer(void *pTestArray[], uint32_t NumTests);

int main(void)
{
 	uint32_t Result = 0u;



	/**
	 * Initialize managed drivers and/or services that have been added to
	 * the project.
	 * @return zero on success
	 */
	adi_initComponents();


	*pREG_SPU0_SECUREP95 = 2;     /* PPI0 */
		*pREG_SPU0_SECUREP107 = 2;    /* PPI0 Channel0 DMA 28 */

//
//	if( Result == 0u)
//	{
//		/* Software Switch Configuration for the ADSP-BF707 EZ-BOARD */
//        ConfigSoftSwitches();
//	}
//    /* Test, callback mode, Receive buffer */
	while(1){
		if(Result == 0u)
    {
    	eDMASize = ADI_EPPI_DMA_TRANSFER_32BIT; // 8 bit Data transfer
    	xMod = 2;
    	yMod = 2;
    	Result = TestDevice(0, &CallbackModeRxBuffer, &PingPong[0], TEST_NUM);
    }

	if (Result == 0)
	{
		printf(" Data Received \n");
	}

	for(int i=0; i<BUFFER_SIZE; i++)
	{
		printf("i=%d Rx=%X : %d\n",i,pTest[i],pTest[i]);

	}
	}
	return 0;
}

/* tests the device via a function pointer to a test case function and its associated test parameters */
uint32_t TestDevice(uint32_t DeviceNum, uint32_t (*pTestFunction)(void **, uint32_t), void *pTestArray[], uint32_t NumTests)
{
	uint32_t Result = 0u;

	/* Reset the test parameters */
	if(Result == 0u)
	{
		/* resets the test parameters to a known state */
		ResetTestParameters();
	}
	/* open the device */
	if(Result == 0u)
	{
		Result = OpenDevice(DeviceNum);
	}
	/* configure the device under test */
	if(Result == 0u)
	{
		Result = ConfigureDevice();
	}
	/* test the device with the test function pointer and its parameters */
	if(Result == 0u)
	{
		Result = pTestFunction(pTestArray, NumTests);
	}

	return Result;
}

uint32_t OpenDevice(uint32_t DeviceNum)
{
	return (uint32_t)adi_eppi_Open(DeviceNum, ADI_EPPI_DIRECTION_RX, &EppiMemory, ADI_EPPI_MEMORY_SIZE, &phPpi); //Receiver code
}

uint32_t ConfigureDevice(void)
{
	uint32_t Result = 0u;

	if(Result == 0u)
	{
    	Result = (uint32_t)adi_eppi_SetITUMode(phPpi, ADI_EPPI_GENERAL_PURPOSE  );
	}

	if(Result == 0u)
	{
    	Result = (uint32_t)adi_eppi_SetFSMode(phPpi, ADI_EPPI_FS_MODE1 );
	}
	if(Result == 0u)
	{
	   	Result = (uint32_t)adi_eppi_SetClkPolarity(phPpi, ADI_EPPI_RISECLK_FALLFS);
	}
	if(Result == 0u)
	{
		Result = (uint32_t)adi_eppi_SetDataLength(phPpi, ADI_EPPI_24BIT);
	}
	if(Result == 0u)
	{
	    Result = (uint32_t)adi_eppi_SetDmaTransferSize(phPpi, ADI_EPPI_DMA_TRANSFER_32BIT);
	}
	if(Result == 0u)
	{
		Result = (uint32_t)adi_eppi_SetInternalClk(phPpi,false); // External clock
	}
	if(Result == 0u)
	{
		Result = (uint32_t)adi_eppi_SetInternalFS(phPpi,false); //External Frame sync
	}
	if(Result == 0u)
	{
			Result = (uint32_t)adi_eppi_SetClockDivide(phPpi, 24);
	}

		/*****************************************/
		/**** Horizontal timing configuration ****/
		/*****************************************/

	if(Result == 0u)
	{
		   Result = (uint32_t)adi_eppi_SetFrameSync1(phPpi, 100, 20, 1);
	}

	if(Result == 0u)
	{
	    	Result = (uint32_t)adi_eppi_SetHorizontalDelay(phPpi, 0);
	}

	if(Result == 0u)
	{
	    	Result = (uint32_t)adi_eppi_SetSamplesPerLine(phPpi, 23);
	}

	if(Result == 0u)
	{
	    	Result = (uint32_t)adi_eppi_SetHorizontalCount(phPpi, 24);
	}


	if(Result == 0u)
	{
		    	Result = (uint32_t)adi_eppi_SetPack(phPpi, true);
	}

	if(Result == 0u)
		{
			    	Result = (uint32_t)adi_eppi_SetSplit(phPpi, false);
		}

	if(Result == 0u)
			{
				    	Result = (uint32_t)adi_eppi_StreamingEnable(phPpi, false);
			}

	if(Result == 0u)
				{
					    	Result = (uint32_t)adi_eppi_RepetiveBufferEnable(phPpi, false);
				}


	return Result;
}

void ResetTestParameters(void)
{
	uint8_t i;
	/* Reset test flags, index, pointers */
	bCallbackFlag = false;
	bCallbackTestEndFlag = false;
	GetIndex = 0;
	pBuf = NULL;

	for(i=0; i < TEST_NUM; i++)
	{
		pSubmit[i] = NULL;
		pGet[i] = NULL;
	}
}

uint32_t CompareSubmitVerusCallbackFrames(void)
{
	int i;
	uint32_t Result = 0u;

	for(i=0; i < TEST_NUM; i++)
	{
		/* pSubmit must equal pGet but not be NULL */
		if((pSubmit[i] != pGet[i]) || pSubmit[i] == NULL || pGet[i] == NULL )
		{
			Result = 1u;
			break;
		}
	}

    return Result;
}

/* Output a 1D buffer in callback mode */
uint32_t CallbackModeRxBuffer(void *pTestArray[], uint32_t NumTests)
{
	uint32_t TestIndex = 0;
	bool bPpiEnable = false;
	uint32_t Result = 0u;

	/* enable callbacks */
    if (Result == 0u)
	{
	    Result = (uint32_t)adi_eppi_RegisterCallback(phPpi, PPI_Callback, NULL);
	}
    /* submit test buffer until last test case */
    while(TestIndex < NumTests)
    {
    	/* send until queue is full */
    	while((Result == 0u) && (TestIndex < NumTests))
    	{
    		Result = (uint32_t)adi_eppi_SubmitBuffer(phPpi, PingPong[TestIndex++], BUFFER_SIZE*4);




    		/* store buffer submitted */
    		if(Result == 0u)
    		{
    			pSubmit[TestIndex-1] =  PingPong[TestIndex-1];
    		}
    	}
    	if(Result == (uint32_t)ADI_EPPI_QUEUE_FULL)
        {
            TestIndex--;
            Result = ADI_EPPI_SUCCESS;
        }
		if(bPpiEnable == false)
		{
			*pREG_DMA28_ADDRSTART=&PingPong;
			 *pREG_DMA28_CFG = 0x20;
			 *pREG_DMA28_XCNT=0X10;
			 *pREG_DMA28_XMOD=0x20;
//			  *pREG_DMA28_CFG |= 0x1;//Start DMA
			bPpiEnable = true;
			Result = (uint32_t)adi_eppi_Enable(phPpi, true);

//
//			for(int i=0; i<BUFFER_SIZE; i++)
//			{
//				printf("Rx=%X\n",pTest[i]);
//
//			}

			if (Result != 0u)
			{

				return Result;
			}
		}
    }




    while(bCallbackTestEndFlag == false);
    adi_eppi_Enable((ADI_EPPI_HANDLE)phPpi, false); // Disable EPPI
	return (uint32_t)Result;
}

void PPI_Callback(void *pCBParam, uint32_t nEvent, void *pArg)
{	printf("PPI_Callback");
    switch(nEvent)
    {
        case ADI_EPPI_DMA_BUFFER_PROCESSED:
        	if(GetIndex < TEST_NUM)
        	{printf("PPI_Callback buffer full");
        		pGet[GetIndex++] = (uint8_t *)pArg;
        	}

			/* set callback flag */
        	if(pArg == (uint8_t *)PingPong[TEST_NUM-1])
        	{
        		bCallbackTestEndFlag = true;
        	}
            bCallbackFlag = true;
            break;
        default:
        	/* There is a race condition in updateFrame mode where an update frame */
        	/* may not be submitted in time and the driver (correctly) repeats the */
        	/* previous frame. Since the PPI callbacks will continue in RepetiveBufferEnable */
        	/* eventually the pArg == (uint8_t *)PingPong[TEST_NUM-1] will become true. */
        	/* But the event will no longer be ADI_EPPI_DMA_BUFFER_PROCESSED since the submitted */
        	/* frames have all been processed. This is OK and to be expected (race condition) */
        	if(GetIndex < TEST_NUM*2)
        	{printf("PPI_Callback");
        		pGet[GetIndex++] = (uint8_t *)pArg;
        	}
        	if(pArg == (uint8_t *)PingPong[TEST_NUM-1])
        	{
        		bCallbackTestEndFlag = true;
        	}

            break;
    }
}