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

📄 memorysticktest.c

📁 PXA270硬件测试源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2002 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:       MemoryStickTest.c
**
**  PURPOSE:        This file contains the Bulverde Memory Stick POST code for 
**                  the Intel(r) XScale(tm) Microarchitecture.
**
**  LAST MODIFIED:  $Modtime: 7/17/03 1:01p $
******************************************************************************/

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

//#define _MemoryStickSimualtorDebug // if using a simulator then uncomment

#include "string.h"
#include "stdio.h"
#include <stdlib.h>
#include <ctype.h>

#include "systypes.h"
#include "timedelays.h"
#include "dm_errors.h"
#include "xsuart.h"
#include "xsffuart.h"
#include "xsbtuart.h"
#include "xsstuart.h"
#include "uarts.h"
#include "DM_SerialInOut.h"

#include "dm_debug.h"
#include "platform.h"
#include "cotulla.h"
#include "MemoryStickTest.h"
#include "XsMemCtrl.h"
#include "boardcontrol.h"
#include "xsClkMgr.h"
#include "boardIntCtrlApi.h"


/*
*******************************************************************************
*   GLOBAL DEFINITIONS
*******************************************************************************
*/


/*
*******************************************************************************
*   LOCAL DEFINITIONS
*******************************************************************************
*/


/*
*******************************************************************************
*    Bulverde MSHC Registers
*******************************************************************************
*/
#ifndef _MemoryStickSimualtorDebug
#define	MSCMR_REG		(*(volatile UINT32 *) 0x41800000)
#define	MSCRSR_REG		(*(volatile UINT32 *) 0x41800004)
#define	MSINT_REG		(*(volatile UINT32 *) 0x41800008)
#define	MSINTEN_REG		(*(volatile UINT32 *) 0x4180000C)
#define	MSCR2_REG		(*(volatile UINT32 *) 0x41800010)
#define	MSACD_REG		(*(volatile UINT32 *) 0x41800014)
#define	MSRXFIFO_REG	(*(volatile UINT8 *) 0x41800018)
#define	MSTXFIFO_REG	(*(volatile UINT8 *) 0x4180001C)
#else // make some variables to take the place of the real registers
volatile UINT32 mscmr_r = 0;
#define	MSCMR_REG		(mscmr_r)
volatile UINT32 mscrsr_r = 0;
#define	MSCRSR_REG		(mscrsr_r)
volatile UINT32 msint_r = 0;
#define	MSINT_REG		(msint_r)
volatile UINT32 msinten_r = 0;
#define	MSINTEN_REG		(msinten_r)
volatile UINT32 mscr2_r = 0;
#define	MSCR2_REG		(mscr2_r)
volatile UINT32 msacd_r = 0;
#define	MSACD_REG		(msacd_r)
volatile UINT32 msrxfifo_r = 0;
#define	MSRXFIFO_REG	(msrxfifo_r)
volatile UINT32 mstxfifo_r = 0;
#define	MSTXFIFO_REG	(mstxfifo_r)
#endif

/*
*******************************************************************************
*    Bulverde MSHC Register Field Macros
*******************************************************************************
*/
#define MSCMR_READ_REG_TPC        (0x4 << 12)
#define MSCMR_WRITE_REG_TPC       (0xb << 12)
#define MSCMR_SET_RW_REG_ADRS_TPC (0x8 << 12)

#define MSCMR_READ_WRITE_REG_DATA_SIZE  1
#define MSCMR_SET_RW_REG_ADRS_DATA_SIZE 4

#define MSCRSR_RST_FIELD  (0x8000)       // MSHC MSCRSR Reset Field
#define MSCRSR_SIEN_FIELD (0x2000)       // MSHC MSCRSR SIEN Field

#define MSCRSR_RXAVAIL_OFFSET 5
#define MSCRSR_RXAVAIL_FIELD (0x1f << MSCRSR_RXAVAIL_OFFSET)
#define MSCRSR_TXAVAIL_OFFSET 0
#define MSCRSR_TXAVAIL_FIELD (0x1f << MSCRSR_TXAVAIL_OFFSET)

#define MSINT_RDY_FIELD    (0x8)         // MSHC MSINT RDY SIEN Field

/*
*******************************************************************************
*    Memory Stick Register Macros
*******************************************************************************
*/

#define MS_SYSTEM_PARAMETER_REGISTER_ADDRESS    (0x02)
#define MS_SYSTEM_PARAMETER_REGISTER_LENGTH     (0x01)
#define MS_SYSTEM_PARAMETER_REGISTER_BAMD_FIELD (0x80)


/*
*******************************************************************************
*    Bulverde GPIO Registers used by Memory Stick
*******************************************************************************
*/
#ifndef _MemoryStickSimualtorDebug
#define	GPDR1_REG		(*(volatile UINT32 *) 0x40e00010)
#define	GPDR2_REG		(*(volatile UINT32 *) 0x40e00014)
#define	GPDR3_REG		(*(volatile UINT32 *) 0x40e0010c)
#define	GAFR1_L_REG		(*(volatile UINT32 *) 0x40e0005c)
#define	GAFR2_U_REG		(*(volatile UINT32 *) 0x40e00068)
#define	GAFR3_L_REG		(*(volatile UINT32 *) 0x40e0006c)
#define	GAFR3_U_REG		(*(volatile UINT32 *) 0x40e00070)
#else // make some variables to take the place of the real registers
volatile UINT32 gpdr1_r = 0;
#define	GPDR1_REG		(gpdr1_r)
volatile UINT32 gpdr2_r = 0;
#define	GPDR2_REG		(gpdr2_r)
volatile UINT32 gpdr3_r = 0;
#define	GPDR3_REG		(gpdr3_r)
volatile UINT32 gafr1_r = 0;
#define	GAFR1_L_REG		(gafr1_r)
volatile UINT32 gafr2_u_r = 0;
#define	GAFR2_U_REG		(gafr2_u_r)
volatile UINT32 gafr3_l_r = 0;
#define	GAFR3_L_REG		(gafr3_l_r)
volatile UINT32 gafr3_u_r = 0;
#define	GAFR3_U_REG		(gafr3_u_r)
#endif

/*
*******************************************************************************
*    Mainstone Platform Registers for Memory Stick
*******************************************************************************
*/
#ifndef _MemoryStickSimualtorDebug
#define	MISCELLANEOUS_WRITE_REGISTER_1		(*(volatile UINT32 *) 0x08000080)
#define MISCELLANEOUS_READ_REGISTER_1		(*(volatile UINT32 *) 0x08000090)
#else // make some variables to take the place of the real registers
volatile UINT32 mw_r = 0;
#define	MISCELLANEOUS_WRITE_REGISTER_1		(mw_r)
volatile UINT32 mr_r = 0;
#define MISCELLANEOUS_READ_REGISTER_1		(mr_r)
#endif

#define MS_ON  (0x1000)			// Memory Stick Power Control
#define MS_SEL (0x0400)			// SD/Memory Stick Mux Control
#define nMEMSTK_CD (0x100)      // Memory Stick Detection Signal

/*
*******************************************************************************
*  Error sub-location codes for ERR_L_MEMSTICK location code
*******************************************************************************
*/
#define ERR_S_MEMSTICK_INIT             0x01 // HW Initialization
#define ERR_S_MEMSTICK_INSERT           0x02 // Stick Insertion
#define ERR_S_MEMSTICK_FIRST_READ       0x03 // First Stick Read
#define ERR_S_MEMSTICK_WRITE            0x04 // Stick Write
#define ERR_S_MEMSTICK_SECOND_READ      0x05 // Second Stick Read
#define ERR_S_MEMSTICK_REMOVE           0x06 // Stick Removal
#define ERR_S_MEMSTICK_SHUTDOWN         0x07 // HW Shtdown
#define ERR_S_MEMSTICK_PASS             0x08 // Test Result = PASS
#define ERR_S_MEMSTICK_FAIL             0x09 // Test Result = FAIL

/*
*******************************************************************************
*  Return Codes
*******************************************************************************
*/
#define MS_TEST_SUCCESS    0
#define MS_TEST_FAILURE    1

/*
*******************************************************************************
*
* FUNCTION:
*    PostMemoryStickTest
*
* DESCRIPTION:
*    Test the Memory Stick socket.
*
* INPUT PARAMETERS:
*    None.
*
* RETURNS:
*    1 if error, 0 if no error.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    None.
*
* CALLED BY: 
*    Post main function.
*
* PROTOTYPE:
*    int PostMemoryStickTest(void);
*
*******************************************************************************
*/
int PostMemoryStickTest(void)
{
ErrorT retVal;
int MemoryStickTestResult = MS_TEST_SUCCESS;  // Overall Memory Stick Test Result
int MemoryStickInserted;                // Memory Stick Inserted status
BOOL ContinueTest = FALSE;              // Continue or exit test
UINT8 SystemParameterValue;             // Data read/written to Memory Stick

    printf(" Testing Memory Stick\r\n");
	
	// Initialize the MSHC and Mainstone board
    PostDisplayProgress(ERR_L_MEMSTICK, ERR_S_MEMSTICK_INIT, __LINE__);
	MemoryStickHWSetup();

	// Check that a Memory Stick is inserted
    if ((MISCELLANEOUS_READ_REGISTER_1 & nMEMSTK_CD) == 0)
    {
        printf(" User! A Memory Stick has been detected.\r\n");
        printf(" User! Remove the Memory Stick from the Mainstone board.\r\n");
        ContinueTest = GetUserResponse(YES);
    }
		
	// Prompt the user to insert the Memory Stick
    PostDisplayProgress(ERR_L_MEMSTICK, ERR_S_MEMSTICK_INSERT, __LINE__);	
    printf(" User! Insert a Memory Stick into the Mainstone board\r\n");
	printf(" User! with the LOCK switch on (RED showing).\r\n");
    ContinueTest = GetUserResponse(YES);
    ContinueTest = FALSE;       // Initialize for the next time
	
	// Check that a Memory Stick is inserted
    if ((MISCELLANEOUS_READ_REGISTER_1 & nMEMSTK_CD) == 0)
    {
        MemoryStickInserted = 1; 
    }
    else
    {
       	retVal = ERRORCODEX(ERR_L_MEMSTICK, 0x80, 1, ERR_T_NODEVICE);
   		XllpUtilityOutputError(retVal);
		return (MS_TEST_FAILURE);
    }	
	
	if (MemoryStickTestResult == MS_TEST_SUCCESS)
	{

      // Configure Mainstone Platform Registers by setting Memory Stick Power On
      // and Selecting Memory Stick on the SD/Memory Stick MUX
	  MISCELLANEOUS_WRITE_REGISTER_1 |= (MS_ON + MS_SEL);

      DM_WaitMs(500);   // Dealy 100 mS for Memory Stick to come up

      // Load the SET_R/W_REG_ADRS TPC
	  // Write the TPC first - then send the data!
      MSCMR_REG = (MSCMR_SET_RW_REG_ADRS_TPC + 
                MSCMR_SET_RW_REG_ADRS_DATA_SIZE);

      // Set the address of the System Parameter (Address 0x10)register 
	  // of the Memory Stick.
      //Starting Address for READ_REG
      MSTXFIFO_REG = MS_SYSTEM_PARAMETER_REGISTER_ADDRESS;
      //Consecutive size for READ_REG
      MSTXFIFO_REG = MS_SYSTEM_PARAMETER_REGISTER_LENGTH;
      //Starting Address for WRITE_REG        
      MSTXFIFO_REG = MS_SYSTEM_PARAMETER_REGISTER_ADDRESS;
      //Consecutive size for WRITE_REG        
      MSTXFIFO_REG = MS_SYSTEM_PARAMETER_REGISTER_LENGTH;
                            
      // Wait for TPC completion to be signalled by the set RDY bit
       while ((MSINT_REG & MSINT_RDY_FIELD) != MSINT_RDY_FIELD)
      {
        // Spin here while waiting for the RDY bit to become set
      }
      // Read the System Parameter (Address 0x10)register on the Memory 
	  // Stick and store the results.


        PostDisplayProgress(ERR_L_MEMSTICK, ERR_S_MEMSTICK_FIRST_READ, __LINE__);	
                        
        // Load the READ_REG TPC
        MSCMR_REG = MSCMR_READ_REG_TPC + 
                    MSCMR_READ_WRITE_REG_DATA_SIZE;
                    
        // Wait for TPC completion to be signalled by the set RDY bit
        while ((MSINT_REG & MSINT_RDY_FIELD) != MSINT_RDY_FIELD)
        {
            // Spin here while waiting for the RDY bit to become set
        }

        // Verify the 1 expected RX data was received
        if (((MSCRSR_REG & MSCRSR_RXAVAIL_FIELD) >> MSCRSR_RXAVAIL_OFFSET) 
           == MSCMR_READ_WRITE_REG_DATA_SIZE)
        {
            // Read the System Parameter value and store the value.
            SystemParameterValue = MSRXFIFO_REG;
			//printf("Inital SystemParameterValue = %08x\r\n", SystemParameterValue);

            if (SystemParameterValue != 0x21)    // This byte should = 0x21
			{
            MemoryStickTestResult = MS_TEST_FAILURE;
			}
            if (SystemParameterValue == 0x20)    // If = 20 the write protect switch is OFF
			{
       		retVal = ERRORCODEX(ERR_L_MEMSTICK, 0x80, 1, ERR_T_DEV_NO_WRITE_PRO);
   			XllpUtilityOutputError(retVal);
			return (MS_TEST_FAILURE);
 	       	}
 	     }  	    
	}

/* THIS NEXT SECTION OF CODE IS SKIPPED FOR NOW UNTIL ISSUES WITH THE MSHC ARE RESOLVEDD **
	
	// write the System Parameter register on the Memory Stick to a 

⌨️ 快捷键说明

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