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

📄 detection.c

📁 Ep93XX TionProV2 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 2005, All Rights Reserved                       
//                                                                      
//**********************************************************************

#include <windows.h>
#include <hwdefs.h>
#include <blcommon.h>
#include <halether.h>
#include "eboot.h"
#include "tuple.h"
#include "ide.h"
#include "fat.h"
#include "pcmciasupport.h"

extern int m_BootDeviceType;

#ifdef EDB9307_12_15

typedef struct 
{
    BOOL        bInitialized;
    USHORT      usManfID;
    UCHAR       ucProdID;
    UCHAR       ucFuncID;
} PCMCIAInfo;
static PCMCIAInfo  g_sPcmciaInfo = {0,0,0,0};

static void PCMCIAParseTuples( void );

//****************************************************************************
//  OEM_PCMCIA_Binary
//****************************************************************************
// Looks for binary in the root of a a compact flash card.
// 
//
static BOOL OEM_PCMCIA_Binary(void)
{
    UCHAR pName[] = KIMAGE_NAME;

    RETAILMSG(1, (TEXT("Initializing CF drive...\r\n")));

    //
    // Set the IDE pcmcia cards attribute space to use memory and reset the PCMCIA card.
    //
    //*CF_CONFIG = CONFIG_LEVIRQ | CONFIG_SRESET;
    *CF_CONFIG = CONFIG_LEVIRQ | 1;

    // Initialize IDE
    if (init_ide())
    {
        RETAILMSG(1, (TEXT("ERROR: IDE device initialization failed.\r\n")));
        return(FALSE);
    }

    // Initialize FAT structs
    if (!InitFAT(0))
    {
        RETAILMSG(1, (TEXT("ERROR: FAT initialization failed.\r\n")));
        return(FALSE);
    }

    RETAILMSG(1, (TEXT("Looking for NK.bin in root of CF drive.\r\n")));

    // Open image (finds starting LBA and size - inits structs for later ops)
    // Only read is supported
    if (0 == OpenFile( (PCHAR)pName))
    {
        RETAILMSG(1, (TEXT("Warning: No BIN file found in root of drive.\r\n")));
        return(FALSE);
    }

    return(TRUE);
}

//****************************************************************************
//  OEM_PCMCIA_HDDDetect
//****************************************************************************
// Detects to see if a compact flash card is put in the slot.
// 
//
static BOOL OEM_PCMCIA_HDDDetect(void)
{
    BOOL result = FALSE;

    //
    // Initialize a PCMCIA card.
    // Not necessary to reinitialize the pcmcia card.
    //
    // OEMPCMCIAInitialize();

    //
    // Check to make sure that a card is inserted into the card slot.
    //    
    if(*GPIO_PFDR & ( GPIOF_PCMCIA_CD1 | GPIOF_PCMCIA_CD2 ) )
    {
        result = FALSE;
    }
    else
    {
        //
        // 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.
        // 
        result = (g_sPcmciaInfo.ucFuncID == FUNCTION_FIXED_DISK);
        
        m_BootDeviceType =BOOT_FROM_PCMCIA;
    }
  
    return( result );
}
#endif
//****************************************************************************
//  OEM_IDE_HDDDetect
//****************************************************************************
// Detects to see if there is an IDE drive to check...
// 
//
extern void ide_enable();
static BOOL OEM_IDE_HDDDetect(void)
{
    BOOL result = FALSE;
    m_BootDeviceType = BOOT_FROM_IDE_ATADISK;

        
    if(ide_reset())
    {
        // EdbgOutputDebugString("ide_reset failed.\r\n");
        return( result );
    }
    EdbgOutputDebugString("ide_reset succeeded.\r\n");

    ide_enable();

    if (id_drive())
    {
        // EdbgOutputDebugString("id_drive failed.\r\n");
        return( result );
    }
    // EdbgOutputDebugString("id_drive succeeded.\r\n");

    return( TRUE );
}

//****************************************************************************
//  OEMHDDDetect
//****************************************************************************
// Detects to see if a compact flash card is put in the slot.
// 
//
BOOL OEMHDDDetect(void)
{
    BOOL    bRet = FALSE;
#ifdef EDB9307_12_15
    //
    // Check to see if there is a compact flash card in the PCMCIA slot.
    //
    bRet = OEM_PCMCIA_HDDDetect();
    if ( bRet )
    {
        EdbgOutputDebugString("Found Compact Flash Card in PCMCIA slot.\r\n");
        if(OEMHDDImageCheck()==-1)
        {
            bRet = FALSE;
        }
    }
#endif    
    //
    // Check to see if there i a compact flash card/IDE hard drive in the
    // IDE slot.
    //
    if ( !bRet  )
    {
        bRet = OEM_IDE_HDDDetect();
        if(bRet)
        {
            EdbgOutputDebugString("Found Hard Drive/CF Card in IDE interface.\r\n");
            if(OEMHDDImageCheck()==-1)
                bRet = FALSE;
        }
    }

    return bRet;
}

#ifdef EDB9307_12_15

//****************************************************************************
// 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;
}        

#endif

⌨️ 快捷键说明

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