📄 pdsocket.cpp
字号:
//**********************************************************************
//
// Filename: pdsocket.cpp
//
// Description:
//
// 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.
//
// Use of this source code is subject to the terms of the Cirrus 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
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved
//
//**********************************************************************
#include <windows.h>
#include <types.h>
#include <socksv2.h>
#include <memory.h>
#include <ceddk.h>
#include <nkintr.h>
#include <oalintr.h>
#include <hwdefs.h>
#include "pdsocket.h"
//////////////////////////////////////////////////////////////////////////
// special registry values for this driver
#define SYSINTR_VALUE_NAME TEXT("SysIntr")
#define CLIENT_IRQ_VALUE_NAME TEXT("ClientIrq")
#define POLL_TIMEOUT_NAME TEXT("PollTimeout")
#define POLLING_MODE_NAME TEXT("PollingMode")
#define CSC_THREAD_PRIORITY_NAME TEXT("CSCThreadPriority")
#define POWER_OPTION_NAME TEXT("RegPowerOption")
#define DEFAULT_PRIORITY 101
const SS_POWER_ENTRY CPcmciaCardSocket::m_rgPowerEntries[NUM_POWER_ENTRIES] =
{
{ 0, PWR_SUPPLY_VCC | PWR_SUPPLY_VPP1 | PWR_SUPPLY_VPP2 },
{ 33, PWR_SUPPLY_VCC | PWR_SUPPLY_VPP1 | PWR_SUPPLY_VPP2 },
{ 50, PWR_SUPPLY_VCC | PWR_SUPPLY_VPP1 | PWR_SUPPLY_VPP2 }
};
DWORD CPcmciaCardSocket::m_dwSocketLastIndex = 1;
STATUS CPcmciaCardSocket::GetPowerEntry( PDWORD pdwNumOfEntry,
PSS_POWER_ENTRY pPowerEntry )
{
STATUS status = CERR_BAD_ARGS;
if( pdwNumOfEntry != NULL && pPowerEntry != NULL )
{
DWORD dwNumOfCopied = min( *pdwNumOfEntry, NUM_POWER_ENTRIES );
if( dwNumOfCopied != 0 )
{
memcpy( pPowerEntry,
m_rgPowerEntries,
dwNumOfCopied * sizeof( SS_POWER_ENTRY ) );
*pdwNumOfEntry = dwNumOfCopied;
status = CERR_SUCCESS;
}
}
return status;
}
CPcmciaBusBridge::CPcmciaBusBridge( LPCTSTR RegPath ) : CPCCardBusBridgeBase( RegPath ),
CMiniThread( 0,
TRUE )
{
//m_fPCICCritSecInitialized = false;
m_hISTEvent = NULL;
m_prgCardSocket = NULL;
m_rgfPowerCycleEvent = FALSE;
m_rgForceEject = FALSE;
m_fPollingMode = FALSE;
};
CPcmciaBusBridge::~CPcmciaBusBridge()
{
GetSocketNumberFromCS( FALSE );
// Terminate IST
m_bTerminated = TRUE;
if( m_hISTEvent )
{
SetEvent( m_hISTEvent );
ThreadTerminated( 1000 );
if( !m_fPollingMode )
{
InterruptDisable( m_dwCSCSysIntr );
}
CloseHandle( m_hISTEvent );
};
RemovePcmciaCardSocket();
UnMapDeviceRegisters();
}
BOOL CPcmciaBusBridge::InstallIsr()
{
// CreateIST Event.
m_hISTEvent = CreateEvent( 0, FALSE, FALSE, NULL );
if( !m_fPollingMode )
{
InterruptInitialize( m_dwCSCSysIntr, m_hISTEvent, 0, 0 );
}
return(TRUE);
}
BOOL CPcmciaBusBridge::InitializeBridgeHW( void )
{
// TODO - handle initializing only the current slot...
PowerPCCardWrite( 0,0 );
InitSocketNoCard( );
return(TRUE);
}
BOOL CPcmciaBusBridge::UnMapDeviceRegisters( void )
{
return(TRUE);
}
BOOL CPcmciaBusBridge::MapDeviceRegisters( void )
{
return(TRUE);
} // MapDeviceRegisters.
//
// Function to get the initial settings from the registry
//
// NOTE: lpRegPath is assumed to be under HKEY_LOCAL_MACHINE
//
// Returns ERROR_SUCCESS on success or a Win32 error code on failure
//
DWORD CPcmciaBusBridge::GetRegistryConfig( void )
{
DWORD dwRet = 1;
DWORD dwSize, dwType, dwData;
// Get the PCMCIA window configurations
if( !LoadWindowsSettings() )
{
dwRet = ERROR_INVALID_DATA;
goto grc_fail;
}
// Read the registry to determine the physical slot number we're dealing with.
// Get the polling mode value.
dwSize = sizeof( DWORD );
if( !RegQueryValueEx( POLLING_MODE_NAME,
&dwType,
( PUCHAR ) & dwData,
&dwSize ) )
{
m_fPollingMode = FALSE; // RegQueryValueEx failed, default to FALSE;
}
else
{
m_fPollingMode = dwData ? TRUE : FALSE;
}
// Get client (function) IRQ.
dwSize = sizeof( DWORD );
if( !RegQueryValueEx( CLIENT_IRQ_VALUE_NAME,
&dwType,
( PUCHAR ) & dwData,
&dwSize ) )
{
DEBUGMSG( ZONE_PDD,
( TEXT( "PCMCIA:GetRegistyConfig RegQueryValueEx(%s) failed\r\n" ),
CLIENT_IRQ_VALUE_NAME ) );
goto grc_fail;
}
m_dwClientIrq = dwData;
// TODO - get CD IRQ and SYSINTR - no polling.
// Get card status change (CSC) IRQ and SYSINTR values.
// NOTE: the CSC and CD IRQ values are part of the same IRQ multi-string in the registry.
dwSize = sizeof( DWORD );
if( !RegQueryValueEx( SYSINTR_VALUE_NAME,
&dwType,
( PUCHAR ) & dwData,
&dwSize ) )
{
m_dwCSCSysIntr = SYSINTR_PCMCIA_STATE;
m_dwCSCIrq = 0;
m_fPollingMode = FALSE;
}
else
{
m_dwCSCSysIntr = dwData;
}
// Get the polling timeout value.
dwSize = sizeof( DWORD );
if( !RegQueryValueEx( POLL_TIMEOUT_NAME,
&dwType,
( PUCHAR ) & dwData,
&dwSize ) )
{
// RegQueryValueEx failed; if pooling, set the timeout to 0.5 sec, otherwise set to INFINITE
// m_dwPollTimeout = m_fPollingMode ? 500 : INFINITE;
m_dwPollTimeout = INFINITE;
}
else
{
m_dwPollTimeout = dwData;
}
// Get thread priority from registry and set it.
m_uPriority = DEFAULT_PRIORITY;
dwSize = sizeof( DWORD );
if( RegQueryValueEx( CSC_THREAD_PRIORITY_NAME,
&dwType,
( PUCHAR ) & dwData,
&dwSize ) )
{
m_uPriority = ( UINT )dwData;
}
dwRet = ERROR_SUCCESS;
grc_fail : return dwRet;
} // GetRegistryConfig
BOOL CPcmciaBusBridge::InitCardBusBridge( void )
{
// Get PCCARD controller registry information.
if((GetRegistryConfig()) != ERROR_SUCCESS)
{
DEBUGMSG( ZONE_PDD,
( TEXT( "PDCardInitServices GetRegistryConfig failed.\r\n" )));
return(FALSE);
}
// Map PCCARD controller device buffers.
if( !MapDeviceRegisters() )
{
DEBUGMSG( ZONE_PDD,
( TEXT( "PDCardInitServices MapDeviceRegisters failed %d\r\n" )));
return(FALSE);
}
// Initialize the PCMCIA bridge hardware.
if( !InitializeBridgeHW() )
{
DEBUGMSG( ZONE_PDD,
( TEXT( "PDCardInitServices InitializeBridgeHW failed %d\r\n" )));
return(FALSE);
}
// Initialize slot interrupts.
InstallIsr();
return(TRUE);
}
BOOL CPcmciaBusBridge::Init()
{
if(!loadPcCardEntry())
{
return(FALSE);
}
if(!InitCardBusBridge())
{
return(FALSE);
}
if (!GetSocketNumberFromCS( TRUE ))
{
return(FALSE);
}
// Set Tread Priority.
CeSetPriority( m_uPriority );
m_bTerminated = FALSE;
ThreadStart();
return(TRUE);
}
void CPcmciaBusBridge::PowerMgr( BOOL bPowerDown )
{
}
BOOL CPcmciaBusBridge::NeedPowerResuming()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -