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

📄 cardservice.c

📁 PXA270CF卡代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
**  This software as well as the software described in it is furnished under
**  license and may only be used or copied in accordance with the terms of the
**  license. The information in this file is furnished for informational use
**  only, is subject to change without notice, and should not be construed as
**  a commitment by Intel Corporation. Intel Corporation assumes no
**  responsibility or liability for any errors or inaccuracies that may appear
**  in this document or any software that may be provided in association with
**  this document.
**  Except as permitted by such license, no part of this document may be
**  reproduced, stored in a retrieval system, or transmitted in any form or by
**  any means without the express written consent of Intel Corporation.
**
**  FILENAME:       CardService.c
**
**  PURPOSE:        This file contains the Card Services interface. This
**                  provides card configuration services for Compact Flash
**                  and PCMCIA. This is a very basic services layer and does
**                  not model the PCMCIA card services architecture.
**
**  LAST MODIFIED:  $Modtime: 7/17/03 1:01p $
******************************************************************************/

/*
*******************************************************************************
*   HEADER FILES
*******************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>

#include "systypes.h"
#include "timedelays.h"
#include "dm_errors.h"
#include "dm_debug.h"
#include "dm_perf.h"
#include "menu.h"
#include "boardcontrol.h"
#include "cardservice.h"
#include "cis.h"
#include "network.h"
#include "networkAPI.h"
#include "cardserviceAPI.h"
#include "XsPcmciaApi.h"
#include "xsmemctrl.h"
#include "dp8390API.h"
#include "xsuart.h"
#include "DM_SerialInOut.h"
#include "stdinout.h"
#include "stubs.h"
#include "boardIntCtrlApi.h"

/*
*******************************************************************************
*   EXTERNAL DEFINITIONS
*******************************************************************************
*/
extern INT DefaultSocket;
extern DP8390_ContextT * DP8390CtxP;
extern DM_MenuItem_T CfCardEnumeratedMenuList[];
extern DM_MenuItem_T MainstoneCardServicesMenuList[];

/*
*******************************************************************************
*   LOCAL DEFINITIONS
*******************************************************************************
*/
static CIS_ConfigT * defaultCfgP;
static int screenWidth = 80;

// Low-Power Ethernet CF card detected.
BOOL CfLpeDetect = FALSE;
BOOL CfSocketDetect[2] = {FALSE, FALSE};

/*
*******************************************************************************
*    Power conversion tables
*******************************************************************************
*/
static int multTab[8] = { 1,10,100,1000,10000,100000,1000000,10000000 };
static int mantTab[16] = {
  10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80, 90
};
static int extMultTab[16] = {
  10,100,100,100, 10,100, 10,100, 10,100, 10,100, 10, 10, 10, 10
};

/*
*******************************************************************************
*    Timing value conversion tables
*******************************************************************************
*/
static int timeMult[8] = { 1,10,100,1000,10000,100000,1000000,10000000 };
static int timeTab[16] = {
  00, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80
};

/*
*******************************************************************************
*    List of supported cards.
*******************************************************************************
*/
CS_CardRegistrationT cfCardsList[] = {

	"Socket Ethernet - E",
	"CF+ LPE",
	"Socket Communications Inc",
	"DP8390",
	1,

	"Socket Ethernet - C",
	"Low Power Ethernet CF",
	"Socket Communications, Inc",
	"DP8390",
	1,

    "IBM Microdrive",
    "IBM",
    "microdrive",
    "ATA",
    2,

    "Simple 8MB CF",
    "SiliconTech,Inc.",
    "8MB Compact PC Card",
    "ATA",
    3,

    "NE2000 Compatible",
    "ACCTON",
    "EN2216-PCMCIA-ETHERNET",
    "DP8390",
    4,
//===hzh
//	"NE2000 Compatible",
//	"CF",
//	"10Base-Ethernet",
//	"DP8390",
//	1,
//===
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
};

/*
*******************************************************************************
*
* FUNCTION:
*    GetParameters
*
* DESCRIPTION:
*    This routine parses the input string to determine the parameters.
*
* INPUT PARAMETERS:
*    XS_PCMCIA_DCST **ctxP - Pointer to the pointer of the PCMCIA socket Device
*                            Context Structure
*    PCHAR arg - Arguments, "DISPLAYCIS,0", "DISPLAYCIS,1", "DUMPCIS,0",
*                           "DUMPCIS,1", "DUMPIO,0", "DUMPIO,1", "ENUMERATE,0",
*                           "ENUMERATE,1", "DISABLE,0", "DISABLE,1"
*    PUINT socketP - returns the socket number.
*
* RETURNS:
*    0 - Success
*    non-zero - Error
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    None.
*
* CALLS:
*    sscanf, DM_ErrPrintf, LOGERROR, DM_CwDbgPrintf
*
* CALLED BY:
*    Ethernet test routines.
*
* PROTOTYPE:
*    static INT GettParameters(PCHAR arg, PUINT socketP);
*
*******************************************************************************
*/
static INT GetParameters(XS_PCMCIA_DCST **ctxP, PCHAR arg, PUINT socketP)
{
    XS_PCMCIA_DCST *XsPcmciaCtxP = NULL;
    UINT loggedError = 0;
    
    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "PCMCIA: First Parameter string: %s", arg);

    if (arg)
    {
        // Check first parameter
        if (sscanf(arg, "%d", socketP) == 0)
        {
            DM_ErrPrintf("PCMCIA: Invalid parameter\r\n");
            LOGERROR(loggedError, ERR_L_DP8390, 0, ERR_T_ILLPARAM, 0, 0, 0);
            return (-1);
        }

        DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "PCMCIA: Parameter value: %d", *socketP);

        // Check the socket number.
        if (*socketP == 0)
        {
            // Get slot 0 Device Context Structure.
            XsPcmciaCtxP = &XS_PCMCIA_DCS[PCMCIA_SLOT0];
        }
        else if (*socketP == 1)
        {
            // Get slot 1 Device Context Structure.
            XsPcmciaCtxP = &XS_PCMCIA_DCS[PCMCIA_SLOT1];
        }
        else
        {
            *ctxP = NULL;
            return (-1);
        }
    }

    // Save the socket number.
    XsPcmciaCtxP->socket = *socketP;
    // Return pointer to DCS.
    *ctxP = XsPcmciaCtxP;

    return (0);
}

/*
*******************************************************************************
*
* FUNCTION:
*    statSocket
*
* DESCRIPTION:
*    Determine the status of the PCMCIA socket. If there is a card inserted
*    then enable it if not already enabled.
*
* INPUT PARAMETERS:
*    PVOID *ctxP - Pointer the the PCMCIA socket Device Context Structure
*    INT socket - The socket of interest
*    INT quiet - Control error messages
*
* RETURNS:
*    0 - success
*    non-zero - error code
*
* GLOBAL EFFECTS:
*    PC card inserted into the socket is enabled.
*
* ASSUMPTIONS:
*    None
*
* CALLS:
*    The platform specific PCMCIA device driver.
*
* CALLED BY:
*    Test memnus
*
* PROTOTYPE:
*    static
*    UINT32 statSocket(PVOID *ctxP, INT socket, INT quiet);
*
*******************************************************************************
*/
static UINT32 statSocket(XS_PCMCIA_DCST *ctxP, INT socket, INT quiet)
{
    SocketStatusT * infoP = &ctxP->status;
    ErrorT retVal;

    PostDisplayProgress(ERR_L_PCMCIA, 0x84, 0);

    // Clear out the configuration record
    memset(infoP, 0, sizeof(SocketStatusT));
    PostDisplayProgress(ERR_L_PCMCIA, 0x84, 1);

    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "PCMCIA: Getting socket information");

    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "PCMCIA: ctxP: %04x", ctxP);

    // Check to make sure a card is inserted and enabled.
    ctxP->XsPcmciaGetSocketFnP(ctxP, infoP);
    PostDisplayProgress(ERR_L_PCMCIA, 0x84, 2);

    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "PCMCIA: socket status:");
    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "type: %x", infoP->type);
    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "vccLevel: %x", infoP->vccLevel);
    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "vppLevel: %x", infoP->vppLevel);
    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "stateMask: %x", infoP->stateMask);
    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "intVector: %x", infoP->intVector);
    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "attSpaceP: %x", infoP->attSpaceP);
    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "ioSpaceP: %x", infoP->ioSpaceP);
    DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "memSpaceP: %x", infoP->memSpaceP);

    if ((infoP->stateMask & (1 << SocketCardDetect)) == 0)
    {
        if (!quiet)
        {
            DM_Error("No card detected\r\n");
        }
        retVal = ERRORCODEX(ERR_L_PCMCIA, 0x84, 2, ERR_T_NODEVICE);
        return retVal;
    }

    if ((infoP->stateMask & (1 << SocketCardEnabled)) == 0)
    {
        DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "PCMCIA: Enabling socket");
        PostDisplayProgress(ERR_L_PCMCIA, 0x84, 3);
        ctxP->XsPcmciaEnableSocketFnP(ctxP);
        PostDisplayProgress(ERR_L_PCMCIA, 0x84, 4);
        DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "PCMCIA: Getting socket information");
        ctxP->XsPcmciaGetSocketFnP(ctxP, infoP);
        PostDisplayProgress(ERR_L_PCMCIA, 0x84, 5);

        if ((infoP->stateMask & (1 << SocketCardEnabled)) == 0) {
            if (!quiet)
            {
                DM_Error("Card failed to enable\r\n");
            }
            retVal = ERRORCODEX(ERR_L_PCMCIA, 0x84, 5, ERR_T_NODEVICE);
            return retVal;
        }
    }

    // Wait for ready to assert
    if ((infoP->stateMask & (1 << SocketCardReady)) == 0)
    {
        int readyRetry = 50;
        do {
            DM_CwDbgPrintf(DM_CW_SK_PCMCIA_0, "PCMCIA: Get socket");
            DM_WaitMs(10);
            PostDisplayProgress(ERR_L_PCMCIA, 0x84, 6);
            ctxP->XsPcmciaGetSocketFnP(ctxP, infoP);
            PostDisplayProgress(ERR_L_PCMCIA, 0x84, 7);
            if (--readyRetry < 0)
            {
                if (!quiet)
                {
                    DM_Error("Card ready is not asserted\r\n");
                }
                retVal = ERRORCODEX(ERR_L_PCMCIA, 0x84, 7, ERR_T_NODEVICE);
                return retVal;
            }
        } while ((infoP->stateMask & (1 << SocketCardReady)) == 0);
    }

    return (0);
}

/*
*******************************************************************************
*
* FUNCTION:
*    copyString
*
* DESCRIPTION:
*    Copy a NULL or 0xff terminated string.
*
* INPUT PARAMETERS:
*    PUCHAR dst - pointer to destination string
*    PUCHAR src - pointer to source string
*
* RETURNS:
*    Pointer to the source string.
*
* GLOBAL EFFECTS:
*    None
*
* ASSUMPTIONS:
*    None
*
* CALLS:
*    None
*
* CALLED BY:
*    decodeTuple
*
* PROTOTYPE:
*    static
*    PUCHAR copyString(PUCHAR dst, PUCHAR src);
*
*******************************************************************************
*/
static
PUCHAR copyString(PUCHAR dst, PUCHAR src)
{
    while (*src && (*src != 255))
    {
        *dst++ = *src++;
    }

    *dst++ = '\0';

    if (*src != 255)
    {
        src++;
    }

    return (src);
}

/*
*******************************************************************************
*
* FUNCTION:
*    decodeAddrValue
*
* DESCRIPTION:
*    Decode a variable length number from a Card Information Structure (CIS)
*    Configuration Tuple. Refer to the PC Card Standard, Volume 4, Metaformat
*    Specification for details.
*
* INPUT PARAMETERS:
*    PUCHAR p - Pointer to an address value entry
*    int num - Size of the address value
*    PUINT valP - The returned value
*
* RETURNS:
*    The pointer to the next address value.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    The pointer to the tuple is a valid virtual address.
*    The return pointer is a valid virtual address.
*
* CALLS:
*    None.
*
* CALLED BY:
*    decodeIO, decodeMemory, decodeTuple
*
* PROTOTYPE:
*    static
*    PUCHAR decodeAddrValue(PUCHAR p, int num, PUINT valP);
*
*******************************************************************************
*/
static
PUCHAR decodeAddrValue(PUCHAR p, int num, PUINT valP)
{
    UINT v = 0;
    INT i;
    for (i=0; i < num; i++)
    {
        v |= (*p++ << (i << 3));
    }

    *valP = v;
    return (p);
}

/*
*******************************************************************************
*
* FUNCTION:
*    decodePowerValue
*
* DESCRIPTION:
*    Decode a power value from a Card Information Structure (CIS) Configuration
*    Tuple. Refer to the PC Card Standard, Volume 4, Metaformat Specification
*    for details.
*
* INPUT PARAMETERS:
*    PUCHAR p - Pointer to the power value entry
*    INT amps - The power value
*    PINT pow - The returned value
*
* RETURNS:
*    The pointer to the next power value.
*
* GLOBAL EFFECTS:
*    None.
*
* ASSUMPTIONS:
*    The pointer to the tuple is a valid virtual address.
*    The return pointer is a valid virtual address.
*
* CALLS:
*    None.
*
* CALLED BY:
*    decodePower
*
* PROTOTYPE:
*    static
*    PUCHAR decodePowerValue(PUCHAR p, INT amps, PINT pow);
*
*******************************************************************************
*/
static
PUCHAR decodePowerValue(PUCHAR p, INT amps, PINT pow)
{
    INT mult = multTab[*p & 7];
    INT v = mantTab[(*p >> 3) & 15] * mult;
    INT vMult = mult / extMultTab[(*p >> 3) & 15];

    p++;
    while (*(p-1) & (1 << 7))
    {
        if ((*p & 0x7f) < 0x64)
        {
            v += (*p & 0x3f) * vMult;
            vMult /= 100;
        }
        p++;

⌨️ 快捷键说明

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