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

📄 lan91c111end.c

📁 atmel9200 vxworks bsp
💻 C
📖 第 1 页 / 共 5 页
字号:
	SYS_OUT_SHORT( Adapter->IOBase + BANK_SELECT, (USHORT) 0 );
	SYS_IN_SHORT((Adapter->IOBase + BANK0_TCR),(USHORT*)&Temp);
	DRV_LOG(DRV_DEBUG_LOAD,"VALUE OF TCR=%x",Temp,2,3,4,5,6);


    /* set the flags to indicate readiness */

    END_OBJ_READY (&pDrvCtrl->endObj,
		    IFF_UP | IFF_RUNNING | IFF_NOTRAILERS | IFF_BROADCAST
		    | IFF_MULTICAST | IFF_SIMPLEX);

    DRV_LOG (DRV_DEBUG_LOAD, "Done loading lan91c111...\n", 1, 2, 3, 4, 5, 6);
    DRV_LOG(DRV_DEBUG_LOAD, "IOBase 0x%x Ivec 0x%x ILevel 0x%x Offset %d InitConfig 0x%x\n",pDrvCtrl->IOBase,pDrvCtrl->ivec, pDrvCtrl->ilevel, pDrvCtrl->offset, pDrvCtrl->InitConfigVal, 6);
    
    return (&pDrvCtrl->endObj);

errorExit:
    if (pDrvCtrl != NULL)
	free ((char *)pDrvCtrl);

    return NULL;		   	

	}

/*******************************************************************************
* lan91c111InitParse - parse the initialization string
*
* Parse the input string.  Fill in values in the driver control structure.
* The initialization string format is:
* "<unit>:<IOBase>:<interruptVector>:<interruptLevel>:<offset>:<configValue>
*
* RETURNS: OK, or ERROR if any arguments are invalid.
*/

STATUS lan91c111InitParse
    (
    LAN91C111END_DEVICE * pDrvCtrl,
    char * initString
    )
    {
    char *	tok;
    char *	pHolder = NULL;
    long	address;


    /* Parse the initString */

    /* Unit number. */

    tok = strtok_r (initString, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->unit = atoi (tok);

    /* IO Base */

    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    address = strtoul (tok, NULL, 16);
    pDrvCtrl->IOBase = (UINT)address;
#if DUMP_BANKS
myIOBase = pDrvCtrl->IOBase;
#endif

    /* Interrupt vector. */

    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->ivec = (UINT)strtoul(tok,NULL,16);

    /* Interrupt level. */
    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->ilevel = (UINT)strtoul (tok,NULL,16);

    /* Caller supplied alignment offset. */
    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->offset = (UINT)strtoul (tok,NULL,16);

    /* Config string */
    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    pDrvCtrl->InitConfigVal = (UINT)strtoul (tok, NULL, 16);

	pDrvCtrl->userNetAddrOverRide = FALSE;

	/* MAC Address[0] */
    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	goto parse_exit;
    address = strtoul (tok, NULL, 16);
	if (address != 0) pDrvCtrl->userNetAddrOverRide = TRUE;
    pDrvCtrl->userNetAddr.Address[0] = (unsigned char)address;

	/* MAC Address[1] */
    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    address = strtoul (tok, NULL, 16);
	if (address != 0) pDrvCtrl->userNetAddrOverRide = TRUE;
    pDrvCtrl->userNetAddr.Address[1] = (unsigned char)address;

	/* MAC Address[2] */
    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    address = strtoul (tok, NULL, 16);
	if (address != 0) pDrvCtrl->userNetAddrOverRide = TRUE;
    pDrvCtrl->userNetAddr.Address[2] = (unsigned char)address;

	/* MAC Address[3] */
    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    address = strtoul (tok, NULL, 16);
	if (address != 0) pDrvCtrl->userNetAddrOverRide = TRUE;
    pDrvCtrl->userNetAddr.Address[3] = (unsigned char)address;

	/* MAC Address[4] */
    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    address = strtoul (tok, NULL, 16);
	if (address != 0) pDrvCtrl->userNetAddrOverRide = TRUE;
    pDrvCtrl->userNetAddr.Address[4] = (unsigned char)address;

	/* MAC Address[5] */
    tok = strtok_r (NULL, ":", &pHolder);
    if (tok == NULL)
	return ERROR;
    address = strtoul (tok, NULL, 16);
	if (address != 0) pDrvCtrl->userNetAddrOverRide = TRUE;
    pDrvCtrl->userNetAddr.Address[5] = (unsigned char)address;

	DRV_LOG(DRV_DEBUG_LOAD, "MAC Addr : %2x:%2x:%2x:%2x:%2x:%2x\n",
					pDrvCtrl->userNetAddr.Address[0],
					pDrvCtrl->userNetAddr.Address[1],
					pDrvCtrl->userNetAddr.Address[2],
					pDrvCtrl->userNetAddr.Address[3],
					pDrvCtrl->userNetAddr.Address[4],
					pDrvCtrl->userNetAddr.Address[5])



parse_exit:
    DRV_LOG (DRV_DEBUG_LOAD, "Processed all arugments\n", 1, 2, 3, 4, 5, 6);
    return OK;
    }

/*******************************************************************************
* lan91c111MemInit - initialize memory for the chip
*
* This routine is highly specific to the device.
*
* RETURNS: OK or ERROR.
*/

STATUS lan91c111MemInit
    (
    LAN91C111END_DEVICE * pDrvCtrl	/* device to be initialized */
    )
    {

    DRV_LOG (DRV_DEBUG_LOAD, "lan91c111MemInit: called\n", 1, 2, 3, 4, 5, 6);

	pDrvCtrl->numFrames = 128;

    /* Allocate space for the NET_POOL */

    if ((pDrvCtrl->endObj.pNetPool = malloc (sizeof(NET_POOL))) == NULL)
        return (ERROR);

    /* Calculate the total memory for all the M-Blks and CL-Blks. */

    lan91c111MclBlkConfig.mBlkNum = pDrvCtrl->numFrames*2;
    lan91c111ClDescTbl[0].clNum = pDrvCtrl->numFrames;
    lan91c111MclBlkConfig.clBlkNum = lan91c111ClDescTbl[0].clNum;

    lan91c111MclBlkConfig.memSize = (lan91c111MclBlkConfig.mBlkNum *
				    (MSIZE + sizeof (long))) +
			      (lan91c111MclBlkConfig.clBlkNum *
				    (CL_BLK_SZ + sizeof(long)));

    if ((lan91c111MclBlkConfig.memArea = (char *) memalign (sizeof(long),
                                                  lan91c111MclBlkConfig.memSize))
        == NULL)
        return (ERROR);

    /* Calculate the memory size of all the clusters. */

    lan91c111ClDescTbl[0].memSize = (lan91c111ClDescTbl[0].clNum *
				    (LAN91C111_BUFSIZE + 8)) + sizeof(int);

    /* Allocate the memory for the clusters from cache safe memory. */

    lan91c111ClDescTbl[0].memArea =
        (char *) cacheDmaMalloc (lan91c111ClDescTbl[0].memSize);

    if ((int)lan91c111ClDescTbl[0].memArea == NULL)
        {
        DRV_LOG (DRV_DEBUG_LOAD, "lan91c111MemInit: system memory unavailable\n",
				1, 2, 3, 4, 5, 6);
        return (ERROR);
        }

    /* Initialize the memory pool. */

    if (netPoolInit(pDrvCtrl->endObj.pNetPool, &lan91c111MclBlkConfig,
                    &lan91c111ClDescTbl[0], lan91c111ClDescTblNumEnt,
		    NULL) == ERROR)
        {
        DRV_LOG (DRV_DEBUG_LOAD, "lan91c111MemInit: Could not init buffering\n",
				1, 2, 3, 4, 5, 6);
        return (ERROR);
        }

    /* Store a reference to the cluster pool */
    if ((pDrvCtrl->pClPoolId = netClPoolIdGet (pDrvCtrl->endObj.pNetPool,
	sizeof (TX_PKT), FALSE))
        == NULL)
        return (ERROR);

    /*
     * If you need clusters to store received packets into then get them
     * here ahead of time.
     */
    pDrvCtrl->pTxBase = (TX_PKT *)calloc(TX_PACKETS * sizeof(TX_PKT),1);
    pDrvCtrl->pTxReadIndex = pDrvCtrl->pTxBase;
    pDrvCtrl->pTxWriteIndex = pDrvCtrl->pTxBase;

    pDrvCtrl->pRxBase = (RX_PKT *)calloc(RX_PACKETS * sizeof(RX_PKT),1);
    pDrvCtrl->pRxReadIndex = pDrvCtrl->pRxBase;
    pDrvCtrl->pRxWriteIndex = pDrvCtrl->pRxBase;

    pDrvCtrl->sendBuf = (unsigned char *)calloc(2048, 1);
#if PING_DEBUG
	debugTxBuf = pDrvCtrl->sendBuf;
#endif

    DRV_LOG (DRV_DEBUG_LOAD, "lan91c111MemInit: Memory setup complete\n",
			1, 2, 3, 4, 5, 6);

    return OK;
    }

/*******************************************************************************
* lan91c111Start - start the device
*
* This function calls BSP functions to connect interrupts and start the
* device running in interrupt mode.
*
* RETURNS: OK or ERROR
*
*/

 STATUS lan91c111Start
    (
    END_OBJ * pEnd	/* device ID */
    )
    {
    LAN91C111END_DEVICE  	*pDrvCtrl = (LAN91C111END_DEVICE *)pEnd;

    STATUS result;
        (void)intUninitVecSet((VOIDFUNCPTR)lan91c111Int);        
        SYS_INT_CONNECT (pDrvCtrl,(VOIDFUNCPTR) lan91c111Int, (int)pDrvCtrl, &result);
        if (result == ERROR)
	    return NULL;
        DRV_LOG (DRV_DEBUG_LOAD, "lan91c111Start: Interrupt connected.\n",
			    1, 2, 3, 4, 5, 6);

   	SYS_INT_ENABLE (pDrvCtrl);
#if 1
	logMsg("lan91c111Start: iLev = %x, iVector = %x\n", pDrvCtrl->ilevel, pDrvCtrl->ivec, 3,4,5,6);
#endif

	return (OK);
    }

/*******************************************************************************
* lan91c111Int - handle controller interrupt
*
* This routine is called at interrupt level in response to an interrupt from
* the controller.
*
* RETURNS: N/A.
*/

void lan91c111Int
	(
    LAN91C111END_DEVICE * pDrvCtrl	/* device to be initialized */
	)
	{
	LAN91C111END_DEVICE *Adapter = pDrvCtrl;
    /*-----------------3/15/01 3:07PM-------------------
     * Short Cut for Bank Select Values
     * --------------------------------------------------*/
    UINT IOBase;
    UINT IntrPort;
    UINT MmuPort;
    UINT DataPort;
    UINT RxFifoPort;
    UINT PtrPort;
    /*-----------------3/15/01 3:07PM-------------------
     * s for saving Bank Select, Pack Num, Ptr Reg
     * --------------------------------------------------*/
    USHORT SavedBank;
    USHORT SavedPtr;
    USHORT SavedPnr;
    USHORT tempWord;

    UCHAR IntrSts, IntMask;
    USHORT FifoPort;
    USHORT Count;
    /*-----------------3/15/01 3:06PM-------------------
     * Used in Rx Interrupt Processing
     * --------------------------------------------------*/
    USHORT Pointer;
    USHORT PacketStatus;
    USHORT PacketRange;
    int i;
    UINT16  len;
    char *usr_buf, *ReadBuffer, *pData;
    RX_PKT 			*pRxWriteIndex_ahead;
    /*-----------------3/15/01 3:06PM-------------------
     * Used in Tx Interrupt Processing
     * --------------------------------------------------*/
    UCHAR PacketNumber;
    /*-----------------3/15/01 3:13PM-------------------
     * Used in EPH Interrupt Processing
     * --------------------------------------------------*/
    USHORT EphStatus;
    /*-----------------3/15/01 3:11PM-------------------
     * Used in MDINT
     * --------------------------------------------------*/
    USHORT DefaultVal;

   short Packet_num,Rve_int,Rve_Status,Rve_count,Des_add1,Des_add2,Des_add3,Sor_add1,Sor_add2,Sor_add3,Pak_protocal,Pak_Size,Ctrl_Word;
   short Rvebuff[100];
   short tempb;
   int  j=0;


	DRV_LOG (DRV_DEBUG_INT, "----------- START ISR -------------\n",
			1, 2, 3, 4, 5, 6);


    /*-----------------3/16/01 4:40PM-------------------
     * DisableInterrupt is not called in NT driver code.
     * However it is done here because EnableInterrupt is
     * called just before exit from this ISR
     * --------------------------------------------------*/
/*    lan91c111DisableInterrupt(pDrvCtrl);*/


    IOBase		= Adapter->IOBase;
    IntrPort	= IOBase + BANK2_INT_STS;
    MmuPort		= IOBase;
    DataPort	= IOBase + BANK2_DATA1;
    RxFifoPort	= IOBase + BANK2_RX_FIFO;
    PtrPort		= IOBase + BANK2_PTR;
    

	/* read original Bank Select so it can be restored later */

    SYS_IN_SHORT (IOBase + BANK_SELECT, (USHORT *) &SavedBank);
    SYS_OUT_SHORT(IOBase + BANK_SELECT, (USHORT) 2);

    /* read original Pointer register so it can be restored later */

    SYS_IN_SHORT (IOBase + BANK2_PTR, (USHORT *) &SavedPtr);
    SYS_IN_SHORT (IOBase + BANK2_PNR, (USHORT *) &SavedPnr);



	while(1)
	{
	    SYS_IN_SHORT( IntrPort, &tempWord);
	    IntrSts = LOBYTE(tempWord);
	    IntMask = HIBYTE(tempWord);
	    IntrSts &=IntMask;

	    if(!IntrSts)
	    {
		DRV_LOG (DRV_DEBUG_INT, "lan91c111Int: Got weird status %x\n",
				IntrSts, 2, 3, 4, 5, 6);
	        tempWord = tempWord & ( 0xff00 | ~IntMask);
                SYS_OUT_SHORT(IntrPort, tempWord);
		goto lan91c111IntExit;

⌨️ 快捷键说明

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