⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 afe.c

📁 DSP 5409 plc应用程序,调试通过,是用在电力线通讯上的演示程序.
💻 C
📖 第 1 页 / 共 4 页
字号:
		temp = 	(i16)((pSrc++)->re);		// First transmit value
		*pDest++ = temp;
		temp = 	(i16)((pSrc++)->re);		// Second transmit value
		*pDest++ = (AFEctrl1 << 8) + ((temp>>8)&0x00ff);
		*pDest++ = ((temp&0x00ff) << 8) + AFEctrl2;
	}

	return(pDest);
}
#endif


//==========================================================================================
// Function:		FillAFETxBuffI16()
//
// Description: 	This function copies data from an integer source buffer to a destination
//					buffer while modifying the destination data format to be compatible
//					with the AFE (Analog Front End).
//
// Revision History:
//==========================================================================================
TXDATA* FillAFETxBuffI16 (TXDATA* pDest, i16* pSrc, u16 uCnt)
{
#if COMPILE_MODE == MEX_COMPILE
	memcpy( pDest, pSrc, uCnt*sizeof(i16) ); 
	pDest += uCnt;
	return(pDest);

#else
	u16		i;	// Loop counter
	i16		temp;

	WaitForTxBufferFree(pDest, uCnt);		// Wait until DMA is not using destination memory segment

	// 	Transmit three 16-bit values
	// Fill Temp Transmit buffer with real data interleaved between control words
  	for(i = 0; i<(uCnt/2); i++ )
	{
		temp = 	(i16)*pSrc++;		// First transmit value
		*pDest++ = temp;
		temp = 	(i16)*pSrc++;		// Second transmit value
		*pDest++ = (AFEctrl1 << 8) + ((temp>>8)&0x00ff);
		*pDest++ = ((temp&0x00ff) << 8) + AFEctrl2;
	}

	return(pDest);
#endif
}


//==========================================================================================
// Function:		WaitForTxBufferFree()
//
// Description: 	This function polls the DMA source address point until the required 
//					section in the Tx buffer is available.
//
// Revision History:
//==========================================================================================
void WaitForTxBufferFree(TXDATA* uStart, u16 uCnt) 
{
	TXDATA*		uSrc;
	TXDATA*		uFirstSrc;
	TXDATA*		uPrevSrc;
	u16		uStallCnt= 0;

	uSrc = ReadTxDMAPointer();								// Read DMA source pointer in TxBuffer
	DebugDelay();	// Flush C54x if in debug mode.
	DebugDelay();	// Flush C54x if in debug mode.
	uFirstSrc = uSrc;										// Take a snapshot of first value seen

	while (  (uSrc >= uStart) 								// Wait until we are out of the needed segment
		  && (uSrc < (uStart + (uCnt*AFE_SIZE))) )
	{	
		uPrevSrc = uSrc;									// Save the previous DMA pointer value
		uSrc = ReadTxDMAPointer();							// Read DMA source pointer in TxBuffer
		
		//  Look for stalled pointer 
		if (uSrc == uPrevSrc) 								
		{
			DelayNus(1);									
			uStallCnt++;
			if (uStallCnt>1000)
			{
				DebugDelay();	// Flush C54x if in debug mode.
				break;			// Bail out if DMA pointer is not moving for 1000 consecutive readings
			}
		}
		else
		{
			uStallCnt = 0;		// Reset consecutive stalled counter
		}
		
		//  Look for roll-over 
		if (uSrc < uFirstSrc) 								 
		{
			DebugDelay();		// Flush C54x if in debug mode.
			break;				// Bail out if rollover seen, else we might wait here forever.
		}

		FlashStateMachine( );   // execute current state of flash management state machine
		DebugDelay();			// Flush C54x if in debug mode.
	}

	DebugDelay();				// Flush C54x if in debug mode.
 	return;
 }


//==========================================================================================
// Function:		WaitForRange()
//
// Description: 	This function polls the DMA source address point is inside the 
//					selected range.
//
// Revision History:
//==========================================================================================
void WaitForRange(TXDATA* uStart, u16 uCnt) 
{
	TXDATA*		uSrc;
	TXDATA*		uFirstSrc;

	uSrc = ReadTxDMAPointer();								// Read DMA source pointer in TxBuffer
	uFirstSrc = uSrc;										// Take a snapshot of first value seen

	while (  (uSrc < uStart) 
	 	   ||(uSrc >= (uStart + (uCnt*AFE_SIZE))) )			// Wait until we are inside the needed segment
	{		
		DebugDelay();				// Flush C54x if in debug mode.
		//...
		//    We could do something useful here, like polling the host interface
		//...

		DebugDelay();				// Flush C54x if in debug mode.
	
		uSrc = ReadTxDMAPointer();	// Read DMA source pointer in TxBuffer
		if (uSrc < uFirstSrc) 		//  Look for roll-over 
		{
			DebugDelay();			// Flush C54x if in debug mode.
			//break;			   	// Bail out if rollover seen, else we might wait here forever.
		}

		FlashStateMachine( );  		// execute current state of flash management state machine
		DebugDelay();				// Flush C54x if in debug mode.
	}

	DebugDelay();				// Flush C54x if in debug mode.
	return;
 }


//==========================================================================================
// Function:		ReadRxDMAPointer()
//
// Description: 	This function read the DMA destination address of the receive buffer.
//
// Revision History:
//==========================================================================================
i16* ReadRxDMAPointer(void)
{	
#if COMPILE_MODE == MEX_COMPILE
	if( rxDMApointer >= recSignalArray + RX_CIRC_BUFFER_LEN )
		rxDMApointer = recSignalArray;
	return rxDMApointer;

#else 	//COMPILE_MODE == DSP_COMPILE
	i16*	pRxDest;
	u16		uRxCtr;

	uRxCtr = DMA_SUBREG_READ(DMA_CHANNEL4, DMCTR_SUBADDR);
	RPTNOP(4);
	
	pRxDest = (i16*)DMA_SUBREG_READ(DMA_CHANNEL4, DMDST_SUBADDR);

	RPTNOP(4);
	if (uRxCtr != RX_CIRC_BUFFER_LEN)
	{
		DebugDelay();				// Flush C54x if in debug mode.
		PostErrorCode(0xBAD8, "ReadRxDMAPointer", "AFE.c", "DMA Counter corrupted");
		#if SAVETRACE == TRUE
			SaveTraceData(0xBAD8);			//!!!DEBUG  Put a marker in the trace buffer
			SaveTraceData((u16)pRxDest); 	//!!!DEBUG  Put a marker in the trace buffer
			SaveTraceData(uRxCtr);			//!!!DEBUG  Put a marker in the trace buffer
		#endif
		DebugDelay();				// Flush C54x if in debug mode.
		DebugDelay();				// Flush C54x if in debug mode.
	}

	return (pRxDest);
#endif
}


//==========================================================================================
// Function:		ReadTxDMAPointer()
//
// Description: 	This function read the DMA source address of the transmit buffer.
//
// Revision History:
//==========================================================================================
TXDATA* ReadTxDMAPointer(void)
{
	TXDATA* temp;
	temp = (TXDATA*)DMA_SUBREG_READ(DMA_CHANNEL5, DMSRC_SUBADDR);

	return(temp);
}


//==========================================================================================
// Function:		WaitForRxBufferFree()
//
// Description: 	This function polls the DMA destination address point until the required 
//					section in the receive buffer is available.
//
// Revision History:
//==========================================================================================
void WaitForRxBufferFree(i16* uStart, u16 uCnt) 
{
	i16*	uDest;
	i16*	uFirstDest;

	SetXF();					// Turn on XF flag for debug
	uDest = ReadRxDMAPointer();	// Read DMA destination pointer in RxBuffer
	uFirstDest = uDest;			// Take a snapshot of first value seen

	while ((uDest >= uStart) && (uDest < (uStart + uCnt)) )	// Wait until we are out of the needed segment
	{	
		uDest = ReadRxDMAPointer();		// Read DMA destination pointer in RxBuffer
		if (uDest < uFirstDest) 		//  Look for roll-over 
		{
			DebugDelay();	// Flush C54x if in debug mode.
			break;			// Bail out if rollover seen, else we might wait here forever.
		}

		FlashStateMachine( );   // execute current state of flash management state machine
		DebugDelay();	   		// Flush C54x if in debug mode.
	}

	ClearXF();		// Turn off XF flag for debug

	if (uCnt > 0x300)		// Put this here as a trigger point for errors
	{
		DebugDelay();		// Flush C54x if in debug mode.
		DebugDelay();		// Flush C54x if in debug mode.
	}

	DebugDelay();				// Flush C54x if in debug mode.
 	return;
 }



//==========================================================================================
// Function:		JamDMAReloadRegs()
//
// Description: 	This function jams the DMA Global Reload registers so that when the 
//					present frame finishes it will jump to next desired location.
//
// Revision History:
//==========================================================================================
void JamDMAReloadRegs(TXDATA* uStart, u16 uCnt)
{
#if COMPILE_MODE == DSP_COMPILE
	// If we are almost at the end of the previous block, wait for it to roll over
	//  before we jam the global registers.  We don't want the DMA to expire while
	//  we're in the middle of changing them.  Mainly useful when switching from 
	//	idle to preamble.
	while( DMA_SUBREG_READ(DMA_CHANNEL5, DMCTR_SUBADDR) <= 1 )		
	{
		DebugDelay();				// Flush C54x if in debug mode.
	}

	DMA_SUBREG_WRITE(DMA_CHANNEL5, DMGSA_SUBADDR, (u16)uStart);	//  DMA Global Source Address
	DMA_SUBREG_WRITE(DMA_CHANNEL5, DMGCR_SUBADDR, (uCnt*AFE_SIZE)-1);	//  DMA Global Element Count

	// Wait until the last frame has started being transmitted
	WaitForRange(uStart, uCnt);
	DebugDelay();				// Flush C54x if in debug mode.
#endif

	return;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -