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

📄 custom_ethernet.c

📁 使用silabs提供的协议栈做的一个基于c8051f的web服务器。ps:绝不是那个常见的简单web服务器。
💻 C
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------
// custom_ethernet.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
//
// Description:
// 	This file is a custom ethernet driver template.
//    By modifying this file, the TCP/IP stack can be used with any 
//       Ethernet controller.
//
// Generated by TCP/IP Library Builder 3.23
//

#include <c8051F120.h>           // Device-specific SFR Definitions
#include "mn_stackconst.h"       // TCP/IP Library Constants
#include "mn_userconst.h"        // TCP/IP Library Constants
#include "mn_errs.h"             // Library Error codes 
#include "mn_defs.h"             // Library type definitions 
#include "mn_funcs.h"            // Library Function Prototypes
#include "custom_ethernet.h"

/******************************************************************/
/* Functions                                                      */
/******************************************************************/

/************************************************************/
/*                                                          */
/* ether_init                                               */
/*                                                          */
/* This function initializes the Ethernet controller.       */
/* Returns 1 if initialization completes successfully or a  */
/* negative number (ETHER_INIT_ERROR) on error.             */
/*                                                          */
/************************************************************/
int ether_init(unsigned char DuplexMode)
{

   /***************************************************************************/
   /*                                                                         */
   /* Reset the Ethernet controller here                                      */
   /*                                                                         */
   /***************************************************************************/

   /***************************************************************************/
   /*                                                                         */
   /* Initialize the Ethernet controller here                                 */
   /* Initialization may include:                                             */
   /*    1. Verifying that the Ethernet controller is communicating properly. */
   /*    2. Auto-negotiation settings.                                        */
   /*    3. Enabling transmission / reception.                                */
   /*    4. Placing controller in polled or interrupt mode.                   */
   /*    5. Enabling or disabling features (e.g. Duplex Mode).                */
   /*    6. Writing the MAC address to registers on the controller (The MAC   */
   /*       address should be stored in eth_src_hw_addr in mn_vars.c).        */
   /*                                                                         */
   /***************************************************************************/

   /***************************************************************************/
   /*                                                                         */
   /* Return 1 if initialization completes or a                               */
   /* negative number (ETHER_INIT_ERROR) if initialization fails.             */
   /*                                                                         */
   /***************************************************************************/

   return 1;
}

/************************************************************/
/*                                                          */
/* ether_send                                               */
/*                                                          */
/* This routine is called by the TCP/IP stack when it       */
/* needs to transmit an Ethernet packet.                    */
/*                                                          */
/* An Ethernet packet consists of a 14-byte header and a    */
/* data payload.                                            */
/*                                                          */
/* The Ethernet header and other header info is pointed to  */
/* by send_out_ptr.                                         */
/* xmit_buff_len is the number of bytes in the header.      */
/*                                                          */
/* The data payload is pointed to by socket_ptr->send_ptr.  */
/* data_buff_len is the number of bytes in the data payload.*/
/*                                                          */
/* Ether_send returns the number of bytes sent or a         */
/* negative number on error.                                */
/*                                                          */
/************************************************************/
int ether_send(PSOCKET_INFO socket_ptr, word16 data_buff_len)
{
   word16 i;
   word16 xmit_buff_len;
   word16 total_len;
   int retval;
   byte oddLength;
   byte *data_buff_ptr;

   retval = 0;
   oddLength = FALSE;

   /* make sure there is something to send */
   if (send_out_ptr != send_in_ptr)
   {
      /* calculate the number of bytes in the header */
      if (send_out_ptr < send_in_ptr)
         xmit_buff_len = send_in_ptr - send_out_ptr;
      else
      {
         xmit_buff_len = (&send_buff[xmit_buff_size] - send_out_ptr) + \
            (send_in_ptr - &send_buff[0]);
      }

      if (data_buff_len && socket_ptr->send_ptr != PTR_NULL)
      {
         data_buff_ptr = socket_ptr->send_ptr;
         oddLength = (data_buff_len & 0x0001);
      }
      else if (xmit_buff_len & 0x0001)
      {
         /* xmit_buff_len should be an even # if socket_ptr->send_ptr != PTR_NULL,
            otherwise force it to be even.
         */
         mn_send_byte(0x00);
         xmit_buff_len++;
      }
   
      total_len = data_buff_len + xmit_buff_len;
      if (total_len > ETHER_SIZE)
         return (ETHER_SEND_ERROR);

      retval = (int)total_len;
   
      if (!retval)
      {
         return (UNABLE_TO_SEND);
      }
   
      /* write the header */
      for (i=0;i<xmit_buff_len;i += 2)
      {
         /***************************************************/
         /*                                                 */
         /* Modfy this code to write the data pointed to by */
         /* send_out_ptr to the TX buffer of the            */
         /* Ethernet controller.                            */
         /*                                                 */
         /***************************************************/
         //ETHER_RDWR[TX_PORT] = *send_out_ptr;
         ++send_out_ptr;
         //ETHER_RDWR[TX_PORT] = *send_out_ptr;
         ++send_out_ptr;
      }

      if (oddLength)
         data_buff_len--;     /* need even count for the loop */
   
      /* write the data */
      for (i=0;i<data_buff_len;i += 2)
      {
         /***************************************************/
         /*                                                 */
         /* Modfy this code to write the data pointed to by */
         /* data_buff_ptr to the TX buffer of the           */
         /* Ethernet controller.                            */
         /*                                                 */
         /***************************************************/
         //ETHER_RDWR[TX_PORT] = *data_buff_ptr++;
         //ETHER_RDWR[TX_PORT] = *data_buff_ptr++;
      }
   
      if (oddLength)
      {
         /***************************************************/
         /*                                                 */
         /* Modfy this code to write the data pointed to by */
         /* data_buff_ptr to the TX buffer of the           */
         /* Ethernet controller.                            */
         /*                                                 */
         /***************************************************/
         //ETHER_RDWR[TX_PORT] = *data_buff_ptr;
         //ETHER_RDWR[TX_PORT] = (byte)'\0';
      }

      /***************************************************/
      /*                                                 */
      /* Replace TRANSMIT_PACKET with code which         */
      /* initiates packet transmission.                  */
      /*                                                 */
      /***************************************************/
   	//TRANSMIT_PACKET;

      while (1)
      {
         /***************************************************/
         /*                                                 */
         /* Modfy this code to read the result of the       */
         /* transmission from the status register of the    */
         /* Ethernet controller.                            */
         /*                                                 */
         /***************************************************/
         //i = ETHER_RDWR[TX_RESULT];
         
         if (1)
         {
            // If there was an error on transmit, return ETHER_SEND_ERROR

⌨️ 快捷键说明

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