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

📄 ax88796end.c

📁 操作系统vxworks
💻 C
📖 第 1 页 / 共 5 页
字号:
	SYS_IN_CHAR (pDrvCtrl, ENE_CMD, &cmdStat);

    ENDLOGMSG (("ax88796PollSend: done: imask=%x flags=%x\n",
		pDrvCtrl->imask, pDrvCtrl->flags, 0, 0, 0, 0));

    return (OK);
    }

/*******************************************************************************
*
* ax88796PollStart - start polled mode operations
*
* RETURNS: OK or ERROR.
*/

LOCAL STATUS ax88796PollStart
    (
    AX88796END_DEVICE* pDrvCtrl
    )
    {
    int oldLevel;

    oldLevel = intLock ();
    ENDLOGMSG (("ax88796PollStart: imask=%x flags=%x\n",
		pDrvCtrl->imask, pDrvCtrl->flags, 0, 0, 0, 0));
    pDrvCtrl->flags |= END_POLLING;
    pDrvCtrl->imask = 0;
    SYS_OUT_CHAR (pDrvCtrl, ENE_INTMASK, pDrvCtrl->imask);
    intUnlock (oldLevel);

    return (OK);
    }

/*******************************************************************************
*
* ax88796PollStop - stop polled mode operations
*
* This function terminates polled mode operation.  The device returns to
* interrupt mode.
*
* The device interrupts are enabled, the current mode flag is switched
* to indicate interrupt mode and the device is then reconfigured for
* interrupt operation.
*
* RETURNS: OK or ERROR.
*/

LOCAL STATUS ax88796PollStop
    (
    AX88796END_DEVICE* pDrvCtrl
    )
    {
    int oldLevel;

    oldLevel = intLock ();
    pDrvCtrl->flags &= ~END_POLLING;
    pDrvCtrl->imask = AX88796_ALL_INTS;
    /* leave recv int disabled if in receive loop. */
    if (pDrvCtrl->flags & END_RECV_HANDLING_FLAG)
	pDrvCtrl->imask &= ~IM_PRXE;
    SYS_OUT_CHAR (pDrvCtrl, ENE_INTMASK, pDrvCtrl->imask);

    ENDLOGMSG (("ax88796PollStop: imask=%x flags=%x\n",
		pDrvCtrl->imask, pDrvCtrl->flags, 0, 0, 0, 0));
    intUnlock (oldLevel);
    return (OK);
    }

/******************************************************************************
*
* ax88796AddrFilterSet - set the address filter for multicast addresses
*
* This routine loops through all of the multicast addresses on the list
* of addresses (added with the endAddrAdd() routine) and sets the
* device's filter appropriately.
*
* NOMANUAL
*/
LOCAL void ax88796AddrFilterSet
    (
    AX88796END_DEVICE *pDrvCtrl
    )
    {
    int i;
    int eAddr;
    u_char enetChar;
    u_char *pCp;
    u_long crc;
    ETHER_MULTI* pCurr;

    ENDLOGMSG (("ax88796AddrFilterSet\n", 0, 0, 0, 0, 0, 0));

    /*
     * There are 8 multicast address registers (MAR0-7) which
     * decode the multicast addresses to be received.  These
     * registers provide filtering of multicast addresses hashed
     * by the CRC hardware logic.  All destination addresses are
     * fed through the CRC hardware logic and when the last bit
     * of the destination address enters the CRC hardware, the
     * 6 MSB's of the CRC generator are latched.  These six bits
     * are then used to index a unique filter bit (FB0-63, 64 since
     * there are eight-8bit registers, and 2^6 = 64) in the multicast
     * address registers.   If the index filter bit is set,
     * the packet is accepted.
     *
     * To configure MAR0-7 to accept a specific multicast address,
     * the above sequence must be also be duplicated in software to
     * determine which filter bit in the multicast registers should
     * be set for a given multicast address.   Several bits can be
     * set to accept several multicast addresses.
     *
     * The standard AUTODIN-II polynomial is used for the 32-bit CRC
     * hash index calculation.  The AUTODIN-II, FDDI, ethernet
     * polynomial for 32 bit CRC is 0x04c11db7, as deemed kosher
     * by the mighty polynomial gods of error awareness.
     *
     * The polynomial is expressed:
     *
     *   ( x^32 + x^26 + x^23 + x^22 + x^16 +
     *     x^12 + x^11 + x^10 + x^8  + x^7  +
     *            x^5  + x^4  + x^2  + x^1  + 1 ) = 0x04c11db7
     *
     * Where x = base 2 (binary) and x^32 is ignored for CRC.
     *
     */

    /* initialize (clear) all filter bits */

    for (i = 0; i < 8; ++i)
	pDrvCtrl->mcastFilter[i] = 0;


    /* set the proper MAR0-7 filter bit(s) for every address */

    for (pCurr = END_MULTI_LST_FIRST (&pDrvCtrl->endObj);
	 pCurr != NULL;
	 pCurr = END_MULTI_LST_NEXT(pCurr))
	{
	pCp = (unsigned char *)&pCurr->addr;

	crc = 0xffffffff;  /* initial CRC seed */

	/* build the CRC for the 6 byte adrs */

	for (eAddr = 0; eAddr < 6; eAddr++)
	    {
	    enetChar = *pCp++;
            crc = ax88796CrcWork (enetChar, crc);
	    }

	/*
	 * We now have the crc for the current address and we are
	 * interested in the 6 most significant bits of the crc
	 * for indexing because that is whats latched by the CRC
	 * hardware logic.
	 *
	 * Which of the eight MAR registers, 0-7, is indexed with
	 * the upper three bits of the six.  Which of the eight bits
	 * to set in that MAR register is indexed by the lower three
	 * bits of the six.
	 */

	/* get six msb */

	crc >>= 26;
	crc &= 0x3f;


	/* high 3 bit index MAR reg, low three bits index reg bit */

	pDrvCtrl->mcastFilter[crc >> 3] |= (1 << (crc & 7));
	}
    }

/*****************************************************************************
*
* ax88796CrcWork - return CRC using a 32 bit polynomial
*
* This is a work routine used by ax88796AddrFilterSet
*
* NOMANUAL
*
*/

LOCAL UINT32 ax88796CrcWork
    (
    UINT8 inChar,
    UINT32 inCrc
    )
    {
    UINT8 work = 0;
    UINT8 wrap;
    int i;

    /*
     * standard CRC algorithm, 8 bit stream.
     */

    for (i = 0; i < 8; i++)
        {
        wrap = (inCrc >> 31);
        inCrc <<= 1;
        work  = ((work << 1) | wrap) ^ inChar;
        if (work & 1)
            {
            inCrc ^= CRC32_POLYNOMIAL;
            }
         work >>= 1;
         inChar >>= 1;
         }
     return (inCrc);
     }


/*****************************************************************************
*
* ax88796MCastAdd - add a multicast address for the device
*
* This routine adds a multicast address to whatever the driver
* is already listening for.  It then resets the address filter.
*/

LOCAL STATUS ax88796MCastAdd
    (
    void*	pCookie,	/* device ptr */
    char*	pAddress
    )
    {
    AX88796END_DEVICE* pDrvCtrl = (AX88796END_DEVICE *) pCookie;

    ENDLOGMSG (("ax88796MCastAdd - %02x:%02x:%02x:%02x:%02x:%02x\n",
		pAddress[0]&0xff, pAddress[1]&0xff, pAddress[2]&0xff,
		pAddress[3]&0xff, pAddress[4]&0xff, pAddress[5]&0xff));

	if (etherMultiAdd (&pDrvCtrl->endObj.multiList, pAddress) == ENETRESET)
	{
	ax88796Config (pDrvCtrl, TRUE);
	}

    return (OK);
    }

/*****************************************************************************
*
* ax88796MCastDel - delete a multicast address for the device
*
* This routine removes a multicast address from whatever the driver
* is listening for.  It then resets the address filter.
*/

LOCAL STATUS ax88796MCastDel
    (
    void*	pCookie,	/* device ptr */
    char*	pAddress
    )
    {
    AX88796END_DEVICE* pDrvCtrl = (AX88796END_DEVICE *) pCookie;

    ENDLOGMSG (("ax88796MCastDel - %02x:%02x:%02x:%02x:%02x:%02x\n",
		pAddress[0]&0xff, pAddress[1]&0xff, pAddress[2]&0xff,
		pAddress[3]&0xff, pAddress[4]&0xff, pAddress[5]&0xff));

    if (etherMultiDel (&pDrvCtrl->endObj.multiList,
		       (char *)pAddress) == ENETRESET)
	{
	ax88796Config (pDrvCtrl, TRUE);
	}

    return (OK);
    }

/*****************************************************************************
*
* ax88796MCastGet - get the multicast address list for the device
*
* This routine gets the multicast list of whatever the driver
* is already listening for.
*/

LOCAL STATUS ax88796MCastGet
    (
    void*		pCookie,	/* device ptr */
    MULTI_TABLE*	pTable
    )
    {
    int error;
    AX88796END_DEVICE* pDrvCtrl = (AX88796END_DEVICE *) pCookie;

    ENDLOGMSG (("ax88796MCastGet\n", 0, 0, 0, 0, 0, 0));
    error = etherMultiGet (&pDrvCtrl->endObj.multiList, pTable);

    return (error);
    }

/******************************************************************************
*
* ax88796Stop - 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 ax88796Stop
    (
    void *pCookie
    )
    {
    STATUS result = OK;
    AX88796END_DEVICE* pDrvCtrl;

    pDrvCtrl = (AX88796END_DEVICE *) pCookie;

    /* mark the interface -- down */

    END_FLAGS_CLR (&pDrvCtrl->endObj, IFF_UP | IFF_RUNNING);

    /* Disable device interrupts */

    pDrvCtrl->imask = 0;

    SYS_OUT_CHAR (pDrvCtrl, ENE_INTMASK, pDrvCtrl->imask);

    /* stop device */

    SYS_OUT_CHAR (pDrvCtrl, ENE_CMD, CMD_NODMA | CMD_PAGE0 | CMD_STOP);
    
    /* delay at least 1.5 ms */
    
    delay (3000);

    ENDLOGMSG (("ax88796Stop\n", 0, 0, 0, 0, 0, 0));

    SYS_INT_DISCONNECT (pDrvCtrl, ax88796Int, (int)pDrvCtrl, &result);

    if (result == ERROR)
	ENDLOGMSG (("Could not disconnect interrupt!\n", 1, 2, 3, 4, 5, 6));

    return (result);
    }

/******************************************************************************
*
* ax88796Unload - 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 ax88796Unload
    (
    void *pCookie
    )
    {
    AX88796END_DEVICE* pDrvCtrl = (AX88796END_DEVICE *) pCookie;

    ENDLOGMSG (("ax88796Unload\n", 0, 0, 0, 0, 0, 0));

    END_OBJECT_UNLOAD (&pDrvCtrl->endObj); /* generic end unload functions */

    return (OK);
    }

/******************************************************************************
*
* ax88796EnetAddrGet - get enet address
*
* NOMANUAL
*/

LOCAL void ax88796EnetAddrGet
    (
    AX88796END_DEVICE* pDrvCtrl
    )
    {
    char ax88796EnetAddr[7];
    int i;

    if (pDrvCtrl->usePromEnetAddr)
	{
	SYS_OUT_CHAR (pDrvCtrl, ENE_CMD, CMD_NODMA | CMD_PAGE0 | CMD_START);
	SYS_OUT_CHAR (pDrvCtrl, ENE_RSAR0, AX88796_EADDR_LOC);
	SYS_OUT_CHAR (pDrvCtrl, ENE_RSAR1, AX88796_CONFIG_PAGE);
	SYS_OUT_CHAR (pDrvCtrl, ENE_RBCR0, (EADDR_LEN * 2) & 0xff);
	SYS_OUT_CHAR (pDrvCtrl, ENE_RBCR1, (EADDR_LEN * 2) >> 8);
	SYS_OUT_CHAR (pDrvCtrl, ENE_CMD, CMD_RREAD | CMD_START);

	for (i = 0; i < 6; ++i)
	    {
	    char ch;

	    SYS_IN_CHAR (pDrvCtrl, ENE_DATA, &pDrvCtrl->enetAddr[i]);
	    /* Must consume "duplicate" high bytes in 8-bit mode */
	    if (pDrvCtrl->byteAccess)
		SYS_IN_CHAR (pDrvCtrl, ENE_DATA, &ch);
	    }

	/* check for enet addr of all zeros (unprogrammed) */
	for (i = 0; i < 6; ++i)
	    if (pDrvCtrl->enetAddr[i])
		return;
	}
	else
	{
	
	    ax88796EnetMacAddrGet(ax88796EnetAddr);
	
	    /* get the enet addr from the BSP. */
	    for (i = 0; i < 6; ++i)
		pDrvCtrl->enetAddr[i] = ax88796EnetAddr[i];
	}

    }

/******************************************************************************
*
* ax88796GetCurr - get current page
*
* RETURNS: current page that ENE is working on
*
* NOMANUAL
*/

LOCAL UCHAR ax88796GetCurr
    (
    AX88796END_DEVICE* pDrvCtrl
    )
    {
    UCHAR curr;

    /* get CURR register */
    SYS_IN_CHAR (pDrvCtrl, ENE_TCNTH, &curr);

    return (curr);
    }
    
/*******************************************************************************
*
* ax88796OverWiteRcvInt - receive packet in overwrite interrupt
*
* This routine is called at task level indirectly by the interrupt
* service routine to do any message received processing.
*
* RETURNS: N/A.
*/

LOCA

⌨️ 快捷键说明

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