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

📄 uarts.c

📁 优龙YLP270的串口裸机测试程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
**  This software as well as the software described in it is furnished under 
**  license and may only be used or copied in accordance with the terms of the 
**  license. The information in this file is furnished for informational use 
**  only, is subject to change without notice, and should not be construed as 
**  a commitment by Intel Corporation. Intel Corporation assumes no 
**  responsibility or liability for any errors or inaccuracies that may appear 
**  in this document or any software that may be provided in association with 
**  this document. 
**  Except as permitted by such license, no part of this document may be 
**  reproduced, stored in a retrieval system, or transmitted in any form or by 
**  any means without the express written consent of Intel Corporation. 
**
**  FILENAME:       UARTs.c
**
**  PURPOSE:        This module contains the test code for UARTs.
**
**  LAST MODIFIED:  $Modtime: 7/17/03 1:01p $
******************************************************************************/

/*
*******************************************************************************
*   HEADER FILES
*******************************************************************************
*/                                                                      

#include <stdio.h>
#include <stdlib.h>
#include "systypes.h"
#include "XsDmaApi.h"
#include "xsuart.h"
#include "xsffuart.h"
#include "xsbtuart.h"
#include "xsstuart.h"
#include "uarts.h"
#include "serialCommon.h"  
#include "DM_Debug.h"
#include "dm_errors.h"
#include "timedelays.h"
#include "boardControl.h"
#include "DM_SerialInOut.h"


static UartCfgT * tempCfgP;
static UartDmaCfgT * tempDmaTxCfgP;
static UartDmaCfgT * tempDmaRxCfgP;
static XsDmaDescriptorElementsT * firstDescTxVtP;
static XsDmaDescriptorElementsT * firstDescRxVtP;
/*
*******************************************************************************
*   LOCAL DEFINITIONS
*******************************************************************************
*/

// Single transaction loopback values. Attempt to spread out bits.
static INT testValues8[] =
{
 	0x10, 0x80, 0xAA, 0x55, 0xC0, 0x03,
   	0x90, 0x60, 0x11, 0x22, 0x44, 0x88																  
};																						  

// Default configuration structure used in the test
static UartCfgT testConfigUART = 
{
	FCR_TRFIFOE,				 // Enable FIFOs
	IER_UUE,    				 // Disable DMA, no NRZ, disable IRQ, and enable UART unit
	LCR_WLS8,                    // One stop bit, no parity, 8 bits
	0,			                 // No IRDA
	UartLoopbackOff,			 // Disable loopback		
	115200					     // baud rate 115200
};

// DMA configuration structure to setup the transmit channel
static UartDmaCfgT testDmaTxCfg = 
{
	NUM_BUF,		
	DMA_BUFSIZ,
	XFER_LEN,	
	XSDMA_DN_MEMORY,	
	XSDMA_DN_MEMORY,
	XSDMA_CH_PR_LOW	
};

// DMA configuration structure to setup the receive channel
static UartDmaCfgT testDmaRxCfg = 
{
	NUM_BUF,		
	DMA_BUFSIZ,
	XFER_LEN,	
	XSDMA_DN_MEMORY,	
	XSDMA_DN_MEMORY,
	XSDMA_CH_PR_LOW	
};

static UINT32 UartType;

/*
*******************************************************************************
*
* FUNCTION:			UartReturnFromTestIfSystem
*	
* DESCRIPTION: 
*	This function checks if the currently selected tor the tests Uart is a system Uart,
*   and returns a message that the test is not available, because this is a System Uart
*   used by the Diagnostic Manager as a serial I/O 
*
* INPUT PARAMETERS:
*   UartContextT * ctxP - Pointer the the UART Device Context Structure.
*
* RETURNS:			INT (-1) if the current device is a System Uart.
*                       0 - otherwise
* GLOBAL EFFECTS:	none.
*
* ASSUMPTIONS:		none.
*
* CALLS:
*
* CALLED BY:
*	The Uarts' tests.
*
* PROTOTYPE:
*	INT UartReturnFromTestIfSystem (UartContextT * ctxP)
*
*******************************************************************************
*/
static
INT UartReturnFromTestIfSystem (UartContextT * ctxP)
{
    if ((ctxP->type & SystemUart) == SystemUart)
    {
    	printf (" POST System Uart.\r\n No tests available.\r\n");
        DM_WaitMs(1000);
        return (-1);
    }

    return 0;
}

static VOID UartStartTesting(UartContextT * ctxP)
{
	switch (ctxP->type & 0x03)
	{
		case FFUartType:
            printf (" Testing FFUART\r\n");
            UartType = ERR_L_XSFFUART;
			break;
		case BTUartType:
            printf (" Testing BTUART\r\n");
            UartType = ERR_L_XSBTUART;
			break;
		case STUartType:
            printf (" Testing STUART\r\n");
            UartType = ERR_L_XSSTUART;
	}
}

/*
*******************************************************************************
*
* FUNCTION:			UartSetConfiguration
*	
* DESCRIPTION: 
*	This function saves the original pointer of the Uart's configuration structure
*	and sets it to the test config. structure to support the tests. 
*
* INPUT PARAMETERS:
*   UartContextT * ctxP - Pointer the the UART Device Context Structure.
*
* RETURNS:			none.
*
* GLOBAL EFFECTS:	none.
*
* ASSUMPTIONS:		none.
*
* CALLS:
*
* CALLED BY:
*	Menu system
*
* PROTOTYPE:
*	VOID UartSetConfiguration (UartContextT * ctxP)
*
*******************************************************************************
*/
VOID UartSetConfiguration (UartContextT * ctxP)
{
	if (ctxP->uartCfgP == NULL)
	  ctxP->uartCfgP = &testConfigUART;
	tempCfgP = ctxP->uartCfgP;	
	ctxP->uartCfgP = &testConfigUART;
}


/*
*******************************************************************************
*
* FUNCTION:			UartRestoreConfiguration
*	
* DESCRIPTION: 
*	This function sets the pointer of the Uart's configuration structure to the
*	original config. structure to restore the original configuration after the tests. 
*
* INPUT PARAMETERS:
*   UartContextT * ctxP - Pointer the the UART Device Context Structure.
*
* RETURNS:			none.
*
* GLOBAL EFFECTS:	none.
*
* ASSUMPTIONS:		none.
*
* CALLS:
*
* CALLED BY:
*	Menu system
*
* PROTOTYPE:
*	VOID UartRestoreConfiguration (UartContextT * ctxP)
*
*******************************************************************************
*/

VOID UartRestoreConfiguration (UartContextT * ctxP)
{
	// Restore contence of the configuration structure
	ctxP->uartCfgP = tempCfgP;

	// Restore default test configuration structure
    testConfigUART.loopback = UartLoopbackOff;
	testConfigUART.maskIRDA = 0;
}

/*
*******************************************************************************
*
* FUNCTION:			UartSetDmaConfiguration
*	
* DESCRIPTION: 
*	This function saves the original pointer of the Uart's Dma configuration structure
*	and sets it to the test Dma config. structure to support the tests. 
*
* INPUT PARAMETERS:
*   UartContextT * ctxP - Pointer the the UART Device Context Structure.
*
* RETURNS:			none.
*
* GLOBAL EFFECTS:	none.
*
* ASSUMPTIONS:		none.
*
* CALLS:
*
* CALLED BY:
*	Menu system
*
* PROTOTYPE:
*	VOID UartSetDmaConfiguration (UartContextT * ctxP)
*
*******************************************************************************
*/
VOID UartSetDmaConfiguration (UartContextT * ctxP)
{
	if (ctxP->dmaTxCfgP == NULL)
	  ctxP->dmaTxCfgP = &testDmaTxCfg;

	if (ctxP->dmaRxCfgP == NULL)
	  ctxP->dmaRxCfgP = &testDmaRxCfg;

	tempDmaTxCfgP = ctxP->dmaTxCfgP;
	ctxP->dmaTxCfgP = &testDmaTxCfg;

	tempDmaRxCfgP = ctxP->dmaRxCfgP;
	ctxP->dmaRxCfgP = &testDmaRxCfg;

	switch (ctxP->type & 0x03)
	{
		case FFUartType:
			ctxP->dmaTxCfgP->sourceName = XSDMA_DN_MEMORY;
			ctxP->dmaTxCfgP->targetName = XSDMA_DN_FFUART;
			ctxP->dmaRxCfgP->sourceName = XSDMA_DN_FFUART;
			ctxP->dmaRxCfgP->targetName = XSDMA_DN_MEMORY;
			break;
		case BTUartType:
			ctxP->dmaTxCfgP->sourceName = XSDMA_DN_MEMORY;
			ctxP->dmaTxCfgP->targetName = XSDMA_DN_BTUART;
			ctxP->dmaRxCfgP->sourceName = XSDMA_DN_BTUART;
			ctxP->dmaRxCfgP->targetName = XSDMA_DN_MEMORY;
			break;
		case STUartType:
			ctxP->dmaTxCfgP->sourceName = XSDMA_DN_MEMORY;
			ctxP->dmaTxCfgP->targetName = XSDMA_DN_STUART;
			ctxP->dmaRxCfgP->sourceName = XSDMA_DN_STUART;
			ctxP->dmaRxCfgP->targetName = XSDMA_DN_MEMORY;
	}
}


/*
*******************************************************************************
*
* FUNCTION:			UartRestoreDmaConfiguration
*	
* DESCRIPTION: 
*	This function sets the pointer of the Uart's configuration structure to the
*	original config. structure to restore the original configuration after the tests. 
*
* INPUT PARAMETERS:
*   UartContextT * ctxP - Pointer the the UART Device Context Structure.
*
* RETURNS:			none.
*
* GLOBAL EFFECTS:	none.
*
* ASSUMPTIONS:		none.
*
* CALLS:
*
* CALLED BY:
*	Menu system
*
* PROTOTYPE:
*	VOID UartRestoreDmaConfiguration (UartContextT * ctxP)
*
*******************************************************************************
*/

VOID UartRestoreDmaConfiguration (UartContextT * ctxP)
{

	// Restore contence of the configuration structure
	ctxP->uartCfgP = tempCfgP;

	ctxP->dmaTxCfgP = tempDmaTxCfgP;
	ctxP->dmaRxCfgP = tempDmaRxCfgP;
}

/*
*******************************************************************************
*
* FUNCTION:
*   UartLoopbackSingle
*
* DESCRIPTION: 
*	This is a simple loopback test where the single byte of data is sent
*   via loopback path.
*
* INPUT PARAMETERS:
*   UartContextT * ctxP - Pointer the the UART Device Context Structure.
*   INT data            - Single byte of data, that is sent via loopback.
*
* RETURNS:
*	The single byte of data if success 
*   or (-1) if loopback timout time has expiered
*
* GLOBAL EFFECTS:
*
* ASSUMPTIONS:
*
* CALLS:
*
* CALLED BY:
*   UartStaticLoopTest
*
* PROTOTYPE:
*   INT UartLoopbackSingle (UartContextT * ctxP, INT data)
*
*******************************************************************************
*/
static
INT UartLoopbackSingle (UartContextT * ctxP, INT data)
{
 	UINT32 status;
    INT x;

    PostDisplayProgress(UartType, ERR_TS_UART_LOOPSINGLE, 1);
    x = ctxP->loopbackUartFnP (ctxP, data);
    if (x < 0)
    {
        // Report Timeout on loopback write
        status = ERRORCODE(UartType, 
                           ERR_S_UART_TRANSMIT,
                           ERR_T_TIMEOUT);
        XllpUtilityOutputError(status);
    }
    return x;
}

INT PostUartStaticLoop (UartContextT * ctxP, INT loopbackMode)
{
    INT data;
    INT testFailed = 0;
    INT i;
    INT testCount = NUM_TEST_VALUES;
    INT errorCount = 0;
    UINT32 status;

    // if this UART is used as a system UART, skip the test
    if ((ctxP->type & SystemUart) == SystemUart)

⌨️ 快捷键说明

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