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

📄 diskmain.h

📁 EP9315开发板的Wince6.0的BSP包文件
💻 H
📖 第 1 页 / 共 2 页
字号:
//**********************************************************************
//                                                                      
// Filename: diskmain.h
//                                                                      
// 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                       
//                                                                      
//**********************************************************************
//
// 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 _DISKMAIN_H_
#define _DISKMAIN_H_

#include <atapi2.h>
#include <atapiio.h>
#include <ideioctl.h>
#include "ntddscsi.h"


//
// Device Extension Device Flags
//

#define DFLAGS_DEVICE_PRESENT        (1 << 0)    // Indicates that some device is present.
#define DFLAGS_ATAPI_DEVICE          (1 << 1)    // Indicates whether Atapi commands can be used.
#define DFLAGS_TAPE_DEVICE           (1 << 2)    // Indicates whether this is a tape device.
#define DFLAGS_INT_DRQ               (1 << 3)    // Indicates whether device interrupts as DRQ is set after
                                                 // receiving Atapi Packet Command

#define DFLAGS_REMOVABLE_DRIVE       (1 << 4)    // Indicates that the drive has the 'removable' bit set in
                                                 // identify data (offset 128)
#define DFLAGS_MEDIA_STATUS_ENABLED  (1 << 5)    // Media status notification enabled

#define DFLAGS_DEVICE_ISDVD          (1 << 6)    // Indicates that the drive is DVD and we use 12 bit reads
#define DFLAGS_MEDIA_ISDVD           (1 << 7)    // Indicates that the media is DVD

#define DFLAGS_USE_DMA               (1 << 9)    // Indicates whether device can use DMA
#define DFLAGS_LBA                   (1 << 10)   // support LBA addressing
#define DFLAGS_MULTI_LUN_INITED      (1 << 11)   // Indicates that the init path for multi-lun has already been done.

#define DFLAGS_MSN_SUPPORT           (1 << 12)   // Device support media status notification
#define DFLAGS_AUTO_EJECT_ZIP        (1 << 13)   // bootup default enables auto eject
#define DFLAGS_WD_MODE               (1 << 14)   // Indicates that unit is WD-Mode(not SFF-Mode).

#define DFLAGS_USE_UDMA              (1 << 16)    // Indicates whether device can use UDMA
#define DFLAGS_IDENTIFY_VALID        (1 << 17)    // Indicates whether the Identify data is valid or not

#define DFLAGS_DEVICE_PWRDN          (1 << 24)  // Indicates that the device has been powered down

#define DFLAGS_DEVICE_BUSY           (1 << 25)    // Indicates whether Device is in use
#define DFLAGS_DEVICE_CDROM          (1 << 26)    // Indicates whether Device CD-ROM
#define DFLAGS_MEDIA_CHANGED         (1 << 27)    // Set If Media Changed
#define DFLAGS_DEVICE_READY          (1 << 28)    // If Removeable Device  is Ready
#define DFLAGS_DEVICE_ACTIVATED      (1 << 29)    // If Removeable Device Activated / Mounted
#define DFLAGS_DEVICE_INITIALIZED    (1 << 30)    // If FS is Loaded & Asking for Dev Info.


#ifdef FAKE_CRC_ERROR
#define DFLAGS_FAKING_CRC_ERROR      (1 << 31)    // faking crc error
#endif // FAKE_CRC_ERROR


#define     ATA_VERSION_MASK    (0xfffe)
#define     ATA1_COMPLIANCE     (1 << 1)
#define     ATA2_COMPLIANCE     (1 << 2)
#define     ATA3_COMPLIANCE     (1 << 3)
#define     ATA4_COMPLIANCE     (1 << 4)


//
// Wait type codes for WaitForDisc
//
#define WAIT_TYPE_BUSY      1
#define WAIT_TYPE_NOT_BUSY  2
#define WAIT_TYPE_READY     3
#define WAIT_TYPE_DRQ       4   // wait for data request
#define WAIT_TYPE_NOT_DRQ   5 
#define WAIT_TYPE_ERROR     6

#if (_WIN32_WCE==400)
    void StallExecution(ULONG ulMicroSec);
#endif 

//
// MAX_DMARETRYS is the number of retries before using PIO on a given read or write.
//
#define     MAX_DMARETRYS                       5
#define     MAX_DMA_FAILURES_IN_A_ROW           10


//
// These are defined for the Hardware issues in the EP931x rev D1 and E0.
//
#define     DMAWAIT_NOERROR                 0
#define     DMAWAIT_ERROR                   1
#define     DMAWAIT_ERROR_BUSY              2
#define     DMAWAIT_ERROR_STATUS            3
#define     DMAWAIT_ERROR_CRC               4
#define     DMAWAIT_ERROR_WRITE_1           5
#define     DMAWAIT_ERROR_WRITE_2           6
#define     DMAWAIT_ERROR_READ_1            7


class CDisk
{
public:
    DWORD m_dwDeviceFlags;
    DWORD dwPktSize ; //  ATAPI command packet size, currently 12 or 16 bytes
public:
    CDisk *m_pNextDisk;
    HKEY m_hDevKey;  // Points to the driver key
    HANDLE m_hDevice;
    CRITICAL_SECTION m_csDisk;
    DWORD m_dwOpenCount; // Open Count;
    DWORD m_dwStateFlag;
    TCHAR m_szActiveKey[MAX_PATH];
    TCHAR m_szDeviceKey[MAX_PATH];
public:
    //volatile PBYTE m_pATAReg;          // MmMapped pointer to ATA register range (Is in IO Space for x86)
    //volatile PBYTE m_pATARegAlt;       // MmMapped pinter to ATA Alt regsiters (Is in IO Space for x86)
    IDENTIFY_DATA m_Id;               // Data filled from ATA Identify command
    BOOL m_fAtapiDevice;
    BOOL m_fDMAActive;
 
public:
    DWORD m_dwDevice;
    DWORD m_dwDeviceId;
    DWORD m_dwPort;
    BOOL m_f16Bit; // 8 bit or 16 bit access to the port ...should only be set for now on PCMCIA
    PTSTR  m_szDiskName;
public:
    DISK_INFO m_DiskInfo;                       // Disk Geometry Info
    BOOL    m_fLBAMode;                         // TRUE => logical block addressing supported
    BOOL    m_fUseLBA48;       // Device supports extended 48 bit LBA from the revised ATA6 spec (disks > 128 GB)
    BYTE    m_bSectorsPerBlock;                 // Number of Sector Per Block
    BYTE    m_bReadCommand;                     // Current Read Command 
    BYTE    m_bWriteCommand;                    //Current Write Command;
    WORD    m_wNextByte;                        // Read but nod used byte (if not -1)
    BOOL    m_fInterruptSupported;
     
public:
    // These are required for removable media
    DWORD m_dwUnitReadyTime;                // Tick count from last unit ready check
    DWORD m_dwLastCheckTime;                

    // IO Operation 
    DWORD   m_dwBestPioCycleTime;
    DWORD   m_dwBestSwDmaCycleTime;
    DWORD   m_dwBestMwDmaCycleTime;
    DWORD   m_dwBestUDmaCycleTime;

    DWORD   m_dwTransferModeSupported;
    DWORD   m_dwBestPioMode;
    DWORD   m_dwBestSwDmaMode;
    DWORD   m_dwBestMwDmaMode;
    DWORD   m_dwBestUDmaMode;
    DWORD   m_dwTransferModeCurrent;

protected:

    BOOL        m_fUDMAActive;
    DWORD       m_ulBestMwDmaModeReg;
    DWORD       m_ulBestUDmaModeReg;

    BOOL        m_fReadBug1Failure;
    BOOL        m_fWriteBug1Failure;
    BOOL        m_fWriteBug2Failure;
    BOOL        m_fStuckBusyFailure;



public: // ATAPI stuff
    INQUIRY_DATA m_InqData;
    
public:
    CDisk()    {}
    CDisk(HKEY hKey) :
        m_dwDeviceFlags(0),
        m_pNextDisk(NULL),
        // m_pATAReg(NULL),
        // m_pATARegAlt(NULL),
        m_dwDevice(0),
        m_hDevKey( hKey),
        m_dwDeviceId(0),
        m_dwPort(0),
        m_f16Bit(FALSE),
        m_fAtapiDevice(FALSE),
        m_fInterruptSupported(FALSE),
        m_szDiskName(NULL),
        m_fDMAActive(FALSE),
        m_dwOpenCount(0),
        m_dwUnitReadyTime(0),                
        m_dwBestPioCycleTime(0),
        m_dwBestSwDmaCycleTime(0),
        m_dwBestMwDmaCycleTime(0),
        m_dwBestUDmaCycleTime(0),
        m_dwTransferModeSupported(0),
        m_dwBestPioMode(0),
        m_dwBestSwDmaMode(0),
        m_dwBestMwDmaMode(0),
        m_dwBestUDmaMode(0),
        m_dwTransferModeCurrent(0),
        m_dwStateFlag(0),
        m_dwLastCheckTime(0),
        m_fUDMAActive(FALSE),
        m_ulBestMwDmaModeReg(2),
        m_ulBestUDmaModeReg(4),
        m_fReadBug1Failure(FALSE),
        m_fWriteBug1Failure(FALSE),
        m_fWriteBug2Failure(FALSE),
        m_fStuckBusyFailure(FALSE)
    {
        InitializeCriticalSection( &m_csDisk);
        memset( &m_Id, 0, sizeof(IDENTIFY_DATA));
        memset( &m_DiskInfo, 0, sizeof(DISK_INFO));
        memset( &m_InqData, 0, sizeof(INQUIRY_DATA));
    }
    virtual ~CDisk() 
    {

⌨️ 快捷键说明

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