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

📄 pcmciawin.cpp

📁 freescale i.mx31 BSP CE5.0全部源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Parameters:
//      pWindowState
//             [in]         memory Window state
//      dwNewOffset
//             [in]         new offset within the memory window
//      dwNewOffset
//             [in]         new length of the memory window
//      dwNewBaseAddress
//             [OUT]         new base address for the memory window
//
// Returns:
//     TRUE always
//
//------------------------------------------------------------------------------
BOOL CPcmciaMemWindows::GetBaseAddress( PSS_WINDOW_STATE pWindowState,
                                        DWORD dwNewOffset,
                                        DWORD dwNewLength,
                                        DWORD& dwNewBaseAddress )
{
	dwNewBaseAddress = m_dwBaseAddress;	
 	DEBUGMSG(ZONE_PDD,(TEXT("CPcmciaMemWindows::GetBaseAddress [%d]: m_dwBaseAddress:0x%X\r\n"),m_dwWinIndex,m_dwBaseAddress));	
   	return TRUE;
}


//Object Class that maps to PCMCIA supported IO windows
CPcmciaIoWindows::CPcmciaIoWindows( CPcmciaSocket* pPcmSocket,
                                    DWORD dwWinIndex,
                                    const SS_WINDOW_STATE* pcWindowState,
                                    const SS_WINDOW_INFO* pcWindowInfo ) : CPcmciaIoWindowImpl<CPcmciaSocket>( pPcmSocket,
                                                                                                            dwWinIndex,
                                                                                                            pcWindowState,
                                                                                                            pcWindowInfo )
{	
	DEBUGMSG(ZONE_PDD,(TEXT("++CPcmciaIoWindows::CPcmciaIoWindows[%d]\r\n"),dwWinIndex));	
	m_dwOffset = 0;
	m_dwBaseAddress = pcWindowInfo->uIOFirstByte;
	Initialize();
}

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

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

//------------------------------------------------------------------------------
//
// Function: DisableWindow
//
// This function disables the card access to the corresponding IO window
//
// Parameters:
//      None
//
// Returns:
//     None
//
//------------------------------------------------------------------------------
void CPcmciaIoWindows::DisableWindow()
{
	UINT32 dwIoIndex = m_dwWinIndex + PCMCIA_NUM_MEMWIN;

	DEBUGMSG(ZONE_PDD,(TEXT("++CPcmciaIoWindows::DisableWindow [%d]\r\n"),m_dwWinIndex));	
	g_vPcmciaReg->POR[dwIoIndex] &= ~PCMCIA_POR_PVALID;	
}

//------------------------------------------------------------------------------
//
// Function: ProgramWindow
//
// This function configures the corresponding IO window for card access
//
// Parameters:
//      None
//
// Returns:
//     None
//
//------------------------------------------------------------------------------
void CPcmciaIoWindows::ProgramWindow()
{
	UINT32 tmp;
	UINT32 i;
	UINT32 bankSizeValue;
	UINT32 dwIoIndex = m_dwWinIndex + PCMCIA_NUM_MEMWIN;
	
	DEBUGMSG(ZONE_PDD,(TEXT("++CPcmciaIoWindows::ProgramWindow [%d]\r\n"),m_dwWinIndex));

	// Disable this	window while we	work on	it.
	g_vPcmciaReg->POR[dwIoIndex] &= ~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[dwIoIndex] = m_WinStatus.uBase & PCMCIA_ADDRESS_OFFSET_MASK;
	g_vPcmciaReg->POFR[dwIoIndex] = m_WinStatus.uOffset & PCMCIA_ADDRESS_OFFSET_MASK;
	
	// set to min bank size if the requested size is smaller
	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);
		
	// Set Port Size
	
	if(!(m_WinStatus.fState & WIN_STATE_16BIT))	
	{
		tmp	|= (PCMCIA_PORTSIZE_8BIT << PCMCIA_POR_PORTSIZE_BS);		
	}
	else
	{
		tmp	|= (PCMCIA_PORTSIZE_16BIT << PCMCIA_POR_PORTSIZE_BS);
	}

				
	// set as IO mode
	tmp	|= (PCMCIA_REGIONSELECT_IO << 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);				
			
	// Now write to POR register
	g_vPcmciaReg->POR[dwIoIndex] = tmp;
			
	//
	// Enable or disable this window as	requested.
	//
	if (m_WinStatus.fState & WIN_STATE_ENABLED) {
		g_vPcmciaReg->POR[dwIoIndex] |= PCMCIA_POR_PVALID;
		Sleep(100);
	} else {		
		g_vPcmciaReg->POR[dwIoIndex] &= ~PCMCIA_POR_PVALID;
	}		

#ifdef DEBUG
	PcPrintPcmciaReg();
#endif
}

//------------------------------------------------------------------------------
//
// Function: GetNewOffset
//
// This function retrieves the offset of the corresponding IO window
//
// Parameters:
//      pWindowState
//             [in]         memory Window state
//
// Returns:
//     dwNewOffset - minimum offset size
//
//------------------------------------------------------------------------------
DWORD CPcmciaIoWindows::GetNewOffset( PSS_WINDOW_STATE pWindowState )
{
	// alignment with the minimum size allocation
	DWORD dwNewOffset = pWindowState->uOffset & (~(m_WinInfo.uIOMinSize-1));
	
	DEBUGMSG(ZONE_PDD,(TEXT("CPcmciaIoWindows::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 CPcmciaIoWindows::GetNewLength( PSS_WINDOW_STATE pWindowState,
                                      DWORD dwNewOffset )
{
	// compensate the new offset
    DWORD dwNewLength = 	pWindowState->uOffset +
                        				pWindowState->uSize -
                        				dwNewOffset ;			

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

	return dwNewLength;
}

//------------------------------------------------------------------------------
//
// Function: GetBaseAddress
//
// This function retrieves the base address of the memory window
//
// Parameters:
//      pWindowState
//             [in]         memory Window state
//      dwNewOffset
//             [in]         new offset within the memory window
//      dwNewOffset
//             [in]         new length of the memory window
//      dwNewBaseAddress
//             [OUT]         new base address for the memory window
//
// Returns:
//     TRUE always
//
//------------------------------------------------------------------------------
BOOL CPcmciaIoWindows::GetBaseAddress( PSS_WINDOW_STATE pWindowState,
                                       DWORD dwNewOffset,
                                       DWORD dwNewLength,
                                       DWORD& dwNewBaseAddress )
{
	DEBUGMSG(ZONE_PDD,(TEXT("CPcmciaIoWindows::GetBaseAddress [%d]: m_dwBaseAddress:0x%X\r\n"),m_dwWinIndex,m_dwBaseAddress));	

	dwNewBaseAddress = m_dwBaseAddress;
    return TRUE;
}

⌨️ 快捷键说明

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