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

📄 nimu_eth6455.c

📁 TI公司的NSP
💻 C
📖 第 1 页 / 共 2 页
字号:
 * FUNCTION NAME : DSK6455Emacioctl
 *********************************************************************
 * DESCRIPTION   :
 *  The function is called by the NDK core stack to configure the 
 *  driver
 *
 * RETURNS       :
 *  0   -   Success
 *  <0  -   Error
 *********************************************************************/
static int DSK6455Emacioctl (NETIF_DEVICE* ptr_net_device, uint cmd, void* pBuf, uint size)
{
    DSK6455_EMAC_DATA*  ptr_pvt_data;
    int                 count = 0;
    UINT8*              mac_address_add_del = (UINT8 *)pBuf;   
    UINT16              index;

    /* Get the pointer to the private data */
    ptr_pvt_data = (DSK6455_EMAC_DATA *)ptr_net_device->pvt_data;

    /* Process the command. */    
    switch (cmd)
    {
        case NIMU_ADD_MULTICAST_ADDRESS:
        {
            /* Validate the arguments. */
            if ((pBuf == NULL) || (size != 6))
                return -EINVAL;

            /* We need to add an address to the NIMU Network Interface Object's multicast 
             * list. Check for duplicate addresses. */
            while (count < ptr_pvt_data->pdi.MCastCnt)
            {
                UINT8* mac_address_list = (UINT8 *)&ptr_pvt_data->pdi.bMCast[count*6];

                /* Match the MAC Addresses  */
                for (index=0; index<6; index++)
                {
                    if( *(mac_address_add_del+index) != *(mac_address_list+index))
                        break;
                }

                /* Check if there is a hit or not? */
                if (index == 6)
                {
                    /* Duplicate MAC address; the address was already present in the list. 
                     * This is not an error we will still return SUCCESS here */
                    return 0;                        
                }
                else
                {
                    /* No HIT! Goto the next entry in the device multicast list. */
                    count++;                        
                }
            }

            /* Control comes here implies that the MAC Address needs to be added to the
             * device list. The variable 'count' is pointing to the free location available
             * in which the multicast address can be added. But before we do so check if 
             * we dont exceed the upper limit? */
            if (count >= PKT_MAX_MCAST)
                return -ENOMEM;

            /* Add the multicast address to the end of the list. */
            mmCopy (&ptr_pvt_data->pdi.bMCast[count*6], mac_address_add_del, 6);
            ptr_pvt_data->pdi.MCastCnt++;

            /* Configure the DSK6455 Ethernet controller with the new multicast list. */
            HwPktSetRx (&ptr_pvt_data->pdi);
            break;
        }
        case NIMU_DEL_MULTICAST_ADDRESS:
        {
            /* Validate the arguments. */
            if ((pBuf == NULL) || (size != 6))
                return -EINVAL;

            /* We need to delete an address from the NIMU Network Interface Object's multicast 
             * list. First cycle through and make sure the entry exists. */
            while (count < ptr_pvt_data->pdi.MCastCnt)
            {
                UINT8* mac_address_list = (UINT8 *)&ptr_pvt_data->pdi.bMCast[count*6];

                /* Match the MAC Addresses  */
                for ( index=0; index<6; index++)
                {
                    if( *(mac_address_add_del+index) != *(mac_address_list+index))
                        break;
                }

                /* Check if there is a hit or not? */
                if (index == 6)
                {
                    /* Found the matching entry. We can now delete this! */
                    break;
                }
                else
                {
                    /* No HIT! Goto the next entry in the device multicast list. */
                    count++;
                }
            }

            /* Did we find a match or not? If not then report the error back */
            if (count == ptr_pvt_data->pdi.MCastCnt)
                return -EINVAL;

            /* At this time 'count' points to the entry being deleted. We now need to copy all 
             * the entries after the 'del' entry back one space in the multicast array. */
            for (index = count; index < (ptr_pvt_data->pdi.MCastCnt - 1); index++)
                mmCopy (&ptr_pvt_data->pdi.bMCast[index*6], &ptr_pvt_data->pdi.bMCast[(index+1)*6], 6);

            /* Decrement the multicast entries. */
            ptr_pvt_data->pdi.MCastCnt--;

            /* Configure the DSK6455 Ethernet controller with the new multicast list. */
            HwPktSetRx (&ptr_pvt_data->pdi);
            break;
        }
        default:
        {
            /* The command is NOT handled by the driver. */
            return -1;
        } 
    }
    return 0;
}

/*********************************************************************
 * FUNCTION NAME : DSK6455EmacInit
 *********************************************************************
 * DESCRIPTION   :
 *  The function is used to initialize and register the EMAC for the
 *  DSK6455 with the Network Interface Management Unit (NIMU)
 *********************************************************************/
int DSK6455EmacInit (STKEVENT_Handle hEvent)
{
    NETIF_DEVICE*       ptr_device;
    DSK6455_EMAC_DATA*  ptr_pvt_data;

    /* Allocate memory for the private data */
    ptr_pvt_data = mmAlloc(sizeof(DSK6455_EMAC_DATA));
    if (ptr_pvt_data == NULL)
    {
        printf ("Error: Unable to allocate private memory data\n");
        return -1;
    }

    /* Initialize the allocated memory block. */
    mmZeroInit (ptr_pvt_data, sizeof(DSK6455_EMAC_DATA));

    /* Initialize the RX Queue */
    PBMQ_init(&ptr_pvt_data->pdi.PBMQ_rx);

    /* Initialize the packet drivers. */
    HwPktInit();

    /* Initialize the private data */
    mmZeroInit(&ptr_pvt_data->pdi, sizeof(PDINFO));

    /* Set physical index */
    ptr_pvt_data->pdi.PhysIdx = 0;
    ptr_pvt_data->pdi.hEvent  = hEvent;

    /* MCast List is EMPTY */
    ptr_pvt_data->pdi.MCastCnt    = 0;

    /* Default MAC Address (can be overwritten by HwPktOpen()) */
    ptr_pvt_data->pdi.bMacAddr[0] = 0x08;
    ptr_pvt_data->pdi.bMacAddr[1] = 0x00;
    ptr_pvt_data->pdi.bMacAddr[2] = 0x28;
    ptr_pvt_data->pdi.bMacAddr[3] = 0xFF;
    ptr_pvt_data->pdi.bMacAddr[4] = 0xFF;
    ptr_pvt_data->pdi.bMacAddr[5] = 0x20;

    /* Init Logical Device */
    /* ptr_pvt_data->pdi.hEther = hEther; */

    /* Allocate memory for the DSK6455 EMAC. */
    ptr_device = mmAlloc(sizeof(NETIF_DEVICE));
    if (ptr_device == NULL)
    {
        printf ("Error: Unable to allocate memory for the DSK6455 EMAC\n");
        return -1;
    }

    /* Initialize the allocated memory block. */
    mmZeroInit (ptr_device, sizeof(NETIF_DEVICE));

    /* Populate the Network Interface Object. */
    strcpy (ptr_device->name, "eth0");
    ptr_device->mtu         = ETH_MAX_PAYLOAD - ETHHDR_SIZE;
    ptr_device->pvt_data    = (void *)ptr_pvt_data;

    /* Populate the Driver Interface Functions. */
    ptr_device->start       = DSK6455EmacStart;
    ptr_device->stop        = DSK6455EmacStop;
    ptr_device->poll        = DSK6455EmacPoll;
    ptr_device->send        = DSK6455EmacSend;
    ptr_device->pkt_service = DSK6455EmacPktService;
    ptr_device->ioctl       = DSK6455Emacioctl;
    ptr_device->add_header  = NIMUAddEthernetHeader;

    /* Register the device with NIMU */
    if (NIMURegister (ptr_device) < 0)
    {
        printf ("Error: Unable to register the DSK6455 EMAC\n");
        return -1;
    }

    printf ("Registeration of the DSK6455 EMAC Successful\n");
    return 0;
}

#endif /* _INCLUDE_NIMU_CODE */

⌨️ 快捷键说明

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