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

📄 pcmciawin.cpp

📁 freescale i.mx31 BSP CE5.0全部源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
 *
 * Copyright (C) 2003-2004, MOTOROLA, INC. All Rights Reserved
 * THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
 * BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
 * MOTOROLA, INC.
 *
 * Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
 * THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
 * BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
 * FREESCALE SEMICONDUCTOR, INC.
 *
 * Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved
 * THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
 * BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
 * FREESCALE SEMICONDUCTOR, INC.
 //
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
//
//
 *
 * 	File:			drivers/pccard/pcmciawin.cpp
 * 	Purpose:		PCMCIA Controller Codes 
 *
 * 	Notes:		
 *
 * 	Author:	    	Kok Choon Kiat
 * 	Date:		10/01/2004
 *
 * 	Modifications:
 *  MM/DD/YYYY      Initials     	Change description 
 *  02/20/2006        ASH             Modifications done for MX31 BSP
 */
 
#define __PCMCIAWIN_CPP__
#include "pcmciawin.h"

//Object Class that maps to PCMCIA supported memory windows
CPcmciaMemWindows::CPcmciaMemWindows( CPcmciaSocket* pPcmSocket,
                                      DWORD dwWinIndex,
                                      const SS_WINDOW_STATE* pcWindowState,
                                      const SS_WINDOW_INFO* pcWindowInfo ) : CPcmciaMemWindowImpl<CPcmciaSocket>( pPcmSocket,
                                                                                                               dwWinIndex,
                                                                                                               pcWindowState,
                                                                                                               pcWindowInfo )
{	
	DEBUGMSG(ZONE_PDD,(TEXT("++CPcmciaMemWindows::CPcmciaMemWindows[%d]\r\n"),dwWinIndex));
	// Base & Offset Address of uWindow
	g_vPcmciaReg->PBR[dwWinIndex] = pcWindowInfo->uMemFirstByte;
    	m_dwBaseAddress = pcWindowInfo->uMemFirstByte; // save the 1st memory window base address
    	Initialize();    
}

//Destructor class
CPcmciaMemWindows::~CPcmciaMemWindows()
{
    Deinitialize();
}

//------------------------------------------------------------------------------
//
// Function: FreeResources
//
// This function frees the OS resources consumed by the corresponding memory window
//
// Parameters:
//      None
//
// Returns:
//     None
//
//------------------------------------------------------------------------------
void CPcmciaMemWindows::FreeResources()
{
}

//------------------------------------------------------------------------------
//
// Function: DisableWindow
//
// This function disables the card access to the corresponding window
//
// Parameters:
//      None
//
// Returns:
//     None
//
//------------------------------------------------------------------------------
void CPcmciaMemWindows::DisableWindow()
{
	DEBUGMSG(ZONE_PDD,(TEXT("++CPcmciaMemWindows::DisableWindow [%d]\r\n"),m_dwWinIndex));
	
	g_vPcmciaReg->POR[m_dwWinIndex] &= ~PCMCIA_POR_PVALID;	
}

//------------------------------------------------------------------------------
//
// Function: ProgramWindow
//
// This function configures the corresponding memory window for card access
//
// Parameters:
//      None
//
// Returns:
//     None
//
//------------------------------------------------------------------------------
void CPcmciaMemWindows::ProgramWindow()
{
	UINT32	tmp;
	UINT32 i;
	UINT32 bankSizeValue;
	
	DEBUGMSG(ZONE_PDD,(TEXT("++CPcmciaMemWindows::ProgramWindow [%d]\r\n"),m_dwWinIndex));
	
	// Disable this window while we work on it.
	g_vPcmciaReg->POR[m_dwWinIndex] &= ~PCMCIA_POR_PVALID;
	
	// Base & Offset Address of uWindow
	DEBUGMSG(ZONE_PDD,(TEXT("\tOriginal request, uBase: 0x%X, uOffset:0x%X\n\r"),m_WinStatus.uBase,m_WinStatus.uOffset));
	DEBUGMSG(ZONE_PDD,(TEXT("\tDue to add limitation, new uBase: 0x%X, uOffset:0x%X\n\r"),
								m_WinStatus.uBase&PCMCIA_ADDRESS_OFFSET_MASK,m_WinStatus.uOffset&PCMCIA_ADDRESS_OFFSET_MASK));
	g_vPcmciaReg->PBR[m_dwWinIndex] = m_WinStatus.uBase & PCMCIA_ADDRESS_OFFSET_MASK;
	g_vPcmciaReg->POFR[m_dwWinIndex] = m_WinStatus.uOffset & PCMCIA_ADDRESS_OFFSET_MASK;    	

	// starting TO3, BSIZE needs to be >=16 bytes
	if (m_WinStatus.uSize < PCMCIA_BANKSIZE_MIN)
		m_WinStatus.uSize = PCMCIA_BANKSIZE_MIN; 

	i=0;
	while(TRUE) {
		tmp=(UINT32) ( 1 << ( i + PCMCIA_BSIZE_BIT_OFFSET) );
		// Instead of return Bad Window, we give size bigger than requested
		if (m_WinStatus.uSize <= tmp) {
			bankSizeValue = g_bankSizeValue[i];
			break;
		} else if ( tmp > PCMCIA_BANKSIZE_MAX) {
			return;
		} else {
			i++;
		}
	}	
			
	// Write BankSize for window size
	tmp=(bankSizeValue << PCMCIA_POR_BSIZE_BS);
		
	if(PCMCIA_BANKSIZE_MIN >= 16) {
		// force to 16 bit access since it's 16bit data allignment
		m_WinStatus.fState |= WIN_STATE_16BIT;
	} else if(!(m_WinStatus.fState & WIN_STATE_16BIT)) {
		// set 8 bit mode
		tmp	|= (PCMCIA_PORTSIZE_8BIT << PCMCIA_POR_PORTSIZE_BS);
	} 
	
	// set memory window as common or attribute
	if(m_WinStatus.fState & WIN_STATE_ATTRIBUTE) {
		tmp	|= (PCMCIA_REGIONSELECT_ATTRIBUTE << PCMCIA_POR_REGIONSELECT_BS);
	} else {
		tmp	|= (PCMCIA_REGIONSELECT_COMMON << PCMCIA_POR_REGIONSELECT_BS);
	}
		
	// Set strobe timing
	tmp |= ( PCMCIA_POR_PSL_BS_DEFAULT << PCMCIA_POR_PSL_BS);
	tmp |= ( PCMCIA_POR_PSST_BS_DEFAULT << PCMCIA_POR_PSST_BS);
	tmp |= ( PCMCIA_POR_PSHT_BS_DEFAULT << PCMCIA_POR_PSHT_BS);				
				
	g_vPcmciaReg->POR[m_dwWinIndex] = tmp;

	//
	// Enable or disable this window as requested.
	//
	if (m_WinStatus.fState & WIN_STATE_ENABLED) 
	{
		g_vPcmciaReg->POR[m_dwWinIndex] |= PCMCIA_POR_PVALID;
		Sleep(100);
	} 
	else 
	{		
		g_vPcmciaReg->POR[m_dwWinIndex] &= ~PCMCIA_POR_PVALID;
	}	

#ifdef DEBUG
	PcPrintPcmciaReg();
#endif

}

//------------------------------------------------------------------------------
//
// Function: GetNewOffset
//
// This function retrieves the offset of the corresponding memory window
//
// Parameters:
//      pWindowState
//             [in]         memory Window state
//
// Returns:
//     dwNewOffset - minimum offset size
//
//------------------------------------------------------------------------------
DWORD CPcmciaMemWindows::GetNewOffset( PSS_WINDOW_STATE pWindowState )
{

    // alignment with the minimum size allocation
    DWORD dwNewOffset = pWindowState->uOffset & (~(m_WinInfo.uMemMinSize-1));
	DEBUGMSG(ZONE_PDD,(TEXT("CPcmciaMemWindows::GetNewOffset [%d]: newOffset:0x%X\r\n"),m_dwWinIndex,dwNewOffset));	

    return dwNewOffset;
}

//------------------------------------------------------------------------------
//
// Function: GetNewLength
//
// This function retrieves the length of the corresponding memory window
//
// Parameters:
//      pWindowState
//             [in]         memory Window state
//      dwNewOffset
//             [in]         new offset within the memory window
//
// Returns:
//     dwNewLength - memory window length
//
//------------------------------------------------------------------------------
DWORD CPcmciaMemWindows::GetNewLength( PSS_WINDOW_STATE pWindowState,
                                       DWORD dwNewOffset )
{
	// compensate the new offset
    DWORD dwNewLength = 	pWindowState->uOffset +
                        				pWindowState->uSize -
                        				dwNewOffset ;			

	// alignment with minimum size
	if(dwNewLength %m_WinInfo.uMemMinSize)
		dwNewLength += m_WinInfo.uMemMinSize - dwNewLength %m_WinInfo.uMemMinSize;
	DEBUGMSG(ZONE_PDD,(TEXT("CPcmciaMemWindows::GetNewLength [%d]: dwNewLength:0x%X\r\n"),m_dwWinIndex,dwNewLength));	

    return dwNewLength;
}

//------------------------------------------------------------------------------
//
// Function: GetBaseAddress
//
// This function retrieves the base address of the memory window
//

⌨️ 快捷键说明

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