adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 1 | #include "uip.h" |
| 2 | #include "rtl8019dev.h" |
| 3 | |
| 4 | /***************************************************************************** |
| 5 | * Module Name: Realtek 8019AS Driver Interface for uIP-AVR Port |
| 6 | * |
| 7 | * Created By: Louis Beaudoin (www.embedded-creations.com) |
| 8 | * |
| 9 | * Original Release: September 21, 2002 |
| 10 | * |
| 11 | * Module Description: |
| 12 | * Provides three functions to interface with the Realtek 8019AS driver |
| 13 | * These functions can be called directly from the main uIP control loop |
| 14 | * to send packets from uip_buf and uip_appbuf, and store incoming packets to |
| 15 | * uip_buf |
| 16 | * |
| 17 | * September 30, 2002 - Louis Beaudoin |
| 18 | * Modifications required to handle the packet receive function changes in |
| 19 | * rtl8019.c. There is no longer a need to poll for an empty buffer or |
| 20 | * an overflow. |
| 21 | * Added support for the Imagecraft Compiler |
| 22 | * |
| 23 | *****************************************************************************/ |
| 24 | |
| 25 | |
| 26 | #define IP_TCP_HEADER_LENGTH 40 |
| 27 | #define TOTAL_HEADER_LENGTH (IP_TCP_HEADER_LENGTH+ETHERNET_HEADER_LENGTH) |
| 28 | |
| 29 | |
| 30 | |
| 31 | void RTL8019dev_init(void) |
| 32 | { |
| 33 | initRTL8019(); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | void RTL8019dev_send(void) |
| 38 | { |
| 39 | RTL8019beginPacketSend(uip_len); |
| 40 | |
| 41 | // send packet, using data in uip_appdata if over the IP+TCP header size |
| 42 | if( uip_len <= TOTAL_HEADER_LENGTH ) { |
| 43 | RTL8019sendPacketData(uip_buf, uip_len); |
| 44 | } else { |
| 45 | uip_len -= TOTAL_HEADER_LENGTH; |
| 46 | RTL8019sendPacketData(uip_buf, TOTAL_HEADER_LENGTH); |
| 47 | RTL8019sendPacketData((unsigned char *)uip_appdata, uip_len); |
| 48 | } |
| 49 | |
| 50 | RTL8019endPacketSend(); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 55 | unsigned int RTL8019dev_poll(void) |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 56 | { |
| 57 | unsigned int packetLength; |
| 58 | |
| 59 | packetLength = RTL8019beginPacketRetreive(); |
| 60 | |
| 61 | // if there's no packet or an error - exit without ending the operation |
| 62 | if( !packetLength ) |
| 63 | return 0; |
| 64 | |
| 65 | // drop anything too big for the buffer |
| 66 | if( packetLength > UIP_BUFSIZE ) |
| 67 | { |
| 68 | RTL8019endPacketRetreive(); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | // copy the packet data into the uIP packet buffer |
| 73 | RTL8019retreivePacketData( uip_buf, packetLength ); |
| 74 | RTL8019endPacketRetreive(); |
| 75 | |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 76 | return packetLength; |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 77 | } |