diff --git a/platform/esb/Makefile.esb b/platform/esb/Makefile.esb index 0c372b974..034cb2acd 100644 --- a/platform/esb/Makefile.esb +++ b/platform/esb/Makefile.esb @@ -1,16 +1,17 @@ -# $Id: Makefile.esb,v 1.14 2010/02/09 07:34:37 nifi Exp $ +# $Id: Makefile.esb,v 1.15 2010/03/02 22:40:39 nifi Exp $ SENSORS = sensors.c irq.c button-sensor.c pir-sensor.c vib-sensor.c \ sound-sensor.c radio-sensor.c ctsrts-sensor.c battery-sensor.c \ temperature-sensor.c -ESB = ir.c beep.c ds1629.c tr1001-uip.c tr1001-gcr.c gcr.c \ - esb-sensors.c node-id.c eeprom.c +ESB = ir.c beep.c ds1629.c tr1001-gcr.c gcr.c \ + esb-sensors.c node-id.c eeprom.c \ + uip-driver.c uip-ipchksum.c CFS_EEPROM = cfs-eeprom.c CFS_COFFEE = cfs-coffee.c cfs-coffee-arch.c CONTIKI_TARGET_DIRS = . dev apps net loader ifndef CONTIKI_TARGET_MAIN -CONTIKI_TARGET_MAIN = contiki-esb-main.c + CONTIKI_TARGET_MAIN = contiki-esb-main.c endif CONTIKI_TARGET_SOURCEFILES += $(SENSORS) $(ESB) \ @@ -19,33 +20,26 @@ CONTIKI_TARGET_SOURCEFILES += $(SENSORS) $(ESB) \ rs232.c rs232-putchar.c fader.c $(CONTIKI_TARGET_MAIN) ifdef WITH_CODEPROP -CONTIKI_TARGET_DIRS += ../../apps/codeprop -CONTIKI_TARGET_SOURCEFILES += codeprop-tmp.c -ifndef NETSTACK -NETSTACK = uip -endif + CONTIKI_TARGET_DIRS += ../../apps/codeprop + CONTIKI_TARGET_SOURCEFILES += codeprop-tmp.c + WITH_UIP=1 endif -ifeq ($(NETSTACK),uip) -CONTIKI_TARGET_SOURCEFILES += contiki-esb-init-net-uip.c uip-ipchksum.c -else -ifeq ($(NETSTACK),uip-noslip) -CONTIKI_TARGET_SOURCEFILES += contiki-esb-init-net-uip-noslip.c uip-ipchksum.c -else -CONTIKI_TARGET_SOURCEFILES += contiki-esb-default-init-net.c -endif +ifdef WITH_UIP + ifndef WITH_SLIP + WITH_SLIP=1 + endif + CFLAGS += -DWITH_UIP=1 -DWITH_SLIP=${WITH_SLIP} endif ifeq ($(CFS),coffee) -CONTIKI_TARGET_SOURCEFILES += $(CFS_COFFEE) + CONTIKI_TARGET_SOURCEFILES += $(CFS_COFFEE) else -CONTIKI_TARGET_SOURCEFILES += $(CFS_EEPROM) + CONTIKI_TARGET_SOURCEFILES += $(CFS_EEPROM) endif include $(CONTIKI)/platform/$(TARGET)/apps/Makefile.apps -#PROJECT_OBJECTFILES += $(OBJECTDIR)/contiki-esb-main.o - MCU=msp430x149 include $(CONTIKI)/cpu/msp430/Makefile.msp430 diff --git a/platform/esb/contiki-conf.h b/platform/esb/contiki-conf.h index 7a436eccb..cb30e2602 100644 --- a/platform/esb/contiki-conf.h +++ b/platform/esb/contiki-conf.h @@ -1,20 +1,10 @@ #ifndef __CONTIKI_CONF_H__ #define __CONTIKI_CONF_H__ -#define NETSTACK_CONF_RADIO tr1001_driver - /* DCO speed resynchronization for more robust UART, etc. */ #define DCOSYNCH_CONF_ENABLED 1 #define DCOSYNCH_CONF_PERIOD 30 -/* Specifies the default MAC driver */ -#define MAC_CONF_DRIVER nullmac_driver - -#define PACKETBUF_CONF_ATTRS_INLINE 1 -#define QUEUEBUF_CONF_NUM 1 -#define QUEUEBUF_CONF_REF_NUM 1 -#define ROUTE_CONF_ENTRIES 4 - #define SERIAL_LINE_CONF_BUFSIZE 64 #define TIMESYNCH_CONF_ENABLED 0 @@ -53,6 +43,36 @@ void clock_wait(int ms10); #define LOG_CONF_ENABLED 0 +#define PACKETBUF_CONF_ATTRS_INLINE 1 +#define NETSTACK_CONF_RADIO tr1001_driver + +#if WITH_UIP +/* Network setup for IPv4 */ + +#define NETSTACK_CONF_NETWORK uip_driver +#define NETSTACK_CONF_MAC nullmac_driver +#define NETSTACK_CONF_RDC nullrdc_driver +#define NETSTACK_CONF_FRAMER framer_nullmac + +#define QUEUEBUF_CONF_NUM 0 +#define QUEUEBUF_CONF_REF_NUM 0 +#define ROUTE_CONF_ENTRIES 0 + +#else /* WITH_UIP */ + +/* Network setup for non-IPv4 (rime). */ + +#define NETSTACK_CONF_NETWORK rime_driver +#define NETSTACK_CONF_MAC nullmac_driver +#define NETSTACK_CONF_RDC nullrdc_framer_driver +#define NETSTACK_CONF_FRAMER framer_nullmac + +#define QUEUEBUF_CONF_NUM 1 +#define QUEUEBUF_CONF_REF_NUM 1 +#define ROUTE_CONF_ENTRIES 4 + +#endif /* WITH_UIP */ + /** * The statistics data type. * @@ -69,8 +89,8 @@ typedef unsigned short uip_stats_t; #define UIP_CONF_BUFFER_SIZE 110 #define UIP_CONF_RECEIVE_WINDOW (UIP_CONF_BUFFER_SIZE - 40) #define UIP_CONF_MAX_CONNECTIONS 4 -#define UIP_CONF_MAX_LISTENPORTS 8 -#define UIP_CONF_UDP_CONNS 6 +#define UIP_CONF_MAX_LISTENPORTS 4 +#define UIP_CONF_UDP_CONNS 3 #define UIP_CONF_FWCACHE_SIZE 1 #define UIP_CONF_BROADCAST 1 #define UIP_ARCH_IPCHKSUM 1 @@ -87,6 +107,8 @@ typedef unsigned short uip_stats_t; #define ELFLOADER_CONF_DATAMEMORY_SIZE 100 #define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x1000 +#define WEBSERVER_CONF_CGI_CONNS 1 + /* LEDs ports. */ #define LEDS_PxDIR P2DIR #define LEDS_PxOUT P2OUT diff --git a/platform/esb/contiki-esb-default-init-net.c b/platform/esb/contiki-esb-default-init-net.c deleted file mode 100644 index ed99266e8..000000000 --- a/platform/esb/contiki-esb-default-init-net.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2005, 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: contiki-esb-default-init-net.c,v 1.14 2010/02/18 23:19:03 adamdunkels Exp $ - */ - -#include "contiki-conf.h" -#include "dev/tr1001.h" -#include "dev/rs232.h" -#include "dev/serial-line.h" -#include "net/rime.h" -#include "node-id.h" -#include - -#ifndef MAC_DRIVER -#ifdef MAC_CONF_DRIVER -#define MAC_DRIVER MAC_CONF_DRIVER -#else -#define MAC_DRIVER nullmac_driver -#endif /* MAC_CONF_DRIVER */ -#endif /* MAC_DRIVER */ - -extern const struct mac_driver MAC_DRIVER; - -void -init_net(void) -{ - rimeaddr_t rimeaddr; - int i; - - netstack_init(); - - rimeaddr.u8[0] = node_id & 0xff; - rimeaddr.u8[1] = node_id >> 8; - rimeaddr_set_node_addr(&rimeaddr); - - printf("Rime started with address "); - for(i = 0; i < sizeof(rimeaddr.u8) - 1; i++) { - printf("%u.", rimeaddr.u8[i]); - } - printf("%u (%s)\n", rimeaddr.u8[i], MAC_DRIVER.name); - - rs232_set_input(serial_line_input_byte); - serial_line_init(); -} diff --git a/platform/esb/contiki-esb-init-net-uip-noslip.c b/platform/esb/contiki-esb-init-net-uip-noslip.c deleted file mode 100644 index bdacb47d2..000000000 --- a/platform/esb/contiki-esb-init-net-uip-noslip.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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: contiki-esb-init-net-uip-noslip.c,v 1.2 2007/08/07 11:17:54 nifi Exp $ - */ - -#include "contiki-esb.h" - -static struct uip_fw_netif tr1001if = - {UIP_FW_NETIF(0,0,0,0, 0,0,0,0, tr1001_uip_send)}; - -#define NODE_ID (node_id & 0xFF) - -void -init_net(void) -{ - uip_ipaddr_t hostaddr; - - uip_init(); - uip_fw_init(); - - process_start(&tcpip_process, NULL); - process_start(&uip_fw_process, NULL); - - tr1001_uip_init(); - - if (NODE_ID > 0) { - /* node id is set, construct an ip address based on the node id */ - uip_ipaddr(&hostaddr, 172, 16, 1, NODE_ID); - uip_sethostaddr(&hostaddr); - } - uip_fw_default(&tr1001if); -} diff --git a/platform/esb/contiki-esb-init-net-uip.c b/platform/esb/contiki-esb-init-net-uip.c deleted file mode 100644 index bdcc47c61..000000000 --- a/platform/esb/contiki-esb-init-net-uip.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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. - * - * $Id: contiki-esb-init-net-uip.c,v 1.2 2007/08/07 11:17:54 nifi Exp $ - * - * ----------------------------------------------------------------- - * - * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne - * Created : 2007-04-03 - * Updated : $Date: 2007/08/07 11:17:54 $ - * $Revision: 1.2 $ - */ - -#include "contiki-esb.h" - -static struct uip_fw_netif tr1001if = - {UIP_FW_NETIF(0,0,0,0, 0,0,0,0, tr1001_uip_send)}; - -static struct uip_fw_netif slipif = - {UIP_FW_NETIF(172,16,0,0, 255,255,255,0, slip_send)}; - -#define NODE_ID (node_id & 0xFF) - -void -init_net(void) -{ - uip_ipaddr_t hostaddr; - - uip_init(); - uip_fw_init(); - - rs232_set_input(slip_input_byte); - - process_start(&tcpip_process, NULL); - process_start(&slip_process, NULL); - process_start(&uip_fw_process, NULL); - - tr1001_uip_init(); - - if (NODE_ID > 0) { - /* node id is set, construct an ip address based on the node id */ - uip_ipaddr(&hostaddr, 172, 16, 1, NODE_ID); - uip_sethostaddr(&hostaddr); - } - uip_fw_register(&slipif); - uip_fw_default(&tr1001if); -} diff --git a/platform/esb/contiki-esb-main.c b/platform/esb/contiki-esb-main.c index 326f74670..1fdec10c6 100644 --- a/platform/esb/contiki-esb-main.c +++ b/platform/esb/contiki-esb-main.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: contiki-esb-main.c,v 1.17 2010/02/03 13:59:55 nifi Exp $ + * @(#)$Id: contiki-esb-main.c,v 1.18 2010/03/02 22:40:39 nifi Exp $ */ #include @@ -37,10 +37,24 @@ #include #include "contiki.h" +#include "contiki-esb.h" #include "dev/watchdog.h" #include "sys/autostart.h" -#include "contiki-esb.h" +#include "net/uip-driver.h" +#include "net/netstack.h" + +#if WITH_UIP + +static struct uip_fw_netif tr1001if = + {UIP_FW_NETIF(0,0,0,0, 0,0,0,0, uip_driver_send)}; + +#if WITH_SLIP +static struct uip_fw_netif slipif = + {UIP_FW_NETIF(172,16,0,0, 255,255,255,0, slip_send)}; +#endif /* WITH_SLIP */ + +#endif /* WITH_UIP */ #ifdef DCOSYNCH_CONF_PERIOD #define DCOSYNCH_PERIOD DCOSYNCH_CONF_PERIOD @@ -62,6 +76,53 @@ SENSORS(&button_sensor, &sound_sensor, &vib_sensor, &pir_sensor, &radio_sensor, &battery_sensor, &ctsrts_sensor, &temperature_sensor); +/*---------------------------------------------------------------------------*/ +static void +set_rime_addr(void) +{ + int i; + rimeaddr_t rimeaddr; + + rimeaddr.u8[0] = node_id & 0xff; + rimeaddr.u8[1] = node_id >> 8; + rimeaddr_set_node_addr(&rimeaddr); + + printf("Rime started with address "); + for(i = 0; i < sizeof(rimeaddr.u8) - 1; i++) { + printf("%u.", rimeaddr.u8[i]); + } + printf("%u\n", rimeaddr.u8[i]); +} +/*---------------------------------------------------------------------------*/ +#if WITH_UIP +static void +init_uip_net(void) +{ + uip_ipaddr_t hostaddr; + + uip_init(); + uip_fw_init(); + + process_start(&tcpip_process, NULL); +#if WITH_SLIP + process_start(&slip_process, NULL); + rs232_set_input(slip_input_byte); +#endif /* WITH_SLIP */ + process_start(&uip_fw_process, NULL); + + if (node_id > 0) { + /* node id is set, construct an ip address based on the node id */ + uip_ipaddr(&hostaddr, 172, 16, 1, node_id & 0xff); + uip_sethostaddr(&hostaddr); + } + +#if WITH_SLIP + uip_fw_register(&slipif); +#endif /* WITH_SLIP */ + + uip_fw_default(&tr1001if); +} +#endif /* WITH_UIP */ /*---------------------------------------------------------------------------*/ static void print_processes(struct process * const processes[]) @@ -135,14 +196,7 @@ main(void) ctimer_init(); -#if PROFILE_CONF_ON - profile_init(); -#endif /* PROFILE_CONF_ON */ - -#if ENERGEST_CONF_ON - energest_init(); - ENERGEST_ON(ENERGEST_TYPE_CPU); -#endif /* ENERGEST_CONF_ON */ + set_rime_addr(); printf(CONTIKI_VERSION_STRING " started. "); if(node_id > 0) { @@ -151,13 +205,36 @@ main(void) printf("Node id is not set.\n"); } - init_net(); + netstack_init(); + + printf("%s %s, channel check rate %u Hz\n", + NETSTACK_MAC.name, NETSTACK_RDC.name, + CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1: + NETSTACK_RDC.channel_check_interval())); beep_spinup(); leds_on(LEDS_RED); clock_delay(100); leds_off(LEDS_RED); +#if !WITH_SLIP + rs232_set_input(serial_line_input_byte); + serial_line_init(); +#endif + +#if WITH_UIP + init_uip_net(); +#endif /* WITH_UIP */ + +#if PROFILE_CONF_ON + profile_init(); +#endif /* PROFILE_CONF_ON */ + +#if ENERGEST_CONF_ON + energest_init(); + ENERGEST_ON(ENERGEST_TYPE_CPU); +#endif /* ENERGEST_CONF_ON */ + init_apps(); print_processes(autostart_processes); autostart_start(autostart_processes); diff --git a/platform/esb/contiki-esb.h b/platform/esb/contiki-esb.h index 89da16a58..f16faf18d 100644 --- a/platform/esb/contiki-esb.h +++ b/platform/esb/contiki-esb.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: contiki-esb.h,v 1.5 2009/03/17 20:19:11 adamdunkels Exp $ + * @(#)$Id: contiki-esb.h,v 1.6 2010/03/02 22:40:39 nifi Exp $ */ #ifndef __CONTIKI_ESB_H__ #define __CONTIKI_ESB_H__ @@ -46,8 +46,6 @@ #include "dev/serial-line.h" #include "dev/slip.h" -#include "dev/tr1001.h" -#include "net/tr1001-uip.h" #include "node-id.h" @@ -71,7 +69,5 @@ void msp430_cpu_init(void); void init_lowlevel(void); void init_apps(void); -void init_net(void); - #endif /* __CONTIKI_ESB_H__ */ diff --git a/platform/esb/dev/tr1001-gcr.c b/platform/esb/dev/tr1001-gcr.c index 1bdf234eb..d2c2a58d8 100644 --- a/platform/esb/dev/tr1001-gcr.c +++ b/platform/esb/dev/tr1001-gcr.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: tr1001-gcr.c,v 1.14 2009/11/19 18:04:02 nifi Exp $ + * @(#)$Id: tr1001-gcr.c,v 1.15 2010/03/02 22:40:39 nifi Exp $ */ /** * \addtogroup esb @@ -56,6 +56,7 @@ #include "dev/radio-sensor.h" #include "lib/gcr.h" #include "lib/crc16.h" +#include "net/netstack.h" #include "net/rime/rimestats.h" #include @@ -88,6 +89,11 @@ #define RXBUFSIZE PACKETBUF_SIZE #endif /* TR1001_CONF_BUFFER_SIZE */ +/* + * Pending data to send when using prepare/transmit functions. + */ +static const void *pending_data; + /* * The buffer which holds incoming data. */ @@ -140,7 +146,6 @@ static unsigned short tmp_sstrength, sstrength; static unsigned short tmp_count; #define DEBUG 0 - #if DEBUG #include #define LOG(...) printf(__VA_ARGS__) @@ -154,16 +159,23 @@ static unsigned short tmp_count; PROCESS(tr1001_process, "TR1001 driver"); /*---------------------------------------------------------------------------*/ -static void (* receiver_callback)(const struct radio_driver *); - -static void tr1001_set_receiver(void (* recv)(const struct radio_driver *)); +static int prepare_packet(const void *data, unsigned short len); +static int transmit_packet(unsigned short len); +static int receiving_packet(void); +static int pending_packet(void); +static int channel_clear(void); static int tr1001_on(void); static int tr1001_off(void); const struct radio_driver tr1001_driver = { + tr1001_init, + prepare_packet, + transmit_packet, tr1001_send, tr1001_read, - tr1001_set_receiver, + channel_clear, + receiving_packet, + pending_packet, tr1001_on, tr1001_off }; @@ -312,7 +324,6 @@ sendx_crc16(unsigned char b, uint16_t crcacc) } return crcacc; } - /*---------------------------------------------------------------------------*/ void tr1001_set_txpower(unsigned char p) @@ -344,13 +355,7 @@ tr1001_set_txpower(unsigned char p) P2OUT |= 0x40; /* P26 = 1 (chipselect off) */ } /*---------------------------------------------------------------------------*/ -static void -tr1001_set_receiver(void (* recv)(const struct radio_driver *)) -{ - receiver_callback = recv; -} -/*---------------------------------------------------------------------------*/ -void +int tr1001_init(void) { PT_INIT(&rxhandler_pt); @@ -377,6 +382,8 @@ tr1001_init(void) rxclear(); process_start(&tr1001_process, NULL); + + return 1; } /*---------------------------------------------------------------------------*/ interrupt (UART0RX_VECTOR) @@ -552,22 +559,44 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte)) PT_END(&rxhandler_pt); } /*---------------------------------------------------------------------------*/ -/* - * Prepare a transmission. - * - * This function does the necessary setup before a packet can be sent - * out. - */ -static void -prepare_transmission(int synchbytes) +static int +prepare_packet(const void *data, unsigned short len) +{ + pending_data = data; + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +transmit_packet(unsigned short len) +{ + int ret = RADIO_TX_ERR; + if(pending_data != NULL) { + ret = tr1001_send(pending_data, len); + pending_data = NULL; + } + return ret; +} +/*---------------------------------------------------------------------------*/ +int +tr1001_send(const void *packet, unsigned short len) { int i; + uint16_t crc16; + + LOG("tr1001_send: sending %d bytes\n", len); + + if(onoroff == ON) { + ENERGEST_OFF(ENERGEST_TYPE_LISTEN); + } + ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); + + /* Prepare the transmission. */ /* Delay the transmission for a short random duration. */ clock_delay(random_rand() & 0x3ff); - /* Check that we don't currently are receiveing a packet, and if so + /* Check that we don't currently are receiving a packet, and if so we wait until the reception has been completed. Reception is done with interrupts so it is OK for us to wait in a while() loop. */ @@ -588,8 +617,6 @@ prepare_transmission(int synchbytes) /* Transmit preamble and synch bytes. */ - - for(i = 0; i < 20; ++i) { send(0xaa); } @@ -597,29 +624,11 @@ prepare_transmission(int synchbytes) send(0xaa);*/ send(0xff); - for(i = 0; i < synchbytes; ++i) { + for(i = 0; i < NUM_SYNCHBYTES; ++i) { send(SYNCH1); } send(SYNCH2); -} -/*---------------------------------------------------------------------------*/ -int -tr1001_send(const void *packet, unsigned short len) -{ - int i; - uint16_t crc16; - - LOG("tr1001_send: sending %d bytes\n", len); - - if(onoroff == ON) { - ENERGEST_OFF(ENERGEST_TYPE_LISTEN); - } - ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); - - /* Prepare the transmission. */ - prepare_transmission(NUM_SYNCHBYTES); - crc16 = 0xffff; gcr_init(); @@ -702,8 +711,29 @@ tr1001_read(void *buf, unsigned short bufsize) return 0; } /*---------------------------------------------------------------------------*/ +static int +receiving_packet(void) +{ + return tr1001_rxstate == RXSTATE_RECEIVING && + !timer_expired(&rxtimer); +} +/*---------------------------------------------------------------------------*/ +static int +pending_packet(void) +{ + return tr1001_rxstate == RXSTATE_FULL; +} +/*---------------------------------------------------------------------------*/ +static int +channel_clear(void) +{ + /* TODO add CCA functionality */ + return 0; +} +/*---------------------------------------------------------------------------*/ PROCESS_THREAD(tr1001_process, ev, data) { + int len; PROCESS_BEGIN(); /* Reset reception state now that the process is ready to receive data. */ @@ -711,13 +741,11 @@ PROCESS_THREAD(tr1001_process, ev, data) while(1) { PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); - if(receiver_callback != NULL) { - receiver_callback(&tr1001_driver); - } else { - LOG("tr1001 has no receive function\n"); - - /* Perform a dummy read to drop the message. */ - tr1001_read((uint8_t *)&data, 0); + packetbuf_clear(); + len = tr1001_read(packetbuf_dataptr(), PACKETBUF_SIZE); + if(len > 0) { + packetbuf_set_datalen(len); + NETSTACK_RDC.input(); } } @@ -756,6 +784,6 @@ tr1001_sstrength(void) { return sstrength; } -/*--------------------------------------------------------------------------*/ +/*---------------------------------------------------------------------------*/ /** @} */ /** @} */ diff --git a/platform/esb/dev/tr1001.c b/platform/esb/dev/tr1001.c index bbd991224..35c24413c 100644 --- a/platform/esb/dev/tr1001.c +++ b/platform/esb/dev/tr1001.c @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: tr1001.c,v 1.12 2009/11/19 18:04:02 nifi Exp $ + * @(#)$Id: tr1001.c,v 1.13 2010/03/02 22:40:39 nifi Exp $ */ /** * \addtogroup esb @@ -56,6 +56,7 @@ #include "dev/radio-sensor.h" #include "lib/me.h" #include "lib/crc16.h" +#include "net/netstack.h" #include "net/rime/rimestats.h" #include @@ -88,6 +89,11 @@ #define RXBUFSIZE PACKETBUF_SIZE #endif /* TR1001_CONF_BUFFER_SIZE */ +/* + * Pending data to send when using prepare/transmit functions. + */ +static const void *pending_data; + /* * The buffer which holds incoming data. */ @@ -151,16 +157,23 @@ static unsigned short tmp_count; PROCESS(tr1001_process, "TR1001 driver"); /*---------------------------------------------------------------------------*/ -static void (* receiver_callback)(const struct radio_driver *); - -static void tr1001_set_receiver(void (* recv)(const struct radio_driver *)); +static int prepare_packet(const void *data, unsigned short len); +static int transmit_packet(unsigned short len); +static int receiving_packet(void); +static int pending_packet(void); +static int channel_clear(void); static int tr1001_on(void); static int tr1001_off(void); const struct radio_driver tr1001_driver = { + tr1001_init, + prepare_packet, + transmit_packet, tr1001_send, tr1001_read, - tr1001_set_receiver, + channel_clear, + receiving_packet, + pending_packet, tr1001_on, tr1001_off }; @@ -333,16 +346,9 @@ tr1001_set_txpower(unsigned char p) P2OUT |= 0x40; /* P26 = 1 (chipselect off) */ } /*---------------------------------------------------------------------------*/ -static void -tr1001_set_receiver(void (* recv)(const struct radio_driver *)) -{ - receiver_callback = recv; -} -/*---------------------------------------------------------------------------*/ -void +int tr1001_init(void) { - PT_INIT(&rxhandler_pt); onoroff = OFF; @@ -367,6 +373,8 @@ tr1001_init(void) rxclear(); process_start(&tr1001_process, NULL); + + return 1; } /*---------------------------------------------------------------------------*/ interrupt (UART0RX_VECTOR) @@ -548,22 +556,44 @@ PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte)) PT_END(&rxhandler_pt); } /*---------------------------------------------------------------------------*/ -/* - * Prepare a transmission. - * - * This function does the necessary setup before a packet can be sent - * out. - */ -static void -prepare_transmission(int synchbytes) +static int +prepare_packet(const void *data, unsigned short len) +{ + pending_data = data; + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +transmit_packet(unsigned short len) +{ + int ret = RADIO_TX_ERR; + if(pending_data != NULL) { + ret = tr1001_send(pending_data, len); + pending_data = NULL; + } + return ret; +} +/*---------------------------------------------------------------------------*/ +int +tr1001_send(const void *packet, unsigned short len) { int i; + uint16_t crc16; + + LOG("tr1001_send: sending %d bytes\n", len); + + if(onoroff == ON) { + ENERGEST_OFF(ENERGEST_TYPE_LISTEN); + } + ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); + + /* Prepare the transmission. */ /* Delay the transmission for a short random duration. */ clock_delay(random_rand() & 0x3ff); - /* Check that we don't currently are receiveing a packet, and if so + /* Check that we don't currently are receiving a packet, and if so we wait until the reception has been completed. Reception is done with interrupts so it is OK for us to wait in a while() loop. */ @@ -584,8 +614,6 @@ prepare_transmission(int synchbytes) /* Transmit preamble and synch bytes. */ - - for(i = 0; i < 20; ++i) { send(0xaa); } @@ -593,29 +621,11 @@ prepare_transmission(int synchbytes) send(0xaa);*/ send(0xff); - for(i = 0; i < synchbytes; ++i) { + for(i = 0; i < NUM_SYNCHBYTES; ++i) { send(SYNCH1); } send(SYNCH2); -} -/*---------------------------------------------------------------------------*/ -int -tr1001_send(const void *packet, unsigned short len) -{ - int i; - uint16_t crc16; - - LOG("tr1001_send: sending %d bytes\n", len); - - if(onoroff == ON) { - ENERGEST_OFF(ENERGEST_TYPE_LISTEN); - } - ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); - - /* Prepare the transmission. */ - prepare_transmission(NUM_SYNCHBYTES); - crc16 = 0xffff; /* Send packet header. */ @@ -687,8 +697,29 @@ tr1001_read(void *buf, unsigned short bufsize) return 0; } /*---------------------------------------------------------------------------*/ +static int +receiving_packet(void) +{ + return tr1001_rxstate == RXSTATE_RECEIVING && + !timer_expired(&rxtimer); +} +/*---------------------------------------------------------------------------*/ +static int +pending_packet(void) +{ + return tr1001_rxstate == RXSTATE_FULL; +} +/*---------------------------------------------------------------------------*/ +static int +channel_clear(void) +{ + /* TODO add CCA functionality */ + return 0; +} +/*---------------------------------------------------------------------------*/ PROCESS_THREAD(tr1001_process, ev, data) { + int len; PROCESS_BEGIN(); /* Reset reception state now that the process is ready to receive data. */ @@ -696,13 +727,11 @@ PROCESS_THREAD(tr1001_process, ev, data) while(1) { PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); - if(receiver_callback != NULL) { - receiver_callback(&tr1001_driver); - } else { - LOG("tr1001 has no receive function\n"); - - /* Perform a dummy read to drop the message. */ - tr1001_read(&data, 0); + packetbuf_clear(); + len = tr1001_read(packetbuf_dataptr(), PACKETBUF_SIZE); + if(len > 0) { + packetbuf_set_datalen(len); + NETSTACK_RDC.input(); } } diff --git a/platform/esb/dev/tr1001.h b/platform/esb/dev/tr1001.h index fc5d79c49..a775684d6 100644 --- a/platform/esb/dev/tr1001.h +++ b/platform/esb/dev/tr1001.h @@ -28,7 +28,7 @@ * * This file is part of the Contiki operating system. * - * @(#)$Id: tr1001.h,v 1.8 2008/07/09 20:45:06 nifi Exp $ + * @(#)$Id: tr1001.h,v 1.9 2010/03/02 22:40:39 nifi Exp $ */ #ifndef __TR1001_H__ #define __TR1001_H__ @@ -49,7 +49,7 @@ extern const struct radio_driver tr1001_driver; * Turns on reception of bytes and installs the receive interrupt * handler. */ -void tr1001_init(void); +int tr1001_init(void); /** * Set the speed of the TR1001 radio device. diff --git a/platform/esb/net/tr1001-uip.c b/platform/esb/net/uip-driver.c similarity index 59% rename from platform/esb/net/tr1001-uip.c rename to platform/esb/net/uip-driver.c index de0297074..425e45047 100644 --- a/platform/esb/net/tr1001-uip.c +++ b/platform/esb/net/uip-driver.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Swedish Institute of Computer Science + * Copyright (c) 2010, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,40 +26,62 @@ * 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: tr1001-uip.c,v 1.2 2007/08/07 11:14:39 nifi Exp $ + * $Id: uip-driver.c,v 1.1 2010/03/02 22:40:39 nifi Exp $ */ -#include "contiki-esb.h" -#include "net/hc.h" +/** + * \file + * A brief description of what this file is + * \author + * Niclas Finne + * Joakim Eriksson + */ -/*---------------------------------------------------------------------------*/ +#include "net/netstack.h" +#include "net/uip.h" +#include "net/tcpip.h" +#include "net/hc.h" +#include "net/rime/packetbuf.h" +#include "net/uip-driver.h" +#include + +/*--------------------------------------------------------------------*/ static void -tr1001_uip_callback(const struct radio_driver *driver) +init(void) { - uip_len = driver->read(&uip_buf[UIP_LLH_LEN], UIP_BUFSIZE - UIP_LLH_LEN); - if(uip_len > 0) { - uip_len = hc_inflate(&uip_buf[UIP_LLH_LEN], uip_len); + /* + * Set out output function as the function to be called from uIP to + * send a packet. + */ + tcpip_set_outputfunc(uip_driver_send); +} +/*--------------------------------------------------------------------*/ +static void +input(void) +{ + if(packetbuf_datalen() > 0 && + packetbuf_datalen() <= UIP_BUFSIZE - UIP_LLH_LEN) { + memcpy(&uip_buf[UIP_LLH_LEN], packetbuf_dataptr(), packetbuf_datalen()); + uip_len = hc_inflate(&uip_buf[UIP_LLH_LEN], packetbuf_datalen()); tcpip_input(); } } -/*---------------------------------------------------------------------------*/ -void -tr1001_uip_init() -{ - tr1001_init(); - tr1001_driver.set_receive_function(tr1001_uip_callback); -} -/*---------------------------------------------------------------------------*/ -u8_t -tr1001_uip_send(void) +/*--------------------------------------------------------------------*/ +uint8_t +uip_driver_send(void) { uip_len = hc_compress(&uip_buf[UIP_LLH_LEN], uip_len); - if (tr1001_driver.send(&uip_buf[UIP_LLH_LEN], uip_len) == 0) { - return UIP_FW_OK; - } else { - return UIP_FW_DROPPED; - } + packetbuf_copyfrom(&uip_buf[UIP_LLH_LEN], uip_len); + + /* XXX we should provide a callback function that is called when the + packet is sent. For now, we just supply a NULL pointer. */ + NETSTACK_MAC.send(NULL, NULL); + return 1; } -/*---------------------------------------------------------------------------*/ +/*--------------------------------------------------------------------*/ +const struct network_driver uip_driver = { + "uip", + init, + input +}; +/*--------------------------------------------------------------------*/ diff --git a/platform/esb/net/tr1001-uip.h b/platform/esb/net/uip-driver.h similarity index 76% rename from platform/esb/net/tr1001-uip.h rename to platform/esb/net/uip-driver.h index 4c46fd19f..a0e694020 100644 --- a/platform/esb/net/tr1001-uip.h +++ b/platform/esb/net/uip-driver.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Swedish Institute of Computer Science + * Copyright (c) 2010, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,14 +26,24 @@ * 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: tr1001-uip.h,v 1.2 2007/08/07 11:14:39 nifi Exp $ + * $Id: uip-driver.h,v 1.1 2010/03/02 22:40:39 nifi Exp $ */ -#ifndef __TR1001_UIP_H__ -#define __TR1001_UIP_H__ -void tr1001_uip_init(); -u8_t tr1001_uip_send(void); +/** + * \file + * A brief description of what this file is + * \author + * Niclas Finne + * Joakim Eriksson + */ -#endif /* __TR1001_UIP_H__ */ +#ifndef __UIP_DRIVER_H__ +#define __UIP_DRIVER_H__ + +#include "net/netstack.h" + +uint8_t uip_driver_send(void); + +extern const struct network_driver uip_driver; + +#endif /* __UIP_DRIVER_H__ */