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

📄 usbotg.c

📁 优龙pxa270平台试验程序
💻 C
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000 - 2003 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:       UsbOTG.c
**
**  PURPOSE:        This file contained functions to test the functionality of
**					the USB OTG device.
**
**  LAST MODIFIED:  $Modtime: 9/17/03 9:50a $
******************************************************************************/

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

#include <string.h>
#include <stdio.h>
#include "systypes.h"
#include "xllp_defs.h"
#include "DM_Debug.h"
#include "timedelays.h"
#include "boardControl.h"
#include "xsuart.h"
#include "DM_SerialInOut.h"
#include "DM_Errors.h"
#include "DRV_i2c.h"
#include "UsbOTGi2c.h"
#include "UsbOTG.h"

/*
*******************************************************************************
*   LOCAL CONSTANTS
*******************************************************************************
*/

#define DEBUG_MODE   1

#ifdef DEBUG_MODE
static UINT32 debugMode = 1;
#else
static UINT32 debugMode = 0;
#endif

#define MAX_REG_NUM 22

UINT32 USB_OTG_TRV_ADDRESS = 0x58; 

/*
*******************************************************************************
*   LOCAL VARIABLES
*******************************************************************************
*/
static XLLP_BOOL_T firstTest = XLLP_FALSE;

/*
*******************************************************************************
*
* FUNCTION:			UsbOTGDumpRegistersI2CTest
*
* DESCRIPTION:		This function dumps the registers' values of the Phillips ISP1301 
*                   USB OTG Transceiver. 
*
* INPUT PARAMETERS:	PVOID ctxP -  Not used
*					PCHAR param - Not used
*
* RETURNS:		    None.
*
* GLOBAL EFFECTS:	None.
*
* ASSUMPTIONS:		None.
*
* CALLS:
*
* CALLED BY:		
*
* PROTOTYPE:		VOID UsbOTGDumpRegistersI2CTest (PVOID ctxp, PCHAR param);
*
*******************************************************************************
*/

VOID UsbOTGDumpRegistersI2CTest (PVOID ctxp, PCHAR param)
{
    XLLP_UINT8_T dataBuff[MAX_REG_NUM];
    XLLP_INT32_T i = 0;
    XLLP_INT32_T error = ERR_L_NONE, status;
    XLLP_UINT16_T vendorID, productID ; 
    
	  volatile P_POST_I2C_T I2CRegsBaseP  = (P_POST_I2C_T)STAND_I2C_BASE;
    volatile P_XLLP_CLKMGR_T clkMgrP    = (P_XLLP_CLKMGR_T)CLK_MGR_REGS_BASE;
    volatile P_XLLP_GPIO_T	gpioRegP    = (P_XLLP_GPIO_T ) GPIO_REGS_BASE;

    printf (" Testing USB OTG ISP1301 Transceiver\r\n");

    PostDisplayProgress(ERR_L_USBOTG, ERR_S_USBOTG_DUMP_REG, 1);

	printf (" User!	Is the USBOTG transceiver set to the High Address? \r\n");
    if(GetUserResponse(YESNO))
	{
		USB_OTG_TRV_ADDRESS = 0x5A;
        printf(" User! USBOTG transceiver set to 0x5A.\r\n");
	}
	else
    {
		USB_OTG_TRV_ADDRESS = 0x58;
        printf(" User! USBOTG transceiver set to 0x58.\r\n");
    }
	printf (" User! This test must run with the terminal on the BTUART.\r\n");
	printf (" User! Is the terminal connected to the BTUART?\r\n");

	if(GetUserResponse(YESNO))
	{
	    // Initialize the BTUART
	    //InitSystemUart(BTUartType);
	    
	    // Get USB OTG Transceiver out of reset
	    ModifyMiscWr2Register(1, USB_OTG_RST | USB_OTG_EN);

	    PostDisplayProgress(ERR_L_USBOTG, ERR_S_USBOTG_DUMP_REG, 2);
	    DM_WaitMs(1000);

	    // Set GPIOs for Transceivers control signals
	    UsbOTGi2cConfigGpio (debugMode);

	    // Initialize I2C controller
	    PostI2cInit(I2CRegsBaseP, gpioRegP, clkMgrP, POST_I2C_SLAVE_ID);

	    // Read data from the register
	    error = UsbOTGi2cRead (XLLP_REG_VENDOR_ID_R, MAX_REG_NUM, dataBuff);


	    if (error != ERR_L_NONE)
	    {
	        PostDisplayProgress(ERR_L_USBOTG, ERR_S_USBOTG_DUMP_REG, 3);
	        
	//        printf (" User! Please switch control back to FFUART...\r\n");
	//        GetUserResponse(YES);
	        
	        // Put USB OTG Transceiver in reset
	        ModifyMiscWr2Register(0, USB_OTG_RST | USB_OTG_EN);

	        // Set GPIOs for FFUART
	//        UsbOTGi2cConfigGpio (0);

	        // Initialize the FFUART
	//        InitSystemUart(FFUartType);
	//        DM_WaitMs(500);

		    // Read registers fail
	        status = ERRORCODEX(ERR_L_USBOTG,
	                        ERR_S_USBOTG_DUMP_REG,
	                        2,
	                        ERR_T_NORECEIVE);
	        XllpUtilityOutputError(status);
	        return;
	    }

	    PostDisplayProgress(ERR_L_USBOTG, ERR_S_USBOTG_DUMP_REG, 4);

	    // Dump Registers
	    for (i = 0; i < MAX_REG_NUM; ++i)
	    {
	        DM_CwDbgPrintf(DM_CW_USB_CLIENT, " Register %d: %02X\r\n", (int)i, dataBuff[i]);
	    }
	    
	    vendorID = (dataBuff[XLLP_REG_VENDOR_ID_R+1] << 8) |dataBuff[XLLP_REG_VENDOR_ID_R] ;
	    productID = (dataBuff[XLLP_REG_PRODUCT_ID_R+1] << 8) | dataBuff[XLLP_REG_PRODUCT_ID_R] ;

		  if((vendorID == USB_OTG_VENDOR_ID) & (productID == USB_OTG_PRODUCT_ID))
		  {
		    printf("\r\nUSB OTG Dump Registers Test - PASS\r\n\r\n") ;
		    
   		  printf (" ISP1301 Registers:\r\n");
	    	printf (" Register          Address     Value     Default\r\n");
	    	printf (" Vendor ID         0x01-0x00   0x%02X%02X    0x04CC\r\n",
	                                            dataBuff[XLLP_REG_VENDOR_ID_R+1], 
	                                            dataBuff[XLLP_REG_VENDOR_ID_R]);
	    	printf (" Product ID        0x03-0x02   0x%02X%02X    0x1301\r\n",
	                                            dataBuff[XLLP_REG_PRODUCT_ID_R+1],
	                                            dataBuff[XLLP_REG_PRODUCT_ID_R]);
	    	printf (" Chip Version      0x15-0x14   0x%02X%02X    0x0100\r\n",
	                                            dataBuff[XLLP_REG_CHIP_VER_R+1], 
	                                            dataBuff[XLLP_REG_CHIP_VER_R]);
	    	printf (" Mode Control 1    0x04        0x%02X      0x00\r\n",
	                                            dataBuff[XLLP_REG_MODE_1_R]);
	    	printf (" Mode Control 2    0x12        0x%02X      0x04\r\n",
	                                            dataBuff[XLLP_REG_MODE_2_R]);
	    	printf (" OTG Control 1     0x06        0x%02X      0x0C\r\n",
	                                            dataBuff[XLLP_REG_OTG_R]);
	    	printf (" Interrupt Source  0x08        0x%02X      0xA0\r\n",
	                                            dataBuff[XLLP_REG_INT_SOURCE_R]);
	    	printf (" Interrupt Latch   0x0A        0x%02X      0x00\r\n",
	                                            dataBuff[XLLP_REG_LATCH_R]);
		    printf (" Int. Enable 0     0x0C        0x%02X      0x00\r\n",
	                                            dataBuff[XLLP_REG_INT_EN_FALL_R]);
		    printf (" Int. Enable 1     0x0E        0x%02X      0x00\r\n",
		                                        dataBuff[XLLP_REG_INT_EN_RAS_R]);
		  }
		  else
		  {
			  // Put USB OTG Transceiver in reset
		    ModifyMiscWr2Register(0, USB_OTG_RST | USB_OTG_EN);
		    
		    printf("USB OTG Dump Registers Test - FAIL!!!!!\r\n") ;
			  printf("Vendor and Product IDs do not match expected !!!\r\n") ;
			  // Read registers fail
	      status = ERRORCODEX(ERR_L_USBOTG,
	                        ERR_S_USBOTG_DUMP_REG,
	                        2,
	                        ERR_T_NORECEIVE);
	        XllpUtilityOutputError(status);
	        return;
		}

	    // Put USB OTG Transceiver in reset
	    ModifyMiscWr2Register(0, USB_OTG_RST | USB_OTG_EN);

	    printf (" User! Please switch control back to FFUART.\r\n");
	    //GetUserResponse(YES);

	    PostDisplayProgress(ERR_L_USBOTG, ERR_S_USBOTG_DUMP_REG, 5);

	    // Set GPIOs for FFUART
	//    UsbOTGi2cConfigGpio (0);
	    
	    // Initialize the FFUART
	//    InitSystemUart(FFUartType);
	    
	    PostDisplayProgress(ERR_L_USBOTG, ERR_S_USBOTG_DUMP_REG, 6);
	    DM_WaitMs(200);

	//	GetUserResponse(YES);

	  	// Test done
	    // It should print via FFUART
	  	printf (" Success!\r\n");

	    PostDisplayProgress(ERR_L_USBOTG, ERR_S_USBOTG_DUMP_REG, 7);
	}
	else
	{
		printf(" User! Test not executed.\r\n");
		GetUserResponse(YES);

	}
	
   }

/*
*******************************************************************************
*
* FUNCTION:			UsbOTGReadRegisterI2CTest
*
* DESCRIPTION:		This function reads the register's values of the Phillips ISP1301
*                   USB OTG Transceiver. 
*
* INPUT PARAMETERS:	PVOID ctxP -    Not used
*					PCHAR param -   a pointer to a string, where the first element
*                                   is a starting address of the registers, and 
*                                   the second element is a number of regisers to read.
*                                
* RETURNS:		    None.
*
* GLOBAL EFFECTS:	None.
*
* ASSUMPTIONS:		None.
*
* CALLS:
*
* CALLED BY:		
*
* PROTOTYPE:		VOID UsbOTGReadRegisterI2CTest (PVOID ctxp, PCHAR param);
*
*******************************************************************************
*/

VOID UsbOTGReadRegisterI2CTest (PVOID ctxp, PCHAR param)
{
	UINT32 regAddr, numBytes;
    XLLP_UINT8_T dataBuff[MAX_REG_NUM];
    XLLP_UINT32_T paramArray[4];
	XLLP_INT32_T i;
	volatile P_POST_I2C_T I2CRegsBaseP  = (P_POST_I2C_T)STAND_I2C_BASE;
    volatile P_XLLP_CLKMGR_T clkMgrP    = (P_XLLP_CLKMGR_T)CLK_MGR_REGS_BASE;
    volatile P_XLLP_GPIO_T	gpioRegP    = (P_XLLP_GPIO_T ) GPIO_REGS_BASE;

	// Process input parameter
    GetMultipleParamFromString (param, 2, (PUINT32)paramArray);
    regAddr = paramArray[0];
    numBytes = paramArray[1];

    if (firstTest == XLLP_FALSE)
    {
        // Set GPIOs for Transceivers control signals
        UsbOTGi2cConfigGpio (debugMode);

        // Initialize I2C controller
        PostI2cInit(I2CRegsBaseP, gpioRegP, clkMgrP, POST_I2C_SLAVE_ID);

        // Get USB OTG Transceiver out of reset
        ModifyMiscWr2Register(1, USB_OTG_RST);
        
        firstTest = XLLP_TRUE;
    }

    if (numBytes > MAX_REG_NUM)
      numBytes = MAX_REG_NUM;

    // Read data from the register
    UsbOTGi2cRead (regAddr, numBytes, dataBuff);

    // Print Registers address and value
    for (i = 0; i < numBytes; ++i)
    {
        printf (" Reading from register 0x%02X: 0x%02X\r\n", (int)regAddr, dataBuff[i]);
        ++regAddr;
    }
}


/*
*******************************************************************************
*
* FUNCTION:			UsbOTGWriteRegisterI2CTest
*
* DESCRIPTION:		This function writes to registers of the Phillips ISP1301
*                   USB OTG Transceiver. 
*
* INPUT PARAMETERS:	PVOID ctxP -    Not used
*					PCHAR param -   a pointer to a string, where: 
*                                   the first element is an address of the registers,
*                                   the second element is a value that needs to be written,
*                                   the third element ia a register accsess type, 1 - set, 0 - clear
*                                
* RETURNS:		    None.
*
* GLOBAL EFFECTS:	None.
*
* ASSUMPTIONS:		None.
*
* CALLS:
*
* CALLED BY:		
*
* PROTOTYPE:		VOID UsbOTGWriteRegisterI2CTest (PVOID ctxp, PCHAR param);
*
*******************************************************************************
*/

VOID UsbOTGWriteRegisterI2CTest (PVOID ctxp, PCHAR param)
{
	UINT32 regAddr, newRegAddr;
    XLLP_UINT8_T data;
    XLLP_UINT32_T paramArray[4];
	XLLP_REG_ACCESS_T attribute;
	volatile P_POST_I2C_T I2CRegsBaseP  = (P_POST_I2C_T)STAND_I2C_BASE;
    volatile P_XLLP_CLKMGR_T clkMgrP    = (P_XLLP_CLKMGR_T)CLK_MGR_REGS_BASE;
    volatile P_XLLP_GPIO_T	gpioRegP    = (P_XLLP_GPIO_T ) GPIO_REGS_BASE;

	// Process input parameter
    GetMultipleParamFromString (param, 3, (PUINT32)paramArray);
    regAddr     = paramArray[0];
    data        = paramArray[1];
    attribute   = paramArray[2];

    if (firstTest == XLLP_FALSE)
    {
        // Set GPIOs for Transceivers control signals
        UsbOTGi2cConfigGpio (debugMode);

        // Initialize I2C controller
        PostI2cInit(I2CRegsBaseP, gpioRegP, clkMgrP, POST_I2C_SLAVE_ID);

        // Get USB OTG Transceiver out of reset
        ModifyMiscWr2Register(1, USB_OTG_RST);
        
        firstTest = XLLP_TRUE;
    }

    // Compute an address of the register depend on attribute: set or clear.
    if (attribute == XLLP_REG_ACCESS_CLEAR)
      newRegAddr = ++regAddr;
    else
      newRegAddr = regAddr;

    // Write data to the register
    UsbOTGi2cWrite (newRegAddr, 1, &data);

    // Print Registers address and value
    printf (" Writing to register 0x%02X: 0x%02X\r\n", (int)regAddr, data);

    // Read data from the register
    UsbOTGi2cRead (regAddr, 1, &data);

    // Print Registers address and value
    printf (" Reading back from register 0x%02X: 0x%02X\r\n", (int)regAddr, data);
}

VOID UsbOTGEnableDebugMode (void * ctxp, PCHAR param)
{
    INT enable;
    
    if (sscanf(param, "%d", &enable) != 1)
	{
		// Bad number of the parameters have been passed to the function
        return;
	}

    DM_ControlWordsDebugPrintPutBit(DM_CW_USB_CLIENT, enable);
}

⌨️ 快捷键说明

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