Changed packet drivers from services to plain processes.

Now tcpip_output() is a function pointer that is supposed to be set via the macro tcpip_set_outputfunc(). Packet drivers do so on process startup.

Thus if there are several packet drivers in a Contiki system the one started last is the one actually used. This behaviour is especially useful for the 'IP forwarding' "meta" packet driver.
This commit is contained in:
oliverschmidt 2007-05-26 23:05:36 +00:00
parent 6ab3a6d1e3
commit 75f04995a9
5 changed files with 91 additions and 69 deletions

View file

@ -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 <stdio.h>
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();
}
/*---------------------------------------------------------------------------*/

View file

@ -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__ */

View file

@ -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)
{
}

View file

@ -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__ */

View file

@ -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 <avr/io.h>
#include <avr/pgmspace.h>
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}};