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

📄 uarts.c

📁 优龙YLP270的串口裸机测试程序
💻 C
📖 第 1 页 / 共 3 页
字号:

	    // Restore an original Uart configuration
		UartRestoreDmaConfiguration (ctxP);

        // Shutdown the UART
        ctxP->shutdownUartFnP (ctxP);
    }

	// Test done
    if (!status) 
      printf (" Success!\r\n");
}


/*
*******************************************************************************
*
* FUNCTION:
*   UartDmaLoopTest
*	
* DESCRIPTION: 
*	In this test the DMA is used to load and empty the receive and transmit FIFOs.
*
* INPUT PARAMETERS:
*   UartContextT * ctxP - Pointer the the UART Device Context Structure.
*   PCHAR param - Pointer to the parameter string in UART's command structure.
*	              It controlls the mode of UART's operation (internal loopback or normal) 
*
* RETURNS:			none.
*
* GLOBAL EFFECTS:	none.
*
* ASSUMPTIONS:		none.
*
* CALLS:
*	
*
* CALLED BY:
*	Menu system
*
* PROTOTYPE:
*   void UartDmaLoopTest (void * arg, CHAR * param)
*
*******************************************************************************
*/
VOID UartDmaLoopTest (PVOID arg, CHAR * param)
{
    UartContextT * ctxP = (UartContextT *)arg;
	INT loopbackMode;
	UINT32  error, status = 0, length;

    DM_ControlWordsDebugPrintPutBit (DM_CW_UART_0, 1);
    DM_ControlWordsDebugPrintPutBit (DM_CW_DMA_0, 1);
    DM_ControlWordsDebugPrintPutBit (DM_CW_XS_INT_CTRL, 1);

    // Check if we are going to test the DM System Uart
    if (UartReturnFromTestIfSystem (ctxP) != 0)
      return;

    // Print a standard message on what UART is about to be tested
    UartStartTesting (ctxP);

    PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 1);
  	// Initialize the device and select loopback
    if (ctxP == NULL)
    {
        // printf (" Error! UART device open failed\r\n");
        status = ERRORCODE(UartType, 
                           ERR_S_UART_INV_DEV,
                           ERR_T_NODEVICE);
        XllpUtilityOutputError(status);
        return;
    }
    else
    {
        // Configure UART to operate either in normal or internal loopback mode
		if (sscanf(param, "%d", &loopbackMode) != 1)
		{
			// Bad number of the parameters have been passed to the function
			// printf (" Error! UART device invalid number of param\r\n");
            status = ERRORCODE(UartType, 
                               ERR_TS_UART_DMA_LOOPBACK,
                               ERR_T_ILLPARAM);
            XllpUtilityOutputError(status);
			return;
		}

        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 2);

		// Setup the test config. structure for the specific Uart.   
		UartSetConfiguration (ctxP);
 
        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 3);

        // Process input parameters and select the DMA config. structure
		// for the specific UART
		UartSetDmaConfiguration (ctxP);
		
		// Set the loopback variable in UART's configuration structure
		ctxP->uartCfgP->loopback = loopbackMode;

		// Enable DMA in UART's configuration structure
		ctxP->uartCfgP->maskInt |= IER_DMAE;

		// Set the receive DMA request triger level to 32 bytes
		ctxP->uartCfgP->maskFIFO |= FCR_ITL32;

		// Configure the DMA channel to be used to service transmit FIFO
		// Enable an interrupt on the completion of the transfer
        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 4);
		error = XsDmaConfigureDevice (XSDMA_CH_PR_LOW,
							ctxP->dmaTxCfgP->targetName, 
							TRUE,
							&firstDescTxVtP,
							ctxP->dmaTxCfgP->descNum,
							ctxP->dmaTxCfgP->bufferSize,
							NULL,
							NULL,
							0,
							(PINT)&ctxP->dmaTxChannel); 

		if (error != 0)
		{
	        // DMA channel or source memory can not be allocated
	        // printf (" Error! UART DMA Tx config failed\r\n");
            status = ERRORCODE(UartType, 
                               ERR_S_UART_TRANSMIT,
                               ERR_T_DMA_NOCHAN);
            XllpUtilityOutputError(status);
		    // Cleanup the allocated resources
		    XsDmaFreeChannel (ctxP->dmaTxChannel);
		    XsDmaDestroyChain (firstDescTxVtP);
	        // Restore an original Uart configuration
		    UartRestoreDmaConfiguration (ctxP);
		}

		// Configure the DMA channel to be used to service receive FIFO
		// Enable an interrupt on the completion of the transfer
        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 5);
		error = XsDmaConfigureDevice (XSDMA_CH_PR_LOW,
							ctxP->dmaRxCfgP->sourceName, 
							FALSE,
							&firstDescRxVtP,
							ctxP->dmaRxCfgP->descNum,
							ctxP->dmaRxCfgP->bufferSize,
							NULL,
							NULL,
							0,
							(PINT)&ctxP->dmaRxChannel); 

		if (error != 0)
		{
	        // DMA channel or source memory can not be allocated
            status = ERRORCODE(UartType, 
                               ERR_S_UART_RECEIVE,
                               ERR_T_DMA_NOCHAN);
            XllpUtilityOutputError(status);
		    // Cleanup the allocated resources
		    XsDmaFreeChannel (ctxP->dmaRxChannel);
		    XsDmaDestroyChain (firstDescRxVtP);
	        // Restore an original Uart configuration
		    UartRestoreDmaConfiguration (ctxP);
		}

        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 6);

		// Fill transmit buffers with a known pattern
		FillTxBufferSerial (firstDescTxVtP, ctxP->dmaTxCfgP->descNum, ctxP->dmaTxCfgP->bufferSize, 0);

        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 7);

		// Clear the receive buffer
		ClearRxBufferSerial (firstDescRxVtP, ctxP->dmaRxCfgP->descNum, ctxP->dmaRxCfgP->bufferSize);

        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 8);

		// Fill receive buffers with a known pattern
		FillRxBufferSerial (firstDescRxVtP, ctxP->dmaRxCfgP->descNum, ctxP->dmaRxCfgP->bufferSize, 0x55);

        // Clear the Rx and Tx transfer completion flag 
        // These flags will be set by the DMA interrupt handler
		ctxP->xferTxComplete = 0;
        ctxP->xferRxComplete = 0;
		ctxP->dmaTxIntStatusP->stopIntCount = 0;
		ctxP->dmaRxIntStatusP->stopIntCount = 0;

		// Clear the receiver's FIFO
    	ctxP->clearRxUartFnP (ctxP);

        // Setup the Uart's hardware  						
        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 9);
        ctxP->setupUartFnP (ctxP);							
        DM_WaitMs (500);

        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 0xA);

        length = XsDmaGetRemainingLength (ctxP->dmaTxChannel);
        status = XsDmaReadChannelStatus (ctxP->dmaTxChannel);
	    DM_CwDbgPrintf(DM_CW_DMA_0, "Tx Xfer Length: %x \n", (UINT)length);
	    DM_CwDbgPrintf(DM_CW_DMA_0, "Tx DSCR: %x \n", (UINT)status);

		// Wait for the completion of the Tx transfer
		error = XsDmaWaitUntilStopped(ctxP->dmaTxChannel);
		if (error != 0)
		{
	        // Time out on Tx DMA channel
            status = ERRORCODE(UartType, 
                               ERR_S_UART_TRANSMIT,
                               ERR_T_TIMEOUT);
            XllpUtilityOutputError(status);
		    // Cleanup the allocated resources
		    XsDmaFreeChannel (ctxP->dmaTxChannel);
		    XsDmaFreeChannel (ctxP->dmaRxChannel);
		    XsDmaDestroyChain (firstDescTxVtP);
		    XsDmaDestroyChain (firstDescRxVtP);
	        // Restore an original Uart configuration
		    UartRestoreDmaConfiguration (ctxP);
            // Shutdown the UART
            ctxP->shutdownUartFnP (ctxP);
            return;
		}

        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 0xB);

        length = XsDmaGetRemainingLength (ctxP->dmaRxChannel);
        status = XsDmaReadChannelStatus (ctxP->dmaRxChannel);
	    DM_CwDbgPrintf(DM_CW_DMA_0, "Rx Xfer Length: %x \n", (UINT)length);
	    DM_CwDbgPrintf(DM_CW_DMA_0, "Rx DSCR: %x \n", (UINT)status);

		// Wait for the completion of the Rx transfer
		error = XsDmaWaitUntilStopped(ctxP->dmaRxChannel);
		if (error != 0)
		{
	        // Time out on Rx DMA channel
            status = ERRORCODE(UartType, 
                               ERR_S_UART_RECEIVE,
                               ERR_T_TIMEOUT);
            XllpUtilityOutputError(status);
		    // Cleanup the allocated resources
		    XsDmaFreeChannel (ctxP->dmaTxChannel);
		    XsDmaFreeChannel (ctxP->dmaRxChannel);
		    XsDmaDestroyChain (firstDescTxVtP);
		    XsDmaDestroyChain (firstDescRxVtP);
	        // Restore an original Uart configuration
		    UartRestoreDmaConfiguration (ctxP);
            // Shutdown the UART
            ctxP->shutdownUartFnP (ctxP);
            return;
		}

		// Compare the data between receive and transmit buffers
        PostDisplayProgress(UartType, ERR_TS_UART_DMA_LOOPBACK, 0xC);
		status = CompareDataDmaXferSerial (firstDescTxVtP,  firstDescRxVtP,
				                           ctxP->dmaTxCfgP->descNum, 
				                           ctxP->dmaTxCfgP->bufferSize,
				                           ctxP->dmaTxCfgP->xferLength);
        if (status)
        {
            // Report data mismatch error
            status = ERRORCODE(UartType, 
                               ERR_S_UART_RECEIVE,
                               ERR_T_RECEIVE_MISMATCH);
            XllpUtilityOutputError(status);
        }

		// Cleanup the allocated resources
		XsDmaFreeChannel (ctxP->dmaTxChannel);
		XsDmaFreeChannel (ctxP->dmaRxChannel);
		XsDmaDestroyChain (firstDescTxVtP);
		XsDmaDestroyChain (firstDescRxVtP);

	    // Restore an original Uart configuration
		UartRestoreDmaConfiguration (ctxP);

        // Shutdown the UART
        ctxP->shutdownUartFnP (ctxP);
    }

	// Test done
    if (!status) 
      printf (" Success!\r\n");
}

/*
*******************************************************************************
*
* FUNCTION:
*   KPostSetBtAsSysIo
*	
* DESCRIPTION: 
*	calls the real procedure to switch the system Uart
*
* INPUT PARAMETERS:
*   None
*
* RETURNS:			none.
*
* GLOBAL EFFECTS:	Sets the BTUart as the system Uart.
*
* ASSUMPTIONS:		none.
*
* CALLS:  PostSetBtAsSysIo()
*	
*
*******************************************************************************
*/

void KPostSetBtAsSysIo(PVOID arg, PCHAR param)
{
    PostSetBtAsSysIo();
}

/*
*******************************************************************************
*
* FUNCTION:
*   PostSetBtAsSysIo
*	
* DESCRIPTION: 
*	Switch the system UART to use the BTUART
*
* INPUT PARAMETERS:
*   None
*
* RETURNS:			none.
*
* GLOBAL EFFECTS:	Sets the BTUart as the system Uart.
*
* ASSUMPTIONS:		none.
*
* CALLS:  PostSetBtAsSysIo()
*	
*
*******************************************************************************
*/

void PostSetBtAsSysIo(void)
{
	InitSystemUart(BTUartType);
}

/*
*******************************************************************************
*
* FUNCTION:
*   KPostSetFfAsSysIo
*	
* DESCRIPTION: 
*	calls the real procedure to switch the system Uart
*
* INPUT PARAMETERS:
*   None
*
* RETURNS:			none.
*
* GLOBAL EFFECTS:	Sets the FFUart as the system Uart.
*
* ASSUMPTIONS:		none.
*
* CALLS:  PostSetFfAsSysIo()
*	
*
*******************************************************************************
*/

void KPostSetFfAsSysIo(PVOID arg, PCHAR param)
{
    PostSetFfAsSysIo();
}

/*
*******************************************************************************
*
* FUNCTION:
*   PostSetFfAsSysIo
*	
* DESCRIPTION: 
*	Switch the system UART to use the FFUART
*
* INPUT PARAMETERS:
*   None
*
* RETURNS:			none.
*
* GLOBAL EFFECTS:	Sets the BTUart as the system Uart.
*
* ASSUMPTIONS:		none.
*
* CALLS:  PostSetFfAsSysIo()
*	
*
*******************************************************************************
*/

void PostSetFfAsSysIo(void)
{
	InitSystemUart(FFUartType);
}

⌨️ 快捷键说明

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