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

📄 ep931xide.h

📁 EP9315开发板的Wince6.0的BSP包文件
💻 H
字号:
//**********************************************************************
//                                                                      
// Filename: EP931xide.cpp
//                                                                      
// Description: IDE driver for the internal EP931x port.
//
// 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                       
//                                                                      
//**********************************************************************
#ifndef _H_EP931XDISK
#define _H_EP931XDISK

//
// Only two ata device are supported.  A master and a slave device.
//
#define MAX_ATA_DEVICES     2

#if 0
struct  SGBuffInfo
{
    SG_BUF  m_Sg;

    //
    // This is the pointer mapped into Filesys space.
    //
    PULONG  m_pulBuffer;

    //
    // Physical Address
    //
    ULONG   m_ulPhyAddress;

    //
    // Is the Item Aligned
    //
    BOOL    m_fAligned;
};
#endif // 0

#define DMA_EVENT       0
#define IDE_EVENT       1


class CEP931xPort
{
    
    public:

        //
        // Constructor, Initialization and destructor functions.
        //
        CEP931xPort():  m_hIdeIntEvent(0), 
                        m_hDmaIntEvent(0),
                        m_hThreadWaitEvent(0),
                        m_hDmaThread(0),
                        m_bThreadExit(FALSE),
                        m_pulDmaBase( DMA_M2M0_BASE),
                        m_bDMAState(FALSE),
                        m_pucStaticBuffer(0),
                        m_ulStaticPhysBuff(0),
                        m_fForcePIO(FALSE),
                        m_bWaitForDMARQCleared(FALSE)
        {
            memset(m_hIstEvent, 0, sizeof(m_hIstEvent));
            InitializeCriticalSection( &m_CriticalSection);
        }

        ~CEP931xPort();
        BOOL        Init();


        //
        // Functions used for critical sections.
        //
        inline void TakeCS() { EnterCriticalSection( &m_CriticalSection); }
        inline void ReleaseCS() { LeaveCriticalSection( &m_CriticalSection); }


        //
        // Dma functions. 
        //
        BOOL SetupDMA( PSG_BUF pSgBuf, DWORD dwSgCount, BOOL fRead, ULONG ulCurrentMode);   
        BOOL SetupDMAInit (void);
        BOOL BeginDMA(BOOL fRead);                                     
        BOOL EndDMA();                                                 
        BOOL AbortDMA();                                               
        BOOL CompleteDMA(PSG_BUF pSgBuf, DWORD dwSgCount, BOOL fRead); 
        ULONG WaitForDmaInterrupt(DWORD dwTimeOut);
        BOOL WaitOnDMARQ(ULONG ulTime);
        BOOL WaitOnDMARQForCD(ULONG ulTime);


        void PIOMode(void);

        //
        // Debug functions.
        //
        void DumpDmaState(void);
        void DumpIDEState(void);

        void CleanUpDmaUDMAWrite(void);

        BOOL                m_bDMAState;

        //
        // DMA base address
        //
        volatile ULONG  *   m_pulDmaBase;

        //
        // Forces PIO mode because one of the drives does not support UDMA.
        //
        BOOL                m_fForcePIO;

        //
        // The DMA, IDE and thread events.
        //
        HANDLE              m_hDmaIntEvent;
        HANDLE              m_hIdeIntEvent;
        HANDLE              m_hThreadWaitEvent;


        HANDLE              m_hIstEvent[2];

        //
        // Debug informatio for the Dma and IDE ist.
        //
        LARGE_INTEGER       m_liDmaStart, m_liDmaEnd; 
        LARGE_INTEGER       m_liIdeStart, m_liIdeEnd;
        LARGE_INTEGER       m_liTotalStart, m_liTotalEnd;
        BOOL                m_fDMARead;


    private:

        static DWORD    DmaIst(LPVOID lpParameter);
        static DWORD    IdeIst(LPVOID lpParameter);

        //
        // DMA base address
        //

        /* Original is this.
        volatile ULONG  *   m_pulDmaBase;
        */

        //
        // Critical section to prevent the master and slave from talking at
        // the same time.
        //
        CRITICAL_SECTION    m_CriticalSection;

        //
        // The DMA thread handle.
        //
        HANDLE              m_hDmaThread;
        HANDLE              m_hIdeThread;

        //
        // Set to exit the DMA thread.
        //
        BOOL                m_bThreadExit;

        //
        // These are physical and virtual pointers to a DMA buffer if the scatter
        // gather list that is passed in is unaligned.
        //
        // This buffer is static.
        //
        PUCHAR              m_pucStaticBuffer;
        ULONG               m_ulStaticPhysBuff;

        //
        // If the DMA buffer is aligned then just dma it into memory.
        //
        PUCHAR              m_pucDmaBuffer;
        ULONG               m_ulDmaPhysBuff;
        ULONG               m_ulDmaCount;

        //
        // Contains the value of the current dma control register.
        //
        ULONG               m_ulDmaCtrlReg;

        //
        // Save the information for the scatter gather buffers.
        //
        PSG_BUF             m_pDMASgBuf;
        DWORD               m_dwDMASgCount;
        BOOL                m_fAligned;
        ULONG               m_ulCurrentMode;

        //
        // Get the Page shift values so that I don't have to perform a
        // multiply
        //
        ULONG               m_ulPageShift;


        BOOL                m_bWaitForDMARQCleared;
};

class CEP931xDisk : public CDisk
{
    public:
        CEP931xDisk(CEP931xPort *pPort, HKEY hDevKey);
        BOOL TranslateAddress(PDWORD);
        
        //
        // Initialization function.
        //
        virtual BOOL Init(HKEY hActiveKey);

    
        //
        // Critical Section functions.
        //
        virtual void TakeCS()
        {
            m_pPort->TakeCS();
        }    
        virtual void ReleaseCS()
        {
            m_pPort->ReleaseCS();
        }    


        //
        // Dma functions. Currently only using PIO for Disk access.
        //
        virtual BOOL SetupDMA( PSG_BUF pSgBuf, DWORD dwSgCount, BOOL fRead)
        {
            return m_pPort->SetupDMA( pSgBuf, dwSgCount, fRead, m_dwTransferModeCurrent);
        }

        virtual BOOL BeginDMA(BOOL fRead)
        {
            return m_pPort->BeginDMA(fRead);
        }                                     
        virtual BOOL EndDMA()
        {
            return m_pPort->EndDMA();
        }                                                 
        virtual BOOL AbortDMA()
        {
            return m_pPort->AbortDMA();
        }                                               
        virtual BOOL CompleteDMA(PSG_BUF pSgBuf, DWORD dwSgCount, BOOL fRead)
        {
            return m_pPort->CompleteDMA(pSgBuf, dwSgCount, fRead);
        } 
        virtual BOOL WaitOnDMARQ(ULONG ulTime)
        {
            return m_pPort->WaitOnDMARQ(ulTime);
        }
    
        virtual BOOL WaitOnDMARQForCD(ULONG ulTime)
        {
            return m_pPort->WaitOnDMARQForCD(ulTime);
        }


        virtual void SetBestTransferMode();
        virtual DWORD ForceTransferMode(BOOL fUDMAActive, ULONG ulDmaMode);


        virtual BOOL IsReadDMASupported();
        virtual BOOL IsWriteDMASupported();

        //{
        //    return ((m_Id.Capabilities & IDENTIFY_CAPABILITIES_DMA_SUPPORTED) && m_fDMAActive &&
        //            (((int)m_dwBestUDmaMode!=-1 && m_fUDMAActive) || ((int)m_dwBestMwDmaMode!=-1 && !m_fUDMAActive )));
        //}    



        //
        // Interrupt functions.
        //
        virtual BOOL WaitForInterrupt(DWORD dwTimeOut); 
        virtual ULONG WaitForDmaInterrupt(DWORD dwTimeOut);
    

        virtual void EnableInterrupt();

        //
        // This status function ack's the interrupt
        virtual BYTE GetAltStatus();
        virtual BYTE GetBaseStatus();
        virtual BYTE GetError();
        virtual BYTE GetReason();
        virtual void SelectDevice();
        virtual void WriteDriveController(BYTE bData);
        virtual void WriteAltDriveController(BYTE bData);
        virtual void SetDriveHead(BYTE bDriveHead);
        virtual void WriteCommand(BYTE bCommand);
        virtual void WriteFeature(BYTE bFeature);
        virtual void WriteSectorCount(BYTE bValue);
        virtual void WriteDriveHeadReg(BYTE bValue);
        virtual void WriteSectorNumber(BYTE bValue);
        virtual void WriteLowCount(BYTE bValue);
        virtual void WriteHighCount(BYTE bValue);
        virtual BYTE GetLowCount();
        virtual BYTE GetHighCount();
        virtual void ReadWordBuffer( PWORD pBuffer, DWORD dwCount);
        virtual void WriteWordBuffer( PWORD pBuffer, DWORD dwCount);
        virtual void ReadByteBuffer( PBYTE pBuffer, DWORD dwCount);
        virtual void WriteByteBuffer( PBYTE pBuffer, DWORD dwCount);
        virtual void WriteWord(WORD wData);
        virtual WORD ReadWord();
        virtual void WriteByte(BYTE bData);
        virtual WORD ReadByte();
        virtual DWORD GetUserDriveStatistics(UserDriveStatistics *pStats);


    private:

        void TestRoutines(void);
        void DMASectorReadTest(void);
        CEP931xPort *   m_pPort;
        BOOL            m_fForcePIO;
        DmaStatistics   m_DmaStatistics;

        //SGBuffInfo *    m_pMySgBuff;
};


#endif // _H_EP931XDISK

⌨️ 快捷键说明

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