diff --git a/cpu/avr/dev/rtl8019-drv.c b/cpu/avr/dev/rtl8019-drv.c index b4daae613..ea5f9745e 100644 --- a/cpu/avr/dev/rtl8019-drv.c +++ b/cpu/avr/dev/rtl8019-drv.c @@ -29,66 +29,72 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: rtl8019-drv.c,v 1.1 2006/06/17 22:41:21 adamdunkels Exp $ + * $Id: rtl8019-drv.c,v 1.2 2007/05/26 23:05:36 oliverschmidt Exp $ * */ -#include "net/packet-service.h" +#include "contiki-net.h" #include "dev/rtl8019dev.h" -#include "net/uip_arp.h" - -#include - -static u8_t output(void); - -SERVICE(rtl8019_drv_service, packet_service, { output }); - -PROCESS(rtl8019_drv_process, "RTL8019 driver"); - -PROCESS_THREAD(rtl8019_drv_process, ev, data) -{ - PROCESS_BEGIN(); - - SERVICE_REGISTER(rtl8019_drv_service); - - RTL8019dev_init(); - - while(1) { - process_poll(&rtl8019_drv_process); - PROCESS_WAIT_EVENT(); - - uip_len = RTL8019dev_poll(); - - if(uip_len > 0) { +#include "net/uip-neighbor.h" #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) - /* A frame was avaliable (and is now read into the uip_buf), so - we process it. */ - if(BUF->type == HTONS(UIP_ETHTYPE_IP)) { - uip_arp_ipin(); - uip_len -= sizeof(struct uip_eth_hdr); - tcpip_input(); - } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) { - uip_arp_arpin(); - /* If the above function invocation resulted in data that - should be sent out on the network, the global variable - uip_len is set to a value > 0. */ - if(uip_len > 0) { - RTL8019dev_send(); - } - } - } - } - - PROCESS_END(); -} + +PROCESS(rtl8019_process, "RTL8019 driver"); /*---------------------------------------------------------------------------*/ -static u8_t -output(void) +u8_t +rtl8019_output(void) { uip_arp_out(); RTL8019dev_send(); + return 0; } /*---------------------------------------------------------------------------*/ +static void +pollhandler(void) +{ + process_poll(&rtl8019_process); + uip_len = RTL8019dev_poll(); + + if(uip_len > 0) { +#if UIP_CONF_IPV6 + if(BUF->type == htons(UIP_ETHTYPE_IPV6)) { + uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src); + tcpip_input(); + } else +#endif /* UIP_CONF_IPV6 */ + if(BUF->type == htons(UIP_ETHTYPE_IP)) { + uip_len -= sizeof(struct uip_eth_hdr); + tcpip_input(); + } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { + uip_arp_arpin(); + /* If the above function invocation resulted in data that + should be sent out on the network, the global variable + uip_len is set to a value > 0. */ + if(uip_len > 0) { + RTL8019dev_send(); + } + } + } +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(rtl8019_process, ev, data) +{ + PROCESS_POLLHANDLER(pollhandler()); + + PROCESS_BEGIN(); + + RTL8019dev_init(); + + tcpip_set_outputfunc(rtl8019_output); + + process_poll(&rtl8019_process); + + PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT); + + RTL8019dev_exit(); + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/cpu/avr/dev/rtl8019-drv.h b/cpu/avr/dev/rtl8019-drv.h index c0740701c..513891a07 100644 --- a/cpu/avr/dev/rtl8019-drv.h +++ b/cpu/avr/dev/rtl8019-drv.h @@ -31,7 +31,7 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: rtl8019-drv.h,v 1.1 2006/06/17 22:41:21 adamdunkels Exp $ + * $Id: rtl8019-drv.h,v 1.2 2007/05/26 23:05:36 oliverschmidt Exp $ * */ #ifndef __RTL8019_DRV_H__ @@ -39,6 +39,8 @@ #include "contiki.h" -PROCESS_NAME(rtl8019_drv_process); +PROCESS_NAME(rtl8019_process); + +u8_t rtl8019_output(void); #endif /* __RTL8019_DRV_H__ */ diff --git a/cpu/avr/dev/rtl8019dev.c b/cpu/avr/dev/rtl8019dev.c index 50d96929a..7f2eed770 100644 --- a/cpu/avr/dev/rtl8019dev.c +++ b/cpu/avr/dev/rtl8019dev.c @@ -30,7 +30,7 @@ void RTL8019dev_init(void) { - initRTL8019(); + initRTL8019(); } @@ -54,24 +54,29 @@ void RTL8019dev_send(void) unsigned int RTL8019dev_poll(void) { - unsigned int packetLength; + unsigned int packetLength; - packetLength = RTL8019beginPacketRetreive(); + packetLength = RTL8019beginPacketRetreive(); - // if there's no packet or an error - exit without ending the operation - if( !packetLength ) - return 0; + // 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; - } + // 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(); + // copy the packet data into the uIP packet buffer + RTL8019retreivePacketData( uip_buf, packetLength ); + RTL8019endPacketRetreive(); - return packetLength; + return packetLength; +} + + +void RTL8019dev_exit(void) +{ } diff --git a/cpu/avr/dev/rtl8019dev.h b/cpu/avr/dev/rtl8019dev.h index 4442401d3..29850c155 100644 --- a/cpu/avr/dev/rtl8019dev.h +++ b/cpu/avr/dev/rtl8019dev.h @@ -57,4 +57,13 @@ void RTL8019dev_send(void); unsigned int RTL8019dev_poll(void); +/***************************************************************************** +* RTL8019dev_exit() +* Created By: - +* Date: - +* Description: Final shutdown of the RTL8019 +*****************************************************************************/ +void RTL8019dev_exit(void); + + #endif /* __RTL8019DEV_H__ */ diff --git a/platform/ethernut1/ethernut-main.c b/platform/ethernut1/ethernut-main.c index 3716ea883..b0f3ed49b 100644 --- a/platform/ethernut1/ethernut-main.c +++ b/platform/ethernut1/ethernut-main.c @@ -29,7 +29,7 @@ * * This file is part of the Contiki OS * - * $Id: ethernut-main.c,v 1.2 2006/06/20 21:23:10 adamdunkels Exp $ + * $Id: ethernut-main.c,v 1.3 2007/05/26 23:06:31 oliverschmidt Exp $ * */ @@ -43,7 +43,7 @@ #include #include -PROCINIT(&etimer_process, &tcpip_process, &rtl8019_drv_process); +PROCINIT(&etimer_process, &tcpip_process, &rtl8019_process); static const struct uip_eth_addr ethaddr = {{0x00,0x06,0x98,0x01,0x02,0x29}};