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

📄 nimu_eth6455.c

📁 TI公司的NSP
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************
 * FILE PURPOSE	:  	NIMU Interface for the Ethernet Driver (DSK6455)
 **************************************************************************
 * FILE NAME	:   nimu_eth6455.c
 *
 * DESCRIPTION	:
 *  Ethernet Packet Driver for the DSK6455 rewritten using the NIMU Packet
 *  Architecture guidelines. 

 *	CALL-INs:
 *
 *	CALL-OUTs:
 *
 *	User-Configurable Items:
 *
 *	(C) Copyright 2008, Texas Instruments, Inc.
 *************************************************************************/

#include <stkmain.h>
#include "llpacket.h"

#ifdef _INCLUDE_NIMU_CODE

/* The DSK6455 EMAC Initialization Function. */
int DSK6455EmacInit (STKEVENT_Handle hEvent);

/* This is the NIMU Device Table for the DSK6455 Platform. 
 * This should be defined for each platform. Since the DSK6455 platform
 * has a single network Interface; this has been defined here. If the 
 * platform supports more than one network interface this should be 
 * defined to have a list of "initialization" functions for each of the
 * interfaces. */
NIMU_DEVICE_TABLE_ENTRY NIMUDeviceTable[] = 
{
    DSK6455EmacInit,
    NULL
};

/*********************************************************************
 * STRUCTURE NAME : DSK6455_EMAC_DATA
 *********************************************************************
 * DESCRIPTION   :
 *  The structure is used to store the private data for the DSK6455 
 *  EMAC controller.
 *********************************************************************/
typedef struct DSK6455_EMAC_DATA
{
    PDINFO      pdi;        /* Private Information  */
}DSK6455_EMAC_DATA;

/*********************************************************************
 * FUNCTION NAME : DSK6455EmacStart
 *********************************************************************
 * DESCRIPTION   :
 *  The function is used to initialize and start the DSK6455 EMAC
 *  controller and device.
 *
 * RETURNS       :
 *  0   -   Success
 *  <0  -   Error
 *********************************************************************/
static int DSK6455EmacStart (NETIF_DEVICE* ptr_net_device)
{
    DSK6455_EMAC_DATA*  ptr_pvt_data;

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

    /* Call low-level open function */
    if (HwPktOpen(&ptr_pvt_data->pdi) == 1)
    {
        /* Copy the MAC Address into the network interface object here. */
        mmCopy(&ptr_net_device->mac_address[0], &ptr_pvt_data->pdi.bMacAddr[0], 6);

        /* Set the 'initial' Receive Filter */
        ptr_pvt_data->pdi.Filter = ETH_PKTFLT_MULTICAST;
        HwPktSetRx(&ptr_pvt_data->pdi);

        /* Inform the world that we are operational. */
        printf ("DSK6455 EMAC has been started successfully\n");
        return 0;
    }

    /* Error: DSK6455 EMAC failed to start. */
    return -1;
}

/*********************************************************************
 * FUNCTION NAME : DSK6455EmacStop
 *********************************************************************
 * DESCRIPTION   :
 *  The function is used to de-initialize and stop the DSK6455 EMAC
 *  controller and device.
 *
 * RETURNS       :
 *  0   -   Success
 *  <0  -   Error
 *********************************************************************/
static int DSK6455EmacStop (NETIF_DEVICE* ptr_net_device)
{
    DSK6455_EMAC_DATA*  ptr_pvt_data;

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

    /* Call low-level close function */
    HwPktClose (&ptr_pvt_data->pdi);

    /* Shut down the Ethernet controller. */    
    HwPktShutdown();

    /* Flush out our pending queue */
    while( PBMQ_count(&ptr_pvt_data->pdi.PBMQ_rx) )
        PBM_free( PBMQ_deq(&ptr_pvt_data->pdi.PBMQ_rx) );
       
    /* EMAC Controller has been stopped. */ 
    return 0;
}

/*********************************************************************
 * FUNCTION NAME : DSK6455EmacPoll
 *********************************************************************
 * DESCRIPTION   :
 *  The function is used to poll the DSK6455 EMAC controller to check
 *  if there has been any activity.
 *********************************************************************/
static void DSK6455EmacPoll (NETIF_DEVICE* ptr_net_device, uint timer_tick)
{
    DSK6455_EMAC_DATA*  ptr_pvt_data;

    /* Get the pointer to the private data */
    ptr_pvt_data = (DSK6455_EMAC_DATA *)ptr_net_device->pvt_data;
    
    /* Poll the driver. */
    _HwPktPoll (&ptr_pvt_data->pdi, timer_tick);
    return;
}

/*********************************************************************
 * FUNCTION NAME : DSK6455EmacSend
 *********************************************************************
 * DESCRIPTION   :
 *  The function is the interface routine invoked by the NDK stack to
 *  pass packets to the driver. 
 *
 * RETURNS       :
 *  0   -   Success
 *  <0  -   Error
 *********************************************************************/
static int DSK6455EmacSend (NETIF_DEVICE* ptr_net_device, PBM_Handle hPkt)
{
    DSK6455_EMAC_DATA*  ptr_pvt_data;

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

    /* Make sure the driver does not transmit packet less than min. as per the
     * Ethernet standards. */
    if( PBM_getValidLen(hPkt) < 60 )
        PBM_setValidLen (hPkt, 60 );

    /* Transmit the packet only if does not exceed the MTU */
    if(PBM_getValidLen(hPkt) <= 1518 )
    {
        /* Enqueue the packet and send it for transmission. */
        PBMQ_enq (&ptr_pvt_data->pdi.PBMQ_tx, hPkt);

        /* Pass the packet to the controller if the transmitter is free. */
        if(ptr_pvt_data->pdi.TxFree )
            HwPktTxNext(&ptr_pvt_data->pdi);

        /* Packet has been successfully transmitted. */
        return 0;
    }

    /* NOTE: This is a violation and should never occur as the NDK stack should have 
     * fragmented the packet. In this case though we drop and clean the packet we will 
     * still return success. */
    PBM_free (hPkt);
    return 0;
}

/*********************************************************************
 * FUNCTION NAME : DSK6455EmacPktService
 *********************************************************************
 * DESCRIPTION   :
 *  The function is called by the NDK core stack to receive any packets
 *  from the driver.
 *********************************************************************/
static void DSK6455EmacPktService (NETIF_DEVICE* ptr_net_device)
{
    DSK6455_EMAC_DATA*  ptr_pvt_data;
    PBM_Handle          hPacket;

    /* Get the pointer to the private data */
    ptr_pvt_data = (DSK6455_EMAC_DATA *)ptr_net_device->pvt_data;
        
    /* Give all queued packets to the Ether module */
    while (PBMQ_count(&ptr_pvt_data->pdi.PBMQ_rx))
    {
        /* Dequeue a packet from the driver receive queue. */
        hPacket = PBMQ_deq(&ptr_pvt_data->pdi.PBMQ_rx);

        /* Prepare the packet so that it can be passed up the networking stack. 
         * If this 'step' is not done the fields in the packet are not correct
         * and the packet will eventually be dropped.  */
        PBM_setIFRx (hPacket, ptr_net_device);
        
        /* Pass the packet to the NDK Core stack. */    
        NIMUReceivePacket(hPacket);
    }

    /* Work has been completed; the receive queue is empty... */ 
    return;
}

/*********************************************************************

⌨️ 快捷键说明

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