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

📄 detection.c

📁 Cirrus EP9315 wince bsp
💻 C
字号:
//**********************************************************************
//                                                                      
// Filename: detection.c
//                                                                      
// Description: Detects the NE2000 PCMCIA and Compact Flash cards.
//
// 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 2002, All Rights Reserved                       
//                                                                      
//**********************************************************************

#include <windows.h>
#include <hwdefs.h>
#include <blcommon.h>
#include "tuple.h"

typedef struct 
{
    BOOL        bInitialized;
    USHORT      usManfID;
    UCHAR       ucProdID;
    UCHAR       ucFuncID;
} PCMCIAInfo;

static PCMCIAInfo  g_sPcmciaInfo = {0,0,0,0};

static void PCMCIAParseTuples( void );

//****************************************************************************
//  OEMHDDDetect
//****************************************************************************
// Detects to see if a compact flash card is put in the slot.
// 
//
BOOL OEMHDDDetect(void)
{
    //
    // Check to make sure that a card is inserted into the card slot.
    //    
    if(*GPIO_PFDR & ( GPIOF_PCMCIA_CD1 | GPIOF_PCMCIA_CD2 ) )
    {
        return FALSE;
    }

    //
    // Read certain locations in attribute space to see if it is a compact flash 
    // cards.
    //
    PCMCIAParseTuples();

    //
    // Check to see if it is a hard drive.
    // 
    if(g_sPcmciaInfo.ucFuncID == FUNCTION_FIXED_DISK)
        return TRUE;
    
    return FALSE;    
}

//****************************************************************************
// OEMNE2000Detect
//****************************************************************************
// Routine to detect an NE2000 card.
// 
//
BOOL OEMNE2000Detect(void)
{
    //
    // Check to make sure that a card is inserted into the card slot.
    //    
    if(*GPIO_PFDR & ( GPIOF_PCMCIA_CD1 | GPIOF_PCMCIA_CD2 ) )
    {
        return FALSE;
    }

    //
    // Read certain locations in attribute space to see if it is a compact flash 
    // cards.
    //
    PCMCIAParseTuples();

    //
    // Check to see if it is a Socket LPE NE2000 card.
    //
    if(g_sPcmciaInfo.usManfID == MANFID_SOCKET && 
      (g_sPcmciaInfo.ucProdID == PRODID_SOCKET_LPE || 
       g_sPcmciaInfo.ucProdID == PRODID_SOCKET_LPE_CF))
    {
        *(volatile unsigned short *)(PCMCIACARD_ATTRIBUTE + 0x3F8) = 0x21;
        return TRUE;
    }

    //
    // Check to see if it is a Corega NE2000 card.
    //
    if(g_sPcmciaInfo.usManfID == MANFID_COREGA && 
       g_sPcmciaInfo.ucProdID == PRODID_COREGA_PCCT )
    {
       *(volatile unsigned short *)(PCMCIACARD_ATTRIBUTE + 0x3F8) = 0x26;
        return TRUE;
    }
    
    return FALSE;    
}

//****************************************************************************
// GetCardName
//****************************************************************************
// Gets the PCMCIA cards name.
// 
//

static void PCMCIAParseTuples( void )
{
    volatile unsigned short *pCis = (volatile unsigned short *)PCMCIACARD_ATTRIBUTE;


    //
    // Return if the PCMCIA has already been parsed.
    //
    if(g_sPcmciaInfo.bInitialized)
    {
        return;
    }
        

    //
    // Search thru all the CIS tuples until find CISTPL_VERS_1
    // tuple or reach the end of all tuples
    //
    while ((*pCis & 0xFF) != CISTPL_END && ((ULONG)pCis < PCMCIACARD_ATTRIBUTE + 0x500))
    {
        switch (*pCis & 0xFF)
        {
            case CISTPL_MANFID:      
                g_sPcmciaInfo.usManfID = (pCis[2] & 0xFF) | ((pCis[3] & 0xFF) << 8);
                g_sPcmciaInfo.ucProdID = pCis[4] & 0xFF;
                break;
            case CISTPL_FUNCID:      
                g_sPcmciaInfo.ucFuncID = (UCHAR)(pCis[2] & 0xFF);
                break;
            default:
                break;
        }
        pCis += (*(pCis + 1) & 0xFF) + 2;  
    }

    EdbgOutputDebugString
    (
        "ManfID = 0x%x, ProdID = 0x%x, ucFundID = 0x%x \r\n", 
        (unsigned int)g_sPcmciaInfo.usManfID,
        (unsigned int) g_sPcmciaInfo.ucProdID,
        (unsigned int)g_sPcmciaInfo.ucFuncID
    );

    g_sPcmciaInfo.bInitialized = TRUE;
}        


⌨️ 快捷键说明

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