Post Go back to editing

ADSP-21569 SPORT Enbale not possible

Hello,

I would like to set up 4 TDM interfaces with SPORTs (4A,4B,5A,5B).
I just tried to stay close to the provied example for my EZKIT SOM Board.

Sadly my code gets stuck in the adi_sport_enable() function. Do I have something wrong?

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

Copyright(c) 2014-2016 Analog Devices, Inc. All Rights Reserved.

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.

*********************************************************************************/
/*!
 * @file      adc_dac_playback.c
 * @brief     This example demonstrates the submission of DMA driven audio buffers
 *            to both the ADC and DAC.
 * @version:  $Revision: 31665 $
 * @date:     $Date: 2017-12-12 02:26:29 -0500 (Tue, 12 Dec 2017) $
 *
 * @details
 *            This is the primary source file for ADC / DAC play-back example that shows
 *            how to submit DMA driven audio buffers to both the ADC and DAC .
 *
 */

/*=============  I N C L U D E S   =============*/

#include <sys/platform.h>
/* SPU Manager includes */
#include <services/spu/adi_spu.h>
#include <services/gpio/adi_gpio.h>
#include <adi_adau1979.h>
#include <adi_adau1962a.h>
#include <cdef21569.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "adc_dac_playback.h"
#include "adi_initialize.h"
#include "Platform.h"
#include <drivers/sport/adi_sport_2156x.h>
#include <C:\Analog Devices\CrossCore Embedded Studio 2.10.1\SHARC\lib\src\drivers\Source\sport\adi_sport_def_2156x.h>

#include <SRU.h>

/* ************************************************************************** */
/* Macro Definition Section                                                   */
/* ************************************************************************** */

#define ADC_TWI_PORT_NUM			(2)
#define MIC_ADC_TWI_PORT_NUM		(2)
#define DAC_TWI_PORT_NUM			(2)

#define SPORT_DEVICE_4A 			4u			/* SPORT device number */
#define SPORT_DEVICE_4B 			4u			/* SPORT device number */
#define SPORT_DEVICE_5A 			5u			/* SPORT device number */
#define SPORT_DEVICE_5B 			5u			/* SPORT device number */
#define DMA_NUM_DESC 				2u

#define ADAU1962A_MCLK_IN_HZ		(24576000)
#define AUDIO_SAMPLING_RATE_IN_HZ	(48000)

#define PDMA_CFG_COMMON_SETTING				(ENUM_DMA_CFG_PDAT_NOTFWD | ENUM_DMA_CFG_ADDR1D | ENUM_DMA_CFG_COPY | ENUM_DMA_CFG_TOV_DIS | ENUM_DMA_CFG_NO_TRIG | ENUM_DMA_CFG_XCNT_INT | ENUM_DMA_CFG_FETCH01 | ENUM_DMA_CFG_NO_TRGWAIT | ENUM_DMA_CFG_DSCLIST | ENUM_DMA_CFG_MSIZE04 | ENUM_DMA_CFG_PSIZE04 | ENUM_DMA_CFG_LD_STARTADDR | ENUM_DMA_CFG_NO_SYNC | ENUM_DMA_CFG_EN)
#define PDMA_CFG_TX_Setting					(PDMA_CFG_COMMON_SETTING | ENUM_DMA_CFG_READ)
#define PDMA_CFG_RX_Setting					(PDMA_CFG_COMMON_SETTING | ENUM_DMA_CFG_WRITE)


/* Prepares descriptors for SPORT DMA */
void PrepareDescriptors (void);

/* Memory required for SPORT */
static uint8_t SPORTMemory4A[ADI_SPORT_MEMORY_SIZE];
static uint8_t SPORTMemory4B[ADI_SPORT_MEMORY_SIZE];
static uint8_t SPORTMemory5A[ADI_SPORT_MEMORY_SIZE];
static uint8_t SPORTMemory5B[ADI_SPORT_MEMORY_SIZE];

/* SPORT Handle */
static ADI_SPORT_HANDLE hSPORTDev4ATx;//TX
static ADI_SPORT_HANDLE hSPORTDev4BRx;//RX

static ADI_SPORT_HANDLE hSPORTDev5ATx;//TX
static ADI_SPORT_HANDLE hSPORTDev5BRx;//RX

section("awe_fastdmadata")
ADI_PDMA_DESC_LIST iOUT_LIST_1_SP4A;

section("awe_fastdmadata")
ADI_PDMA_DESC_LIST iOUT_LIST_2_SP4A ;

section("awe_fastdmadata")
ADI_PDMA_DESC_LIST iIN_LIST_1_SP4B ;

section("awe_fastdmadata")
ADI_PDMA_DESC_LIST iIN_LIST_2_SP4B ;

section("awe_fastdmadata")
ADI_PDMA_DESC_LIST iOUT_LIST_1_SP5A;

section("awe_fastdmadata")
ADI_PDMA_DESC_LIST iOUT_LIST_2_SP5A ;

section("awe_fastdmadata")
ADI_PDMA_DESC_LIST iIN_LIST_1_SP5B ;

section("awe_fastdmadata")
ADI_PDMA_DESC_LIST iIN_LIST_2_SP5B ;

#pragma align 4
int32_t section("awe_fastdmadata") InBuf[INPUT_FRAME_SIZE*2] = { 0 };

#pragma align 4
int32_t section("awe_fastdmadata") OutBuf[OUTPUT_FRAME_SIZE*2] = { 0 };





void PrepareDescriptors (void)
{
	//--------SPORT4------------------
	iOUT_LIST_1_SP4A.pStartAddr	= (int *)&OutBuf[0];
	iOUT_LIST_1_SP4A.Config		= PDMA_CFG_TX_Setting ;
	iOUT_LIST_1_SP4A.XCount		= OUTPUT_FRAME_SIZE/2;
	iOUT_LIST_1_SP4A.XModify	= 4;
	iOUT_LIST_1_SP4A.YCount		= 0;
	iOUT_LIST_1_SP4A.YModify	= 0;
	iOUT_LIST_1_SP4A.pNxtDscp	= &iOUT_LIST_2_SP4A;

	iOUT_LIST_2_SP4A.pStartAddr	= (int *)&OutBuf[OUTPUT_FRAME_SIZE];
	iOUT_LIST_2_SP4A.Config		= PDMA_CFG_TX_Setting ;
	iOUT_LIST_2_SP4A.XCount		= OUTPUT_FRAME_SIZE/2;
	iOUT_LIST_2_SP4A.XModify	= 4;
	iOUT_LIST_2_SP4A.YCount		= 0;
	iOUT_LIST_2_SP4A.YModify	= 0;
	iOUT_LIST_2_SP4A.pNxtDscp	= &iOUT_LIST_1_SP4A;

	iIN_LIST_1_SP4B.pStartAddr	=(int *)&InBuf[0];
	iIN_LIST_1_SP4B.Config		= PDMA_CFG_RX_Setting ;
	iIN_LIST_1_SP4B.XCount		= INPUT_FRAME_SIZE/2;
	iIN_LIST_1_SP4B.XModify		= 4;
	iIN_LIST_1_SP4B.YCount		= 0;
	iIN_LIST_1_SP4B.YModify		= 0;
	iIN_LIST_1_SP4B.pNxtDscp	= &iIN_LIST_2_SP4B;

	iIN_LIST_2_SP4B.pStartAddr	=(int *)&InBuf[INPUT_FRAME_SIZE];
	iIN_LIST_2_SP4B.Config		= PDMA_CFG_RX_Setting;
	iIN_LIST_2_SP4B.XCount		= INPUT_FRAME_SIZE/2;
	iIN_LIST_2_SP4B.XModify		= 4;
	iIN_LIST_2_SP4B.YCount		= 0;
	iIN_LIST_2_SP4B.YModify		= 0;
	iIN_LIST_2_SP4B.pNxtDscp	= &iIN_LIST_1_SP4B;
	//---------SPORT5------------------------------------------------------------------------
	iOUT_LIST_1_SP5A.pStartAddr	= (int *)&OutBuf[32*4];
	iOUT_LIST_1_SP5A.Config		= PDMA_CFG_TX_Setting ;
	iOUT_LIST_1_SP5A.XCount		= OUTPUT_FRAME_SIZE/2;
	iOUT_LIST_1_SP5A.XModify	= 4;
	iOUT_LIST_1_SP5A.YCount		= 0;
	iOUT_LIST_1_SP5A.YModify	= 0;
	iOUT_LIST_1_SP5A.pNxtDscp	= &iOUT_LIST_2_SP5A;

	iOUT_LIST_2_SP5A.pStartAddr	= (int *)&OutBuf[OUTPUT_FRAME_SIZE+(32*4)];
	iOUT_LIST_2_SP5A.Config		= PDMA_CFG_TX_Setting ;
	iOUT_LIST_2_SP5A.XCount		= OUTPUT_FRAME_SIZE/2;
	iOUT_LIST_2_SP5A.XModify	= 4;
	iOUT_LIST_2_SP5A.YCount		= 0;
	iOUT_LIST_2_SP5A.YModify	= 0;
	iOUT_LIST_2_SP5A.pNxtDscp	= &iOUT_LIST_1_SP5A;

	iIN_LIST_1_SP5B.pStartAddr	=(int *)&InBuf[32*4];
	iIN_LIST_1_SP5B.Config		= PDMA_CFG_RX_Setting ;
	iIN_LIST_1_SP5B.XCount		= INPUT_FRAME_SIZE/2;
	iIN_LIST_1_SP5B.XModify		= 4;
	iIN_LIST_1_SP5B.YCount		= 0;
	iIN_LIST_1_SP5B.YModify		= 0;
	iIN_LIST_1_SP5B.pNxtDscp	= &iIN_LIST_2_SP5B;

	iIN_LIST_2_SP5B.pStartAddr	=(int *)&InBuf[INPUT_FRAME_SIZE+(32*4)];
	iIN_LIST_2_SP5B.Config		= PDMA_CFG_RX_Setting;
	iIN_LIST_2_SP5B.XCount		= INPUT_FRAME_SIZE/2;
	iIN_LIST_2_SP5B.XModify		= 4;
	iIN_LIST_2_SP5B.YCount		= 0;
	iIN_LIST_2_SP5B.YModify		= 0;
	iIN_LIST_2_SP5B.pNxtDscp	= &iIN_LIST_1_SP5B;

}

int Sport_Init(void)
{
    /* SPORT return code */
    ADI_SPORT_RESULT    eResult;

	/* Open the SPORT Device 4A (Current Out to I/O card)*/
	eResult = adi_sport_Open(SPORT_DEVICE_4A,ADI_HALF_SPORT_A,ADI_SPORT_DIR_TX, ADI_SPORT_MC_MODE, SPORTMemory4A,ADI_SPORT_MEMORY_SIZE,&hSPORTDev4ATx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	/* Open the SPORT Device 4B (Signal in from I/O card)*/
	eResult = adi_sport_Open(SPORT_DEVICE_4B,ADI_HALF_SPORT_B,ADI_SPORT_DIR_RX, ADI_SPORT_MC_MODE, SPORTMemory4B,ADI_SPORT_MEMORY_SIZE,&hSPORTDev4BRx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

/* Open the SPORT Device 5A (Signal Out to Amp)*/
	eResult = adi_sport_Open(SPORT_DEVICE_5A,ADI_HALF_SPORT_A,ADI_SPORT_DIR_TX, ADI_SPORT_MC_MODE, SPORTMemory5A,ADI_SPORT_MEMORY_SIZE,&hSPORTDev5ATx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	/* Open the SPORT Device 5B (Current in from Amp)*/
	eResult = adi_sport_Open(SPORT_DEVICE_5B,ADI_HALF_SPORT_B,ADI_SPORT_DIR_RX, ADI_SPORT_MC_MODE, SPORTMemory5B,ADI_SPORT_MEMORY_SIZE,&hSPORTDev5BRx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	//-----------------------------------------------------------------------------------------------------
	/* Configure the data,clock,frame sync and MCTL of SPORT Device 4A (Current Out to I/O card)*/
	eResult = adi_sport_ConfigData(hSPORTDev4ATx,ADI_SPORT_DTYPE_ZERO_FILL,31,false,false,false);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif


	eResult = adi_sport_ConfigClock(hSPORTDev4ATx,0,false,false,false);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	eResult = adi_sport_ConfigFrameSync(hSPORTDev4ATx,0,true,false,false,true,false,true);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif



	eResult = adi_sport_ConfigMC(hSPORTDev4ATx,0u,3u,0u,false);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	eResult = adi_sport_SelectChannel(hSPORTDev4ATx,0u,3u);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	//------------------------------------------------------------------------------------------------
	/* Configure the data,clock,frame sync and MCTL of SPORT Device 5A  (Signal Out to Amp)*/
	eResult = adi_sport_ConfigData(hSPORTDev5ATx,ADI_SPORT_DTYPE_ZERO_FILL,31,false,false,false);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif


	eResult = adi_sport_ConfigClock(hSPORTDev5ATx,0,false,false,false);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	eResult = adi_sport_ConfigFrameSync(hSPORTDev5ATx,0,true,false,false,true,false,true);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif



	eResult = adi_sport_ConfigMC(hSPORTDev5ATx,0u,3u,0u,false);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	eResult = adi_sport_SelectChannel(hSPORTDev5ATx,0u,3u);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
/*
	ADI_SPORT_DEVICE        *pDevice = (ADI_SPORT_DEVICE *)hSPORTDev4ATx;
	unMCcfg |=  ((uint32_t) nFrameDelay <<BITP_SPORT_MCTL_MFD)       |
            ( (uint32_t)nNumSlots <<BITP_SPORT_MCTL_WSIZE)       |
            ( (uint32_t)nWindowSize <<BITP_SPORT_MCTL_WOFFSET )  |
              ( (uint32_t)ENUM_SPORT_MCTL_EN );
 pDevice->pSportInfo->pSportRegs->SPORT_MCTL = nMCcfg;


	pDevice->pSportInfo->pSportRegs->SPORT_MCTL|= nSPORT_MCTL;

*/

	//-----------------------------------------------------------------------------
	/* Configure the data,clock,frame sync and MCTL of SPORT Device 4B (Signal in from I/O card)*/
	eResult = adi_sport_ConfigData(hSPORTDev4BRx,ADI_SPORT_DTYPE_ZERO_FILL,31,false,false,false); //(hSPORTDev4BRx(ja),ADI_SPORT_DTYPE_ZERO_FILL(vermutlich ja),31(JA),false(JA),true(?),false(vermutlich ja))
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	eResult = adi_sport_ConfigClock(hSPORTDev4BRx,0,false,false,false); //(hSPORTDev4BRx(ja),0(ja),false(ja),false(ja),false(ja))
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	eResult = adi_sport_ConfigFrameSync(hSPORTDev4BRx,0,true,false,false,true,false,true); //(hSPORTDev4BRx(ja),0(ja),true(ja),false(ja),false(?),true(?),false(?),true(ja))
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif


	eResult = adi_sport_ConfigMC(hSPORTDev4BRx,1u,3u,0u,false); //
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	eResult = adi_sport_SelectChannel(hSPORTDev4BRx,0u,3u);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif


	/* Register SPORT Callback function */
	/*eResult = adi_sport_RegisterCallback(hSPORTDev4ATx,SPORTCallback,NULL);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif*/

	/* Register SPORT Callback function */
	eResult = adi_sport_RegisterCallback(hSPORTDev4BRx,SPORTCallback,NULL);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	//-----------------------------------------------------------------------------
	/* Configure the data,clock,frame sync and MCTL of SPORT Device 5B (Signal in from I/O card)*/
	eResult = adi_sport_ConfigData(hSPORTDev5BRx,ADI_SPORT_DTYPE_ZERO_FILL,31,false,false,false); //(hSPORTDev4BRx(ja),ADI_SPORT_DTYPE_ZERO_FILL(vermutlich ja),31(JA),false(JA),true(?),false(vermutlich ja))
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	eResult = adi_sport_ConfigClock(hSPORTDev5BRx,0,false,false,false); //(hSPORTDev4BRx(ja),0(ja),false(ja),false(ja),false(ja))
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	eResult = adi_sport_ConfigFrameSync(hSPORTDev5BRx,0,true,false,false,true,false,true); //(hSPORTDev4BRx(ja),0(ja),true(ja),false(ja),false(?),true(?),false(?),true(ja))
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif


	eResult = adi_sport_ConfigMC(hSPORTDev5BRx,1u,3u,0u,false); //
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	eResult = adi_sport_SelectChannel(hSPORTDev5BRx,0u,3u);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif


	/* Register SPORT Callback function */
	/*eResult = adi_sport_RegisterCallback(hSPORTDev4ATx,SPORTCallback,NULL);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif*/

	//Register SPORT Callback function
	eResult = adi_sport_RegisterCallback(hSPORTDev5BRx,SPORTCallback,NULL);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
//-----------------------------------------SPORT INIT END----------------------------------------------------------------------------

//-----------------------------------------DMA INIT BEGINN----------------------------------------------------------------------------

	/* Prepare descriptors */
	PrepareDescriptors();

	/* Submit the first buffer for 4BRx.  */
	eResult = adi_sport_DMATransfer(hSPORTDev4BRx,&iIN_LIST_1_SP4B,(DMA_NUM_DESC),ADI_PDMA_DESCRIPTOR_LIST, ADI_SPORT_CHANNEL_PRIM);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	/* Submit the first buffer for 5BRx.  */
	eResult = adi_sport_DMATransfer(hSPORTDev5BRx,&iIN_LIST_1_SP5B,(DMA_NUM_DESC),ADI_PDMA_DESCRIPTOR_LIST, ADI_SPORT_CHANNEL_PRIM);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
	/* Submit the first buffer for 4ATx.  */
	eResult = adi_sport_DMATransfer(hSPORTDev4ATx,&iOUT_LIST_1_SP4A,(DMA_NUM_DESC),ADI_PDMA_DESCRIPTOR_LIST, ADI_SPORT_CHANNEL_PRIM);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

/* Submit the first buffer for 5ATx.  */
	eResult = adi_sport_DMATransfer(hSPORTDev5ATx,&iOUT_LIST_1_SP5A,(DMA_NUM_DESC),ADI_PDMA_DESCRIPTOR_LIST, ADI_SPORT_CHANNEL_PRIM);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

//--------------------------------------------------ENABLE SPORT PORTS-------------------------------------------

	/*Enable the Sport Device 4B */
	eResult = adi_sport_Enable(hSPORTDev4BRx,true);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif


	/*Enable the Sport Device 5A */
	eResult = adi_sport_Enable(hSPORTDev5ATx,true);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	/*Enable the Sport Device 4A */
	eResult = adi_sport_Enable(hSPORTDev4ATx,true);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif


	/*Enable the Sport Device 5B */
	eResult = adi_sport_Enable(hSPORTDev5BRx,true);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
	return eResult;

}
AWE_FW_FAST_CODE
void SPORTCallback(void        *pAppHandle,
				uint32_t     nEvent,
				void        *pArg)
{
	/* CASEOF (event type) */
	switch (nEvent)
	{
		/* CASE (buffer processed) */
		case ADI_SPORT_EVENT_RX_BUFFER_PROCESSED:

			if ((int *)pArg == &InBuf[0])
			{
				AWEProcessing(&InBuf[0], &OutBuf[0]);
			}
			else
			{
				AWEProcessing(&InBuf[INPUT_FRAME_SIZE], &OutBuf[OUTPUT_FRAME_SIZE]);
			}

		break;


		default:
		break;
	}
}


int Sport_Stop(void)
{
    /* SPORT return code */
    ADI_SPORT_RESULT    eResult;

    /*Stop the DMA transfer of  Sport Device 4B */
	eResult = adi_sport_StopDMATransfer(hSPORTDev4BRx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
	/*Stop the DMA transfer of  Sport Device 4A */
	eResult = adi_sport_StopDMATransfer(hSPORTDev4ATx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
    /*Stop the DMA transfer of  Sport Device 5B */
	eResult = adi_sport_StopDMATransfer(hSPORTDev5BRx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
	/*Stop the DMA transfer of  Sport Device 5A */
	eResult = adi_sport_StopDMATransfer(hSPORTDev5ATx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
	/*Close Sport Device 4B */
	eResult = adi_sport_Close(hSPORTDev4BRx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
	/*Close Sport Device 4A */
	eResult = adi_sport_Close(hSPORTDev4ATx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif

	/*Close Sport Device 5B */
	eResult = adi_sport_Close(hSPORTDev5BRx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
	/*Close Sport Device 5A */
	eResult = adi_sport_Close(hSPORTDev5ATx);
#ifdef ADI_DEBUG
	printf(eResult);
	printf("\n");
#endif
	return eResult;
}