SPORT Transmit Interrupt Handler Issue - ADSP-21489

Hi All,

Code written to config Channel A and B of SPORT0 as Transmitters with interrupts enable and Chanel A of SPORT1 as Receiver with interrupt enable. PCG is used to generate clocks to SPORT0 and SPORT1 (external clock to SPORTs)

Transmit Interrupt handler used to load data in Transmit Buffers, pTXSP0A and pTXSP0B. After data loaded into these buffers expected that the program control comes back to Main() Function then stays in Main() till the loaded data into pTXSP0A and pTXSP0B is tranferred WHEREAS the program enters into the function : EX_DISPATCHED_HANDLER_NESTED(_adi_osal_stdWrapper, iid,  index, arg) then wait in this function till data loaded into pTXSP0A and pTXSP0B is transmitted then enters into SPORT0 Hndler function to load next data bytes. 

while above is happening if any data i received in SPORT1 then program control enters into SPORT1 Handler then goes to SPORT0 Handler ... but not entering into Main().

Notice that if program calls :  Status = adi_int_InstallHandler(ADI_CID_P3I,(ADI_INT_HANDLER_PTR ) SPORT1Handler,0,true); is before Status = (int) adi_int_InstallHandler(ADI_CID_P6I,(ADI_INT_HANDLER_PTR ) SPORT0Handler,0,true); then code works as above.

If the program calls : Status = (int) adi_int_InstallHandler(ADI_CID_P6I,(ADI_INT_HANDLER_PTR ) SPORT0Handler,0,true); is before Status = adi_int_InstallHandler(ADI_CID_P3I,(ADI_INT_HANDLER_PTR ) SPORT1Handler,0,true); then the SPORT1 Handler do not receive data. 

Code is attached herewith. Please help to resolve the issue/bug. 

/*****************************************************************************
 * SPORT_Tx_INTR.c
 *****************************************************************************/

#include <sys/platform.h>
#include "adi_initialize.h"
#include "SPORT_Tx_INTR.h"
#include "def21489.h"
#include "sru.h"
#include<stdio.h>
#include <services/int/adi_int.h>
#include<string.h>

#define SPORT_UART_BAUDRATE  9600 	// Defining the required UART Baud Rate
#define USE_SELF_NESTING

#define PCLK 200000000		// ADSP-21489 PCLK=200MHz, i.e input clock to Precision Clock Generator-PCG when CPU runs at 400MHz
#define	TxCLKDIV  PCLK/SPORT_UART_BAUDRATE		// Divisor factor of PCG-Channel-A to generate clocks to SPORTs Tx-Channels.
#define RxCLKDIV  PCLK/(SPORT_UART_BAUDRATE*3)	// Divisor factor of PCG-Channel-A to generate clocks to SPORTs Rx-Channels.

void Init_SPORT(void); 	//Initializes all SPORT channels as UART channels.
void InitPCG(void);		//Initializes Precision Clock Generator Module to generate baud rate clocks to SPORT Channels
void ConfigSRU(void);	//Initializes DAI Pins of ADSP-21489 as UART-Tx and Rx.

static void SPORT0Handler(uint32_t iid, void* handlerArg);
static void SPORT1Handler(void);

unsigned char SPORT_RxProcess(unsigned int temp);
unsigned short int SPORT_TxProcess(unsigned char tx1);

char strA[]="Hello";
int SPORT0ATxBuffLength;
char strB[]="Ananth";
int SPORT0BTxBuffLength;

int SPORT0A_TxByte=0xAB;
volatile int SPORT0ATxCompleted=0;

int SPORT0B_TxByte;
volatile int SPORT0BTxCompleted=0;

int SPORT1A_RxByte;
volatile int SPORT1A_RxByte_Available=0;

void main(void)
{
	unsigned char temp, TxData, RxData=0xAB; // to receive data from SPORT1 through UART Config
	volatile int dumm1=10, dumm2=20, dumm3;
	int Status;

	SPORT0ATxBuffLength=strlen(strA);
	SPORT0BTxBuffLength=strlen(strB);

	adi_initComponents();
	ConfigSRU();
	Init_SPORT();

	Status = adi_int_InstallHandler(ADI_CID_P3I,(ADI_INT_HANDLER_PTR ) SPORT1Handler,0,true);
	printf("S1 : %d \n", Status);

	Status = (int) adi_int_InstallHandler(ADI_CID_P6I,(ADI_INT_HANDLER_PTR ) SPORT0Handler,0,true);
	printf("S0 : %d \n", Status);

	while(1)
	{
		if(SPORT1A_RxByte_Available==1)
		{
			SPORT1A_RxByte_Available=0;
			SPORT0ATxBuffLength=strlen(strA);
			SPORT0BTxBuffLength=strlen(strB);

			RxData = SPORT_RxProcess(SPORT1A_RxByte);

			SPORT0ATxBuffLength=strlen(strA);
			SPORT0BTxBuffLength=strlen(strB);
			SPORT0ATxCompleted=0;
			SPORT0BTxCompleted=0;
			adi_int_EnableInt(ADI_CID_P6I, true);
		}

		dumm3=dumm1+dumm2;
	}

}


static void SPORT0Handler(uint32_t iid, void* handlerArg)
{
	volatile unsigned int status0, err;
	status0=*pSPCTL0;

	if(SPORT0ATxCompleted==0)
	{
		if((status0 & 0xC0000000) == 0x00000000)	// Check DXS_A 2-Bit-Field status for Channel-A Data Buffer Status
		{
			*pTXSP0A = SPORT_TxProcess((unsigned char)strA[SPORT0ATxBuffLength]); // Read/Write data from/to Receive/Transmit Data Buffer : RXSPxB or TXSPxB
			SPORT0ATxBuffLength--;
			if(SPORT0ATxBuffLength<0)
			//SPORT0ATxBuffLength=strlen(strA);
				SPORT0ATxCompleted=1;
		}
	}

	if(SPORT0BTxCompleted==0)
	{
		if((status0 & 0x180000000) == 0x00000000)	// Check DXS_B 2-Bit-Field status for Channel-A Data Buffer Status
		{
			//*pTXSP0B = SPORT0B_TxByte;	/* Read/Write data from/to Receive/Transmit Data Buffer : RXSPxB or TXSPxB*/

			SPORT0BTxBuffLength--;
			*pTXSP0B = SPORT_TxProcess((unsigned char)strB[SPORT0BTxBuffLength]); // Read/Write data from/to Receive/Transmit Data Buffer : RXSPxB or TXSPxB
			if(SPORT0BTxBuffLength==0)
			//SPORT0BTxBuffLength=strlen(strB);
				SPORT0BTxCompleted=1;
		}
	}

	if ((SPORT0ATxCompleted==1) && (SPORT0BTxCompleted==1))
	{
		//adi_int_EnableInt(ADI_CID_P6I, false);	// Disable SPORT0 interrupts which is high priority interrupt which blocks the SPORT2 interrupts
	}
}

static void SPORT1Handler(void)
{
	volatile unsigned int status1;
	status1=*pSPCTL1;

	if((status1 & 0xC0000000) != 0x00000000)	// Check DXS_A 2-Bit-Field status for Channel-A Data Buffer Status
	{
		SPORT1A_RxByte = *pRXSP1A; // Read/Write data from/to Receive/Transmit Data Buffer : RXSPxB or TXSPxB
		SPORT1A_RxByte_Available=1;
	}

	if(status1 & 0x180000000 != 0x000000000)	// Check DXS_B 2-Bit-Field status for Channel-A Data Buffer Status
	{
		//SPORT3B_RxByte = *pRXSP3B; // Read/Write data from/to Receive/Transmit Data Buffer : RXSPxB or TXSPxB
	}
}

unsigned char SPORT_RxProcess(unsigned int temp)
{
	unsigned char ch;
	unsigned int value=0;

	value+= ((temp>>23) &(1<<0));
	value+= ((temp>>19) &(1<<1));
	value+= ((temp>>15) &(1<<2));
	value+= ((temp>>11) &(1<<3));
	value+= ((temp>>7) &(1<<4));
	value+= ((temp>>3) &(1<<5));
	value+= ((temp<<1) &(1<<6));
	value+= ((temp<<5) &(1<<7));
	ch=(unsigned char)value;
	return ch;
}

unsigned short int SPORT_TxProcess(unsigned char tx1)
{
	unsigned short int tx=0x00;
	unsigned char temp=0;
	unsigned short int Ms1= 0x03FC;
	unsigned short int Ms2= 0x0401;
	tx = tx1;
	tx= tx<<2;
	tx = tx & Ms1;
	tx = tx | Ms2;
	return tx;
}


/*
 * This function initializes the SRU for below actions:
 * 1. Configure DAI-Pin-2 as SPORT0-UART Transmit Pin.
 * 2. Configure DAI-Pin-4 as SPORT1-UART Receive Pin.
 * 3. Call Precision Clock Generator Init Function to generate external clocks to SPORT-0 and 1.
 * 4. Configures the SPORT-0 and 1 for receiving external clock that is from PCG.
 * 5. Configure the DAI-Pin-4 as SPORT1 to received External Frame Sync signal from DAI-Pin-4 which is also act as UART/SPORT Data Pin
 */
void ConfigSRU(void)
{

	InitPCG();	// Precision Clock Generator generates Clocks to for Tx and Rx of SPORT0-7.

	/******* UART-1 Config:SPORT0-A with DAI_PB-2::EZ-BoardPin:15 as Tx & SPORT1-A with DAI_PB-1::EZ-BoardPin:13 as Rx **********/

		/* SPORT-0 Pins Config to transmit Data */
		SRU(HIGH,PBEN02_I);
		SRU(SPORT0_DA_O,DAI_PB02_I);

		/* SPORT-1 Pins Config to Receive Data*/
		SRU(LOW,PBEN01_I);
		SRU(DAI_PB01_O,SPORT1_DA_I);

		/* SPORT-0,1 and PCG Pins Config */

		InitPCG();

		SRU(PCG_CLKA_O,SPORT0_CLK_I);       //SPORT-0_CLK_I is same as PCG_CLKA_O.
		SRU(PCG_CLKB_O,SPORT1_CLK_I);       //SPORT-1_CLK_I is same as SPORT1_CLK_O.
		SRU(DAI_PB01_O,SPORT1_FS_I);    	//SPORT-1 Frame Sync is connected to DAI-Pin-4.

}

/*
 * This function initializes the SPORT0 Channel A to emulate the UART Transmit and SPORT1 Channel A to emulate the UART Receive.
 * The code is developed using the Analog Devices Application Notes: EE-191, EE-391, EE-1245
 */
void Init_SPORT()
{

	//Clearing the Buffers of SPORTs.
	*pSPCTL0 = 0;
	*pSPCTL1 = 0;

	//FSDIV needs to fix for SPORTs:: Set FSDIV as 32 or above for 29-Bits Receive and set 12 or above for 11-Bit transfer
	*pDIV0 = 0x000B0000|(1<<1);	/*Divisor register for FS and CLK for SPORT-0*/
	*pDIV1 = 0x001B0000|(1<<1);	/*Divisor register for FS and CLK for SPORT-1*/

	//UART-1 config uses SPORT1A and 2A.
	*pSPERRCTL0=0x00;		//Disable Error detection
	*pSPERRCTL1=0x00;		//Disable Error detection

	*pSPCTL0=SPEN_A | SPEN_B | SLEN11 | CKRE |  FSR | IFS | LFS | LAFS  | SPTRAN | LSBF; //Sets SPORT0-A&B as UART1-Tx & UART4-Tx.
	*pSPCTL1=LAFS | LFS | FSR | SLEN29 | SPEN_A;	//Sets SPORT1-A as UART1-Rx.
}

void InitPCG(void)
{
    unsigned char n;

    /*Disable PCG = Clearing the PCG Enable Bits in order to Config PCG */
    *pPCG_CTLA0 = 0x00;
    *pPCG_CTLB0 = 0x00;

    // Wait minimum 16 cycles after disable the PCG : to give enough time to stabilize PCG.
	for (n=0; n<100; n++)
    {
        asm("NOP;");
    }

    /*PCG CLK generation */
	*pPCG_SYNC1 = (*pPCG_SYNC1) | 0x00000004;	// Configuring the Channel-A input clock as PCLK=200MHz.
	*pPCG_SYNC1 = (*pPCG_SYNC1) | 0x00040000;	// Configuring the Channel-B input clock as PCLK=200MHz.

    *pPCG_CTLA1 = TxCLKDIV & CLKADIV;	// Configuring the Channel-A to generate Clock output suitable to UART-Transmit
    *pPCG_CTLB1 = RxCLKDIV & CLKBDIV;	// Configuring the Channel-B to generate Clock output suitable to UART-Receive = 03 times of Transmit Buad Rate

    /*Enable PCG = Setting the PCG Enable Bits in order to Config PCG */
    *pPCG_CTLA0 = ENCLKA;
    *pPCG_CTLB0 = ENCLKB;

}



Subject/Topic name is added with ADSP-21489
[edited by: Muni at 4:49 AM (GMT 0) on 1 May 2019]
Parents Reply Children
No Data