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

📄 pccardlib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
     */    return pccardDosDevCreate( sock, pCard->pBlkDev,	SRAM_CACHE_SIZE, USE_PARTITIONS );#else    return (OK);#endif /* INCLUDE_DOSFS */    }/********************************************************************************* pccardSramCscIntr - PCMCIA memory card status change interrupt handler** RETURNS: OK, or ERROR if the CSC event is Ready.*/LOCAL STATUS pccardSramCscIntr    (    int sock,			/* socket no. */    int csc			/* CSC bits */    )    {    PCMCIA_CTRL *pCtrl		= &pcmciaCtrl;    PCMCIA_CARD *pCard		= &pCtrl->card[sock];    SEM_ID muteSemID		= &sramCtrl.muteSem[sock];    SEM_ID syncSemID		= &sramCtrl.syncSem[sock];    /* hot insertion */    /* hot removal */    if ((csc & PC_DETECT) && ((pCard->cardStatus & PC_DETECT) == 0x0))	{	semFlush (syncSemID);	pcmciaJobAdd ((VOIDFUNCPTR)semTerminate, (int)muteSemID, 0, 0, 0, 0, 0);	}    /* card is ready */    if (csc & PC_READY)	{	semGive (syncSemID);	return (ERROR);	}    /* other card status changes */    if ((csc & PC_BATDEAD) && (_func_logMsg != NULL))	(* _func_logMsg) ("sramDrv: socket=%d Battery dead\n",			  sock, 0, 0, 0, 0, 0);    if ((csc & PC_BATWARN) && (_func_logMsg != NULL))	(* _func_logMsg) ("sramDrv: socket=%d Battery warn\n",			  sock, 0, 0, 0, 0, 0);    if ((csc & PC_WRPROT) && (_func_logMsg != NULL))	(* _func_logMsg) ("sramDrv: socket=%d Write protect\n",			  sock, 0, 0, 0, 0, 0);    return (OK);    }#endif	/* INCLUDE_SRAM */#ifdef	INCLUDE_ELT/********************************************************************************* pccardEltEnabler - enable the PCMCIA Etherlink III card** This routine enables the PCMCIA Etherlink III (ELT) card.** RETURNS:** OK, ERROR_FIND if there is no ELT card, or ERROR if another error occurs.*/STATUS pccardEltEnabler    (    int		 sock,		/* socket no. */    ELT_RESOURCE *pEltResource, /* pointer to ELT resources */    int		 numEnt,	/* number of ELT resource entries */    FUNCPTR	 showRtn 	/* show routine */    )    {    PCMCIA_CTRL *pCtrl		= &pcmciaCtrl;    PCMCIA_CHIP *pChip		= &pCtrl->chip;    PCMCIA_CARD *pCard		= &pCtrl->card[sock];    DL_LIST *pList		= &pCard->cisTupleList;    PCCARD_RESOURCE *pResource	= &pEltResource->resource;    short manufacturerID0	= 0;    short manufacturerID1	= 0;    int functionCode		= 0;    DL_NODE *pNode;    PCMCIA_IOWIN pcmciaIowin;    CIS_TUPLE *pTuple;    char *pChar;    int flag;    int ctrl;    int sock0;    if (!pChip->installed)	return (ERROR);    for (pNode = DLL_FIRST (pList); pNode != NULL; pNode = DLL_NEXT(pNode))	{	pTuple	= (CIS_TUPLE *)((char *)pNode + sizeof (DL_NODE));	pChar	= (char *)pTuple + sizeof (CIS_TUPLE);	switch (pTuple->code)	    {	    case CISTPL_FUNCID:		functionCode = *pChar;		break;	    case CISTPL_MANFID:		manufacturerID0 = *(short *)pChar;		manufacturerID1 = *(short *)(pChar+2);		break;	    }	}    /* return if we didn't recognize the card */    if ((functionCode != FUNC_LAN) ||        (manufacturerID0 != ELT_PCMCIA_ID0) ||        ((manufacturerID1 != ELT_PCMCIA_ID1_589) &&	 (manufacturerID1 != ELT_PCMCIA_ID1_562)))	return (ERROR_FIND);    /* get un-used resource */    for (ctrl = 0; ctrl < numEnt; ctrl++)	{        pResource = &pEltResource->resource;	for (sock0 = 0; sock0 < pChip->socks; sock0++)	    {    	    PCMCIA_CARD *pCard0 = &pCtrl->card[sock0];	    if (pCard0->pResource == pResource)		break;	    }	if (sock0 == pChip->socks)	    break;	pEltResource++;	}    if (ctrl == numEnt)	{	if (_func_logMsg != NULL)	    (* _func_logMsg) ("pccardEltEnabler: sock=%d out of resource\n",			      sock, 0, 0, 0, 0, 0);	return (ERROR);	}    /* configure the card with the resource */    pCard->type		= PCCARD_LAN_ELT;    pCard->sock		= sock;    pCard->ctrl		= ctrl;    pCard->detected	= TRUE;    pCard->pResource	= pResource;    pCard->cardStatus	= (* pChip->status)(sock);    pCard->cscIntr	= (FUNCPTR)pccardEltCscIntr;    pCard->showRtn	= (FUNCPTR)showRtn;    flag = PC_PWR_AUTO | PC_IOCARD;    if (pResource->vcc == PCCARD_5V)        flag |= PC_VCC_5V;    else if (pResource->vcc == PCCARD_3V)        flag |= PC_VCC_3V;    if (pResource->vpp == PCCARD_5V)        flag |= PC_VPP_5V;    else if (pResource->vpp == PCCARD_12V)        flag |= PC_VPP_12V;    if ((* pChip->flagSet)(sock, flag) != OK)        return (ERROR);    cisConfigregSet (sock, CONFIG_STATUS_REG, 0x00);    cisConfigregSet (sock, CONFIG_OPTION_REG, COR_LEVIREQ | 0x03);    pcmciaIowin.window	= PCCARD_IOWIN0;    pcmciaIowin.flags	= MAP_ACTIVE | MAP_16BIT;    pcmciaIowin.extraws	= pResource->ioExtraws;    pcmciaIowin.start	= pResource->ioStart[0];    pcmciaIowin.stop	= pResource->ioStop[0];    if ((* pChip->iowinSet)(sock, &pcmciaIowin) != OK)        return (ERROR);    if ((* pChip->irqSet)(sock, pEltResource->intLevel) != OK)        return (ERROR);    sysOutWord (pResource->ioStart[0] + ELT_COMMAND, SELECT_WINDOW|WIN_CONFIG);    sysOutWord (pResource->ioStart[0] + RESOURCE_CONFIG, 0x3f00);    if (pCard->pNetIf != NULL)	free (pCard->pNetIf);    if ((pCard->pNetIf = malloc (sizeof(NETIF))) == NULL)	return (ERROR);    pCard->pNetIf->ifName	= "pcmcia";    pCard->pNetIf->attachRtn	= eltattach;    pCard->pNetIf->arg1		= (char *)pResource->ioStart[0];    pCard->pNetIf->arg2		= pEltResource->intVector;    pCard->pNetIf->arg3		= pEltResource->intLevel;    pCard->pNetIf->arg4		= pEltResource->rxFrames;    pCard->pNetIf->arg5		= pEltResource->connector;    pCard->pNetIf->arg6		= (int)pCard->pNetIf->ifName;    pCard->pNetIf->arg7		= 0;    pCard->pNetIf->arg8		= 0;    pCard->installed		= TRUE;    return (OK);    }/********************************************************************************* pccardEltCscIntr - ELT controller PCMCIA card status change interrupt handler.** RETURNS: OK (always).*/LOCAL STATUS pccardEltCscIntr    (    int sock,			/* socket no. */    int csc			/* CSC bits */    )    {    PCMCIA_CTRL *pCtrl		= &pcmciaCtrl;    PCMCIA_CARD *pCard		= &pCtrl->card[sock];    ELT_RESOURCE *pEltResource	= (ELT_RESOURCE *)pCard->pResource;    ELT_CTRL *pDrvCtrl		= pEltCtrl [pCard->ctrl];    /* card is inserted */    /* card is removed */    if ((csc & PC_DETECT) && ((pCard->cardStatus & PC_DETECT) == 0x0))	{        if (pCard->pResource != 0)            sysIntDisablePIC (pEltResource->intLevel);        pDrvCtrl->idr.ac_if.if_flags	= 0;        pDrvCtrl->attached		= FALSE;	}    return (OK);    }#endif	/* INCLUDE_ELT */#ifdef	INCLUDE_TFFS/********************************************************************************* pccardTffsEnabler - enable the PCMCIA-TFFS driver** This routine enables the PCMCIA-TFFS driver.** RETURNS:* OK, ERROR_FIND if there is no TFFS(Flash) card, or ERROR if another error occurs.*/STATUS pccardTffsEnabler    (    int		  sock,		  /* socket no. */    TFFS_RESOURCE *pTffsResource, /* pointer to TFFS resources */    int		  numEnt,	  /* number of SRAM resource entries */    FUNCPTR	  showRtn 	  /* TFFS show routine */    )    {    PCMCIA_CTRL *pCtrl		= &pcmciaCtrl;    PCMCIA_CHIP *pChip		= &pCtrl->chip;    PCMCIA_CARD *pCard		= &pCtrl->card[sock];    int deviceType		= 0;    PCCARD_RESOURCE *pResource;    DL_NODE *pNode;    CIS_TUPLE *pTuple;    int flag;    char *pChar;    if ((!pChip->installed) || (sock >= numEnt))	return (ERROR);    for (pNode = DLL_FIRST (&pCard->cisTupleList);	 pNode != NULL;	 pNode = DLL_NEXT(pNode))	{	pTuple	= (CIS_TUPLE *)((char *)pNode + sizeof (DL_NODE));	pChar	= (char *)pTuple + sizeof (CIS_TUPLE);	switch (pTuple->code)	    {	    case CISTPL_DEVICE:		deviceType = *pChar & 0xf0;		break;	    }	}    /* configure the card with a resource which is assigned for the socket */    if (deviceType == DTYPE_FLASH)	{        pTffsResource		+= sock;        pResource		= &pTffsResource->resource;        pCard->type		= PCCARD_FLASH;        pCard->sock		= sock;        pCard->detected		= TRUE;        pCard->pResource	= pResource;        pCard->cardStatus	= (* pChip->status)(sock);        pCard->cscIntr		= (FUNCPTR)pccardTffsCscIntr;        pCard->showRtn		= (FUNCPTR)showRtn;        pResource->memStart	&= 0xfffff000;        pResource->memStop	|= 0x00000fff;        flag = PC_PWR_AUTO;        if (pResource->vcc == PCCARD_5V)	    flag |= PC_VCC_5V;        else if (pResource->vcc == PCCARD_3V)	    flag |= PC_VCC_3V;        if ((* pChip->flagSet)(sock, flag) != OK)	    return (ERROR);        if ((pCard->initStatus = tffsDrv ()) != OK)	/* just in case */	    return (ERROR);        pCard->installed = TRUE;	}    else	return (ERROR_FIND);    /* return if we didn't recognize the card or didn't install the driver */    if (!pCard->installed)	return (ERROR);    /* we assume that a media on the socket is formated by tffsDevFormat() */    if (pcDriveNo[sock] == NONE)	{	printErr ("pccardTffs:pcDriveNo[%d] == NONE\n", sock);	return ERROR ;	}    if (pCard->pBlkDev != NULL)	free ((char *)pCard->pBlkDev);    pCard->pBlkDev = tffsDevCreate (pcDriveNo[sock], TRUE);    if (pCard->pBlkDev == (BLK_DEV *)NULL)	    {	    printErr ("Error during tffsDevCreate: %x\n", errno);	    return (ERROR);	    }    if ((pcmciaDebug) && (_func_logMsg != NULL))	(* _func_logMsg) ("TFFS sock=%d blkDev=%x\n",			      sock,pCard->pBlkDev , 0, 0, 0, 0);#ifdef INCLUDE_DOSFS    /*     * init DOS device with new block device driver and     * valid disk cache size     */    return pccardDosDevCreate( sock, pCard->pBlkDev,	TFFS_CACHE_SIZE, USE_PARTITIONS );#else    printErr ("DosFs not included, card in socket %d ignored\n", sock);#endif /* INCLUDE_DOSFS */    return (OK);    }/********************************************************************************* pccardTffsCscIntr - PCMCIA flash card status change interrupt handler** RETURNS: OK, or ERROR if the CSC event is Ready.*/LOCAL STATUS pccardTffsCscIntr    (    int sock,			/* socket no. */    int csc			/* CSC bits */    )    {    PCMCIA_CTRL *pCtrl		= &pcmciaCtrl;    PCMCIA_CARD *pCard		= &pCtrl->card[sock];    /* hot insertion */    /* hot removal */    if ((csc & PC_DETECT) && ((pCard->cardStatus & PC_DETECT) == 0x0))	{	}    /* card is ready */    if (csc & PC_READY)	{	return (ERROR);	}    /* other card status changes */    if ((csc & PC_WRPROT) && (_func_logMsg != NULL))	(* _func_logMsg) ("TFFS: socket=%d Write protect\n",			  sock, 0, 0, 0, 0, 0);    return (OK);    }#endif	/* INCLUDE_TFFS */

⌨️ 快捷键说明

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