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

📄 pcmsock.cpp

📁 WinCE5.0BSP for Renesas SH7770
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
//  Copyright(C) Renesas Technology Corp. 2005. All rights reserved.
//
// PCCARD driver for ITS-DS7
//
// FILE     : pcmsock.cpp
// CREATED  : 2005.02.03
// MODIFIED : 
// AUTHOR   : Renesas Technology Corp.
// HARDWARE : RENESAS ITS-DS7
// HISTORY  : 
//            2005.02.03
//            - Created release code.
//                (based on PCCARD driver for ASPEN for WCE5.0)

//
// 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.

Module Name:  

Abstract:

    MR-SHPC PCMCIA Socket Services Object for PCMCIA(16-bit) Interface.

Notes: 
--*/
#include <windows.h>
#include <types.h>
#include <socksv2.h>
#include <memory.h>
#include <ceddk.h>
#include <debug.h>
#include "PdSocket.h"
#define ZONE_SOCKET ZONE_PDD


//--------------------Pcmcia Socket Implementation--------------------------------------------
const SS_SOCKET_INFO CPCardSocket::ms_PcmciaSocketInfo =
{
    SOCK_CAP_MEM_CARD |
    SOCK_CAP_IO_MEMORY_CARD |
    SOCK_CAP_WAKEUP_BYCLIENT |
	SOCK_CAP_ONLY_SYSINTR |
    SOCK_CAP_WAKEUP_BYEVENT |
    SOCK_CAP_KEEP_POWERED,      //dwSocketCaps
    SOCK_CAP_PWRCYCLE |
    SOCK_CAP_CD |
    SOCK_CAP_SUSPEND_RESUME,  // Socket Interrupt Capability Set follow bitmap.
    SOCK_CAP_PWRCYCLE |
    SOCK_CAP_CD |
    SOCK_CAP_SUSPEND_RESUME,  // Socket status report capability
    0, // Socket status indicate capability
    0,          // Number of power entry this socket have.
    0,             // Number of Window supported in this Socket.
    ( DWORD )
    PCMCIABus,  //.
    ( DWORD ) -
    1,     // Card Number.
    { - 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
};
const SS_SOCKET_STATE CPCardSocket::ms_SockInitState =
{
    SOCK_EVENT_PWRCYCLE |
    SOCK_EVENT_CD |
    SOCK_EVENT_SUSPEND_RESUME |
    SOCK_EVENT_WP |
    SOCK_EVENT_BVD1 |
    SOCK_EVENT_BVD2, // Initial EventMask
    0, // Event Changed.
    0, // Event Status
    CFG_IFACE_MEMORY,  //default interface type
    0,  // Interrupt Enable.
    0,  // Vcc
    0,  // Vpp1
    0   // Vpp2

};

DWORD CPCardSocket::sdwSocketLastIndex = 1;

CPCardSocket::CPCardSocket( int nSlot, CPCCardBusBridge* pBridge ) : CPCMCIASocketBase<CStaticMemoryWindow<CPCardSocket>, CStaticIOWindow<CPCardSocket>, CStaticWindowBridgeContainer<CPCCardBusBridge>, CPCCardBusBridge>( pBridge )
{
    m_nSlot = nSlot;
    m_dwSocketIndex = 0;
    while( m_dwSocketIndex == 0 )
    {
        m_dwSocketIndex = ( DWORD ) InterlockedIncrement( ( LONG * ) &sdwSocketLastIndex ); 
        //Make sure that no other socket with that index exists.
        CPCardSocket* pSocket = GetSocket( ( HANDLE ) m_dwSocketIndex );
        if( pSocket != NULL )
        {
            // Duplicated , Retry.
            m_dwSocketIndex = 0;
            pSocket->DeRef();
        }
    }

    DEBUGCHK( m_pBridge );

    m_SockState = ms_SockInitState;
    mss_PcmciaSocketInfo = ms_PcmciaSocketInfo;

    for( DWORD dwIndex = 0; dwIndex < IRQ_ROUTINGTABLE_SIZE; dwIndex++ )
    {
        mss_PcmciaSocketInfo.bArrayIrqRouting[dwIndex] = ( BYTE )pBridge->GetClientInterrupt( m_nSlot );
    }

    mss_PcmciaSocketInfo.dwNumOfPowerEntry = PCMCIA_POWER_ENTRIES;

    mss_PcmciaSocketInfo.dwNumOfWindows = pBridge->GetMemWindowCount( m_nSlot ) +
                                          pBridge->GetIoWindowCount( m_nSlot );
    
    mss_PcmciaSocketInfo.dwBusNumber = 0;

    m_bResuming = FALSE;

    m_pBridge->SetupWakeupSource( FALSE );
    m_pBridge->EnableClientInterrupt( m_nSlot, FALSE );
    m_pBridge->SetupWakeupSource( FALSE );
    m_pBridge->ApplyPower( m_nSlot, 0, 0 );

    DEBUGMSG( ZONE_INIT,
              ( TEXT( "CPCardSocket (Socket=%d Index=%d) Created\r\n" ),
                GetSocketNumber(),
                GetSocketHandle() ) );
}
CPCardSocket::~CPCardSocket()
{
    DEBUGMSG( ZONE_SOCKET, ( TEXT( "+CPCardSocket::Deinitialize()\r\n" ) ) );
    Lock();
    m_pBridge->SetupWakeupSource( FALSE );
    m_pBridge->EnableClientInterrupt( m_nSlot, FALSE );
    m_pBridge->SetupWakeupSource( FALSE );
    BOOL bInitWindow = CardDeInitWindow();
    DEBUGCHK( bInitWindow );
    // If necessary, force a removal
    m_pBridge->ApplyPower( m_nSlot, 0, 0 );
	m_pBridge->SetCardType( m_nSlot, CFG_IFACE_MEMORY );
    Unlock();
    DEBUGMSG( ZONE_SOCKET, ( TEXT( "-PCMSocket::Deinitialize()\r\n" ) ) );
    DEBUGMSG( ZONE_INIT,
              ( TEXT( "CPCardSocket (Socket=%d Index=%d) Deleted\r\n" ),
                GetSocketNumber(),
                GetSocketHandle() ) );
}
STATUS CPCardSocket::GetPowerEntry( PDWORD pdwNumOfEnery, PSS_POWER_ENTRY pPowerEntry )
{
    STATUS status = CERR_BAD_ARGS;
    if( pdwNumOfEnery != NULL && pPowerEntry != NULL )
    {
        DWORD dwNumOfCopied = min( *pdwNumOfEnery, PCMCIA_POWER_ENTRIES );
        if( dwNumOfCopied != 0 )
        {
            memcpy( pPowerEntry,
                CPCCardBusBridge::cs_rgPowerEntries,
                    dwNumOfCopied * sizeof( SS_POWER_ENTRY ) );
            *pdwNumOfEnery = dwNumOfCopied;
            status = CERR_SUCCESS;
        }
    }
    return status;
}

//
// InquireSocket - return Socket Info
// return CERR_SUCCESS on success, CERR_UNSUPPORTED_SERVICE if size is anomolous
//
STATUS CPCardSocket::CardInquireSocket( PSS_SOCKET_INFO pSocketInfo )
{
    if( pSocketInfo )
    {
        *pSocketInfo = mss_PcmciaSocketInfo;
        return CERR_SUCCESS;
    }
    else
    {
        return CERR_BAD_ARGS;
    }
}
//
// GetSocket - return Socket state
// return CERR_SUCCESS on success, CERR_UNSUPPORTED_SERVICE if size is anomolous
//
STATUS CPCardSocket::CardGetSocket( PSS_SOCKET_STATE pState )
{
    DEBUGMSG( ZONE_SOCKET, ( TEXT( "+PCMSocket::GetSocket()\r\n" ) ) );
    Lock();
    if( pState )
    {
        // Read voltage information
        m_SockState.uVpp2 = m_SockState.uVpp1;

        // This is only capability we have.
        m_SockState.dwEventStatus = 0;
        m_SockState.dwEventStatus |= ( m_pBridge->IsCardInserted(m_nSlot) ?
                                       SOCK_EVENT_CD :
                                       0 );
        m_SockState.dwEventStatus |= ( m_pBridge->IsCardReady(m_nSlot) ?
                                       SOCK_EVENT_READY :
                                       0 );

        *pState = m_SockState;
        pState->dwEventChanged = 0; //pState->dwEventMask;

        DEBUGMSG( ZONE_SOCKET,
                  ( TEXT( "-PCMSocket::GetSocket(): dwEventMask: %x dwEventChanged: %x dwEventStatus: %x\r\n" ),
                    pState->dwEventMask,
                    pState->dwEventChanged,
                    pState->dwEventStatus ) );
    }
    Unlock();
    return CERR_SUCCESS;
}

//
// PDCardSetSocket
//
// @func    STATUS | PDCardSetSocket | Set the socket state of the specified socket.
// @rdesc   Returns one of the CERR_* return codes in cardserv.h.
//
// @comm    This function sets the specified socket's state and adjusts the socket
//          controller appropriately.
//          PDCardGetSocketState will usually be called first and adjustments will
//          be made to the PDCARD_SOCKET_STATE structure before PDCardSetSocketState
//          is called.  This avoids duplicated socket state on different layers and
//          it avoids unintentionally setting socket parameters.
//
// @xref <f PDCardGetSocketState>
//

STATUS CPCardSocket::CardSetSocket( PSS_SOCKET_STATE pState )
{
    Lock();
    STATUS status = CERR_SUCCESS;
    if( m_pBridge && pState )
    {
        //
        // Check socket power level indexes
        //
        m_SockState.dwEventMask = pState ->dwEventMask;
        m_SockState.dwEventChanged &= ~pState->dwEventChanged;

        // Do we need to do somthing for fIREQRouting?
        if( ( pState->dwInteruptStatus & SOCK_INT_STATUS_CHG_WAKE ) !=
            ( m_SockState.dwInteruptStatus & SOCK_INT_STATUS_CHG_WAKE ) )
        {
            m_pBridge->SetupWakeupSource( ( pState->dwInteruptStatus & SOCK_INT_STATUS_CHG_WAKE ) !=
                                          0 );
        }
        if( ( pState->dwInteruptStatus & SOCK_INT_FUNC_IRQ_ROUTING ) !=
            ( m_SockState.dwInteruptStatus & SOCK_INT_FUNC_IRQ_ROUTING ) )
        {
            m_pBridge->EnableClientInterrupt( m_nSlot, ( pState->dwInteruptStatus & SOCK_INT_FUNC_IRQ_ROUTING ) !=
                                              0 );
        };
        m_SockState.dwInteruptStatus = pState->dwInteruptStatus;
        m_SockState.fIREQRouting = pState->fIREQRouting;

        // Set the card interface (IO & memory or memory only)
        if( m_SockState.dwInterfaceType != pState->dwInterfaceType )
        {
            if( pState->dwInterfaceType == CFG_IFACE_MEMORY_IO )
            {
                m_pBridge->SetCardType( m_nSlot, CFG_IFACE_MEMORY_IO );
                m_SockState.dwInterfaceType = CFG_IFACE_MEMORY_IO;
            }
            else if( pState->dwInterfaceType == CFG_IFACE_MEMORY )
            {
                m_pBridge->SetCardType( m_nSlot, CFG_IFACE_MEMORY );
                m_SockState.dwInterfaceType = CFG_IFACE_MEMORY;
            }
        }

        if( ( pState->dwEventStatus & SOCK_EVENT_EJECT ) != 0 ||
            ( pState->dwEventStatus & SOCK_EVENT_INSERT ) != 0 )
        {
            // Ask for ejection of the card.
            DEBUGMSG( ZONE_PDD,
                      ( TEXT( "PDCardSetSocket  PCMSocket. Gernerate Artificial Eject\r\n" ) ) );
            // We have to force 
            m_pBridge->SetInterruptEvent( m_nSlot, PCMCIA_INTERRUPT_FORCE_EJECT );
        }

⌨️ 快捷键说明

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