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

📄 dec21143.c

📁 嵌入式操作系统Nucleus Plus下的以太网驱动模板
💻 C
📖 第 1 页 / 共 5 页
字号:

    /* Clear out this entry. */
    DEC21143_Negotiate_Device_Buffer[DEC21143_Negotiate_Read] = NU_NULL;

    /* Update the read index. */
    if(DEC21143_Negotiate_Read >= (MAX_DEC21143_DEVICES -1))
        DEC21143_Negotiate_Read = 0;
    else
        DEC21143_Negotiate_Read++;

    /* Make sure we got a device pointer. */
    if (device == NU_NULL)
        return;

    /* Get a pointer to the DECs extended data. */
    dec_data = (DEC21143_XDATA *) device->user_defined_1;

    /* All we need to do here is to renegotiate the link. If it passes
       then mark the link as up. */
    if (DEC21143_Negotiate_Link (device, &dec_data->DEC21143_Saved_CSR6)
                                                == NU_SUCCESS)
        /* Mark the device as up. */
        device->dev_flags |= DV_UP;

} /* end DEC21143_Negotiate_Link_HISR */

/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*  DEC21143_Get_Address                                                    */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*  This function reads the chips MAC address from the eeprom data passed   */
/*  in.                                                                     */
/*                                                                          */
/* AUTHOR                                                                   */
/*                                                                          */
/*    Uriah T. Pollock,  Accelerated Technology Inc.                        */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    DEC21143_Init                                                         */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    NONE                                                                  */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    uchar * : pointer to the location to store the read Ethernet address. */
/*    UINT8 * : Address of the eeprom data.                                 */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    STATUS  : Returns a value of NU_SUCCESS                               */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*       NAME                 DATE            REMARKS                       */
/*                                                                          */
/*  Uriah T. Pollock        01/12/99      Created initial version 1.0       */
/*                                                                          */
/****************************************************************************/
STATUS DEC21143_Get_Address (UINT8 *eeprom_data, UINT8 *ether_addr)
{
    UINT8 x;

    /* Read the hardware address from the EEPROM on the board. */
    for (x = 0; x < 6; x++)
        ether_addr [x] = eeprom_data [IEEE_ADDRESS_OFFSET + x];

    return (NU_SUCCESS);

} /* end DEC21143_Get_Address */

/****************************************************************************/
/* FUNCTION                                                                 */
/*                                                                          */
/*    DEC21143_RX_Packet                                                    */
/*                                                                          */
/* DESCRIPTION                                                              */
/*                                                                          */
/*    This function will handle the incomming data packets from the         */
/* Ethernet board. It is called from the LISR whenever a receive interrupt  */
/* occurrs. It will handle the parsing and storing of the current packet    */
/* from the wire.                                                           */
/*                                                                          */
/* AUTHOR                                                                   */
/*                                                                          */
/*    Uriah T. Pollock,  Accelerated Technology Inc.                        */
/*                                                                          */
/* CALLED BY                                                                */
/*                                                                          */
/*    DEC21143_LISR                                                         */
/*                                                                          */
/* CALLS                                                                    */
/*                                                                          */
/*    MEM_One_Buffer_Chain_Free                                             */
/*    MEM_Buffer_Enqueue                                                    */
/*    NU_Activate_HISR                                                      */
/*    NU_Tcp_Log_Error                                                      */
/*                                                                          */
/* INPUTS                                                                   */
/*                                                                          */
/*    DV_DEVICE_ENTRY * : Pointer to the device to receive the packet with. */
/*    DEC21143_XDATA *  : Pointer to the devices extended data area.        */
/*                                                                          */
/* OUTPUTS                                                                  */
/*                                                                          */
/*    NONE                                                                  */
/*                                                                          */
/* HISTORY                                                                  */
/*                                                                          */
/*       NAME                 DATE            REMARKS                       */
/*                                                                          */
/*  Uriah T. Pollock        01/12/99      Created initial version 1.0       */
/*                                                                          */
/****************************************************************************/
VOID DEC21143_RX_Packet (DV_DEVICE_ENTRY *device, DEC21143_XDATA *dec_data)
{
    /* Loop through all the descriptors, processing frames as we go,
       until we run into one that is owned by the DEC chip. More
       than one frame could be ready to be processed. */
    do
    {

        /* Is this the first segment of this frame. If so we need to get
           a pointer to the buffer and save off the device that generated
           this buffer. */
        if (dec_data->DEC21143_Current_RX_Descriptor->status &
                    RDES0_FIRST_DESCRIPTOR)
        {
            /* Init */
            dec_data->DEC21143_Current_Data_Size    =
            dec_data->DEC21143_Total_Data_Size      = 0;

            /* Get buffer pointer to the first buffer. There may or may not be
               more of them. */
            dec_data->DEC21143_Buffer_Ptr = dec_data->DEC21143_Work_Ptr =
                    (NET_BUFFER *) (dec_data->
                    DEC21143_Current_RX_Descriptor->buffer);

            /* Save the device that this packet came off of. */
            dec_data->DEC21143_Buffer_Ptr->mem_buf_device = device;

        } /* end if this is the first segment of this frame */
        else
        {
            /* Link the next buffer into this buffer chain. */
            dec_data->DEC21143_Work_Ptr->next_buffer =
                        (NET_BUFFER *) (dec_data->
                            DEC21143_Current_RX_Descriptor->buffer);

            /* Move to the next buffer so we can work with it. */
            dec_data->DEC21143_Work_Ptr =
                            dec_data->DEC21143_Work_Ptr->next_buffer;
        }

        /* Is this the last segment of this frame? */
        if (dec_data->DEC21143_Current_RX_Descriptor->status &
                    RDES0_LAST_DESCRIPTOR)
        {
            /* Did we get any errors during reception? */
            if (dec_data->DEC21143_Current_RX_Descriptor->status &
                    RDES0_ERROR_SUMMARY)
            {
                /* Free the buffer space used up by this errant frame. */
                if (dec_data->DEC21143_Buffer_Ptr)
                {
                    MEM_One_Buffer_Chain_Free (dec_data->DEC21143_Buffer_Ptr,
                                                &MEM_Buffer_Freelist);

                    /* Null the buffer pointer so that this buffer can not
                       be freed again by the code below. */
                    dec_data->DEC21143_Buffer_Ptr = NU_NULL;

                }

                /* Find out which error and log it. */

                /* Was it a CRC error? Only valid if there is not a
                   runt or collision seen error. */
                if ((dec_data->DEC21143_Current_RX_Descriptor->status &
                        RDES0_CRC_ERROR) &&
                        (!((dec_data->DEC21143_Current_RX_Descriptor->status
                        & RDES0_COLLISION_SEEN) |
                        (dec_data->DEC21143_Current_RX_Descriptor->status
                        & RDES0_RUNT_FRAME))))
                {
                    dec_data->DEC21143_CRC_Errors++;
                }

                /* Was it a collision seen error? */
                if (dec_data->DEC21143_Current_RX_Descriptor->status &
                        RDES0_COLLISION_SEEN)
                {
                    dec_data->DEC21143_Collisions_Seen++;
                }

                /* Was it a frame too long error? */
                if (dec_data->DEC21143_Current_RX_Descriptor->status &
                        RDES0_FRAME_TOO_LONG)
                {
                    dec_data->DEC21143_Frames_Too_Long++;
                }

                /* Was it a runt frame error? */
                if (dec_data->DEC21143_Current_RX_Descriptor->status &
                        RDES0_RUNT_FRAME)
                {
                    dec_data->DEC21143_Runt_Frames++;
                }

                /* Was it a descriptor error? */
                if (dec_data->DEC21143_Current_RX_Descriptor->status &
                        RDES0_DESCRIPTOR_ERROR)
                {
                    dec_data->DEC21143_Descriptor_Errors++;
                }


            } /* end if we got an error */
            else
            {
                /* This is a good frame. Finish building the buffer chain,
                   setup the descriptor to be reused, and let the stack
                   know it has a packet to process. */

                /* Get the total data size of this frame. */
                dec_data->DEC21143_Total_Data_Size = ((dec_data->
                                DEC21143_Current_RX_Descriptor->status &
                                RDES0_FRAME_LENGTH_ISOLATE) >> 16);

                /* Take away the CRC */
                dec_data->DEC21143_Total_Data_Size -=
                                        DEC21143_ETHERNET_CRC_SIZE;

                /* Set the total data length for this buffer chain. */
                dec_data->DEC21143_Buffer_Ptr->mem_total_data_len =
                            dec_data->DEC21143_Total_Data_Size;

                /* Now take away what we have already processed. This is
                   the amount of data that is in this buffer. */
                dec_data->DEC21143_Total_Data_Size -=
                            dec_data->DEC21143_Current_Data_Size;

                /* There is one special case here. This buffer may not
                   contain any data. It may only contain the CRC or part
                   of the CRC, this is because the DEC chip copies
                   over the CRC along with the data. If this is the case,
                   we want to free up the buffer used by the CRC, we do
                   not care about the CRC, and then adjust the size of
                   the last buffer in the chain, get rid of the CRC. */
                if (dec_data->DEC21143_Total_Data_Size < 0)
                {
                    /* Loop through th

⌨️ 快捷键说明

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