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,46 +29,45 @@
*
* 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 "net/uip-neighbor.h"
#include <stdio.h>
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
static u8_t output(void);
PROCESS(rtl8019_process, "RTL8019 driver");
SERVICE(rtl8019_drv_service, packet_service, { output });
PROCESS(rtl8019_drv_process, "RTL8019 driver");
PROCESS_THREAD(rtl8019_drv_process, ev, data)
/*---------------------------------------------------------------------------*/
u8_t
rtl8019_output(void)
{
PROCESS_BEGIN();
SERVICE_REGISTER(rtl8019_drv_service);
RTL8019dev_init();
while(1) {
process_poll(&rtl8019_drv_process);
PROCESS_WAIT_EVENT();
uip_arp_out();
RTL8019dev_send();
return 0;
}
/*---------------------------------------------------------------------------*/
static void
pollhandler(void)
{
process_poll(&rtl8019_process);
uip_len = RTL8019dev_poll();
if(uip_len > 0) {
#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();
#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)) {
} 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
@ -78,17 +77,24 @@ PROCESS_THREAD(rtl8019_drv_process, ev, data)
}
}
}
}
}
/*---------------------------------------------------------------------------*/
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();
}
/*---------------------------------------------------------------------------*/
static u8_t
output(void)
{
uip_arp_out();
RTL8019dev_send();
return 0;
}
/*---------------------------------------------------------------------------*/

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

@ -75,3 +75,8 @@ unsigned int RTL8019dev_poll(void)
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}};