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

📄 atapipcmcia.h

📁 这是运行在windows ce 4.2 版本下的关于硬盘加载的驱动程序
💻 H
字号:
//
// 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.
//
#ifndef _ATAPIPCMCIA_H_
#define _ATAPIPCMCIA_H_

#include "atapi2.h"

#if 0
#define ATA_IO_REG_BASE                0x170
#define ATA_IO_REG_BASE_SECONDARY    0x1F0

#define ATA_ALT_IO_REG_BASE                 0x374
#define ATA_ALT_IO_REG_BASE_SECONDARY     0x3F4

#define ATADISK_FLAG_TRY8BIT                (1 << 0)
#define ATADISK_FLAG_ADDR_MODIFIER          (1 << 1)
#define ATADISK_FLAG_MEMORY_MAPPED          (1 << 2)
//
// GetATAWindows return codes:
//
#define GAW_SUCCESS              0
#define GAW_PRIMARY_FAIL         1
#define GAW_SECONDARY_FAIL      2
#define GAW_MEMORY_FAIL         3

//
// I/O access capabilities (wtype)
//
#define ACCESS_MEMORY_ONLY      0
#define ACCESS_IO_8BIT          1
#define ACCESS_IO_16BIT         2
#define ACCESS_IO_ANY           3

//
// States to keep track of so that we can clean up correctly 
//
#define STATE_CARD_CONFIGURED       0x01
#define STATE_CARD_IRQ_REQUESTED    0x02

//
// Device states - To guard against races during trasitions to and from
// standby mode, a disk starts in the STATE_INITING state.  Upon entering
// standby mode, a disk goes into the STATE_DEAD state and can no longer
// be used.  Coming out of standby mode, the pcmcia system will force a card
// removal and this driver will get unloaded.  Between the time the device has
// left standby mode and the card removal notice gets generated, the disk 
// should not be used at all, since as the driver is unloading it unmaps the
// ATA registers in pcmcia I/O space.
//
#define STATE_INITING 1
#define STATE_CLOSED  2
#define STATE_OPENED  3
#define STATE_DEAD    4    // Power down
#define STATE_REMOVED 5    // Power down


class CPCMCIADisk : public CDisk
{
private:
    CARD_SOCKET_HANDLE m_hSock;
    CARD_CLIENT_HANDLE m_hPcmcia;
    CARD_WINDOW_HANDLE m_hATAReg;   // Handle to ATA I/O register window
    CARD_WINDOW_HANDLE m_hATARegAlt;// Handle to ATA alternate reg window
    PWORD m_pAlignBuf;      // 16 bit aligned sector buffer
    HANDLE m_hIRQEvent;
    DWORD m_dwPCMCIAFlags;
    UINT  m_dwMemGran;
public:
    BYTE m_bState;
public:
    CPCMCIADisk(HKEY hKey) : 
        CDisk(hKey),
        m_hPcmcia(NULL),
        m_pAlignBuf(NULL),
        m_hATAReg(NULL),
        m_hATARegAlt(NULL),
        m_hIRQEvent(NULL),
        m_dwPCMCIAFlags(0),
        m_dwMemGran(0),
        m_bState(0)
    {
        memset( &m_hSock, 0, sizeof(CARD_SOCKET_HANDLE));
    }
    virtual ~CPCMCIADisk();
    virtual BOOL Init(HKEY hActiveKey);
    virtual BOOL WaitForInterrupt(DWORD dwTimeOut) 
    {
        if (WaitForSingleObject( m_hIRQEvent, dwTimeOut) != WAIT_OBJECT_0) {
            return FALSE;
        } 
        ResetEvent( m_hIRQEvent);
        return TRUE;
    }
    virtual void EnableInterrupt()  {}
    void SetEvent() { ::SetEvent(m_hIRQEvent); }   
    void RemoveCardEvent(CARD_SOCKET_HANDLE hSock);
    BOOL IsCardInserted(CARD_SOCKET_HANDLE hSock);
    virtual DWORD GetDeviceInfo(PIOREQ pIOReq);
public:
    virtual BOOL SetupDMA( PSG_BUF pSgBuf, DWORD dwSgCount, BOOL fRead) { return FALSE;}
    virtual BOOL BeginDMA(BOOL fRead) { return FALSE;}
    virtual BOOL EndDMA() { return FALSE;}
    virtual BOOL AbortDMA() { return FALSE; }
    virtual BOOL CompleteDMA(PSG_BUF pSgBuf, DWORD dwSgCount, BOOL fRead) { return FALSE;}

private:    
    BOOL Config(HKEY hActiveKey);
    DWORD GetATAWindows(DWORD dwType, DWORD dwRegBase, DWORD dwAltBase, DWORD dwModifier);
    
    inline static BOOL IsVoltageNear (WORD wSupply, WORD wDemand)
    {
        // Some cards don't report any power usage! They probably mean to be 5V.
        if (wDemand == 0)
            wDemand = 50;
    
        // True iff demand is in [0.9*supply, supply]
        // We need this because some cards ask for a nominal voltage of 3.0 V
        // rather than 3.3 V, and then don't specify min and peak values.
        // The 0.9 constant is arbitrary but sufficient for the 3.0/3.3 comparison
        // without matching the 5 V entries.
        return (wDemand <= wSupply && wDemand >= 9*wSupply/10);
    }
};
#endif
#endif //_ATAPIPCMCIA_H_


⌨️ 快捷键说明

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