rtl8019dev.c

来自「运行环境是keil。这是一个实现嵌入式TCP/IP的程序」· C语言 代码 · 共 77 行

C
77
字号

#ifndef  OS_MASTER_FILE
#include    <CORE\includes.h>
#endif
#include <uip\uip.h>
#include "rtl8019.h"

#include "rtl8019dev.h"


#define IP_TCP_HEADER_LENGTH 40
#define TOTAL_HEADER_LENGTH (IP_TCP_HEADER_LENGTH+ETHERNET_HEADER_LENGTH)



void RTL8019dev_init(void)
{
	initRTL8019();
}


void RTL8019dev_send(void)
{
	RTL8019beginPacketSend(uip_len);
	
	// send packet, using data in uip_appdata if over the IP+TCP header size
	if( uip_len <= TOTAL_HEADER_LENGTH )
	{
      RTL8019sendPacketData(uip_buf, uip_len);
	}
	else
	{
      uip_len -= TOTAL_HEADER_LENGTH;
      RTL8019sendPacketData(uip_buf, TOTAL_HEADER_LENGTH);
	  RTL8019sendPacketData((unsigned char *)uip_appdata, uip_len);
	}

	RTL8019endPacketSend();
}



#if UIP_BUFSIZE > 255
unsigned int RTL8019dev_poll(void)
#else 
unsigned char RTL8019dev_poll(void)
#endif /* UIP_BUFSIZE > 255 */
{
	unsigned int packetLength;
	
	packetLength = RTL8019beginPacketRetreive();

	// if there's no packet or an error - exit without ending the operation
	if( !packetLength )
	  return 0;

	// drop anything too big for the buffer
	if( packetLength > UIP_BUFSIZE )
	{
	  RTL8019endPacketRetreive();
      return 0;
	}
	
	// copy the packet data into the uIP packet buffer
	RTL8019retreivePacketData( uip_buf, packetLength );
	RTL8019endPacketRetreive();
		
#if UIP_BUFSIZE > 255
	return packetLength;
#else 
	return (unsigned char)packetLength;
#endif /* UIP_BUFSIZE > 255 */
		
}


⌨️ 快捷键说明

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