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

📄 nicevbend.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 5 页
字号:
            bcopy ((char *)data, (char *)END_HADDR(&pDrvCtrl->end),		   END_HADDR_LEN(&pDrvCtrl->end));            nicEvbConfig (pDrvCtrl);	/* HELP  Will it work? */            break;        case EIOCGADDR:	    if (data == NULL)		return (EINVAL);            bcopy ((char *)END_HADDR(&pDrvCtrl->end), (char *)data,		    END_HADDR_LEN(&pDrvCtrl->end));            break;        case EIOCSFLAGS:/* no driver-dependent flags */            break;        case EIOCGFLAGS:	    *(int *)data = END_FLAGS_GET(&pDrvCtrl->end);            break;        case EIOCMULTIADD:                   /* move to mux */            error = nicEvbMCastAddrAdd (pDrvCtrl, (char *)data);            break;        case EIOCMULTIDEL:                   /* move to mux */            error = nicEvbMCastAddrDel (pDrvCtrl, (char *)data);            break;        case EIOCMULTIGET:                   /* move to mux */            error = nicEvbMCastAddrGet (pDrvCtrl, (MULTI_TABLE *)data);            break;        case EIOCPOLLSTART:                  /* move to mux */            error = nicEvbPollStart (pDrvCtrl);            break;        case EIOCPOLLSTOP:                   /* move to mux */            error = nicEvbPollStop (pDrvCtrl);            break;                    case EIOCGMIB2:            if (data == NULL)                return (EINVAL);            bcopy((char *)&pDrvCtrl->end.mib2Tbl, (char *)data,                  sizeof(pDrvCtrl->end.mib2Tbl));            break;        default:            error = EINVAL;	}    return (error);    } /********************************************************************************* nicEvbStop - stop the device** This function calls BSP functions to disconnect interrupts and stop* the device from operating in interrupt mode.** RETURNS: OK or ERROR*/LOCAL STATUS nicEvbStop    (    NICEVB_END_DEVICE* pDrvCtrl    )    {    STATUS	result = OK;    NIC_DEVICE*	pNic = pDrvCtrl->pNic;        /* Stop the device. */    nicEvbWriteReg(pNic, &pNic->Imr, 0, RPAGE0);  /* disable all interrupts */    SYS_INT_DISCONNECT (pDrvCtrl, nicEvbInt, (int)pDrvCtrl, &result);    if (result == ERROR)	{	DRV_LOG (DRV_DEBUG_LOAD, "Could not diconnect interrupt!\n",                 1, 2, 3, 4, 5, 6);	}    return (result);    }/******************************************************************************** nicEvbUnload - unload a driver from the system** This function first brings down the device, and then frees any* stuff that was allocated by the driver in the load function.*/LOCAL STATUS nicEvbUnload    (    NICEVB_END_DEVICE* pDrvCtrl    )    {    if (pDrvCtrl != NULL)        {        END_OBJECT_UNLOAD (&pDrvCtrl->end);        /* free cluster memory */        if (pDrvCtrl->pRxCluster != NULL)            free (pDrvCtrl->pRxCluster);        }    return (OK);    }/********************************************************************************* nicEvbMCastAddrAdd - add a multicast address*** RETURNS: OK on success, ERROR otherwise.*/LOCAL STATUS nicEvbMCastAddrAdd    (    NICEVB_END_DEVICE *	pDrvCtrl,    char *	pAddr    )    {    int retVal;    DRV_LOG (DRV_DEBUG_IOCTL, "MCastAddrAdd\n", 0, 0, 0, 0, 0, 0);    retVal = etherMultiAdd (&pDrvCtrl->end.multiList, pAddr);    if (retVal == ENETRESET)        nicEvbAddrFilterSet (pDrvCtrl, pAddr, TRUE);    return OK; /*((retVal == OK) ? OK : ERROR);*/    }/********************************************************************************* nicEvbMCastAddrDel - remove a multicast address*** RETURNS: OK on success, ERROR otherwise.*/LOCAL STATUS nicEvbMCastAddrDel    (    NICEVB_END_DEVICE *	pDrvCtrl,    char *	pAddr    )    {    int retVal;    DRV_LOG (DRV_DEBUG_IOCTL, "MCastAddrDel\n", 0, 0, 0, 0, 0, 0);    retVal = etherMultiDel (&pDrvCtrl->end.multiList, pAddr);    if (retVal == ENETRESET)        nicEvbAddrFilterSet (pDrvCtrl, pAddr, FALSE);    return OK; /*((retVal == OK) ? OK : ERROR);*/    }/********************************************************************************* nicEvbMCastAddrGet - retreive current multicast address list*** RETURNS: OK on success; otherwise ERROR.*/LOCAL STATUS nicEvbMCastAddrGet    (    NICEVB_END_DEVICE *	pDrvCtrl,    MULTI_TABLE *pTable    )    {    DRV_LOG (DRV_DEBUG_IOCTL, "MCastAddrGet\n", 0, 0, 0, 0, 0, 0);    return (etherMultiGet (&pDrvCtrl->end.multiList, pTable));    }/*(FIXED)*//********************************************************************************* nicEvbPollStart - starting polling mode** RETURNS: OK, always.*/LOCAL STATUS nicEvbPollStart    (    NICEVB_END_DEVICE *	pDrvCtrl    )    {    int		intLevel;    NIC_DEVICE*	pNic = pDrvCtrl->pNic;		/* address of NIC chip */    DRV_LOG (DRV_DEBUG_POLL, "S ", 0, 0, 0, 0, 0, 0);    intLevel = intLock();    /* disable all interrupts */    nicEvbWriteReg (pNic, &pNic->Imr, 0x00, RPAGE0);    DRV_FLAGS_SET(NIC_FLAG_POLL);    intUnlock (intLevel);    return (OK);        }/********************************************************************************* nicEvbPollStop - stop polling mode** RETURNS: OK, always.*/LOCAL STATUS nicEvbPollStop    (    NICEVB_END_DEVICE *	pDrvCtrl    )    {    NIC_DEVICE*	pNic = pDrvCtrl->pNic;		/* address of NIC chip */    int		intLevel;    intLevel = intLock();    nicEvbWriteReg (pNic, &pNic->Imr, PRXE | OVWE, RPAGE0); /* enable int */    DRV_FLAGS_CLR(NIC_FLAG_POLL);    DRV_LOG (DRV_DEBUG_POLL, "s", 0, 0, 0, 0, 0, 0);        intUnlock (intLevel);    return (OK);    }/********************************************************************************* nicEvbPollSend - send a packet in polled mode** RETURNS: OK on success, EAGAIN on failure*/LOCAL STATUS nicEvbPollSend    (    NICEVB_END_DEVICE*	pDrvCtrl,    M_BLK*		pMblk    )    {    return (nicEvbSend (pDrvCtrl, pMblk));    }/********************************************************************************* nicEvbPollReceive - get a packet in polled mode** RETURNS: OK on success, EAGAIN on failure.*/LOCAL STATUS nicEvbPollReceive    (    NICEVB_END_DEVICE*	pDrvCtrl,    M_BLK*		pMblk    )    {    STATUS	nRetValue = OK;    NIC_CLUSTER	pCluster;    int		len;        DRV_LOG (DRV_DEBUG_POLL, "Start Poll Read!\n", 1, 2, 3, 4, 5, 6);    if ((pCluster = nicEvbReadFrame (pDrvCtrl)) == NULL)        nRetValue = EAGAIN;    else        {        NIC_RX_FRAME* pRx = (NIC_RX_FRAME*)pCluster;                len = pRx->rxHdr.cntL + (pRx->rxHdr.cntH << 8) - NIC_ETH_CRC_LEN;    	pMblk->mBlkHdr.mFlags |= M_PKTHDR; /* set the packet header */	pMblk->mBlkHdr.mLen = len;	   /* set the data len */	pMblk->mBlkPktHdr.len = len;	   /* set the total len */        NIC_FRAME_DATA_ADDR_GET(pCluster);        bcopy (pCluster, (char *)pMblk->mBlkHdr.mData, len);        netClFree (pDrvCtrl->end.pNetPool, (char*)pRx);                }        DRV_LOG (DRV_DEBUG_POLL, "End Poll Read!\n", 1, 2, 3, 4, 5, 6);            return nRetValue;    }/********************************************************************************* nicEvbHashIndex - compute the hash index for an ethernet address** RETURNS: hash index for an ethernet address.*/LOCAL int nicEvbHashIndex    (    char *	eAddr    )    {    UINT8	eAddrByte;    int		index;                       /* hash index - return value */    int		byte;                        /* loop - counter */    int		bit;                         /* loop - counter */    UINT	crc = 0xffffffff;    UINT8	msb;    for (byte=0; byte<6; byte++)        {        eAddrByte = eAddr[byte];        for (bit=0; bit<8; bit++)            {            msb = crc >> 31;            crc <<= 1;            if (msb ^ (eAddrByte & 0x1))                {                crc ^= NIC_CRC_POLY;                crc |= 0x1;                }            eAddrByte >>= 1;            }        }    /* Just want the 6 most significant bits. */        index = crc >> 26 ;    return index;    } /******************************************************************************** nicEvbAddrFilterSet - set the address filter for multicast addresses** This routine goes through all of the multicast addresses on the list* of addresses (added with the MCastAddrAdd() routine) and sets the* device's filter correctly.** NOMANUAL*/LOCAL void nicEvbAddrFilterSet    (    NICEVB_END_DEVICE	*pDrvCtrl,    char*		pAddr,    BOOL		bSet    )    {    UINT8		nHashIndex;    /* get hash index for the address */    nHashIndex = nicEvbHashIndex (pAddr);    /* Turn on the corresponding bit in the filter. */    nicEvbMARSet (pDrvCtrl, nHashIndex, bSet);    }/********************************************************************************* nicEvbMARSet - sets/resets the MAR for the specified hash index** This routine sets/resets the MAR bit for the specified hash index** RETURNS: OK or ERROR.*/LOCAL void nicEvbMARSet    (    NICEVB_END_DEVICE*	pDrvCtrl,        UINT8		index,		/* hash index */    BOOL		bSet		/* Set/Reset */    )    {    UINT8	nRegOffset	= index;    UINT8	nBitPosition	= index;    UINT8	nBitMask = (UINT8)0x01;    UINT8	nValue;    char*	pMAR = (char*)pDrvCtrl->pNic;        /* Finde register and bit position */    nBitPosition = nBitPosition & 0x07;  /* 3 LSB bits */    nRegOffset >>= 3;		     /* next 3 bits */    nBitMask <<= nBitPosition;    pMAR += NIC_IR_MAR0 + nRegOffset;    /* set the bit in bit array*/    nValue = nicEvbReadReg (pDrvCtrl->pNic, pMAR, RPAGE1);    DRV_LOG (DRV_DEBUG_LOAD, "Hash Index:%d MAR Offset:%d value:%d\n",             index, nRegOffset, nValue, 4, 5, 6);        if (bSet)        {        nValue |= nBitMask;	/* set */        }    else        {        nBitMask = ~nBitMask;	/* reset */        nValue &= nBitMask;                }        nicEvbWriteReg (pDrvCtrl->pNic, pMAR, nValue, RPAGE1);        DRV_LOG (DRV_DEBUG_LOAD, "Hash Index:%d MAR Offset:%d value:%d\n",             index, nRegOffset, nValue, 4, 5, 6);        }/* (OLD) *//********************************************************************************* nicReset - reset of interface** This routine performs a software reset of the ST-NIC device.** RETURNS: N/A.** NOMANUAL*/LOCAL void nicEvbReset    (    NICEVB_END_DEVICE*		pDrvCtrl    )    {    NIC_DEVICE *	pNic = pDrvCtrl->pNic;    nicEvbWriteCr (pNic, STP | ABORT | RPAGE0);    taskDelay (2);			/* wait at least 1.6 mSec */    }

⌨️ 快捷键说明

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