From: sdhsdh Date: Wed, 16 Sep 2009 22:23:12 +0000 (+0000) Subject: - add RF230 chip support for IRIS X-Git-Tag: rc_6_tinyos_2_1_1~256 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=152cde92b9bc426618d0ebb1c96736304ec2d85f - add RF230 chip support for IRIS - fix a couple bugs and make warnings --- diff --git a/apps/IPBaseStation/Makefile b/apps/IPBaseStation/Makefile index f2135530..3bf89893 100644 --- a/apps/IPBaseStation/Makefile +++ b/apps/IPBaseStation/Makefile @@ -12,7 +12,9 @@ CFLAGS += -DNO_IP_MALLOC # memmove. This doesn't mean that motes running blip also need this-- # they can use IFRAMES or IEEE154FRAMES CFLAGS += -DIEEE154FRAMES_ENABLED -CFLAGS += -DTOSH_DATA_LENGTH=104 +# when using IEEE154Frames, the maximum payload size is 2 larger, +# since the header is two smaller. +BLIP_L2_MTU = 104 # # debugging # diff --git a/apps/UDPEcho/Makefile b/apps/UDPEcho/Makefile index f883f1bd..5db98c8e 100644 --- a/apps/UDPEcho/Makefile +++ b/apps/UDPEcho/Makefile @@ -4,6 +4,7 @@ COMPONENT=UDPEchoC # BOOTLOADER=tosboot CFLAGS += -DCC2420_DEF_CHANNEL=15 +CFLAGS += -DRF230_DEF_CHANNEL=15 # CFLAGS += -DCC2420_DEF_RFPOWER=4 # disables support for the AM stack, which somewhat reduces code size @@ -11,6 +12,7 @@ CFLAGS += -DCC2420_DEF_CHANNEL=15 # protocols which are AM-based, you should not include this. CFLAGS += -DIEEE154FRAMES_ENABLED + # lib6lowpan contains inet_ntop6 and inet_pton6 to process ascii # representations of IPv6 addresses. You can remove them to save some # code if you don't use them diff --git a/support/make/blip.extra b/support/make/blip.extra index 741cb6e3..d3deacaa 100644 --- a/support/make/blip.extra +++ b/support/make/blip.extra @@ -1,15 +1,20 @@ # -*- makefile -*- -PFLAGS +=-DPACKET_LINK -DDEF_MEMCPY -# PFLAGS += -DCC2420_HW_ACKNOWLEDGEMENTS -PFLAGS += -DTOSH_DATA_LENGTH=102 +# radio stack defs +PFLAGS += -DPACKET_LINK -DDEF_MEMCPY +PFLAGS += -DENABLE_SPI0_DMA -DBLIP_MULTICAST +PFLAGS += -DCC2420_HW_ACKNOWLEDGEMENTS + +ifdef BLIP_L2_MTU + PFLAGS += -DTOSH_DATA_LENGTH=$(BLIP_L2_MTU) +else + PFLAGS += -DTOSH_DATA_LENGTH=102 +endif ifndef LOWPAN_ROOT LOWPAN_ROOT=$(TOSROOT) endif -PFLAGS+=-DENABLE_SPI0_DMA - PFLAGS+=-I$(TOSROOT)/tos/lib/net/ PFLAGS+=-I$(LOWPAN_ROOT)/support/sdk/c/blip/lib6lowpan/ PFLAGS+=-I$(LOWPAN_ROOT)/support/sdk/c/blip/libtcp/ @@ -25,4 +30,4 @@ PFLAGS+=$(LOWPAN_ROOT)/support/sdk/c/blip/lib6lowpan/lib6lowpanIP.c PFLAGS+=$(LOWPAN_ROOT)/support/sdk/c/blip/lib6lowpan/lib6lowpanFrag.c PFLAGS+=$(LOWPAN_ROOT)/support/sdk/c/blip/lib6lowpan/in_cksum.c PFLAGS+=$(LOWPAN_ROOT)/support/sdk/c/blip/lib6lowpan/ip_malloc.c - +PFLAGS+=$(LOWPAN_ROOT)/tos/lib/net/blip/table.c diff --git a/support/sdk/c/blip/driver/radvd-1.0/device.c b/support/sdk/c/blip/driver/radvd-1.0/device.c deleted file mode 100644 index 85579d33..00000000 --- a/support/sdk/c/blip/driver/radvd-1.0/device.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - * $Id$ - * - * Authors: - * Lars Fenneberg - * - * This software is Copyright 1996,1997 by the above mentioned author(s), - * All Rights Reserved. - * - * The license which is distributed with this software in the file COPYRIGHT - * applies to this software. If your distribution is missing this file, you - * may request it from . - * - */ - -#include "config.h" -#include "includes.h" -#include "radvd.h" -#include "defaults.h" -#include "pathnames.h" /* for PATH_PROC_NET_IF_INET6 */ - -#ifndef IPV6_ADDR_LINKLOCAL -#define IPV6_ADDR_LINKLOCAL 0x0020U -#endif - -/* - * this function gets the hardware type and address of an interface, - * determines the link layer token length and checks it against - * the defined prefixes - */ -int -setup_deviceinfo(int sock, struct Interface *iface) -{ - struct ifreq ifr; - struct AdvPrefix *prefix; - char zero[sizeof(iface->if_addr)]; - - strncpy(ifr.ifr_name, iface->Name, IFNAMSIZ-1); - ifr.ifr_name[IFNAMSIZ-1] = '\0'; - - if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) { - flog(LOG_ERR, "ioctl(SIOCGIFMTU) failed for %s: %s", - iface->Name, strerror(errno)); - return (-1); - } - - dlog(LOG_DEBUG, 3, "mtu for %s is %d", iface->Name, ifr.ifr_mtu); - iface->if_maxmtu = ifr.ifr_mtu; - - if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) - { - flog(LOG_ERR, "ioctl(SIOCGIFHWADDR) failed for %s: %s", - iface->Name, strerror(errno)); - return (-1); - } - - dlog(LOG_DEBUG, 3, "hardware type for %s is %d", iface->Name, - ifr.ifr_hwaddr.sa_family); - - switch(ifr.ifr_hwaddr.sa_family) - { - case ARPHRD_ETHER: - iface->if_hwaddr_len = 48; - iface->if_prefix_len = 64; - break; -#ifdef ARPHRD_FDDI - case ARPHRD_FDDI: - iface->if_hwaddr_len = 48; - iface->if_prefix_len = 64; - break; -#endif /* ARPHDR_FDDI */ -#ifdef ARPHRD_ARCNET - case ARPHRD_ARCNET: - iface->if_hwaddr_len = 8; - iface->if_prefix_len = -1; - iface->if_maxmtu = -1; - break; -#endif /* ARPHDR_ARCNET */ - default: - iface->if_hwaddr_len = -1; - iface->if_prefix_len = -1; - iface->if_maxmtu = -1; - break; - } - - dlog(LOG_DEBUG, 3, "link layer token length for %s is %d", iface->Name, - iface->if_hwaddr_len); - - dlog(LOG_DEBUG, 3, "prefix length for %s is %d", iface->Name, - iface->if_prefix_len); - - if (iface->if_hwaddr_len != -1) { - unsigned int if_hwaddr_len_bytes = (iface->if_hwaddr_len + 7) >> 3; - - if (if_hwaddr_len_bytes > sizeof(iface->if_hwaddr)) { - flog(LOG_ERR, "address length %d too big for %s", if_hwaddr_len_bytes, iface->Name); - return(-2); - } - memcpy(iface->if_hwaddr, ifr.ifr_hwaddr.sa_data, if_hwaddr_len_bytes); - - memset(zero, 0, sizeof(zero)); - if (!memcmp(iface->if_hwaddr, zero, if_hwaddr_len_bytes)) - flog(LOG_WARNING, "WARNING, MAC address on %s is all zero!", - iface->Name); - } - - prefix = iface->AdvPrefixList; - while (prefix) - { - if ((iface->if_prefix_len != -1) && - (iface->if_prefix_len != prefix->PrefixLen)) - { - flog(LOG_WARNING, "prefix length should be %d for %s", - iface->if_prefix_len, iface->Name); - } - - prefix = prefix->next; - } - - return (0); -} - -/* - * this function extracts the link local address and interface index - * from PATH_PROC_NET_IF_INET6. Note: 'sock' unused in Linux. - */ -int setup_linklocal_addr(int sock, struct Interface *iface) -{ - FILE *fp; - char str_addr[40]; - unsigned int plen, scope, dad_status, if_idx; - char devname[IFNAMSIZ]; - - if ((fp = fopen(PATH_PROC_NET_IF_INET6, "r")) == NULL) - { - flog(LOG_ERR, "can't open %s: %s", PATH_PROC_NET_IF_INET6, - strerror(errno)); - return (-1); - } - - while (fscanf(fp, "%32s %x %02x %02x %02x %15s\n", - str_addr, &if_idx, &plen, &scope, &dad_status, - devname) != EOF) - { - if (scope == IPV6_ADDR_LINKLOCAL && - strcmp(devname, iface->Name) == 0) - { - struct in6_addr addr; - unsigned int ap; - int i; - - for (i=0; i<16; i++) - { - sscanf(str_addr + i * 2, "%02x", &ap); - addr.s6_addr[i] = (unsigned char)ap; - } - memcpy(&iface->if_addr, &addr, sizeof(iface->if_addr)); - - iface->if_index = if_idx; - fclose(fp); - return 0; - } - } - - flog(LOG_ERR, "no linklocal address configured for %s", iface->Name); - fclose(fp); - return (-1); -} - -int setup_allrouters_membership(int sock, struct Interface *iface) -{ - struct ipv6_mreq mreq; - - memset(&mreq, 0, sizeof(mreq)); - mreq.ipv6mr_interface = iface->if_index; - - /* ipv6-allrouters: ff02::2 */ - mreq.ipv6mr_multiaddr.s6_addr32[0] = htonl(0xFF020000); - mreq.ipv6mr_multiaddr.s6_addr32[3] = htonl(0x2); - - if (setsockopt(sock, SOL_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) - { - /* linux-2.6.12-bk4 returns error with HUP signal but keep listening */ - if (errno != EADDRINUSE) - { - flog(LOG_ERR, "can't join ipv6-allrouters on %s", iface->Name); - return (-1); - } - } - - return (0); -} - -int check_allrouters_membership(int sock, struct Interface *iface) -{ - #define ALL_ROUTERS_MCAST "ff020000000000000000000000000002" - - FILE *fp; - unsigned int if_idx, allrouters_ok=0; - char addr[32+1]; - int ret=0; - - if ((fp = fopen(PATH_PROC_NET_IGMP6, "r")) == NULL) - { - flog(LOG_ERR, "can't open %s: %s", PATH_PROC_NET_IGMP6, - strerror(errno)); - return (-1); - } - - while ( (ret=fscanf(fp, "%u %*s %32[0-9A-Fa-f] %*x %*x %*x\n", &if_idx, addr)) != EOF) { - if (ret == 2) { - if (iface->if_index == if_idx) { - if (strncmp(addr, ALL_ROUTERS_MCAST, sizeof(addr)) == 0) - allrouters_ok = 1; - } - } - } - - fclose(fp); - - if (!allrouters_ok) { - flog(LOG_WARNING, "resetting ipv6-allrouters membership on %s", iface->Name); - setup_allrouters_membership(sock, iface); - } - - return(0); -} - -static int -set_interface_var(const char *iface, - const char *var, const char *name, - uint32_t val) -{ - FILE *fp; - char spath[64+IFNAMSIZ]; /* XXX: magic constant */ - snprintf(spath, sizeof(spath), var, iface); - - fp = fopen(spath, "w"); - if (!fp) { - if (name) - flog(LOG_ERR, "failed to set %s (%u) for %s", - name, val, iface); - return -1; - } - fprintf(fp, "%u", val); - fclose(fp); - - return 0; -} - -int -set_interface_linkmtu(const char *iface, uint32_t mtu) -{ - return set_interface_var(iface, - PROC_SYS_IP6_LINKMTU, "LinkMTU", - mtu); -} - -int -set_interface_curhlim(const char *iface, uint8_t hlim) -{ - return set_interface_var(iface, - PROC_SYS_IP6_CURHLIM, "CurHopLimit", - hlim); -} - -int -set_interface_reachtime(const char *iface, uint32_t rtime) -{ - int ret; - ret = set_interface_var(iface, - PROC_SYS_IP6_BASEREACHTIME_MS, - NULL, - rtime); - if (ret) - ret = set_interface_var(iface, - PROC_SYS_IP6_BASEREACHTIME, - "BaseReachableTimer", - rtime / 1000); - return ret; -} - -int -set_interface_retranstimer(const char *iface, uint32_t rettimer) -{ - int ret; - ret = set_interface_var(iface, - PROC_SYS_IP6_RETRANSTIMER_MS, - NULL, - rettimer); - if (ret) - ret = set_interface_var(iface, - PROC_SYS_IP6_RETRANSTIMER, - "RetransTimer", - rettimer / 1000); - return ret; -} - diff --git a/tos/lib/net/blip/IPDispatch.h b/tos/lib/net/blip/IPDispatch.h index 7bcd9372..24358996 100644 --- a/tos/lib/net/blip/IPDispatch.h +++ b/tos/lib/net/blip/IPDispatch.h @@ -41,11 +41,14 @@ enum { PATH_COST_DIFF_THRESH = 10, // Threshold for 'similar' path costs LQI_DIFF_THRESH = 10, // Threshold for 'similar' LQI's LINK_EVICT_THRESH = 50, // ETX * 10 - LQI_ADMIT_THRESH = 0x200, - RSSI_ADMIT_THRESH = 0, RANDOM_ROUTE = 20, //Percentage of time to select random default route + LQI_ADMIT_THRESH = 0x200, }; +/* chip-specific lqi values */ +uint16_t adjustLQI(uint8_t val); + + enum { WITHIN_THRESH = 1, ABOVE_THRESH = 2, diff --git a/tos/lib/net/blip/IPDispatchP.nc b/tos/lib/net/blip/IPDispatchP.nc index 86556537..419cd687 100644 --- a/tos/lib/net/blip/IPDispatchP.nc +++ b/tos/lib/net/blip/IPDispatchP.nc @@ -105,13 +105,8 @@ module IPDispatchP { interface ReadLqi; interface Packet; -#ifndef SIM interface Ieee154Send; interface Ieee154Packet; -#else - interface AMSend as Ieee154Send; - interface AMPacket as Ieee154Packet; -#endif interface Receive as Ieee154Receive; interface PacketLink; @@ -137,8 +132,6 @@ module IPDispatchP { } } implementation { -#include "table.c" - #ifdef PRINTFUART_ENABLED #undef dbg #define dbg(X, fmt, args...) printfUART(fmt, ## args) @@ -798,7 +791,7 @@ module IPDispatchP { call PacketLink.setRetries(s_entry->msg, s_entry->info->policy.retries); call PacketLink.setRetryDelay(s_entry->msg, s_entry->info->policy.delay); #ifdef LPL_SLEEP_INTERVAL - call LowPowerListening.setRxSleepInterval(s_entry->msg, LPL_SLEEP_INTERVAL); + call LowPowerListening.setRxSleepInterval(s_entry->msg, call LowPowerListening.getLocalSleepInterval()); #endif dbg("IPDispatch", "sendTask dest: 0x%x len: 0x%x \n", call Ieee154Packet.destination(s_entry->msg), @@ -977,7 +970,6 @@ module IPDispatchP { } event void Ieee154Send.sendDone(message_t *msg, error_t error) { - ip_statistics_t stat; send_entry_t *s_entry = call SendQueue.head(); radioBusy = FALSE; @@ -1017,6 +1009,7 @@ module IPDispatchP { s_entry->info->failed = TRUE; if (s_entry->info->policy.dest[0] != 0xffff) dbg("Drops", "drops: sendDone: frag was not delivered\n"); + BLIP_STATS_INCR(stats.tx_drop); done: s_entry->info->policy.actRetries = call PacketLink.getRetries(msg); @@ -1028,7 +1021,6 @@ module IPDispatchP { call SendQueue.dequeue(); post sendTask(); - call Statistics.get(&stat); } command struct tlv_hdr *IPExtensions.findTlv(struct ip6_ext *ext, uint8_t tlv_val) { diff --git a/tos/lib/net/blip/IPRoutingP.nc b/tos/lib/net/blip/IPRoutingP.nc index 10ed1b0f..4a509784 100644 --- a/tos/lib/net/blip/IPRoutingP.nc +++ b/tos/lib/net/blip/IPRoutingP.nc @@ -85,13 +85,6 @@ module IPRoutingP { void evictNeighbor(struct neigh_entry *neigh); uint16_t getMetric(struct neigh_entry *neigh); - uint16_t adjustLQI(uint8_t val) { - uint16_t result = (80 - (val - 50)); - result = (((result * result) >> 3) * result) >> 3; // result = (result ^ 3) / 64 - dbg("Lqi", "adjustLqi in: 0x%x out: 0x%x\n", val, result); - return result; - } - void clearStats(struct neigh_entry *r) { ip_memclr((uint8_t *)r->stats, sizeof(struct epoch_stats) * N_EPOCHS); #if 0 diff --git a/tos/lib/net/blip/ReadLqiC.nc b/tos/lib/net/blip/ReadLqiC.nc index 534f44a2..7debe7de 100644 --- a/tos/lib/net/blip/ReadLqiC.nc +++ b/tos/lib/net/blip/ReadLqiC.nc @@ -14,7 +14,7 @@ configuration ReadLqiC { #if defined(PLATFORM_MICAZ) || defined(PLATFORM_TELOSB) || \ defined(PLATFORM_EPIC) || defined(PLATFORM_SHIMMER) || \ - defined(PLATFORM_INTELMOTE2) + defined(PLATFORM_SHIMMER2) || defined(PLATFORM_INTELMOTE2) // cc2420 platforms components CC2420ReadLqiC, CC2420PacketC; ReadLqi = CC2420ReadLqiC; diff --git a/tos/lib/net/blip/UdpP.nc b/tos/lib/net/blip/UdpP.nc index cc800652..99c47c45 100644 --- a/tos/lib/net/blip/UdpP.nc +++ b/tos/lib/net/blip/UdpP.nc @@ -56,9 +56,11 @@ module UdpP { command error_t UDP.bind[uint8_t clnt](uint16_t port) { int i; port = htons(port); - for (i = 0; i < N_CLIENTS; i++) - if (i != clnt && local_ports[i] == port) - return FAIL; + if (port > 0) { + for (i = 0; i < N_CLIENTS; i++) + if (i != clnt && local_ports[i] == port) + return FAIL; + } local_ports[clnt] = port; return SUCCESS; } @@ -106,12 +108,12 @@ module UdpP { my_cksum = in_cksum(cksum_vec, 4); printfUART("rx cksum: %x calc: %x\n", rx_cksum, my_cksum); if (rx_cksum != my_cksum) { - BLIP_STATS_INCR(cksum); + BLIP_STATS_INCR(stats.cksum); // return; } } - BLIP_STATS_INCR(rcvd); + BLIP_STATS_INCR(stats.rcvd); signal UDP.recvfrom[i](&addr, (void *)(udph + 1), ntohs(iph->plen) - sizeof(struct udp_hdr), meta); } @@ -147,8 +149,8 @@ module UdpP { ip_memclr((uint8_t *)msg, sizeof(struct split_ip_msg)); ip_memclr((uint8_t *)udp, sizeof(struct udp_hdr)); - call IPAddress.setSource(&msg->hdr); memcpy(&msg->hdr.ip6_dst, dest->sin6_addr.s6_addr, 16); + call IPAddress.setSource(&msg->hdr); if (local_ports[clnt] == 0 && (local_ports[clnt] = alloc_lport(clnt)) == 0) { ip_free(msg); @@ -166,11 +168,12 @@ module UdpP { msg->headers = g_udp; msg->data_len = len; msg->data = payload; + msg->hdr.plen = udp->len; udp->chksum = htons(msg_cksum(msg, IANA_UDP)); rc = call IP.send(msg); - BLIP_STATS_INCR(sent); + BLIP_STATS_INCR(stats.sent); ip_free(msg); return rc; diff --git a/tos/lib/net/blip/platform/CC2420ReadLqiC.nc b/tos/lib/net/blip/platform/CC2420ReadLqiC.nc index da457eae..372d24c8 100644 --- a/tos/lib/net/blip/platform/CC2420ReadLqiC.nc +++ b/tos/lib/net/blip/platform/CC2420ReadLqiC.nc @@ -1,4 +1,10 @@ +uint16_t adjustLQI(uint8_t val) { + uint16_t result = (80 - (val - 50)); + result = (((result * result) >> 3) * result) >> 3; // result = (result ^ 3) / 64 + return result; +} + module CC2420ReadLqiC { provides interface ReadLqi; uses interface CC2420Packet; diff --git a/tos/lib/net/blip/platform/RF230ReadLqiC.nc b/tos/lib/net/blip/platform/RF230ReadLqiC.nc index 7a679033..f814aee6 100644 --- a/tos/lib/net/blip/platform/RF230ReadLqiC.nc +++ b/tos/lib/net/blip/platform/RF230ReadLqiC.nc @@ -1,4 +1,10 @@ +uint16_t adjustLQI(uint8_t val) { + uint16_t result = 64 - (val / 4); + result = (((result * result) >> 3) * result) >> 3; // result = (result ^ 3) / 64 + return result; +} + module RF230ReadLqiC { provides interface ReadLqi; uses interface PacketField as SubLqi;