Added Rime driver for the netsim ethernode layer, renamed init.c to netsim-init.c

This commit is contained in:
adamdunkels 2007-03-13 13:07:47 +00:00
parent 11627c2406
commit 4477d81be4
10 changed files with 200 additions and 51 deletions

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode-drv.c,v 1.4 2006/10/10 15:58:31 adamdunkels Exp $
* $Id: ethernode-drv.c,v 1.5 2007/03/13 13:07:48 adamdunkels Exp $
*/
#include "contiki.h"
@ -50,6 +50,7 @@ enum { NULLEVENT };
u8_t
ethernode_drv_send(void)
{
/* printf("%d: ethernode_drv_send\n", node_id);*/
uip_len = hc_compress(&uip_buf[UIP_LLH_LEN], uip_len);
return ethernode_send();
@ -65,7 +66,7 @@ PROCESS_THREAD(ethernode_drv_process, ev, data)
PROCESS_WAIT_EVENT();
/* Poll Ethernet device to see if there is a frame avaliable. */
uip_len = ethernode_poll();
uip_len = ethernode_poll(uip_buf, UIP_BUFSIZE);
if(uip_len > 0) {
/* printf("%d: new packet len %d\n", node_id, uip_len);*/

View file

@ -0,0 +1,82 @@
/*
* Copyright (c) 2004, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode-rime.c,v 1.1 2007/03/13 13:07:48 adamdunkels Exp $
*/
#include "contiki.h"
#include "ethernode.h"
#include "net/rime.h"
PROCESS(ethernode_rime_process, "Ethernode Rime driver");
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ethernode_rime_process, ev, data)
{
PROCESS_BEGIN();
printf("ethernode_rime_process\n");
while(1) {
process_poll(&ethernode_rime_process);
PROCESS_WAIT_EVENT();
/* Poll Ethernet device to see if there is a frame avaliable. */
{
u16_t len;
rimebuf_clear();
len = ethernode_poll(rimebuf_dataptr(), RIMEBUF_SIZE);
if(len > 0) {
rimebuf_set_datalen(len);
printf("ethernode_rime_process: received len %d\n",
len);
abc_input_packet();
}
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
abc_arch_send(u8_t *buf, int len)
{
ethernode_send_buf(buf, len);
}
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* $Id: ethernode-rime.h,v 1.1 2007/03/13 13:07:48 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __ETHERNODE_RIME_H__
#define __ETHERNODE_RIME_H__
#include "contiki.h"
PROCESS_NAME(ethernode_rime_process);
#endif /* __ETHERNODE_RIME_H__ */

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode.c,v 1.3 2006/10/23 09:01:06 adamdunkels Exp $
* $Id: ethernode.c,v 1.4 2007/03/13 13:07:48 adamdunkels Exp $
*/
/**
* \file
@ -121,22 +121,24 @@ ethernode_init(int port)
*/
/*-------------------------------------------------------------------------------*/
int
ethernode_poll(void)
ethernode_poll(u8_t *buf, int bufsize)
{
int len;
struct hdr *hdr = (struct hdr *)uip_buf;
u8_t tmpbuf[UIP_BUFSIZE];
struct hdr *hdr = (struct hdr *)tmpbuf;
len = ether_client_poll();
len = ether_client_poll(tmpbuf, UIP_BUFSIZE);
if(len == 0) {
return 0;
}
/* printf("ethernode_poll: received data packet with len %d\n", len);*/
/* printf("ethernode_poll: received data packet with len %d type %d\n", len, hdr->type);*/
switch(hdr->type) {
case TYPE_DATA:
if(hdr->dest == state.id ||
hdr->dest == ID_BROADCAST) {
memcpy(buf, tmpbuf + HDR_LEN, bufsize);
return len - HDR_LEN;
}
break;
@ -181,10 +183,24 @@ ethernode_send(void)
dest = ID_BROADCAST;
usleep(100 * (random_rand() % 1000));
usleep(1000 * (random_rand() % 1000));
do_send(TYPE_DATA, dest, hdr, len);
return UIP_FW_OK;
}
/*-------------------------------------------------------------------------------*/
void
ethernode_send_buf(u8_t *buf, int len)
{
char tmpbuf[UIP_BUFSIZE + HDR_LEN];
struct hdr *hdr = (struct hdr *)tmpbuf;
u8_t dest;
memcpy(&tmpbuf[HDR_LEN], buf, len);
len = len + HDR_LEN;
dest = ID_BROADCAST;
do_send(TYPE_DATA, dest, hdr, len);
}
/*-------------------------------------------------------------------------------*/

View file

@ -1,36 +1,36 @@
/*
* Copyright (c) 2004, Swedish Institute of Computer Science.
* All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode.h,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
* $Id: ethernode.h,v 1.2 2007/03/13 13:07:48 adamdunkels Exp $
*/
#ifndef __ETHERNODE_H__
#define __ETHERNODE_H__
@ -38,9 +38,9 @@
#include "contiki.h"
void ethernode_init(int port);
int ethernode_poll(void);
int ethernode_poll(u8_t *buf, int bufsize);
u8_t ethernode_send(void);
void ethernode_send_buf(u8_t *buf, int len);
void ethernode_periodic(void);
#endif /* __ETHERNODE_H__ */