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

📄 memorysticktest.c

📁 PXA270硬件测试源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	// different value
	if (MemoryStickTestResult == MS_TEST_SUCCESS)
	{

        PostDisplayProgress(ERR_L_MEMSTICK, ERR_S_MEMSTICK_WRITE, __LINE__);	
	
        // Load the WRITE_REG TPC
        MSCMR_REG = MSCMR_WRITE_REG_TPC + 
                    MSCMR_READ_WRITE_REG_DATA_SIZE;

    	// Toggle the value to be written to the System Parameter 
    	// register of the Memory Stick.
        MSTXFIFO_REG = (~SystemParameterValue) & 
                       MS_SYSTEM_PARAMETER_REGISTER_BAMD_FIELD;

        // 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 register on the Memory Stick a 2nd time and 
	// verify that the BAMD bit is toggled from the first read. 
	if (MemoryStickTestResult == MS_TEST_SUCCESS)
	{	    	
        PostDisplayProgress(ERR_L_MEMSTICK, ERR_S_MEMSTICK_SECOND_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)
        {

            SystemParameterValue = MSRXFIFO_REG &
                                   MS_SYSTEM_PARAMETER_REGISTER_BAMD_FIELD;
			printf("Final SystemParameterValue = %08x\r\n", SystemParameterValue);

	        printf("DEBUG - 06\r\n");
         
            // Read the System Parameter value and verify toggling
            if (SystemParameterValue == 
               (MSRXFIFO_REG & MS_SYSTEM_PARAMETER_REGISTER_BAMD_FIELD))
            {
                // The BAMD field did not toggle
                MemoryStickTestResult = MS_TEST_FAILURE;
            }   
        }    
        else
        {   // Not the 1 Available Data that is expected
            MemoryStickTestResult = MS_TEST_FAILURE;
        }
    }

** CODE PICKS UP AGAIN HERE */

      // Remove Memory Stick Power
	  MISCELLANEOUS_WRITE_REGISTER_1 &= ~MS_ON;

	
	// Prompt the user to remove the Memory Stick
	if (MemoryStickInserted == 1)
	{
        PostDisplayProgress(ERR_L_MEMSTICK, ERR_S_MEMSTICK_REMOVE, __LINE__);	
        printf(" User! Remove the Memory Stick from the Mainstone board.\r\n");
        ContinueTest = GetUserResponse(YES);
	}

	// Check that the Memory Stick is not inserted
	if (MemoryStickInserted == 1)
	{
    if ((MISCELLANEOUS_READ_REGISTER_1 & nMEMSTK_CD) == 0)
        {
       		retVal = ERRORCODEX(ERR_L_MEMSTICK, 0x80, 1, ERR_T_DEV_PRESENT);
   			XllpUtilityOutputError(retVal);
			return (MS_TEST_FAILURE);
        }
    }
	
	// Restore the MSHC and Mainstone board
	if (MemoryStickTestResult == MS_TEST_SUCCESS)
	{	
        PostDisplayProgress(ERR_L_MEMSTICK, ERR_S_MEMSTICK_SHUTDOWN, __LINE__);	
	    MemoryStickHWShutdown();
	}

    if (MemoryStickTestResult == MS_TEST_SUCCESS)
    {
        PostDisplayProgress(ERR_L_MEMSTICK, ERR_S_MEMSTICK_PASS, __LINE__);
    	printf(" Success!\r\n");        
    	
    }
    else
    {
        retVal = ERRORCODEX(ERR_L_MEMSTICK, 0x80, 1, ERR_T_NODEVICE);
   		XllpUtilityOutputError(retVal);
    }
	
	return (MemoryStickTestResult);
		
}// end of PostMemoryStickTest()

/*
*******************************************************************************
*
* FUNCTION:
*    MemoryStickHWShutdown
*
* DESCRIPTION:
*    Shutdown the Memory Stick socket.
*
* INPUT PARAMETERS:
*    None.
*
* RETURNS:
*    None.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    None.
*
* CALLED BY:
*    Memory Stick test main function.
*
* PROTOTYPE:
*    void MemoryStickHWShutdown(void);
*
*******************************************************************************
*/
void MemoryStickHWShutdown(void)
{
    //DM_CwDbgPrintf(DM_CW_XS_PCMCIA_0, "MemoryStickHWShutdown:");

	// Reset the MSHC
	MSCRSR_REG = MSCRSR_RST_FIELD;
	
	// Reset Mainstone Platform Registers by clearing Memory Stick Power On
	MISCELLANEOUS_WRITE_REGISTER_1 &= ~MS_ON;
	
	// Stop the reset of the MSHC
	MSCRSR_REG &= ~MSCRSR_RST_FIELD;
		
}// end of MemoryStickHWShutdown()

/*
*******************************************************************************
*
* FUNCTION:
*    MemoryStickHWSetup
*
* DESCRIPTION:
*    Initialize the Memory Stick Hardware Controller and Mainstone 
*    Platform Registers.
*
* INPUT PARAMETERS:
*    None.
*
* RETURNS:
*    None.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    None.
*
* CALLED BY:
*    Memory Stick test main function.
*
* PROTOTYPE:
*    void MemoryStickHWSetup(void);
*
*******************************************************************************
*/
void MemoryStickHWSetup(void)
{
    DM_CwDbgPrintf(DM_CW_XS_PCMCIA_0, "MemoryStickHWSetup:");

	// Configure the GPIO Pins
	// Configure GP32 the Memory Stick MSSCLK Signal
	GPDR1_REG |= BIT0;		// Set as Output
	GAFR1_L_REG	|= BIT0;	// Alternate Function 1
	GAFR1_L_REG &= ~BIT1;   // Clear this bit
	
	// Configure GP92 the Memory Stick MSBS Signal	
	GPDR2_REG |= BIT28;		// Set as Output
	GAFR2_U_REG &= ~BIT24;  // Clear this bit
	GAFR2_U_REG |= BIT25;   // Alternate Function 2
	
	// Configure GP109 the Memory Stick MSSDIO Signal
	// GPDR3 setting for MSSDIO is a don't care per note in the Bulverde EAS
	// Section 10.5, "GPIO Alternate Functions"
	GAFR3_L_REG &= ~BIT26;  // Clear this bit
	GAFR3_L_REG |= BIT27;   // Alternate Function 2
	
	// Configure GP112 the Memory Stick MSINS Signal	
	GPDR3_REG &= ~BIT16;	// Set as Input
	GAFR3_U_REG &= ~BIT0;   // Clear this bit
	GAFR3_U_REG |= BIT1;    // Alternate Function 2	

   // Insure Memory Stick Clock is enabled
    xsCMEnableClock(CK_MSTICK);


	// Reset the MSHC
	MSCRSR_REG = MSCRSR_RST_FIELD;

	// Stop the reset of the MSHC
	MSCRSR_REG &= ~MSCRSR_RST_FIELD;
		
	// Enable the Serial Interface of the MSHC
	MSCRSR_REG |= MSCRSR_SIEN_FIELD;
			

}// End of MemoryStickHWSetup()

void KPostMemoryStickTest(PVOID arg, PCHAR param)
{
    PostMemoryStickTest();
}

static XLLP_UINT32_T MshcDetected;

XLLP_UINT32_T MshcDetectStatus (void)
{
    return MshcDetected;
}

void MshcClearDetectStatus (void)
{
    MshcDetected = XLLP_FALSE;
}



void MshcDetectInterruptHandler (void * param)
{
	// Check status of the MS
    if (IsDevicePresent(nMEMSTK_CD))
    {
    	// This is an insertion interrupt
        MshcDetected = XLLP_TRUE;
    }
    else
    {
    	// This is a card removal interrupt
        MshcDetected = XLLP_FALSE;
    }
}
void KPostTstMSDetectCard(PVOID arg, PCHAR param)
{
    PostTstMSDetectCard();
}


UINT PostTstMSDetectCard(void)
{
    UINT32 status;

	printf (" Testing Memory Stick detection interrupt\r\n");
    PostDisplayProgress(ERR_L_MEMSTICK, 0x81, 0);

    // Register the MS interrupt
    status = BoardIcRegisterHandler (PB_IC_ID_MSINS, MshcDetectInterruptHandler,NULL);
    if (status != ERR_L_NONE) {
		DM_CwDbgPrintf(DM_CW_MSHC, " Memory Stick registering interrupt failed: %08X\r\n",status);
		XllpUtilityOutputError(status);
		return 1;
	}

    PostDisplayProgress(ERR_L_MEMSTICK, 0x81, 3);

	if(!IsDevicePresent(nMEMSTK_CD))
	{
        printf (" User! Insert a Memory Stick card.\r\n");
        GetUserResponse(YES);
	}

    // Enable MS interrupt
    PostDisplayProgress(ERR_L_MEMSTICK, 0x81, 2);

    status = BoardIcEnableInt (PB_IC_ID_MSINS);
    if (status != ERR_L_NONE) {
		DM_CwDbgPrintf(DM_CW_MSHC, " Memory Stick enabling interrupt failed: %08X\r\n",status);
        BoardIcDisableInt (PB_IC_ID_MSINS);
        BoardIcUnRegisterHandler (PB_IC_ID_MSINS);
		XllpUtilityOutputError(status);
		return 1;
	}

	if(IsDevicePresent(nMEMSTK_CD))
	{
        ModifyBoardInterruptSetRegister(Int_Set_Register, INT_MSINS);
	}

	// Wait for the MS to be inserted
	status = MshcDetectStatus();
	if (status == FALSE) {
	    // MS was not detected
	    DM_CwDbgPrintf(DM_CW_MSHC, " Misc. Read Register: %08X", ReadMiscRdRegister());
	    DM_CwDbgPrintf(DM_CW_MSHC, " Int. Set/Clear Register: %08X", ReadBoardInterruptSetRegister());
	    DM_CwDbgPrintf(DM_CW_MSHC, " Int. Mask Register: %08X", ReadBoardInterruptMaskRegister());
        XllpUtilityOutputError(ERRORCODEX(ERR_L_MEMSTICK, 0x81, 3, ERR_T_NODEVICE));
        BoardIcDisableInt (PB_IC_ID_MSINS);
        BoardIcUnRegisterHandler (PB_IC_ID_MSINS);
		return 1;
	}	   

	// Clear MS status flag
    PostDisplayProgress(ERR_L_MEMSTICK, 0x81, 4);
    MshcClearDetectStatus ();

    // Disable MS interrupt
    PostDisplayProgress(ERR_L_MEMSTICK, 0x81, 5);
    status = BoardIcDisableInt (PB_IC_ID_MSINS);
    PostDisplayProgress(ERR_L_MEMSTICK, 0x81, 6);
    if (status != ERR_NONE) {
		DM_CwDbgPrintf(DM_CW_MSHC, " Memory Stick disabling interrupt failed: %08X\r\n",status);
		XllpUtilityOutputError(status);
		return 1;
	}

    // Unregister the MS interrupt
    status = BoardIcUnRegisterHandler (PB_IC_ID_MSINS);
    PostDisplayProgress(ERR_L_MEMSTICK, 0x81, 7);
    if (status != ERR_NONE) {
		DM_CwDbgPrintf(DM_CW_MSHC," Memory Stick unregistering interrupt failed: %08X\r\n",status);
		XllpUtilityOutputError(status);
		return 1;
	}

    printf(" Success!\r\n");
    return 0;
    
} // PostTstMsDetectCard()

⌨️ 快捷键说明

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