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();
}
/*---------------------------------------------------------------------------*/