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

📄 secend.c

📁 ARM板驱动程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        /* Stop polling mode. */        error = DRV_POLL_STOP(pDrvCtrl);        break;    case EIOCGMIB2:  #ifdef  DEBUG_TRACE        printf("EIOCGMIB2\n");#endif  /* DEBUG_TRACE */        /* Get MIB2 table. */        bcopy ((char *)&pEndObj->mib2Tbl, (char *)data, sizeof(pEndObj->mib2Tbl));        break;    case EIOCGNPT:#ifdef  DEBUG_TRACE        printf("EIOCGNPT\n");#endif  /* DEBUG_TRACE */        error = EINVAL;        break;    case EIOCGHDRLEN:#ifdef  DEBUG_TRACE        printf("EIOCGHDRLEN\n");#endif  /* DEBUG_TRACE */        *(long *)data = ENET_HDR_REAL_SIZ;        break;    default:#ifdef  DEBUG_TRACE        printf("\n");#endif  /* DEBUG_TRACE */        printf("secEnd%d Error: Unknown IOCTL command(0x%08X)\n", pDrvCtrl->unit, cmd);        error = EINVAL;        break;    }    return (error);}/********************************************************************************* secEndSend - the driver send routine** This routine takes a M_BLK_ID sends off the data in the M_BLK_ID. The buffer* must already have the addressing information properly installed in it. This is* done by a higher layer. The last arguments are a free routine to be called* when the device is done with the buffer and a pointer to the argument to pass* to the free routine.** RETURNS: OK, ERROR, or END_ERR_BLOCK.*/LOCAL STATUS secEndSend(    DRV_CTRL *pDrvCtrl,                                     /* pointer to DRV_CTRL structure */    M_BLK_ID pMblk                                          /* pointer to the mBlk/cluster pair */    ){    STATUS status;#ifdef  DEBUG_TRACE    printf("secEnd%d Send\n", pDrvCtrl->unit);#endif  /* DEBUG_TRACE */    END_TX_SEM_TAKE(&pDrvCtrl->endObj, WAIT_FOREVER);    /* Send data. */    status = DRV_SEND(pDrvCtrl, pMblk);    END_TX_SEM_GIVE(&pDrvCtrl->endObj);    return (status);}/******************************************************************************* secEndMCastAddrAdd - 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.** RETURNS: OK or ERROR.*/LOCAL STATUS secEndMCastAddrAdd(    DRV_CTRL *pDrvCtrl,                                     /* pointer to DRV_CTRL structure */    UCHAR *pAddr                                            /* address to be added */    ){    int retVal;#ifdef  DEBUG_TRACE    printf("secEnd%d MCastAddrAdd\n", pDrvCtrl->unit);#endif  /* DEBUG_TRACE */    /* Add multicast address to a multicast address list. */    retVal = etherMultiAdd(&pDrvCtrl->endObj.multiList, pAddr);    if (retVal == ENETRESET)    {        /* Program multicast address. */        retVal = DRV_MCAST_ADD(pDrvCtrl, pAddr);    }    return (retVal);}/******************************************************************************* secEndMCastAddrDel - 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.** RETURNS: OK or ERROR.*/LOCAL STATUS secEndMCastAddrDel(    DRV_CTRL *pDrvCtrl,                                     /* pointer to DRV_CTRL structure */    UCHAR *pAddr                                            /* address to be deleted */    ){    int retVal;#ifdef  DEBUG_TRACE    printf("secEnd%d MCastAddrDel\n", pDrvCtrl->unit);#endif  /* DEBUG_TRACE */    /* Delete multicast address from a multicast address list. */    retVal = etherMultiDel(&pDrvCtrl->endObj.multiList, pAddr);    while (retVal == ENETRESET)    {        /* Stop the device. */        DRV_STOP(pDrvCtrl);        /* Program multicast address. */        retVal = DRV_MCAST_DEL(pDrvCtrl, pAddr);        /* Restart the device. */        DRV_START(pDrvCtrl);    }    return (retVal);}/******************************************************************************* secEndMCastAddrGet - get the multicast address list for the device** This routine gets the multicast list of whatever the driver is already* listening for.** RETURNS: OK or ERROR.*/LOCAL STATUS secEndMCastAddrGet(    DRV_CTRL *pDrvCtrl,                                     /* pointer to DRV_CTRL structure */    MULTI_TABLE *pTable                                     /* table into which to copy addresses */    ){#ifdef  DEBUG_TRACE    printf("secEnd%d MCastAddrGet\n", pDrvCtrl->unit);#endif  /* DEBUG_TRACE */    /* Retrieve a table of multicast addresses from a driver. */    return (etherMultiGet(&pDrvCtrl->endObj.multiList, pTable));}/********************************************************************************* secEndPollSend - routine to send a packet in polled mode** This routine is called by a user to try and send a packet on the device.** RETURNS: OK upon success.  EAGAIN if device is busy.*/LOCAL STATUS secEndPollSend(    DRV_CTRL *pDrvCtrl,                                     /* pointer to DRV_CTRL structure */    M_BLK_ID pMblk                                          /* pointer to the mBlk/cluster pair */    ){#ifdef  DEBUG_TRACE    printf("secEnd%d PollSend\n", pDrvCtrl->unit);#endif  /* DEBUG_TRACE */    while (1)    {        if (pMblk == NULL)        {            printf("secEnd%d Error: NULL tansmit M_BLK\n", pDrvCtrl->unit);            break;        }        /* Send data. */        return DRV_POLL_SEND(pDrvCtrl, pMblk);    }    END_ERR_ADD(&pDrvCtrl->endObj, MIB2_OUT_ERRS, +1);    return EAGAIN;}/********************************************************************************* secEndPollReceive - routine to receive a packet in polled mode** This routine is called by a user to try and get a packet from the device.** RETURNS: OK upon success.  EAGAIN is returned when no packet is available.*/LOCAL STATUS secEndPollReceive(    DRV_CTRL *pDrvCtrl,                                     /* pointer to DRV_CTRL structure */    M_BLK_ID pMblk                                          /* pointer to the mBlk/cluster pair */    ){#ifdef  DEBUG_TRACE    printf("secEnd%d PollReceive\n", pDrvCtrl->unit);#endif  /* DEBUG_TRACE */    while (1)    {        if (pMblk == NULL)        {            printf("secEnd%d Error: NULL receive M_BLK\n", pDrvCtrl->unit);            break;        }        /* If not has an associated cluster, avoid operation. */        if (!(pMblk->mBlkHdr.mFlags & M_EXT))        {            printf("secEnd%d Error: Invalid receive M_BLK\n", pDrvCtrl->unit);            break;        }        /* Receive data if available. */        return DRV_POLL_RECEIVE(pDrvCtrl, pMblk);    }    END_ERR_ADD(&pDrvCtrl->endObj, MIB2_IN_ERRS, +1);    return EAGAIN;}/********************************************************************************* secEndInitParse - parse the init string** Parse the input string. Fill in values in the driver control structure.** The muxLib.o module automatically prepends the unit number to the user's* initialization string from the BSP (configNet.h).** RETURNS: OK or ERROR for invalid arguments.*/LOCAL STATUS secEndInitParse(    DRV_CTRL *pDrvCtrl,                                     /* pointer to DRV_CTRL structure */    char *initString                                        /* parameter string */    ){    char *tok;    char *holder = NULL;#ifdef  DEBUG_TRACE    printf("secEnd InitParse, %s\n", initString);#endif  /* DEBUG_TRACE */    tok = strtok_r(initString, ":", &holder);    if (tok == NULL)    {        return ERROR;    }    pDrvCtrl->unit = 0 ; /* (int)strtoul(tok, NULL, 16);*/    /* Sanity check the unit number. */    if (pDrvCtrl->unit < 0)    {        printf("secEnd Error: Invalid unit number, %d\n", pDrvCtrl->unit);        return ERROR;    }    return OK;}/********************************************************************************* secEndInitMem - initialize memory for the chip** This routine is highly specific to the device.** RETURNS: OK or ERROR.*/    LOCAL STATUS secEndInitMem(    DRV_CTRL *pDrvCtrl                                      /* pointer to DRV_CTRL structure */    ){    M_CL_CONFIG mClBlkConfig;                               /* mBlk, clBlk pool configuration table. */    CL_DESC clDescTbl[SEC_END_NUM_CL_TYPE];                 /* cluster pool configuration table. */#ifdef  DEBUG_TRACE    printf("secEnd%d InitMem\n", pDrvCtrl->unit);#endif  /* DEBUG_TRACE */    /* Allocate the netPool. */    if ((pDrvCtrl->endObj.pNetPool = malloc(sizeof(NET_POOL))) == NULL)    {        return (ERROR);    }    /* Initialize mBlk/clBlk pool. */    mClBlkConfig.mBlkNum    = DRV_NUM_MBLK;    mClBlkConfig.clBlkNum   = DRV_NUM_CLUSTER ;//DRV_NUM_MBLK;    mClBlkConfig.memSize    = mClBlkConfig.mBlkNum * (M_BLK_SZ + sizeof(long)) +                              mClBlkConfig.clBlkNum * (CL_BLK_SZ+ sizeof(long));    mClBlkConfig.memArea    = (char *)memalign(MBLK_ALIGNMENT, mClBlkConfig.memSize);    if (mClBlkConfig.memArea == NULL)    {        printf("secEnd%d Error: Failed to allocate mBlk/clBlk pool\n", pDrvCtrl->unit);        return (ERROR);    }    /* Save the pointer to the mBlock/cBlk pool area. */    pDrvCtrl->pMblkArea = (void *)mClBlkConfig.memArea;    /* Initialize cluster pool. */    clDescTbl[0].clSize     =  SIZE_ETH_MDMA ;  /*SIZE_FB - CL_OVERHEAD;*/    clDescTbl[0].clNum      =   DRV_NUM_CLUSTER;    clDescTbl[0].memSize    =   (clDescTbl[0].clNum *                               (clDescTbl[0].clSize + 8))      						  + sizeof(int);        /* +8 is for proper alignment */	/* SIZE_FB * DRV_NUM_CLUSTER;*//*    clDescTbl[0].memArea    = (char *)(DRV_CLUSTER_MEM_BASE );*/    clDescTbl[0].memArea =    (char *) cacheDmaMalloc (clDescTbl[0].memSize);    if (clDescTbl[0].memArea == NULL)    {		;    	return (ERROR);    }   pDrvCtrl->pClArea = clDescTbl[0].memArea ;#ifdef  DEBUG_TRACE    printf("    mBlk/clBlk pool     : 0x%08X\n", (UINT32)mClBlkConfig.memArea);    printf("    cluster pool        : 0x%08X\n", (UINT32)clDescTbl[0].memArea);#endif  /* DEBUG_TRACE */    /* Initialize the netPool. */    if (netPoolInit(pDrvCtrl->endObj.pNetPool, &mClBlkConfig, &clDescTbl[0], SEC_END_NUM_CL_TYPE, NULL) == ERROR)    {        printf("secEnd%d Error: Failed to initialize netPool\n", pDrvCtrl->unit);        return (ERROR);    }    /* Save cluster pool. */ /*   if ((pDrvCtrl->pClPool = netClPoolIdGet(pDrvCtrl->endObj.pNetPool, DRV_SIZE_CLUSTER, FALSE)) == NULL)    {        printf("secEnd%d Error: Failed to get clPool\n", pDrvCtrl->unit);        return (ERROR);    }*/#ifdef  DEBUG_TRACE    printf("    pNetPool->mBlkCnt   : %d\n", pDrvCtrl->endObj.pNetPool->mBlkCnt);    printf("    pNetPool->mBlkFree  : %d\n", pDrvCtrl->endObj.pNetPool->mBlkFree);    printf("    pNetPool->clLg2Max  : %d\n", pDrvCtrl->endObj.pNetPool->clLg2Max);    printf("    pNetPool->clSizeMax : %d\n", pDrvCtrl->endObj.pNetPool->clSizeMax);    printf("    pNetPool->clLg2Min  : %d\n", pDrvCtrl->endObj.pNetPool->clLg2Min);    printf("    pNetPool->clSizeMin : %d\n", pDrvCtrl->endObj.pNetPool->clSizeMin);/*  printf("    pClPool->clSize     : %d\n", pDrvCtrl->pClPool->clSize);    printf("    pClPool->clLg2      : %d\n", pDrvCtrl->pClPool->clLg2);    printf("    pClPool->clNum      : %d\n", pDrvCtrl->pClPool->clNum);    printf("    pClPool->clNumFree  : %d\n", pDrvCtrl->pClPool->clNumFree);*/#endif  /* DEBUG_TRACE */    /* Change cluster size to real size. *//*    pDrvCtrl->pClPool->clSize = DRV_SIZE_CLUSTER;*/    return OK;}LOCAL unsigned char sysSecEnetAddr[][6] = {#if 1    {0x08, 0x00, 0x01, 0x01, 0x01, 0x01},    {0x08, 0x00, 0x01, 0x01, 0x01, 0x02},    {0x08, 0x00, 0x01, 0x01, 0x01, 0x03},    {0x08, 0x00, 0x01, 0x01, 0x01, 0x04},    {0x08, 0x00, 0x01, 0x01, 0x01, 0x05},    {0x08, 0x00, 0x01, 0x01, 0x01, 0x06}#else    {0x08, 0x00, 0x02, 0x02, 0x02, 0x01},    {0x08, 0x00, 0x02, 0x02, 0x02, 0x02},    {0x08, 0x00, 0x02, 0x02, 0x02, 0x03},    {0x08, 0x00, 0x02, 0x02, 0x02, 0x04},    {0x08, 0x00, 0x02, 0x02, 0x02, 0x05},    {0x08, 0x00, 0x02, 0x02, 0x02, 0x06}#endif};STATUS sysSecEnetAddrGet(    int unit,                                               /* unit number of device being used */    UCHAR* addr                                             /* where to copy the ethernet address */    ){    bcopy((char*)sysSecEnetAddr[unit], (char*)addr, 6);    return (OK);}

⌨️ 快捷键说明

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