?? pcmsock.cpp
字號:
else if( ( pState->fVcc & SOCK_VCC_LEVEL_MASK ) >=
PCMCIA_POWER_ENTRIES ||
!( CPCCardBusBridge::cs_rgPowerEntries[pState->fVcc & SOCK_VCC_LEVEL_MASK].fSupply & PWR_SUPPLY_VCC ) )
{
pState->fVcc = m_SockState.fVcc;
status = CERR_BAD_VCC;
}
else
{
BYTE oldfVcc = m_SockState.fVcc;
BYTE olduVpp = m_SockState.uVpp1;
if( ( pState->fVcc & SOCK_VCC_LEVEL_MASK ) !=
( m_SockState.fVcc & SOCK_VCC_LEVEL_MASK ) )
{
m_SockState.fVcc = pState->fVcc;
}
if( ( pState->uVpp1 & SOCK_VCC_LEVEL_MASK ) !=
( m_SockState.uVpp1 & SOCK_VCC_LEVEL_MASK ) )
{
if( ( pState->uVpp1 & SOCK_VCC_LEVEL_MASK ) >=
PCMCIA_POWER_ENTRIES ||
!( CPCCardBusBridge::cs_rgPowerEntries[pState->uVpp1 & SOCK_VCC_LEVEL_MASK].fSupply & PWR_SUPPLY_VPP1 ) )
pState->uVpp1 = m_SockState.uVpp1;
m_SockState.uVpp1 = pState->uVpp1;
if( CPCCardBusBridge::cs_rgPowerEntries[m_SockState.uVpp1 & SOCK_VCC_LEVEL_MASK].uPowerLevel !=
0 &&
CPCCardBusBridge::cs_rgPowerEntries[m_SockState.uVpp1 & SOCK_VCC_LEVEL_MASK].uPowerLevel !=
120 )
{
// VPP is same as VCC.
m_SockState.uVpp1 = m_SockState.fVcc;
}
}
if( ( oldfVcc != m_SockState.fVcc || olduVpp != m_SockState.uVpp1 ) &&
m_pBridge->IsValidPowerSetting( m_SockState.fVcc, m_SockState.uVpp1 ) )
{
m_pBridge->EnableClientInterrupt( m_nSlot, FALSE );
if( CPCCardBusBridge::cs_rgPowerEntries[m_SockState.fVcc & SOCK_VCC_LEVEL_MASK].uPowerLevel ==
0 )
{
DEBUGMSG( ZONE_PDD,
( TEXT( "PDCardSetSocket PCMSocket. Socket is Power Down! Function Interrupt Routing will force to Off\r\n" ) ) );
m_SockState.dwInteruptStatus &= ~SOCK_INT_FUNC_IRQ_ROUTING;
m_pBridge->ApplyEnable(m_nSlot, FALSE);
m_pBridge->ApplyPower( m_nSlot, 0, 0 );
}
else
{
PowerOnProcedure( m_SockState.fVcc, m_SockState.uVpp1 );
m_pBridge->EnableClientInterrupt( m_nSlot, ( m_SockState.dwInteruptStatus & SOCK_INT_FUNC_IRQ_ROUTING ) !=
0 );
DEBUGMSG( ZONE_PDD,
( TEXT( "PDCardSetSocket PCMSocket. Socket is Power Up with fVcc=%d\r\n" ),
m_SockState.fVcc ) );
}
}
else
{
DEBUGMSG( ZONE_PDD,
( TEXT( "PDCardSetSocket PCMSocket. Same Power with fVcc=%d and uVpp1\r\n" ),
m_SockState.fVcc,
m_SockState.uVpp1 ) );
if( oldfVcc != m_SockState.fVcc ||
olduVpp != m_SockState.uVpp1 )
{
DEBUGMSG( ZONE_PDD |
ZONE_ERROR,
( TEXT( "PDCardSetSocket PCMSocket. Unsported Power with fVcc=%d and uVpp1\r\n" ),
m_SockState.fVcc,
m_SockState.uVpp1 ) );
m_SockState.fVcc = oldfVcc;
m_SockState.uVpp1 = olduVpp;
status = CERR_BAD_VCC;
}
}
}
}
else
{
status = CERR_BAD_SOCKET;
}
Unlock();
return status;
}
//
// ResetSocket - do a PCMCIA reset
// return CERR_SUCCESS on success, CERR_UNSUPPORTED_SERVICE if size is anomolous
//
STATUS CPCardSocket::CardResetSocket()
{
DEBUGMSG( ZONE_SOCKET, ( TEXT( "!ResetPCMCIASocket()\r\n" ) ) );
// set INT_CARD_NOT_RESET in INTERRUPT_AND_GENERAL_CONTROL register as directed
Lock();
STATUS status = CERR_SUCCESS;
if( m_pBridge )
{
if( m_pBridge->IsCardInserted(m_nSlot) )
{
BYTE uVcc = m_pBridge->GetVSPinOut(m_nSlot);
BYTE uVpp = 0;
//
// Power the socket
//
DEBUGMSG( ZONE_SOCKET,
( TEXT( "CPCardSocket::CardResetSocket: Initial Power on is uVcc=%d \r\n" ), uVcc ) );
PowerOnProcedure( uVcc, uVpp );
m_SockState.fVcc = uVcc;
m_SockState.uVpp1 = uVpp;
m_SockState.uVpp2 = uVpp;
m_pBridge->SetInterruptEvent( m_nSlot, PCMCIA_INTERRUPT_POWER );
}
else
{
status = CERR_NO_CARD;
}
}
else
{
status = CERR_BAD_SOCKET;
}
DEBUGMSG( ZONE_SOCKET,
( TEXT( "-MRSHPC!ResetPCMCIASocket() return status =%x\r\n" ),
status ) );
Unlock();
return status;
}
void CPCardSocket::PowerOnProcedure( UINT8 fVcc, UINT8 fVpp )
{
DEBUGMSG( ZONE_SOCKET,
( TEXT( "+PCMCIA!PCMSocket:PowerOnProcedure fVcc=%d,fVpp=%d\r\n" ), fVcc,fVpp ) );
m_pBridge->ApplyEnable(m_nSlot, FALSE ) ;
m_pBridge->ApplyPower( m_nSlot, 0 , 0 );
Sleep(310);
if (!m_pBridge->ApplyPower(m_nSlot,fVcc,fVpp)) {
DEBUGCHK(FALSE);
DEBUGMSG( ZONE_POWER, (TEXT("PowerOnProcedure fVcc (%d) & fVpp(%d) combo does not exist!\r\n"),fVcc,fVpp ) );
return ;
}
Sleep(100);
m_pBridge->ApplyEnable(m_nSlot,TRUE);
m_pBridge->ApplyReset(m_nSlot, TRUE);
Sleep(20);
m_pBridge->ApplyReset(m_nSlot, FALSE);
for (DWORD dwCount = 0; dwCount < 10 * 1000 / 20; dwCount++) {
if (m_pBridge->IsCardReady( m_nSlot ))
break;
Sleep(20);
}
//m_pBridge->SetInterruptEvent( m_nSlot, PCMCIA_INTERRUPT_POWER );
DEBUGMSG( ZONE_PDD, ( TEXT( "-PCMCIA!PCMSocket:PowerOnProcedure return with Ready = %d \r\n" ),m_pBridge->IsCardReady( m_nSlot ) ) );
}
UINT16 CPCardSocket::GetSocketNumber()
{
return m_pBridge->GetSocketNumber(m_nSlot) ;
};
void CPCardSocket::PowerMgrCallback( BOOL bPowerOff )
{
SS_SOCKET_STATE sSocketState = m_SockState;
sSocketState.dwEventChanged = SOCK_EVENT_SUSPEND_RESUME;
sSocketState.dwEventStatus = ( bPowerOff ?
SOCK_EVENT_CD :
( SOCK_EVENT_CD |
SOCK_EVENT_SUSPEND_RESUME ) );
m_pBridge->CallBackToCardService( m_nSlot, GetSocketHandle(), &sSocketState );
}
void CPCardSocket::PowerMgr( BOOL bPowerDown )
{
if( bPowerDown )
{
// Power Off Socket If it is applied.
PowerMgrCallback( bPowerDown );
if( ( m_SockState.dwInteruptStatus & SOCK_INT_FUNC_IRQ_WAKE ) == 0 )
{
// We can shud down this function card
m_pBridge->EnableClientInterrupt( m_nSlot, FALSE );
m_pBridge->ApplyPower( m_nSlot, 0, 0 );
m_pBridge->ApplyEnable(m_nSlot, FALSE );
m_bResuming = TRUE;
}
}
else
{
if( m_bResuming )
{
if( ! m_pBridge->ApplyPower( m_nSlot, m_SockState.fVcc, m_SockState.uVpp1 ) )
{
DEBUGCHK( FALSE );
DEBUGMSG( ZONE_ERROR,
( TEXT( "+PCMCIA!PCMSocket:PowerOnProcedure fVcc(%d) & fVpp(%d) combo does not exist!\r\n" ),
m_SockState.fVcc,
m_SockState.uVpp1 ) );
}
m_pBridge->NeedPowerResuming();
}
else
{
PowerMgrCallback( bPowerDown );
}
}
}
BOOL CPCardSocket::Resuming() // This routine can not call sleep because it could endup yeild to other thread.
{
if( m_bResuming )
{
Lock();
DWORD dwStartTickCount = GetTickCount();
// Wait for 100MS for power set .
while( GetTickCount() - dwStartTickCount < 100 )
Sleep( 0 ); //Yeild among same priority thread.
//Assert Resetting.
m_pBridge->ApplyEnable(m_nSlot, TRUE );
m_pBridge->ApplyReset( m_nSlot, TRUE );
dwStartTickCount = GetTickCount();
while( GetTickCount() - dwStartTickCount < 20 )
Sleep( 0 ); //Yeild among same priority thread.
// Deassert Reset.
m_pBridge->ApplyReset( m_nSlot, FALSE );
dwStartTickCount = GetTickCount();
while( GetTickCount() - dwStartTickCount < 20 )
Sleep( 0 ); //Yeild among same priority thread.
m_bResuming = FALSE;
dwStartTickCount = GetTickCount();
while( GetTickCount() - dwStartTickCount < 1000 )
{
// Check for one second.
if( m_pBridge->IsCardReady(m_nSlot) )
break;
Sleep( 0 );
};
if( m_pBridge->IsCardReady(m_nSlot) == 0 )
DEBUGMSG( ZONE_ERROR,
( TEXT( "PCMSocket::Resuming: Power is not on yet!!!!\r\n" ) ) );
// Enabler the IRQ routing if we need.
m_pBridge->EnableClientInterrupt( m_nSlot, ( m_SockState.dwInteruptStatus & SOCK_INT_FUNC_IRQ_ROUTING ) !=
0 );
PowerMgrCallback( FALSE );
Unlock();
return TRUE;
}
return FALSE;
}
void CPCardSocket::SocketEventHandle( int nSlot, WORD wStateChange, WORD wState, PCMCIA_INTERRUPT_EVENT otherEvent )
{
SS_SOCKET_STATE sSockState;
Lock();
// get the current socket state
CardGetSocket( &sSockState );
// indicate the powercycle event if appropriate
if( otherEvent == PCMCIA_INTERRUPT_POWER )
{
sSockState.dwEventChanged |= SOCK_EVENT_PWRCYCLE;
sSockState.dwEventStatus |= SOCK_EVENT_PWRCYCLE;
}
// we do not report the CD events here
//sSockState.dwEventStatus &= ~SOCK_EVENT_CD;
sSockState.dwEventChanged &= ~SOCK_EVENT_CD;
Unlock();
// send the notification to socket services
m_pBridge->CallBackToCardService( m_nSlot, GetSocketHandle(), &sSockState );
}
CPCardSocket* CreatePCMCIASocket( int nSlot, CPCCardBusBridge* pBridge )
{
CPCardSocket* pNewSocket = new CPCardSocket( nSlot, pBridge );
if( pNewSocket != NULL )
{
if( pNewSocket->CardInitWindow( pNewSocket, nSlot ) )
{
return pNewSocket;
}
else
{
delete pNewSocket;
}
}
return NULL;
}
BOOL CPCardSocket::EnableWindow()
{
return m_pBridge->EnableWindow( m_nSlot );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -