From 2218d8ef8b97af2babb02be22415df4c124cccde Mon Sep 17 00:00:00 2001 From: julienabeille Date: Tue, 27 Jan 2009 10:57:28 +0000 Subject: [PATCH] Added an application and example to run IPSo interoperability test using RAVEN boards --- apps/raven-ipso/Makefile.raven-ipso | 4 + apps/raven-ipso/raven-ipso.c | 266 +++++++++++++++++++++++++ examples/ipso-ipv6-raven/Makefile | 9 + examples/ipso-ipv6-raven/Makefile.ipso | 10 + examples/ipso-ipv6-raven/ipso.c | 44 ++++ 5 files changed, 333 insertions(+) create mode 100755 apps/raven-ipso/Makefile.raven-ipso create mode 100755 apps/raven-ipso/raven-ipso.c create mode 100755 examples/ipso-ipv6-raven/Makefile create mode 100755 examples/ipso-ipv6-raven/Makefile.ipso create mode 100755 examples/ipso-ipv6-raven/ipso.c diff --git a/apps/raven-ipso/Makefile.raven-ipso b/apps/raven-ipso/Makefile.raven-ipso new file mode 100755 index 000000000..4963d2f9c --- /dev/null +++ b/apps/raven-ipso/Makefile.raven-ipso @@ -0,0 +1,4 @@ +raven-ipso_src = raven-ipso.c + + +CFLAGS+=-DRAVEN_LCD_INTERFACE=1 diff --git a/apps/raven-ipso/raven-ipso.c b/apps/raven-ipso/raven-ipso.c new file mode 100755 index 000000000..2ebab5cb6 --- /dev/null +++ b/apps/raven-ipso/raven-ipso.c @@ -0,0 +1,266 @@ +/* Copyright (c) 2008, 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: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + * + */ + +/** + * \brief This module contains code to interface a Contiki-based + * project on the AVR Raven platform's ATMega1284P chip to the LCD + * driver chip (ATMega3290P) on the Raven. + * + * \author Durvy Mathilde + * + */ + +/** \addtogroup raven + * @{ + */ + +/** + * \defgroup ravenserial Serial interface between Raven processors + * @{ + */ + +/** + * \file + * This file contains code to connect the two AVR Raven processors via + * a serial connection for the IPSO interop application + * + */ + +#include "contiki.h" +#include "contiki-lib.h" +#include "contiki-net.h" + +#include "frame.h" +#include "mac.h" + +#include "raven-lcd.h" + +#include +#include + +#define cmd_len 8 +#define data_len 20 + +static u8_t seqno; +uip_ipaddr_t ping_addr; +uip_ipaddr_t udp_addr; +static struct uip_udp_conn *udp_conn; +char udp_data[data_len]; + +static struct{ + u8_t frame[cmd_len]; + u8_t ndx; + u8_t len; + u8_t cmd; + u8_t done; +} cmd; + +#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) +#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) +#define CMD_PING 0x81 +#define CMD_TEMP 0x80 + +#define SOF_CHAR 1 +#define EOF_CHAR 4 + +void rs232_send(uint8_t port, unsigned char c); + + +/*------------------------------------------------------------------*/ +/* Sends a ping packet out the radio */ +static void +raven_ping6(void) +{ + + /* ping ipv6.google.com*/ + uip_ip6addr(&ping_addr,0x2001,0x420,0x5FFF,0x7D,0x2D0,0xB7FF,0xFE23,0xE6DB); + //uip_ip6addr(&ping_addr, 0x2001, 0x4860, 0, 0x2001, 0, 0, 0, 0x68); + //uip_ip6addr(&ping_addr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); + + UIP_IP_BUF->vtc = 0x60; + UIP_IP_BUF->tcflow = 1; + UIP_IP_BUF->flow = 0; + UIP_IP_BUF->proto = UIP_PROTO_ICMP6; + UIP_IP_BUF->ttl = uip_netif_physical_if.cur_hop_limit; + uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &ping_addr); + uip_netif_select_src(&UIP_IP_BUF->srcipaddr, &UIP_IP_BUF->destipaddr); + + UIP_ICMP_BUF->type = ICMP6_ECHO_REQUEST; + UIP_ICMP_BUF->icode = 0; + /* set identifier and sequence number to 0 */ + memset((void *)UIP_ICMP_BUF + UIP_ICMPH_LEN, 0, 4); + + uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN + UIP_IPH_LEN; + UIP_IP_BUF->len[0] = (u8_t)((uip_len - 40) >> 8); + UIP_IP_BUF->len[1] = (u8_t)((uip_len - 40) & 0x00FF); + + UIP_ICMP_BUF->icmpchksum = 0; + UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); + + tcpip_ipv6_output(); +} + +/*------------------------------------------------------------------*/ +/* Send a serial command frame to the ATMega3290 Processsor on Raven + via serial port */ +static void +send_frame(uint8_t cmd, uint8_t len, uint8_t *payload) +{ + uint8_t i; + + rs232_send(0, SOF_CHAR); /* Start of Frame */ + rs232_send(0, len); + rs232_send(0, cmd); + for (i=0;i= cmd.len+3){ + /* all done, check ETX */ + if (ch == 0x04){ + cmd.done = true; + process_post(&raven_lcd_process, SERIAL_CMD, 0); + } else { + /* Failed ETX */ + cmd.ndx = 0; + } + } else { + /* Just grab and store payload */ + cmd.frame[cmd.ndx - 3] = ch; + } + break; + } + + cmd.ndx++; + + return 0; +} + +/*---------------------------------------------------------------------------*/ +PROCESS(raven_lcd_process, "Raven LCD interface process"); +PROCESS_THREAD(raven_lcd_process, ev, data) +{ + u8_t error; + + PROCESS_BEGIN(); + + /*Create a udp connection to the IPSOserver*/ + + //swisscom uip_ip6addr(&udp_addr,0x2001,918,0xfff9,0,0,0,0,1); + //HE uip_ip6addr(&udp_addr,0x2001,0x470,0x1f12,0x5ec,0x12,0x13ff,0xfe14,0x1516); + uip_ip6addr(&udp_addr,0x2001,0x420,0x5FFF,0x7D,0x2D0,0xB7FF,0xFE23,0xE6DB); + + /* set destination parameters*/ + udp_conn = udp_new(&udp_addr, HTONS(0xF0B0), NULL); + /*set local port */ + udp_bind(udp_conn, HTONS(0xF0B0+1)); + + if((error = icmp6_new(NULL)) == 0) { + while(1) { + PROCESS_YIELD(); + raven_gui_loop(ev, data); + } + } + PROCESS_END(); +} +/** @} */ +/** @} */ diff --git a/examples/ipso-ipv6-raven/Makefile b/examples/ipso-ipv6-raven/Makefile new file mode 100755 index 000000000..93e5c4e57 --- /dev/null +++ b/examples/ipso-ipv6-raven/Makefile @@ -0,0 +1,9 @@ +all: + make -f Makefile.ipso TARGET=avr-raven ipso.elf + avr-objcopy -O ihex -R .eeprom ipso.elf ipso.hex + avr-size -C ipso.elf + +clean: + make -f Makefile.ipso TARGET=avr-raven clean + rm symbols.c symbols.h ipso.elf ipso.hex + rm -rf obj_avr-raven diff --git a/examples/ipso-ipv6-raven/Makefile.ipso b/examples/ipso-ipv6-raven/Makefile.ipso new file mode 100755 index 000000000..007011072 --- /dev/null +++ b/examples/ipso-ipv6-raven/Makefile.ipso @@ -0,0 +1,10 @@ + +all: ipso + +APPS=raven-ipso +TARGET=avr-raven +UIP_CONF_IPV6=1 +CONTIKI = ../.. + + +include $(CONTIKI)/Makefile.include diff --git a/examples/ipso-ipv6-raven/ipso.c b/examples/ipso-ipv6-raven/ipso.c new file mode 100755 index 000000000..bd9dd3f87 --- /dev/null +++ b/examples/ipso-ipv6-raven/ipso.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2006, 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. + * + */ +#include "contiki.h" + +/*---------------------------------------------------------------------------*/ +PROCESS(init_stack_process, "Init stack process"); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(init_stack_process, ev, data) +{ + PROCESS_BEGIN(); + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +AUTOSTART_PROCESSES(&init_stack_process); +/*---------------------------------------------------------------------------*/