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

@ -12,7 +12,8 @@ SENSORS = sensors.c beep.c button-sensor.c pir-sensor.c vib-sensor.c \
NETSIM = ether.c ethernode.c ethernode-drv.c lpm.c \
tapdev-drv.c tapdev-service.c tapdev.c rs232.c flash.c \
node.c nodes.c sensor.c display.c random.c radio.c \
dlloader.c main.c init.c contiki-main.c symtab.c symbols.c tr1001.c tr1001-drv.c
dlloader.c main.c netsim-init.c contiki-main.c symtab.c symbols.c tr1001.c tr1001-drv.c \
ethernode-rime.c
CONTIKI_TARGET_SOURCEFILES = $(NETSIM) $(SENSORS)
@ -26,7 +27,7 @@ include $(CONTIKI)/cpu/x86/Makefile.x86
### Compiler definitions
CC = gcc
LD = ld
LD = gcc
AS = as
OBJCOPY = objcopy
STRIP = strip

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: contiki-main.c,v 1.4 2006/10/23 09:01:06 adamdunkels Exp $
* $Id: contiki-main.c,v 1.5 2007/03/13 13:07:47 adamdunkels Exp $
*/
#include "contiki.h"
@ -41,6 +41,7 @@
#include "net/tapdev-drv.h"
#include "net/tapdev-service.h"
#include "net/ethernode-drv.h"
#include "net/ethernode-rime.h"
#include "net/ethernode.h"
#include "ether.h"
@ -67,7 +68,7 @@ static const struct uip_eth_addr ethaddr = {{0x00,0x06,0x98,0x01,0x02,0x12}};
SENSORS(&button_sensor, &pir_sensor, &vib_sensor, &radio_sensor);
PROCINIT(&sensors_process, &etimer_process, &tcpip_process,
&ethernode_drv_process,
&ethernode_drv_process, &ethernode_rime_process,
&uip_fw_process);
#if 0
@ -166,7 +167,7 @@ contiki_main(int flag)
leds_green(LEDS_ON);
autostart_start(autostart_processes);
while(1) {
int n;
n = process_run();

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.c,v 1.4 2006/10/23 09:01:06 adamdunkels Exp $
* $Id: ether.c,v 1.5 2007/03/13 13:07:47 adamdunkels Exp $
*/
/**
* \file
@ -205,7 +205,7 @@ ether_client_init(int port)
}
/*-----------------------------------------------------------------------------------*/
u16_t
ether_client_poll(void)
ether_client_poll(u8_t *buf, int bufsize)
{
int ret, len;
fd_set fdset;
@ -224,14 +224,14 @@ ether_client_poll(void)
return 0;
}
if(FD_ISSET(sc, &fdset)) {
ret = recv(sc, &rxbuffer[0], UIP_BUFSIZE, 0);
ret = recv(sc, &rxbuffer[0], bufsize, 0);
if(ret == -1) {
perror("ether_client_poll: read");
return 0;
}
len = ret;
memcpy(uip_buf, &rxbuffer[sizeof(struct ether_hdr)], len);
memcpy(buf, &rxbuffer[sizeof(struct ether_hdr)], len);
radio_sensor_signal = hdr->signal;
if(hdr->type == PTYPE_DATA && hdr->srcid != node.id) {
@ -277,13 +277,13 @@ ether_server_poll(void)
}
if(FD_ISSET(s, &fdset)) {
ret = recv(s, &rxbuffer[0], UIP_BUFSIZE, 0);
/* printf("ether_poll: read %d bytes from (%d, %d)\n", ret, hdr->srcx, hdr->srcy);*/
if(ret == -1) {
perror("ether_poll: read");
return;
}
switch(hdr->type) {
case PTYPE_DATA:
/* printf("ether_poll: read %d bytes from (%d, %d)\n", ret, hdr->srcx, hdr->srcy);*/
ether_put(rxbuffer, ret, hdr->srcx, hdr->srcy);
break;
case PTYPE_LEDS:
@ -402,7 +402,7 @@ ether_tick(void)
if(interference) {
num_collisions++;
/* printf("Collisions %d\n", num_collisions);*/
printf("Collisions %d\n", num_collisions);
}
if(!interference) {

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.h,v 1.3 2006/10/23 09:01:06 adamdunkels Exp $
* $Id: ether.h,v 1.4 2007/03/13 13:07:48 adamdunkels Exp $
*/
#ifndef __ETHER_H__
#define __ETHER_H__
@ -59,7 +59,7 @@ void ether_client_init(int port);
void ether_tick(void);
u16_t ether_client_poll(void);
u16_t ether_client_poll(u8_t *buf, int len);
void ether_server_poll(void);
void ether_put(char *packet, int len, int src_x, int src_y);

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

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: node.c,v 1.3 2006/09/26 22:10:12 adamdunkels Exp $
* $Id: node.c,v 1.4 2007/03/13 13:07:48 adamdunkels Exp $
*/
#include "node.h"
#include "contiki.h"
@ -64,7 +64,7 @@ node_init(int id, int posx, int posy, int b)
}
uip_sethostaddr(&addr);
drift = random() % 9572627217;
drift = random() % 95726272;
init_node_log();
}
@ -79,7 +79,7 @@ node_time(void)
gettimeofday(&tv, &tz);
return tv.tv_sec * 1000 + tv.tv_usec / 1000 + drift;
return tv.tv_sec * 1000 + tv.tv_usec / 1000/* + drift*/;
}
/*------------------------------------------------------------------------------*/
unsigned long