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

📄 pccardlib.c

📁 用于EQUATOR处理器上的FAT32文件系统(vxWorks5.5)
💻 C
📖 第 1 页 / 共 3 页
字号:
/* pccardLib.c - PC CARD enabler library */

/* Copyright 1984-1996 Wind River Systems, Inc. */
#include "copyright_wrs.h"

/*
modification history
--------------------
01o,31aug99,jkf  changed from cbio.h to cbioLib.h
01n,03nov98,lrn  cleanup warnings
01m,06oct98,lrn  merge DosFs 2.0 changes into T2.0, DosFs 2.0 API for TFFS
01l,17sep98,lrn  reworked DosFs 2.0 support and memory leak issues
01k,13jul98,lrn  DosFs 2.0 - can not delete a DOS device
01j,19jan98,hdn  added a check to see if the socket is registered.
01i,11dec97,hdn  added TFFS support for flash PC card.
01h,19mar97,hdn  deleted a line that writes 0 to the ELT's address config reg.
01g,16jan97,hdn  initialized pcmciaCtrl.
01f,17nov96,jdi  doc: tweaks.
01e,08nov96,dgp  doc: final formatting
01d,28mar96,jdi  doc: cleaned up language and format.
01c,08mar96,hdn  added more descriptions.
01b,22feb96,hdn  cleaned up
01a,19oct95,hdn  written.
*/

/*
DESCRIPTION
This library provides generic facilities for enabling PC CARD.
Each PC card device driver needs to provide an enabler routine and
a CSC interrupt handler.  The enabler routine must be in the
`pccardEnabler' structure.
Each PC card driver has its own resource structure, `xxResources'.  The
ATA PC card driver resource structure is `ataResources' in
sysLib, which also supports a local IDE disk.
The resource structure has a PC card common resource structure in
the first member.  Other members are device-driver dependent resources.

The PCMCIA chip initialization routines tcicInit() and pcicInit() are
included in the PCMCIA chip table `pcmciaAdapter'.
This table is scanned when the PCMCIA library is initialized.  If the
initialization routine finds the PCMCIA chip, it registers all function
pointers of the PCMCIA_CHIP structure.

A memory window defined in `pcmciaMemwin' is used to access
the CIS of a PC card through the routines in cisLib.

SEE ALSO
pcmciaLib, cisLib, tcic, pcic

*/

/* LINTLIBRARY */

#include "private/funcBindP.h"
#include "drv/pcmcia/pcmciaLib.h"
#include "drv/pcmcia/cisLib.h"
#include "drv/pcmcia/pcic.h"
#include "drv/pcmcia/tcic.h"
#include "drv/pcmcia/sramDrv.h"
#include "drv/hdisk/ataDrv.h"
#include "cbioLib.h"
#include "dcacheCbio.h"
#include "dpartCbio.h"

#ifdef	INCLUDE_ELT
#include "net/if.h"
#include "netinet/if_ether.h"
#include "drv/netif/if_elt.h"
#endif	/* INCLUDE_ELT */

#ifdef	INCLUDE_TFFS
#include "tffs/tffsDrv.h"
#endif	/* INCLUDE_TFFS */


/* defines */

#define ELT_PCMCIA_ID0		0x0101	/* manufacturer code */
#define ELT_PCMCIA_ID1_562	0x0562	/* manufacturer info for 3C562 */
#define ELT_PCMCIA_ID1_589	0x0589	/* manufacturer info for 3C589B */

/* XXX it should go in pc386/pc.h */
#define TFFS0_MEM_START		0xd8000	/* mem start addr for TFFS in sock 0 */
#define TFFS0_MEM_STOP		0xd9fff	/* mem stop addr for TFFS in sock 0 */
#define TFFS1_MEM_START		0xda000	/* mem start addr for TFFS in sock 1 */
#define TFFS1_MEM_STOP		0xdbfff	/* mem stop addr for TFFS in sock 1 */


/* externs */
IMPORT BOOL pcmciaDebug;
/* dont use partition table decoder unless ATA is included */
#define	USE_PARTITIONS	FALSE

#ifdef	INCLUDE_ELT
IMPORT ELT_CTRL		*pEltCtrl [];
LOCAL STATUS	pccardEltCscIntr  (int sock, int csc);
#endif	/* INCLUDE_ELT */

#ifdef	INCLUDE_ATA
IMPORT ATA_CTRL		ataCtrl [ATA_MAX_CTRLS];
LOCAL STATUS	pccardAtaCscIntr  (int sock, int csc);
#undef	USE_PARTITIONS
#define	USE_PARTITIONS	TRUE
#endif	/* INCLUDE_ATA */

#ifdef	INCLUDE_SRAM
IMPORT SRAM_CTRL	sramCtrl;
IMPORT int		sramResourceNumEnt;
LOCAL STATUS	pccardSramCscIntr (int sock, int csc);
#endif	/* INCLUDE_SRAM */

#ifdef	INCLUDE_TFFS
IMPORT char		pcDriveNo [];
LOCAL STATUS	pccardTffsCscIntr (int sock, int csc);
#endif	/* INCLUDE_TFFS */


/* globals */

PCMCIA_CTRL pcmciaCtrl = {PCMCIA_SOCKS, PCMCIA_MEMBASE} ;

PCMCIA_MEMWIN pcmciaMemwin [] =
    {
    {0, 0, 0, CIS_MEM_START, CIS_MEM_STOP, 0},	/* CIS extraction */
    {0, 0, 0, CIS_REG_START, CIS_REG_STOP, 0},	/* config registers */
    };

PCMCIA_ADAPTER pcmciaAdapter [] =
    {
    {PCMCIA_PCIC, PCIC_BASE_ADR, PCIC_INT_VEC, PCIC_INT_LVL, pcicInit, NULL},
    {PCMCIA_TCIC, TCIC_BASE_ADR, TCIC_INT_VEC, TCIC_INT_LVL, tcicInit, NULL}
    };

#ifdef	INCLUDE_ELT
ELT_RESOURCE eltResources[] =
    {
    {
     {
     5, 0,
     {ELT0_IO_START, 0}, {ELT0_IO_STOP, 0}, 0,
     0, 0, 0, 0, 0
     },
     ELT0_INT_VEC, ELT0_INT_LVL, ELT0_NRF, ELT0_CONFIG
    },
    {
     {
     5, 0,
     {ELT1_IO_START, 0}, {ELT1_IO_STOP, 0}, 0,
     0, 0, 0, 0, 0
     },
     ELT1_INT_VEC, ELT1_INT_LVL, ELT1_NRF, ELT1_CONFIG
    }
    };
#endif	/* INCLUDE_ELT */

#ifdef	INCLUDE_SRAM
SRAM_RESOURCE sramResources[] =
    {
    {
     {
     5, 0,
     {0, 0}, {0, 0}, 0,
     SRAM0_MEM_START, SRAM0_MEM_STOP, 1, 0x0, SRAM0_MEM_LENGTH
     }
    },
    {
     {
     5, 0,
     {0, 0}, {0, 0}, 0,
     SRAM1_MEM_START, SRAM1_MEM_STOP, 1, 0x0, SRAM1_MEM_LENGTH
     }
    },
    {
     {
     5, 0,
     {0, 0}, {0, 0}, 0,
     SRAM2_MEM_START, SRAM2_MEM_STOP, 1, 0x0, SRAM2_MEM_LENGTH
     }
    },
    {
     {
     5, 0,
     {0, 0}, {0, 0}, 0,
     SRAM3_MEM_START, SRAM3_MEM_STOP, 1, 0x0, SRAM3_MEM_LENGTH
     }
    }
    };
#endif	/* INCLUDE_SRAM */

#ifdef	INCLUDE_TFFS
TFFS_RESOURCE tffsResources[] =
    {
    {
     {
     5 /* vcc */, 0 /* vpp */,
     {0, 0}, {0, 0}, 0,
     TFFS0_MEM_START, TFFS0_MEM_STOP, 2 /* extra wait state */,
     0x0 /* offset card address */, 0x0 /* size of the memory */
     }
    },
    {
     {
     5 /* vcc */, 0 /* vpp */,
     {0, 0}, {0, 0}, 0,
     TFFS1_MEM_START, TFFS1_MEM_STOP, 2 /* extra wait state */,
     0x0 /* offset card address */, 0x0 /* size of the memory */
     }
    }
    };
#endif	/* INCLUDE_TFFS */

PCCARD_ENABLER pccardEnabler [] =
    {
#ifdef	INCLUDE_ELT
    {
     PCCARD_LAN_ELT, (void *)eltResources, NELEMENTS(eltResources),
     (FUNCPTR)pccardEltEnabler, NULL
    },
#endif	/* INCLUDE_ELT */

#ifdef	INCLUDE_ATA
    {
     PCCARD_ATA, (void *)ataResources, NELEMENTS(ataResources),
     (FUNCPTR)pccardAtaEnabler, NULL
    },
#endif	/* INCLUDE_ATA */

#ifdef	INCLUDE_TFFS
    {
     PCCARD_FLASH, (void *)tffsResources, NELEMENTS(tffsResources),
     (FUNCPTR)pccardTffsEnabler, NULL
    },
#endif	/* INCLUDE_TFFS */

#ifdef	INCLUDE_SRAM
    {
     PCCARD_SRAM, (void *)sramResources, NELEMENTS(sramResources),
     (FUNCPTR)pccardSramEnabler, NULL
    }
#endif	/* INCLUDE_SRAM */
    };

int pcmciaAdapterNumEnt = NELEMENTS (pcmciaAdapter);
int pccardEnablerNumEnt = NELEMENTS (pccardEnabler);


/* locals */

#ifdef	INCLUDE_SRAM
LOCAL int sramSizeTable [] = {512, 2000, 8000, 32000,
			      128000, 512000, 2000000, 0};
#endif	/* INCLUDE_SRAM */

#ifdef INCLUDE_DOSFS
#define ATA_CACHE_SIZE	(128*1024)
#define SRAM_CACHE_SIZE	(2*1024)
#define TFFS_CACHE_SIZE	(32*1024)

CBIO_DEV_ID sockCbioDevs[ PCIC_MAX_SOCKS * NELEMENTS (pcmciaAdapter) ];
char * sockDevNames[ PCIC_MAX_SOCKS * NELEMENTS (pcmciaAdapter) ] =
		 { "/card0", "/card1", "/card2", "/card3",
    	     	   "/card4", "/card5", "/card6", "/card7", NULL };
#endif /* INCLUDE_DOSFS */

/*******************************************************************************
*
* pccardMount - mount a DOS file system
*
* This routine mounts a DOS file system.
*
* RETURNS: OK or ERROR.
*/
STATUS pccardMount
    (
    int	 sock,			/* socket number */
    char *pName			/* name of a device */
    )

    {

    printErr( "This function is discontinued\n" );
    return ERROR;

#if FALSE
    PCMCIA_CTRL *pCtrl		= &pcmciaCtrl;
    PCMCIA_CHIP *pChip		= &pCtrl->chip;
    PCMCIA_CARD *pCard		= &pCtrl->card[sock];
    DOS_VOL_DESC *pDos		= pCard->pDos;

    if ((!pChip->installed) || (!pCard->installed) || (sock >= pChip->socks))
        return (ERROR);

    if (pDos != NULL)
	{
	iosDevDelete (&pDos->dosvd_devHdr);
	free ((char *)pDos);
	return (ERROR);
	}

    pCard->pDos = dosFsDevInit (pName, pCard->pBlkDev, NULL);
    if (pCard->pDos == NULL)
	return (ERROR);

    return (OK);
#endif /* FALSE */
    }

/*******************************************************************************
*
* pccardMkfs - initialize a device and mount a DOS file system
*
* This routine initializes a device and mounts a DOS file system.
*
* RETURNS: OK or ERROR.
*/
STATUS pccardMkfs
    (
    int	 sock,			/* socket number */
    char *pName			/* name of a device */
    )

    {

    printErr( "This function is discontinued. Use dosFsVolFormat()\n" );
    return ERROR;

#if FALSE
    PCMCIA_CTRL *pCtrl		= &pcmciaCtrl;
    PCMCIA_CHIP *pChip		= &pCtrl->chip;
    PCMCIA_CARD *pCard		= &pCtrl->card[sock];
    DOS_VOL_DESC *pDos		= pCard->pDos;

    if ((!pChip->installed) || (!pCard->installed) || (sock >= pChip->socks))
        return (ERROR);

    if (pDos != NULL)
	{
	iosDevDelete (&pDos->dosvd_devHdr);
	free ((char *)pDos);
	return (ERROR);
	}

    pCard->pDos = dosFsMkfs (pName, pCard->pBlkDev);
    if (pCard->pDos == NULL)
	return (ERROR);

    return (OK);
#endif /* FALSE */
    }

#ifdef INCLUDE_DOSFS
/*******************************************************************************
*
* pccardDosDevCreate - create DOSFS device for on PCMCIA socket.
*
* This routine creates a DOS FS device for PCMCIA socket # <sock>
* with predefined name based on socket number.  The device will use
* device driver pointed by <pBlkDev> to access device on the low level.
*
* If DOS device already exists, only low level driver is changed to
* reflect the new devices physical parameters.
*
* RETURNS: STATUS.
*/
LOCAL STATUS pccardDosDevCreate
    (
    int		sock,
    void *	pBlkDev,
    int		cacheSize,
    BOOL	partitions
    )
    {
    void * subDev = NULL ;
    void * masterCbio ;
    IMPORT STATUS usrFdiskPartRead();
    STATUS stat;

    /* create cache of appropriate size and DOS device on top of it */

    if ( sockCbioDevs[ sock ] == NULL )
    	{

    	sockCbioDevs[ sock ] =
    	    	dcacheDevCreate(pBlkDev, 0, cacheSize,
    	    	    	    	 sockDevNames[ sock ] );
    	if( sockCbioDevs[ sock ] == NULL )
    	    {
    	    printErr ("Error during dcacheDevCreate: %p\n",
    	    	      (void *)errno );
    	    return (ERROR);
    	    }
   	if ( partitions )
	    {
    	    masterCbio = dpartDevCreate(sockCbioDevs[ sock ] ,
			 1, (FUNCPTR) usrFdiskPartRead );

    	    if( masterCbio == NULL)
            	{
	    	printErr ("Error creating partition manager: %x\n", errno);
            	return (ERROR);
            	}

	    subDev = (void *) dpartPartGet(masterCbio,0);
	    }
	else
	    {
	    subDev = sockCbioDevs[ sock ];
	    }
    	return dosFsDevCreate( sockDevNames[ sock ],
    	    	    	       subDev, 0,0 );
    	}

    /* resize cache and RESET device */
    dcacheDevMemResize (sockCbioDevs[ sock ], cacheSize);

    stat = cbioIoctl (sockCbioDevs[ sock ], CBIO_RESET, pBlkDev );

    if( stat != OK )

⌨️ 快捷键说明

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