From 707353f71bb40e1dfc701132ac4a261a079cbc3e Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 10 Jan 2016 15:01:58 +0000 Subject: [PATCH] Remove Sensinode platform, cpu, example and tools files This is part of a set of commits that will obsolete the Sensinode platform --- cpu/cc2430/8051def.h | 112 -- cpu/cc2430/Makefile.cc2430 | 116 --- cpu/cc2430/Makefile.customrules-cc2430 | 63 -- cpu/cc2430/bank-alloc.py | 228 ---- cpu/cc2430/cc2430_sfr.h | 709 ------------- cpu/cc2430/dev/bus.c | 58 -- cpu/cc2430/dev/bus.h | 53 - cpu/cc2430/dev/cc2430_rf.c | 750 -------------- cpu/cc2430/dev/cc2430_rf.h | 91 -- cpu/cc2430/dev/cc2430_rf_intr.c | 112 -- cpu/cc2430/dev/clock.c | 169 --- cpu/cc2430/dev/dma.c | 69 -- cpu/cc2430/dev/dma.h | 148 --- cpu/cc2430/dev/dma_intr.c | 73 -- cpu/cc2430/dev/hwconf.h | 148 --- cpu/cc2430/dev/lpm.h | 57 - cpu/cc2430/dev/random.c | 135 --- cpu/cc2430/dev/uart.h | 43 - cpu/cc2430/dev/uart0.c | 69 -- cpu/cc2430/dev/uart0.h | 31 - cpu/cc2430/dev/uart1.c | 74 -- cpu/cc2430/dev/uart1.h | 39 - cpu/cc2430/dev/uart_intr.c | 91 -- cpu/cc2430/dev/watchdog-cc2430.c | 129 --- cpu/cc2430/dev/watchdog-cc2430.h | 72 -- cpu/cc2430/mtarch.h | 49 - cpu/cc2430/rtimer-arch.c | 127 --- cpu/cc2430/rtimer-arch.h | 62 -- cpu/cc2430/segment.rules | 26 - cpu/cc2430/stack.c | 71 -- cpu/cc2430/stack.h | 68 -- examples/sensinode/Makefile | 17 - examples/sensinode/README.md | 60 -- examples/sensinode/blink-hello.c | 62 -- examples/sensinode/border-router/Makefile | 19 - examples/sensinode/border-router/README.md | 20 - .../sensinode/border-router/border-router.c | 150 --- .../sensinode/border-router/project-conf.h | 51 - .../sensinode/border-router/slip-bridge.c | 104 -- examples/sensinode/broadcast-rime.c | 119 --- .../sensinode/cc2431-location-engine/Makefile | 18 - .../cc2431-location-engine/blind-node.c | 280 ----- .../cc2431-location-engine/cc2431_loc_eng.h | 108 -- examples/sensinode/disco/Makefile | 18 - examples/sensinode/disco/disco-example.c | 53 - examples/sensinode/energy-scan/Makefile | 17 - examples/sensinode/energy-scan/energy-scan.c | 108 -- examples/sensinode/energy-scan/netstack.c | 49 - examples/sensinode/energy-scan/project-conf.h | 50 - examples/sensinode/energy-scan/stub-rdc.c | 100 -- examples/sensinode/event-post/Makefile | 17 - examples/sensinode/event-post/event-post.c | 98 -- examples/sensinode/event-post/event-post.h | 22 - examples/sensinode/sensors-ipv6/Makefile | 18 - .../sensinode/sensors-ipv6/project-conf.h | 52 - .../sensinode/sensors-ipv6/sensors-driver.c | 246 ----- .../sensinode/sensors-ipv6/sensors-ipv6.c | 154 --- examples/sensinode/sensors/Makefile | 17 - examples/sensinode/sensors/sensors-example.c | 376 ------- examples/sensinode/sensors/sensors-example.h | 53 - examples/sensinode/serial-flash/Makefile | 14 - examples/sensinode/serial-flash/flash.c | 268 ----- examples/sensinode/sniffer/Makefile | 16 - examples/sensinode/sniffer/README.md | 15 - examples/sensinode/sniffer/netstack.c | 49 - examples/sensinode/sniffer/project-conf.h | 52 - examples/sensinode/sniffer/sniffer.c | 54 - examples/sensinode/sniffer/stub-rdc.c | 100 -- examples/sensinode/timer-test.c | 139 --- examples/sensinode/udp-ipv6/Makefile | 20 - examples/sensinode/udp-ipv6/client.c | 213 ---- examples/sensinode/udp-ipv6/ping6.c | 139 --- examples/sensinode/udp-ipv6/project-conf.h | 52 - examples/sensinode/udp-ipv6/server.c | 207 ---- .../sensinode/Makefile.customrules-sensinode | 1 - platform/sensinode/Makefile.sensinode | 92 -- .../sensinode/apps/batmon/Makefile.batmon | 3 - platform/sensinode/apps/batmon/batmon.c | 230 ----- platform/sensinode/contiki-conf.h | 286 ----- platform/sensinode/contiki-sensinode-main.c | 382 ------- platform/sensinode/debug.c | 61 -- platform/sensinode/debug.h | 55 - platform/sensinode/dev/adc-sensor.c | 212 ---- platform/sensinode/dev/button-sensor.c | 205 ---- platform/sensinode/dev/button-sensor.h | 48 - platform/sensinode/dev/leds-arch.c | 90 -- platform/sensinode/dev/m25p16.c | 318 ------ platform/sensinode/dev/m25p16.h | 293 ------ platform/sensinode/dev/models.c | 95 -- platform/sensinode/dev/models.h | 60 -- platform/sensinode/dev/n740.c | 187 ---- platform/sensinode/dev/n740.h | 75 -- platform/sensinode/dev/sensinode-sensors.c | 81 -- platform/sensinode/dev/sensinode-sensors.h | 166 --- platform/sensinode/dev/slip-arch.c | 49 - platform/sensinode/disco.c | 350 ------- platform/sensinode/disco.h | 129 --- platform/sensinode/putchar.c | 39 - platform/sensinode/segment.rules | 13 - platform/sensinode/uip-debug.c | 82 -- platform/sensinode/viztool.c | 286 ----- tools/sensinode/nano_programmer/Makefile | 43 - tools/sensinode/nano_programmer/README.md | 38 - tools/sensinode/nano_programmer/cdi_program.c | 607 ----------- tools/sensinode/nano_programmer/ihex.c | 99 -- tools/sensinode/nano_programmer/ihex.h | 36 - tools/sensinode/nano_programmer/linux/port.c | 371 ------- .../sensinode/nano_programmer/nano_programmer | Bin 18776 -> 0 bytes tools/sensinode/nano_programmer/port.h | 94 -- tools/sensinode/nano_programmer/programmer.c | 440 -------- tools/sensinode/nano_programmer/programmer.h | 62 -- .../sensinode/nano_programmer/windows/port.c | 383 ------- tools/sensinode/nano_usb_programmer/Makefile | 32 - tools/sensinode/nano_usb_programmer/README.md | 60 -- .../sensinode/nano_usb_programmer/Rules.make | 14 - tools/sensinode/nano_usb_programmer/cdi.c | 506 --------- tools/sensinode/nano_usb_programmer/cdi.h | 44 - .../nano_usb_programmer/ftdi_linux/WinTypes.h | 116 --- .../nano_usb_programmer/ftdi_linux/ftd2xx.h | 975 ------------------ .../nano_usb_programmer/ftdi_win32/ftd2xx.h | 922 ----------------- tools/sensinode/nano_usb_programmer/ihex.c | 210 ---- tools/sensinode/nano_usb_programmer/ihex.h | 36 - tools/sensinode/nano_usb_programmer/main.c | 348 ------- tools/sensinode/nano_usb_programmer/prog.c | 372 ------- tools/sensinode/nano_usb_programmer/prog.h | 46 - 125 files changed, 17578 deletions(-) delete mode 100644 cpu/cc2430/8051def.h delete mode 100644 cpu/cc2430/Makefile.cc2430 delete mode 100644 cpu/cc2430/Makefile.customrules-cc2430 delete mode 100644 cpu/cc2430/bank-alloc.py delete mode 100644 cpu/cc2430/cc2430_sfr.h delete mode 100644 cpu/cc2430/dev/bus.c delete mode 100644 cpu/cc2430/dev/bus.h delete mode 100644 cpu/cc2430/dev/cc2430_rf.c delete mode 100644 cpu/cc2430/dev/cc2430_rf.h delete mode 100644 cpu/cc2430/dev/cc2430_rf_intr.c delete mode 100644 cpu/cc2430/dev/clock.c delete mode 100644 cpu/cc2430/dev/dma.c delete mode 100644 cpu/cc2430/dev/dma.h delete mode 100644 cpu/cc2430/dev/dma_intr.c delete mode 100644 cpu/cc2430/dev/hwconf.h delete mode 100644 cpu/cc2430/dev/lpm.h delete mode 100644 cpu/cc2430/dev/random.c delete mode 100644 cpu/cc2430/dev/uart.h delete mode 100644 cpu/cc2430/dev/uart0.c delete mode 100644 cpu/cc2430/dev/uart0.h delete mode 100644 cpu/cc2430/dev/uart1.c delete mode 100644 cpu/cc2430/dev/uart1.h delete mode 100644 cpu/cc2430/dev/uart_intr.c delete mode 100644 cpu/cc2430/dev/watchdog-cc2430.c delete mode 100644 cpu/cc2430/dev/watchdog-cc2430.h delete mode 100644 cpu/cc2430/mtarch.h delete mode 100644 cpu/cc2430/rtimer-arch.c delete mode 100644 cpu/cc2430/rtimer-arch.h delete mode 100644 cpu/cc2430/segment.rules delete mode 100644 cpu/cc2430/stack.c delete mode 100644 cpu/cc2430/stack.h delete mode 100644 examples/sensinode/Makefile delete mode 100644 examples/sensinode/README.md delete mode 100644 examples/sensinode/blink-hello.c delete mode 100644 examples/sensinode/border-router/Makefile delete mode 100644 examples/sensinode/border-router/README.md delete mode 100644 examples/sensinode/border-router/border-router.c delete mode 100644 examples/sensinode/border-router/project-conf.h delete mode 100644 examples/sensinode/border-router/slip-bridge.c delete mode 100644 examples/sensinode/broadcast-rime.c delete mode 100644 examples/sensinode/cc2431-location-engine/Makefile delete mode 100644 examples/sensinode/cc2431-location-engine/blind-node.c delete mode 100644 examples/sensinode/cc2431-location-engine/cc2431_loc_eng.h delete mode 100644 examples/sensinode/disco/Makefile delete mode 100644 examples/sensinode/disco/disco-example.c delete mode 100644 examples/sensinode/energy-scan/Makefile delete mode 100644 examples/sensinode/energy-scan/energy-scan.c delete mode 100644 examples/sensinode/energy-scan/netstack.c delete mode 100644 examples/sensinode/energy-scan/project-conf.h delete mode 100644 examples/sensinode/energy-scan/stub-rdc.c delete mode 100644 examples/sensinode/event-post/Makefile delete mode 100644 examples/sensinode/event-post/event-post.c delete mode 100644 examples/sensinode/event-post/event-post.h delete mode 100644 examples/sensinode/sensors-ipv6/Makefile delete mode 100644 examples/sensinode/sensors-ipv6/project-conf.h delete mode 100644 examples/sensinode/sensors-ipv6/sensors-driver.c delete mode 100644 examples/sensinode/sensors-ipv6/sensors-ipv6.c delete mode 100644 examples/sensinode/sensors/Makefile delete mode 100644 examples/sensinode/sensors/sensors-example.c delete mode 100644 examples/sensinode/sensors/sensors-example.h delete mode 100644 examples/sensinode/serial-flash/Makefile delete mode 100644 examples/sensinode/serial-flash/flash.c delete mode 100644 examples/sensinode/sniffer/Makefile delete mode 100644 examples/sensinode/sniffer/README.md delete mode 100644 examples/sensinode/sniffer/netstack.c delete mode 100644 examples/sensinode/sniffer/project-conf.h delete mode 100644 examples/sensinode/sniffer/sniffer.c delete mode 100644 examples/sensinode/sniffer/stub-rdc.c delete mode 100644 examples/sensinode/timer-test.c delete mode 100644 examples/sensinode/udp-ipv6/Makefile delete mode 100644 examples/sensinode/udp-ipv6/client.c delete mode 100644 examples/sensinode/udp-ipv6/ping6.c delete mode 100644 examples/sensinode/udp-ipv6/project-conf.h delete mode 100644 examples/sensinode/udp-ipv6/server.c delete mode 100644 platform/sensinode/Makefile.customrules-sensinode delete mode 100644 platform/sensinode/Makefile.sensinode delete mode 100644 platform/sensinode/apps/batmon/Makefile.batmon delete mode 100644 platform/sensinode/apps/batmon/batmon.c delete mode 100644 platform/sensinode/contiki-conf.h delete mode 100644 platform/sensinode/contiki-sensinode-main.c delete mode 100644 platform/sensinode/debug.c delete mode 100644 platform/sensinode/debug.h delete mode 100644 platform/sensinode/dev/adc-sensor.c delete mode 100644 platform/sensinode/dev/button-sensor.c delete mode 100644 platform/sensinode/dev/button-sensor.h delete mode 100644 platform/sensinode/dev/leds-arch.c delete mode 100644 platform/sensinode/dev/m25p16.c delete mode 100644 platform/sensinode/dev/m25p16.h delete mode 100644 platform/sensinode/dev/models.c delete mode 100644 platform/sensinode/dev/models.h delete mode 100644 platform/sensinode/dev/n740.c delete mode 100644 platform/sensinode/dev/n740.h delete mode 100644 platform/sensinode/dev/sensinode-sensors.c delete mode 100644 platform/sensinode/dev/sensinode-sensors.h delete mode 100644 platform/sensinode/dev/slip-arch.c delete mode 100644 platform/sensinode/disco.c delete mode 100644 platform/sensinode/disco.h delete mode 100644 platform/sensinode/putchar.c delete mode 100644 platform/sensinode/segment.rules delete mode 100644 platform/sensinode/uip-debug.c delete mode 100644 platform/sensinode/viztool.c delete mode 100644 tools/sensinode/nano_programmer/Makefile delete mode 100755 tools/sensinode/nano_programmer/README.md delete mode 100644 tools/sensinode/nano_programmer/cdi_program.c delete mode 100644 tools/sensinode/nano_programmer/ihex.c delete mode 100644 tools/sensinode/nano_programmer/ihex.h delete mode 100644 tools/sensinode/nano_programmer/linux/port.c delete mode 100755 tools/sensinode/nano_programmer/nano_programmer delete mode 100644 tools/sensinode/nano_programmer/port.h delete mode 100644 tools/sensinode/nano_programmer/programmer.c delete mode 100644 tools/sensinode/nano_programmer/programmer.h delete mode 100644 tools/sensinode/nano_programmer/windows/port.c delete mode 100644 tools/sensinode/nano_usb_programmer/Makefile delete mode 100644 tools/sensinode/nano_usb_programmer/README.md delete mode 100644 tools/sensinode/nano_usb_programmer/Rules.make delete mode 100644 tools/sensinode/nano_usb_programmer/cdi.c delete mode 100644 tools/sensinode/nano_usb_programmer/cdi.h delete mode 100644 tools/sensinode/nano_usb_programmer/ftdi_linux/WinTypes.h delete mode 100644 tools/sensinode/nano_usb_programmer/ftdi_linux/ftd2xx.h delete mode 100644 tools/sensinode/nano_usb_programmer/ftdi_win32/ftd2xx.h delete mode 100644 tools/sensinode/nano_usb_programmer/ihex.c delete mode 100644 tools/sensinode/nano_usb_programmer/ihex.h delete mode 100644 tools/sensinode/nano_usb_programmer/main.c delete mode 100644 tools/sensinode/nano_usb_programmer/prog.c delete mode 100644 tools/sensinode/nano_usb_programmer/prog.h diff --git a/cpu/cc2430/8051def.h b/cpu/cc2430/8051def.h deleted file mode 100644 index f0acda7b9..000000000 --- a/cpu/cc2430/8051def.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * \file - * This file contains a set of configuration for using SDCC as a compiler. - * Modified from z80 port for cc2430 port. - * - * \author - * Takahide Matsutsuka (Original) - * George Oikonomou - - * (recent updates for the sensinode/cc2430 port) - */ - -#ifndef E051_DEF_H_ -#define E051_DEF_H_ - -#include - -/* This port no longer implements the legacy clock_delay. Hack its usages - * outta the way till it gets phased out completely - * NB: This also overwrites the prototype so delay_usec() is declared twice */ -#define clock_delay(t) clock_delay_usec(t) - -/* - * lint - style defines to help syntax parsers with sdcc-specific 8051 code - * They don't interfere with actual compilation - */ -#if !defined(__SDCC_mcs51) && !defined(SDCC_mcs51) -#define __data -#define __xdata -#define __code -#define __bit bool -#define __sfr volatile unsigned char -#define __sbit volatile bool -#define __critical -#define __at(x) -#define __using(x) -#define __interrupt(x) -#define __naked -#endif - -#define CC_CONF_FUNCTION_POINTER_ARGS 1 -#define CC_CONF_VA_ARGS 1 -#define CC_CONF_UNSIGNED_CHAR_BUGS 0 -#define CC_CONF_REGISTER_ARGS 0 -#define CC_CONF_FUNCTION_POINTER_KEYWORD __reentrant -#define CC_CONF_NON_BANKED_OPTIMIZATION 1 - -#if (defined(__SDCC_mcs51) || defined(SDCC_mcs51)) && CC_CONF_NON_BANKED_OPTIMIZATION -#define CC_NON_BANKED __nonbanked -#else -#define CC_NON_BANKED -#endif - -/* - * Max Stack Depth manipulation. It is possible to get up to 247 bytes - * allocated for the stack if: - * - You set this to 1 and - * - You have a patched toolchain and - * - You don't use __bit variables - * - You do not link libraries using BIT registers (e.g. printf_large) - * Enabling this will mean ISRs will NOT push bits (#pragma exclude bits) so - * make sure you know what you're doing - * - * More information on the wiki - */ -#define CC_CONF_OPTIMIZE_STACK_SIZE 0 - -#if CC_CONF_OPTIMIZE_STACK_SIZE -#define CC_AT_DATA -#else -#define CC_AT_DATA __data -#endif - -/* Generic types. */ -typedef unsigned short uip_stats_t; - -/* Time type. */ -typedef unsigned short clock_time_t; -#define MAX_TICKS (~((clock_time_t)0) / 2) -/* Defines tick counts for a second. */ -#define CLOCK_CONF_SECOND 128 - -/* Compiler configurations */ -#define CCIF -#define CLIF - -/* Single asm instruction without messing up syntax highlighting */ -#if defined(__SDCC_mcs51) || defined(SDCC_mcs51) -#define ASM(x) __asm \ - x \ - __endasm -#else -#define ASM(x) -#endif - -/* Critical section management */ -#define DISABLE_INTERRUPTS() do {EA = 0;} while(0) -#define ENABLE_INTERRUPTS() do {EA = 1;} while(0) - -/* Macro for a soft reset. */ -#define SOFT_RESET() do {((void (__code *) (void)) 0x0000) ();} while(0) - -/* We don't provide architecture-specific checksum calculations */ -#define UIP_ARCH_ADD32 0 -#define UIP_ARCH_CHKSUM 0 - -#define CC_CONF_ASSIGN_AGGREGATE(dest, src) \ - memcpy(dest, src, sizeof(*dest)) - -#define uip_ipaddr_copy(dest, src) \ - memcpy(dest, src, sizeof(*dest)) - -#endif /* E051_DEF_H_ */ diff --git a/cpu/cc2430/Makefile.cc2430 b/cpu/cc2430/Makefile.cc2430 deleted file mode 100644 index 1a1c12b1e..000000000 --- a/cpu/cc2430/Makefile.cc2430 +++ /dev/null @@ -1,116 +0,0 @@ -### Compiler definitions -CC = sdcc -LD = sdcc -AS = sdcc -AR = sdar -OBJCOPY = objcopy -STRIP = strip -PACKIHX = packihx -BANK_ALLOC = $(CONTIKI)/cpu/cc2430/bank-alloc.py -SEGMENT_RULES = $(OBJECTDIR)/segment.rules - -CFLAGS += --model-$(MEMORY_MODEL) --stack-auto -DSDCC_CC2430 --std-c99 -CFLAGS += --fomit-frame-pointer - -### Disable warning 110 (EVELYN the modified dog) and 126 (unreachable code) -CFLAGS += --disable-warning 110 --disable-warning 126 - -LDFLAGS += --model-$(MEMORY_MODEL) --stack-auto -DSDCC_CC2430 --out-fmt-ihx -LDFLAGS += --xram-loc 0xE000 --xram-size 0x1F00 -LDFLAGS += --code-loc $(START_ADDR) --code-size $(CODE_SIZE) - -ASFLAGS += -plosgff - -AROPTS = -rc - -### Our object files are .rel, so we can't use the default finalize dependency -### generation. Override here. -define FINALIZE_SDCC_DEPENDENCY -cp $(@:.rel=.d) $(@:.rel=.$$$$); \ -sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \ - -e '/^$$/ d' -e 's/$$/ :/' < $(@:.rel=.$$$$) >> $(@:.rel=.d); \ -rm -f $(@:.rel=.$$$$) -endef - -### Banking Guesswork: -### Examples outside examples/sensinode do not specify banking. -### We automatically turn it on if its unspecified and if we are building with -### CONTIKI_WITH_IPV6 -ifndef HAVE_BANKING - ifeq ($(CONTIKI_WITH_IPV6),1) - HAVE_BANKING=1 - else - HAVE_BANKING=0 - endif -endif - -### Does the project want us to offset the firmware? -### define start address and max code size accordingly, turn Disco on -ifeq ($(OFFSET_FIRMWARE),1) - START_ADDR = 0x01000 - HOME_START = 00001000 - ifeq ($(HAVE_BANKING),1) - CODE_SIZE = 0x1F000 - else - CODE_SIZE = 0x0F000 - endif -else - START_ADDR = 0x00000 - HOME_START = 00000000 - ifeq ($(HAVE_BANKING),1) - CODE_SIZE = 0x20000 - else - CODE_SIZE = 0x10000 - endif -endif - -### Are we building with BANKing supoprt? -ifeq ($(HAVE_BANKING),1) - ## Yes - MEMORY_MODEL=huge - LDFLAGS += -Wl-bBANK1=0x018000 - LD_POST_FLAGS += -Wl-bBANK2=0x028000 - LD_POST_FLAGS += -Wl-bBANK3=0x038000 - LDFLAGS += -Wl-r - CFLAGS += -DHAVE_SDCC_BANKING - #use this in $(call c_seg,$<) to get segment for a source file. - c_seg = --codeseg $(shell python $(BANK_ALLOC) $1 $(SEGMENT_RULES) $2) -else - ## No banking - MEMORY_MODEL=large - c_seg = -endif - -### CPU-dependent cleanup files -CLEAN += *.lnk *.lk *.sym *.lib *.ihx *.rel *.mem *.rst *.asm *.hex -CLEAN += *.omf *.cdb *.banks -CLEAN += symbols.c symbols.h - -### CPU-dependent directories -CONTIKI_CPU_DIRS = . dev - -### CPU-dependent source files -CONTIKI_SOURCEFILES += bus.c clock.c uart0.c uart1.c cc2430_rf.c dma.c -CONTIKI_SOURCEFILES += uart_intr.c cc2430_rf_intr.c dma_intr.c -CONTIKI_SOURCEFILES += watchdog-cc2430.c rtimer-arch.c stack.c -CONTIKI_ASMFILES += - -CONTIKI_ASMOBJECTFILES = $(addprefix $(OBJECTDIR)/,$(CONTIKI_ASMFILES:.S=.rel)) - -CONTIKI_CASMOBJECTFILES = $(addprefix $(OBJECTDIR)/, \ - $(CONTIKI_CASMFILES:.cS=.rel)) - -CONTIKI_PLATFORM_DIRS = $(PLATFORM_APPDIRS) \ - $(addprefix $(CONTIKI)/platform/$(TARGET)/, $(CONTIKI_TARGET_DIRS)) - -CONTIKI_CPU_DIRS_LIST = $(addprefix $(CONTIKI_CPU)/, \ - $(CONTIKI_CPU_DIRS)) - -oname = $(patsubst %.c,%.rel,$(patsubst %.S,%.rel,$(1))) - -CONTIKI_OBJECTFILES = $(addprefix $(OBJECTDIR)/, \ - $(call oname, $(CONTIKI_SOURCEFILES))) - -PROJECT_OBJECTFILES = $(addprefix $(OBJECTDIR)/, \ - $(call oname, $(PROJECT_SOURCEFILES))) - diff --git a/cpu/cc2430/Makefile.customrules-cc2430 b/cpu/cc2430/Makefile.customrules-cc2430 deleted file mode 100644 index 68ed21c60..000000000 --- a/cpu/cc2430/Makefile.customrules-cc2430 +++ /dev/null @@ -1,63 +0,0 @@ -### Compilation rules - -SEGMENT_RULE_FILES = $(foreach dir, . $(CONTIKI_PLATFORM_DIRS) \ - $(CONTIKI_CPU_DIRS_LIST), $(wildcard $(dir)/segment.rules) ) - -# NB: Assumes SEGMENT_RULES was not overridden and is in $(OBJECTDIR) -$(SEGMENT_RULES): $(SEGMENT_RULE_FILES) | $(OBJECTDIR) - cat $(SEGMENT_RULE_FILES) | \ - sed -e 's/#.*$$//' -e 's/^\s*//' -e '/^$$/d' > $@ - -CUSTOM_RULE_LINK=1 -CUSTOM_RULE_C_TO_OBJECTDIR_O=1 -CUSTOM_RULE_ALLOBJS_TO_TARGETLIB=1 - -$(OBJECTDIR)/%.rel: %.c $(SEGMENT_RULES) | $(OBJECTDIR) - $(TRACE_CC) - $(Q)$(CC) $(call c_seg,$<,$@) $(CFLAGS) -c $< -o $@ -Wp,-MMD,$(@:.rel=.d),-MQ,$@ - @$(FINALIZE_SDCC_DEPENDENCY) - -contiki-$(TARGET).lib: $(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) \ - $(CONTIKI_ASMOBJECTFILES) $(CONTIKI_CASMOBJECTFILES) - rm -f $@ - for target in $^; do echo $$target >> $@; done - -.PRECIOUS: %.$(TARGET) %.hex - -# build app/example local object files. We need a separate rule so that we can -# pass -DAUTOSTART_ENABLE for those files only -$(OBJECTDIR)/%.app.rel: %.c $(SEGMENT_RULES) | $(OBJECTDIR) - $(TRACE_CC) - $(Q)$(CC) $(call c_seg,$<,$@) -DAUTOSTART_ENABLE $(CFLAGS) -c $< -o $@ - -# .ihx is the sdcc binary output file -%.ihx: $(OBJECTDIR)/%.app.rel $(CONTIKI_TARGET_MAIN) contiki-$(TARGET).lib -# Automatic bank relocation when building banked code -ifeq ($(HAVE_BANKING),1) - @echo "\nFirst Link" - @echo "===============" - $(TRACE_LD) - $(Q)$(LD) $(LDFLAGS) -o $@ $(CONTIKI_TARGET_MAIN) $(OBJECTDIR)/$*.app.rel -llibsdcc.lib -lcontiki-$(TARGET).lib - @echo "\nBank Allocation" - @echo "===============" - python $(BANK_ALLOC) $(basename $(@F)) $(SEGMENT_RULES) $(OFFSET_FIRMWARE) - @echo "\nFinal Link" - @echo "===============" -endif - $(TRACE_LD) - $(Q)$(LD) $(LDFLAGS) $(LD_POST_FLAGS) -o $@ $(CONTIKI_TARGET_MAIN) $(OBJECTDIR)/$*.app.rel -llibsdcc.lib -lcontiki-$(TARGET).lib - -# Pack the hex file for programmers which dislike SDCC output hex format -%.hex: %.ihx - @echo "\nPack hex file" - @echo "===============" -ifeq ($(HAVE_BANKING),1) - srec_cat -disable_sequence_warnings $< -intel -crop 0x10000 0x1FFFF -offset -0x10000 -o bank1.hex -intel - srec_cat -disable_sequence_warnings $< -intel -crop 0x20000 0x2FFFF -offset -0x18000 -o bank2.hex -intel - srec_cat -disable_sequence_warnings $< -intel -crop 0x30000 0x3FFFF -offset -0x20000 -o bank3.hex -intel - srec_cat -disable_sequence_warnings $< -intel -crop 0x00000 0x0FFFF -o home.ihx -intel - srec_cat home.ihx -intel bank1.hex -intel bank2.hex -intel bank3.hex -intel -o $@ -intel - rm -f home.ihx bank1.hex bank2.hex bank3.hex -else - $(PACKIHX) $< > $@ -endif diff --git a/cpu/cc2430/bank-alloc.py b/cpu/cc2430/bank-alloc.py deleted file mode 100644 index 10e452577..000000000 --- a/cpu/cc2430/bank-alloc.py +++ /dev/null @@ -1,228 +0,0 @@ -#!/usr/bin/env python - -# Copyright (c) 2010, Loughborough University - 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. - -# \file -# Automatic allocation of modules to code segments for bankable builds -# with SDCC's huge memory model. -# -# \author -# George Oikonomou - -import sys -import re -import operator -import fileinput -import os - -# Open a module object file (.rel) and read it's code size -def retrieve_module_size(file_name): - size_pat = re.compile('^A\s+(?:HOME|BANK[0-9])\s+size\s+([1-9A-F][0-9A-F]*)') - for code_line in open(file_name): - matches = size_pat.search(code_line) - if matches is not None: - return int(matches.group(1), 16) - return 0 - -# Searches for a code segment rule for file_name in the segment_rules file -# If there is a rule, we respect it. Otherwise, we can move the file around -def get_source_seg(source_file, object_file, segment_rules): - for line in open(segment_rules): - tokens = line.split(None) - match = re.search(tokens[1], source_file) - if match is not None: - # Save it in basename.seg - base, ext = os.path.splitext(object_file) - of = open(base + '.seg', 'w') - of.write(tokens[0] + '\n') - of.close - return tokens[0] - return None - -# If segment.rules specified a rule for a source file, the respective object -# file's banking requirement will be stored in object_file.seg -def get_object_seg(object_file): - base, ext = os.path.splitext(object_file) - seg = base + '.seg' - bank = None - if os.path.isfile(seg) is True: - of = open(base + '.seg', 'r') - bank = of.readline().strip() - of.close() - return bank - -# Open project.mem and retreive the project's total code footprint -def get_total_size(project): - mem_file = project + '.mem' - pat = re.compile('FLASH\s+(0x[0-9a-f]+\s+){2}([0-9]+)') - for line in open(mem_file): - l = pat.search(line) - if l is not None: - return int(l.group(2)) - -# Open project.map and retrieve the list of modules linked in -# This will only consider contiki sources, not SDCC libraries -# NB: Sometimes object filenames get truncated: -# contiki-sensinode.lib [ obj_sensinode/watchdog-cc2430.re ] -# See how for this file the 'l' in 'rel' is missing. For that reason, we retrieve -# the filaname until the last '.' but without the extension and we append 'rel' -# As long as the filename doesn't get truncated, we're good -def populate(project, modules, segment_rules, bins): - bankable_total = 0 - user_total = 0 - - map_file = project + '.map' - file_pat = re.compile('obj_sensinode[^ ]+\.') - for line in open(map_file): - file_name = file_pat.search(line) - if file_name is not None: - mod = file_name.group(0) + 'rel' - code_size = retrieve_module_size(mod) - seg = get_object_seg(mod) - if seg is not None: - # This module has been assigned to a bank by the user - #print 'In', seg, file_name.group(0), 'size', code_size - bins[seg][0] += code_size - user_total += code_size - else: - # We are free to allocate this module - modules.append([mod, code_size, "NONE"]) - bankable_total += code_size - return bankable_total, user_total - -# Allocate bankable modules to banks according to a simple -# 'first fit, decreasing' bin packing heuristic. -def bin_pack(modules, bins, offset, log): - if offset==1: - bins['HOME'][1] -= 4096 - - # Sort by size, descending, in=place - modules.sort(key=operator.itemgetter(1), reverse=True) - - for module in modules: - # We want to iterate in a specific order and dict.keys() won't do that - for bin_id in ['BANK1', 'BANK2', 'BANK3', 'HOME']: - if bins[bin_id][0] + module[1] < bins[bin_id][1]: - bins[bin_id][0] += module[1] - module[2] = bin_id - log.writelines(' '.join([module[2].ljust(8), \ - str(module[1]).rjust(5), module[0], '\n'])) - break - else: - if bin_id == 'HOME': - print "Failed to allocate", module[0], "with size", module[1], \ - "to a code bank. This is fatal" - return 1 - return 0 - -# Hack the new bank directly in the .rel file -def relocate(module, bank): - code_pat = re.compile('(A\s+)(?:HOME|BANK[0-9])(\s+size\s+[1-9A-F][0-9A-F]*.+\n)') - - for line in fileinput.input(module, inplace=1): - m = code_pat.search(line) - if m is not None: - line = m.group(1) + bank + m.group(2) - sys.stdout.write(line) - return - -if len(sys.argv) < 3: - print 'Usage:' - print 'bank-alloc.py project path_to_segment_rules [offset]' - print 'bank-alloc.py source_file path_to_segment_rules object_file' - sys.exit(1) - -modules = list() -file_name = sys.argv[1] -segment_rules = sys.argv[2] - -# Magic: Guess whether we want to determine the code bank for a code file -# or whether we want to bin-pack -basename, ext = os.path.splitext(file_name) -if ext == '.c': - # Code Segment determination - if len(sys.argv) < 4: - print 'Usage:' - print 'bank-alloc.py project path_to_segment_rules [offset]' - print 'bank-alloc.py source_file path_to_segment_rules object_file' - sys.exit(1) - object_file = sys.argv[3] - seg = get_source_seg(file_name, object_file, segment_rules) - if seg is None: - print "BANK1" - else: - print seg - exit() - -# Bin-Packing -offset = 0 -if len(sys.argv) > 3 and sys.argv[3] is not None: - offset = int(sys.argv[3]) - -sizes = {'total': 0, 'bankable': 0, 'user': 0, 'libs': 0} - -# Name : [Allocated, capacity] -bins = { - 'HOME': [0, 32768], - 'BANK1': [0, 32768], - 'BANK2': [0, 32768], - 'BANK3': [0, 30720] -} - -sizes['total'] = get_total_size(basename) -sizes['bankable'], sizes['user'] = populate(basename, modules, segment_rules, bins) -sizes['libs'] = sizes['total'] - sizes['bankable'] - sizes['user'] - -print 'Total Size =', sizes['total'], 'bytes (' + \ - str(sizes['bankable']), 'bankable,', \ - str(sizes['user']), 'user-allocated,', \ - str(sizes['libs']), 'const+libs)' - -bins['HOME'][0] += sizes['libs'] - -print 'Preallocations: HOME=' + str(bins['HOME'][0]) + \ - ', BANK1=' + str(bins['BANK1'][0]) + ', BANK2=' + str(bins['BANK2'][0]) + \ - ', BANK3=' + str(bins['BANK3'][0]) - -# Open a log file -of = open(basename + '.banks', 'w') -pack = bin_pack(modules, bins, offset, of) -of.close() - -print "Bin-Packing results (target allocation):" -print "Segment - max - alloc" -for bin_id in ['HOME', 'BANK1', 'BANK2', 'BANK3']: - print bin_id.rjust(7), str(bins[bin_id][1]).rjust(6), str(bins[bin_id][0]).rjust(6) - -if pack > 0: - sys.exit(1) - -# If we reach here we seem to have a sane allocation. Start changing .rel files -for module in modules: - relocate(module[0], module[2]) diff --git a/cpu/cc2430/cc2430_sfr.h b/cpu/cc2430/cc2430_sfr.h deleted file mode 100644 index 53581cd29..000000000 --- a/cpu/cc2430/cc2430_sfr.h +++ /dev/null @@ -1,709 +0,0 @@ -/** - * - * \file cc2430_sfr.h - * \brief CC2430 registers header file for CC2430. - * - * Definitions for CC2430 SFR registers. - * - * - */ - -#ifndef REG_CC2430_H -#define REG_CC2430_H - -#include "8051def.h" - -/* BYTE Register */ - -__sfr __at (0x80) P0 ; -/* P0 */ -__sbit __at (0x87) P0_7 ; -__sbit __at (0x86) P0_6 ; -__sbit __at (0x85) P0_5 ; -__sbit __at (0x84) P0_4 ; -__sbit __at (0x83) P0_3 ; -__sbit __at (0x82) P0_2 ; -__sbit __at (0x81) P0_1 ; -__sbit __at (0x80) P0_0 ; - -__sfr __at (0x81) SP ; -__sfr __at (0x82) DPL0 ; -__sfr __at (0x83) DPH0 ; -/*DPL and DPH correspond DPL0 and DPH0 (82-83)*/ -__sfr __at (0x84) DPL1; -__sfr __at (0x85) DPH1; -__sfr __at (0x86) U0CSR; -#define U_MODE 0x80 -#define U_RE 0x40 -#define U_SLAVE 0x20 -#define U_FE 0x10 -#define U_ERR 0x08 -#define U_RXB 0x04 -#define U_TXB 0x02 -#define U_ACTIVE 0x01 - -__sfr __at (0x87) PCON ; -/* PCON (0x87) */ -#define IDLE 0x01 - -__sfr __at (0x88) TCON ; -/* TCON (0x88) */ -__sbit __at (0x8F) TCON_URX1IF; -/*__sbit __at (0x8E) RES;*/ -__sbit __at (0x8D) TCON_ADCIF; -/*__sbit __at (0x8C) RES;*/ -__sbit __at (0x8B) TCON_URX0IF; -__sbit __at (0x8A) TCON_IT1; -__sbit __at (0x89) TCON_RFERRIF; -__sbit __at (0x88) TCON_IT0; - - -__sfr __at (0x89) P0IFG; -__sfr __at (0x8A) P1IFG; -__sfr __at (0x8B) P2IFG; -__sfr __at (0x8C) PICTL; -/*PICTL bits*/ -#define PADSC 0x40 -#define P2IEN 0x20 -#define P0IENH 0x10 -#define P0IENL 0x08 -#define P2ICON 0x04 -#define P1ICON 0x02 -#define P0ICON 0x01 - -__sfr __at (0x8D) P1IEN; -__sfr __at (0x8F) P0INP; - -__sfr __at (0x90) P1 ; -/* P1 */ -__sbit __at (0x90) P1_0 ; -__sbit __at (0x91) P1_1 ; -__sbit __at (0x92) P1_2 ; -__sbit __at (0x93) P1_3 ; -__sbit __at (0x94) P1_4 ; -__sbit __at (0x95) P1_5 ; -__sbit __at (0x96) P1_6 ; -__sbit __at (0x97) P1_7 ; - -__sfr __at (0x91) RFIM; -__sfr __at (0x92) DPS; -__sfr __at (0x93) _XPAGE; /*MPAGE as paging register for sdcc*/ -__sfr __at (0x94) T2CMP; -__sfr __at (0x95) ST0; -__sfr __at (0x96) ST1; -__sfr __at (0x97) ST2; -__sfr __at (0x98) S0CON ; - -__sbit __at (0x99) S0CON_ENCIF_1; -__sbit __at (0x98) S0CON_ENCIF_0; - -__sfr __at (0x99) HSRC; -__sfr __at (0x9A) IEN2; -/*IEN2 bits*/ -#define WDTIE 0x20 -#define P1IE 0x10 -#define UTX1IE 0x08 -#define UTX0IE 0x04 -#define P2IE 0x02 -#define RFIE 0x01 -__sfr __at (0x9B) S1CON; -/*S1CON bits*/ -#define RFIF_1 0x02 -#define RFIF_0 0x01 -__sfr __at (0x9C) T2PEROF0; -__sfr __at (0x9D) T2PEROF1; -__sfr __at (0x9E) T2PEROF2; -/*T2PEROF2 bits*/ -#define CMPIM 0x80 -#define PERIM 0x40 -#define OFCMPIM 0x20 - -#define PEROF23 0x08 -#define PEROF22 0x04 -#define PEROF21 0x02 -#define PEROF20 0x01 - -__sfr __at (0x9F) FMAP; -__sfr __at (0x9F) PSBANK; - -__sfr __at (0xA0) P2 ; -/* P2 */ -__sbit __at (0xA0) P2_0 ; -__sbit __at (0xA1) P2_1 ; -__sbit __at (0xA2) P2_2 ; -__sbit __at (0xA3) P2_3 ; -__sbit __at (0xA4) P2_4 ; -/*__sbit __at (0xA5) P2_5 ; -__sbit __at (0xA6) P2_6 ; -__sbit __at (0xA7) P2_7 ;*/ - -__sfr __at (0xA1) T2OF0; -__sfr __at (0xA2) T2OF1; -__sfr __at (0xA3) T2OF2; -__sfr __at (0xA4) T2CAPLPL; -__sfr __at (0xA5) T2CAPHPH; -__sfr __at (0xA6) T2TLD; -__sfr __at (0xA7) T2THD; - -__sfr __at (0xA8) IE ; -__sfr __at (0xA8) IEN0; -/*IEN0 bits*/ -#define IEN0_EA_MASK 0x80 -#define STIE 0x20 -#define ENCIE 0x10 -#define URX1IE 0x08 -#define URX0IE 0x04 -#define ADCIE 0x02 -#define RFERRIE 0x01 -/* IEN0 (0xA8) */ -__sbit __at (0xAF) EA; -__sbit __at (0xAF) IEN0_EA; -/*__sbit __at (0xAE) RES;*/ -__sbit __at (0xAD) IEN0_STIE; -__sbit __at (0xAC) IEN0_ENCIE; -__sbit __at (0xAB) IEN0_URX1IE; -__sbit __at (0xAA) IEN0_URX0IE; -__sbit __at (0xA9) IEN0_ADCIE; -__sbit __at (0xA8) IEN0_RFERRIE; - -__sfr __at (0xA9) IP0; -/*IP0 bits*/ -#define IP0_5 0x20 -#define IP0_4 0x10 -#define IP0_3 0x08 -#define IP0_2 0x04 -#define IP0_1 0x02 -#define IP0_0 0x01 -__sfr __at (0xAB) FWT; -__sfr __at (0xAC) FADDRL; -__sfr __at (0xAD) FADDRH; - -__sfr __at (0xAE) FCTL; -#define F_BUSY 0x80 -#define F_SWBSY 0x40 -#define F_CONTRD 0x10 -#define F_WRITE 0x02 -#define F_ERASE 0x01 -__sfr __at (0xAF) FWDATA; - -/*No port 3 (0xB0)*/ -__sfr __at (0xB1) ENCDI; -__sfr __at (0xB2) ENCDO; -__sfr __at (0xB3) ENCCS; -#define CCS_MODE2 0x40 -#define CCS_MODE1 0x20 -#define CCS_MODE0 0x10 -#define CCS_RDY 0x08 -#define CCS_CMD1 0x04 -#define CCS_CMD0 0x02 -#define CCS_ST 0x01 -__sfr __at (0xB4) ADCCON1; -/*ADCCON1 bits*/ -#define ADEOC 0x80 -#define ADST 0x40 -#define ADSTS1 0x20 -#define ADSTS0 0x10 -#define ADRCTRL1 0x08 -#define ADRCTRL0 0x04 -__sfr __at (0xB5) ADCCON2; -/*ADCCON2 bits*/ -#define ADSREF1 0x80 -#define ADSREF0 0x40 -#define ADSDIV1 0x20 -#define ADSDIV0 0x10 -#define ADSCH3 0x08 -#define ADSCH2 0x04 -#define ADSCH1 0x02 -#define ADSCH0 0x01 -__sfr __at (0xB6) ADCCON3; -/*ADCCON3 bits*/ -#define ADEREF1 0x80 -#define ADEREF0 0x40 -#define ADEDIV1 0x20 -#define ADEDIV0 0x10 -#define ADECH3 0x08 -#define ADECH2 0x04 -#define ADECH1 0x02 -#define ADECH0 0x01 - -__sfr __at (0xB7) RCCTL; -#undef IP /*this is 0xb8 in base core*/ - -__sfr __at (0xB8) IEN1; -/*IEN1 bits*/ -#define P0IE 0x20 -#define T4IE 0x10 -#define T3IE 0x08 -#define T2IE 0x04 -#define T1IE 0x02 -#define DMAIE 0x01 -/* IEN1 (0xB8) */ -/*__sbit __at (0xBF) IEN1_RES;*/ -/*__sbit __at (0xBE) RES;*/ -__sbit __at (0xBD) IEN1_P0IE; -__sbit __at (0xBC) IEN1_T4IE; -__sbit __at (0xBB) IEN1_T3IE; -__sbit __at (0xBA) IEN1_T2IE; -__sbit __at (0xB9) IEN1_T1IE; -__sbit __at (0xB8) IEN1_DMAIE; - -__sfr __at (0xB9) IP1; -/*IP1 bits*/ -#define IP1_5 0x20 -#define IP1_4 0x10 -#define IP1_3 0x08 -#define IP1_2 0x04 -#define IP1_1 0x02 -#define IP1_0 0x01 - -__sfr __at (0xBA) ADCL; -__sfr __at (0xBB) ADCH; -__sfr __at (0xBC) RNDL; -__sfr __at (0xBD) RNDH; - -__sfr __at (0xBE) SLEEP; -#define OSC32K_CALDIS 0x80 -#define XOSC_STB 0x40 -#define HFRC_STB 0x20 -#define RST1 0x10 -#define RST0 0x08 -#define OSC_PD 0x04 -#define SLEEP_MODE1 0x02 -#define SLEEP_MODE0 0x01 - -__sfr __at (0xC0) IRCON; -/*IRCON bits*/ -#define STIF 0x80 -#define P0IF 0x20 -#define T4IF 0x10 -#define T3IF 0x08 -#define T2IF 0x04 -#define T1IF 0x02 -#define DMAIF 0x01 -/* IRCON */ -__sbit __at (0xC7) IRCON_STIF ; -/*__sbit __at (0x86) IRCON_6 ;*/ -__sbit __at (0xC5) IRCON_P0IF; -__sbit __at (0xC4) IRCON_T4IF; -__sbit __at (0xC3) IRCON_T3IF; -__sbit __at (0xC2) IRCON_T2IF; -__sbit __at (0xC1) IRCON_T1IF; -__sbit __at (0xC0) IRCON_DMAIF; - -__sfr __at (0xC1) U0BUF; - -__sfr __at (0xC2) U0BAUD; -__sfr __at (0xC3) T2CNF; -/*T2SEL bits*/ -#define CMPIF 0x80 -#define PERIF 0x40 -#define OFCMPIF 0x20 - -#define CMSEL 0x08 - -#define SYNC 0x02 -#define RUN 0x01 - -__sfr __at (0xC4) U0UCR; -#define U_FLUSH 0x80 -#define U_FLOW 0x40 -#define U_D9 0x20 -#define U_BIT9 0x10 -#define U_PARITY 0x08 -#define U_SPB 0x04 -#define U_STOP 0x02 -#define U_START 0x01 - -__sfr __at (0xC5) U0GCR; -#define U_CPOL 0x80 -#define U_CPHA 0x40 -#define U_ORDER 0x20 -#define U_BAUD_E4 0x10 -#define U_BAUD_E3 0x08 -#define U_BAUD_E2 0x04 -#define U_BAUD_E1 0x02 -#define U_BAUD_E0 0x01 - -__sfr __at (0xC6) CLKCON; -#define OSC32K 0x80 -#define OSC 0x40 -#define TICKSPD2 0x20 -#define TICKSPD1 0x10 -#define TICKSPD0 0x08 -#define CLKSPD 0x01 - -__sfr __at (0xC7) MEMCTR; -#define MUNIF 0x40 -__sfr __at (0xC8) T2CON; - -__sfr __at (0xC9) WDCTL; -#define WDT_CLR3 0x80 -#define WDT_CLR2 0x40 -#define WDT_CLR1 0x20 -#define WDT_CLR0 0x10 -#define WDT_EN 0x08 -#define WDT_MODE 0x04 -#define WDT_INT1 0x02 -#define WDT_INT0 0x01 - -__sfr __at (0xCA) T3CNT; - -__sfr __at (0xCB) T3CTL; -/*T3CTL bits*/ -#define T3DIV2 0x80 -#define T3DIV1 0x40 -#define T3DIV0 0x20 -#define T3START 0x10 -#define T3OVFIM 0x08 -#define T3CLR 0x04 -#define T3MODE1 0x02 -#define T3MODE0 0x01 - -__sfr __at (0xCC) T3CCTL0; -/*T3CCTL0 bits*/ -#define T3IM 0x40 -#define T3CMP2 0x20 -#define T3CMP1 0x10 -#define T3CMP0 0x08 -#define T3MODE 0x04 -#define T3CAP1 0x02 -#define T3CAP0 0x01 - -__sfr __at (0xCD) T3CC0; -__sfr __at (0xCE) T3CCTL1; -/*T3CCTL0 bits apply*/ -__sfr __at (0xCF) T3CC1; - -__sfr __at (0xD0) PSW ; -/* PSW */ -__sbit __at (0xD0) P ; -__sbit __at (0xD1) F1 ; -__sbit __at (0xD2) OV ; -__sbit __at (0xD3) RS0 ; -__sbit __at (0xD4) RS1 ; -__sbit __at (0xD5) F0 ; -__sbit __at (0xD6) AC ; -__sbit __at (0xD7) CY ; - -__sfr __at (0xD1) DMAIRQ; -/*DMAIRQ bits*/ -#define DMAIF4 0x10 -#define DMAIF3 0x08 -#define DMAIF2 0x04 -#define DMAIF1 0x02 -#define DMAIF0 0x01 - -__sfr __at (0xD2) DMA1CFGL; -__sfr __at (0xD3) DMA1CFGH; -__sfr __at (0xD4) DMA0CFGL; -__sfr __at (0xD5) DMA0CFGH; - -__sfr __at (0xD6) DMAARM; -/*DMAARM bits*/ -#define ABORT 0x80 -#define DMAARM4 0x10 -#define DMAARM3 0x08 -#define DMAARM2 0x04 -#define DMAARM1 0x02 -#define DMAARM0 0x01 - -__sfr __at (0xD7) DMAREQ; -/*DMAREQ bits*/ -#define DMAREQ4 0x10 -#define DMAREQ3 0x08 -#define DMAREQ2 0x04 -#define DMAREQ1 0x02 -#define DMAREQ0 0x01 - -__sfr __at (0xD8) TIMIF; -/*TIMIF bits*/ -#define OVFIM 0x40 -#define T4CH1IF 0x20 -#define T4CH0IF 0x10 -#define T4OVFIF 0x08 -#define T3CH1IF 0x04 -#define T3CH0IF 0x02 -#define T3OVFIF 0x01 - -__sfr __at (0xD9) RFD; -__sfr __at (0xDA) T1CC0L; -__sfr __at (0xDB) T1CC0H; -__sfr __at (0xDC) T1CC1L; -__sfr __at (0xDD) T1CC1H; -__sfr __at (0xDE) T1CC2L; -__sfr __at (0xDF) T1CC2H; - -__sfr __at (0xE0) ACC; -__sfr __at (0xE1) RFST; -__sfr __at (0xE2) T1CNTL; -__sfr __at (0xE3) T1CNTH; - -__sfr __at (0xE4) T1CTL; -/*T1CTL bits*/ -#define CH2IF 0x80 -#define CH1IF 0x40 -#define CH0IF 0x20 -#define OVFIF 0x10 -#define T1DIV1 0x08 -#define T1DIV0 0x04 -#define T1MODE1 0x02 -#define T1MODE0 0x01 - -__sfr __at (0xE5) T1CCTL0; -/*T1CCTL0 bits*/ -#define T1CPSEL 0x80 -#define T1IM 0x40 -#define T1CMP2 0x20 -#define T1CMP1 0x10 -#define T1CMP0 0x08 -#define T1MODE 0x04 -#define T1CAP1 0x02 -#define T1CAP0 0x01 - -__sfr __at (0xE6) T1CCTL1; -/*Bits defined in T1CCTL0 */ -__sfr __at (0xE7) T1CCTL2; -/*Bits defined in T1CCTL0 */ -__sfr __at (0xE8) IRCON2; -/*IRCON2 bits*/ -#define WDTIF 0x10 -#define P1IF 0x08 -#define UTX1IF 0x04 -#define UTX0IF 0x02 -#define P2IF 0x01 -/* IRCON 2 */ -/*__sbit __at (0xEF) IRCON2_P1_7 ; -__sbit __at (0xEE) IRCON2_P1_6 ; -__sbit __at (0xED) IRCON2_P1_5 ;*/ -__sbit __at (0xEC) IRCON2_WDTIF ; -__sbit __at (0xEB) IRCON2_P1IF ; -__sbit __at (0xEA) IRCON2_UTX1IF ; -__sbit __at (0xE9) IRCON2_UTX0IF ; -__sbit __at (0xE8) IRCON2_P2IF; - - -__sfr __at (0xE9) RFIF; -/*RFIF bits*/ -#define IRQ_RREG_ON 0x80 -#define IRQ_TXDONE 0x40 -#define IRQ_FIFOP 0x20 -#define IRQ_SFD 0x10 -#define IRQ_CCA 0x08 -#define IRQ_CSP_WT 0x04 -#define IRQ_CSP_STOP 0x02 -#define IRQ_CSP_INT 0x01 - -__sfr __at (0xEA) T4CNT; -__sfr __at (0xEB) T4CTL; -/*T4CTL bits*/ -#define T4DIV2 0x80 -#define T4DIV1 0x40 -#define T4DIV0 0x20 -#define T4START 0x10 -#define T4OVFIM 0x08 -#define T4CLR 0x04 -#define T4MODE1 0x02 -#define T4MODE0 0x01 - -__sfr __at (0xEC) T4CCTL0; -/*T4CCTL0 bits*/ -#define T4IM 0x40 -#define T4CMP2 0x20 -#define T4CMP1 0x10 -#define T4CMP0 0x08 -#define T4MODE 0x04 -#define T4CAP1 0x02 -#define T4CAP0 0x01 - -__sfr __at (0xED) T4CC0; -__sfr __at (0xEE) T4CCTL1; -/*T4CCTL0 bits apply*/ -__sfr __at (0xEF) T4CC1; - -__sfr __at (0xF0) B ; -__sfr __at (0xF1) PERCFG; -/*PERCFG bits*/ -#define T1CFG 0x40 -#define T3CFG 0x20 -#define T4CFG 0x10 -#define U1CFG 0x02 -#define U0CFG 0x01 - -__sfr __at (0xF2) ADCCFG; -/*ADCCFG bits*/ -#define ADC7EN 0x80 -#define ADC6EN 0x40 -#define ADC5EN 0x20 -#define ADC4EN 0x10 -#define ADC3EN 0x08 -#define ADC2EN 0x04 -#define ADC1EN 0x02 -#define ADC0EN 0x01 - -__sfr __at (0xF3) P0SEL; -__sfr __at (0xF4) P1SEL; -__sfr __at (0xF5) P2SEL; -/*P2SEL bits*/ -#define PRI3P1 0x40 -#define PRI2P1 0x20 -#define PRI1P1 0x10 -#define PRI0P1 0x08 -#define SELP2_4 0x04 -#define SELP2_3 0x02 -#define SELP2_0 0x01 - -__sfr __at (0xF6) P1INP; - -__sfr __at (0xF7) P2INP; -/*P2INP bits*/ -#define PDUP2 0x80 -#define PDUP1 0x40 -#define PDUP0 0x20 -#define MDP2_4 0x10 -#define MDP2_3 0x08 -#define MDP2_2 0x04 -#define MDP2_1 0x02 -#define MDP2_0 0x01 - -__sfr __at (0xF8) U1CSR; -__sfr __at (0xF9) U1BUF; -__sfr __at (0xFA) U1BAUD; -__sfr __at (0xFB) U1UCR; -__sfr __at (0xFC) U1GCR; -__sfr __at (0xFD) P0DIR; -__sfr __at (0xFE) P1DIR; - -__sfr __at (0xFF) P2DIR; -/*P2DIR bits*/ -#define PRI1P0 0x80 -#define PRI0P0 0x40 -#define DIRP2_4 0x10 -#define DIRP2_3 0x08 -#define DIRP2_2 0x04 -#define DIRP2_1 0x02 -#define DIRP2_0 0x01 - -/* IEN0 */ -/*__sbit __at (0xA8) EA ; -__sbit __at (0x99) TI ; -__sbit __at (0x9A) RB8 ; -__sbit __at (0x9B) TB8 ; -__sbit __at (0x9C) REN ; -__sbit __at (0x9D) SM2 ; -__sbit __at (0x9E) SM1 ; -__sbit __at (0x9F) SM0 ;*/ - - - -/* Interrupt numbers: address = (number * 8) + 3 */ -/*#undef IE0_VECTOR -#undef TF0_VECTOR -#undef IE1_VECTOR -#undef TF1_VECTOR -#undef SI0_VECTOR*/ - -/* CC2430 interrupt vectors */ -#define RFERR_VECTOR 0 -#define ADC_VECTOR 1 -#define URX0_VECTOR 2 -#define URX1_VECTOR 3 -#define ENC_VECTOR 4 -#define ST_VECTOR 5 -#define P2INT_VECTOR 6 -#define UTX0_VECTOR 7 -#define DMA_VECTOR 8 -#define T1_VECTOR 9 -#define T2_VECTOR 10 -#define T3_VECTOR 11 -#define T4_VECTOR 12 -#define P0INT_VECTOR 13 -#define UTX1_VECTOR 14 -#define P1INT_VECTOR 15 -#define RF_VECTOR 16 -#define WDT_VECTOR 17 - -/* RF control registers*/ -__xdata __at (0xDF02) unsigned char MDMCTRL0H; -__xdata __at (0xDF03) unsigned char MDMCTRL0L; -__xdata __at (0xDF04) unsigned char MDMCTRL1H; -__xdata __at (0xDF05) unsigned char MDMCTRL1L; -__xdata __at (0xDF06) unsigned char RSSIH; -__xdata __at (0xDF07) unsigned char RSSIL; -__xdata __at (0xDF08) unsigned char SYNCWORDH; -__xdata __at (0xDF09) unsigned char SYNCWORDL; -__xdata __at (0xDF0A) unsigned char TXCTRLH; -__xdata __at (0xDF0B) unsigned char TXCTRLL; -__xdata __at (0xDF0C) unsigned char RXCTRL0H; -__xdata __at (0xDF0D) unsigned char RXCTRL0L; -__xdata __at (0xDF0E) unsigned char RXCTRL1H; -__xdata __at (0xDF0F) unsigned char RXCTRL1L; -__xdata __at (0xDF10) unsigned char FSCTRLH; -__xdata __at (0xDF11) unsigned char FSCTRLL; -__xdata __at (0xDF12) unsigned char CSPX; -__xdata __at (0xDF13) unsigned char CSPY; -__xdata __at (0xDF14) unsigned char CSPZ; -__xdata __at (0xDF15) unsigned char CSPCTRL; -__xdata __at (0xDF16) unsigned char CSPT; -__xdata __at (0xDF17) unsigned char RFPWR; -#define ADI_RADIO_PD 0x10 -#define RREG_RADIO_PD 0x08 -#define RREG_DELAY_MASK 0x07 - -__xdata __at (0xDF20) unsigned char FSMTCH; -__xdata __at (0xDF21) unsigned char FSMTCL; -__xdata __at (0xDF22) unsigned char MANANDH; -__xdata __at (0xDF23) unsigned char MANANDL; -__xdata __at (0xDF24) unsigned char MANORH; -__xdata __at (0xDF25) unsigned char MANORL; -__xdata __at (0xDF26) unsigned char AGCCTRLH; -__xdata __at (0xDF27) unsigned char AGCCTRLL; - -__xdata __at (0xDF39) unsigned char FSMSTATE; -__xdata __at (0xDF3A) unsigned char ADCTSTH; -__xdata __at (0xDF3B) unsigned char ADCTSTL; -__xdata __at (0xDF3C) unsigned char DACTSTH; -__xdata __at (0xDF3D) unsigned char DACTSTL; - -__xdata __at (0xDF43) unsigned char IEEE_ADDR0; -__xdata __at (0xDF44) unsigned char IEEE_ADDR1; -__xdata __at (0xDF45) unsigned char IEEE_ADDR2; -__xdata __at (0xDF46) unsigned char IEEE_ADDR3; -__xdata __at (0xDF47) unsigned char IEEE_ADDR4; -__xdata __at (0xDF48) unsigned char IEEE_ADDR5; -__xdata __at (0xDF49) unsigned char IEEE_ADDR6; -__xdata __at (0xDF4A) unsigned char IEEE_ADDR7; -__xdata __at (0xDF4B) unsigned char PANIDH; -__xdata __at (0xDF4C) unsigned char PANIDL; -__xdata __at (0xDF4D) unsigned char SHORTADDRH; -__xdata __at (0xDF4E) unsigned char SHORTADDRL; -__xdata __at (0xDF4F) unsigned char IOCFG0; -__xdata __at (0xDF50) unsigned char IOCFG1; -__xdata __at (0xDF51) unsigned char IOCFG2; -__xdata __at (0xDF52) unsigned char IOCFG3; -__xdata __at (0xDF53) unsigned char RXFIFOCNT; -__xdata __at (0xDF54) unsigned char FSMTC1; -#define ABORTRX_ON_SRXON 0x20 -#define RX_INTERRUPTED 0x10 -#define AUTO_TX2RX_OFF 0x08 -#define RX2RX_TIME_OFF 0x04 -#define PENDING_OR 0x02 -#define ACCEPT_ACKPKT 0x01 - -__xdata __at (0xDF60) unsigned char CHVER; -__xdata __at (0xDF61) unsigned char CHIPID; -__xdata __at (0xDF62) unsigned char RFSTATUS; -#define TX_ACTIVE 0x10 -#define FIFO 0x08 -#define FIFOP 0x04 -#define SFD 0x02 -#define CCA 0x01 - -__xdata __at (0xDFC1) unsigned char U0BUF_SHADOW; - -__xdata __at (0xDFD9) unsigned char RFD_SHADOW; - -__xdata __at (0xDFF9) unsigned char U1BUF_SHADOW; - -__xdata __at (0xDFBA) unsigned int ADC_SHADOW; - -#endif /*REG_CC2430*/ diff --git a/cpu/cc2430/dev/bus.c b/cpu/cc2430/dev/bus.c deleted file mode 100644 index 0108cde58..000000000 --- a/cpu/cc2430/dev/bus.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2009, 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. - * - */ - -/** - * \file - * Initialization functions for the 8051 bus - * \author - * Adam Dunkels - */ - -#include "cc2430_sfr.h" -#include "dev/bus.h" -#include "sys/clock.h" -#include "contiki-conf.h" - -/*---------------------------------------------------------------------------*/ -void -bus_init(void) -{ - CLKCON = (0x00 | OSC32K); /* 32k internal */ - while(CLKCON != (0x00 | OSC32K)); - - P1DIR |= 0x0E; - IEN0_EA = 1; - - /* Initialize the clock */ - clock_init(); -} -/*---------------------------------------------------------------------------*/ diff --git a/cpu/cc2430/dev/bus.h b/cpu/cc2430/dev/bus.h deleted file mode 100644 index aa15cf0bd..000000000 --- a/cpu/cc2430/dev/bus.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2009, 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. - * - */ - -/** - * \file - * A brief description of what this file is. - * \author - * Adam Dunkels - */ - - -#ifndef BUS_H_ -#define BUS_H_ - -#include "cc2430_sfr.h" -#include "8051def.h" -#include "contiki-conf.h" - -#define inline - -void bus_init(void); -void clock_ISR( void ) __interrupt (ST_VECTOR); - -#endif /* BUS_H_ */ diff --git a/cpu/cc2430/dev/cc2430_rf.c b/cpu/cc2430/dev/cc2430_rf.c deleted file mode 100644 index 7738cb34f..000000000 --- a/cpu/cc2430/dev/cc2430_rf.c +++ /dev/null @@ -1,750 +0,0 @@ -/** - * \file - * CC2430 RF driver - * \author - * Zach Shelby (Original) - * George Oikonomou - - * (port to the netstack API, hexdump output, RX FIFO overflow fixes - * code cleanup, ...) - * - * bankable code for cc2430 rf driver. this code can be placed in any bank. - * - */ - -#include - -#include "contiki.h" -#include "dev/radio.h" -#include "dev/cc2430_rf.h" -#include "cc2430_sfr.h" -#include "sys/clock.h" -#include "sys/rtimer.h" - -#include "net/packetbuf.h" -#include "net/rime/rimestats.h" -#include "net/netstack.h" - -#define CC2430_RF_TX_POWER_RECOMMENDED 0x5F -#ifdef CC2430_RF_CONF_TX_POWER -#define CC2430_RF_TX_POWER CC2430_RF_CONF_TX_POWER -#else -#define CC2430_RF_TX_POWER CC2430_RF_TX_POWER_RECOMMENDED -#endif - -#ifdef CC2430_RF_CONF_CHANNEL -#define CC2430_RF_CHANNEL CC2430_RF_CONF_CHANNEL -#else -#define CC2430_RF_CHANNEL 18 -#endif /* CC2430_RF_CONF_CHANNEL */ -#define CC2430_CHANNEL_MIN 11 -#define CC2430_CHANNEL_MAX 26 - -#ifdef CC2430_RF_CONF_AUTOACK -#define CC2430_RF_AUTOACK CC2430_RF_CONF_AUTOACK -#else -#define CC2430_RF_AUTOACK 1 -#endif - -#ifndef CC2430_CONF_CHECKSUM -#define CC2430_CONF_CHECKSUM 0 -#endif /* CC2420_CONF_CHECKSUM */ - -#if CC2430_CONF_CHECKSUM -#include "lib/crc16.h" -#define CHECKSUM_LEN 2 -#else -#define CHECKSUM_LEN 2 -#endif /* CC2430_CONF_CHECKSUM */ -#if DEBUG_LEDS -/* moved leds code to BANK1 to make space for cc2430_rf_process in HOME */ -/* can't call code in BANK1 from alternate banks unless it is marked with __banked */ -#include "dev/leds.h" -#define RF_RX_LED_ON() leds_on(LEDS_RED); -#define RF_RX_LED_OFF() leds_off(LEDS_RED); -#define RF_TX_LED_ON() leds_on(LEDS_GREEN); -#define RF_TX_LED_OFF() leds_off(LEDS_GREEN); -#else -#define RF_RX_LED_ON() -#define RF_RX_LED_OFF() -#define RF_TX_LED_ON() -#define RF_TX_LED_OFF() -#endif -#define DEBUG 0 -#if DEBUG -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) do {} while (0) -#endif - -/* rf_flags bits */ -#define RX_ACTIVE 0x80 -#define TX_ACK 0x40 -#define TX_ON_AIR 0x20 -#define WAS_OFF 0x10 -#define INITIALISED 0x01 - -#define RX_NO_DMA -/* Bits of the last byte in the RX FIFO */ -#define CRC_BIT_MASK 0x80 -#define LQI_BIT_MASK 0x7F - -/* 192 ms, radio off -> on interval */ -#define ONOFF_TIME ((RTIMER_ARCH_SECOND / 3125) + 4) - -#if CC2430_RF_CONF_HEXDUMP -#include "uart1.h" -static const uint8_t magic[] = { 0x53, 0x6E, 0x69, 0x66 }; /* Snif */ -#endif - -#ifdef HAVE_RF_ERROR -uint8_t rf_error = 0; -#endif - -/*---------------------------------------------------------------------------*/ -#if !NETSTACK_CONF_SHORTCUTS -PROCESS(cc2430_rf_process, "CC2430 RF driver"); -#endif -/*---------------------------------------------------------------------------*/ -static uint8_t CC_AT_DATA rf_flags; -static uint8_t rf_channel; - -static int on(void); /* prepare() needs our prototype */ -static int off(void); /* transmit() needs our prototype */ -static int channel_clear(void); /* transmit() needs our prototype */ -/*---------------------------------------------------------------------------*/ -/** - * Execute a single CSP command. - * - * \param command command to execute - * - */ -void -cc2430_rf_command(uint8_t command) -{ - if(command >= 0xE0) { /*immediate strobe*/ - uint8_t fifo_count; - switch (command) { /*hardware bug workaround*/ - case ISRFOFF: - case ISRXON: - case ISTXON: - fifo_count = RXFIFOCNT; - RFST = command; - clock_delay_usec(2); - if(fifo_count != RXFIFOCNT) { - RFST = ISFLUSHRX; - RFST = ISFLUSHRX; - } - break; - - default: - RFST = command; - } - } else if(command == SSTART) { - RFIF &= ~IRQ_CSP_STOP; /*clear IRQ flag*/ - RFST = SSTOP; /*make sure there is a stop in the end*/ - RFST = ISSTART; /*start execution*/ - while((RFIF & IRQ_CSP_STOP) == 0); - } else { - RFST = command; /*write command*/ - } -} -/*---------------------------------------------------------------------------*/ -static void -flush_rx() -{ - cc2430_rf_command(ISFLUSHRX); - cc2430_rf_command(ISFLUSHRX); - -#if !NETSTACK_CONF_SHORTCUTS - IEN2 |= RFIE; -#endif -#if CC2430_RFERR_INTERRUPT - IEN0 |= RFERRIE; -#endif - - RFIF &= ~IRQ_FIFOP; -} -/*---------------------------------------------------------------------------*/ -/** - * Select RF channel. - * - * \param channel channel number to select - * - * \return channel value or negative (invalid channel number) - */ - - /* channel freqdiv = (2048 + FSCTRL(9:0)) / 4 - freq = (2048 + FSCTRL(9:0)) MHz */ - -int8_t -cc2430_rf_channel_set(uint8_t channel) -{ - uint16_t freq; - - if((channel < 11) || (channel > 26)) { - return -1; - } - - cc2430_rf_command(ISSTOP); /*make sure CSP is not running*/ - cc2430_rf_command(ISRFOFF); - /* Channel values: 11-26 */ - freq = (uint16_t) channel - 11; - freq *= 5; /*channel spacing*/ - freq += 357; /*correct channel range*/ - freq |= 0x4000; /*LOCK_THR = 1*/ - FSCTRLH = (freq >> 8); - FSCTRLL = (uint8_t)freq; - - cc2430_rf_command(ISRXON); - - rf_channel = channel; - - return (int8_t) channel; -} -/*---------------------------------------------------------------------------*/ -uint8_t -cc2430_rf_channel_get() -{ - return rf_channel; -} -/*---------------------------------------------------------------------------*/ -/** - * Select RF transmit power. - * - * \param new_power new power level - * - * \return new level - */ -uint8_t -cc2430_rf_power_set(uint8_t new_power) -{ - /* Set transmitter power */ - TXCTRLL = new_power; - - return TXCTRLL; -} -/*---------------------------------------------------------------------------*/ -#if 0 /* unused */ -/** - * Enable RF transmitter. - * - * - * \return pdTRUE - * \return pdFALSE bus not free - */ -int -cc2430_rf_tx_enable(void) -{ - DMAARM = 0x80 + (1 << 0); /*ABORT + channel bit*/ - - return 1; -} -#endif -/*---------------------------------------------------------------------------*/ -/** - * Set MAC addresses - * - * \param pan The PAN address to set - * \param addr The short address to set - * \param ieee_addr The 64-bit IEEE address to set - */ -void -cc2430_rf_set_addr(unsigned pan, unsigned addr, const uint8_t *ieee_addr) -{ - uint8_t f; - __xdata unsigned char *ptr; - - PANIDH = pan >> 8; - PANIDL = pan & 0xff; - - SHORTADDRH = addr >> 8; - SHORTADDRL = addr & 0xff; - - if(ieee_addr != NULL) { - ptr = &IEEE_ADDR7; - /* LSB first, MSB last for 802.15.4 addresses in CC2420 */ - for(f = 0; f < 8; f++) { - *ptr-- = ieee_addr[f]; - } - } -} -#if 0 /* currently unused */ -/*---------------------------------------------------------------------------*/ -/** - * Channel energy detect. - * - * Coordinator use this function detect best channel for PAN-network. - * \return RSSI-energy level dBm. - * \return 0 operation failed. - */ - -int8_t -cc2430_rf_analyze_rssi(void) -{ - int8_t retval = -128; - /*pause_us(128);*/ - - retval = (int8_t)RSSIL; - retval -= 45; - return retval; -} -#endif /* currently unused */ -/*---------------------------------------------------------------------------*/ -/** - * Send ACK. - * - *\param pending set up pending flag if pending > 0. - */ -void -cc2430_rf_send_ack(uint8_t pending) -{ - if(pending) { - cc2430_rf_command(ISACKPEND); - } else { - cc2430_rf_command(ISACK); - } -} -/*---------------------------------------------------------------------------*/ -/* Netstack API radio driver functions */ -/*---------------------------------------------------------------------------*/ -static int -init(void) -{ - if(rf_flags & INITIALISED) { - return 0; - } - - PRINTF("cc2430_rf_init called\n"); - - RFPWR &= ~RREG_RADIO_PD; /*make sure it's powered*/ - while((RFPWR & ADI_RADIO_PD) == 1); - while((RFIF & IRQ_RREG_ON) == 0); /*wait for power up*/ - SLEEP &= ~OSC_PD; /*Osc on*/ - while((SLEEP & XOSC_STB) == 0); /*wait for power up*/ - - rf_flags = 0; - - FSMTC1 = 1; /*don't abort reception, if enable called, accept ack, auto rx after tx*/ - - MDMCTRL0H = 0x0A; /* Generic client, standard hysteresis, decoder on 0x0a */ - MDMCTRL0L = 0xE2; /* automatic CRC, standard CCA and preamble 0xE2 */ -#if CC2430_RF_AUTOACK - MDMCTRL0L |= 0x10; -#endif - - MDMCTRL1H = 0x30; /* Defaults */ - MDMCTRL1L = 0x0; - - RXCTRL0H = 0x32; /* RX tuning optimized */ - RXCTRL0L = 0xf5; - - cc2430_rf_channel_set(CC2430_RF_CHANNEL); - cc2430_rf_command(ISFLUSHTX); - cc2430_rf_command(ISFLUSHRX); - - /* Temporary values, main() will sort this out later on */ - cc2430_rf_set_addr(0xffff, 0x0000, NULL); - - RFIM = IRQ_FIFOP; - RFIF &= ~(IRQ_FIFOP); - - S1CON &= ~(RFIF_0 | RFIF_1); -#if !NETSTACK_CONF_SHORTCUTS - IEN2 |= RFIE; -#endif - - /* If contiki-conf.h turns on the RFERR interrupt, enable it here */ -#if CC2430_RFERR_INTERRUPT - IEN0 |= RFERRIE; -#endif - - RF_TX_LED_OFF(); - RF_RX_LED_OFF(); - - rf_flags |= INITIALISED; - -#if !NETSTACK_CONF_SHORTCUTS - process_start(&cc2430_rf_process, NULL); -#endif - - cc2430_rf_power_set(CC2430_RF_TX_POWER); - - return 1; -} -/*---------------------------------------------------------------------------*/ -static int -prepare(const void *payload, unsigned short payload_len) -{ - uint8_t i; - /* - * When we transmit in very quick bursts, make sure previous transmission - * is not still in progress before re-writing in the TX FIFO - */ - while(RFSTATUS & TX_ACTIVE); - - if(rf_flags & TX_ACK) { - return -1; - } - - if((rf_flags & RX_ACTIVE) == 0) { - on(); - } - - PRINTF("cc2430_rf: sending %u byte payload\n", payload_len); - - cc2430_rf_command(ISFLUSHTX); - PRINTF("cc2430_rf: data = "); - /* Send the phy length byte first */ - RFD = payload_len + CHECKSUM_LEN; /* Payload plus FCS */ - PRINTF("(%d)", payload_len + CHECKSUM_LEN); - for(i = 0; i < payload_len; i++) { - RFD = ((unsigned char *)(payload))[i]; - PRINTF("%02X", ((unsigned char *)(payload))[i]); - } - PRINTF("\n"); - - /* Leave space for the FCS */ - RFD = 0; - RFD = 0; - - return 0; -} -/*---------------------------------------------------------------------------*/ -static int -transmit(unsigned short transmit_len) -{ - uint8_t counter; - int ret = RADIO_TX_ERR; - - if(!(rf_flags & RX_ACTIVE)) { - on(); - rf_flags |= WAS_OFF; - } - - if(channel_clear() == CC2430_CCA_BUSY) { - RIMESTATS_ADD(contentiondrop); - return RADIO_TX_COLLISION; - } - - /* - * prepare() double checked that TX_ACTIVE is low. If SFD is high we are - * receiving. Abort transmission and bail out with RADIO_TX_COLLISION - */ - if(RFSTATUS & SFD) { - RIMESTATS_ADD(contentiondrop); - return RADIO_TX_COLLISION; - } - - /* Start the transmission */ - ENERGEST_OFF(ENERGEST_TYPE_LISTEN); - ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); - - cc2430_rf_command(ISTXON); - counter = 0; - while(!(RFSTATUS & TX_ACTIVE) && (counter++ < 3)) { - clock_delay_usec(6); - } - - if(!(RFSTATUS & TX_ACTIVE)) { - PRINTF("cc2430_rf: TX never active.\n"); - cc2430_rf_command(ISFLUSHTX); - ret = RADIO_TX_ERR; - } else { - /* Wait for the transmission to finish */ - while(RFSTATUS & TX_ACTIVE); - RF_RX_LED_OFF(); - RF_TX_LED_ON(); - ret = RADIO_TX_OK; - // rf_flags |= TX_ON_AIR; - } - ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT); - ENERGEST_ON(ENERGEST_TYPE_LISTEN); - - if(rf_flags & WAS_OFF) { - off(); - } - - RIMESTATS_ADD(lltx); - /* OK, sent. We are now ready to send more */ - return ret; -} -/*---------------------------------------------------------------------------*/ -static int -send(void *payload, unsigned short payload_len) -{ - prepare(payload, payload_len); - return transmit(payload_len); -} -/*---------------------------------------------------------------------------*/ -static int -read(void *buf, unsigned short bufsize) -{ - uint8_t i; - uint8_t len; - uint8_t crc_corr; - int8_t rssi; -#if CC2420_CONF_CHECKSUM - uint16_t checksum; -#endif /* CC2420_CONF_CHECKSUM */ - - /* Don't interrupt us while emptying the FIFO */ -#if !NETSTACK_CONF_SHORTCUTS - IEN2 &= ~RFIE; -#endif -#if CC2430_RFERR_INTERRUPT - IEN0 &= ~RFERRIE; -#endif - - /* RX interrupt polled the cc2430_rf_process, now read the RX FIFO */ - /* Check the length */ - len = RFD; - - /* Check for validity */ - if(len > CC2430_MAX_PACKET_LEN) { - /* Oops, we must be out of sync. */ - PRINTF("error: bad sync\n"); - - RIMESTATS_ADD(badsynch); - flush_rx(); - return 0; - } - - if(len <= CC2430_MIN_PACKET_LEN) { - PRINTF("error: too short\n"); - - RIMESTATS_ADD(tooshort); - flush_rx(); - return 0; - } - - if(len - CHECKSUM_LEN > bufsize) { - PRINTF("error: too long\n"); - - RIMESTATS_ADD(toolong); - flush_rx(); - return 0; - } - -#if CC2430_RF_CONF_HEXDUMP - /* If we reach here, chances are the FIFO is holding a valid frame */ - uart1_writeb(magic[0]); - uart1_writeb(magic[1]); - uart1_writeb(magic[2]); - uart1_writeb(magic[3]); - uart1_writeb(len); -#endif - - PRINTF("cc2430_rf: read = "); - PRINTF("(%d)", len); - len -= CHECKSUM_LEN; - for(i = 0; i < len; ++i) { - ((unsigned char *)(buf))[i] = RFD; -#if CC2430_RF_CONF_HEXDUMP - uart1_writeb(((unsigned char *)(buf))[i]); -#endif - PRINTF("%02X", ((unsigned char *)(buf))[i]); - } - PRINTF("\n"); - -#if CC2430_CONF_CHECKSUM - /* Deal with the checksum */ - checksum = RFD * 256; - checksum += RFD; -#endif /* CC2430_CONF_CHECKSUM */ - - /* Read the RSSI and CRC/Corr bytes */ - rssi = ((int8_t) RFD) - 45; - crc_corr = RFD; - -#if CC2430_RF_CONF_HEXDUMP - uart1_writeb(rssi); - uart1_writeb(crc_corr); -#endif - - /* MS bit CRC OK/Not OK, 7 LS Bits, Correlation value */ - if(crc_corr & CRC_BIT_MASK) { - packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi); - packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, crc_corr & LQI_BIT_MASK); - RIMESTATS_ADD(llrx); - } else { - RIMESTATS_ADD(badcrc); - flush_rx(); - return 0; - } - - /* If FIFOP==1 and FIFO==0 then we had a FIFO overflow at some point. */ - if((RFSTATUS & (FIFO | FIFOP)) == FIFOP) { - /* - * If we reach here means that there might be more intact packets in the - * FIFO despite the overflow. This can happen with bursts of small packets. - * - * Only flush if the FIFO is actually empty. If not, then next pass we will - * pick up one more packet or flush due to an error. - */ - if(!RXFIFOCNT) { - flush_rx(); - } - } - - RF_RX_LED_OFF(); - -#if !NETSTACK_CONF_SHORTCUTS - IEN2 |= RFIE; -#endif -#if CC2430_RFERR_INTERRUPT - IEN0 |= RFERRIE; -#endif - - RFIF &= ~IRQ_FIFOP; - - return (len); -} -/*---------------------------------------------------------------------------*/ -static int -channel_clear(void) -{ - if(!(RFSTATUS & CCA)) { - return CC2430_CCA_BUSY; - } - return CC2430_CCA_CLEAR; -} -/*---------------------------------------------------------------------------*/ -static int -receiving_packet(void) -{ - /* - * SFD high while transmitting and receiving. - * TX_ACTIVE high only when transmitting - * - * RFSTATUS & (TX_ACTIVE | SFD) == SFD <=> receiving - */ - return (RFSTATUS & (TX_ACTIVE | SFD) == SFD); -} -/*---------------------------------------------------------------------------*/ -static int -pending_packet(void) -{ - return (RFSTATUS & FIFOP); -} -/*---------------------------------------------------------------------------*/ -/** - * Enable RF receiver. - * - * - * \return pdTRUE - * \return pdFALSE bus not free - */ -static int -on(void) -{ - rtimer_clock_t t0; - PRINTF("cc2430_rf_rx_enable called\n"); - if(!(rf_flags & RX_ACTIVE)) { - t0 = RTIMER_NOW(); - rf_flags |= RX_ACTIVE; - IOCFG0 = 0x7f; /* Set the FIFOP threshold 127 */ - RSSIH = 0xd2; /* -84dbm = 0xd2 default, 0xe0 -70 dbm */ - - RFPWR &= ~RREG_RADIO_PD; /* make sure it's powered */ - while((RFIF & IRQ_RREG_ON) == 0); /* wait for power up */ - - /* Make sure the RREG On Interrupt Flag is 0 next time we get called */ - RFIF &= ~IRQ_RREG_ON; - - cc2430_rf_command(ISRXON); - cc2430_rf_command(ISFLUSHRX); - while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + ONOFF_TIME)); - - } - PRINTF("cc2430_rf_rx_enable done\n"); - ENERGEST_ON(ENERGEST_TYPE_LISTEN); - return 1; -} -/*---------------------------------------------------------------------------*/ -/** - * Disable RF receiver. - * - * - * \return pdTRUE - * \return pdFALSE bus not free - */ - -static int -off(void) -{ - cc2430_rf_command(ISSTOP); /* make sure CSP is not running */ - cc2430_rf_command(ISRFOFF); - - RFPWR |= RREG_RADIO_PD; /* RF powerdown */ - - /* Clear the RREG On Interrupt Flag */ - RFIF &= ~IRQ_RREG_ON; - - rf_flags &= ~RX_ACTIVE; - rf_flags &= ~WAS_OFF; - ENERGEST_OFF(ENERGEST_TYPE_LISTEN); - return 1; -} -/*---------------------------------------------------------------------------*/ -static radio_result_t -get_value(radio_param_t param, radio_value_t *value) -{ - return RADIO_RESULT_NOT_SUPPORTED; -} -/*---------------------------------------------------------------------------*/ -static radio_result_t -set_value(radio_param_t param, radio_value_t value) -{ - return RADIO_RESULT_NOT_SUPPORTED; -} -/*---------------------------------------------------------------------------*/ -static radio_result_t -get_object(radio_param_t param, void *dest, size_t size) -{ - return RADIO_RESULT_NOT_SUPPORTED; -} -/*---------------------------------------------------------------------------*/ -static radio_result_t -set_object(radio_param_t param, const void *src, size_t size) -{ - return RADIO_RESULT_NOT_SUPPORTED; -} -/*---------------------------------------------------------------------------*/ -const struct radio_driver cc2430_rf_driver = { - init, - prepare, - transmit, - send, - read, - channel_clear, - receiving_packet, - pending_packet, - on, - off, - get_value, - set_value, - get_object, - set_object -}; -/*---------------------------------------------------------------------------*/ -#if !NETSTACK_CONF_SHORTCUTS -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(cc2430_rf_process, ev, data) -{ - int len; - PROCESS_BEGIN(); - while(1) { - PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); - - packetbuf_clear(); - len = read(packetbuf_dataptr(), PACKETBUF_SIZE); - if(len > 0) { - packetbuf_set_datalen(len); - NETSTACK_RDC.input(); - } - } - - PROCESS_END(); -} -#endif -/*---------------------------------------------------------------------------*/ diff --git a/cpu/cc2430/dev/cc2430_rf.h b/cpu/cc2430/dev/cc2430_rf.h deleted file mode 100644 index 83527d4ba..000000000 --- a/cpu/cc2430/dev/cc2430_rf.h +++ /dev/null @@ -1,91 +0,0 @@ -/** - * \file - * CC2430 RF driver header file - * \author - * Zach Shelby - */ - -#ifndef CC2430_RF_H_ -#define CC2430_RF_H_ - -#include "contiki.h" -#include "dev/radio.h" -#include "cc2430_sfr.h" -#if HAVE_RF_DMA -#include "dev/dma.h" -#endif - -/* Constants */ -typedef enum rf_address_mode_t { - RF_DECODER_NONE = 0, - RF_DECODER_COORDINATOR, - RF_SOFTACK_MONITOR, - RF_MONITOR, - RF_SOFTACK_CLIENT, - RF_DECODER_ON -} rf_address_mode_t; - -/*CSP command set*/ -#define SSTOP 0xDF -/*this is not a real command but a way of having rf_command - wait until the script is done*/ -#define SSTART 0xDE - -#define SNOP 0xC0 -#define STXCALN 0xC1 -#define SRXON 0xC2 -#define STXON 0xC3 -#define STXONCCA 0xC4 -#define SRFOFF 0xC5 -#define SFLUSHRX 0xC6 -#define SFLUSHTX 0xC7 -#define SACK 0xC8 -#define SACKPEND 0xC9 - -#define ISTXCALN 0xE1 -#define ISRXON 0xE2 -#define ISTXON 0xE3 -#define ISTXONCCA 0xE4 -#define ISRFOFF 0xE5 -#define ISFLUSHRX 0xE6 -#define ISFLUSHTX 0xE7 -#define ISACK 0xE8 -#define ISACKPEND 0xE9 - -#define ISSTOP 0xFF -#define ISSTART 0xFE - -#define MAC_IFS (1200/128) - -#define CC2430_MAX_PACKET_LEN 127 -#define CC2430_MIN_PACKET_LEN 4 - -#define CC2430_CCA_CLEAR 1 -#define CC2430_CCA_BUSY 0 - -#ifdef CC2430_CONF_RFERR_INTERRUPT -#define CC2430_RFERR_INTERRUPT CC2430_CONF_RFERR_INTERRUPT -#else -#define CC2430_RFERR_INTERRUPT 0 -#endif - -extern const struct radio_driver cc2430_rf_driver; - -void cc2430_rf_command(uint8_t command); -int8_t cc2430_rf_channel_set(uint8_t channel); -uint8_t cc2430_rf_channel_get(); -uint8_t cc2430_rf_power_set(uint8_t new_power); -void cc2430_rf_set_addr(unsigned pan, unsigned addr, const uint8_t *ieee_addr); - -#if !NETSTACK_CONF_SHORTCUTS -extern void cc2430_rf_ISR(void) __interrupt(RF_VECTOR); -#endif -#if CC2430_RFERR_INTERRUPT -extern void cc2430_rf_error_ISR(void) __interrupt(RFERR_VECTOR); -#endif - -#ifdef HAVE_RF_DMA -void rf_dma_callback_isr(void); -#endif - -#endif /* CC2430_RF_H_ */ diff --git a/cpu/cc2430/dev/cc2430_rf_intr.c b/cpu/cc2430/dev/cc2430_rf_intr.c deleted file mode 100644 index 85b9879c9..000000000 --- a/cpu/cc2430/dev/cc2430_rf_intr.c +++ /dev/null @@ -1,112 +0,0 @@ -/** - * \file - * CC2430 RF driver - * \author - * Zach Shelby (Original) - * George Oikonomou - - * (recent updates for the contiki cc2430 port) - * - * Non-bankable code for cc2430 rf driver. - * Interrupt routines must be placed into the HOME bank. - * - */ - -#include - -#include "contiki.h" -#include "dev/radio.h" -#include "dev/cc2430_rf.h" -#include "cc2430_sfr.h" -#ifdef RF_LED_ENABLE -#include "dev/leds.h" -#endif -#include "sys/clock.h" - -#include "net/packetbuf.h" -#include "net/rime/rimestats.h" -#include "net/netstack.h" -#define DEBUG 0 -#if DEBUG -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) do {} while (0) -#endif - -#ifdef RF_LED_ENABLE -#define RF_RX_LED_ON() leds_on(LEDS_RED); -#define RF_RX_LED_OFF() leds_off(LEDS_RED); -#define RF_TX_LED_ON() leds_on(LEDS_GREEN); -#define RF_TX_LED_OFF() leds_off(LEDS_GREEN); -#else -#define RF_RX_LED_ON() -#define RF_RX_LED_OFF() -#define RF_TX_LED_ON() -#define RF_TX_LED_OFF() -#endif - -#ifdef HAVE_RF_ERROR -uint8_t rf_error = 0; -#endif - -PROCESS_NAME(cc2430_rf_process); - -#if !NETSTACK_CONF_SHORTCUTS -/*---------------------------------------------------------------------------*/ -/** - * RF interrupt service routine. - * - */ -#pragma save -#if CC_CONF_OPTIMIZE_STACK_SIZE -#pragma exclude bits -#endif -void -cc2430_rf_ISR(void) __interrupt(RF_VECTOR) -{ - EA = 0; - ENERGEST_ON(ENERGEST_TYPE_IRQ); - /* - * We only vector here if RFSTATUS.FIFOP goes high. - * Just double check the flag. - */ - if(RFIF & IRQ_FIFOP) { - RF_RX_LED_ON(); - /* Poll the RF process which calls cc2430_rf_read() */ - process_poll(&cc2430_rf_process); - } - S1CON &= ~(RFIF_0 | RFIF_1); - - ENERGEST_OFF(ENERGEST_TYPE_IRQ); - EA = 1; -} -#pragma restore -#endif -/*---------------------------------------------------------------------------*/ -#if CC2430_RFERR_INTERRUPT -/** - * RF error interrupt service routine. - * Turned off by default, can be turned on in contiki-conf.h - */ -#pragma save -#if CC_CONF_OPTIMIZE_STACK_SIZE -#pragma exclude bits -#endif -void -cc2430_rf_error_ISR(void) __interrupt(RFERR_VECTOR) -{ - EA = 0; - TCON_RFERRIF = 0; -#ifdef HAVE_RF_ERROR - rf_error = 254; -#endif - cc2430_rf_command(ISRFOFF); - cc2430_rf_command(ISFLUSHRX); - cc2430_rf_command(ISFLUSHRX); - cc2430_rf_command(ISRXON); - RF_RX_LED_OFF(); - RF_TX_LED_OFF(); - EA = 1; -} -#pragma restore -#endif -/*---------------------------------------------------------------------------*/ diff --git a/cpu/cc2430/dev/clock.c b/cpu/cc2430/dev/clock.c deleted file mode 100644 index 1fc781b1b..000000000 --- a/cpu/cc2430/dev/clock.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2009, 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. - */ - -/** - * \file - * Implementation of the clock functions for the cc243x - * \author - * Zach Shelby (zach@sensinode.com) - original - * George Oikonomou - - */ -#include "sys/clock.h" -#include "sys/etimer.h" -#include "cc2430_sfr.h" -#include "sys/energest.h" - -/* Sleep timer runs on the 32k RC osc. */ -/* One clock tick is 7.8 ms */ -#define TICK_VAL (32768/128) /* 256 */ -/*---------------------------------------------------------------------------*/ -#if CLOCK_CONF_STACK_FRIENDLY -volatile uint8_t sleep_flag; -#endif -/*---------------------------------------------------------------------------*/ -/* Used in sleep timer interrupt for calculating the next interrupt time */ -static unsigned long timer_value; -static volatile CC_AT_DATA clock_time_t count = 0; /* Uptime in ticks */ -static volatile CC_AT_DATA clock_time_t seconds = 0; /* Uptime in secs */ -/*---------------------------------------------------------------------------*/ -/* - * Each iteration is ~1.0xy usec, so this function delays for roughly len usec - */ -void -clock_delay_usec(uint16_t len) -{ - DISABLE_INTERRUPTS(); - while(len--) { - ASM(nop); ASM(nop); - ASM(nop); ASM(nop); - } - ENABLE_INTERRUPTS(); -} -/*---------------------------------------------------------------------------*/ -/* - * Wait for a multiple of ~8 ms (a tick) - */ -void -clock_wait(clock_time_t i) -{ - clock_time_t start; - - start = clock_time(); - while(clock_time() - start < (clock_time_t)i); -} -/*---------------------------------------------------------------------------*/ -CCIF clock_time_t -clock_time(void) -{ - return count; -} -/*---------------------------------------------------------------------------*/ -CCIF unsigned long -clock_seconds(void) -{ - return seconds; -} -/*---------------------------------------------------------------------------*/ -void -clock_init(void) -{ - CLKCON = OSC32K | TICKSPD2 | TICKSPD1; /* tickspeed 500 kHz for timers[1-4] */ - - /* Initialize tick value */ - timer_value = ST0; /* ST low bits [7:0] */ - timer_value += ((unsigned long int)ST1) << 8; /* middle bits [15:8] */ - timer_value += ((unsigned long int)ST2) << 16; /* high bits [23:16] */ - timer_value += TICK_VAL; /* Init value 256 */ - ST2 = (unsigned char)(timer_value >> 16); - ST1 = (unsigned char)(timer_value >> 8); - ST0 = (unsigned char)timer_value; - - IEN0_STIE = 1; /* IEN0.STIE acknowledge Sleep Timer Interrupt */ -} -/*---------------------------------------------------------------------------*/ -#pragma save -#if CC_CONF_OPTIMIZE_STACK_SIZE -#pragma exclude bits -#endif -void -clock_ISR(void) __interrupt(ST_VECTOR) -{ - DISABLE_INTERRUPTS(); - ENERGEST_ON(ENERGEST_TYPE_IRQ); - - /* - * If the Sleep timer throws an interrupt while we are powering down to - * PM1, we need to abort the power down. Clear SLEEP.MODE, this will signal - * main() to abort the PM1 transition - */ - SLEEP &= 0xFC; - - /* - * Read value of the ST0:ST1:ST2, add TICK_VAL and write it back. - * Next interrupt occurs after the current time + TICK_VAL - */ - timer_value = ST0; - timer_value += ((unsigned long int)ST1) << 8; - timer_value += ((unsigned long int)ST2) << 16; - timer_value += TICK_VAL; - ST2 = (unsigned char)(timer_value >> 16); - ST1 = (unsigned char)(timer_value >> 8); - ST0 = (unsigned char)timer_value; - - ++count; - - /* Make sure the CLOCK_CONF_SECOND is a power of two, to ensure - that the modulo operation below becomes a logical and and not - an expensive divide. Algorithm from Wikipedia: - http://en.wikipedia.org/wiki/Power_of_two */ -#if (CLOCK_CONF_SECOND & (CLOCK_CONF_SECOND - 1)) != 0 -#error CLOCK_CONF_SECOND must be a power of two (i.e., 1, 2, 4, 8, 16, 32, 64, ...). -#error Change CLOCK_CONF_SECOND in contiki-conf.h. -#endif - if(count % CLOCK_CONF_SECOND == 0) { - ++seconds; - } - -#if CLOCK_CONF_STACK_FRIENDLY - sleep_flag = 1; -#else - if(etimer_pending() - && (etimer_next_expiration_time() - count - 1) > MAX_TICKS) { - etimer_request_poll(); - } -#endif - - IRCON_STIF = 0; - ENERGEST_OFF(ENERGEST_TYPE_IRQ); - ENABLE_INTERRUPTS(); -} -#pragma restore -/*---------------------------------------------------------------------------*/ diff --git a/cpu/cc2430/dev/dma.c b/cpu/cc2430/dev/dma.c deleted file mode 100644 index 2c198acc3..000000000 --- a/cpu/cc2430/dev/dma.c +++ /dev/null @@ -1,69 +0,0 @@ -/** - * \file - * Driver for the cc2430 DMA controller. Can be assigned to any bank - * - * \author - * Original: Martti Huttunen - * Port: Zach Shelby - * Further Modifications: - * George Oikonomou - * - */ - -#include "contiki.h" -#include "dev/dma.h" -#include "cc2430_sfr.h" - -#if DMA_ON -struct dma_config dma_conf[DMA_CHANNEL_COUNT]; /* DMA Descriptors */ -struct process *dma_callback[DMA_CHANNEL_COUNT]; -/*---------------------------------------------------------------------------*/ -void -dma_init(void) -{ - uint16_t tmp_ptr; - - memset(dma_conf, 0, 4 * sizeof(dma_config_t)); - - for(tmp_ptr = 0; tmp_ptr < DMA_CHANNEL_COUNT; tmp_ptr++) { - dma_callback[tmp_ptr] = 0; - } - - /* The address of the descriptor for Channel 0 is configured separately */ - tmp_ptr = (uint16_t)&(dma_conf[0]); - DMA0CFGH = tmp_ptr >> 8; - DMA0CFGL = tmp_ptr; - - /* - * Descriptors for Channels 1-4 must be consecutive in RAM. - * We write the address of the 1st one to the register and the rest are - * derived by the SoC - */ -#if (DMA_CHANNEL_COUNT > 1) - tmp_ptr = (uint16_t)&(dma_conf[1]); - DMA1CFGH = tmp_ptr >> 8; - DMA1CFGL = tmp_ptr; -#endif - - IEN1_DMAIE = 1; /* Enable DMA interrupts */ -} -/*---------------------------------------------------------------------------*/ -/* - * Associate process p with DMA channel c. When a transfer on that channel - * completes, the ISR will poll this process. - */ -void -dma_associate_process(struct process *p, uint8_t c) -{ - if((!c) || (c >= DMA_CHANNEL_COUNT)) { - return; - } - - if(p) { - dma_conf[c].inc_prio |= 8; /* Enable interrupt generation */ - IEN1_DMAIE = 1; /* Make sure DMA interrupts are acknowledged */ - } - dma_callback[c] = p; -} -/*---------------------------------------------------------------------------*/ -#endif diff --git a/cpu/cc2430/dev/dma.h b/cpu/cc2430/dev/dma.h deleted file mode 100644 index 30060b40f..000000000 --- a/cpu/cc2430/dev/dma.h +++ /dev/null @@ -1,148 +0,0 @@ -/** - * \file - * Header file for the cc2430 DMA controller - * - * \author - * Original: Martti Huttunen - * Port: Zach Shelby - * Further Modifications: - * George Oikonomou - */ - -#ifndef __DMA_H -#define __DMA_H -#include "cc2430_sfr.h" - -/* DMA triggers */ -#define DMA_T_NONE 0 /* None, DMAREQ.DMAREQx bits start transfer */ -#define DMA_T_PREV 1 /* completion of previous channel */ -#define DMA_T_T1_CH0 2 /* Timer 1, compare, channel 0 */ -#define DMA_T_T1_CH1 3 /* Timer 1, compare, channel 1 */ -#define DMA_T_T1_CH2 4 /* Timer 1, compare, channel 2 */ -#define DMA_T_T2_COMP 5 /* Timer 2, compare */ -#define DMA_T_T2_OVFL 6 /* Timer 2, overflow */ -#define DMA_T_T3_CH0 7 /* Timer 3, compare, channel 0 */ -#define DMA_T_T3_CH1 8 /* Timer 3, compare, channel 1 */ -#define DMA_T_T4_CH0 9 /* Timer 4, compare, channel 0 */ -#define DMA_T_T4_CH1 10 /* Timer 4, compare, channel 1 */ -#define DMA_T_ST 11 /* Sleep Timer compare */ -#define DMA_T_IOC_0 12 /* Port 0 I/O pin input transition */ -#define DMA_T_IOC_1 13 /* Port 1 I/O pin input transition */ -#define DMA_T_URX0 14 /* USART0 RX complete */ -#define DMA_T_UTX0 15 /* USART0 TX complete */ -#define DMA_T_URX1 16 /* USART1 RX complete */ -#define DMA_T_UTX1 17 /* USART1 TX complete */ -#define DMA_T_FLASH 18 /* Flash data write complete */ -#define DMA_T_RADIO 19 /* RF packet byte received/transmit */ -#define DMA_T_ADC_CHALL 20 /* ADC end of a conversion in a sequence */ -#define DMA_T_ADC_CH11 21 /* ADC end of conversion channel 0 in sequence */ -#define DMA_T_ADC_CH21 22 /* ADC end of conversion channel 1 in sequence */ -#define DMA_T_ADC_CH32 23 /* ADC end of conversion channel 2 in sequence */ -#define DMA_T_ADC_CH42 24 /* ADC end of conversion channel 3 in sequence */ -#define DMA_T_ADC_CH53 25 /* ADC end of conversion channel 4 in sequence */ -#define DMA_T_ADC_CH63 26 /* ADC end of conversion channel 5 in sequence */ -#define DMA_T_ADC_CH74 27 /* ADC end of conversion channel 6 in sequence */ -#define DMA_T_ADC_CH84 28 /* ADC end of conversion channel 7 in sequence */ -#define DMA_T_ENC_DW 29 /* AES processor requests download input data */ -#define DMA_T_ENC_UP 30 /* AES processor requests upload output data */ - -/* variable DMA length modes (VLEN) */ -#define DMA_VLEN_LEN (0 << 5) /* Use LEN for transfer count*/ -/* - * Transfer the number of bytes/words specified by first byte/word + 1 - * (up to a maximum specified by LEN). - * Thus transfer count excludes length byte/word. - */ -#define DMA_VLEN_N1 (1 << 5) - /* - * Transfer the number of bytes/words specified by first byte/word - * (up to a maximum specified by LEN). - * Thus transfer count includes length byte/word. - */ -#define DMA_VLEN_N (2 << 5) - /* - * Transfer the number of bytes/words specified by first byte/word + 2 - * (up to a maximum specified by LEN). - */ -#define DMA_VLEN_N2 (3 << 5) - /* - * Transfer the number of bytes/words specified by first byte/word + 3 - * (up to a maximum specified by LEN). - */ -#define DMA_VLEN_N3 (4 << 5) -#define DMA_VLEN_RES1 (5 << 5) /* reserved */ -#define DMA_VLEN_RES2 (6 << 5) /* reserved */ -#define DMA_VLEN_LEN2 (7 << 5) /* Use LEN for transfer count */ - -/* Transfer Types (Byte 6 [6:5]) */ -#define DMA_SINGLE 0x00 /* Single */ -#define DMA_BLOCK 0x20 /* Block */ -#define DMA_RPT_SINGLE 0x40 /* Repeated single */ -#define DMA_RPT_BLOCK 0x60 /* Repeated block */ - -/* Source Increment Modes (Byte 7 [7:6])*/ -#define DMA_SRC_INC_NO 0x00 /* Source No increment */ -#define DMA_SRC_INC_1 0x40 /* Source Increment 1 */ -#define DMA_SRC_INC_2 0x80 /* Source Increment 2 */ -#define DMA_SRC_DEC 0xC0 /* Source Decrement 1 */ -/* Source Increment Modes (Byte 7 [5:4])*/ -#define DMA_DST_INC_NO 0x00 /* DestinationNo increment */ -#define DMA_DST_INC_1 0x10 /* Destination Increment 1 */ -#define DMA_DST_INC_2 0x20 /* Destination Increment 2 */ -#define DMA_DST_DEC 0x30 /* Destination Decrement 1 */ - -/* Descriptor Byte 7, Bits[3:0] */ -#define DMA_IRQ_MASK_ENABLE 0x08 -#define DMA_MODE_7_BIT 0x04 -#define DMA_PRIO_HIGHEST 0x03 -#define DMA_PRIO_HIGH 0x02 -#define DMA_PRIO_GUARANTEED 0x01 -#define DMA_PRIO_LOW 0x00 - -/** DMA configuration structure */ -typedef struct dma_config { - uint8_t src_h; /* source address high byte*/ - uint8_t src_l; /* source address low byte*/ - uint8_t dst_h; /* dest. address high byte*/ - uint8_t dst_l; /* dest. address low byte*/ - uint8_t len_h; /* [7:5] VLEN, [4:0] length high byte, 5 lowest bits*/ - uint8_t len_l; /* length low byte*/ - uint8_t wtt; /* 7: wordsize, [6:5] transfer mode, [4:0] trigger */ - /* [7:6] src inc, [5:4] dst_inc, 3: IRQ, 2: M8(vlen), [1-0] prio */ - uint8_t inc_prio; -} dma_config_t; - -#ifdef DMA_CONF_ON -#define DMA_ON DMA_CONF_ON -#else -#define DMA_ON 0 -#endif - -/* Number of DMA Channels and their Descriptors */ -#if DMA_ON -#define DMA_CHANNEL_COUNT 2 -extern dma_config_t dma_conf[DMA_CHANNEL_COUNT]; -#endif - -/* DMA-Related Macros */ -#define DMA_ARM(c) (DMAARM |= (1 << c)) /* Arm DMA Channel C */ -#define DMA_TRIGGER(c) (DMAREQ |= (1 << c)) /* Trigger DMA Channel C */ -/* - * Check Channel C for Transfer Status - * 1: Complete, Pending Interrupt, 0: Incomplete - */ -#define DMA_STATUS(c) (DMAIRQ &(1 << c)) -/* Abort Ongoing DMA Transfers on Channel C */ -#define DMA_ABORT(c) (DMAARM = ABORT | (1 << c)) -#define DMA_ABORT_ALL() (DMAARM = 0x9F) /* Abort ALL Ongoing DMA Transfers */ - -/* Functions Declarations */ -void dma_init(void); -void dma_associate_process(struct process *p, uint8_t c); - -/* Only link the ISR when DMA_ON is .... on */ -#if DMA_ON -void dma_ISR(void) __interrupt(DMA_VECTOR); -#endif - -#endif /*__DMA_H*/ diff --git a/cpu/cc2430/dev/dma_intr.c b/cpu/cc2430/dev/dma_intr.c deleted file mode 100644 index 01e96c8ac..000000000 --- a/cpu/cc2430/dev/dma_intr.c +++ /dev/null @@ -1,73 +0,0 @@ -/** - * \file - * DMA driver ISRs - * \author - * Original: Martti Huttunen - * Port: Zach Shelby - * - * DMA interrupt routines, must be stored in HOME bank - */ - -#include - -#include "contiki.h" - -#include "dev/dma.h" -#include "cc2430_sfr.h" - -#if DMA_ON -extern struct process *dma_callback[DMA_CHANNEL_COUNT]; -#endif - -/*---------------------------------------------------------------------------*/ -#ifdef HAVE_RF_DMA -extern void rf_dma_callback_isr(void); -#endif -#ifdef SPI_DMA_RX -extern void spi_rx_dma_callback(void); -#endif -/*---------------------------------------------------------------------------*/ -/** - * DMA interrupt service routine. - * - * if callback defined a poll is made to that process - */ -#pragma save -#if CC_CONF_OPTIMIZE_STACK_SIZE -#pragma exclude bits -#endif -void -dma_ISR(void) __interrupt(DMA_VECTOR) -{ -#if DMA_ON - uint8_t i; -#endif - EA = 0; - IRCON_DMAIF = 0; -#ifdef HAVE_RF_DMA - if((DMAIRQ & 1) != 0) { - DMAIRQ &= ~1; - DMAARM = 0x81; - rf_dma_callback_isr(); - } -#endif -#ifdef SPI_DMA_RX - if((DMAIRQ & 0x08) != 0) { - DMAIRQ &= ~(1 << 3); - spi_rx_dma_callback(); - } -#endif -#if DMA_ON - for(i = 0; i < DMA_CHANNEL_COUNT; i++) { - if((DMAIRQ & (1 << i)) != 0) { - DMAIRQ &= ~(1 << i); - if(dma_callback[i] != 0) { - process_poll(dma_callback[i]); - } - } - } -#endif - EA = 1; -} -#pragma restore -/*---------------------------------------------------------------------------*/ diff --git a/cpu/cc2430/dev/hwconf.h b/cpu/cc2430/dev/hwconf.h deleted file mode 100644 index 6d1fad135..000000000 --- a/cpu/cc2430/dev/hwconf.h +++ /dev/null @@ -1,148 +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. - * - */ -#ifndef HWCONF_H_ -#define HWCONF_H_ - -#include "sys/cc.h" - -#include - -#define HWCONF_PIN(name, port, bit) \ -static CC_INLINE void name##_SELECT() {P##port##SEL &= ~(1 << bit);} \ -static CC_INLINE void name##_SELECT_IO() {P##port##SEL &= ~(1 << bit);} \ -static CC_INLINE void name##_SELECT_PM() {P##port##SEL |= 1 << bit;} \ -static CC_INLINE void name##_SET() {P##port##_##bit = 1; } \ -static CC_INLINE void name##_CLEAR() {P##port##_##bit = 0; } \ -static CC_INLINE unsigned char name##_READ() {return P##port##_##bit; } \ -static CC_INLINE void name##_MAKE_OUTPUT() {P##port##DIR |= 1 << bit;} \ -static CC_INLINE void name##_MAKE_INPUT() {P##port##DIR &= ~(1 << bit); } - -#define HWCONF_IRQ_XXX(name, port, bit) \ -static CC_INLINE void name##_ENABLE_IRQ() { \ - if ( port == 2 ) { PICTL |= P2IEN; p2ien |= 1<=4)) { PICTL |= P0IENH; p0ien |= 1<=4)) { \ - p0ien &= ~(1<=4 ) { PICTL |= P0IENH; p0ien |= 1<=4) { \ - p0ien &= ~(1< - */ -#ifndef LPM_H_ -#define LPM_H_ - -#include "contiki-conf.h" - -#define LPM_MODE_NONE 0 /* No LPM - Always on */ -#define LPM_MODE_IDLE 1 /* Set MCU Idle as part of the main loop */ -#define LPM_MODE_PM2 2 /* Drop to PM1 - causes radio packet losses for now */ - -#ifdef LPM_CONF_MODE -#define LPM_MODE LPM_CONF_MODE -#else -#define LPM_MODE LPM_MODE_IDLE -#endif /* LPM_CONF_MODE */ - -#endif /* LPM_H_ */ diff --git a/cpu/cc2430/dev/random.c b/cpu/cc2430/dev/random.c deleted file mode 100644 index 639f384e5..000000000 --- a/cpu/cc2430/dev/random.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Random number generator routines exploiting the cc2430 hardware - * capabilities. - * - * This file overrides core/lib/random.c. - * - * \author - * George Oikonomou - - */ -#include "cc2430_sfr.h" -#include "dev/cc2430_rf.h" -/*---------------------------------------------------------------------------*/ -/** - * \brief Generates a new random number using the cc2430 RNG. - * \return The random number. - */ -unsigned short -random_rand(void) -{ - /* Clock the RNG LSFR once */ - ADCCON1 |= ADRCTRL0; - - return (RNDL | (RNDH << 8)); -} -/*---------------------------------------------------------------------------*/ -/** - * \brief Seed the cc2430 random number generator. - * \param seed Seed value for the RNG. - * - * If the SEED argument is 0, seed the RNG with IF_ADC as - * discussed in the cc2430 datasheet (rev. 2.1), section 13.11.2.2, - * page 134. Seeding with this method should not be done during - * normal radio operation. Thus, use this function before - * initialising the network. - * - * If the SEED is provided, seed with this value instead. This will - * result in the same sequence of random numbers each time the node - * reboots. So, don't use it unless you have a reason (e.g. tests) - */ -void -random_init(unsigned short seed) -{ - int i; - - /* Comment out this if() block to save a nice 16 bytes of code size */ - if(seed) { - /* If the caller provides a seed, write the high-byte first and then - * write the low byte */ - RNDL = seed >> 8; /* High byte first */ - RNDL = seed & 0xFF; - return; - } - - /* - * cc2430 Datasheet: - * "When a true random value is required, the LFSR should be seeded by - * writing RNDL with random values from the IF_ADC in the RF receive path." - * - * "To use this seeding method, the radio must first be powered on by - * enabling the voltage regulator" - */ - RFPWR &= ~RREG_RADIO_PD; /* Turn on the voltage regulator */ - while(!(RFIF & IRQ_RREG_ON)); /* Wait for power up*/ - - /* OK, it's powered. The respective interrupt flag has been set, clear it */ - RFIF &= ~IRQ_RREG_ON; - - /* - * "The radio should be placed in infinite TX state, to avoid possible sync - * detect in RX state." - * - * Judging by old chipcon cc2430 code examples as well as by the way cc2530 - * works, this is very likely to be "RX state" (i.e. a typo in the datasheet) - * - * With infinite TX, ADCTSTx always read as 0 so we'll use infinite RX - */ - MDMCTRL1L = 0x02; /* RX mode 10 - RX_INFINITE state */ - - /* "Enter RX State - Immediate" command strobe */ - cc2430_rf_command(ISRXON); - - /* Make sure the RNG is on */ - ADCCON1 &= ~(ADRCTRL1 | ADRCTRL0); - - /* Wait for IF_ADC I-branch and Q-branch values */ - while(!(ADCTSTH & ADCTSTL)); - - /* 32 times as per the chipcon example. This seems to increase randomness */ - for(i = 0; i < 32; i++) { - /* Seed the RNG by writing into RNDL twice with values from ADCTSTx */ - RNDL = ADCTSTH; - RNDL = ADCTSTL; - - /* Clock the RNG LSFR once */ - ADCCON1 |= ADRCTRL0; - } - - /* - * Exit RX state. Just shut down, network initialisation will take care of - * properly starting the radio for us. - */ - RFPWR |= RREG_RADIO_PD; -} diff --git a/cpu/cc2430/dev/uart.h b/cpu/cc2430/dev/uart.h deleted file mode 100644 index e230c3bcd..000000000 --- a/cpu/cc2430/dev/uart.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef UART_H -#define UART_H - -#include "contiki-conf.h" - -#include "cc2430_sfr.h" -#include "8051def.h" - -/*---------------------------------------------------------------------------*/ -/* UART BAUD Rates */ -/* - * Macro to set speed of UART N by setting the UnBAUD SFR to M and the - * UnGCR SRF to E. See the cc2430 datasheet for possible values of M and E - */ -#define UART_SET_SPEED(N, M, E) do{ U##N##BAUD = M; U##N##GCR = E; } while(0) - -/* - * Sample Values for M and E in the macro above to achieve some common BAUD - * rates. For more values, see the cc2430 datasheet - */ -/* 2000000 - cc2430 theoretical MAX when using the 32MHz clock */ -#define UART_2K_M 0 -#define UART_2K_E 16 -/* 1000000 - cc2430 theoretical MAX when using the 16MHz clock */ -#define UART_1K_M 0 -#define UART_1K_E 15 -/* 921600 */ -#define UART_921_M 216 -#define UART_921_E 14 -/* 460800 Higher values lead to problems when the node needs to RX */ -#define UART_460_M 216 -#define UART_460_E 13 -/* 115200 */ -#define UART_115_M 216 -#define UART_115_E 11 -/* 38400 */ -#define UART_38_M 59 -#define UART_38_E 10 -/* 9600 */ -#define UART_9_M 59 -#define UART_9_E 8 - -#endif /* UART_H */ diff --git a/cpu/cc2430/dev/uart0.c b/cpu/cc2430/dev/uart0.c deleted file mode 100644 index 254dba765..000000000 --- a/cpu/cc2430/dev/uart0.c +++ /dev/null @@ -1,69 +0,0 @@ -/** - * \file - * - * uart0 write routines - * - * \author - * - * Anthony "Asterisk" Ambuehl - * - */ -#include -#include - -#include "cc2430_sfr.h" -#include "dev/uart0.h" - -#if UART_ZERO_ENABLE -/*---------------------------------------------------------------------------*/ -void -uart0_init() -{ - UART_SET_SPEED(0, UART_115_M, UART_115_E); - -#ifdef UART0_ALTERNATIVE_2 - PERCFG |= U0CFG; /*alternative port 2 = P1.5-2*/ -#ifdef UART0_RTSCTS - P1SEL |= 0x3C; /*peripheral select for TX and RX, RTS, CTS*/ -#else - P1SEL |= 0x30; /*peripheral select for TX and RX*/ - P1 &= ~0x08; /*RTS down*/ -#endif - P1DIR |= 0x28; /*RTS, TX out*/ - P1DIR &= ~0x14; /*CTS & RX in*/ -#else - PERCFG &= ~U0CFG; /*alternative port 1 = P0.5-2*/ -#ifdef UART0_RTSCTS - P0SEL |= 0x3C; /*peripheral select for TX and RX, RTS, CTS*/ -#else - P0SEL |= 0x0C; /*peripheral select for TX and RX*/ - P0 &= ~0x20; /*RTS down*/ -#endif - P0DIR |= 0x28; /*RTS & TX out*/ - P0DIR &= ~0x14; /*CTS & RX in*/ -#endif - - -#ifdef UART0_RTSCTS - U0UCR = 0x42; /*defaults: 8N1, RTS/CTS, high stop bit*/ -#else - U0UCR = 0x02; /*defaults: 8N1, no flow control, high stop bit*/ -#endif - - U0CSR = U_MODE | U_RE | U_TXB; /*UART mode, receiver enable, TX done*/ - - /*set priority group of group 3 to highest, so the UART won't miss bytes*/ - IP1 |= IP1_3; - IP0 |= IP0_3; -} -/*---------------------------------------------------------------------------*/ -/* Write one byte over the UART. */ -void -uart0_writeb(uint8_t byte) -{ - IRCON2_UTX0IF = 0; - U0BUF = byte; - while(!IRCON2_UTX0IF); /* Wait until byte has been transmitted. */ - IRCON2_UTX0IF = 0; -} -#endif diff --git a/cpu/cc2430/dev/uart0.h b/cpu/cc2430/dev/uart0.h deleted file mode 100644 index 8a1357639..000000000 --- a/cpu/cc2430/dev/uart0.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef UART_0_H -#define UART_0_H - -#include "contiki-conf.h" - -#include "cc2430_sfr.h" -#include "8051def.h" -#include "uart.h" - -/*---------------------------------------------------------------------------*/ -/* UART0 Enable - Disable */ -#ifdef UART_ZERO_CONF_ENABLE -#define UART_ZERO_ENABLE UART_ZERO_CONF_ENABLE -#else -#define UART_ZERO_ENABLE 0 -#endif -/*---------------------------------------------------------------------------*/ -/* UART0 Function Declarations */ -#if UART_ZERO_ENABLE -void uart0_init(); -void uart0_writeb(uint8_t byte); - -void uart0_set_input(int (* input)(unsigned char c)); - -void uart0_rx_ISR(void) __interrupt(URX0_VECTOR); -void uart0_tx_ISR(void) __interrupt(UTX0_VECTOR); -/* Macro to turn on / off UART RX Interrupt */ -#define UART0_RX_INT(v) do { IEN0_URX0IE = v; } while(0) -#endif - -#endif /* UART_0_H */ diff --git a/cpu/cc2430/dev/uart1.c b/cpu/cc2430/dev/uart1.c deleted file mode 100644 index 7f388c5b6..000000000 --- a/cpu/cc2430/dev/uart1.c +++ /dev/null @@ -1,74 +0,0 @@ -/** - * \file - * - * uart1 write routines - * - * \author - * - * Anthony "Asterisk" Ambuehl - * - */ -#include -#include - -#include "cc2430_sfr.h" -#include "dev/uart1.h" - -#if UART_ONE_ENABLE -/*---------------------------------------------------------------------------*/ -/* UART1 initialization */ -void -uart1_init() -{ -#ifdef UART1_ALTERNATIVE_1 - PERCFG &= ~U1CFG; /*alternative port 1 = P0.5-2*/ -#ifdef UART1_RTSCTS - P0SEL |= 0x3C; /*peripheral select for TX and RX, RTS, CTS*/ -#else - P0SEL |= 0x30; /*peripheral select for TX and RX*/ - P0 &= ~0x08; /*RTS down*/ -#endif - P0DIR |= 0x18; /*RTS, TX out*/ - P0DIR &= ~0x24; /*CTS, RX in*/ -#else - PERCFG |= U1CFG; /*alternative port 2 = P1.7-4*/ -#ifdef UART1_RTSCTS - P1SEL |= 0xF0; /*peripheral select for TX and RX*/ -#else - P1SEL |= 0xC0; /*peripheral select for TX and RX*/ - P1 &= ~0x20; /*RTS down*/ -#endif - P1DIR |= 0x60; /*RTS, TX out*/ - P1DIR &= ~0x90; /*CTS, RX in*/ -#endif - -#if UART_ONE_CONF_HIGH_SPEED - UART_SET_SPEED(1, UART_460_M, UART_460_E); -#else - UART_SET_SPEED(1, UART_115_M, UART_115_E); -#endif - -#ifdef UART1_RTSCTS - U1UCR = 0x42; /*defaults: 8N1, RTS/CTS, high stop bit*/ -#else - U1UCR = 0x02; /*defaults: 8N1, no flow control, high stop bit*/ -#endif - - U1CSR = U_MODE | U_RE; /* UART mode, receiver enable */ - - /*set priority group of group 3 to highest, so the UART won't miss bytes*/ - IP1 |= IP1_3; - IP0 |= IP0_3; -} -/*---------------------------------------------------------------------------*/ -/* Write one byte over the UART. */ -void -uart1_writeb(uint8_t byte) -{ - IRCON2_UTX1IF = 0; - U1BUF = byte; - while(!IRCON2_UTX1IF); /* Wait until byte has been transmitted. */ - IRCON2_UTX1IF = 0; -} -/*---------------------------------------------------------------------------*/ -#endif diff --git a/cpu/cc2430/dev/uart1.h b/cpu/cc2430/dev/uart1.h deleted file mode 100644 index 1a4b7e9fa..000000000 --- a/cpu/cc2430/dev/uart1.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef UART_1_H -#define UART_1_H - -#include "contiki-conf.h" - -#include "cc2430_sfr.h" -#include "8051def.h" -#include "uart.h" - -/*---------------------------------------------------------------------------*/ -/* UART1 Enable - Disable */ -#ifdef UART_ONE_CONF_ENABLE -#define UART_ONE_ENABLE UART_ONE_CONF_ENABLE -#else -#define UART_ONE_ENABLE 0 -#endif -/*---------------------------------------------------------------------------*/ -/* UART1 Function Declarations */ -#if UART_ONE_ENABLE -void uart1_init(); -void uart1_writeb(uint8_t byte); - -void uart1_set_input(int (*input)(unsigned char c)); -#if UART_ONE_CONF_WITH_INPUT -void uart1_rx_ISR(void) __interrupt(URX1_VECTOR); -void uart1_tx_ISR(void) __interrupt(UTX1_VECTOR); -/* Macro to turn on / off UART RX Interrupt */ -#define UART1_RX_INT(v) do { IEN0_URX1IE = v; } while(0) -#else -#define UART1_RX_INT(v) -#endif /* UART_ONE_CONF_WITH_INPUT */ -#else -#define uart1_init(...) -#define uart1_writeb(...) -#define uart1_set_input(...) -#define UART1_RX_INT(v) -#endif /* UART_ONE_ENABLE */ - -#endif /* UART_1_H */ diff --git a/cpu/cc2430/dev/uart_intr.c b/cpu/cc2430/dev/uart_intr.c deleted file mode 100644 index 17a5427aa..000000000 --- a/cpu/cc2430/dev/uart_intr.c +++ /dev/null @@ -1,91 +0,0 @@ -/** - * \file - * - * uart write routines - * - * \author - * - * Anthony "Asterisk" Ambuehl - * - * interrupt routines which must be in HOME bank. handles received data from UART. - * - */ -#include -#include - -#include "cc2430_sfr.h" - -#include "dev/leds.h" -#include "dev/uart0.h" -#include "dev/uart1.h" -#include "sys/energest.h" - -#if UART_ZERO_ENABLE -static int (* uart0_input_handler)(unsigned char c); -#endif -#if UART_ONE_ENABLE -static int (* uart1_input_handler)(unsigned char c); -#endif - -#if UART_ZERO_ENABLE -/*---------------------------------------------------------------------------*/ -void -uart0_set_input(int (* input)(unsigned char c)) -{ - uart0_input_handler = input; -} - -/*---------------------------------------------------------------------------*/ -#pragma save -#if CC_CONF_OPTIMIZE_STACK_SIZE -#pragma exclude bits -#endif -void -uart0_rx_ISR(void) __interrupt(URX0_VECTOR) -{ - ENERGEST_ON(ENERGEST_TYPE_IRQ); - TCON_URX0IF = 0; - if(uart0_input_handler != NULL) { - uart0_input_handler(U0BUF); - } - ENERGEST_OFF(ENERGEST_TYPE_IRQ); -} -/*---------------------------------------------------------------------------*/ -void -uart0_tx_ISR(void) __interrupt(UTX0_VECTOR) -{ -} -#pragma restore -#endif /* UART_ZERO_ENABLE */ -#if UART_ONE_ENABLE -/*---------------------------------------------------------------------------*/ -void -uart1_set_input(int (* input)(unsigned char c)) -{ - uart1_input_handler = input; -} -/*---------------------------------------------------------------------------*/ -#if UART_ONE_CONF_WITH_INPUT -#pragma save -#if CC_CONF_OPTIMIZE_STACK_SIZE -#pragma exclude bits -#endif -void -uart1_rx_ISR(void) __interrupt(URX1_VECTOR) -{ - ENERGEST_ON(ENERGEST_TYPE_IRQ); - TCON_URX1IF = 0; - if(uart1_input_handler != NULL) { - uart1_input_handler(U1BUF); - } - ENERGEST_OFF(ENERGEST_TYPE_IRQ); -} -/*---------------------------------------------------------------------------*/ -void -uart1_tx_ISR(void) __interrupt(UTX1_VECTOR) -{ -} -#pragma restore -/*---------------------------------------------------------------------------*/ -#endif /* UART_ONE_CONF_WITH_INPUT */ -#endif /* UART_ONE_ENABLE */ diff --git a/cpu/cc2430/dev/watchdog-cc2430.c b/cpu/cc2430/dev/watchdog-cc2430.c deleted file mode 100644 index f8c4646a5..000000000 --- a/cpu/cc2430/dev/watchdog-cc2430.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Hardware-dependent functions used for the cc2430 watchdog timer. - * - * This file contains an ISR and must reside in the HOME bank. - * - * \author - * George Oikonomou - - */ - -#include "sys/energest.h" -#include "cc2430_sfr.h" -#include "contiki-conf.h" -#include "dev/watchdog-cc2430.h" - -/*---------------------------------------------------------------------------*/ -/* The watchdog only throws interrupts in timer mode */ -#if WDT_TIMER_MODE -#pragma save -#if CC_CONF_OPTIMIZE_STACK_SIZE -#pragma exclude bits -#endif -void -cc4230_watchdog_ISR(void) __interrupt(WDT_VECTOR) -{ - EA = 0; - ENERGEST_ON(ENERGEST_TYPE_IRQ); - /* Do something */ - IRCON2 &= ~WDTIF; - ENERGEST_OFF(ENERGEST_TYPE_IRQ); - EA = 1; -} -#pragma restore -#endif -/*---------------------------------------------------------------------------*/ -void -watchdog_init(void) -{ - WDCTL = WDT_TIMER_MODE | WDT_INTERVAL; - -#if WDT_TIMER_MODE - /* Enable the watchdog interrupts in timer mode */ - IEN2 |= WDTIE; -#endif - return; -} -/*---------------------------------------------------------------------------*/ -void -watchdog_start(void) -{ - WDCTL |= WDT_EN; -} -/*---------------------------------------------------------------------------*/ -void -watchdog_periodic(void) -{ -#if WDT_TIMER_MODE - /* In timer mode, all we need to do is write 1 to WDT:CLR[0] */ - WDCTL |= WDT_CLR0; -#else - /* Write the 'clear' sequence while maintaining mode and interval setting */ - WDCTL = (WDCTL & 0x0F) | WDT_CLR3 | WDT_CLR1; - WDCTL = (WDCTL & 0x0F) | WDT_CLR2 | WDT_CLR0; -#endif -} -/*---------------------------------------------------------------------------*/ -void -watchdog_stop(void) -{ -#if WDT_TIMER_MODE - /* In timer mode, the watchdog can actually be stopped */ - WDCTL &= ~WDT_EN; - IRCON2 &= ~WDTIF; -#else - /* In watchdog mode, stopping is impossible so we just reset the timer */ - watchdog_periodic(); -#endif -} -/*---------------------------------------------------------------------------*/ -void -watchdog_reboot(void) -{ -#if WDT_TIMER_MODE - /* Switch modes to watchdog, minimum interval, enable */ - WDCTL = WDT_EN | WDT_TIMEOUT_2_MSEC; -#else - /* Let's get this over with ASAP */ - WDCTL = WDT_TIMEOUT_2_MSEC; -#endif - /* Dis-acknowledge all interrupts while we wait for the dog to bark */ - DISABLE_INTERRUPTS(); - /* NOP till the dog barks... */ - while(1) { - __asm - nop - __endasm; - } -} diff --git a/cpu/cc2430/dev/watchdog-cc2430.h b/cpu/cc2430/dev/watchdog-cc2430.h deleted file mode 100644 index 8ea81fa2c..000000000 --- a/cpu/cc2430/dev/watchdog-cc2430.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Hardware-dependent header file for the cc2430 watchdog timer. - * - * The interrupt service routine's prototype must be included by the - * file containing main(). - * - * \author - * George Oikonomou - - */ - -#ifndef WATCHDOG_CC2430_H_ -#define WATCHDOG_CC2430_H_ - -#include "dev/watchdog.h" -#include "cc2430_sfr.h" -#include "contiki-conf.h" - -#define WDT_TIMEOUT_1_SEC 0x00 -#define WDT_TIMEOUT_250_MSEC WDT_INT0 -#define WDT_TIMEOUT_15_MSEC WDT_INT1 -#define WDT_TIMEOUT_2_MSEC WDT_INT1 | WDT_INT0 - -#if WDT_CONF_TIMER_MODE -#define WDT_TIMER_MODE WDT_MODE /* Timer */ -#else -#define WDT_TIMER_MODE 0x00 /* Watchdog */ -#endif - -#ifdef WDT_CONF_INTERVAL -#define WDT_INTERVAL WDT_CONF_INTERVAL -#else -#define WDT_INTERVAL WDT_TIMEOUT_1_SEC /* 2 secs */ -#endif - -/* The watchdog only throws interrupts in timer mode */ -#if WDT_TIMER_MODE -void cc4230_watchdog_ISR(void) __interrupt (WDT_VECTOR); -#endif - -#endif /* WATCHDOG_CC2430_H_ */ diff --git a/cpu/cc2430/mtarch.h b/cpu/cc2430/mtarch.h deleted file mode 100644 index 9542270a1..000000000 --- a/cpu/cc2430/mtarch.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. The name of the author may not be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - */ - -/* - * \file - * Stub header file for cc2430 multi-threading. It doesn't do anything, it - * just exists so that mt.c can compile cleanly. - * - * This is based on the original mtarch.h for z80 by Takahide Matsutsuka - * - * \author - * George Oikonomou - - */ -#ifndef MTARCH_H_ -#define MTARCH_H_ - -struct mtarch_thread { - unsigned char *sp; -}; - -#endif /* MTARCH_H_ */ diff --git a/cpu/cc2430/rtimer-arch.c b/cpu/cc2430/rtimer-arch.c deleted file mode 100644 index 1abff5c08..000000000 --- a/cpu/cc2430/rtimer-arch.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - * - */ - -/** - * \file - * Hardware-dependent functions used to support the - * contiki rtimer module. - * - * clock and etimer are using the sleep timer on the cc2430 - * - * clock_init() has set our tick speed prescaler already, so we - * are ticking with 500 kHz freq. - * - * rtimer_clock_t is unsigned short (16bit on the cc2430) - * It thus makes sense to use the 16bit clock (Timer 1) - * - * This file contains an ISR and must reside in the HOME bank - * - * \author - * George Oikonomou - - */ - -#include "sys/rtimer.h" /* Includes rtimer-arch.h for us */ -#include "cc2430_sfr.h" -#include "sys/energest.h" - -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif - -/*---------------------------------------------------------------------------*/ -void -rtimer_arch_init(void) -{ - PRINTF("rtimer_arch_init() "); - /* - * - Free running mode - * - Prescale by 32: - * Tick Speed has been prescaled to 500 kHz already in clock_init() - * We further prescale by 32 resulting in 15625 Hz for this timer. - */ - T1CTL = (T1DIV1 | T1MODE0); /* 00001001 */ - PRINTF("T1CTL=0x%02x\n", T1CTL); - /* Acknowledge Timer 1 Interrupts */ - IEN1_T1IE = 1; - PRINTF("IEN1_T1IE=0x%02x\n", IEN1_T1IE); - - /* Timer 1, Channel 1. Compare Mode (0x04), Interrupt mask on (0x40) */ - T1CCTL1 = T1MODE + T1IM; - PRINTF("T1CCTL1=0x%02x\n", T1CCTL1); - - /* Interrupt Mask Flags: No interrupt on overflow */ - TIMIF &= ~OVFIM; - PRINTF("TIMIF=0x%02x\n", TIMIF); - - PRINTF("done\n"); -} -/*---------------------------------------------------------------------------*/ -void -rtimer_arch_schedule(rtimer_clock_t t) -{ - PRINTF("rtimer_arch_schedule(%u)\n", t); - - /* set the compare mode values so we can get an interrupt after t */ - T1CC1L = (unsigned char)t; - T1CC1H = (unsigned char)(t >> 8); - PRINTF("T1CC1=%u, t=%u\n", (T1CC1L + (T1CC1H << 8)), t); - - /* Turn on compare mode interrupt */ - PRINTF("T1CTL=0x%02x\n", T1CTL); - T1CCTL1 |= T1IM; -} -/*---------------------------------------------------------------------------*/ -#pragma save -#if CC_CONF_OPTIMIZE_STACK_SIZE -#pragma exclude bits -#endif -void -cc2430_timer_1_ISR(void) __interrupt(T1_VECTOR) -{ - IEN1_T1IE = 0; /* Ignore Timer 1 Interrupts */ - ENERGEST_ON(ENERGEST_TYPE_IRQ); - /* No more interrupts from Channel 1 till next rtimer_arch_schedule() call. - * Setting the mask will instantly generate an interrupt so we clear the - * flag first. */ - T1CTL &= ~(CH1IF); - T1CCTL1 &= ~T1IM; - - rtimer_run_next(); - - ENERGEST_OFF(ENERGEST_TYPE_IRQ); - IEN1_T1IE = 1; /* Acknowledge Timer 1 Interrupts */ -} -#pragma restore diff --git a/cpu/cc2430/rtimer-arch.h b/cpu/cc2430/rtimer-arch.h deleted file mode 100644 index f007cff91..000000000 --- a/cpu/cc2430/rtimer-arch.h +++ /dev/null @@ -1,62 +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. - * - */ - -/** - * \file - * Hardware-dependent function declarations used to - * support the contiki rtimer module. - * - * We use Timer 1 on the cc2431. - * - * \author - * Zach Shelby (Original) - * George Oikonomou - - * (rtimer-arch implementation for cc2430) - */ - -#ifndef RTIMER_ARCH_H_ -#define RTIMER_ARCH_H_ - -#include "contiki-conf.h" -#include "cc2430_sfr.h" - -/* - * 32 MHz clock, prescaled down to 500 kHz for all 4 timers in clock_init(). - * Further prescaled factor 32 for T1, thus T1 is 15625 Hz - */ -#define RTIMER_ARCH_SECOND (15625U) - -#define rtimer_arch_now() ((rtimer_clock_t)(T1CNTL + (T1CNTH << 8))) - -void cc2430_timer_1_ISR(void) __interrupt(T1_VECTOR); - -#endif /* RTIMER_ARCH_H_ */ diff --git a/cpu/cc2430/segment.rules b/cpu/cc2430/segment.rules deleted file mode 100644 index 3b4ffbdfa..000000000 --- a/cpu/cc2430/segment.rules +++ /dev/null @@ -1,26 +0,0 @@ -# segment.rules files assign source code modules to specific banks -# These files are only used when we build code with banking (HAVE_BANKING=1) -# The final segment.rules file is constructed from any segment.rules found in -# the search path, defined in Makefile.cc2430 -# When building bankable code, the bank-alloc.py script automatically allocates -# modules to banks. segment.rules files provide hints, instructing the script -# as to which files are safe to move around and which files to leave alone -# In other words, only specify a rule for a file if you need to -# comments starting with "#" are supported -# The file spec in rules is actually interpreted as a python regex so you can -# write a rule that will match multiple files -# -# general rules -- -# This file is only used when the Makefile defines HAVE_BANKING=1 -# SDCC's standard libraries will always go in CSEG - We don't touch them -# Interrupt code must be in HOME. Specify all files with an ISR here -# All files without an associated rule get allocated to a bank automatically - -# Files with ISRs must be in HOME -HOME intr.c # Match all files ending in intr.c (e.g. uart_intr.c) -HOME rtimer-arch.c -HOME watchdog-cc2430.c -HOME clock.c - -# Some cc2430 files which need special treatment -HOME bus.c # bus.c::flash_read() must be run from HOME (if compiled in) diff --git a/cpu/cc2430/stack.c b/cpu/cc2430/stack.c deleted file mode 100644 index 7043b2edf..000000000 --- a/cpu/cc2430/stack.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2011, George Oikonomou - - * 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 AUTHOR 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. - */ - -/** - * \file - * 8051 stack debugging facilities - * - * \author - * George Oikonomou - - * Philippe Retornaz (EPFL) - */ -#include "contiki.h" - -#ifndef STACK_POISON -#define STACK_POISON 0xAA -#endif - -CC_AT_DATA uint8_t sp; - -void -stack_poison(void) -{ - __asm - mov r1, _SP -poison_loop: - inc r1 - mov @r1, #STACK_POISON - cjne r1, #0xFF, poison_loop - __endasm; -} - -uint8_t -stack_get_max(void) -{ - __data uint8_t *sp = (__data uint8_t *)0xff; - uint8_t free = 0; - - while(*sp-- == STACK_POISON) { - free++; - } - - return 0xff - free; -} diff --git a/cpu/cc2430/stack.h b/cpu/cc2430/stack.h deleted file mode 100644 index 6ee7442b6..000000000 --- a/cpu/cc2430/stack.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2011, George Oikonomou - - * 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 AUTHOR 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. - */ - -/** - * \file - * Header file for 8051 stack debugging facilities - * - * \author - * George Oikonomou - - * Philippe Retornaz (EPFL) - */ -#ifndef STACK_H_ -#define STACK_H_ - -#if STACK_CONF_DEBUGGING -extern CC_AT_DATA uint8_t sp; - -#define stack_dump(f) do { \ - putstring(f); \ - sp = SP; \ - puthex(sp); \ - putchar('\n'); \ -} while(0) - -#define stack_max_sp_print(f) do { \ - putstring(f); \ - puthex(stack_get_max()); \ - putchar('\n'); \ -} while(0) - -void stack_poison(void); -uint8_t stack_get_max(void); -#else -#define stack_dump(...) -#define stack_max_sp_print(...) -#define stack_poison() -#define stack_get_max() -#endif - -#endif /* STACK_H_ */ diff --git a/examples/sensinode/Makefile b/examples/sensinode/Makefile deleted file mode 100644 index cd1472d33..000000000 --- a/examples/sensinode/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N740 - -# These examples don't need code banking so we turn it off -#HAVE_BANKING=1 - -CONTIKI_PROJECT += timer-test blink-hello broadcast-rime - -all: $(CONTIKI_PROJECT) - -CONTIKI = ../.. -CONTIKI_WITH_RIME = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/README.md b/examples/sensinode/README.md deleted file mode 100644 index 5168ff692..000000000 --- a/examples/sensinode/README.md +++ /dev/null @@ -1,60 +0,0 @@ -Sensinode platform example and test applications -================================================ - -by Zach Shelby - -Some more examples by George Oikonomou - -Loughborough University - -cc2431-location-engine, udp-ipv6, broadcast-rime blink-hello, event-post, -timer-test - -This directory contains example and test applications for Sensinode CC2430 -based devices. By default it is set to use the sensinode platform: - -/platform/sensinode -/cpu/cc2430 - -To build an application: - - make [app_name] - make hello_world - -To build and upload an application using the Sensinode nano_programmer included -under /tools (default /dev/ttyUSB0): - - make [app_name].upload - make hello_world.upload - -To dump the serial port output (default /dev/ttyUSB0): - - make sensinode.serialdump - -To configure the hardware model, you can include a make option e.g. for the -N601 (N100 is assumed by default): - - make hello_world DEFINES=MODEL_N601 - -These make options are defined in /platform/sensinode/Makefile.sensinode - -Descriptions of applications: - -- udp-ipv6: UDP client-server example over uIPv6. Uses link-local and global - addresses. Button 1 on the client will send an echo request. - -- broadcast-rime: Just a broadcast rime example, slightly modified - -- sensors: Demonstrating button and ADC functionality - -- cc2431-location-engine: Example demonstrating the usage cc2431 location - engine (blind node) N.B. Not all sensinode devides have a cc2431 - -- event-post: Demonstrating the interaction between two processes with custom - events - -- blink-hello: Hello World with LED blinking. - -- timer-test: Same as clock_test above + testing the rtimer-arch code - -- border-router: 802.15.4 to SLIP bridge example. The node will forward packets - from the 15.4 network to its UART (and thus a connected PC over SLIP) diff --git a/examples/sensinode/blink-hello.c b/examples/sensinode/blink-hello.c deleted file mode 100644 index 80d2fb9ad..000000000 --- a/examples/sensinode/blink-hello.c +++ /dev/null @@ -1,62 +0,0 @@ -/* This is a very simple hello_world program. - * It aims to demonstrate the co-existence of two processes: - * One of them prints a hello world message and the other blinks the LEDs - * - * It is largely based on hello_world in $(CONTIKI)/examples/sensinode - * - * Author: George Oikonomou - */ - -#include "contiki.h" -#include "dev/leds.h" - -#include -/*---------------------------------------------------------------------------*/ -PROCESS(hello_world_process, "Hello world process"); -PROCESS(blink_process, "LED blink process"); - -AUTOSTART_PROCESSES(&hello_world_process, &blink_process); -/*---------------------------------------------------------------------------*/ -/* Implementation of the first process */ -PROCESS_THREAD(hello_world_process, ev, data) -{ - static struct etimer timer; - static int count; - - PROCESS_BEGIN(); - - etimer_set(&timer, CLOCK_CONF_SECOND * 4); - count = 0; - - while(1) { - - PROCESS_WAIT_EVENT(); - - if(ev == PROCESS_EVENT_TIMER) { - printf("Sensor says no... #%d\r\n", count); - count++; - - etimer_reset(&timer); - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -/* Implementation of the second process */ -PROCESS_THREAD(blink_process, ev, data) -{ - static struct etimer timer; - PROCESS_BEGIN(); - - while(1) { - etimer_set(&timer, CLOCK_CONF_SECOND); - - PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); - - printf("Blink... (state %0.2X).\r\n", leds_get()); - leds_toggle(LEDS_GREEN); - } - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/border-router/Makefile b/examples/sensinode/border-router/Makefile deleted file mode 100644 index 38ebe9e27..000000000 --- a/examples/sensinode/border-router/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N601,PROJECT_CONF_H - -# We need uIPv6, therefore we also need banking -HAVE_BANKING=1 - -PROJECT_SOURCEFILES += slip-bridge.c - -CONTIKI_PROJECT = border-router -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../.. - -CONTIKI_WITH_IPV6 = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/border-router/README.md b/examples/sensinode/border-router/README.md deleted file mode 100644 index 92900008d..000000000 --- a/examples/sensinode/border-router/README.md +++ /dev/null @@ -1,20 +0,0 @@ -border-router example for sensinode devices -=========================================== - -This example is meant to be used with tunslip6 in tools/ - -- Build the code and load it onto your node -- Connect your node to your PC over USB -- run: - - sudo ./tunslip6
/ - -This will setup tun0 on your PC over device /dev/ttyUSBx. The address argument -should contain the v6 address that you want to assign to tun0 The node will use -this address to obtain the network prefix - -For example: - - sudo ./tunslip6 aaaa::1/64 - -This will use aaaa:: / 64 as the prefix for the 15.4 network. diff --git a/examples/sensinode/border-router/border-router.c b/examples/sensinode/border-router/border-router.c deleted file mode 100644 index 9442c9e03..000000000 --- a/examples/sensinode/border-router/border-router.c +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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" -#include "contiki-lib.h" -#include "contiki-net.h" - -#include - -#define DEBUG DEBUG_PRINT -#include "net/ip/uip-debug.h" -#include "net/rpl/rpl.h" -#include "dev/watchdog.h" -#include "dev/slip.h" -#include "dev/leds.h" -#include "dev/cc2430_rf.h" -#include "debug.h" - -static uint8_t prefix_set; - -#if DEBUG -#define PUTSTRING(...) putstring(__VA_ARGS__) -#define PUTHEX(...) puthex(__VA_ARGS__) -#define PUTBIN(...) putbin(__VA_ARGS__) -#define PUTDEC(...) putdec(__VA_ARGS__) -#define PUTCHAR(...) putchar(__VA_ARGS__) -#else -#define PUTSTRING(...) -#define PUTHEX(...) -#define PUTBIN(...) -#define PUTDEC(...) -#define PUTCHAR(...) -#endif -/*---------------------------------------------------------------------------*/ -PROCESS(border_router_process, "Border Router process"); -AUTOSTART_PROCESSES(&border_router_process); -/*---------------------------------------------------------------------------*/ -static void -print_local_addresses(void) CC_NON_BANKED -{ - int i; - uint8_t state; - - PUTSTRING("Router's IPv6 addresses:\n"); - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - state = uip_ds6_if.addr_list[i].state; - if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state - == ADDR_PREFERRED)) { - PUTSTRING(" "); - PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); - PUTCHAR('\n'); - if(state == ADDR_TENTATIVE) { - uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; - } - } - } -} -/*---------------------------------------------------------------------------*/ -static void -request_prefix(void) CC_NON_BANKED -{ - /* mess up uip_buf with a dirty request... */ - uip_buf[0] = '?'; - uip_buf[1] = 'P'; - uip_len = 2; - slip_send(); - uip_clear_buf(); -} -/*---------------------------------------------------------------------------*/ -/* Set our prefix when we receive one over SLIP */ -void -set_prefix_64(uip_ipaddr_t *prefix_64) -{ - rpl_dag_t *dag; - uip_ipaddr_t ipaddr; - memcpy(&ipaddr, prefix_64, 16); - prefix_set = 1; - uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); - uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); - - /* Become root of a new DODAG with ID our global v6 address */ - dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &ipaddr); - if(dag != NULL) { - rpl_set_prefix(dag, &ipaddr, 64); - PUTSTRING("Created a new RPL dag with ID: "); - PRINT6ADDR(&dag->dag_id); - PUTCHAR('\n'); - } -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(border_router_process, ev, data) -{ - static struct etimer et; - - PROCESS_BEGIN(); - PUTSTRING("Border Router started\n"); - prefix_set = 0; - - leds_on(LEDS_RED); - - /* Request prefix until it has been received */ - while(!prefix_set) { - leds_on(LEDS_GREEN); - PUTSTRING("Prefix request.\n"); - etimer_set(&et, CLOCK_SECOND); - request_prefix(); - leds_off(LEDS_GREEN); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - } - - /* We have created a new DODAG when we reach here */ - PUTSTRING("On Channel "); - PUTDEC(cc2430_rf_channel_get()); - PUTCHAR('\n'); - - print_local_addresses(); - - leds_off(LEDS_RED); - - PROCESS_EXIT(); - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/border-router/project-conf.h b/examples/sensinode/border-router/project-conf.h deleted file mode 100644 index 17cbe3193..000000000 --- a/examples/sensinode/border-router/project-conf.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Project specific configuration defines for the border router / - * slip bridge example. - * - * We make sure that SLIP is turned on - * - * \author - * George Oikonomou - - */ - -#ifndef PROJECT_CONF_H_ -#define PROJECT_CONF_H_ - -#define VIZTOOL_MAX_PAYLOAD_LEN 120 -#define SLIP_ARCH_CONF_ENABLE 1 -#define LPM_CONF_MODE 0 -#define UIP_FALLBACK_INTERFACE slip_interface - -#endif /* PROJECT_CONF_H_ */ diff --git a/examples/sensinode/border-router/slip-bridge.c b/examples/sensinode/border-router/slip-bridge.c deleted file mode 100644 index b0ebd066d..000000000 --- a/examples/sensinode/border-router/slip-bridge.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2010, 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. - * - */ - -/** - * \file - * Slip fallback interface - * \author - * Niclas Finne - * Joakim Eriksson - * Joel Hoglund - * Nicolas Tsiftes - */ - -#include "net/ip/uip.h" -#include "net/ipv6/uip-ds6.h" -#include "net/rpl/rpl.h" -#include "dev/slip.h" -#include "dev/uart1.h" -#include - -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) - -#define DEBUG DEBUG_NONE -#include "net/ip/uip-debug.h" - -void set_prefix_64(uip_ipaddr_t *); - -static uip_ipaddr_t last_sender; -/*---------------------------------------------------------------------------*/ -static void -slip_input_callback(void) -{ - PRINTF("SIN: %u\n", uip_len); - if((char)uip_buf[0] == '!') { - PRINTF("Got configuration message of type %c\n", uip_buf[1]); - uip_clear_buf(); - if((char)uip_buf[1] == 'P') { - uip_ipaddr_t prefix; - /* Here we set a prefix !!! */ - memset(&prefix, 0, 16); - memcpy(&prefix, &uip_buf[2], 8); - PRINTF("Setting prefix "); - PRINT6ADDR(&prefix); - PRINTF("\n"); - set_prefix_64(&prefix); - } - } - /* Save the last sender received over SLIP to avoid bouncing the - packet back if no route is found */ - uip_ipaddr_copy(&last_sender, &UIP_IP_BUF->srcipaddr); -} -/*---------------------------------------------------------------------------*/ -static void -init(void) -{ - process_start(&slip_process, NULL); - slip_set_input_callback(slip_input_callback); -} -/*---------------------------------------------------------------------------*/ -static int -output(void) -{ - if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) { - /* Do not bounce packets back over SLIP if the packet was received - over SLIP */ - PRINTF("slip-bridge: Destination off-link but no route\n"); - } else { - PRINTF("SUT: %u\n", uip_len); - slip_send(); - } - return 0; -} -/*---------------------------------------------------------------------------*/ -const struct uip_fallback_interface slip_interface = { - init, output -}; -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/broadcast-rime.c b/examples/sensinode/broadcast-rime.c deleted file mode 100644 index f69c2a1bc..000000000 --- a/examples/sensinode/broadcast-rime.c +++ /dev/null @@ -1,119 +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. - * - */ - -/** - * \file - * Testing the broadcast layer in Rime - * \author - * Adam Dunkels - */ -#include "contiki.h" -#include "net/rime/rime.h" -#include "lib/random.h" -#include "net/rime/rimestats.h" -#include "dev/leds.h" -#include "dev/models.h" - -#define DEBUG 1 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif - -#define BROADCAST_CHANNEL 129 - -/*---------------------------------------------------------------------------*/ -PROCESS(example_broadcast_process, "BROADCAST example"); -AUTOSTART_PROCESSES(&example_broadcast_process); -/*---------------------------------------------------------------------------*/ -static void -broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from) -{ - leds_toggle(LEDS_RED); - PRINTF("broadcast message received from %02x.%02x\n", from->u8[0], - from->u8[1]); - PRINTF("Size=0x%02x: '0x%04x'\n", packetbuf_datalen(), - *(uint16_t *)packetbuf_dataptr()); -} -/*---------------------------------------------------------------------------*/ -static void -print_rime_stats() -{ - PRINTF("\nNetwork Stats\n"); - PRINTF(" TX=%lu , RX=%lu\n", RIMESTATS_GET(tx), RIMESTATS_GET(rx)); - PRINTF("LL-TX=%lu , LL-RX=%lu\n", RIMESTATS_GET(lltx), RIMESTATS_GET(llrx)); - PRINTF(" Long=%lu , Short=%lu\n", RIMESTATS_GET(toolong), - RIMESTATS_GET(tooshort)); - PRINTF("T/Out=%lu , CCA-Err=%lu\n", RIMESTATS_GET(timedout), - RIMESTATS_GET(contentiondrop)); -} - -static const struct broadcast_callbacks bc_rx = { broadcast_recv }; -static struct broadcast_conn broadcast; -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(example_broadcast_process, ev, data) -{ - static struct etimer et; - static uint16_t counter; - - PROCESS_EXITHANDLER(broadcast_close(&broadcast);) - - PROCESS_BEGIN(); - - PRINTF("Start\n"); - broadcast_open(&broadcast, BROADCAST_CHANNEL, &bc_rx); - PRINTF("Open Broadcast Connection, channel %u\n", BROADCAST_CHANNEL); - - while(1) { - - /* Delay 2-4 seconds */ - etimer_set(&et, CLOCK_SECOND * 2); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - leds_on(LEDS_GREEN); - packetbuf_copyfrom(&counter, sizeof(counter)); - PRINTF("Sending %u bytes: 0x%04x\n", packetbuf_datalen(), - *(uint16_t *)packetbuf_dataptr()); - if(broadcast_send(&broadcast) == 0) { - PRINTF("Error Sending\n"); - } - - print_rime_stats(); - PRINTF("===================================\n"); - counter++; - leds_off(LEDS_GREEN); - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/cc2431-location-engine/Makefile b/examples/sensinode/cc2431-location-engine/Makefile deleted file mode 100644 index 4a14b80a9..000000000 --- a/examples/sensinode/cc2431-location-engine/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N740 - -# This example doesn't need code banking so we turn it off -#HAVE_BANKING=1 - -CONTIKI_PROJECT = blind-node - -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../.. - -CONTIKI_WITH_RIME = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/cc2431-location-engine/blind-node.c b/examples/sensinode/cc2431-location-engine/blind-node.c deleted file mode 100644 index f4c4aeacd..000000000 --- a/examples/sensinode/cc2431-location-engine/blind-node.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Example demonstrating the cc2431 location engine. - * - * This file contains code for the blind node. The blind node must be - * equipped with a cc2431 SoC (as opposed to reference nodes which - * don't need to have a Loc. Eng.) - * - * The blind node receives co-ordinates of reference nodes over - * broadcast rime. Once it has enough data (3+ reference nodes), it - * will calculate its own position. - * - * We calculate with all potential values for parameter 'n' to - * demonstrate how 'n' influences the result of the calculation. - * - * Optionally, send the result of the calculation to a collection node - * - * More information on the cc2431 Location Engine can be found in: - * - cc2431 Datasheet - * - Texas Instruments Application Note 42 - * - * \author - * George Oikonomou - - */ - -#include "contiki.h" -#include "net/rime/rime.h" -#include "cc2431_loc_eng.h" -#include "cc2430_sfr.h" - -#include -#include - -#define MAX_REF_NODES 16 /* Do not change */ - -#define SAMPLE_RSSI 100 /* Used for testing */ -#define SAMPLE_ALPHA 101 - -static struct meas_params parameters; -static struct refcoords ref_coords[MAX_REF_NODES]; - -/* Store our current location here to be transmitted to a collector node */ -static uint8_t coords[2]; - -/*---------------------------------------------------------------------------*/ -PROCESS(blindnode_bcast_rec, "Blind Node"); -AUTOSTART_PROCESSES(&blindnode_bcast_rec); -/*---------------------------------------------------------------------------*/ -/* - * This handles the calculation cycle. Returns non-zero on error, 0 on success. - * - * When we move this outside the example, we will perhaps want to pass - * struct refcoords *, struct meas_params * - * instead of exposing our own data structures. If this happens, we will need - * to add checks to our code to detect non-sane values - */ -static uint8_t -calculate() -{ - static int j, x; - uint8_t valid_rssi = 0; - - /* Turn on the Engine */ - LOCENG = LOCENG_EN; - while(!(LOCENG & LOCENG_EN)); - - /* Reference Coordinate Load Stage */ - LOCENG |= LOCENG_REFLD; - while(!(LOCENG & LOCENG_REFLD)); - - for(j = 0; j < MAX_REF_NODES; j++) { - /* Write the Reference Node x,y into the engine */ - REFCOORD = ref_coords[j].x; - REFCOORD = ref_coords[j].y; - } - - /* Reference Coordinate Load Stage Done. Proceed with measured params */ - LOCENG &= ~LOCENG_REFLD; - LOCENG |= LOCENG_PARLD; - - /* Load Parameters */ - MEASPARM = parameters.alpha; - MEASPARM = parameters.n; - MEASPARM = parameters.x_min; - MEASPARM = parameters.x_delta; - MEASPARM = parameters.y_min; - MEASPARM = parameters.y_delta; - - /* Load Neighbor RSSIs */ - for(j = 0; j < MAX_REF_NODES; j++) { - if(parameters.rssi[j] != 0) { - /* Range-check for the RSSI here, can only be in [-95 dBm , -40 dBm] - * so we only accept 80 <= rssi <= 190*/ - if(parameters.rssi[j] >= 80 && parameters.rssi[j] <= 190) { - valid_rssi++; - } - } - /* Write the value, even if it's zero */ - MEASPARM = parameters.rssi[j]; - } - - /* Done with measured parameters too */ - LOCENG &= ~LOCENG_PARLD; - - /* Only Calculate if we have 3+ reference nodes (non-zero RSSIs) */ - if(valid_rssi >= 3) { - LOCENG |= LOCENG_RUN; - } else { - LOCENG = 0; - printf("some error\n"); - return 1; - } - - /* Block on the calculation, between 50us and 13ms */ - while(!(LOCENG & LOCENG_DONE)); - - /* - * LOCX contains an offset. Remove it to obtain our actual X value. - * cc2431 datasheet, section 2.1.3 - */ - x = (LOCX - parameters.x_min + 1) % (parameters.x_delta + 1) - + parameters.x_min; - coords[0] = x; - coords[1] = LOCY; /* No offset here */ - printf("n=%2u: X=%3u, Y=%3u\n", parameters.n, LOCX, LOCY); - - /* Turn it off */ - LOCENG = 0; - - return 0; -} - -/*---------------------------------------------------------------------------*/ -/* - * We receive X, Y from reference nodes. - * We store this in location J of the ref_coords array, where J is the LSB - * of the reference node's rime address. So we can only accept data from nodes - * with rime address ending in [0 , 15] - */ -static void -broadcast_recv(struct broadcast_conn *c, const linkaddr_t *from) -{ - packetbuf_attr_t rssi; /* Careful here, this is uint16_t */ - - if(from->u8[1] < MAX_REF_NODES) { - memset(&ref_coords[from->u8[1] - 1], 0, sizeof(struct refcoords)); - - /* Obtain incoming message's RSSI from contiki */ - rssi = packetbuf_attr(PACKETBUF_ATTR_RSSI); - /* Convert RSSI to the loc. eng. format */ - parameters.rssi[from->u8[1] - 1] = (-2 * rssi); - /* Raw dump the packetbuf into the ref_coords struct */ - memcpy(&ref_coords[from->u8[1] - 1], packetbuf_dataptr(), - 2 * sizeof(uint8_t)); - } - - return; -} -/* - * Imaginary nodes to test functionality - * All nodes at 1 meter distance, rssi = -40 (80) - * Since the rssi at 1 meter = -40 (A), the blind node should think it's at - * 5,5 - */ -/*---------------------------------------------------------------------------*/ -static void -set_imaginary_ref_nodes() -{ - ref_coords[0].x = 1; - ref_coords[0].y = 5; - parameters.rssi[0] = SAMPLE_RSSI; - - ref_coords[1].x = 5; - ref_coords[1].y = 1; - parameters.rssi[1] = SAMPLE_RSSI; - - ref_coords[2].x = 5; - ref_coords[2].y = 9; - parameters.rssi[2] = SAMPLE_RSSI; - - ref_coords[3].x = 9; - ref_coords[3].y = 5; - parameters.rssi[3] = SAMPLE_RSSI; -} -/*---------------------------------------------------------------------------*/ -static const struct broadcast_callbacks broadcast_call = { broadcast_recv }; -static struct broadcast_conn broadcast; -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(blindnode_bcast_rec, ev, data) -{ - static struct etimer et; - static uint8_t n; - int i; - - PROCESS_EXITHANDLER(broadcast_close(&broadcast)); - - PROCESS_BEGIN(); - - printf("Reading Chip ID: 0x%02x\n", CHIPID); - /* Read our chip ID. If we are not cc2431, bail out */ - if(CHIPID != CC2431_CHIP_ID) { - printf("Hardware does not have a location engine. Exiting.\n"); - PROCESS_EXIT(); - } - - /* OK, we are cc2431. Do stuff */ - n = 0; - - /* Initalise our structs and parameters */ - memset(ref_coords, 0, sizeof(struct refcoords) * MAX_REF_NODES); - memset(¶meters, 0, sizeof(struct meas_params)); - - /* - * Just hard-coding measurement parameters here. - * Ideally, this should be part of a calibration mechanism - */ - parameters.alpha = SAMPLE_ALPHA; - parameters.x_min = 0; - parameters.x_delta = 255; - parameters.y_min = 0; - parameters.y_delta = 255; - - set_imaginary_ref_nodes(); - - broadcast_open(&broadcast, 129, &broadcast_call); - - while(1) { - - etimer_set(&et, CLOCK_SECOND); - - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - - /* - * With the hard-coded parameters and locations, we will calculate - * for all possible values of n [0 , 31] - */ - parameters.n = n; - calculate(); - n++; - if(n == 32) { - n = 0; - } - - /* Send our calculated location to some monitoring node */ - packetbuf_copyfrom(&coords, 2 * sizeof(uint8_t)); - broadcast_send(&broadcast); - } - PROCESS_END(); -} diff --git a/examples/sensinode/cc2431-location-engine/cc2431_loc_eng.h b/examples/sensinode/cc2431-location-engine/cc2431_loc_eng.h deleted file mode 100644 index b5489797c..000000000 --- a/examples/sensinode/cc2431-location-engine/cc2431_loc_eng.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Header file used by the example demonstrating the cc2431 location - * engine. - * - * This file contains declarations of the location engine registers and - * the LOCENG register bits. It also contains some data structures used - * to store calculation parameters and reference node coordinates. - * - * This file only needs to be included bye the blind node code file. - * - * More information on the cc2431 Location Engine can be found in: - * - cc2431 Datasheet - * - K. Aamodt, "CC2431 Location Engine", Texas Instruments Application - * Note 42. - * - * \author - * George Oikonomou - - */ - -#include "8051def.h" -#include /* For syntax parsers */ - -/* Location Engine Registers on the cc2431 */ -__xdata __at (0xDF55) unsigned char REFCOORD; -__xdata __at (0xDF56) unsigned char MEASPARM; -__xdata __at (0xDF57) unsigned char LOCENG; -__xdata __at (0xDF58) unsigned char LOCX; -__xdata __at (0xDF59) unsigned char LOCY; - -/* LOCENG Register Bits */ -#define LOCENG_RUN 0x01 -#define LOCENG_REFLD 0x02 -#define LOCENG_PARLD 0x04 -#define LOCENG_DONE 0x08 -#define LOCENG_EN 0x10 - -/* cc2431 chips report 0x89 when the CHIPID register is read */ -#define CC2431_CHIP_ID 0x89 - -/* - * Struct for the Calculation Parameters. - * Values stored here feed the MEASPARM register. - * - * Values should be stored here in Location Engine format: - * RSSI: 0.5 Precision, without the minus sign. All 16 must be used. Use 0 - * to reduce the number of ref. nodes used in the calculation. - * Value range [-95 dBm , -40 dBm] - * A: 0.5 Precision. Value range [30.0 , 50.0] (Thus [60 , 100] decimal) - * n: Use the n Index value [0 , 31] - See cc2431 datasheet, Table 2. - * delta: Must be present. If we want the calculation to be unrestricted, - * use 0xFF - * - */ -struct meas_params { - uint8_t alpha; - uint8_t n; - uint8_t x_min; - uint8_t x_delta; - uint8_t y_min; - uint8_t y_delta; - uint8_t rssi[16]; -}; - -/* - * Store the reference node coordinates here. - * This will feed REFCOORD. - * - * Values should be stored here in Location Engine format: - * 2 LS bits for the fractional part, 0.25 precision - * 6 MS bits for the integral part. - * Value range [0 , 63.75] (thus [0 , 255]) - */ -struct refcoords { - uint8_t x; - uint8_t y; -}; diff --git a/examples/sensinode/disco/Makefile b/examples/sensinode/disco/Makefile deleted file mode 100644 index 9c1903d4b..000000000 --- a/examples/sensinode/disco/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N740 - -HAVE_BANKING=1 -OFFSET_FIRMWARE=1 - -CONTIKI_PROJECT = disco-example - -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../.. - -CONTIKI_WITH_IPV6 = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/disco/disco-example.c b/examples/sensinode/disco/disco-example.c deleted file mode 100644 index 8f97a13fc..000000000 --- a/examples/sensinode/disco/disco-example.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Stub project source file. We just need to build contiki with - * OFFSET_FIRMWARE, Makefile does so. - * - * \author - * George Oikonomou - - */ - -#include "contiki.h" - -/*---------------------------------------------------------------------------*/ -PROCESS(stub_process, "Stub process"); -AUTOSTART_PROCESSES(&stub_process); -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(stub_process, ev, data) -{ - PROCESS_BEGIN(); - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/energy-scan/Makefile b/examples/sensinode/energy-scan/Makefile deleted file mode 100644 index e91d74b96..000000000 --- a/examples/sensinode/energy-scan/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N740,PROJECT_CONF_H - -PROJECT_SOURCEFILES += stub-rdc.c - -CONTIKI_PROJECT = energy-scan - -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../.. - -CONTIKI_WITH_RIME = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/energy-scan/energy-scan.c b/examples/sensinode/energy-scan/energy-scan.c deleted file mode 100644 index 7f90e593a..000000000 --- a/examples/sensinode/energy-scan/energy-scan.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Minimalistic channel energy detection. - * - * \author - * George Oikonomou - - */ - -#include "contiki.h" -#include "cc2430_sfr.h" - -#include "debug.h" -#include "dev/cc2430_rf.h" -#include - -static uint8_t channel; -static int8_t j; -static int8_t cmax; -static int8_t rssi; -static struct etimer et; -static rtimer_clock_t t0; - -#define RSSI_BASE -50 -#define RSSI_SAMPLES 30 -#define SAMPLE_INTERVAL (CLOCK_SECOND) -#define CHANNEL_MIN 11 -#define CHANNEL_MAX 26 -/* ToDo: Do this in infinite RX. Take more samples */ -/*---------------------------------------------------------------------------*/ -PROCESS(energy_scan, "Energy Scanner"); -AUTOSTART_PROCESSES(&energy_scan); -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(energy_scan, ev, data) -{ - - PROCESS_BEGIN(); - - printf("Energy Scanner\n"); - printf("CCA Threshold: %d\n", (int8_t)RSSIH); - printf("Channel scan range: [%u , %u]\n", CHANNEL_MIN, CHANNEL_MAX); - printf("%u samples per channel, interval %u ticks\n", - RSSI_SAMPLES, SAMPLE_INTERVAL); - - channel = CHANNEL_MIN; - while(1) { - cmax = RSSI_BASE; - cc2430_rf_channel_set(channel); - clock_delay_usec(200); - - for(j = 0; j < RSSI_SAMPLES; j++) { - t0 = RTIMER_NOW(); - rssi = RSSIL; - if(rssi > cmax) { - cmax = rssi; - } - while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + 25)); - } - printf("%u [%3d]: ", channel, cmax); - for(j = RSSI_BASE; j <= cmax; j++) { - printf("#"); - } - printf("\n"); - if(channel == CHANNEL_MAX) { - printf("===============\n"); - channel = CHANNEL_MIN; - } else { - channel++; - } - - etimer_set(&et, SAMPLE_INTERVAL); - PROCESS_YIELD(); - - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/energy-scan/netstack.c b/examples/sensinode/energy-scan/netstack.c deleted file mode 100644 index d59acc3fe..000000000 --- a/examples/sensinode/energy-scan/netstack.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Stub file overriding core/net/netstack.c. What we want to achieve - * here is call netstack_init from main without initialising the RDC, - * MAC and Network layers. It will just turn on the radio instead. - * - * \author - * George Oikonomou - - */ - -#include "netstack.h" -/*---------------------------------------------------------------------------*/ -void -netstack_init(void) -{ - NETSTACK_RADIO.init(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/energy-scan/project-conf.h b/examples/sensinode/energy-scan/project-conf.h deleted file mode 100644 index 91c1917e4..000000000 --- a/examples/sensinode/energy-scan/project-conf.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Project specific configuration defines for the sniffer example. - * - * We make sure that the radio driver outputs all packets in hexdump - * format. - * - * \author - * George Oikonomou - - */ - -#ifndef PROJECT_CONF_H_ -#define PROJECT_CONF_H_ - -#define NETSTACK_CONF_RDC stub_rdc_driver -#define ADC_SENSOR_CONF_ON 0 -#define LPM_CONF_MODE 0 - -#endif /* PROJECT_CONF_H_ */ diff --git a/examples/sensinode/energy-scan/stub-rdc.c b/examples/sensinode/energy-scan/stub-rdc.c deleted file mode 100644 index ed335fc70..000000000 --- a/examples/sensinode/energy-scan/stub-rdc.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Definition of a fake RDC driver to be used with passive - * examples. The code will never send packets and it will never - * push incoming packets up the stack. We do this by defining this - * driver as our RDC. We then drop everything - * - * \author - * George Oikonomou - - */ - -#include "net/mac/mac.h" -#include "net/mac/rdc.h" -/*---------------------------------------------------------------------------*/ -static void -send(mac_callback_t sent, void *ptr) -{ - if(sent) { - sent(ptr, MAC_TX_OK, 1); - } -} -/*---------------------------------------------------------------------------*/ -static void -send_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *list) -{ - if(sent) { - sent(ptr, MAC_TX_OK, 1); - } -} -/*---------------------------------------------------------------------------*/ -static void -input(void) -{ -} -/*---------------------------------------------------------------------------*/ -static int -on(void) -{ - return 1; -} -/*---------------------------------------------------------------------------*/ -static int -off(int keep_radio_on) -{ - return 1; -} -/*---------------------------------------------------------------------------*/ -static unsigned short -cca(void) -{ - return 0; -} -/*---------------------------------------------------------------------------*/ -static void -init(void) -{ -} -/*---------------------------------------------------------------------------*/ -const struct rdc_driver stub_rdc_driver = { - "stub-rdc", - init, - send, - send_list, - input, - on, - off, - cca, -}; -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/event-post/Makefile b/examples/sensinode/event-post/Makefile deleted file mode 100644 index 114de943f..000000000 --- a/examples/sensinode/event-post/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N740 - -# This example doesn't need code banking so we turn it off -#HAVE_BANKING=1 - -CONTIKI_PROJECT = event-post - -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../.. -CONTIKI_WITH_RIME = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/event-post/event-post.c b/examples/sensinode/event-post/event-post.c deleted file mode 100644 index 7a091cfa7..000000000 --- a/examples/sensinode/event-post/event-post.c +++ /dev/null @@ -1,98 +0,0 @@ -/* This file demonstrates the interaction between two processes via events. - * - * - "Sensor process": Throws an event periodically. This can be for example a - * sensor value. - * - "Print process" : Waits for events from "Sensor" and prints a message when - * an event occurs (e.g. prints the sensor value) - * - * This example is derived from the contiki code examples for the WSN430 - * (SensTools - Inria: http://senstools.gforge.inria.fr/) - * - * Author: George Oikonomou - */ - -#include "contiki.h" -//#include "dev/leds.h" -#include -#include -#include "event-post.h" - -/* This is our event type */ -static process_event_t event_data_ready; -/*---------------------------------------------------------------------------*/ -/* Declare the two processes here */ -PROCESS(sensor_process, "Sensor process"); -PROCESS(print_process, "Print process"); - -AUTOSTART_PROCESSES(&sensor_process, &print_process); -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(sensor_process, ev, data) -{ - static struct etimer timer; - static struct event_struct es; - - PROCESS_BEGIN(); - - es.s_val = SHRT_MAX - 2; - es.i_val = INT_MAX - 2; - es.l_val = LONG_MAX - 2; - es.ll_val = LONG_MAX - 2; - es.u8_val = UCHAR_MAX - 2; - es.u16_val = USHRT_MAX - 2; - es.u32_val = ULONG_MAX - 2; - - event_data_ready = process_alloc_event(); - - printf("Contiki allocated event ID %d.\r\n", event_data_ready); - - etimer_set(&timer, CLOCK_CONF_SECOND * 2); - - while(1) { - printf("Sensor process: Wait for timer event...\r\n"); - - PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); - - printf("Sensor Process: Incrementing values...\r\n"); - es.s_val++; - es.i_val++; - es.l_val++; - es.ll_val++; - es.u8_val++; - es.u16_val++; - es.u32_val++; - - printf("Sensor Process: Generating 'Data Ready' event.\r\n"); - process_post(&print_process, event_data_ready, &es); - - etimer_reset(&timer); - - } - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ -/* Implementation of "Print Process" */ -PROCESS_THREAD(print_process, ev, data) -{ - - struct event_struct *sd; - - PROCESS_BEGIN(); - - while(1) { - - PROCESS_WAIT_EVENT_UNTIL(ev == event_data_ready); - - sd = data; - printf("Print Process - Data Ready:\r\n"); - printf(" s: %d\r\n", sd->s_val); - printf(" i: %d\r\n", sd->i_val); - printf(" l: %ld\r\n", sd->l_val); - printf(" ll: %lld\r\n", sd->ll_val); - printf(" u8: %u\r\n", sd->u8_val); - printf(" u16: %u\r\n", sd->u16_val); - printf(" u32: %lu\r\n", sd->u32_val); - - } - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/event-post/event-post.h b/examples/sensinode/event-post/event-post.h deleted file mode 100644 index 650d38b4a..000000000 --- a/examples/sensinode/event-post/event-post.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * event-post.h - * Header file for the event_post example - * - * Created on: 30 Mar 2010 - * Author: George Oikonomou - */ - -#ifndef EVENT_POST_H_ -#define EVENT_POST_H_ - -struct event_struct { - short s_val; - int i_val; - long l_val; - long long ll_val; - uint8_t u8_val; - uint16_t u16_val; - uint32_t u32_val; -}; - -#endif /* EVENT_POST_H_ */ diff --git a/examples/sensinode/sensors-ipv6/Makefile b/examples/sensinode/sensors-ipv6/Makefile deleted file mode 100644 index 4332e42c9..000000000 --- a/examples/sensinode/sensors-ipv6/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N740,PROJECT_CONF_H - -# This example won't fit in flash without banking so we turn it on -HAVE_BANKING=1 - -CONTIKI_SOURCEFILES += sensors-driver.c - -CONTIKI_PROJECT = sensors-ipv6 -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../.. -CONTIKI_WITH_IPV6 = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/sensors-ipv6/project-conf.h b/examples/sensinode/sensors-ipv6/project-conf.h deleted file mode 100644 index 053f48d85..000000000 --- a/examples/sensinode/sensors-ipv6/project-conf.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Project specific configuration defines for the UDP client/server - * example. - * - * We make sure that buttons and ADC are on. We also demonstrate the - * new LPM functionality - * - * \author - * George Oikonomou - - */ - -#ifndef PROJECT_CONF_H_ -#define PROJECT_CONF_H_ - -#define BUTTON_SENSOR_CONF_ON 1 -#define ADC_SENSOR_CONF_ON 1 -#define LPM_CONF_MODE 0 -#define VIZTOOL_CONF_ON 0 - -#endif /* PROJECT_CONF_H_ */ diff --git a/examples/sensinode/sensors-ipv6/sensors-driver.c b/examples/sensinode/sensors-ipv6/sensors-driver.c deleted file mode 100644 index c3e90a13b..000000000 --- a/examples/sensinode/sensors-ipv6/sensors-driver.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * This file handles the sensor readings and float conversions - * for sensors-example. We keep this separate in order to place it - * to a higher BANK. - * - * Bankable - * - * \author - * George Oikonomou - - */ - -#include "contiki-conf.h" -#include "uip.h" /* for htons / htonl */ -#include "dev/leds.h" -#if CONTIKI_TARGET_SENSINODE -#include "dev/sensinode-sensors.h" -#include "debug.h" -#endif - -#define DEBUG 0 -#if DEBUG -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif -#include -#include - -#define SENSOR_OK 0 -#define SENSOR_ADC_OFF -1 -#define SENSOR_UNKNOWN -2 - -/* Request Bits */ -#define REQUEST_BIT_P0_GET 0x0400 -#define REQUEST_BIT_L2_SET 0x0200 -#define REQUEST_BIT_L1_SET 0x0100 -#define REQUEST_BIT_LED_GET 0x0080 -#define REQUEST_BIT_ACC 0x0040 -#define REQUEST_BIT_BAT 0x0020 -#define REQUEST_BIT_VDD 0x0010 -#define REQUEST_BIT_TEMP 0x0008 -#define REQUEST_BIT_LIGHT 0x0004 -#define REQUEST_BIT_UPTIME 0x0002 -#define REQUEST_BIT_CHIPID 0x0001 - -/*---------------------------------------------------------------------------*/ -int8_t -read_sensor(char *rs) -{ - /* Sensor Values */ - static int rv; - static struct sensors_sensor *sensor; - - /* Those 3 variables are only used for debugging */ -#if DEBUG - static float sane = 0; - static int dec; - static float frac; -#endif - uint16_t r; - uint8_t len = 0; - - sensor = sensors_find(ADC_SENSOR); - if(!sensor) { - PRINTF("ADC not found\n"); - return (SENSOR_ADC_OFF); - } - - /* Fetch the request bytes */ - memcpy(&r, rs, 2); - r = uip_ntohs(r); - PRINTF("R=%u\n", r); - - if(r & REQUEST_BIT_CHIPID) { - uint8_t chipid = CHIPID; - memcpy(rs + len, &chipid, sizeof(chipid)); - len += sizeof(chipid); - PRINTF("ChipID=0x%02x\n", chipid); - } - if(r & REQUEST_BIT_UPTIME) { - /* Uptime */ - unsigned long l; - - l = uip_htonl(clock_seconds()); - memcpy(rs + len, &l, sizeof(l)); - len += sizeof(l); - PRINTF("Uptime=%lu secs\n", uip_ntohl(l)); - } - if(r & REQUEST_BIT_LIGHT) { - rv = sensor->value(ADC_SENSOR_TYPE_LIGHT); - if(rv != -1) { -#if DEBUG - sane = (float)(rv * 0.4071); - dec = sane; - frac = sane - dec; - PRINTF(" Light=%d.%02ulux (%d)\n", dec, (unsigned int)(frac * 100), rv); -#endif - memcpy(rs + len, &rv, sizeof(rv)); - len += sizeof(rv); - } - } - if(r & REQUEST_BIT_TEMP) { - rv = sensor->value(ADC_SENSOR_TYPE_TEMP); - if(rv != -1) { -#if DEBUG - sane = ((rv * 0.61065 - 773) / 2.45); - dec = sane; - frac = sane - dec; - PRINTF(" Temp=%d.%02u C (%d)\n", dec, (unsigned int)(frac * 100), rv); -#endif - memcpy(rs + len, &rv, sizeof(rv)); - len += sizeof(rv); - } - } - if(r & (REQUEST_BIT_VDD | REQUEST_BIT_BAT)) { - /* We want VDD for both cases */ - rv = sensor->value(ADC_SENSOR_TYPE_VDD); - if(rv != -1) { -#if DEBUG - sane = rv * 3.75 / 2047; - dec = sane; - frac = sane - dec; - PRINTF("Supply=%d.%02uV (%d)\n", dec, (unsigned int)(frac * 100), rv); - /* Store rv temporarily in dec so we can use it for the battery */ - dec = rv; -#endif - memcpy(rs + len, &rv, sizeof(rv)); - len += sizeof(rv); - } - /* And then carry on with battery if needed */ - if(r & REQUEST_BIT_BAT) { - rv = sensor->value(ADC_SENSOR_TYPE_BATTERY); - if(rv != -1) { -#if DEBUG - sane = (11.25 * rv * dec) / (0x7FE002); - dec = sane; - frac = sane - dec; - PRINTF(" Batt.=%d.%02uV (%d)\n", dec, (unsigned int)(frac * 100), rv); -#endif - memcpy(rs + len, &rv, sizeof(rv)); - len += sizeof(rv); - } - } - } - if(r & REQUEST_BIT_ACC) { - rv = sensor->value(ADC_SENSOR_TYPE_ACC_X); - if(rv != -1) { -#if DEBUG - sane = ((rv * 3.75 / 2047) - 1.65) / 0.44; - dec = sane; - frac = sane - dec; - frac = (frac < 0) ? -frac : frac; - - PRINTF(" AccX="); - if(sane < 0 && dec == 0) { - PRINTF('-'); - } - PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv); -#endif - memcpy(rs + len, &rv, sizeof(rv)); - len += sizeof(rv); - } - rv = sensor->value(ADC_SENSOR_TYPE_ACC_Y); - if(rv != -1) { -#if DEBUG - sane = ((rv * 3.75 / 2047) - 1.65) / 0.44; - dec = sane; - frac = sane - dec; - frac = (frac < 0) ? -frac : frac; - PRINTF(" AccY="); - if(sane < 0 && dec == 0) { - PRINTF('-'); - } - PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv); -#endif - memcpy(rs + len, &rv, sizeof(rv)); - len += sizeof(rv); - } - rv = sensor->value(ADC_SENSOR_TYPE_ACC_Z); - if(rv != -1) { -#if DEBUG - sane = ((rv * 3.75 / 2047) - 1.65) / 0.44; - dec = sane; - frac = sane - dec; - frac = (frac < 0) ? -frac : frac; - PRINTF(" AccZ="); - if(sane < 0 && dec == 0) { - PRINTF('-'); - } - PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv); -#endif - memcpy(rs + len, &rv, sizeof(rv)); - len += sizeof(rv); - } - } - if(r & REQUEST_BIT_L1_SET) { - leds_toggle(LEDS_GREEN); - } - if(r & REQUEST_BIT_L2_SET) { - leds_toggle(LEDS_RED); - } - if(r & REQUEST_BIT_LED_GET) { - uint8_t leds = leds_get(); - memcpy(rs + len, &leds, sizeof(leds)); - len += sizeof(leds); - PRINTF(" LED 2=%u\n", leds); - } - if(r & REQUEST_BIT_P0_GET) { - uint8_t p0 = P0_3; - memcpy(rs + len, &p0, sizeof(p0)); - len += sizeof(p0); - } - return len; -} diff --git a/examples/sensinode/sensors-ipv6/sensors-ipv6.c b/examples/sensinode/sensors-ipv6/sensors-ipv6.c deleted file mode 100644 index 1b563975b..000000000 --- a/examples/sensinode/sensors-ipv6/sensors-ipv6.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Example to demonstrate-test the sensors functionality on - * sensinode/cc2430 devices. - * - * A UDP/IPv6 process waits for requests from a monitoring station - * and responds with sensor values. - * - * The message exchange is based on a custom protocol. - * Check sensors-driver.c for protocol details. - * - * \author - * George Oikonomou - - */ - -#include "contiki.h" -#include "contiki-lib.h" -#include "contiki-net.h" - -#include - -#define DEBUG DEBUG_NONE -#include "net/ip/uip-debug.h" -#include "dev/watchdog.h" -#include "dev/leds.h" -#include "net/rpl/rpl.h" -#include - -#if CONTIKI_TARGET_SENSINODE -#include "debug.h" -#include "dev/sensinode-sensors.h" -#else -#define putstring(s) -#endif - -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) - -#define MAX_PAYLOAD_LEN 120 - -static struct uip_udp_conn *server_conn; -static char buf[MAX_PAYLOAD_LEN]; -static uint16_t len; - -#define SERVER_PORT 60000 - -#define SENSOR_OK 0 -#define SENSOR_ADC_OFF 1 -#define SENSOR_UNKNOWN 2 - -int8_t read_sensor(char *rs); -/*---------------------------------------------------------------------------*/ -extern const struct sensors_sensor adc_sensor; -/*---------------------------------------------------------------------------*/ -PROCESS(udp_server_process, "UDP server process"); -AUTOSTART_PROCESSES(&udp_server_process); -/*---------------------------------------------------------------------------*/ -static void -tcpip_handler(void) -{ - memset(buf, 0, MAX_PAYLOAD_LEN); - - if(uip_newdata()) { - len = uip_datalen(); - memcpy(buf, uip_appdata, len); - PRINTF("%u bytes from [", len); - PRINT6ADDR(&UIP_IP_BUF->srcipaddr); - PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport)); - len = read_sensor(buf); - if(len) { - server_conn->rport = UIP_UDP_BUF->srcport; - uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr); - uip_udp_packet_send(server_conn, buf, len); - PRINTF("Sent %u bytes\n", len); - } - - /* Restore server connection to allow data from any node */ - uip_create_unspecified(&server_conn->ripaddr); - server_conn->rport = 0; - } - return; -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(udp_server_process, ev, data) -{ -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - static struct sensors_sensor *b1; - static struct sensors_sensor *b2; -#endif - - PROCESS_BEGIN(); - putstring("Starting UDP server\n"); - -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - putstring("Button X: Toggle LED X\n"); -#endif - - server_conn = udp_new(NULL, UIP_HTONS(0), NULL); - udp_bind(server_conn, UIP_HTONS(SERVER_PORT)); - -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - b1 = sensors_find(BUTTON_1_SENSOR); - b2 = sensors_find(BUTTON_2_SENSOR); -#endif - - while(1) { - PROCESS_YIELD(); - if(ev == tcpip_event) { - tcpip_handler(); -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - } else if(ev == sensors_event && data != NULL) { - if(data == b1) { - leds_toggle(LEDS_GREEN); - } else if(data == b2) { - leds_toggle(LEDS_RED); - } -#endif /* (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) */ - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/sensors/Makefile b/examples/sensinode/sensors/Makefile deleted file mode 100644 index 8502ff884..000000000 --- a/examples/sensinode/sensors/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N740 - -# This example doesn't need code banking so we turn it off -#HAVE_BANKING=1 - -CONTIKI_PROJECT = sensors-example - -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../.. -CONTIKI_WITH_RIME = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/sensors/sensors-example.c b/examples/sensinode/sensors/sensors-example.c deleted file mode 100644 index 4df6a7ac3..000000000 --- a/examples/sensinode/sensors/sensors-example.c +++ /dev/null @@ -1,376 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Example to demonstrate-test the sensors functionality on - * sensinode/cc2430 devices. - * - * B1 turns L2 on and off. - * B2 reboots the node via the watchdog. - * - * The node takes readings from the various sensors every x seconds and - * prints out the results. - * - * We use floats here to translate the AD conversion results to - * meaningful values. However, our printf does not have %f support so - * we use an ugly hack to print out the value by extracting the integral - * part and then the fractional part. Don't try this at home. - * - * Temperature: - * Math is correct, the sensor needs calibration per device. - * I currently use default values for the math which may result in - * very incorrect values in degrees C. - * See TI Design Note DN102 about the offset calibration. - * - * Supply Voltage (VDD) and Battery Sensor: - * For VDD, math is correct, conversion is correct. See DN101 for details if - * interested. - * Battery reports different values when we run it many times - * in succession. The cause is unknown. - * I am fairly confident that I have captured the connections on the - * device correctly. I am however accepting input/feedback - * - * Light Sensor (Vishay Semiconductors TEPT4400): - * I am uncertain about the math. This needs testing. All I know is - * that 600lux = 0.9V and that the relation is linear. See inline for - * more details - * - * Accelerometer (Freescale Semiconductor MMA7340L): - * Math is correct but the sensor needs calibration. I've not - * attempted one cause the reported values differ per device. - * Place the N740 with the logo facing down to get 1g on the Z axis. - * Place the antenna side facing down to get 1g on the Y axis - * Place the N740 on its longer side while looking at the antenna and - * the D connector. Antenna on the bottom, D connector on the top. - * This should give you 1g on the X axis. - * - * Make sure you enable/disable things in contiki-conf.h - * - * \author - * George Oikonomou - - */ - -#include "contiki.h" -#include "contiki-conf.h" -#include "net/rime/rime.h" -#include "dev/leds.h" -#include "dev/watchdog.h" -#include "lib/random.h" - -#if CONTIKI_TARGET_SENSINODE -#include "dev/sensinode-sensors.h" -#else -#include "lib/sensors.h" -#endif - -#define DEBUG 1 -#if DEBUG -#include -#if CONTIKI_TARGET_SENSINODE -#include "debug.h" -#endif /* CONTIKI_TARGET_SENSINODE */ -#define PRINTF(...) printf(__VA_ARGS__) -#else /* DEBUG */ -/* We overwrite (read as annihilate) all output functions here */ -#define PRINTF(...) -#define putstring(...) -#define putchar(...) -#endif /* DEBUG */ - - -#define SEND_BATTERY_INFO 0 -#if SEND_BATTERY_INFO -#include "sensors-example.h" -static void -bc_rx(struct broadcast_conn *c, const linkaddr_t *from) -{ - return; -} - -static const struct broadcast_callbacks bc_cb = { bc_rx }; -static struct broadcast_conn bc_con; -#endif - -#if BUTTON_SENSOR_ON -extern const struct sensors_sensor button_1_sensor, button_2_sensor; -#endif - -/*---------------------------------------------------------------------------*/ -PROCESS(sensors_test_process, "Sensor Test Process"); -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) -PROCESS(buttons_test_process, "Button Test Process"); -AUTOSTART_PROCESSES(&sensors_test_process, &buttons_test_process); -#else -AUTOSTART_PROCESSES(&sensors_test_process); -#endif -/*---------------------------------------------------------------------------*/ -#if BUTTON_SENSOR_ON -PROCESS_THREAD(buttons_test_process, ev, data) -{ - struct sensors_sensor *sensor; - - PROCESS_BEGIN(); - - while(1) { - - PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event); - - /* If we woke up after a sensor event, inform what happened */ - sensor = (struct sensors_sensor *)data; - if(sensor == &button_1_sensor) { - leds_toggle(LEDS_GREEN); - } else if(sensor == &button_2_sensor) { - watchdog_reboot(); - } - } - - PROCESS_END(); -} -#endif -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(sensors_test_process, ev, data) -{ - static struct etimer et; -#if SEND_BATTERY_INFO - /* Node Time */ - static struct sensor_data sd; -#endif - - /* Sensor Values */ - static int rv; - static struct sensors_sensor *sensor; - static float sane = 0; - static int dec; - static float frac; - -#if SEND_BATTERY_INFO - PROCESS_EXITHANDLER(broadcast_close(&bc_con);) -#endif - - PROCESS_BEGIN(); - - putstring("========================\n"); - putstring("Starting Sensor Example.\n"); - putstring("========================\n"); - -#if SEND_BATTERY_INFO - broadcast_open(&bc_con, BATTERY_RIME_CHANNEL, &bc_cb); -#endif - - /* Set an etimer. We take sensor readings when it expires and reset it. */ - etimer_set(&et, CLOCK_SECOND * 2); - - while(1) { - - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - - /* - * Request some ADC conversions - * Return value -1 means sensor not available or turned off in conf - */ - sensor = sensors_find(ADC_SENSOR); - if(sensor) { - putstring("------------------\n"); - leds_on(LEDS_RED); - /* - * Temperature: - * Using 1.25V ref. voltage (1250mV). - * Typical Voltage at 0°C : 743 mV - * Typical Co-efficient : 2.45 mV/°C - * Offset at 25°C : 30 (this varies and needs calibration) - * - * Thus, at 12bit resolution: - * - * ADC x 1250 / 2047 - (743 + 30) 0.61065 x ADC - 773 - * T = ------------------------------ ~= ------------------- °C - * 2.45 2.45 - */ - rv = sensor->value(ADC_SENSOR_TYPE_TEMP); - if(rv != -1) { - sane = ((rv * 0.61065 - 773) / 2.45); - dec = sane; - frac = sane - dec; - PRINTF(" Temp=%d.%02u C (%d)\n", dec, (unsigned int)(frac * 100), - rv); - } - /* - * Accelerometer: Freescale Semiconductor MMA7340L - * Using 1.25V ref. voltage. - * Sensitivity: 0.44 mV/g in ±3g mode. - * 0.1175 mV/g in ±11g mode. - * Typical 0g Vout = 1.65V (both modes, Vdd=3.3V, T=25°C) - * ADC Input Voltage is 1/3 Accelerometer Output Voltage - * - * +3g -> 2.97V Acc Out -> 0.9900V ADC Input -> 1621 - * +1g -> 2.09V Acc Out -> 0.6967V ADC Input -> 1141 - * 0g -> 1.65V Acc Out -> 0.5500V ADC Input -> 901 - * -1g -> 1.21V Acc Out -> 0.4033V ADC Input -> 660 - * -3g -> 0.33V Acc Out -> 0.1100V ADC Input -> 180 - * - * Thus, at 12bit resolution, ±3g mode: - * ADC x 1.25 x 3 - * Vout = -------------- V - * 2047 - * - * Vout - 0g Vout - 1.65 - * Acc = ----------- = ----------- g - * Sensitivity 0.44 - * - * Similar calc. for ±11g with 0.1175V increments - * - * This is only valid if you set ACC_SENSOR_CONF_GSEL 0 in contiki-conf.h - */ - rv = sensor->value(ADC_SENSOR_TYPE_ACC_X); - if(rv != -1) { - sane = ((rv * 3.75 / 2047) - 1.65) / 0.44; - dec = sane; - frac = sane - dec; - frac = (frac < 0) ? -frac : frac; - - /* - * This will fail for numbers like -0.xyz (since there is no such thing - * as -0. We manually add a minus sign in the printout if sane is neg - * and dec is 0. - * This is the wrong way to do it... - */ - putstring(" AccX="); - if(sane < 0 && dec == 0) { - putchar('-'); - } - PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv); - } - rv = sensor->value(ADC_SENSOR_TYPE_ACC_Y); - if(rv != -1) { - sane = ((rv * 3.75 / 2047) - 1.65) / 0.44; - dec = sane; - frac = sane - dec; - frac = (frac < 0) ? -frac : frac; - putstring(" AccY="); - if(sane < 0 && dec == 0) { - putchar('-'); - } - PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv); - } - rv = sensor->value(ADC_SENSOR_TYPE_ACC_Z); - if(rv != -1) { - sane = ((rv * 3.75 / 2047) - 1.65) / 0.44; - dec = sane; - frac = sane - dec; - frac = (frac < 0) ? -frac : frac; - putstring(" AccZ="); - if(sane < 0 && dec == 0) { - putchar('-'); - } - PRINTF("%d.%02ug (%d)\n", dec, (unsigned int)(frac * 100), rv); - } - /* - * Light: Vishay Semiconductors TEPT4400 - * Using 1.25V ref. voltage. - * For 600 Lux illuminance, the sensor outputs 1mA current (0.9V ADC In) - * 600 lux = 1mA output => 1473 ADC value at 12 bit resolution) - * - * Thus, at 12bit resolution: - * 600 x 1.25 x ADC - * Lux = ---------------- ~= ADC * 0.4071 - * 2047 x 0.9 - */ - rv = sensor->value(ADC_SENSOR_TYPE_LIGHT); - if(rv != -1) { - sane = (float)(rv * 0.4071); - dec = sane; - frac = sane - dec; - PRINTF(" Light=%d.%02ulux (%d)\n", dec, (unsigned int)(frac * 100), - rv); - } - /* - * Power Supply Voltage. - * Using 1.25V ref. voltage. - * AD Conversion on VDD/3 - * - * Thus, at 12bit resolution: - * - * ADC x 1.25 x 3 - * Supply = -------------- V - * 2047 - */ - rv = sensor->value(ADC_SENSOR_TYPE_VDD); -#if SEND_BATTERY_INFO - sd.vdd = rv; -#endif - if(rv != -1) { - sane = rv * 3.75 / 2047; - dec = sane; - frac = sane - dec; - PRINTF("Supply=%d.%02uV (%d)\n", dec, (unsigned int)(frac * 100), rv); - /* Store rv temporarily in dec so we can use it for the battery */ - dec = rv; - } - /* - * Battery Voltage - Only 2/3 of the actual voltage reach the ADC input - * Using 1.25V ref. voltage would result in 2047 AD conversions all the - * time since ADC-in would be gt 1.25. We thus use AVDD_SOC as ref. - * - * Thus, at 12bit resolution (assuming VDD is 3.3V): - * - * ADC x 3.3 x 3 ADC x 4.95 - * Battery = ------------- = ---------- V - * 2047 x 2 2047 - * - * Replacing the 3.3V with an ADC reading of the actual VDD would yield - * better accuracy. See monitor-node.c for an example. - * - * 3 x ADC x VDD x 3.75 ADC x VDD x 11.25 - * Battery = -------------------- = ----------------- V - * 2 x 2047 x 2047 0x7FE002 - * - */ - rv = sensor->value(ADC_SENSOR_TYPE_BATTERY); - if(rv != -1) { - /* Instead of hard-coding 3.3 here, use the latest VDD (stored in dec) - * (slightly inaccurate still, but better than crude 3.3) */ - sane = (11.25 * rv * dec) / (0x7FE002); - dec = sane; - frac = sane - dec; - PRINTF(" Batt.=%d.%02uV (%d)\n", dec, (unsigned int)(frac * 100), rv); -#if SEND_BATTERY_INFO - sd.bat = rv; - packetbuf_copyfrom(&sd, sizeof(sd)); - broadcast_send(&bc_con); -#endif - } - leds_off(LEDS_RED); - } - etimer_reset(&et); - } - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/sensors/sensors-example.h b/examples/sensinode/sensors/sensors-example.h deleted file mode 100644 index 432d25073..000000000 --- a/examples/sensinode/sensors/sensors-example.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Header file for the sensors example. Must be included by the - * sensing node as well as the monitor node. - * - * \author - * George Oikonomou - - */ - -#ifndef SENSORSTEST_H_ -#define SENSORSTEST_H_ - -#define BATTERY_RIME_CHANNEL 222 - -/* This is what our PDU looks like */ -struct sensor_data { - int vdd; - int bat; -}; - - -#endif /* SENSORSTEST_H_ */ diff --git a/examples/sensinode/serial-flash/Makefile b/examples/sensinode/serial-flash/Makefile deleted file mode 100644 index 9e80a9c6d..000000000 --- a/examples/sensinode/serial-flash/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N740 - -CONTIKI_PROJECT = flash - -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../.. -CONTIKI_WITH_RIME = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/serial-flash/flash.c b/examples/sensinode/serial-flash/flash.c deleted file mode 100644 index 4ac6048c9..000000000 --- a/examples/sensinode/serial-flash/flash.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * - * Example demonstrating the flash memory functionality on - * sensinode N740s - * - * \author - * George Oikonomou - - */ - -#include "contiki.h" -#include "dev/leds.h" -#include "cc2430_sfr.h" -#include "8051def.h" -#include "dev/m25p16.h" -#include "dev/n740.h" - -#define DEBUG 1 -#if DEBUG -#include -#include "debug.h" -#define PRINTF(...) printf(__VA_ARGS__) -#define PUTBIN(b) putbin(b) -#else -#define PRINTF(...) -#define PUTBIN(b) -#endif - -static struct m25p16_rdid id; - -#define USE_SECTOR 0x10 -#define MAX_READ_CHUNK 10 -static uint8_t r_addr[3]; /* Read address: {USE_SECTOR, 0, 0} */ -static uint8_t d_buf[MAX_READ_CHUNK]; -static uint8_t rv; -static uint8_t counter; -/*---------------------------------------------------------------------------*/ -PROCESS(serial_flash_process, "Serial Flash example"); -AUTOSTART_PROCESSES(&serial_flash_process); -/*---------------------------------------------------------------------------*/ -static void -rdsr() -{ - rv = 0; - - n740_analog_deactivate(); - rv = m25p16_rdsr(); - n740_analog_activate(); - - PRINTF("RDSR: "); - putbin(rv); - PRINTF("\n"); -} -/*---------------------------------------------------------------------------*/ -static void -rdid() -{ - uint8_t i; - memset(&id, 0, sizeof(struct m25p16_rdid)); - - n740_analog_deactivate(); - m25p16_rdid(&id); - n740_analog_activate(); - - PRINTF("RDID: 0x%02x\n", id.man_id); - PRINTF("Type: 0x%02x\n", id.mem_type); - PRINTF("Size: 0x%02x\n", id.mem_size); - PRINTF("ULen: 0x%02x\n", id.uid_len); - PRINTF(" UID:"); - for(i = 0; i < id.uid_len; i++) { - PRINTF(" %02x", id.uid[i]); - } - PRINTF("\n"); -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(serial_flash_process, ev, data) -{ - static struct etimer et; - uint8_t i; - - PROCESS_BEGIN(); - - PRINTF("Start\n"); - - memset(r_addr, 0, 3); - r_addr[0] = USE_SECTOR; - counter = 1; - - while(1) { - - /* Delay */ - etimer_set(&et, CLOCK_SECOND * 2); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - - leds_on(LEDS_GREEN); - - if(counter == 0) { - n740_analog_deactivate(); - rv = m25p16_rdsr(); - n740_analog_activate(); - /* If counter==0, we started Bulk Erasing earlier. Check if we still are */ - if(rv & M25P16_SR_WIP) { - PRINTF("Yield [%02x]\n", rv); - } else { - counter = 1; - } - } - if(counter) { - /* - * Take us out of Deep Power Down - On first power-on, the device will - * go to stand by mode (which is not DP). However, we drop to DP at the - * end of every loop. RES must be 0x14. This is the old style signature - * and is only still there for backward compatibility. - */ - n740_analog_deactivate(); - rv = m25p16_res_res(); - n740_analog_activate(); - - PRINTF(" RES: 0x%02x\n", rv); - - n740_analog_deactivate(); - rv = M25P16_WIP(); - n740_analog_activate(); - - PRINTF("========\n"); - memset(d_buf, 0, MAX_READ_CHUNK); - - - /* - * Read Device ID: Return values must be: - * man_id: 0x20 (Numonyx) - * mem_type: 0x20 - * mem_size: 0x15 (2 ^ 0x15 bytes = 2MB) - * uid_len: number of bytes in UID - * uid: Either all zeroes or a customized factory data content - * */ - rdid(); - - /* Check the value of our Status Register (SR) */ - rdsr(); - - /* Enable Write: Set Bit 1 in the SR to 1 (bit WEL) */ - PRINTF("WREN\n"); - n740_analog_deactivate(); - m25p16_wren(); - n740_analog_activate(); - - /* Confirm: SR & 0x02 must be 1 */ - rdsr(); - - /* Disable the WEL bit */ - PRINTF("WRDI\n"); - n740_analog_deactivate(); - m25p16_wrdi(); - n740_analog_activate(); - - /* Confirm: SR & 0x02 must be 0 */ - rdsr(); - - /* Write something to the SR. We don't need to explicitly set WEL, wrsr() - * will do it for us. When the cycle ends, WEL will go low */ - PRINTF("WRSR\n"); - n740_analog_deactivate(); - - /* For instance, let's protect sector 31 (that's the highest one) */ - m25p16_wrsr(M25P16_SR_BP0); - - /* - * While this is running, WEL should remain high and WIP (bit 0) should - * also be high. When this ends, WIP and WEL will go low. - * - * While the write is in ongoing, we can still read the SR to check the - * cycle's progress - */ - while(M25P16_WIP()); - - n740_analog_activate(); - - /* Confirm: SR & 0x02 must be 0 */ - rdsr(); - - /* Read MAX_READ_CHUNK bytes from Page 0x000000 */ - memset(d_buf, 0, MAX_READ_CHUNK); - n740_analog_deactivate(); - m25p16_read(r_addr, d_buf, MAX_READ_CHUNK); - n740_analog_activate(); - - PRINTF("READ:"); - for(i = 0; i < MAX_READ_CHUNK; i++) { - PRINTF(" %02x", d_buf[i]); - } - PRINTF("\n"); - - /* Write MAX_READ_CHUNK bytes to the same Page */ - PRINTF("WRITE\n"); - for(i = 0; i < MAX_READ_CHUNK; i++) { - d_buf[i] = i; - } - n740_analog_deactivate(); - - /* We don't need to wren() explicitly, pp() will do that for us */ - m25p16_pp(r_addr, d_buf, MAX_READ_CHUNK); - - /* Wait for the cycle */ - while(M25P16_WIP()); - - /* Trash our data buffer */ - memset(d_buf, 0, MAX_READ_CHUNK); - - PRINTF("ERASE\n"); - n740_analog_deactivate(); - - /* Bulk erase every 4 loops, sector erase otherwise */ - - /* Bulk Erase: This takes a few seconds so we can't really block on it. - * It'd be a bad thing to do and the watchdog would bark anyway. - * Bulk Erase will only be accepted if all SR_BP[2:0] == 0 */ - if((counter % 4) == 0) { - m25p16_wrsr(0); - while(M25P16_WIP()); - m25p16_be(); - counter = 0; - } else { - m25p16_se(USE_SECTOR); - while(M25P16_WIP()); - /* Drop to Deep Power Down */ - m25p16_dp(); - counter++; - } - n740_analog_activate(); - } - leds_off(LEDS_GREEN); - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/sniffer/Makefile b/examples/sensinode/sniffer/Makefile deleted file mode 100644 index 5170c55b1..000000000 --- a/examples/sensinode/sniffer/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N601,PROJECT_CONF_H - -PROJECT_SOURCEFILES += stub-rdc.c - -CONTIKI_PROJECT = sniffer - -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../.. -CONTIKI_WITH_RIME = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/sniffer/README.md b/examples/sensinode/sniffer/README.md deleted file mode 100644 index dd3926f0a..000000000 --- a/examples/sensinode/sniffer/README.md +++ /dev/null @@ -1,15 +0,0 @@ -A very simple sniffer for sensinode devices. -============================================ - -The cc2430 RF driver supports outputting all captured packets in hexdump -format. We turn this on, and turn everything else off. We use a stub RDC driver -to make sure no incoming packet ever goes up the stack and no packet is ever -sent out. - -We only initialise the radio driver instead of the entire stack by over-riding -the default netstack.c with the one in this directory. - -You can then pipe the sniffer's output to the n601-cap util, which will convert -the hexdumps to pcap format, which can in turn be piped to wireshark. This is -handy if we want live capture of the lowpan traffic from wireshark. See the -README in n601-cap for more details diff --git a/examples/sensinode/sniffer/netstack.c b/examples/sensinode/sniffer/netstack.c deleted file mode 100644 index d59acc3fe..000000000 --- a/examples/sensinode/sniffer/netstack.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Stub file overriding core/net/netstack.c. What we want to achieve - * here is call netstack_init from main without initialising the RDC, - * MAC and Network layers. It will just turn on the radio instead. - * - * \author - * George Oikonomou - - */ - -#include "netstack.h" -/*---------------------------------------------------------------------------*/ -void -netstack_init(void) -{ - NETSTACK_RADIO.init(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/sniffer/project-conf.h b/examples/sensinode/sniffer/project-conf.h deleted file mode 100644 index 3ed5ec99e..000000000 --- a/examples/sensinode/sniffer/project-conf.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Project specific configuration defines for the sniffer example. - * - * We make sure that the radio driver outputs all packets in hexdump - * format. - * - * \author - * George Oikonomou - - */ - -#ifndef PROJECT_CONF_H_ -#define PROJECT_CONF_H_ - -#define CC2430_RF_CONF_HEXDUMP 1 -#define CC2430_RF_CONF_AUTOACK 0 -#define NETSTACK_CONF_RDC stub_rdc_driver -#define ADC_SENSOR_CONF_ON 0 -#define LPM_CONF_MODE 0 - -#endif /* PROJECT_CONF_H_ */ diff --git a/examples/sensinode/sniffer/sniffer.c b/examples/sensinode/sniffer/sniffer.c deleted file mode 100644 index 74d24588e..000000000 --- a/examples/sensinode/sniffer/sniffer.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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" -#include "cc2430_sfr.h" - -#define DEBUG DEBUG_NONE -#include "net/ip/uip-debug.h" - -/*---------------------------------------------------------------------------*/ -PROCESS(sniffer_process, "Sniffer process"); -AUTOSTART_PROCESSES(&sniffer_process); -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(sniffer_process, ev, data) -{ - - PROCESS_BEGIN(); - - PRINTF("Sniffer started\n"); - - /* Turn off cc2430 Address Recognition - We need to accept all frames */ - MDMCTRL0H &= ~0x08; - - PROCESS_EXIT(); - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/sniffer/stub-rdc.c b/examples/sensinode/sniffer/stub-rdc.c deleted file mode 100644 index a4db0710d..000000000 --- a/examples/sensinode/sniffer/stub-rdc.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Definition of a fake RDC driver to be used with passive - * examples. The sniffer will never send packets and it will never - * push incoming packets up the stack. We do this by defining this - * driver as our RDC. We then drop everything - * - * \author - * George Oikonomou - - */ - -#include "net/mac/mac.h" -#include "net/mac/rdc.h" -/*---------------------------------------------------------------------------*/ -static void -send(mac_callback_t sent, void *ptr) -{ - if(sent) { - sent(ptr, MAC_TX_OK, 1); - } -} -/*---------------------------------------------------------------------------*/ -static void -send_list(mac_callback_t sent, void *ptr, struct rdc_buf_list *list) -{ - if(sent) { - sent(ptr, MAC_TX_OK, 1); - } -} -/*---------------------------------------------------------------------------*/ -static void -input(void) -{ -} -/*---------------------------------------------------------------------------*/ -static int -on(void) -{ - return 1; -} -/*---------------------------------------------------------------------------*/ -static int -off(int keep_radio_on) -{ - return keep_radio_on; -} -/*---------------------------------------------------------------------------*/ -static unsigned short -cca(void) -{ - return 0; -} -/*---------------------------------------------------------------------------*/ -static void -init(void) -{ -} -/*---------------------------------------------------------------------------*/ -const struct rdc_driver stub_rdc_driver = { - "stub-rdc", - init, - send, - send_list, - input, - on, - off, - cca, -}; -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/timer-test.c b/examples/sensinode/timer-test.c deleted file mode 100644 index df954bccc..000000000 --- a/examples/sensinode/timer-test.c +++ /dev/null @@ -1,139 +0,0 @@ -/** - * \file - * Tests related to clocks and timers - * This is based on clock_test.c from the original sensinode port - * - * \author - * Zach Shelby (Original) - * George Oikonomou - (rtimer code) - * - */ - -#include "contiki.h" -#include "sys/clock.h" -#include "sys/rtimer.h" -#include "dev/leds.h" - -#include -/*---------------------------------------------------------------------------*/ -#define TEST_CLOCK_DELAY_USEC 1 -#define TEST_RTIMER 1 -#define TEST_ETIMER 1 -#define TEST_CLOCK_SECONDS 1 -/*---------------------------------------------------------------------------*/ -static struct etimer et; - -#if TEST_CLOCK_DELAY_USEC -static rtimer_clock_t start_count, end_count, diff; -#endif - -#if TEST_CLOCK_SECONDS -static unsigned long sec; -#endif - -#if TEST_ETIMER -static clock_time_t count; -#endif - -#if TEST_RTIMER -static struct rtimer rt; -rtimer_clock_t rt_now, rt_for; -static clock_time_t ct; -#endif - -static uint8_t i; -/*---------------------------------------------------------------------------*/ -PROCESS(clock_test_process, "Clock test process"); -AUTOSTART_PROCESSES(&clock_test_process); -/*---------------------------------------------------------------------------*/ -#if TEST_RTIMER -void -rt_callback(struct rtimer *t, void *ptr) -{ - rt_now = RTIMER_NOW(); - ct = clock_time(); - printf("Task called at %u (clock = %u)\n", rt_now, ct); -} -#endif -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(clock_test_process, ev, data) -{ - - PROCESS_BEGIN(); - - etimer_set(&et, 2 * CLOCK_SECOND); - - PROCESS_YIELD(); - -#if TEST_CLOCK_DELAY_USEC - printf("clock_delay_usec test, (10,000 x i) usec:\n"); - i = 1; - while(i < 7) { - start_count = RTIMER_NOW(); - clock_delay_usec(10000 * i); - end_count = RTIMER_NOW(); - diff = end_count - start_count; - printf("Requested: %u usec, Real: %u rtimer ticks = ~%u us\n", - 10000 * i, diff, diff * 64); - i++; - } -#endif - -#if TEST_RTIMER - printf("Rtimer Test, 1 sec (%u rtimer ticks):\n", RTIMER_SECOND); - i = 0; - while(i < 5) { - etimer_set(&et, 2 * CLOCK_SECOND); - printf("=======================\n"); - ct = clock_time(); - rt_now = RTIMER_NOW(); - rt_for = rt_now + RTIMER_SECOND; - printf("Now=%u (clock = %u) - For=%u\n", rt_now, ct, rt_for); - if(rtimer_set(&rt, rt_for, 1, (rtimer_callback_t) rt_callback, NULL) != - RTIMER_OK) { - printf("Error setting\n"); - } - - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - i++; - } -#endif - -#if TEST_ETIMER - printf("Clock tick and etimer test, 1 sec (%u clock ticks):\n", - CLOCK_SECOND); - i = 0; - while(i < 10) { - etimer_set(&et, CLOCK_SECOND); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - etimer_reset(&et); - - count = clock_time(); - printf("%u ticks\n", count); - - leds_toggle(LEDS_RED); - i++; - } -#endif - -#if TEST_CLOCK_SECONDS - printf("Clock seconds test (5s):\n"); - i = 0; - while(i < 10) { - etimer_set(&et, 5 * CLOCK_SECOND); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - etimer_reset(&et); - - sec = clock_seconds(); - printf("%lu seconds\n", sec); - - leds_toggle(LEDS_GREEN); - i++; - } -#endif - - printf("Done!\n"); - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/udp-ipv6/Makefile b/examples/sensinode/udp-ipv6/Makefile deleted file mode 100644 index ae0bfad0f..000000000 --- a/examples/sensinode/udp-ipv6/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -ifndef TARGET -TARGET=sensinode -endif - -# Make absolutely certain that you specify your device here -DEFINES+=MODEL_N740,PROJECT_CONF_H - -# This example won't fit in flash without banking so we turn it on -HAVE_BANKING=1 - -CONTIKI_SOURCEFILES += ping6.c - -CONTIKI_PROJECT = client server -all: $(CONTIKI_PROJECT) - -CONTIKI = ../../.. -CONTIKI_WITH_IPV6 = 1 -# needed for rimestats -CONTIKI_WITH_RIME = 1 -include $(CONTIKI)/Makefile.include diff --git a/examples/sensinode/udp-ipv6/client.c b/examples/sensinode/udp-ipv6/client.c deleted file mode 100644 index 8308d13a8..000000000 --- a/examples/sensinode/udp-ipv6/client.c +++ /dev/null @@ -1,213 +0,0 @@ -/* - * 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" -#include "contiki-lib.h" -#include "contiki-net.h" - -#include -#include "dev/leds.h" - -#if CONTIKI_TARGET_SENSINODE -#include "dev/sensinode-sensors.h" -#include "debug.h" -#else -#define putstring(s) -#define puthex(s) -#define putchar(s) -#endif - -#define DEBUG DEBUG_NONE -#include "net/ip/uip-debug.h" - -#define SEND_INTERVAL 2 * CLOCK_SECOND -#define MAX_PAYLOAD_LEN 40 - -static char buf[MAX_PAYLOAD_LEN]; - -/* Our destinations and udp conns. One link-local and one global */ -#define LOCAL_CONN_PORT 3001 -static struct uip_udp_conn *l_conn; -#if UIP_CONF_ROUTER -#define GLOBAL_CONN_PORT 3002 -static struct uip_udp_conn *g_conn; -#endif - -/*---------------------------------------------------------------------------*/ -PROCESS(udp_client_process, "UDP client process"); -#if BUTTON_SENSOR_ON -PROCESS_NAME(ping6_process); -AUTOSTART_PROCESSES(&udp_client_process, &ping6_process); -#else -AUTOSTART_PROCESSES(&udp_client_process); -#endif -/*---------------------------------------------------------------------------*/ -static void -tcpip_handler(void) -{ - leds_on(LEDS_GREEN); - if(uip_newdata()) { - putstring("0x"); - puthex(uip_datalen()); - putstring(" bytes response=0x"); - puthex((*(uint16_t *) uip_appdata) >> 8); - puthex((*(uint16_t *) uip_appdata) & 0xFF); - putchar('\n'); - } - leds_off(LEDS_GREEN); - return; -} -/*---------------------------------------------------------------------------*/ -static void -timeout_handler(void) -{ - static int seq_id; - struct uip_udp_conn *this_conn; - - leds_on(LEDS_RED); - memset(buf, 0, MAX_PAYLOAD_LEN); - seq_id++; - -#if UIP_CONF_ROUTER - /* evens / odds */ - if(seq_id & 0x01) { - this_conn = l_conn; - } else { - this_conn = g_conn; - } -#else - this_conn = l_conn; -#endif - - PRINTF("Client to: "); - PRINT6ADDR(&this_conn->ripaddr); - - memcpy(buf, &seq_id, sizeof(seq_id)); - - PRINTF(" Remote Port %u,", UIP_HTONS(this_conn->rport)); - PRINTF(" (msg=0x%04x), %u bytes\n", *(uint16_t *) buf, sizeof(seq_id)); - -#if SEND_TOO_LARGE_PACKET_TO_TEST_FRAGMENTATION - uip_udp_packet_send(this_conn, buf, UIP_APPDATA_SIZE); -#else /* SEND_TOO_LARGE_PACKET_TO_TEST_FRAGMENTATION */ - uip_udp_packet_send(this_conn, buf, sizeof(seq_id)); -#endif /* SEND_TOO_LARGE_PACKET_TO_TEST_FRAGMENTATION */ - leds_off(LEDS_RED); -} -/*---------------------------------------------------------------------------*/ -static void -print_local_addresses(void) -{ - int i; - uint8_t state; - - PRINTF("Client IPv6 addresses:\n"); - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - state = uip_ds6_if.addr_list[i].state; - if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state - == ADDR_PREFERRED)) { - PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); - if(state == ADDR_TENTATIVE) { - uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; - } - PRINTF(" state: %u.\n", uip_ds6_if.addr_list[i].state); - } - } - return; -} -/*---------------------------------------------------------------------------*/ -#if UIP_CONF_ROUTER -static void -set_global_address(void) -{ - uip_ipaddr_t ipaddr; - - uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0); - uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); - uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); -} -#endif /* UIP_CONF_ROUTER */ -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(udp_client_process, ev, data) -{ - static struct etimer et; - uip_ipaddr_t ipaddr; - - PROCESS_BEGIN(); - PRINTF("UDP client process started\n"); - -#if UIP_CONF_ROUTER - set_global_address(); -#endif - - print_local_addresses(); - - uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0x0215, 0x2000, 0x0002, 0x0302); - /* new connection with remote host */ - l_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL); - if(!l_conn) { - PRINTF("udp_new l_conn error.\n"); - } - udp_bind(l_conn, UIP_HTONS(LOCAL_CONN_PORT)); - - PRINTF("Link-Local connection with "); - PRINT6ADDR(&l_conn->ripaddr); - PRINTF(" local/remote port %u/%u\n", - UIP_HTONS(l_conn->lport), UIP_HTONS(l_conn->rport)); - -#if UIP_CONF_ROUTER - uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0x0215, 0x2000, 0x0002, - 0x0302); - g_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL); - if(!g_conn) { - PRINTF("udp_new g_conn error.\n"); - } - udp_bind(g_conn, UIP_HTONS(GLOBAL_CONN_PORT)); - - PRINTF("Global connection with "); - PRINT6ADDR(&g_conn->ripaddr); - PRINTF(" local/remote port %u/%u\n", - UIP_HTONS(g_conn->lport), UIP_HTONS(g_conn->rport)); -#endif - - etimer_set(&et, SEND_INTERVAL); - - while(1) { - PROCESS_YIELD(); - if(etimer_expired(&et)) { - timeout_handler(); - etimer_restart(&et); - } else if(ev == tcpip_event) { - tcpip_handler(); - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/udp-ipv6/ping6.c b/examples/sensinode/udp-ipv6/ping6.c deleted file mode 100644 index 1acccd371..000000000 --- a/examples/sensinode/udp-ipv6/ping6.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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" -#include "contiki-lib.h" -#include "contiki-net.h" -#include -#include - -#if CONTIKI_TARGET_SENSINODE -#include "dev/sensinode-sensors.h" -#include "debug.h" -#endif - -#define DEBUG DEBUG_NONE -#include "net/ip/uip-debug.h" - -#define PING6_NB 5 -#define PING6_DATALEN 16 - -#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]) - -static struct etimer ping6_periodic_timer; -static uint8_t count = 0; -static uip_ipaddr_t dest_addr; - -PROCESS(ping6_process, "PING6 process"); -/*---------------------------------------------------------------------------*/ -static void -ping6handler() -{ - if(count < PING6_NB) { - 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_ds6_if.cur_hop_limit; - uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &dest_addr); - uip_ds6_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((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN, 0, 4); - /* put one byte of data */ - memset((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN, - count, PING6_DATALEN); - - - uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN + UIP_IPH_LEN + PING6_DATALEN; - UIP_IP_BUF->len[0] = (uint8_t)((uip_len - 40) >> 8); - UIP_IP_BUF->len[1] = (uint8_t)((uip_len - 40) & 0x00FF); - - UIP_ICMP_BUF->icmpchksum = 0; - UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); - - - PRINTF("Echo Request to "); - PRINT6ADDR(&UIP_IP_BUF->destipaddr); - PRINTF(" from "); - PRINT6ADDR(&UIP_IP_BUF->srcipaddr); - PRINTF("\n"); - UIP_STAT(++uip_stat.icmp.sent); - - tcpip_ipv6_output(); - - count++; - etimer_set(&ping6_periodic_timer, 3 * CLOCK_SECOND); - } else { - count = 0; - } -} - -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(ping6_process, ev, data) -{ - -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - static struct sensors_sensor *btn; -#endif - - PROCESS_BEGIN(); - PRINTF("ping6 running.\n"); - PRINTF("Button 1: 5 pings 16 byte payload.\n"); - - uip_ip6addr(&dest_addr, 0x2001, 0x470, 0x55, 0, 0x0215, 0x2000, 0x0002, - 0x0302); - count = 0; - - /* Check if we have buttons */ -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - btn = sensors_find(BUTTON_1_SENSOR); -#endif - - while(1) { - PROCESS_YIELD(); - -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - if(ev == sensors_event) { - if(data == btn && count == 0) { - ping6handler(); - } - } -#endif - if(etimer_expired(&ping6_periodic_timer)) { - ping6handler(); - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/udp-ipv6/project-conf.h b/examples/sensinode/udp-ipv6/project-conf.h deleted file mode 100644 index bb755aee9..000000000 --- a/examples/sensinode/udp-ipv6/project-conf.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - * - */ - -/** - * \file - * Project specific configuration defines for the UDP client/server - * example. - * - * We just turn on buttons - * - * \author - * George Oikonomou - - */ - -#ifndef PROJECT_CONF_H_ -#define PROJECT_CONF_H_ - -#define BUTTON_SENSOR_CONF_ON 1 -#define RIMESTATS_CONF_ENABLED 1 -#define VIZTOOL_CONF_ON 0 -#define UIP_CONF_ND6_SEND_NA 1 - -#endif /* PROJECT_CONF_H_ */ diff --git a/examples/sensinode/udp-ipv6/server.c b/examples/sensinode/udp-ipv6/server.c deleted file mode 100644 index fcdc0fec8..000000000 --- a/examples/sensinode/udp-ipv6/server.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * 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" -#include "contiki-lib.h" -#include "contiki-net.h" - -#include - -#define DEBUG DEBUG_NONE -#include "net/ip/uip-debug.h" -#include "dev/watchdog.h" -#include "dev/leds.h" -#include "net/rpl/rpl.h" - -#if CONTIKI_TARGET_SENSINODE -#include "dev/sensinode-sensors.h" -#include "debug.h" -#else -#define putstring(s) -#endif - -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) - -#define MAX_PAYLOAD_LEN 120 - -static struct uip_udp_conn *server_conn; -static char buf[MAX_PAYLOAD_LEN]; -static uint16_t len; - -#define SERVER_REPLY 1 - -/* Should we act as RPL root? */ -#define SERVER_RPL_ROOT 0 - -#if SERVER_RPL_ROOT -static uip_ipaddr_t ipaddr; -#endif -/*---------------------------------------------------------------------------*/ -extern const struct sensors_sensor adc_sensor; -/*---------------------------------------------------------------------------*/ -PROCESS(udp_server_process, "UDP server process"); -AUTOSTART_PROCESSES(&udp_server_process); -/*---------------------------------------------------------------------------*/ -static void -tcpip_handler(void) -{ - memset(buf, 0, MAX_PAYLOAD_LEN); - if(uip_newdata()) { - leds_on(LEDS_RED); - len = uip_datalen(); - memcpy(buf, uip_appdata, len); - PRINTF("%u bytes from [", len); - PRINT6ADDR(&UIP_IP_BUF->srcipaddr); - PRINTF("]:%u", UIP_HTONS(UIP_UDP_BUF->srcport)); - PRINTF(" V=%u", *buf); - PRINTF(" I=%u", *(buf + 1)); - PRINTF(" T=%u", *(buf + 2)); - PRINTF(" Val=%u\n", *(uint16_t *)(buf + 3)); -#if SERVER_REPLY - uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr); - server_conn->rport = UIP_UDP_BUF->srcport; - - uip_udp_packet_send(server_conn, buf, len); - /* Restore server connection to allow data from any node */ - uip_create_unspecified(&server_conn->ripaddr); - server_conn->rport = 0; -#endif - } - leds_off(LEDS_RED); - PRINTF("sent\n"); - return; -} -/*---------------------------------------------------------------------------*/ -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON && (DEBUG==DEBUG_PRINT)) -static void -print_stats() -{ - PRINTF("tl=%lu, ts=%lu, bs=%lu, bc=%lu\n", - RIMESTATS_GET(toolong), RIMESTATS_GET(tooshort), - RIMESTATS_GET(badsynch), RIMESTATS_GET(badcrc)); - PRINTF("llrx=%lu, lltx=%lu, rx=%lu, tx=%lu\n", RIMESTATS_GET(llrx), - RIMESTATS_GET(lltx), RIMESTATS_GET(rx), RIMESTATS_GET(tx)); -} -#else -#define print_stats() -#endif -/*---------------------------------------------------------------------------*/ -static void -print_local_addresses(void) -{ - int i; - uint8_t state; - - PRINTF("Server IPv6 addresses:\n"); - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - state = uip_ds6_if.addr_list[i].state; - if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state - == ADDR_PREFERRED)) { - PRINTF(" "); - PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); - PRINTF("\n"); - if(state == ADDR_TENTATIVE) { - uip_ds6_if.addr_list[i].state = ADDR_PREFERRED; - } - } - } -} -/*---------------------------------------------------------------------------*/ -#if SERVER_RPL_ROOT -void -create_dag() -{ - rpl_dag_t *dag; - - uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0); - uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); - uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); - - print_local_addresses(); - - dag = rpl_set_root(RPL_DEFAULT_INSTANCE, - &uip_ds6_get_global(ADDR_PREFERRED)->ipaddr); - if(dag != NULL) { - uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0); - rpl_set_prefix(dag, &ipaddr, 64); - PRINTF("Created a new RPL dag with ID: "); - PRINT6ADDR(&dag->dag_id); - PRINTF("\n"); - } -} -#endif /* SERVER_RPL_ROOT */ -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(udp_server_process, ev, data) -{ -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - static const struct sensors_sensor *b1; - static const struct sensors_sensor *b2; -#endif - - PROCESS_BEGIN(); - putstring("Starting UDP server\n"); - -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - putstring("Button 1: Print RIME stats\n"); - putstring("Button 2: Reboot\n"); -#endif - -#if SERVER_RPL_ROOT - create_dag(); -#endif - - server_conn = udp_new(NULL, UIP_HTONS(0), NULL); - udp_bind(server_conn, UIP_HTONS(3000)); - - PRINTF("Listen port: 3000, TTL=%u\n", server_conn->ttl); - -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - b1 = sensors_find(BUTTON_1_SENSOR); - b2 = sensors_find(BUTTON_2_SENSOR); -#endif - - while(1) { - PROCESS_YIELD(); - if(ev == tcpip_event) { - tcpip_handler(); -#if (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) - } else if(ev == sensors_event && data != NULL) { - if(data == b1) { - print_stats(); - } else if(data == b2) { - watchdog_reboot(); - } -#endif /* (CONTIKI_TARGET_SENSINODE && BUTTON_SENSOR_ON) */ - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/sensinode/Makefile.customrules-sensinode b/platform/sensinode/Makefile.customrules-sensinode deleted file mode 100644 index 13ec8cf5e..000000000 --- a/platform/sensinode/Makefile.customrules-sensinode +++ /dev/null @@ -1 +0,0 @@ -include $(CONTIKI)/cpu/cc2430/Makefile.customrules-cc2430 diff --git a/platform/sensinode/Makefile.sensinode b/platform/sensinode/Makefile.sensinode deleted file mode 100644 index 80937391c..000000000 --- a/platform/sensinode/Makefile.sensinode +++ /dev/null @@ -1,92 +0,0 @@ -# Sensinode CC2430 platform makefile -# Supported products: N100, N600, N601, N710, N711 -# Support for N740 is experimental. - -# We support defines for product models using the following format -# e.g. MODEL_N601. Run make TARGET=sensinode DEFINES=MODEL_N601 to -# automatically configure the correct LED, button, UART etc. settings -# for that product model. If undefined, MODEL_N100 is chosen by default. -# Model settings are defined in /dev/models.h - -# make sensinode.upload - Will use nano_programmer to upload file using D2xx Devboard -# make sensinode.serialdump - Will use the Contiki serialdump tool on the default UART -# make foo.model - Will copy foo.ihx to foo-XYZ.ihx (e.g. foo-n740.ihx) -PATH:=$(CONTIKI)/platform/$(TARGET)/tools/bin:$(PATH) -export PATH - -ifndef CONTIKI - $(error CONTIKI not defined! You must specify where CONTIKI resides!) -endif - -# Determine our model and (later on) add it as part of the .ihx filename -# Handy when building for various models so we can easily tell which ihx -# is for what model. -# Defaults to N100 (which is what the contiki code does as well) -MODEL_SUFFIX=n100 -ifdef DEFINES - MODEL_SUFFIX=$(patsubst MODEL_N%,n%, \ - $(filter MODEL_%,$(subst $(COMMA), ,$(DEFINES)))) -endif - -# Define the default UART for tools and tool commands -DEFUART = /dev/ttyUSB0 -PROG = $(CONTIKI)/tools/sensinode/nano_programmer/nano_programmer -d $(DEFUART) -SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux -b115200 $(DEFUART) - -CONTIKI_TARGET_DIRS = . dev -CONTIKI_TARGET_MAIN = $(addprefix $(OBJECTDIR)/,contiki-sensinode-main.rel) - -CONTIKI_TARGET_SOURCEFILES = contiki-sensinode-main.c -CONTIKI_TARGET_SOURCEFILES += leds.c leds-arch.c serial-line.c sensors.c -CONTIKI_TARGET_SOURCEFILES += sensinode-sensors.c button-sensor.c adc-sensor.c -CONTIKI_TARGET_SOURCEFILES += n740.c models.c m25p16.c slip-arch.c slip.c -CONTIKI_TARGET_SOURCEFILES += putchar.c debug.c - -CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) - -CLEAN += *.sensinode - -ifeq ($(CONTIKI_WITH_IPV6),1) - ifeq ($(OFFSET_FIRMWARE),1) - CFLAGS += -DDISCO_ENABLED=1 - CONTIKI_TARGET_SOURCEFILES += disco.c - endif - CONTIKI_TARGET_SOURCEFILES += viztool.c -endif - -FORCE: - -# .sensinode target so we can behave similar to other targets -# Lastly, it will create a %-$(MODEL).ihx file -%.$(TARGET): %.hex FORCE - cp $< $(<:.hex=.$(TARGET)) - if [ -f $(<:.hex=.ihx) ] ; then \ - cp $(<:.hex=.ihx) $(<:.hex=-$(MODEL_SUFFIX).ihx); fi - @echo "\nReport" - @echo "===============" - @echo 'Code footprint:' - @echo 'Area Addr Size' \ - ' Decimal' - @echo '---------------------------------- -------- --------' \ - ' --------' - @echo -n 'HOME,CSEG,CONST,XINIT,GS* $(HOME_START) ' - @egrep ',CODE\)' $(<:.hex=.map) | egrep -v '(^BANK[1-9][^=])' | uniq | \ - awk '{ SUM += $$5 } END { printf "%08X = %8d", SUM, SUM }' - @echo '. bytes (REL,CON,CODE)' - @egrep '(^BANK[1-9][^=])' $(<:.hex=.map) | uniq | sort - @egrep -A 5 'Other memory' $(<:.hex=.mem) - -%.upload: %.hex - $(PROG) -P $< - -sensinode.serialdump: - $(SERIALDUMP) - -### Define the CPU directory -CONTIKI_CPU=$(CONTIKI)/cpu/cc2430 -include $(CONTIKI)/cpu/cc2430/Makefile.cc2430 - -contiki-$(TARGET).a:# $(addprefix $(OBJECTDIR)/,symbols.rel) - -MODULES += core/net core/net/mac \ - core/net/llsec diff --git a/platform/sensinode/apps/batmon/Makefile.batmon b/platform/sensinode/apps/batmon/Makefile.batmon deleted file mode 100644 index 1ad4809da..000000000 --- a/platform/sensinode/apps/batmon/Makefile.batmon +++ /dev/null @@ -1,3 +0,0 @@ -batmon_src = batmon.c - -CFLAGS += -DBATMON_CONF_ON=1 \ No newline at end of file diff --git a/platform/sensinode/apps/batmon/batmon.c b/platform/sensinode/apps/batmon/batmon.c deleted file mode 100644 index 184404199..000000000 --- a/platform/sensinode/apps/batmon/batmon.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Sources for the BATtery MONitor app. It dumps a log entry to the - * external flash periodically as well as upon external trigger. - * - * It started off as a VDD and battery logger but now it also stores - * energest values and other goodies. - * - * \author - * George Oikonomou - - */ - -#include "contiki.h" - -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif - -#include "sys/etimer.h" -#include "sys/energest.h" -#include "dev/sensinode-sensors.h" -#include "dev/n740.h" -#include "dev/m25p16.h" - -#define BATMON_LOG_PERIOD 60 /* in seconds */ -/*---------------------------------------------------------------------------*/ -static const uint8_t magic[3] = { 0x0B, 0xEE, 0xF0 }; -/*---------------------------------------------------------------------------*/ -struct record { - uint8_t magic[3]; - uint8_t trigger; - unsigned long c; /* uptime */ - int v; /* VDD (reference) */ - int b; /* Voltage ADC */ -#if ENERGEST_CONF_ON - unsigned long mcu; - unsigned long lpm; - unsigned long irq; - unsigned long tx; - unsigned long rx; - unsigned long f_write; - unsigned long f_read; -#endif -}; - -#define RECORD_SIZE 64 -#define LAST_WRITE (0xFFFF - RECORD_SIZE) - -#define LOG_TRIGGER_PERIODIC 0xFF -/*---------------------------------------------------------------------------*/ -struct flash_address { - uint8_t s; /* sector */ - uint8_t p; /* page */ - uint8_t a; /* address */ -}; -static struct flash_address f; - -static struct record r; -static struct sensors_sensor *s; -static struct etimer et; -#define FLASH_START_ADDR 0x1E0000 -#define FLASH_END_ADDR 0x1FFFFF -/*---------------------------------------------------------------------------*/ -PROCESS(batmon_process, "Logger Process"); -/*---------------------------------------------------------------------------*/ -static int -find_gap() CC_NON_BANKED -{ - uint8_t seq[3]; - uint32_t address = FLASH_START_ADDR; - memset(&f, 0, sizeof(f)); - - for(address = FLASH_START_ADDR; address <= FLASH_END_ADDR; address += - RECORD_SIZE) { - n740_analog_deactivate(); - f.s = ((address & 0xFF0000) >> 16); - f.p = ((address & 0xFF00) >> 8); - f.a = address & 0xFF; - m25p16_read_fast((uint8_t *)&f, seq, sizeof(magic)); - n740_analog_activate(); - if(memcmp(seq, magic, sizeof(magic)) != 0) { - PRINTF("BatMon: Resume write @ 0x%02x%02x%02x\n", f.s, f.p, f.a); - return 1; - } - } - - /* If we reach here, we ran out of flash */ - return -1; -} -/*---------------------------------------------------------------------------*/ -static void -abort() CC_NON_BANKED -{ - PRINTF("BatMon: Abort\n"); - etimer_stop(&et); - process_exit(&batmon_process); -} -/*---------------------------------------------------------------------------*/ -void -batmon_log(uint8_t trigger) -{ - uint32_t next; - - /* Only continue if the process (us) is running */ - if(!process_is_running(&batmon_process)) { - return; - } - - next = f.a; - next |= (((uint32_t) f.p) << 8); - next |= (((uint32_t) f.s) << 16); - - memcpy(r.magic, magic, sizeof(magic)); - r.trigger = trigger; - r.c = clock_seconds(); - - /* Read VDD and use as ADC reference */ - r.v = s->value(ADC_SENSOR_TYPE_VDD); - - /* And then carry on with battery */ - r.b = s->value(ADC_SENSOR_TYPE_BATTERY); - -#if ENERGEST_CONF_ON - /* ENERGEST values */ - r.mcu = energest_type_time(ENERGEST_TYPE_CPU); - r.lpm = energest_type_time(ENERGEST_TYPE_LPM); - r.irq = energest_type_time(ENERGEST_TYPE_IRQ); - r.tx = energest_type_time(ENERGEST_TYPE_TRANSMIT); - r.rx = energest_type_time(ENERGEST_TYPE_LISTEN); - r.f_write = energest_type_time(ENERGEST_TYPE_FLASH_WRITE); - r.f_read = energest_type_time(ENERGEST_TYPE_FLASH_READ); -#endif - - n740_analog_deactivate(); - /* Make sure we're on */ - if(M25P16_WIP()) { - m25p16_res(); - } - m25p16_pp((uint8_t *)&f, (uint8_t *)&r, sizeof(r)); - n740_analog_activate(); - - PRINTF("BatMon: @%lu [%u] ", r.c, r.trigger); - PRINTF("BatMon: 0x%02x%02x%02x\n", f.s, f.p, f.a); - - next += RECORD_SIZE; - - if(next >= FLASH_END_ADDR) { - abort(); - return; - } - - f.s = ((next & 0xFF0000) >> 16); - f.p = ((next & 0xFF00) >> 8); - f.a = next & 0xFF; - - if(trigger == LOG_TRIGGER_PERIODIC) { - etimer_reset(&et); - } -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(batmon_process, ev, data) -{ - - PROCESS_BEGIN(); - - PRINTF("BatMon\n", sizeof(r)); - - s = sensors_find(ADC_SENSOR); - if(!s) { - PRINTF("BatMon: ADC not found\n"); - PROCESS_EXIT(); - } - - n740_analog_deactivate(); - m25p16_res(); - n740_analog_activate(); - - /* Find last written location */ - if(find_gap() == -1) { - PRINTF("BatMon: Flash storage full\n"); - PROCESS_EXIT(); - } - - etimer_set(&et, BATMON_LOG_PERIOD * CLOCK_SECOND); - - while(1) { - PROCESS_YIELD(); - if(ev == PROCESS_EVENT_TIMER && etimer_expired(&et)) { - batmon_log(LOG_TRIGGER_PERIODIC); - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/sensinode/contiki-conf.h b/platform/sensinode/contiki-conf.h deleted file mode 100644 index d09fdbcbd..000000000 --- a/platform/sensinode/contiki-conf.h +++ /dev/null @@ -1,286 +0,0 @@ -#ifndef CONTIKI_CONF_H_ -#define CONTIKI_CONF_H_ - -#include "8051def.h" -#include "sys/cc.h" -#include - -/* Include Project Specific conf */ -#ifdef PROJECT_CONF_H -#include "project-conf.h" -#endif /* PROJECT_CONF_H */ - -/* - * Define this as 1 to poll the etimer process from within main instead of from - * the clock ISR. This reduces the ISR's stack usage and may prevent crashes. - */ -#ifndef CLOCK_CONF_STACK_FRIENDLY -#define CLOCK_CONF_STACK_FRIENDLY 1 -#endif - -/* Memory filesystem RAM size. */ -#define CFS_RAM_CONF_SIZE 512 - -/* Logging.. */ -#define LOG_CONF_ENABLED 0 - -#ifndef STACK_CONF_DEBUGGING -#define STACK_CONF_DEBUGGING 0 -#endif - -/* Energest Module */ -#ifndef ENERGEST_CONF_ON -#define ENERGEST_CONF_ON 0 -#endif - -/* Verbose Startup? Turning this off reduces our footprint a fair bit */ -#define STARTUP_CONF_VERBOSE 0 - -/* More CODE space savings by turning off process names */ -#define PROCESS_CONF_NO_PROCESS_NAMES 1 - -/* - * UARTs: 1=>Enabled, 0=>Disabled. Default: Both Disabled (see uart.h) - * Disabling UARTs reduces our CODE footprint - * Disabling UART1 also disables all debugging output. - * Should be used when nodes are meant to run on batteries - * - * On N740, by enabling UART1, you are also enabling an ugly hack which aims - * to detect the USB connection during execution. It will then turn on/off - * UART1 RX interrupts accordingly. This seems to work but you have been warned - * If you start seeing random crashes when on battery, this is where to look. - */ -#ifndef UART_ONE_CONF_ENABLE -#define UART_ONE_CONF_ENABLE 1 -#endif -#ifndef UART_ONE_CONF_WITH_INPUT -#define UART_ONE_CONF_WITH_INPUT 0 -#endif -#define UART_ZERO_CONF_ENABLE 0 - -#ifndef UART_ONE_CONF_HIGH_SPEED -#define UART_ONE_CONF_HIGH_SPEED 0 -#endif - -#define SLIP_RADIO_CONF_NO_PUTCHAR 1 - -#if defined (UIP_FALLBACK_INTERFACE) || defined (CMD_CONF_OUTPUT) -#define SLIP_ARCH_CONF_ENABLE 1 -#endif - -/* Are we a SLIP bridge? */ -#if SLIP_ARCH_CONF_ENABLE -/* Make sure UART1 is enabled, with interrupts */ -#undef UART_ONE_CONF_ENABLE -#undef UART_ONE_CONF_WITH_INPUT -#define UART_ONE_CONF_ENABLE 1 -#define UART_ONE_CONF_WITH_INPUT 1 -#endif - -/* Output all captured frames over the UART in hexdump format */ -#ifndef CC2430_RF_CONF_HEXDUMP -#define CC2430_RF_CONF_HEXDUMP 0 -#endif - -#if CC2430_RF_CONF_HEXDUMP -/* We need UART1 output */ -#undef UART_ONE_CONF_ENABLE -#define UART_ONE_CONF_ENABLE 1 -#endif - -/* Code Shortcuts */ -/* - * When set, the RF driver is no longer a contiki process and the RX ISR is - * disabled. Instead of polling the radio process when data arrives, we - * periodically check for data by directly invoking the driver from main() - * - * When set, this directive also configures the following bypasses: - * - process_post_synch() in tcpip_input() (we call packet_input()) - * - process_post_synch() in tcpip_uipcall (we call the relevant pthread) - * - mac_call_sent_callback() is replaced with sent() in various places - * - * These are good things to do, they reduce stack usage and prevent crashes - */ -#define NETSTACK_CONF_SHORTCUTS 1 - -/* - * Sensors - * It is harmless to #define XYZ 1 - * even if the sensor is not present on our device - */ -#ifndef BUTTON_SENSOR_CONF_ON -#define BUTTON_SENSOR_CONF_ON 1 /* Buttons */ -#endif -/* ADC - Turning this off will disable everything below */ -#ifndef ADC_SENSOR_CONF_ON -#define ADC_SENSOR_CONF_ON 1 -#endif -#define TEMP_SENSOR_CONF_ON 1 /* Temperature */ -#define BATTERY_SENSOR_CONF_ON 1 /* Battery */ -#define VDD_SENSOR_CONF_ON 1 /* Supply Voltage */ -#define ACC_SENSOR_CONF_ON 1 /* Accelerometer */ -#define ACC_SENSOR_CONF_GSEL 0 /* Acc. g-Select => 1: +/-11g, 0: +/-3g */ -#define LIGHT_SENSOR_CONF_ON 1 /* Light */ - -/* Watchdog */ -#define WDT_CONF_INTERVAL 0 -#define WDT_CONF_TIMER_MODE 0 /* 0 or undefined for watchdog mode */ - -/* Low Power Modes - We only support PM0/Idle and PM1 */ -#ifndef LPM_CONF_MODE -#define LPM_CONF_MODE 1 /* 0: no LPM, 1: MCU IDLE, 2: Drop to PM1 */ -#endif - -/* DMA Configuration */ -#ifndef DMA_CONF_ON -#define DMA_CONF_ON 0 -#endif - -/* N740 Serial Flash */ -#ifndef M25P16_CONF_ON -#define M25P16_CONF_ON 1 -#endif - -/* XXX argh, ugly hack to make stuff compile! */ -#define snprintf(BUF, SIZE, ...) sprintf(BUF, __VA_ARGS__) - -/* Sensinode-Specific Tools and APPs */ -/* Viztool on by default for IPv6 builds */ -#if NETSTACK_CONF_WITH_IPV6 -#ifndef VIZTOOL_CONF_ON -#define VIZTOOL_CONF_ON 1 -#endif /* VIZTOOL_CONF_ON */ -#endif /* NETSTACK_CONF_WITH_IPV6 */ - -/* BatMon off by default unless we build with APPS += batmon */ -#ifndef BATMON_CONF_ON -#define BATMON_CONF_ON 0 -#endif - -/* Network Stack */ -#ifndef NETSTACK_CONF_NETWORK -#if NETSTACK_CONF_WITH_IPV6 -#define NETSTACK_CONF_NETWORK sicslowpan_driver -#else -#define NETSTACK_CONF_NETWORK rime_driver -#endif /* NETSTACK_CONF_WITH_IPV6 */ -#endif /* NETSTACK_CONF_NETWORK */ - -#ifndef NETSTACK_CONF_MAC -#define NETSTACK_CONF_MAC csma_driver -#endif - -#ifndef NETSTACK_CONF_RDC -#define NETSTACK_CONF_RDC nullrdc_driver -#define NULLRDC_802154_AUTOACK 1 -#define NULLRDC_802154_AUTOACK_HW 1 -#endif - -#ifndef NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE -#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 8 -#endif - -#ifndef NETSTACK_CONF_FRAMER -#define NETSTACK_CONF_FRAMER framer_802154 -#endif - -#define NETSTACK_CONF_RADIO cc2430_rf_driver - -/* RF Config */ -#define IEEE802154_CONF_PANID 0x4C55 /* LU */ - -#ifndef CC2430_RF_CONF_CHANNEL -#define CC2430_RF_CONF_CHANNEL 25 -#endif /* CC2430_RF_CONF_CHANNEL */ - -#ifndef CC2430_RF_CONF_TX_POWER -#define CC2430_RF_CONF_TX_POWER 0x5F /* Datasheet recommended value */ -#endif - -#ifndef CC2430_RF_CONF_AUTOACK -#define CC2430_RF_CONF_AUTOACK 1 -#endif /* CC2430_CONF_AUTOACK */ - -#if NETSTACK_CONF_WITH_IPV6 -/* Addresses, Sizes and Interfaces */ -/* 8-byte addresses here, 2 otherwise */ -#define LINKADDR_CONF_SIZE 8 -#define UIP_CONF_LL_802154 1 -#define UIP_CONF_LLH_LEN 0 -#define UIP_CONF_NETIF_MAX_ADDRESSES 3 - -/* TCP, UDP, ICMP */ -#define UIP_CONF_TCP 0 -#define UIP_CONF_UDP 1 -#define UIP_CONF_UDP_CHECKSUMS 1 - -/* ND and Routing */ -#ifndef UIP_CONF_ROUTER -#define UIP_CONF_ROUTER 1 -#endif - -#define UIP_CONF_ND6_SEND_RA 0 -#define UIP_CONF_IP_FORWARD 0 -#define RPL_CONF_STATS 0 - -#ifndef RPL_CONF_OF -#define RPL_CONF_OF rpl_mrhof -#endif - -#define UIP_CONF_ND6_REACHABLE_TIME 600000 -#define UIP_CONF_ND6_RETRANS_TIMER 10000 - -#ifndef NBR_TABLE_CONF_MAX_NEIGHBORS -#define NBR_TABLE_CONF_MAX_NEIGHBORS 4 /* Handle n Neighbors */ -#endif -#ifndef UIP_CONF_MAX_ROUTES -#define UIP_CONF_MAX_ROUTES 4 /* Handle n Routes */ -#endif - -/* uIP */ -#ifndef UIP_CONF_BUFFER_SIZE -#define UIP_CONF_BUFFER_SIZE 240 -#endif -#define UIP_CONF_IPV6_QUEUE_PKT 0 -#define UIP_CONF_IPV6_CHECKS 1 -#define UIP_CONF_IPV6_REASSEMBLY 0 - -/* 6lowpan */ -#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06 -#ifndef SICSLOWPAN_CONF_FRAG -#define SICSLOWPAN_CONF_FRAG 0 /* About 2KB of CODE if 1 */ -#endif -#define SICSLOWPAN_CONF_MAXAGE 8 - -/* Define our IPv6 prefixes/contexts here */ -#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 1 -#define SICSLOWPAN_CONF_ADDR_CONTEXT_0 { \ - addr_contexts[0].prefix[0] = 0x20; \ - addr_contexts[0].prefix[1] = 0x01; \ - addr_contexts[0].prefix[2] = 0x06; \ - addr_contexts[0].prefix[3] = 0x30; \ - addr_contexts[0].prefix[4] = 0x03; \ - addr_contexts[0].prefix[5] = 0x01; \ - addr_contexts[0].prefix[6] = 0x64; \ - addr_contexts[0].prefix[7] = 0x53; \ -} - -#define MAC_CONF_CHANNEL_CHECK_RATE 8 -#ifndef QUEUEBUF_CONF_NUM -#define QUEUEBUF_CONF_NUM 6 -#endif - -#else /* NETSTACK_CONF_WITH_IPV6 */ -/* Network setup for non-IPv6 (rime). */ -#define UIP_CONF_IP_FORWARD 1 -#define UIP_CONF_BUFFER_SIZE 108 -#define RIME_CONF_NO_POLITE_ANNOUCEMENTS 0 -#define QUEUEBUF_CONF_NUM 8 -#endif /* NETSTACK_CONF_WITH_IPV6 */ - -/* Prevent SDCC compile error when UIP_CONF_ROUTER == 0 */ -#if !UIP_CONF_ROUTER -#define UIP_CONF_DS6_AADDR_NBU 1 -#endif - -#endif /* CONTIKI_CONF_H_ */ diff --git a/platform/sensinode/contiki-sensinode-main.c b/platform/sensinode/contiki-sensinode-main.c deleted file mode 100644 index 541b28d26..000000000 --- a/platform/sensinode/contiki-sensinode-main.c +++ /dev/null @@ -1,382 +0,0 @@ -#include "contiki.h" -#include "sys/clock.h" -#include "sys/autostart.h" - -#include "dev/serial-line.h" -#include "dev/slip.h" -#include "dev/bus.h" -#include "dev/leds.h" -#include "dev/uart1.h" -#include "dev/dma.h" -#include "dev/models.h" -#include "dev/cc2430_rf.h" -#include "dev/watchdog.h" -#include "dev/lpm.h" -#include "net/rime/rime.h" -#include "net/netstack.h" -#include "net/mac/frame802154.h" -#include "debug.h" -#include "stack.h" -#include "dev/watchdog-cc2430.h" -#include "dev/sensinode-sensors.h" -#include "disco.h" -#include "contiki-lib.h" -#include "contiki-net.h" - -unsigned short node_id = 0; /* Manually sets MAC address when > 0 */ - -#if VIZTOOL_CONF_ON -PROCESS_NAME(viztool_process); -#endif - -#if BATMON_CONF_ON -PROCESS_NAME(batmon_process); -#endif - -#if NETSTACK_CONF_SHORTCUTS -static CC_AT_DATA uint16_t len; -#endif - -#ifdef STARTUP_CONF_VERBOSE -#define STARTUP_VERBOSE STARTUP_CONF_VERBOSE -#else -#define STARTUP_VERBOSE 0 -#endif - -#if STARTUP_VERBOSE -#define PUTSTRING(...) putstring(__VA_ARGS__) -#define PUTHEX(...) puthex(__VA_ARGS__) -#define PUTBIN(...) putbin(__VA_ARGS__) -#define PUTCHAR(...) putchar(__VA_ARGS__) -#else -#define PUTSTRING(...) do {} while(0) -#define PUTHEX(...) do {} while(0) -#define PUTBIN(...) do {} while(0) -#define PUTCHAR(...) do {} while(0) -#endif - -#if CLOCK_CONF_STACK_FRIENDLY -extern volatile uint8_t sleep_flag; -#endif - -extern linkaddr_t linkaddr_node_addr; -#if ENERGEST_CONF_ON -static unsigned long irq_energest = 0; -#define ENERGEST_IRQ_SAVE(a) do { \ - a = energest_type_time(ENERGEST_TYPE_IRQ); } while(0) -#define ENERGEST_IRQ_RESTORE(a) do { \ - energest_type_set(ENERGEST_TYPE_IRQ, a); } while(0) -#else -#define ENERGEST_IRQ_SAVE(a) do {} while(0) -#define ENERGEST_IRQ_RESTORE(a) do {} while(0) -#endif -/*---------------------------------------------------------------------------*/ -static void -fade(int l) CC_NON_BANKED -{ - volatile int i, a; - int k, j; - for(k = 0; k < 400; ++k) { - j = k > 200 ? 400 - k : k; - - leds_on(l); - for(i = 0; i < j; ++i) { - a = i; - } - leds_off(l); - for(i = 0; i < 200 - j; ++i) { - a = i; - } - } -} -/*---------------------------------------------------------------------------*/ -static void -set_rime_addr(void) CC_NON_BANKED -{ - uint8_t *addr_long = NULL; - uint16_t addr_short = 0; - char i; - __code unsigned char *macp; - - PUTSTRING("Rime is 0x"); - PUTHEX(sizeof(linkaddr_t)); - PUTSTRING(" bytes long\n"); - - if(node_id == 0) { - PUTSTRING("Reading MAC from flash\n"); - /* - * The MAC is always stored in 0x1FFF8 of our flash. This maps to address - * 0xFFF8 of our CODE segment, when BANK3 is selected. - * Switch to BANK3, read 8 bytes starting at 0xFFF8 and restore last BANK - * Since we are called from main(), this MUST be BANK1 or something is very - * wrong. This code can be used even without banking - */ - - /* Don't interrupt us to make sure no BANK switching happens while working */ - DISABLE_INTERRUPTS(); - - /* Switch to BANK3, map CODE: 0x8000 - 0xFFFF to FLASH: 0x18000 - 0x1FFFF */ - FMAP = 3; - - /* Set our pointer to the correct address and fetch 8 bytes of MAC */ - macp = (__code unsigned char *)0xFFF8; - - for(i = (LINKADDR_SIZE - 1); i >= 0; --i) { - linkaddr_node_addr.u8[i] = *macp; - macp++; - } - - /* Remap 0x8000 - 0xFFFF to BANK1 */ - FMAP = 1; - ENABLE_INTERRUPTS(); - - } else { - PUTSTRING("Setting manual address from node_id\n"); - linkaddr_node_addr.u8[LINKADDR_SIZE - 1] = node_id >> 8; - linkaddr_node_addr.u8[LINKADDR_SIZE - 2] = node_id & 0xff; - } - - /* Now the address is stored MSB first */ -#if STARTUP_VERBOSE - PUTSTRING("Rime configured with address "); - for(i = 0; i < LINKADDR_SIZE - 1; i++) { - PUTHEX(linkaddr_node_addr.u8[i]); - PUTCHAR(':'); - } - PUTHEX(linkaddr_node_addr.u8[i]); - PUTCHAR('\n'); -#endif - - /* Set the cc2430 RF addresses */ -#if (LINKADDR_SIZE==8) - addr_short = (linkaddr_node_addr.u8[6] * 256) + linkaddr_node_addr.u8[7]; - addr_long = (uint8_t *) &linkaddr_node_addr; -#else - addr_short = (linkaddr_node_addr.u8[0] * 256) + linkaddr_node_addr.u8[1]; -#endif - cc2430_rf_set_addr(IEEE802154_PANID, addr_short, addr_long); -} -/*---------------------------------------------------------------------------*/ -int -main(void) -{ - - /* Hardware initialization */ - bus_init(); - rtimer_init(); - - stack_poison(); - - /* model-specific h/w init. */ - model_init(); - - /* Init LEDs here */ - leds_init(); - fade(LEDS_GREEN); - - /* initialize process manager. */ - process_init(); - - /* Init UART1 */ - uart1_init(); - -#if DMA_ON - dma_init(); -#endif - -#if SLIP_ARCH_CONF_ENABLE - /* On cc2430, the argument is not used */ - slip_arch_init(0); -#else - uart1_set_input(serial_line_input_byte); - serial_line_init(); -#endif - - PUTSTRING("##########################################\n"); - putstring(CONTIKI_VERSION_STRING "\n"); - putstring(SENSINODE_MODEL " (CC24"); - puthex(((CHIPID >> 3) | 0x20)); - putstring("-" FLASH_SIZE ")\n"); - -#if STARTUP_VERBOSE -#ifdef HAVE_SDCC_BANKING - PUTSTRING(" With Banking.\n"); -#endif /* HAVE_SDCC_BANKING */ -#ifdef SDCC_MODEL_LARGE - PUTSTRING(" --model-large\n"); -#endif /* SDCC_MODEL_LARGE */ -#ifdef SDCC_MODEL_HUGE - PUTSTRING(" --model-huge\n"); -#endif /* SDCC_MODEL_HUGE */ -#ifdef SDCC_STACK_AUTO - PUTSTRING(" --stack-auto\n"); -#endif /* SDCC_STACK_AUTO */ - - PUTCHAR('\n'); - - PUTSTRING(" Net: "); - PUTSTRING(NETSTACK_NETWORK.name); - PUTCHAR('\n'); - PUTSTRING(" MAC: "); - PUTSTRING(NETSTACK_MAC.name); - PUTCHAR('\n'); - PUTSTRING(" RDC: "); - PUTSTRING(NETSTACK_RDC.name); - PUTCHAR('\n'); - - PUTSTRING("##########################################\n"); -#endif - - watchdog_init(); - - /* Initialise the cc2430 RNG engine. */ - random_init(0); - - /* start services */ - process_start(&etimer_process, NULL); - ctimer_init(); - - /* initialize the netstack */ - netstack_init(); - set_rime_addr(); - -#if BUTTON_SENSOR_ON || ADC_SENSOR_ON - process_start(&sensors_process, NULL); - sensinode_sensors_activate(); -#endif - -#if NETSTACK_CONF_WITH_IPV6 - memcpy(&uip_lladdr.addr, &linkaddr_node_addr, sizeof(uip_lladdr.addr)); - queuebuf_init(); - process_start(&tcpip_process, NULL); - -#if DISCO_ENABLED - process_start(&disco_process, NULL); -#endif /* DISCO_ENABLED */ - -#if VIZTOOL_CONF_ON - process_start(&viztool_process, NULL); -#endif - -#if (!UIP_CONF_IPV6_RPL) - { - uip_ipaddr_t ipaddr; - - uip_ip6addr(&ipaddr, 0x2001, 0x630, 0x301, 0x6453, 0, 0, 0, 0); - uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); - uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE); - } -#endif /* UIP_CONF_IPV6_RPL */ -#endif /* NETSTACK_CONF_WITH_IPV6 */ - - /* - * Acknowledge the UART1 RX interrupt - * now that we're sure we are ready to process it - */ - model_uart_intr_en(); - - energest_init(); - ENERGEST_ON(ENERGEST_TYPE_CPU); - - fade(LEDS_RED); - -#if BATMON_CONF_ON - process_start(&batmon_process, NULL); -#endif - - autostart_start(autostart_processes); - - watchdog_start(); - - while(1) { - uint8_t r; - do { - /* Reset watchdog and handle polls and events */ - watchdog_periodic(); - -#if CLOCK_CONF_STACK_FRIENDLY - if(sleep_flag) { - if(etimer_pending() && - (etimer_next_expiration_time() - clock_time() - 1) > MAX_TICKS) { - etimer_request_poll(); - } - sleep_flag = 0; - } -#endif - r = process_run(); - } while(r > 0); -#if NETSTACK_CONF_SHORTCUTS - len = NETSTACK_RADIO.pending_packet(); - if(len) { - packetbuf_clear(); - len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE); - if(len > 0) { - packetbuf_set_datalen(len); - NETSTACK_RDC.input(); - } - } -#endif - -#if LPM_MODE -#if (LPM_MODE==LPM_MODE_PM2) - SLEEP &= ~OSC_PD; /* Make sure both HS OSCs are on */ - while(!(SLEEP & HFRC_STB)); /* Wait for RCOSC to be stable */ - CLKCON |= OSC; /* Switch to the RCOSC */ - while(!(CLKCON & OSC)); /* Wait till it's happened */ - SLEEP |= OSC_PD; /* Turn the other one off */ -#endif /* LPM_MODE==LPM_MODE_PM2 */ - - /* - * Set MCU IDLE or Drop to PM1. Any interrupt will take us out of LPM - * Sleep Timer will wake us up in no more than 7.8ms (max idle interval) - */ - SLEEP = (SLEEP & 0xFC) | (LPM_MODE - 1); - -#if (LPM_MODE==LPM_MODE_PM2) - /* - * Wait 3 NOPs. Either an interrupt occurred and SLEEP.MODE was cleared or - * no interrupt occurred and we can safely power down - */ - __asm - nop - nop - nop - __endasm; - - if(SLEEP & SLEEP_MODE0) { -#endif /* LPM_MODE==LPM_MODE_PM2 */ - - ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM); - - /* We are only interested in IRQ energest while idle or in LPM */ - ENERGEST_IRQ_RESTORE(irq_energest); - - /* Go IDLE or Enter PM1 */ - PCON |= IDLE; - - /* First instruction upon exiting PM1 must be a NOP */ - __asm - nop - __endasm; - - /* Remember energest IRQ for next pass */ - ENERGEST_IRQ_SAVE(irq_energest); - - ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU); - -#if (LPM_MODE==LPM_MODE_PM2) - SLEEP &= ~OSC_PD; /* Make sure both HS OSCs are on */ - while(!(SLEEP & XOSC_STB)); /* Wait for XOSC to be stable */ - CLKCON &= ~OSC; /* Switch to the XOSC */ - /* - * On occasion the XOSC is reported stable when in reality it's not. - * We need to wait for a safeguard of 64us or more before selecting it - */ - clock_delay_usec(65); - while(CLKCON & OSC); /* Wait till it's happened */ - } -#endif /* LPM_MODE==LPM_MODE_PM2 */ -#endif /* LPM_MODE */ - } -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/sensinode/debug.c b/platform/sensinode/debug.c deleted file mode 100644 index f2fcb9498..000000000 --- a/platform/sensinode/debug.c +++ /dev/null @@ -1,61 +0,0 @@ -/** - * \file - * - * Definition of some debugging functions for the sensinode port. - * - * This file is bankable. - * - * putstring() and puthex() are from msp430/watchdog.c - * - * \author - * George Oikonomou - - */ - -#include "cc2430_sfr.h" -#include "8051def.h" -#include "debug.h" - -static const char hexconv[] = "0123456789abcdef"; -static const char binconv[] = "01"; - -/*---------------------------------------------------------------------------*/ -void -putstring(char *s) -{ - while(*s) { - putchar(*s++); - } -} -/*---------------------------------------------------------------------------*/ -void -puthex(uint8_t c) -{ - putchar(hexconv[c >> 4]); - putchar(hexconv[c & 0x0f]); -} -/*---------------------------------------------------------------------------*/ -void -putbin(uint8_t c) -{ - unsigned char i = 0x80; - while(i) { - putchar(binconv[(c & i) != 0]); - i >>= 1; - } -} -/*---------------------------------------------------------------------------*/ -void -putdec(uint8_t c) -{ - uint8_t div; - uint8_t hassent = 0; - for(div = 100; div > 0; div /= 10) { - uint8_t disp = c / div; - c %= div; - if((disp != 0) || (hassent) || (div == 1)) { - hassent = 1; - putchar('0' + disp); - } - } -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/sensinode/debug.h b/platform/sensinode/debug.h deleted file mode 100644 index 94eaa4f51..000000000 --- a/platform/sensinode/debug.h +++ /dev/null @@ -1,55 +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. - * - */ - -/** - * \file - * Header file for debugging functions used by the sensinode port. - * - * putstring() and puthex() are from msp430/watchdog.c - * - * \author - * George Oikonomou - - */ - -#ifndef DEBUG_H_ -#define DEBUG_H_ - -#include "8051def.h" -#include "dev/uart1.h" - -void putchar(char c); -void putstring(char *s); -void puthex(uint8_t c); -void putbin(uint8_t c); -void putdec(uint8_t c); - -#endif /* DEBUG_H_ */ diff --git a/platform/sensinode/dev/adc-sensor.c b/platform/sensinode/dev/adc-sensor.c deleted file mode 100644 index c039adafa..000000000 --- a/platform/sensinode/dev/adc-sensor.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * ADC sensor module for sensinode devices. - * - * This file respects configuration in contiki-conf.h. It also turns - * off features which are not present in the model that we are - * building for. - * - * \author - * George Oikonomou - - */ -#include "dev/sensinode-sensors.h" - -#if ADC_SENSOR_ON -SENSORS_SENSOR(adc_sensor, ADC_SENSOR, value, configure, status); - -static uint8_t ready; - -/*---------------------------------------------------------------------------*/ -static int -value(int type) -{ - uint16_t reading; - /* - * For single-shot AD conversions, we may only write to ADCCON3[3:0] once - * (This write triggers the conversion). We thus use the variable 'command' - * to store intermediate steps (reference, decimation rate, input channel) - */ - uint8_t command; - - ADCCFG = 0; /* Enables/Disables Input Channel */ - - /* 1.25V ref, max decimation rate */ - command = ADEDIV1 | ADEDIV0; - - /* Clear the Interrupt Flag */ - TCON_ADCIF = 0; - - /* Depending on the desired reading, append the input bits to 'command' and - * enable the corresponding input channel in ADCCFG if necessary */ - switch(type) { -#if TEMP_SENSOR_ON - case ADC_SENSOR_TYPE_TEMP: - command |= ADECH3 | ADECH2 | ADECH1; - break; -#endif -#if ACC_SENSOR_ON - case ADC_SENSOR_TYPE_ACC_X: - ADCCFG = ADC5EN; - command |= ADECH2 | ADECH0; - break; - case ADC_SENSOR_TYPE_ACC_Y: - ADCCFG = ADC6EN; - command |= ADECH2 | ADECH1; - break; - case ADC_SENSOR_TYPE_ACC_Z: - ADCCFG = ADC7EN; - command |= ADECH2 | ADECH1 | ADECH0; - break; -#endif -#if VDD_SENSOR_ON - case ADC_SENSOR_TYPE_VDD: - command |= ADECH3 | ADECH2 | ADECH1 | ADECH0; - break; -#endif -#if LIGHT_SENSOR_ON - case ADC_SENSOR_TYPE_LIGHT: - ADCCFG = ADC0EN; - break; -#endif -#if BATTERY_SENSOR_ON - case ADC_SENSOR_TYPE_BATTERY: - ADCCFG = ADC1EN; - command |= ADECH0 | ADEREF1; /* AVDD_SOC reference */ - break; -#endif - default: - /* If the sensor is not present or disabled in conf, return -1 */ - return -1; - } - - /* Writing in bits 3:0 of ADCCON3 will trigger a single conversion */ - ADCCON3 = command; - - /* - * When the conversion is complete, the ADC interrupt flag is set. We don't - * use an ISR here, we just wait on the flag and clear it afterwards. - */ - while(!TCON_ADCIF); - - /* Clear the Interrupt Flag */ - TCON_ADCIF = 0; - - reading = 0; - reading = ADCL; - reading |= (((uint8_t) ADCH) << 8); - /* 12-bit decimation rate: 4 LS bits are noise */ - reading >>= 4; - - return reading; -} -/*---------------------------------------------------------------------------*/ -static int -status(int type) -{ - return ready; -} -/*---------------------------------------------------------------------------*/ -/* - * On N740 we can control Ill and Acc individually: - * ADC_VAL_OTHERS 0x01 - * ADC_VAL_LIGHT_ON 0x04 - * ADC_VAL_ACC_ON 0x08 - * ADC_VAL_ACC_GSEL 0x10 - * - * Return Value is always light | acc | acc_gsel - * - * SENSORS_ACTIVE: - * - 1: Activate everything, use default setting for ACC G-select - * - 0: Turn everything off - * - xyz: Mask with the defines above and act accordingly. - * - * SENSORS_READY: - * - Return Status (0: all off or a value based on the defines above) - */ -static int -configure(int type, int value) -{ -#ifdef MODEL_N740 - /* - * Read current state of the ser-par, ignoring current sensor settings - * Those will be set all over depending on VALUE - */ - uint8_t ser_par_val = n740_ser_par_get() & 0xF2; -#endif /* MODEL_N740 */ - - /* 'Others' are either compiled in or not. Can't be turned on/off */ - ready = ADC_VAL_ALL; - - switch(type) { - case SENSORS_HW_INIT: - case SENSORS_ACTIVE: -#ifdef MODEL_N740 - if(value == ADC_VAL_ALL) { - value = ADC_VAL_ACC_ON | ADC_VAL_LIGHT_ON; -#if ACC_SENSOR_GSEL - value |= ADC_VAL_ACC_GSEL; -#endif /* ACC_SENSOR_GSEL */ - } -#endif /* MODEL_N740 */ - - /* OK, Now value definitely specifies our bits, start masking - * We will refuse to turn things on if they are specified OFF in conf. */ -#ifdef MODEL_N740 -#if ACC_SENSOR_ON - if(value & ADC_VAL_ACC_ON) { - P0SEL |= 0x80 | 0x40 | 0x20; - ser_par_val |= N740_SER_PAR_ACC; - ready |= ADC_VAL_ACC_ON; -#if ACC_SENSOR_GSEL - if(value & ADC_VAL_ACC_GSEL) { - ser_par_val |= N740_SER_PAR_ACC_GSEL; - ready |= ADC_VAL_ACC_GSEL; - } -#endif /*ACC_SENSOR_GSEL */ - } -#endif /* ACC_SENSOR_ON */ - -#if LIGHT_SENSOR_ON - if(value & ADC_VAL_LIGHT_ON) { - ser_par_val |= N740_SER_PAR_LIGHT; - ready |= ADC_VAL_LIGHT_ON; - } -#endif /* LIGHT_SENSOR_ON */ - n740_ser_par_set(ser_par_val); -#endif /* MODEL_N740 */ - } - return ready; -} - -#endif /* ADC_SENSOR_ON */ diff --git a/platform/sensinode/dev/button-sensor.c b/platform/sensinode/dev/button-sensor.c deleted file mode 100644 index 7b9c82ab4..000000000 --- a/platform/sensinode/dev/button-sensor.c +++ /dev/null @@ -1,205 +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. - */ - -/* - * Portions of this file build on button-sensor.c in platforms sky and esb - * This file contains ISRs: Keep it in the HOME bank. - */ - -#include "dev/models.h" -#include "lib/sensors.h" -#include "dev/hwconf.h" -#include "dev/sensinode-sensors.h" - -#if BUTTON_SENSOR_ON -static uint8_t p0ien; -static uint8_t p2ien; -static CC_AT_DATA struct timer debouncetimer[2]; - -#ifdef MODEL_N740 -HWCONF_PIN(BUTTON_1, 1, 0) -HWCONF_PORT_1_IRQ(BUTTON_1, 0) -HWCONF_PIN(BUTTON_2, 0, 4) -HWCONF_PORT_0_IRQ(BUTTON_2, 4) -#endif /* MODEL_N740 */ - -#ifdef MODEL_N711 -HWCONF_PIN(BUTTON_1, 0, 6) -HWCONF_PORT_0_IRQ(BUTTON_1, 6) -HWCONF_PIN(BUTTON_2, 0, 7) -HWCONF_PORT_0_IRQ(BUTTON_2, 7) -#endif /* MODEL_N711 */ - -/*---------------------------------------------------------------------------*/ -static int -value_b1(int type) -{ - return BUTTON_1_READ() || !timer_expired(&debouncetimer[0]); -} -/*---------------------------------------------------------------------------*/ -static int -status_b1(int type) -{ - switch(type) { - case SENSORS_ACTIVE: - case SENSORS_READY: - return BUTTON_1_IRQ_ENABLED(); - } - return 0; -} -/*---------------------------------------------------------------------------*/ -static int -configure_b1(int type, int value) -{ - switch(type) { - case SENSORS_HW_INIT: - /* Generates INT when pressed */ - BUTTON_1_IRQ_EDGE_SELECTD(); - BUTTON_1_SELECT(); - BUTTON_1_MAKE_INPUT(); - return 1; - case SENSORS_ACTIVE: - if(value) { - if(!BUTTON_1_IRQ_ENABLED()) { - timer_set(&debouncetimer[0], 0); - BUTTON_1_IRQ_FLAG_OFF(); - BUTTON_1_ENABLE_IRQ(); - } - } else { - BUTTON_1_DISABLE_IRQ(); - } - return 1; - } - return 0; -} -/*---------------------------------------------------------------------------*/ -static int -value_b2(int type) -{ - return BUTTON_2_READ() || !timer_expired(&debouncetimer[1]); -} -/*---------------------------------------------------------------------------*/ -static int -status_b2(int type) -{ - switch(type) { - case SENSORS_ACTIVE: - case SENSORS_READY: - return BUTTON_2_IRQ_ENABLED(); - } - return 0; -} -/*---------------------------------------------------------------------------*/ -static int -configure_b2(int type, int value) -{ - switch(type) { - case SENSORS_HW_INIT: - /* Generates INT when released */ - /* BUTTON_2_IRQ_EDGE_SELECTD(); */ - BUTTON_2_SELECT(); - BUTTON_2_MAKE_INPUT(); - return 1; - case SENSORS_ACTIVE: - if(value) { - if(!BUTTON_2_IRQ_ENABLED()) { - timer_set(&debouncetimer[1], 0); - BUTTON_2_IRQ_FLAG_OFF(); - BUTTON_2_ENABLE_IRQ(); - } - } else { - BUTTON_2_DISABLE_IRQ(); - } - return 1; - } - return 0; -} -/*---------------------------------------------------------------------------*/ -#pragma save -#if CC_CONF_OPTIMIZE_STACK_SIZE -#pragma exclude bits -#endif -void -port_0_ISR(void) __interrupt (P0INT_VECTOR) -{ - EA = 0; - ENERGEST_ON(ENERGEST_TYPE_IRQ); - - /* This ISR is for the entire port. Check if the interrupt was caused by our - * button's pin. */ - /* Check B1 for N711 */ -#ifdef MODEL_N711 - if(BUTTON_1_CHECK_IRQ()) { - if(timer_expired(&debouncetimer[0])) { - timer_set(&debouncetimer[0], CLOCK_SECOND / 4); - sensors_changed(&button_1_sensor); - } - } -#endif /* MODEL_N711 */ - if(BUTTON_2_CHECK_IRQ()) { - if(timer_expired(&debouncetimer[1])) { - timer_set(&debouncetimer[1], CLOCK_SECOND / 4); - sensors_changed(&button_2_sensor); - } - } - P0IFG = 0; - IRCON_P0IF = 0; - ENERGEST_OFF(ENERGEST_TYPE_IRQ); - EA = 1; -} -/*---------------------------------------------------------------------------*/ -/* We only need this ISR for N740 */ -#ifdef MODEL_N740 -void -port_1_ISR(void) __interrupt (P1INT_VECTOR) -{ - EA = 0; - ENERGEST_ON(ENERGEST_TYPE_IRQ); - - /* This ISR is for the entire port. Check if the interrupt was caused by our - * button's pin. This can only be B1 for N740 */ - if(BUTTON_1_CHECK_IRQ()) { - if(timer_expired(&debouncetimer[0])) { - timer_set(&debouncetimer[0], CLOCK_SECOND / 4); - sensors_changed(&button_1_sensor); - } - } - P1IFG = 0; - IRCON2_P1IF = 0; - ENERGEST_OFF(ENERGEST_TYPE_IRQ); - EA = 1; -} -#endif /* MODEL_N740 */ -#pragma restore - -SENSORS_SENSOR(button_1_sensor, BUTTON_1_SENSOR, value_b1, configure_b1, status_b1); -SENSORS_SENSOR(button_2_sensor, BUTTON_2_SENSOR, value_b2, configure_b2, status_b2); -#endif /* BUTTON_SENSOR_ON */ diff --git a/platform/sensinode/dev/button-sensor.h b/platform/sensinode/dev/button-sensor.h deleted file mode 100644 index 97a185223..000000000 --- a/platform/sensinode/dev/button-sensor.h +++ /dev/null @@ -1,48 +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. - */ - -/** - * \file - * Override core/dev/button-sensor.h - * - * We simply include "dev/sensinode-sensors.h". We do this so that apps - * and examples including button-sensor.h will compile for sensinodes - * - * \author - * George Oikonomou - - */ - -#ifndef BUTTON_SENSOR_H_ -#define BUTTON_SENSOR_H_ - -#include "dev/sensinode-sensors.h" - -#endif /* BUTTON_SENSOR_H_ */ diff --git a/platform/sensinode/dev/leds-arch.c b/platform/sensinode/dev/leds-arch.c deleted file mode 100644 index 5d4154d2f..000000000 --- a/platform/sensinode/dev/leds-arch.c +++ /dev/null @@ -1,90 +0,0 @@ -#include "contiki-conf.h" -#include "dev/models.h" -#include "dev/leds.h" - -#include "cc2430_sfr.h" - -/* - * Sensinode v1.0 HW products have 2 red LEDs, LED1 is mapped to the Contiki - * LEDS_GREEN and LED2 is mapped to LEDS_RED. - */ - -/*---------------------------------------------------------------------------*/ -void -leds_arch_init(void) -{ -#ifdef MODEL_N740 - /* - * We don't need explicit led initialisation for N740s. They are controlled - * by the ser/par chip which is initalised already - */ - return; -#else - P0DIR |= 0x30; -#endif -} -/*---------------------------------------------------------------------------*/ -unsigned char -leds_arch_get(void) -{ - unsigned char l = 0; - -#ifdef MODEL_N740 - /* Read the current ser-par chip status */ - uint8_t ser_par; - ser_par = n740_ser_par_get(); - /* Check bits 7 & 8, ignore the rest */ - if(ser_par & N740_SER_PAR_LED_GREEN) { - l |= LEDS_GREEN; - } - if(ser_par & N740_SER_PAR_LED_RED) { - l |= LEDS_RED; - } -#else - if(LED1_PIN) { - l |= LEDS_GREEN; - } - if(LED2_PIN) { - l |= LEDS_RED; - } -#endif - return l; -} -/*---------------------------------------------------------------------------*/ -void -leds_arch_set(unsigned char leds) -{ -#ifdef MODEL_N740 - /* Read the current ser-par chip status - we want to change bits 7 & 8 but - * the remaining bit values should be retained */ - uint8_t ser_par; - ser_par = n740_ser_par_get(); - if(leds & LEDS_GREEN) { - ser_par |= N740_SER_PAR_LED_GREEN; /* Set bit 7 */ - } else { - ser_par &= ~N740_SER_PAR_LED_GREEN; /* Unset bit 7 */ - } - - if(leds & LEDS_RED) { - ser_par |= N740_SER_PAR_LED_RED; /* Set bit 8 */ - } else { - ser_par &= ~N740_SER_PAR_LED_RED; /* Unset bit 8 */ - } - - /* Write the new status back to the chip */ - n740_ser_par_set(ser_par); -#else - if(leds & LEDS_GREEN) { - LED1_PIN = 1; - } else { - LED1_PIN = 0; - } - - if(leds & LEDS_RED) { - LED2_PIN = 1; - } else { - LED2_PIN = 0; - } -#endif -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/sensinode/dev/m25p16.c b/platform/sensinode/dev/m25p16.c deleted file mode 100644 index f1cbdebfd..000000000 --- a/platform/sensinode/dev/m25p16.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * This file provides functions to control the M25P16 on sensinode N740s. - * This is a Numonyx Forte Serial Flash Memory (16Mbit) - * The S signal (Chip Select) is controlled via 0x02 on the 74HC595D - * The other instructions and timing are performed with bit bang - * - * We can enable, disable, read/write data, erase pages, hold, enter/exit - * deep sleep etc. - * - * Clock (C) => P1_5, - * Ser. I (D) => P1_6, - * Ser. O (Q) => P1_7, - * Hold => Pull Up, - * Write Prot => Pull Up, - * Chip Sel => 74HC595D (0x02) - * - * This file can be placed in any bank. - * - * \author - * George Oikonomou - - */ - -#include "dev/n740.h" -#include "dev/m25p16.h" -#include "sys/clock.h" -#include "sys/energest.h" -#include "cc2430_sfr.h" - -#define CLOCK_RISING() {M25P16_PIN_CLOCK = 1; M25P16_PIN_CLOCK = 0;} -#define CLOCK_FALLING() {M25P16_PIN_CLOCK = 0; M25P16_PIN_CLOCK = 1;} -/*---------------------------------------------------------------------------*/ -/* Bit-Bang write a byte to the chip */ -static void -bit_bang_write(uint8_t byte) CC_NON_BANKED -{ - uint8_t i; - uint8_t bit; - - /* bit-by-bit */ - for(i = 0x80; i > 0; i >>= 1) { - /* Is the bit set? */ - bit = 0; - if(i & byte) { - /* If it was set, we want to send 1 */ - bit = 1; - } - /* Send the bit */ - M25P16_PIN_SER_I = bit; - /* Clock - Rising */ - CLOCK_RISING(); - } -} -/*---------------------------------------------------------------------------*/ -/* Bit-Bang read a byte from the chip */ -static uint8_t -bit_bang_read() CC_NON_BANKED -{ - int8_t i; - uint8_t bits = 0; - - /* bit-by-bit */ - for(i = 7; i >= 0; i--) { - /* Clock - Falling */ - CLOCK_FALLING(); - - /* Read the bit */ - bits |= (M25P16_PIN_SER_O << i); - } - return bits; -} -/*---------------------------------------------------------------------------*/ -static void -select() CC_NON_BANKED -{ - /* Read current ser/par value */ - uint8_t ser_par = n740_ser_par_get(); - - M25P16_PIN_CLOCK = 0; - - ser_par &= ~N740_SER_PAR_CHIP_SEL; /* Select Flash */ - - /* Write the new status back to the ser/par */ - n740_ser_par_set(ser_par); -} -/*---------------------------------------------------------------------------*/ -static void -deselect() CC_NON_BANKED -{ - /* Read current ser/par value */ - uint8_t ser_par = n740_ser_par_get(); - - ser_par |= N740_SER_PAR_CHIP_SEL; /* De-Select Flash */ - - /* Write the new status back to the ser/par */ - n740_ser_par_set(ser_par); -} -/*---------------------------------------------------------------------------*/ -void -m25p16_wren() -{ - select(); - bit_bang_write(M25P16_I_WREN); - deselect(); - - while(!M25P16_WEL()); -} -/*---------------------------------------------------------------------------*/ -void -m25p16_wrdi() -{ - select(); - bit_bang_write(M25P16_I_WRDI); - deselect(); -} -/*---------------------------------------------------------------------------*/ -void -m25p16_rdid(struct m25p16_rdid *rdid) -{ - uint8_t i; - - select(); - bit_bang_write(M25P16_I_RDID); - - rdid->man_id = bit_bang_read(); - rdid->mem_type = bit_bang_read(); /* Device ID MSB */ - rdid->mem_size = bit_bang_read(); /* Device ID LSB */ - rdid->uid_len = bit_bang_read(); - for(i = 0; i < rdid->uid_len; i++) { - rdid->uid[i] = bit_bang_read(); - } - deselect(); -} -/*---------------------------------------------------------------------------*/ -uint8_t -m25p16_rdsr() -{ - uint8_t rv; - - select(); - bit_bang_write(M25P16_I_RDSR); - rv = bit_bang_read(); - deselect(); - - return rv; -} -/*---------------------------------------------------------------------------*/ -void -m25p16_wrsr(uint8_t val) -{ - m25p16_wren(); /* Write Enable */ - - select(); - ENERGEST_ON(ENERGEST_TYPE_FLASH_WRITE); - bit_bang_write(M25P16_I_WRSR); - bit_bang_write(val); - ENERGEST_OFF(ENERGEST_TYPE_FLASH_WRITE); - deselect(); -} -/*---------------------------------------------------------------------------*/ -void -m25p16_read(uint8_t * addr, uint8_t * buff, uint8_t buff_len) -{ - uint8_t i; - - select(); - ENERGEST_ON(ENERGEST_TYPE_FLASH_READ); - -#if M25P16_READ_FAST - bit_bang_write(M25P16_I_FAST_READ); -#else - bit_bang_write(M25P16_I_READ); -#endif - - /* Write the address, MSB in addr[0], bits [7:5] of the MSB: 'don't care' */ - for(i = 0; i < 3; i++) { - bit_bang_write(addr[i]); - } - - /* For FAST_READ, send the dummy byte */ -#if M25P16_READ_FAST - bit_bang_write(M25P16_DUMMY_BYTE); -#endif - - for(i = 0; i < buff_len; i++) { - buff[i] = ~bit_bang_read(); - } - ENERGEST_OFF(ENERGEST_TYPE_FLASH_READ); - deselect(); -} -/*---------------------------------------------------------------------------*/ -void -m25p16_pp(uint8_t * addr, uint8_t * buff, uint8_t buff_len) -{ - uint8_t i; - - m25p16_wren(); /* Write Enable */ - - select(); - ENERGEST_ON(ENERGEST_TYPE_FLASH_WRITE); - bit_bang_write(M25P16_I_PP); - - /* Write the address, MSB in addr[0] */ - for(i = 0; i < 3; i++) { - bit_bang_write(addr[i]); - } - - /* Write the bytes */ - for(i = 0; i < buff_len; i++) { - bit_bang_write(~buff[i]); - } - ENERGEST_OFF(ENERGEST_TYPE_FLASH_WRITE); - deselect(); -} -/*---------------------------------------------------------------------------*/ -void -m25p16_se(uint8_t s) -{ - m25p16_wren(); /* Write Enable */ - - select(); - ENERGEST_ON(ENERGEST_TYPE_FLASH_WRITE); - bit_bang_write(M25P16_I_SE); - bit_bang_write(s); - bit_bang_write(0x00); - bit_bang_write(0x00); - deselect(); - ENERGEST_OFF(ENERGEST_TYPE_FLASH_WRITE); -} -/*---------------------------------------------------------------------------*/ -void -m25p16_be() -{ - m25p16_wren(); /* Write Enable */ - - select(); - bit_bang_write(M25P16_I_BE); - deselect(); -} -/*---------------------------------------------------------------------------*/ -void -m25p16_dp() -{ - select(); - bit_bang_write(M25P16_I_DP); - deselect(); -} -/*---------------------------------------------------------------------------*/ -/* - * Release Deep Power Down. We do NOT read the Electronic Signature - */ -void -m25p16_res() -{ - select(); - bit_bang_write(M25P16_I_RES); - deselect(); - /* a few usec between RES and standby */ - while(M25P16_WIP()); -} -/*---------------------------------------------------------------------------*/ -/** - * Release Deep Power Down. Read and return the Electronic Signature - * must return 0x14 - * - * \return The old style Electronic Signature. This must be 0x14 - */ -uint8_t -m25p16_res_res() -{ - uint8_t rv; - - select(); - bit_bang_write(M25P16_I_RES); - bit_bang_write(M25P16_DUMMY_BYTE); - bit_bang_write(M25P16_DUMMY_BYTE); - bit_bang_write(M25P16_DUMMY_BYTE); - - rv = bit_bang_read(); - - deselect(); - - /* a few usec between RES and standby */ - while(M25P16_WIP()); - return rv; -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/sensinode/dev/m25p16.h b/platform/sensinode/dev/m25p16.h deleted file mode 100644 index 580564953..000000000 --- a/platform/sensinode/dev/m25p16.h +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Header file for the control of the M25P16 on sensinode N740s. - * - * \author - * George Oikonomou - - */ - -#ifndef M25P16_H_ -#define M25P16_H_ - -/* Instruction Set */ -#define M25P16_I_WREN 0x06 /* Write Enable */ -#define M25P16_I_WRDI 0x04 /* Write Disable */ -#define M25P16_I_RDID 0x9F /* Read Identification */ -#define M25P16_I_RDSR 0x05 /* Read Status Register */ -#define M25P16_I_WRSR 0x01 /* Write Status Register */ -#define M25P16_I_READ 0x03 /* Read Data Bytes */ -#define M25P16_I_FAST_READ 0x0B /* Read Data Bytes at Higher Speed */ -#define M25P16_I_PP 0x02 /* Page Program */ -#define M25P16_I_SE 0xD8 /* Sector Erase */ -#define M25P16_I_BE 0xC7 /* Bulk Erase */ -#define M25P16_I_DP 0xB9 /* Deep Power-down */ -#define M25P16_I_RES 0xAB /* Release from Deep Power-down */ - -/* Dummy Byte - Used in FAST_READ and RES */ -#define M25P16_DUMMY_BYTE 0x00 - -/* Pins */ -#define M25P16_PIN_CLOCK P1_5 -#define M25P16_PIN_SER_I P1_6 -#define M25P16_PIN_SER_O P1_7 - -/* Status Register Bits */ -#define M25P16_SR_SRWD 0x80 /* Status Register Write Disable */ -#define M25P16_SR_BP2 0x10 /* Block Protect 2 */ -#define M25P16_SR_BP1 0x08 /* Block Protect 1 */ -#define M25P16_SR_BP0 0x04 /* Block Protect 0 */ -#define M25P16_SR_BP 0x1C /* All Block Protect Bits */ -#define M25P16_SR_WEL 0x02 /* Write Enable Latch */ -#define M25P16_SR_WIP 0x01 /* Write in Progress */ - -/* Do we use READ or FAST_READ to read? Fast by default */ -#ifdef M25P16_CONF_READ_FAST -#define M25P16_READ_FAST M25P16_CONF_READ_FAST -#else -#define M25P16_READ_FAST 1 -#endif -/*---------------------------------------------------------------------------*/ -/** \brief Device Identifier - * - * Holds the value of the device identifier, returned by the RDID instruction. - * - * After a correct RDID, this structure should hold the following values: - * man_id = 0x20, mem_type = 0x20, mem_size = 0x15, uid_len = 0x10. - * - * UID holds optional Customized Factory Data (CFD) content. The CFD bytes are - * read-only and can be programmed with customers data upon their request. - * If the customers do not make requests, the devices are shipped with all the - * CFD bytes programmed to 0x00. - */ -struct m25p16_rdid { - uint8_t man_id; /** Manufacturer ID */ - uint8_t mem_type; /** Memory Type */ - uint8_t mem_size; /** Memory Size */ - uint8_t uid_len; /** Unique ID length */ - uint8_t uid[16]; /** Unique ID */ -}; -/*---------------------------------------------------------------------------*/ -/** - * \brief Retrieve Block Protect Bits from the status register - * - * This macro returns the software block protect status on the device - * by reading the value of the BP bits ([5:3]) in the Status Register - */ -#define M25P16_BP() (m25p16_rdsr() & M25P16_SR_BP) -/** - * \brief Check for Write in Progress - * \retval 1 Write in progress - * \retval 0 Write not in progress - * - * This macro checks if the device is currently in the middle of a write cycle - * by reading the value of the WIP bit (bit 0) in the Status Register - */ -#define M25P16_WIP() (m25p16_rdsr() & M25P16_SR_WIP) -/** - * \brief Check for Write-Enable - * \retval 1 Write enabled - * \retval 0 Write disabled - * - * This macro checks if the device is ready to accept a write instruction - * by reading the value of the WEL bit (bit 1) in the Status Register - */ -#define M25P16_WEL() (m25p16_rdsr() & M25P16_SR_WEL) -/*---------------------------------------------------------------------------*/ -/** - * \brief Write Enable (WREN) instruction. - * - * Completing a WRDI, PP, SE, BE and WRSR - * resets the write enable latch bit, so this instruction should be used every - * time before trying to write. - */ -void m25p16_wren(); - -/** - * \brief Write Disable (WRDI) instruction - */ -void m25p16_wrdi(); - -/** - * \brief Read Identifier (RDID)instruction - * - * \param rdid Pointer to a struct which will hold the information returned - * by the RDID instruction - */ -void m25p16_rdid(struct m25p16_rdid *rdid); - -/** - * \brief Read Status Register (RDSR) instruction - * - * \return Value of the status register - * - * Reads and returns the value of the status register on the Flash Chip - */ -uint8_t m25p16_rdsr(); - -/** - * \brief Write Status Register (WRSR) instruction - * \param val Value to be written to the status register - * - * This instruction does not afect bits 6, 5, 1 and 0 of the SR. - */ -void m25p16_wrsr(uint8_t val); - -/** - * \brief Read Data Bytes (READ) instruction - * \param addr 3 byte array holding the read start address. MSB stored in - * addr[0] and LSB in addr[2] - * \param buff Pointer to a buffer to hold the read bytes. - * \param buff_len Number of bytes to read. buff must be long enough to hold - * buff_len bytes - * - * The bytes will be inverted after being read, so that a value of 0xFF (empty) - * in the flash will read as 0x00 - */ -void m25p16_read(uint8_t * addr, uint8_t * buff, uint8_t buff_len); - -/** - * \brief Program Page (PP) instruction - * \param addr 3 byte array holding the write start address. MSB stored in - * addr[0] and LSB in addr[2] - * \param buff Pointer to a buffer with the data to be written - * \param buff_len Number of bytes to write, Maximum 256 bytes. - * - * Write BUFF_LEN bytes stored in BUFF to flash, starting from location - * ADDR. BUFF_LEN may not exceed 256. ADDR should point to a 3 byte array, - * with the address MSB stored in position 0 and LSB in position 2 - * - * If the start address + buff_len exceed page boundaries, the write will - * wrap to the start of the same page (the page at addr[2:1]). - * - * The bytes will be inverted before being written, so that a value of 0xFF - * will be written as 0x00 (and subsequently correctly read as 0xFF by READ) - * - * This function will set the WEL bit on the SR before attempting to write, - * so the calling function doesn't need to worry about this. - * - * This call is asynchronous. It will return before the write cycle has - * completed. Thus, user software must check the WIP bit Write In Progress) - * before sending further instructions. This can take up to 5 msecs (typical - * duration for a 256 byte write is 640 usec) - */ -void m25p16_pp(uint8_t * addr, uint8_t * buff, uint8_t buff_len); - -/** - * \brief Sector Erase (SE) instruction - * \param s The number of the sector to be erased - * - * Delete the entire sector number s, by setting it's contents to all 0xFF - * (which will read as 0x00 by READ). The flash is broken down into 32 sectors, - * 64 KBytes each. - * - * This function will set the WEL bit on the SR before attempting to write, - * so the calling function doesn't need to worry about this. - * - * This call is asynchronous. It will return before the write cycle has - * completed. Thus, user software must check the WIP bit Write In Progress) - * before sending further instructions. This can take up to 3 secs (typical - * duration 600 msec) - */ -void m25p16_se(uint8_t s); /* Sector Erase */ - - -/** - * \brief Bulk Erase (SE) instruction - * - * Delete the entire memory, by setting it's contents to all 0xFF - * (which will read as 0x00 by READ). - * - * This function will set the WEL bit on the SR before attempting to write, - * so the calling function doesn't need to worry about this. - * - * This call is asynchronous. It will return before the write cycle has - * completed. Thus, user software must check the WIP bit Write In Progress) - * before sending further instructions. - * - * This instructions takes a very long time to complete and must be used with - * care. It can take up to 40 secs (yes, secs). A typical duration is 13 secs - */ -void m25p16_be(); - -/** - * \brief Deep Power Down (DP) instruction - * - * Puts the device into its lowers power consumption mode (This is not the same - * as the stand-by mode caused by de-selecting the device). While the device - * is in DP, it will accept no instruction except a RES (Release from DP). - * - * This call is asynchronous and will return as soon as the instruction - * sequence has been written but before the device has actually entered DP - * - * Dropping to DP takes 3usec and Resuming from DP takes at least 1.8usec, so - * this sequence should not be used when the sleep interval is estimated to be - * short (read as: don't DP then RES then DP repeatedly) - */ -void m25p16_dp(); /* Deep Power down */ - -/** - * \brief Release from Deep Power Down (RES) instruction - * - * Take the device out of the Deep Power Down mode and bring it to standby. - * Does not read the electronic signature. - * - * This call is synchronous. When it returns the device will be in standby - * mode. - * - * Dropping to DP takes 3usec and Resuming from DP takes at least 1.8usec, so - * this sequence should not be used when the sleep interval is estimated to be - * short (read as: don't DP then RES then DP repeatedly) - */ -void m25p16_res(); - -/** - * \brief Release from Deep Power Down (RES) and Read Electronic - * Signature instruction - * - * \return The value of the electronic signature. This is provided for backward - * compatibility and must always be 0x14 - * - * Take the device out of the Deep Power Down mode and bring it to standby. - * Does not read the electronic signature. - * - * This call is synchronous. When it returns the device will be in standby - * mode. - * - * Dropping to DP takes 3usec and Resuming from DP takes at least 1.8usec, so - * this sequence should not be used when the sleep interval is estimated to be - * short (read as: don't DP then RES then DP repeatedly) - */ -uint8_t m25p16_res_res(); - -#endif /* M25P16_H_ */ diff --git a/platform/sensinode/dev/models.c b/platform/sensinode/dev/models.c deleted file mode 100644 index 15b21fffa..000000000 --- a/platform/sensinode/dev/models.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Model-specific functions for Sensinode devices. - * - * Bankable - * - * \author - * George Oikonomou - - */ - -#include "dev/models.h" -#include "dev/uart1.h" -#include "dev/m25p16.h" -/*---------------------------------------------------------------------------*/ -void -model_init() -{ -#ifdef MODEL_N740 - /* - * We want to prevent the dongle from controlling the state of the - * analog switch on the N740s. - * - * Set P0_3 as out and start with P0_3=0 (USB and Light selected) - */ - P0DIR |= 0x08; /* P0_3 out */ - P0_3 = 0; - - /* Init the serial-parallel chip for N740s. This will also 'init' LEDs */ - n740_ser_par_init(); - - /* Put the Serial Flash in Deep Power mode */ - n740_analog_deactivate(); - -#if M25P16_CONF_ON - m25p16_dp(); -#endif /* SERIAL_FLASH_CONF_ON */ - - n740_ser_par_set(0); -#endif -} -/*---------------------------------------------------------------------------*/ -void -model_uart_intr_en() -{ -#ifdef MODEL_N740 - /* - * Dirty, ugly hack for the N740 USART1 RX issue: - * When the USB is for whatever reason disabled (either disconnected or the - * analog switch has switched to the D-connector), RX starts flowing down - * pin 1.7 (and the line stays low), resulting in non-stop UART1_RX - * interrupts. So, we only acknowledge the interrupt when the line is - * high and the dongle is connected (thus we are on USB). - * - * For all other models, just turn the interrupt on - * - * Interrupts will only turn on if UART_ONE_CONF_WITH_INPUT is defined 1 - */ - if(P1_7 == 1 && P0_3 == 0) { - UART1_RX_INT(1); - } -#else - UART1_RX_INT(1); -#endif -} diff --git a/platform/sensinode/dev/models.h b/platform/sensinode/dev/models.h deleted file mode 100644 index 6cf4916f4..000000000 --- a/platform/sensinode/dev/models.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef MODELS_H_ -#define MODELS_H_ - -/* Define model text */ -#ifdef MODEL_N100 -#define SENSINODE_MODEL "N100 Module" -#endif -#ifdef MODEL_N600 -#define SENSINODE_MODEL "N600 NanoRouter USB" -#endif -#ifdef MODEL_N601 -#define SENSINODE_MODEL "N601 NanoRouter USB" -#endif -#ifdef MODEL_N710 -#define SENSINODE_MODEL "N710 NanoSensor" -#endif -#ifdef MODEL_N711 -#define SENSINODE_MODEL "N711 NanoSensor" -#endif -#ifdef MODEL_N740 -#define SENSINODE_MODEL "N740 NanoSensor" -#endif - -#ifndef SENSINODE_MODEL -#define SENSINODE_MODEL "N100 Module" -#endif - -#ifndef FLASH_SIZE -#define FLASH_SIZE "F128" -#endif - -/* - * N740 has a serial-parallel chip onboard - * Defines and functions to control it - */ -#ifdef MODEL_N740 -#include "dev/n740.h" - -#else -/* All other models use these LED pins */ -#define LED1_PIN P0_4 -#define LED2_PIN P0_5 -#endif - -#ifdef MODEL_N711 -#define BUTTON1_PIN P0_6 -#define BUTTON2_PIN P0_7 -#endif - -/* Sensor pins */ - -#ifdef MODEL_N711 -#define LIGHT_PIN P0_0 -#define TEMP_PIN P0_1 -#endif - -/* Model-Specific startup functions */ -void model_init(); -void model_uart_intr_en(); -#endif /* MODELS_H_ */ diff --git a/platform/sensinode/dev/n740.c b/platform/sensinode/dev/n740.c deleted file mode 100644 index de1e20fd1..000000000 --- a/platform/sensinode/dev/n740.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * This file provides functions to control various chips on the - * Sensinode N740s: - * - * - The 74HC595D is an 8-bit serial in-parallel out shift register. - * LEDs are connected to this chip. It also serves other functions such as - * enabling/disabling the Accelerometer (see n740.h). - * - The 74HC4053D is a triple, 2-channel analog mux/de-mux. - * It switches I/O between the USB and the D-Connector. - * It also controls P0_0 input source (Light Sensor / External I/O) - * - * Mux/De-mux: Connected to P0_3 (set to output in models.c - * Changing the state of the mux/demux can have catastrophic (tm) results - * on our software. If we are not careful, we risk entering a state where - * UART1 RX interrupts are being generated non-stop. Only change its state - * via the function in this file. - * - * Shift Register: - * For the shift register we can: - * - write a new instruction - * - remember and retrieve the last instruction sent - * - * The chip is connected to CPU pins as follows: - * - P0_2: Serial Data Input - * - P1_3: Shift Register Clock Input - * - P1_1: Storage Register Clock - * - * This file can be placed in any bank. - * - * \author - * George Oikonomou - - */ - -#include "dev/n740.h" -#include "dev/uart1.h" -#include "8051def.h" - -/* - * This variable stores the most recent instruction sent to the ser-par chip. - * We declare it as static and return its value through n740_ser_par_get(). - */ -static CC_AT_DATA uint8_t ser_par_status; - -/*---------------------------------------------------------------------------*/ -/* Init the serial-parallel chip: - * - Set I/O direction for all 3 pins (P0_2, P1_1 and P1_3) to output - */ -void -n740_ser_par_init() -{ - /* bus_init and uart1_init also touch the I/O direction for those pins */ - P1DIR |= 0x0A; - P0DIR |= 0x04; -} -/*---------------------------------------------------------------------------*/ -/* - * Send a command to the N740 serial-parallel chip. Each command is a single - * byte, each bit controls a different feature on the sensor. - */ -void -n740_ser_par_set(uint8_t data) -{ - uint8_t i; - uint8_t mask = 1; - uint8_t temp = 0; - - DISABLE_INTERRUPTS(); - /* bit-by-bit */ - for(i = 0; i < 8; i++) { - temp = (data & mask); - /* Is the bit set? */ - if(i && temp) { - /* If it was set, we want to send 1 */ - temp >>= i; - } - /* Send the bit */ - P0_2 = temp; - /* Shift */ - P1_3 = 1; - P1_3 = 0; - mask <<= 1; - } - /* Move to Par-Out */ - P1_1 = 1; - P1_1 = 0; - ENABLE_INTERRUPTS(); - - /* Right, we're done. Save the new status in ser_par_status */ - ser_par_status = data; -} -/*---------------------------------------------------------------------------*/ -/* This function returns the last value sent to the ser-par chip on the N740. - * - * The caveat here is that we must always use n740_set_ser_par() to send - * commands to the ser-par chip, never write directly. - * - * If any other function sends a command directly, ser_par_status and the - * actual status will end up out of sync. - */ -uint8_t -n740_ser_par_get() -{ - return ser_par_status; -} -/*---------------------------------------------------------------------------*/ -void -n740_analog_switch(uint8_t state) -{ - /* Turn off the UART RX interrupt before switching */ - DISABLE_INTERRUPTS(); - UART1_RX_INT(0); - - /* Switch */ - P0_3 = state; - - /* If P0_3 now points to the USB and nothing is flowing down P1_7, - * enable the interrupt again */ - if(P1_7 == 1 && P0_3 == N740_ANALOG_SWITCH_USB) { - UART1_RX_INT(1); - } - ENABLE_INTERRUPTS(); -} -/*---------------------------------------------------------------------------*/ -/* - * Activate the the 74HC4053D analog switch U5 on the N740 and at the same - * time set relevant pins to Peripheral I/O mode. This stops communications - * with the serial flash and enables UART1 I/O - */ -void -n740_analog_activate() -{ - uint8_t ser_par = n740_ser_par_get(); - ser_par &= ~N740_SER_PAR_U5_ENABLE; /* Turn on */ - - N740_PINS_PER_IO(); - - n740_ser_par_set(ser_par); -} -/*---------------------------------------------------------------------------*/ -/* - * De-Activate the the 74HC4053D analog switch U5 on the N740 and at the same - * time set relevant pins to GP I/O mode. This effectively prepares us to - * start talking with the serial flash chip - */ -void -n740_analog_deactivate() -{ - uint8_t ser_par = n740_ser_par_get(); - ser_par |= N740_SER_PAR_U5_ENABLE; /* Turn off */ - - n740_ser_par_set(ser_par); - - N740_PINS_GPIO(); -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/sensinode/dev/n740.h b/platform/sensinode/dev/n740.h deleted file mode 100644 index 1bb74380e..000000000 --- a/platform/sensinode/dev/n740.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Header File for the module which controls the Sensinode N740 - * 8-bit serial-in/serial or parallel-out shift register. - * - * This is where the Accelerometer, Leds, Light and Battery Sensors - * are connected. - * - * \author - * George Oikonomou - - */ - -#ifndef N740SERPAR_H_ -#define N740SERPAR_H_ - -#include "8051def.h" - -#define N740_SER_PAR_ACC_GSEL 0x01 /* Acceleration Sensor g-Select */ -#define N740_SER_PAR_CHIP_SEL 0x02 /* Flash Chip Select */ -#define N740_SER_PAR_LIGHT 0x04 /* Light Sensor */ -#define N740_SER_PAR_ACC 0x08 /* Acceleration Sensor */ -#define N740_SER_PAR_RF_IN_GAIN 0x10 /* Receiver Amplifier, best not set */ -#define N740_SER_PAR_U5_ENABLE 0x20 /* U5 analog switch enable */ -#define N740_SER_PAR_LED_GREEN 0x40 /* Led 1 */ -#define N740_SER_PAR_LED_RED 0x80 /* Led 2 */ - -#define N740_ANALOG_SWITCH_USB 0 -#define N740_ANALOG_SWITCH_SERIAL 1 - -#define N740_PINS 0xE0 -#define N740_PINS_GPIO() {P1SEL &= ~N740_PINS;} -#define N740_PINS_PER_IO() {P1SEL |= N740_PINS;} - -/* Serial/Parallel Shift Register (74HC595D) Functions */ -void n740_ser_par_init(void); -void n740_ser_par_set(uint8_t data); -uint8_t n740_ser_par_get(void); - -/* Analog Switch (U5 - 74HC4053D) Functions */ -void n740_analog_switch(uint8_t state); -void n740_analog_activate(); -void n740_analog_deactivate(); - -#endif /* N740SERPAR_H_ */ diff --git a/platform/sensinode/dev/sensinode-sensors.c b/platform/sensinode/dev/sensinode-sensors.c deleted file mode 100644 index c6dbbbfd5..000000000 --- a/platform/sensinode/dev/sensinode-sensors.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * This module centrally controls all sensors on sensinode devices - * - * It respects configuration in contiki-conf.h - * - * \author - * George Oikonomou - - */ - -#include "dev/sensinode-sensors.h" -#include "sys/energest.h" - -const struct sensors_sensor *sensors[] = { -#if ADC_SENSOR_ON - &adc_sensor, -#endif -#if BUTTON_SENSOR_ON - &button_1_sensor, - &button_2_sensor, -#endif - 0 -}; - -unsigned char sensors_flags[(sizeof(sensors) / sizeof(struct sensors_sensor *))]; - -/*---------------------------------------------------------------------------*/ -void -sensinode_sensors_activate() -{ - struct sensors_sensor *sensor; - sensor = sensors_first(); - while(sensor) { - sensor->configure(SENSORS_ACTIVE, 1); - sensor = sensors_next(sensor); - } - ENERGEST_ON(ENERGEST_TYPE_SENSORS); -} -/*---------------------------------------------------------------------------*/ -void -sensinode_sensors_deactivate() -{ - struct sensors_sensor *sensor; - sensor = sensors_first(); - while(sensor) { - sensor->configure(SENSORS_ACTIVE, 0); - sensor = sensors_next(sensor); - } - ENERGEST_OFF(ENERGEST_TYPE_SENSORS); -} diff --git a/platform/sensinode/dev/sensinode-sensors.h b/platform/sensinode/dev/sensinode-sensors.h deleted file mode 100644 index 503499ec8..000000000 --- a/platform/sensinode/dev/sensinode-sensors.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Defines for the sensors on the various Sensinode models. - * - * Sensors will be off by default, unless turned on explicitly - * in contiki-conf.h - * - * If you enable sensors generating interrupts, make sure you include - * this file in the file containing main(). - * - * \author - * George Oikonomou - - */ - -#ifndef SENSINODE_SENSORS_H_ -#define SENSINODE_SENSORS_H_ - -#include "cc2430_sfr.h" -#include "contiki-conf.h" -#include "dev/models.h" -#include "lib/sensors.h" - -void sensinode_sensors_activate(); -void sensinode_sensors_deactivate(); - -/* ADC Sensor Types */ -#define ADC_SENSOR "ADC" - -#define ADC_SENSOR_TYPE_TEMP 0 -#define ADC_SENSOR_TYPE_ACC_X 1 -#define ADC_SENSOR_TYPE_ACC_Y 2 -#define ADC_SENSOR_TYPE_ACC_Z 3 -#define ADC_SENSOR_TYPE_VDD 4 -#define ADC_SENSOR_TYPE_LIGHT 5 -#define ADC_SENSOR_TYPE_BATTERY 6 - -/* Defines to help us control Acc and Ill individually */ -#define ADC_VAL_NONE 0x00 -#define ADC_VAL_ALL 0x01 -#define ADC_VAL_LIGHT_ON 0x04 -#define ADC_VAL_ACC_ON 0x08 -#define ADC_VAL_ACC_GSEL 0x10 - -#ifdef ADC_SENSOR_CONF_ON -#define ADC_SENSOR_ON ADC_SENSOR_CONF_ON -#endif /* ADC_SENSOR_CONF_ON */ - -#if ADC_SENSOR_ON -extern const struct sensors_sensor adc_sensor; -#endif /* ADC_SENSOR_ON */ - -/* - * Accelerometer. Available on N740 only. - * This is a Freescale Semiconductor MMA7340L (3 axis, 3/11g) - * X: P0_5 - * Y: P0_6 - * Z: P0_7 - */ -#ifdef MODEL_N740 -#ifdef ACC_SENSOR_CONF_ON -#define ACC_SENSOR_ON ACC_SENSOR_CONF_ON -#endif /* ACC_SENSOR_CONF_ON */ - -/* Accelerometer g-Select - Define for +/-11g, +/-3g Otherwise */ -#if ACC_SENSOR_ON -#ifdef ACC_SENSOR_CONF_GSEL -#define ACC_SENSOR_GSEL ACC_SENSOR_CONF_GSEL -#endif /* ACC_SENSOR_CONF_GSEL */ -#endif /* ACC_SENSOR_ON */ -#endif /* MODEL_N740 */ - -/* - * Buttons - * N740: P1_0, P0_4 - * N711: P0_6, P0_7 - * N710: Unknown. This will mainly influence which ISRs to declare here - */ -#if defined(MODEL_N740) || defined(MODEL_N711) -#ifdef BUTTON_SENSOR_CONF_ON -#define BUTTON_SENSOR_ON BUTTON_SENSOR_CONF_ON -#endif /* BUTTON_SENSOR_CONF_ON */ -#endif /* defined(MODEL_FOO) */ - -#define BUTTON_1_SENSOR "Button 1" -#define BUTTON_2_SENSOR "Button 2" -#define BUTTON_SENSOR BUTTON_1_SENSOR - -#if BUTTON_SENSOR_ON -extern const struct sensors_sensor button_1_sensor; -extern const struct sensors_sensor button_2_sensor; -#define button_sensor button_1_sensor - -/* Port 0 ISR needed for both models */ -void port_0_ISR(void) __interrupt (P0INT_VECTOR); - -/* Only declare the Port 1 ISR for N740 */ -#ifdef MODEL_N740 -void port_1_ISR(void) __interrupt (P1INT_VECTOR); -#endif /* MODEL_N740 */ -#endif /* BUTTON_SENSOR_ON */ - -/* - * Light - N710, N711, N740 - * N740: P0_0 - * N711: P0_0 - * N710: P?_? - */ -#if defined(MODEL_N740) || defined(MODEL_N711) || defined(MODEL_N710) -#ifdef LIGHT_SENSOR_CONF_ON -#define LIGHT_SENSOR_ON LIGHT_SENSOR_CONF_ON -#endif /* LIGHT_SENSOR_CONF_ON */ -#endif /* defined(MODEL_FOO) */ - -/* - * Battery - N711, N740, (N710 likely) - * N740: P0_1 - * Unknown for other models - */ -#if defined(MODEL_N740) || defined(MODEL_N711) || defined(MODEL_N710) -#ifdef BATTERY_SENSOR_CONF_ON -#define BATTERY_SENSOR_ON BATTERY_SENSOR_CONF_ON -#endif /* BATTERY_SENSOR_CONF_ON */ -#endif /* defined(MODEL_FOO) */ - -/* Temperature - Available on all cc2430 devices */ -#ifdef TEMP_SENSOR_CONF_ON -#define TEMP_SENSOR_ON TEMP_SENSOR_CONF_ON -#endif /* TEMP_SENSOR_CONF_ON */ - -/* Supply Voltage - Available on all cc2430 devices*/ -#ifdef VDD_SENSOR_CONF_ON -#define VDD_SENSOR_ON VDD_SENSOR_CONF_ON -#endif /* VDD_SENSOR_CONF_ON */ - -#endif /* SENSINODE_SENSORS_H_ */ diff --git a/platform/sensinode/dev/slip-arch.c b/platform/sensinode/dev/slip-arch.c deleted file mode 100644 index 422847cf9..000000000 --- a/platform/sensinode/dev/slip-arch.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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. - * - */ - -/* - * Sensinode/cc2430 SLIP routines (over UART1). - */ - -#include "dev/slip.h" -#include "dev/uart1.h" -/*---------------------------------------------------------------------------*/ -void -slip_arch_writeb(unsigned char c) -{ - uart1_writeb(c); -} -/*---------------------------------------------------------------------------*/ -void -slip_arch_init(unsigned long ubr) -{ - uart1_set_input(slip_input_byte); -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/sensinode/disco.c b/platform/sensinode/disco.c deleted file mode 100644 index 63d95c6b9..000000000 --- a/platform/sensinode/disco.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Disco server sources - * (embedded part of the DISCOBALL project) - * - * It objective is to receive a code file over UDP, store it in - * external flash and disseminate it to other nodes of the - * 6LoWPAN network. - * - * For this to work, the image must be co-hosted with the BooTTY! - * bootloader, which will move the image from external to internal - * flash. - * - * To link this application in your contiki image, all you need to - * do is to add this line: - * OFFSET_FIRMWARE=1 - * to your project's makefile - * - * \author - * George Oikonomou - - */ - -#include "contiki.h" -#include "contiki-net.h" -#include "sys/clock.h" -#include "sys/ctimer.h" -#include "dev/watchdog.h" - -#include "dev/n740.h" -#include "dev/m25p16.h" - -#include "disco.h" -/*---------------------------------------------------------------------------*/ -#define DEBUG DEBUG_NONE -#include "net/ip/uip-debug.h" -/*---------------------------------------------------------------------------*/ -#if BATMON_CONF_ENABLED -void batmon_log(uint8_t trigger); - -#define LOG_TRIGGER_OAP_DISCO_START 0x01 -#define LOG_TRIGGER_OAP_DISCO_DONE 0x02 -#define LOG_TRIGGER_OAP_DISCO_ABORT 0x03 -#else -#define batmon_log(t) do { } while(0); -#endif -/*---------------------------------------------------------------------------*/ -static struct uip_udp_conn *server_conn; -static struct disco_request_pdu *req; -static struct disco_response_pdu resp; -static struct disco_seed seed; -static uint8_t state; -static uint8_t sector; -static uint16_t interval; -static struct ctimer disco_timer; - -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) - -extern uint16_t uip_len; -extern void *uip_appdata; - -__xdata __at(BOOTTY_CMD_LOCATION) static uint8_t bd; -/*---------------------------------------------------------------------------*/ -static void timer_handler(void *p); -/*---------------------------------------------------------------------------*/ -static void -abort() CC_NON_BANKED -{ - PRINTF("Disco: Abort @ %lu\n", clock_seconds()); - n740_analog_deactivate(); - m25p16_dp(); - n740_analog_activate(); - state = DISCO_STATE_LISTENING; - memset(&seed, 0, sizeof(seed)); - ctimer_stop(&disco_timer); - batmon_log(LOG_TRIGGER_OAP_DISCO_ABORT); -} -/*---------------------------------------------------------------------------*/ -static void -restart_timer(uint16_t t) CC_NON_BANKED -{ - interval = t; - ctimer_stop(&disco_timer); - ctimer_set(&disco_timer, interval, timer_handler, &state); -} -/*---------------------------------------------------------------------------*/ -static void -timer_handler(void *p) -{ - uint8_t *s = p; - uint8_t wip; - - PRINTF("Disco: @ %lu, s: %u\n", clock_seconds(), *s); - - if(*s == DISCO_STATE_PREPARING) { - n740_analog_deactivate(); - wip = M25P16_WIP(); - n740_analog_activate(); - - if(wip) { - restart_timer(DISCO_TIMEOUT_PREPARE); - } else { - PRINTF("Disco: Erased %u\n", sector); - if((sector & 1) == 0) { - sector++; - PRINTF("Disco: Next %u\n", sector); - n740_analog_deactivate(); - m25p16_se(sector); - n740_analog_activate(); - restart_timer(DISCO_TIMEOUT_PREPARE); - } else { - PRINTF("Disco: Ready\n"); - *s = DISCO_STATE_READY; - resp.status = DISCO_CMD_INIT; - restart_timer(DISCO_TIMEOUT_ABORT); - server_conn->rport = seed.port; - uip_ipaddr_copy(&server_conn->ripaddr, &seed.addr); - uip_udp_packet_send(server_conn, &resp, DISCO_RESP_LEN_INIT); - - /* Restore server connection to allow data from any node */ - uip_create_unspecified(&server_conn->ripaddr); - server_conn->rport = 0; - } - } - } else if(*s == DISCO_STATE_READY) { - abort(); - } else if(*s == DISCO_STATE_REBOOTING) { - watchdog_reboot(); - } -} -/*---------------------------------------------------------------------------*/ -static uint8_t -is_protected(uint8_t a) CC_NON_BANKED -{ - uint8_t bp = M25P16_BP() >> 2; - - if(bp > 5) { - return SECTOR_PROTECTED; - } - - bp -= 1; - - if(a >= (32 - (1 << bp))) { - return SECTOR_PROTECTED; - } - return SECTOR_UNPROTECTED; -} -/*---------------------------------------------------------------------------*/ -static uint8_t -cmd_init() CC_NON_BANKED -{ - PRINTF("Disco: Init 0x%02x\n", req->addr[0]); - if(uip_datalen() != DISCO_LEN_INIT) { - PRINTF("Disco: Bad len (%u)\n", uip_datalen()); - resp.status = DISCO_ERR_BAD_LEN; - return DISCO_RESP_LEN_ERR; - } - n740_analog_deactivate(); - m25p16_res(); - sector = 2 * req->addr[0]; - if(is_protected(sector) == SECTOR_PROTECTED - || is_protected(sector + 1) == SECTOR_PROTECTED) { - resp.status = DISCO_ERR_PROTECTED; - n740_analog_activate(); - return DISCO_RESP_LEN_ERR; - } - m25p16_se(sector); - n740_analog_activate(); - state = DISCO_STATE_PREPARING; - restart_timer(DISCO_TIMEOUT_PREPARE); - - /* Store the sender's address/port so we can reply when ready */ - seed.port = UIP_UDP_BUF->srcport; - uip_ipaddr_copy(&seed.addr, &UIP_IP_BUF->srcipaddr); - PRINTF("Disco: OK\n"); - - batmon_log(LOG_TRIGGER_OAP_DISCO_START); - - return DISCO_RESPONSE_NONE; -} -/*---------------------------------------------------------------------------*/ -static uint8_t -cmd_write() CC_NON_BANKED -{ - PRINTF("Disco: Write 0x%02x%02x%02x\n", req->addr[0], req->addr[1], - req->addr[2]); - if(uip_datalen() != DISCO_LEN_WRITE) { - resp.status = DISCO_ERR_BAD_LEN; - return DISCO_RESP_LEN_ERR; - } - restart_timer(DISCO_TIMEOUT_ABORT); - n740_analog_deactivate(); - m25p16_pp(req->addr, req->data, DISCO_FLEN_DATA); - watchdog_periodic(); - while(M25P16_WIP()); - n740_analog_activate(); - resp.status = DISCO_CMD_WRITE; - memcpy(resp.addr, req->addr, DISCO_FLEN_ADDR); - return DISCO_RESP_LEN_WRITE; -} -/*---------------------------------------------------------------------------*/ -static uint8_t -cmd_switch() CC_NON_BANKED -{ - PRINTF("Disco: Switch 0x%02x\n", req->addr[0]); - if(uip_datalen() != DISCO_LEN_SWITCH) { - resp.status = DISCO_ERR_BAD_LEN; - return DISCO_RESP_LEN_ERR; - } - if(req->addr[0] > 15) { - resp.status = DISCO_ERR_BAD_OFFSET; - return DISCO_RESP_LEN_ERR; - } - - bd = BOOTTY_CMD_COPY_IMAGE; - bd |= req->addr[0]; - - resp.status = DISCO_CMD_SWITCH; - resp.addr[0] = req->addr[0]; - - restart_timer(DISCO_TIMEOUT_REBOOT); - state = DISCO_STATE_REBOOTING; - - return DISCO_RESP_LEN_SWITCH; -} -/*---------------------------------------------------------------------------*/ -static uint8_t -cmd_done() CC_NON_BANKED -{ - PRINTF("Disco: Done\n"); - if(uip_datalen() != DISCO_LEN_DONE) { - resp.status = DISCO_ERR_BAD_LEN; - return DISCO_RESP_LEN_ERR; - } - resp.status = DISCO_CMD_DONE; - - batmon_log(LOG_TRIGGER_OAP_DISCO_DONE); - - return DISCO_RESP_LEN_DONE; -} -/*---------------------------------------------------------------------------*/ -static uint8_t -event_handler(process_event_t ev) CC_NON_BANKED -{ - uint8_t rv = DISCO_RESPONSE_NONE; - - if(ev != tcpip_event) { - return rv; - } - - /* Always accept CMD_DONE */ - if(req->cmd == DISCO_CMD_DONE) { - return cmd_done(); - } - - /* Always accept switch too */ - if(req->cmd == DISCO_CMD_SWITCH) { - return cmd_switch(); - } - - switch(state) { - case DISCO_STATE_LISTENING: - req = uip_appdata; - if(req->cmd == DISCO_CMD_INIT) { - rv = cmd_init(); - } - break; - case DISCO_STATE_PREPARING: - PRINTF("Disco: Not Ready\n"); - resp.status = DISCO_ERR_NOT_READY; - rv = DISCO_RESP_LEN_ERR; - break; - case DISCO_STATE_READY: - req = uip_appdata; - if(req->cmd == DISCO_CMD_WRITE) { - rv = cmd_write(); - } else if(req->cmd == DISCO_CMD_INIT) { - resp.status = DISCO_ERR_INIT_DONE; - rv = DISCO_RESP_LEN_ERR; - } else if(req->cmd == DISCO_CMD_SWITCH) { - rv = cmd_switch(); - } - break; - } - return rv; -} -/*---------------------------------------------------------------------------*/ -PROCESS(disco_process, "Disco Server Process"); -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(disco_process, ev, data) -{ - uint8_t len; - - PROCESS_BEGIN(); - - PRINTF("Disco Server\n"); - - server_conn = udp_new(NULL, UIP_HTONS(0), NULL); - udp_bind(server_conn, UIP_HTONS(DISCO_UDP_PORT)); - - state = DISCO_STATE_LISTENING; - - while(1) { - PROCESS_YIELD(); - len = event_handler(ev); - - if(len > 0) { - server_conn->rport = UIP_UDP_BUF->srcport; - uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr); - uip_udp_packet_send(server_conn, &resp, len); - /* Restore server connection to allow data from any node */ - uip_create_unspecified(&server_conn->ripaddr); - server_conn->rport = 0; - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/sensinode/disco.h b/platform/sensinode/disco.h deleted file mode 100644 index 81549ab8d..000000000 --- a/platform/sensinode/disco.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Header file for the Disco server - * (embedded part of the DISCOBALL project) - * - * \author - * George Oikonomou - - */ - -#ifndef DISCO_H_ -#define DISCO_H_ - -#include "contiki.h" -#include "contiki-net.h" -/*---------------------------------------------------------------------------*/ -#define DISCO_UDP_PORT 60002 -#define DISCO_DESCRIPTORS_LOC /* In external Flash */ - -#define DATA_CHUNK_LEN 64 - -/* Intervals - Timeouts */ -#define DISCO_TIMEOUT_PREPARE (CLOCK_SECOND / 2) -#define DISCO_TIMEOUT_ABORT (CLOCK_SECOND * 10) -#define DISCO_TIMEOUT_REBOOT CLOCK_SECOND - -/* Disco State Machine */ -#define DISCO_STATE_LISTENING 0x00 /* Waiting for a transaction to start */ -#define DISCO_STATE_PREPARING 0x01 /* Erasing Sectors */ -#define DISCO_STATE_READY 0x02 -#define DISCO_STATE_REBOOTING 0x03 /* Reboot to BooTTY and copy new image */ - -/* Instructions */ -#define DISCO_CMD_INIT 0x00 /* Prepare flash area for writes */ -#define DISCO_CMD_SWITCH 0x01 /* Copy image from ext. to int. flash */ -#define DISCO_CMD_WRITE 0x02 /* Write Image to Ext Flash */ -#define DISCO_CMD_DONE 0x03 /* All Done */ - -/* Error Codes */ -#define DISCO_ERR_GENERIC 0xFF /* Generic Error */ -#define DISCO_ERR_BAD_LEN 0xFE /* Incorrect Length */ -#define DISCO_ERR_NOT_READY 0xFD /* Not Initialised */ -#define DISCO_ERR_BAD_OFFSET 0xFC /* Bad Offset */ -#define DISCO_ERR_PROTECTED 0xFB /* Target sector is protected */ -#define DISCO_ERR_INIT_DONE 0xFA /* Already Initialized */ - -/* Message Sizes */ -#define DISCO_FLEN_CMD 1 -#define DISCO_FLEN_IMG 1 -#define DISCO_FLEN_ADDR 3 -#define DISCO_FLEN_DATA 64 - -/* Request Lengths */ -#define DISCO_LEN_INIT (DISCO_FLEN_CMD + DISCO_FLEN_IMG) -#define DISCO_LEN_DONE DISCO_FLEN_CMD -#define DISCO_LEN_WRITE (DISCO_FLEN_CMD + DISCO_FLEN_ADDR + DISCO_FLEN_DATA) -#define DISCO_LEN_SWITCH (DISCO_FLEN_CMD + DISCO_FLEN_IMG) - -/* Response Lengths */ -#define DISCO_RESPONSE_NONE 0 -#define DISCO_RESP_LEN_ERR DISCO_FLEN_CMD -#define DISCO_RESP_LEN_INIT DISCO_FLEN_CMD -#define DISCO_RESP_LEN_DONE DISCO_FLEN_CMD -#define DISCO_RESP_LEN_WRITE (DISCO_FLEN_CMD + DISCO_FLEN_ADDR) -#define DISCO_RESP_LEN_SWITCH (DISCO_FLEN_CMD + DISCO_FLEN_IMG) - -/* Tell BooTTy! what to do after we jump: - * BOOTY_CMD - * [7:5]: Command - * [5:4]: Reserved - * [4:0]: Image number - */ -#define BOOTTY_CMD_LOCATION 0xFEFF - -#define BOOTTY_CMD_JUMP_TO_APP 0x80 -#define BOOTTY_CMD_COPY_IMAGE 0x40 - -#define SECTOR_UNPROTECTED 0 -#define SECTOR_PROTECTED 1 -/*---------------------------------------------------------------------------*/ -PROCESS_NAME(disco_process); -/*---------------------------------------------------------------------------*/ -struct disco_request_pdu { - uint8_t cmd; - uint8_t addr[3]; - uint8_t data[DATA_CHUNK_LEN]; -}; - -struct disco_response_pdu { - uint8_t status; - uint8_t addr[3]; -}; - -struct disco_seed { - uip_ipaddr_t addr; - uint16_t port; -}; -/*---------------------------------------------------------------------------*/ -#endif /* DISCO_H_ */ diff --git a/platform/sensinode/putchar.c b/platform/sensinode/putchar.c deleted file mode 100644 index 8d19ef4d3..000000000 --- a/platform/sensinode/putchar.c +++ /dev/null @@ -1,39 +0,0 @@ -/** - * \file - * hardware-specific putchar() routine for sensinode motes - * - * \author - * George Oikonomou - - */ - -#include "contiki-conf.h" -#include "dev/uart1.h" - -/*---------------------------------------------------------------------------*/ -void -putchar(char c) -{ -#if SLIP_ARCH_CONF_ENABLE -#define SLIP_END 0300 - static char debug_frame = 0; - - if(!debug_frame) { /* Start of debug output */ - uart1_writeb(SLIP_END); - uart1_writeb('\r'); /* Type debug line == '\r' */ - debug_frame = 1; - } -#endif - - uart1_writeb((char)c); - -#if SLIP_ARCH_CONF_ENABLE - /* - * Line buffered output, a newline marks the end of debug output and - * implicitly flushes debug output. - */ - if(c == '\n') { - uart1_writeb(SLIP_END); - debug_frame = 0; - } -#endif -} diff --git a/platform/sensinode/segment.rules b/platform/sensinode/segment.rules deleted file mode 100644 index 0dc7a4a60..000000000 --- a/platform/sensinode/segment.rules +++ /dev/null @@ -1,13 +0,0 @@ -# segment.rules - platform/sensinode - -# segment.rules file for code in platform/sensinode -# Please see cpu/cc2430/segment.rules for more info on code segments -# and for rules of thumb on what to do and what not to do - -# Keep main() in HOME -HOME contiki-sensinode-main.c - -# Files with ISRs must be in HOME -HOME platform/sensinode/dev/button-sensor.c - -# segment.rules - platform/sensinode - end diff --git a/platform/sensinode/uip-debug.c b/platform/sensinode/uip-debug.c deleted file mode 100644 index 5f5b23ca8..000000000 --- a/platform/sensinode/uip-debug.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2010, 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. - * - */ - -/** - * \file - * A set of debugging tools - * \author - * Nicolas Tsiftes - * Niclas Finne - * Joakim Eriksson - */ - -#include "net/ip/uip-debug.h" -#include "debug.h" -/*---------------------------------------------------------------------------*/ -void -uip_debug_ipaddr_print(const uip_ipaddr_t *addr) -{ -#if NETSTACK_CONF_WITH_IPV6 - uint16_t a; - unsigned int i; - int f; - for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) { - a = (addr->u8[i] << 8) + addr->u8[i + 1]; - if(a == 0 && f >= 0) { - if(f++ == 0) { - putstring("::"); - } - } else { - if(f > 0) { - f = -1; - } else if(i > 0) { - putstring(":"); - } - puthex(a >> 8); - puthex(a & 0xFF); - } - } -#else /* NETSTACK_CONF_WITH_IPV6 */ - PRINTA("%u.%u.%u.%u", addr->u8[0], addr->u8[1], addr->u8[2], addr->u8[3]); -#endif /* NETSTACK_CONF_WITH_IPV6 */ -} -/*---------------------------------------------------------------------------*/ -void -uip_debug_lladdr_print(const uip_lladdr_t *addr) -{ - unsigned int i; - for(i = 0; i < sizeof(uip_lladdr_t); i++) { - if(i > 0) { - putstring(":"); - } - puthex(addr->addr[i]); - } -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/sensinode/viztool.c b/platform/sensinode/viztool.c deleted file mode 100644 index e6b2fbed3..000000000 --- a/platform/sensinode/viztool.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2010, Loughborough University - 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. - */ - -/** - * \file - * Small UDP app used to retrieve neighbor cache and routing table - * entries and send them to an external endpoint - * - * \author - * George Oikonomou - - */ - -#include "contiki.h" -#include "contiki-lib.h" -#include "contiki-net.h" -#include "net/ipv6/uip-ds6-route.h" - -#include - -#define DEBUG DEBUG_NONE -#include "net/ip/uip-debug.h" - -#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) - -#ifndef VIZTOOL_MAX_PAYLOAD_LEN -#define VIZTOOL_MAX_PAYLOAD_LEN 60 -#endif - -static struct uip_udp_conn *server_conn; -static unsigned char buf[VIZTOOL_MAX_PAYLOAD_LEN]; -static int8_t len; - -#define VIZTOOL_UDP_PORT 60001 - -/* Request Bits */ -#define REQUEST_TYPE_ND 1 -#define REQUEST_TYPE_RT 2 -#define REQUEST_TYPE_DRT 3 -#define REQUEST_TYPE_ADDR 4 -#define REQUEST_TYPE_TOTALS 0xFF - -extern uip_ds6_netif_t uip_ds6_if; -static uip_ds6_route_t *rt; -static uip_ds6_defrt_t *defrt; -static uip_ipaddr_t *addr; -/*---------------------------------------------------------------------------*/ -static uint8_t -process_request() CC_NON_BANKED -{ - uint8_t len; - uint8_t count; /* How many did we pack? */ - uint8_t i; - uint8_t left; - uint8_t entry_size; - uip_ds6_nbr_t *nbr; - - left = VIZTOOL_MAX_PAYLOAD_LEN - 1; - len = 2; /* start filling the buffer from position [2] */ - count = 0; - if(buf[0] == REQUEST_TYPE_ND) { - /* Neighbors */ - PRINTF("Neighbors\n"); - for(nbr = nbr_table_head(ds6_neighbors); - nbr != NULL; - nbr = nbr_table_next(ds6_neighbors, nbr)) { - entry_size = sizeof(i) + sizeof(uip_ipaddr_t) + sizeof(uip_lladdr_t) - + sizeof(nbr->state); - PRINTF("%02u: ", i); - PRINT6ADDR(&nbr->ipaddr); - PRINTF(" - "); - PRINTLLADDR(&nbr->lladdr); - PRINTF(" - %u\n", nbr->state); - - memcpy(buf + len, &i, sizeof(i)); - len += sizeof(i); - memcpy(buf + len, uip_ds6_nbr_get_ipaddr(nbr), sizeof(uip_ipaddr_t)); - len += sizeof(uip_ipaddr_t); - memcpy(buf + len, uip_ds6_nbr_get_ll(nbr), sizeof(uip_lladdr_t)); - len += sizeof(uip_lladdr_t); - memcpy(buf + len, &nbr->state, - sizeof(nbr->state)); - len += sizeof(nbr->state); - - count++; - left -= entry_size; - - if(left < entry_size) { - break; - } - } - } else if(buf[0] == REQUEST_TYPE_RT) { - uint32_t flip = 0; - - PRINTF("Routing table\n"); - rt = uip_ds6_route_head(); - - for(i = buf[1]; i < uip_ds6_route_num_routes(); i++) { - if(rt != NULL) { - entry_size = sizeof(i) + sizeof(rt->ipaddr) - + sizeof(rt->length) - + sizeof(rt->state.lifetime) - + sizeof(rt->state.learned_from); - - memcpy(buf + len, &i, sizeof(i)); - len += sizeof(i); - memcpy(buf + len, &rt->ipaddr, sizeof(rt->ipaddr)); - len += sizeof(rt->ipaddr); - memcpy(buf + len, &rt->length, sizeof(rt->length)); - len += sizeof(rt->length); - - PRINT6ADDR(&rt->ipaddr); - PRINTF(" - %02x", rt->length); - PRINTF(" - "); - PRINT6ADDR(uip_ds6_route_nexthop(rt)); - - flip = uip_htonl(rt->state.lifetime); - memcpy(buf + len, &flip, sizeof(flip)); - len += sizeof(flip); - PRINTF(" - %08lx", rt->state.lifetime); - - memcpy(buf + len, &rt->state.learned_from, - sizeof(rt->state.learned_from)); - len += sizeof(rt->state.learned_from); - - PRINTF(" - %02x [%u]\n", rt->state.learned_from, entry_size); - - count++; - left -= entry_size; - - rt = uip_ds6_route_next(rt); - - if(left < entry_size) { - break; - } - } - } - } else if(buf[0] == REQUEST_TYPE_DRT) { - uint32_t flip = 0; - - PRINTF("Default Route\n"); - addr = uip_ds6_defrt_choose(); - if(addr != NULL) { - defrt = uip_ds6_defrt_lookup(addr); - } - - i = buf[1]; - - if(defrt != NULL && i < 1) { - entry_size = sizeof(i) + sizeof(defrt->ipaddr) - + sizeof(defrt->isinfinite); - - memcpy(buf + len, &i, sizeof(i)); - len += sizeof(i); - memcpy(buf + len, &defrt->ipaddr, sizeof(defrt->ipaddr)); - len += sizeof(defrt->ipaddr); - memcpy(buf + len, &defrt->isinfinite, sizeof(defrt->isinfinite)); - len += sizeof(defrt->isinfinite); - - PRINT6ADDR(&defrt->ipaddr); - PRINTF(" - %u\n", defrt->isinfinite); - count++; - left -= entry_size; - } - } else if(buf[0] == REQUEST_TYPE_ADDR) { - PRINTF("Unicast Addresses\n"); - for(i = buf[1]; i < UIP_DS6_ADDR_NB; i++) { - if(uip_ds6_if.addr_list[i].isused) { - entry_size = sizeof(i) + sizeof(uip_ds6_if.addr_list[i].ipaddr); - - memcpy(buf + len, &i, sizeof(i)); - len += sizeof(i); - memcpy(buf + len, &uip_ds6_if.addr_list[i].ipaddr, - sizeof(uip_ds6_if.addr_list[i].ipaddr)); - len += sizeof(uip_ds6_if.addr_list[i].ipaddr); - - PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr); - PRINTF("\n"); - count++; - left -= entry_size; - - if(left < entry_size) { - break; - } - } - } - } else if(buf[0] == REQUEST_TYPE_TOTALS) { - memset(&buf[2], 0, 4); - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - if(uip_ds6_if.addr_list[i].isused) { - buf[2]++; - } - } - for(nbr = nbr_table_head(ds6_neighbors); - nbr != NULL; - nbr = nbr_table_next(ds6_neighbors, nbr)) { - buf[3]++; - } - - buf[4] = uip_ds6_route_num_routes(); - buf[5] = 1; - - len += 4; - count = 4; - } else { - return 0; - } - buf[1] = count; - return len; -} -/*---------------------------------------------------------------------------*/ -PROCESS(viztool_process, "Network Visualization Tool Process"); -/*---------------------------------------------------------------------------*/ -static void -tcpip_handler(void) CC_NON_BANKED -{ - if(uip_newdata()) { - memset(buf, 0, VIZTOOL_MAX_PAYLOAD_LEN); - - PRINTF("%u bytes from [", uip_datalen()); - PRINT6ADDR(&UIP_IP_BUF->srcipaddr); - PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport)); - - memcpy(buf, uip_appdata, uip_datalen()); - - len = process_request(); - if(len) { - server_conn->rport = UIP_UDP_BUF->srcport; - uip_ipaddr_copy(&server_conn->ripaddr, &UIP_IP_BUF->srcipaddr); - uip_udp_packet_send(server_conn, buf, len); - PRINTF("Sent %u bytes\n", len); - } - - /* Restore server connection to allow data from any node */ - uip_create_unspecified(&server_conn->ripaddr); - server_conn->rport = 0; - } - return; -} -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(viztool_process, ev, data) -{ - - PROCESS_BEGIN(); - - server_conn = udp_new(NULL, UIP_HTONS(0), NULL); - udp_bind(server_conn, UIP_HTONS(VIZTOOL_UDP_PORT)); - - while(1) { - PROCESS_YIELD(); - if(ev == tcpip_event) { - tcpip_handler(); - } - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/tools/sensinode/nano_programmer/Makefile b/tools/sensinode/nano_programmer/Makefile deleted file mode 100644 index 06c0fb979..000000000 --- a/tools/sensinode/nano_programmer/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -EXE_MAKE=$(notdir $(shell which "make.exe" 2>/dev/null)) -ifeq "$(EXE_MAKE)" "make.exe" -PLATFORM=windows -else -PLATFORM=linux -endif - -OBJECTS = ihex.o $(PLATFORM)/port.o programmer.o cdi_program.o -SUBDIRS = - -ifeq "$(PLATFORM)" "linux" -CFLAGS = -Wall -D_REENTRANT -I. -LDFLAGS = -L. -D_REENTRANT -lpthread -SUFFIX= -else -CFLAGS=-I. -I../nano_usb_programmer/ftdi_win32 -CFLAGS+= -L. -L../nano_usb_programmer/ftdi_win32 -DPLATFORM_WINDOWS -CFLAGS+= -mwin32 -LDFLAGS=../nano_usb_programmer/ftdi_win32/ftd2xx.lib -lkernel32 -SUFFIX=.exe -endif - -TARGET = nano_programmer$(SUFFIX) - -all: binary - -binary: $(TARGET) - strip $(TARGET) - -$(TARGET): $(OBJECTS) - gcc -o $(TARGET) $(OBJECTS) $(LDFLAGS) - -.c.o: - gcc -c -o $(<:.c=.o) -O2 -Wall $(CFLAGS) $< - -platform-test: - @echo $(PLATFORM) - -old-strip: - if [ -x $(TARGET).exe ]; then $(PLATFORM)strip $(TARGET).exe; else $(PLATFORM)strip $(TARGET); fi - -clean: - rm -f $(TARGET) $(OBJECTS) diff --git a/tools/sensinode/nano_programmer/README.md b/tools/sensinode/nano_programmer/README.md deleted file mode 100755 index f85a6a2aa..000000000 --- a/tools/sensinode/nano_programmer/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# Nano Programmer - -Programming tool for the Sensinode Nano series using Dxxx development boards. - -Copyright 2007-2008 Sensinode Ltd. - -## Installation - -### Linux - -No external libraries required. - -### Windows/Cygwin - -See the nano_usb_programmer README file on how to install FTDI library -for nano_usb_programmer. The nano_programmer build system will fetch -the library from there. - -## Usage - -Usage info for the Nano Programmer is available with command - - ./nano_programmer --help - -Note that use might require root/administrator privileges - depending on system configuration. - -## Known problems - -Occasional timing failures resulting in "Reinit failed."-messages do come -up in some PC configurations. If you experience programming failures (the programmer -is not able to recover), please report your system configuration to Sensinode. -On Linux, it is known that the "brltty" program causes problems with the FTDI -serial driver. Uninstalling brltty resolves the problem. - -## Version - -v1.3 2008-01-31 Martti Huttunen Multi-platform build and created instructions diff --git a/tools/sensinode/nano_programmer/cdi_program.c b/tools/sensinode/nano_programmer/cdi_program.c deleted file mode 100644 index 3b2ecd255..000000000 --- a/tools/sensinode/nano_programmer/cdi_program.c +++ /dev/null @@ -1,607 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#include -#include -#include - -#include "port.h" -#include "programmer.h" -#include "ihex.h" - -#include - -extern void crc_add(unsigned char *crc, unsigned char byte); - -int cdi_page_write(port_t *port, unsigned long page_addr, unsigned char *page_buffer); -int cdi_write(port_t *port, conf_opts_t *conf, FILE *ihex); - -int cdi_programmer(conf_opts_t *conf, char *filename) -{ - int error = 0; - port_t *port = 0; - unsigned char buffer[256]; - int length = 0; - FILE *ihex = 0; - - error = programmer_init(conf->device, &port); - - if (error < 0) - { - return error; - } - - if((!error) && (conf->action != 'b')) - { - length = port_write_echo(port, "CDI\r"); - bzero(buffer, sizeof(buffer)); - if (length >= 4) - { - length = port_readline(port, buffer, sizeof(buffer), 100); - } - else length = 0; - - if(memcmp(buffer, "OK", 2) == 0) - { - error = 0; - } - else - { - printf("Programming mode selection failed.\n"); - error = -1; - } - } - - if((!error) && (conf->action != 'b')) - { - printf("Initialize.\n"); - // Succesfully in mode 1 - sleep(1); - port_write_echo(port, "i\r"); - - bzero(buffer, 256); - length = port_readline(port, buffer, sizeof(buffer), 100); - - if(memcmp(buffer, "85", 2) == 0) - { /*Found CC2430 device*/ - printf("Found CC2430 device revision %c%c.\n", buffer[2], buffer[3]); - } - else if (memcmp(buffer, "89", 2) == 0) - { - printf("Found CC2431 device revision %c%c.\n", buffer[2], buffer[3]); - } - else - { - printf("CC2430 not found.\n"); - error = -1; - } - } - - if (error) conf->action = ' '; - - switch(conf->action) - { - case 'e': - // Erase programming - port_write_echo(port, "e\r"); - bzero(buffer, 256); - length = port_readline(port, buffer, sizeof(buffer), 100); - - if(memcmp(buffer, "OK", 2) == 0) - { - // Erase successful - printf("Erase successful.\n"); - error = 0; - } - else - { - // Erase failed - printf("Erase failed: %s.\n", buffer); - error = -1; - } - if ((conf->action != 'P') || error) - break; - - case 'P': - case 'w': - ihex = fopen(conf->ihex_file, "rb"); - if(ihex == NULL) - { - printf("Failed to open ihex file %s.\n", conf->ihex_file); - error = -1; - } - else error = 0; - - if (!error) - { - error = cdi_write(port, conf, ihex); - if (error) printf("Programming failed.\n"); - } - - - - if (ihex != NULL) fclose(ihex); - break; - - case 'b': - length = port_write_echo(port, "V\r"); - bzero(buffer, sizeof(buffer)); - if (length >= 2) - { - length = port_readline(port, buffer, sizeof(buffer), 100); - } - else length = 0; - - if(length > 4) - { - buffer[length] = 0; - printf("BIOS: %s\n", buffer); - error = 0; - } - else - { - printf("Failed to get BIOS version. Upgrade recommended.\n"); - error = -1; - } - break; - - case 'v': - break; - - case 'r': - ihex = fopen(conf->ihex_file, "wb"); - if(ihex == NULL) - { - printf("Failed to open ihex file %s.\n", conf->ihex_file); - error = -1; - } - else - { - port_write_echo(port, "a000000\r"); - bzero(buffer, sizeof(buffer)); - length = port_readline(port, buffer, sizeof(buffer), 200); - if (length <0) length = 0; - if(memcmp(buffer, "OK", 2) == 0) - { - uint32_t address = 0; - uint8_t check = 0; - for (address = 0; address < 128*1024; address += 64) - { - uint8_t i; - - if ((address) && ((address & 0xFFFF)==0)) - { - fprintf(ihex, ":02000004%4.4X%2.2X\r\n", - (int)(address>>16), (int)(0xFA-(address>>16))); - } - port_write_echo(port, "r\r"); - bzero(buffer, 256); - length = 0; - while (length < 64) - { - length += port_readline(port, &buffer[length], sizeof(buffer)-length, 100); - } - for (i=0; i<64; i++) - { - if ((i & 0x0F) == 0) - { - check = 0; - check -= 0x10; - check -= (uint8_t) (address >> 8); - check -= (uint8_t) (address + i); - printf("%4.4X", (int) address + i); - fprintf(ihex, ":10%4.4X00", (int) (address + i) & 0xFFFF); - } - fprintf(ihex, "%2.2X", buffer[i]); - check -= buffer[i]; - if ((i & 0x0F) == 0x0F) - { - fprintf(ihex, "%2.2X\r\n", check); - if (i > 0x30) printf("\n"); - else printf(" "); - } - } - } - fprintf(ihex, ":00000001FF\r\n"); - } - else - { - printf("Failed to set read address.\n"); - error = -1; - } - fclose(ihex); - } - break; - /*skip for error case*/ - case ' ': - break; - - case 'm': - port_write_echo(port, "a01F800\r"); - bzero(buffer, sizeof(buffer)); - length = port_readline(port, buffer, sizeof(buffer), 200); - if (length <0) length = 0; - if(memcmp(buffer, "OK", 2) == 0) - { - uint8_t i; - uint32_t address = 0; - - for (address = 0x01F800; address < 128*1024; address += 64) - { - - port_write_echo(port, "r\r"); - bzero(buffer, 256); - length = 0; - while (length < 64) - { - length += port_readline(port, &buffer[length], sizeof(buffer)-length, 100); - } - if ((address & 0xff) == 0) - { printf("."); - fflush(stdout); - } - } - printf("\nDevice MAC: "); - for (i=56; i<64; i++) - { - if (i != 56) printf(":"); - printf("%2.2X", buffer[i]); - } - printf("\n"); - } - break; - - case 'Q': - port_write_echo(port, "a01F800\r"); - bzero(buffer, sizeof(buffer)); - length = port_readline(port, buffer, sizeof(buffer), 200); - if (length <0) length = 0; - if(memcmp(buffer, "OK", 2) == 0) - { - uint8_t p_buffer[2048]; - int error; - - memset(p_buffer, 0xff, sizeof(p_buffer)); - memcpy(&p_buffer[2040], conf->write_mac, 8); - - printf("\rWriting MAC: "); - error = cdi_page_write(port, 0x01F800, p_buffer); - if (!error) - { - printf("Write complete.\n"); - } - else - { - printf("Write failed.\n"); - } - } - break; - - default: - printf("Unknown CDI action.\n"); - break; - } - - printf("Close programmer.\n"); - usleep(100000); - port_write_echo(port, "q\r"); - programmer_close(port); - return error; -} - -int cdi_write(port_t *port, conf_opts_t *conf, FILE *ihex) -{ - int error = 0; - unsigned char buffer[256]; - int length; - int i; - int pages; - - unsigned long ext_addr=0; - unsigned short int addr=0; - unsigned char page_buffer[128*1024]; - unsigned char page_table[64]; - - bzero(buffer, sizeof(buffer)); - - /*initialize page data*/ - memset(page_table, 0, 64); - memset(page_buffer, 0xFF, sizeof(page_buffer)); - pages = 0; - - error = 0; - - if (conf->page_mode == PAGE_UNDEFINED) - { - int retval; - - while((!error) && ((retval = fscanf(ihex, "%s", buffer)) == 1) ) - { - unsigned char data_len = 0; - - if (memcmp(&buffer[7], "00", 2) == 0) - { /*Data record*/ - } - else if (memcmp(&buffer[7], "01", 2) == 0) - { /*end file*/ - printf("\nFile read complete.\n"); - break; - } - else if (memcmp(&buffer[7], "04", 2) == 0) - { - sscanf((char *)&(buffer[3]),"%4hx", &addr); - sscanf((char *)&(buffer[9]),"%4lx", &ext_addr); - - if (ext_addr >= 0x0002) - { - conf->page_mode = PAGE_SDCC; - } - else - { - if (conf->page_mode == PAGE_UNDEFINED) conf->page_mode = PAGE_LINEAR; - } - } - } - if (retval == -1) - { - printf("Read error\n"); - return -1; - } - rewind(ihex); - retval = 0; - error = 0; - } - switch (conf->page_mode) - { - case PAGE_SDCC: - printf("SDCC banked file.\n"); - break; - case PAGE_LINEAR: - printf("Linear banked file.\n"); - break; - case PAGE_UNDEFINED: - printf("Non-banked file, assuming linear.\n"); - conf->page_mode = PAGE_LINEAR; - break; - } - - while( (fscanf(ihex, "%s", buffer) == 1) && !error) - { - unsigned char data_len = 0; - - if (memcmp(&buffer[7], "00", 2) == 0) - { /*Data record*/ - i=0; - sscanf((char *)&buffer[1], "%2hhx", &data_len); - sscanf((char *)&(buffer[3]),"%4hx", &addr); - while(ipage_mode == PAGE_SDCC) - { - if (ext_addr) ext_addr--; - ext_addr *= 0x8000; - } - else - { - ext_addr *= 0x10000; - } - printf("\rExtended page address: 0x%8.8lX\r", ext_addr); - } - } - - if (pages) - { - int retry = 0; - // Successfully in mode 3 (programming) - printf("Starting programming.\n"); - error = 0; - for (i=0; i<64; i++) - { - if (page_table[i] != 0) - { - ext_addr = 2048*i; - - bzero(buffer, sizeof(buffer)); - - // Write the start address and check return - usleep(3000); - sprintf((char *)buffer, "a%6.6lX\r", ext_addr); - port_write_echo(port, (char *)buffer); - - if((length = port_readline(port, buffer, sizeof(buffer), 200)) < 0) - { - printf("Read from serial timed out without data.\n"); - error = -1; - break; - } - else - { - if(strncmp((char *)buffer, "OK\r\n", 4) == 0) - { - printf("\r \r"); - printf("\rWriting @ 0x%6.6lX: ", ext_addr); - fflush(stdout); - error = cdi_page_write(port, ext_addr, &page_buffer[ext_addr]); - if (error) - { - usleep(20000); - port_write_echo(port, "i\r"); - - bzero(buffer, 256); - length = port_readline(port, buffer, sizeof(buffer), 100); - - if(memcmp(buffer, "85", 2) == 0) - { /*Found CC2430 device*/ - } - else - { - printf("Reinit failed.\n"); - error = -1; - } - if (retry++ < 3) - { - error = 0; - i--; - } - } - else retry = 0; - fflush(stdout); - usleep(20000); - } - else - { - printf("Failed to set CDI programming start address.\n"); - error = -1; - break; - } - } - } - if (error) break; - } - usleep(200000); - printf("\n"); - } - - return error; -} - -int cdi_page_write(port_t *port, unsigned long page_addr, unsigned char *page_buffer) -{ - int error = 0; - unsigned char buffer[80]; - unsigned char cmd[16]; - unsigned char block, i; - int length; - int retry = 0; - - // Write page - port_write_echo(port, "w\r"); - usleep(10000); - for (block=0; block<(2048/64); block++) - { - sprintf((char *)cmd, "%6.6lX", page_addr + (64*block)); - bzero(buffer, sizeof(buffer)); - length = port_readline(port, buffer, sizeof(buffer), 2000); - if (length <0) - { length = 0; - printf("l!");fflush(stdout); - } - buffer[length] = 0; - if (block & 1) - { - } - if(memcmp(buffer, cmd, 6) == 0) - { -#define WRITE_SIZE 64 - for (i=0; i<64; i+=WRITE_SIZE) - { - port_write(port, &page_buffer[(unsigned int)(block*64)+i], WRITE_SIZE); - usleep(1250); - } - - bzero(buffer, sizeof(buffer)); - printf("."); - fflush(stdout); - length = port_readline(port, buffer, sizeof(buffer), 200); - if(memcmp(buffer, "OK", 2) == 0) - { - retry = 0; - } - else - { - block--; - if (retry++ >= 8) - { - error = -1; - break; - } - else - { - buffer[length] = 0; - printf("%s",buffer); - port_rts_clear(port); - usleep(300000); - port_rts_set(port); - bzero(buffer, sizeof(buffer)); - length = port_readline(port, buffer, sizeof(buffer), 800); - if(memcmp(buffer, "CDI", 3) == 0) - { - printf("R"); - } - } - } - } - else - { - error = -1; - break; - } - } - - if (!error) - { - printf("w"); fflush(stdout); - bzero(buffer, sizeof(buffer)); - length = port_readline(port, buffer, sizeof(buffer), 800); - if(memcmp(buffer, "WROK", 4) == 0) - { - error = 0; - } - else - { - printf("%c%c", buffer[0], buffer[1]); - error = -1; - } - } - - if (!error) printf("OK\r"); - return error; -} - diff --git a/tools/sensinode/nano_programmer/ihex.c b/tools/sensinode/nano_programmer/ihex.c deleted file mode 100644 index 83234714e..000000000 --- a/tools/sensinode/nano_programmer/ihex.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#include -#include -#include -#include - -#include - -int hexfile_parse(char *line, unsigned int *type, unsigned int *addr, unsigned char *buffer) -{ - unsigned int row_len = 0; - unsigned int row_index = 7; - unsigned int i; - int tmp; - - uint8_t cksum = 0; - int retval = 0; - - retval = sscanf(line, ":%2x%4x%2x", &row_len, addr, type); - - cksum += row_len; - cksum += *addr >> 8; - cksum += *addr & 0xFF; - cksum += *type; - - i = 0; - if (retval == 3) - { - while(i < row_len) - { - - if (sscanf(&line[row_index], "%2x", &tmp) == 1) - { - cksum += tmp; - buffer[i++] = (unsigned char) tmp; - row_index += 2; - } - else return -1; - } - if (sscanf(&line[row_index], "%2x", &tmp) == 1) - { - if ((cksum + (uint8_t) tmp) == 0) return row_len; - } - } - return -1; -} - -int hexfile_out(char *line, unsigned int type, unsigned int address, unsigned char *data, unsigned int bytes) -{ - uint8_t cksum = 0; - uint8_t i = 0; - char tmp[8]; - - sprintf(line, ":%2.2X%4.4X%2.2X", bytes, address, type); - cksum -= bytes; - cksum -= address >> 8; - cksum -= address & 0xFF; - cksum -= type; - - for (i=0; i - -#include "port.h" - -int port_open(port_t **port, char *device) -{ - port_t *new_port = (port_t *) malloc(sizeof(port_t)); - char err_string[128]; - - *port = new_port; - - new_port->device = 0; - new_port->handle = 0; - - new_port->handle = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK); - - if (new_port->handle <= 0) - { - strerror_r(errno, err_string, 128); - - printf("Serial port open failed with error message: %s.\n", err_string); - return(-1); - } - else - { - tcgetattr(new_port->handle, &(new_port->old_params)); - - fcntl(new_port->handle, F_SETFL, FASYNC); - printf("Serial port %s opened succesfully.\n", device); - - return(0); - } -} - -int port_close(port_t *port) -{ - if (!port) - return(-1); - - if ((port->handle) > 0) - { - tcflush(port->handle, TCIFLUSH); - tcsetattr(port->handle,TCSANOW,&(port->old_params)); - - close(port->handle); - port->handle = 0; - } - - if (port->device) free(port->device); - port->device = 0; - free(port); - - return(1); -} - - -/** @todo port_write() function probably needs mutexes -mjs */ - -int port_write(port_t *port, unsigned char *buffer, size_t buflen) -{ - int i=0; - - if (!port) return -1; - - /** @todo The write to serial port is at the moment done one octet at a time with 10ms interval between each write operation due to some minor problems in MCU interrupts. -mjs */ - while(i < buflen) - { - write(port->handle, &(buffer[i]), 1); - tcflush(port->handle, TCIFLUSH); - i++; - } - -/* write(port->handle, &(buffer[i]), buflen);*/ - - tcflush(port->handle, TCIFLUSH); - - return(0); -} - -int port_read(port_t *port, unsigned char *buffer, size_t buflen) -{ - unsigned int l = 0; - l = read(port->handle, buffer, buflen); - return(l); -} - -int port_set_params(port_t *port, uint32_t speed, uint8_t rtscts) -{ - int rate = B115200; - struct termios newtio; - - if (!port) return -1; - - switch (speed) - { - case 230400: - rate = B230400; - break; - - case 0: - case 115200: - rate = B115200; - break; - - case 57600: - rate = B57600; - break; - - case 38400: - rate = B38400; - break; - - case 19200: - rate = B19200; - break; - - case 9600: - rate = B9600; - break; - - default: - return -1; - - } - bzero(&newtio, sizeof(newtio)); - - if (speed == 9600) - { - newtio.c_cflag |= CS8 | CSTOPB | CLOCAL | CREAD; - } - else - { - newtio.c_cflag |= CS8 | CLOCAL | CREAD; - } - if (rtscts) - { - newtio.c_cflag |= CRTSCTS; - } - newtio.c_iflag = IGNPAR; - - cfsetispeed(&newtio, rate); - cfsetospeed(&newtio, rate); - - newtio.c_cc[VTIME] = 0; - newtio.c_cc[VMIN] = 1; - -#if 0 - newtio.c_cflag = rate | CS8 | CLOCAL | CREAD | CSTOPB; -/* if (rts_cts) newtio.c_cflag |= CRTSCTS;*/ - - newtio.c_iflag = IGNPAR; - newtio.c_oflag = 0; - - newtio.c_lflag = 0; - - newtio.c_cc[VTIME] = 0; - newtio.c_cc[VMIN] = 1; -#endif - - tcflush(port->handle, TCIFLUSH); - tcsetattr(port->handle,TCSANOW,&newtio); - - return(0); -} - -int port_dtr_set(port_t *port) -{ - int port_state = TIOCM_DTR; - - if (!port) return(-1); - -/* error = ioctl(port->handle, TIOCMGET, &port_state); - port_state |= TIOCM_RTS; - ioctl(port->handle, TIOCMSET, &port_state);*/ - - ioctl(port->handle, TIOCMBIS, &port_state); - return 0; -} - -int port_dtr_clear(port_t *port) -{ - int port_state = TIOCM_DTR; - - if (!port) return(-1); - - ioctl(port->handle, TIOCMBIC, &port_state); - return 0; -} - -int port_rts_set(port_t *port) -{ - int port_state = TIOCM_RTS; - - if (!port) return(-1); - - ioctl(port->handle, TIOCMBIS, &port_state); - return 0; -} - -int port_rts_clear(port_t *port) -{ - int port_state = TIOCM_RTS; - - if (!port) return(-1); - - ioctl(port->handle, TIOCMBIC, &port_state); - return 0; -} - -int port_get(port_t *port, unsigned char *buffer, int timeout) -{ - struct pollfd pfds; - unsigned int nfds = 1; - int bytes = 0; - int rval; - - pfds.fd = (int)(port->handle); - pfds.events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL; - - rval = poll(&pfds, nfds, timeout); - - if((rval & POLLIN) != POLLIN) - { - return(-1); - } - else - { - bytes = port_read(port, buffer, 1); - } - return bytes; -} - -int port_readline(port_t *port, unsigned char *buffer, int buf_size, int timeout) -{ - int length = 0; - struct pollfd pfds; - unsigned int nfds = 1; - int bytes = 0; - int rval; - - pfds.fd = (int)(port->handle); - pfds.events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL; - - do - { - rval = poll(&pfds, nfds, timeout); - if((rval & POLLIN) != POLLIN) - { - return(length); - } - else - { - bytes = port_read(port, &(buffer[length]), 1); - if (buffer[length] == '\n') - { - buf_size = length; - } - length += bytes; - } - - }while(length < buf_size); - - buffer[length] = 0; - - if(length != 0) - return length; - else - return(-1); -} - -int port_write_echo(port_t *port, char *string) -{ - int length = 0; - int retry = 0; - unsigned char byte; - - while( (string[length]) && (retry < 100) ) - { - port_write(port, (unsigned char *) &string[length], 1); - while (retry++ < 100) - { - if (port_read(port, &byte, 1) == 1) - { -/* printf("%c",byte);*/ - if (byte == string[length]) - { - retry = 0; - length++; - break; - } - else retry = 100; - } - else usleep(1000); - } - } - if ((string[strlen(string)-1] == '\r') && (retry < 100) ) - { /*wait for \n*/ - retry = 0; - while (retry++ < 100) - { - if (port_read(port, &byte, 1) == 1) - { -/* printf("%c",byte);*/ - break; - } - else usleep(1000); - } - } - - if (retry >= 100) return 0; - else return length; -} - - -int port_write_8byte_no_echo(port_t *port, int dlen, char *string) -{ - int length = 0; - int total_len; - int wrbytes = 4; - - total_len = dlen; - -/* printf("total: %d, length: %d, dlen: %d.\n", total_len, length, dlen); */ - while(total_len > length) - { - if((total_len - length) >= wrbytes) - { - port_write(port, (unsigned char *)&string[length], wrbytes); - length += wrbytes; - } - else - { - port_write(port, (unsigned char *)&string[length], total_len - length); - length += total_len - length; - } - usleep(1250); - - } - - return(length); -} - diff --git a/tools/sensinode/nano_programmer/nano_programmer b/tools/sensinode/nano_programmer/nano_programmer deleted file mode 100755 index fd3e46b8a66dbbb1df54b70bac68e3c11ed4d6a4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 18776 zcmeHv4R}=5o%fk!fC)`HsiJ~Kd(lJ#%9z2Z5I-6rgQ8SW3DU(FhGg=glbJXld{ofj zWR&qTnr@BD`_@*lyXv-DvK3NL1A)*)*S4E=`?hT9YOG&(OteuD(j_(f`<-*|WP<41 z_IaP@ec$KV3un&xpYuQe@AE(B-no|$I zUo+d^5QwgGg@dj+YA#qy*{{2)Le8ZeoZ~<#M464kD_2#g{FFMHBd4MMn%O=N^;c2O zHsSM87od>t1t_%NIVhReR{+dJDMC3H#fdT*WjYG487LRa)~P?ze!wtoV_npVKD4ec zqe0y>uPG+*CDa$8oPm;qG7W{-Bvr}Jv&^<;*0dY1sj3pQP}7EIqU51mh(iACr;O5O z=ND*%$%{J8JZH=F=Wcwf>-i^-(~RRT+Kdy$Qc%!VM<=5feVs9KX(li%ocr3Fnw_nF+s(nwNoo%D2)Sx8yw_N0r_jZ!uwu zUXuwkUO7I`oIlTm-!sSWGU1u#_%}^{b4}Qq|AC3W!5n|ggf(;iZ%w${gwHqUKZn2~ z|D)#k56$^EnB#j*{BN7%kC@|qCcM_1f29fk%)~!o!dCn^O?sBRYt8ZhH1Ru3xY2~) zK;3n~?y#f&3ZnjRQ2*{H7VH#Rpm#81Tp<56Me0L7Zw<3gv8cLXP1P;Fx`uGX7h2%= zhQq$FsH*aXLV;kFKUnRJGz0^J=%Thd5b3P-%5NL3ZdRg=)=qH56+^wu;4 zs-j^ZuxtI%aJ>jeLe)*{g>PL$M1-3{4S`6ls0}vx0wUZ{7x4N;Q#3+`pjUlYRdxMc zRkhv**;`%j4T166hCq#|t_}Ml4dEsq2!o;@(;Iz_=o67@e0n31kZ20}{TQqXMk5f_ z9}N3Mqt_1=qzqoL4_A8wwIbLA(d$G*uo~Lbs=hj31l`a#P$!~czt7hsYS)GuB0kVp zdeoY-N2-A<`Bhb|YpR3XA=oMystPF~gG$J%DjLSLQlqyaAZkNCpSW)EqWKG|=D03( zm89EaEqA)F7+&OV$-*n!Y-iSNXCt?ceG;4hCYbd^SzEmvv7s>U*~L=S`6#R-(;ARo zCyIL!E9{%n(127qK|Ex_Uy-m~JZi%E63!Oi2h7VR|BdBwHJ+6oAH+U75s8*@Isu86 z@i+mAb_D&CNMk>0tPeYD23!$;bW>LTz8)Ok{ zXmBxWY%s;Fv4NGahJtfhBk^9v8jHG&H8#O=*4TWmXN^r~G3zs7Bi7hxma)dhvVt`> zquW_yQ(eUx8*B}0Y>@S=u|fD*WAkicjmlxTPSf3|EGwbt_`&eV)Z)RO6 z#1_`rpj%mAD8!?zu_13|JyVE^#5=df2JHrYuyRv(%N0WC-x(Pl9gV*hnPA+3UgM82 zt6>N3ij}W)k6v~Z79TAf#wX{D7SaRtY^M4#ZM0B;ay`dVeG;}4W=N#EBOLzt0-GrMY%m}LQBD_k%s|deLc&UVI z2=@^#lW;xZLxhVZ>?hn$Sd(xQVS{kKgd>E92nz|XBRoua=ugz25m=Aa3;iYBOxQuV zPr@yP^9grJcr)Rtgxe*&g|J3=n}k~l^LU(UmGGm4c|=GxOL!|`Zpo=8!0r$3NW2+) zduZvhTk19JS@p&ExOsVf|99;U;}1YM+B)t+yvGI|%~!vS{2?N_1Jh$&_8&Y0lB2I} zXQk)IUyBa(OyIcfmF`xBzdav89`A~rM!O3%a(e9r>>KR^PUZ#t+m>TRU95Yi=+RuC zeg=|(NK_2DU(+`_^opqo&+l|kej-wk-&34RB#FPS38X%?e0*CP}kVtwA zwC$vLBb=sJ^v^mw@v*bxz&y{?wfmeM-NXbEC-%I6iS`0xKIehxGBxjX%;Wr(u%TWt z*KT00wGlA5-6GZqhTPSLTzn?s4>b7&C&3CT=gtC8v)lA~-pu zNJILU6BYgX>9OJLNZxKPEsHb^(4VwVv-RzN-;um3AJXqe<`&3EWqa9hA5MA(EjFM# z47#==^5$ujPUeCp-A|w zWoS<+Fg`qi2<>{MJGn+AUqbdpzWuZ2pJ~qj@n0|>S^6{l1Apawi@)o$^Qn4$qVlL- z>F{lrvF#ahcR4#M@)ObF#Kw{M;pll%$FZPs#w)N~bl;TBgO%NzHs%T(o1HDw zF|u|Az-DY#Fq5<8kI;j|H<~a{v$`iY-W7eO*VCSrFT`GcBt1L#@P;zsc~;-}th;OE z$d61a&Xz&+>(TasGSWF<6OkS^TCzoLtFvXNN&ihnKfVO6-D~?Cir;vt-GNQ@waBDR z-*^cVo0Angx!^oIrMn{qcH>Ui2*M!H?Tn?b{^#gukLRC7kLOhzLjjY7p3RYe{UaCH zPA>QH1BWoh-IaP3%VIB%90F>xN=>6=)KP}t-fYO&np)0I-tnduGbW8IF&VNALCj?2 z0=4O}VZ~eG9V|v2W^z=fMu$g72l6u0m0G{cyw{pb_B~ynxYv3HeWe8`eNcZ$=tUG z{?#jTW1rflb@kZih@76-!Rd)1nNC`hJ8?>}&LahgE(kIVL9)|aJx7^1!6oTAN_*Z6 z_Ah`1WtfHtu>?p=r+9Y5hM~lP*ujEC-^$8vi@v%3WYWsjqf|M5EV48{8ky@p%;cJj zY>_4fI{HL1YdJnTN=YcA>dAsJ=bcC#ivE0j|NFpncf}6oO1)%$l=jWlH|EAi?{g2V zh8ko*TDGBBkDb!OfMin%nX$F}9%F_Vgywy^@zTVJnMYzLvhRDD>LYX6hHS5AOqrE2 z#U-a~_yxF|c2)V=eV98E_Md2Oucx0n#758m^TbQo`n2%=jhOE)N z=#4MZoyq8tv^5yw*b<&m=`u2lmV(eYZW}v~A@iQ_MgPsDuY3Bfbl%bx%?G>t5Qyo% zlS%rx+Z;lCfMjgA+WE-s&?@N}V+|9L^=vc2Pjz-oEcG0TXfM`4#>An4UemvpJOz*k z-R&_?zs-FZI)QnzBr9bnU3mkX+($cD`4|ge3W6?vII>#Lj(6QV&vGigau$ds7s&0^ z>Q+noT-r-6?g&tNd1EB>1$OMz(wjRzLFWP)GYCp!8^GPPY3$$>L}V+MDg3i(@EP<$ z@N!ftv#L~zfXPU)#jTaBBjF)&95erRSL=!^3g(}lfY8FajdD+7F88P5~ zYJ)n1_F-aWjCA05spfCOP6ZCz9=27XxKvNixQ8gUlHDmxvfX!HNVX4urFgH@dMCueNihY{xY`G9? z0*Cn8)`1T2%iRfn2S6F8fO9co)Y826g4Zd>4^{s}^dmnqpSwrZ9Y&?h=Mz@Jw)3G1*lt6t z%XRq(kgZNXxb#k_$LAU<2lb6r7#?^ycJ)yT;B4Xd9+sk_j!Xapz- zXI_3v!XbuW1aobUCQggY;dg_p>r~EswFKc)l#5Iz5n(P(7RLNZvp;37D+q@b1BdA-^V>LcF^u z$aP4Egi+qaB)ucut?Ddz0kW36D}LDdL|4qP&FCKZU;0G%VLB-nBLlsZMVcH57UCHl zc;cAo9@v3x*InOyJ7Z{0NbI6C!;eB^zfezm;q+BoEv_PuHk z!l5k!XC>n6_zA8PRmRH4EvIod^iJaNQ_-4;`!U`VzYm|d$!G>ik!WiIG?1gm>rp2> z&CZVRaU5q43jK8u-~ZOcr2R_72oB!;pq|{=YMe0$qM#_BJvbOc#3n)GP7LW%5_IME zO_DAxC%|1u+`rEhZIYZQpC{@S&CSnI8(ZvvEw-_FQlgE4;(X*Or4t40DLQU{R^-R z17ODes9b*=Y+1Z_#rneyV{iPKPyaLuCRjdO(Mq1`J~K_LT>@#{U3>CD6HhXd@phomHvA5UNaV(d%>|w=nd@0WeUDrhJ@Fmr5Of2-$V|2oOve9-mI0w;=ksWh z+)k2%DmIWyN_)^599eHNdJjrAcS>^3mOJ6SWal2rc?{2Qekx~VOAp|o-+}$_f2n!H z8SNtK=qW#=-G=)|dgD(#T_x>V5IfeJWzi>R;~@}tc1U684c)gRH5v3_qlY1gXnp}2?!(4(Q0)8!`^fO3Oe zAluUdpywmS)^6zNP45>UQie8qK&?<)A4M~z;wA!}ZWxwl2x-x1otz3IaikryL0Y>B z+P0t#!;P8J`EVyqm39vh<(<|_H3Vf^83_;{i6@iqu(JPhGdSK!cMl2sNqE|g-L zMzK%g1Aau=M=*w&amS^eJ)o+$S%#$@Dcj$z-cP$Yh(U#2sQfjGo4*WsZB$PC1oN^I%-#1=>o60Z5Og zo}hJP!jHW`N?Fc0H>qBk{Q;}56+uld`i+>JiejE|zA||iBfD-q$?ZIu^#E zgkJ%{x#a~Y;EdPfQ*Yyx*bAF6eYLX%5ABitNRRu%bVe{{^ZaDRCHp0>?qqxj21&$U z1~#!$Z-UT?Z095Sa@Dh22CO{Z$wN{B2c%4~-6q3IFoaEJfYUz4xN)iS5xRwO{P&Dd zOB%VJz-K%6uQthB9fQZMs%l7KN+vB}&K|$EK;<6h{#|JyrF>6-E4HX3Dk?U>PfRoD z`Iw4=obd^$E0gK>Q-heH#fEQlKKM_ViM#n>Oo2AVROC(w-z)9Scv5QjHgl4O0<0Q_ zNI9|0hciZhrn-E}L9_k@o0u{Jp(#ivnfr(IXMCE2`v+q~oiCMj+Nj-_{hlzr=>@^h z^(I)%fEcj>+r4fzRhb$S#+%U0x+U1%V#9XlBPrZPK#_wC?jWo*rn>w-|IcxW!K~V? zR>BI>xo|w4-SC2P*}mD(C4E4MConMPw{55J+toC!40YwV)B@$>rSw4;2IYxWDQw-2 z*mE&Rn-?Qgl>DDD8%95V-7@l+rCz3otwe5GYBIOElLGFTOvFQKxjFc?L5|$D)-ExzJ0(> z-2>Jq={w&HkTUr6^A}har22Ebc{Vr0lk{CYK}zo7`nZ8IXJntH&iH%SQT1I+NL1lY zU~THz0#hbR@O?Pg@)3cvWhscr?O&NjWjoWzKa;n(D$PZ5VI-Zb-oRWw_I>X^p!oe{ z@;!^mvt-gOnE>G!5Wpnf4-uR#FC)>NWTG8FXGoj_XMVnk-uT_AO*AenK;<}htCLK$ z4oAV>_#p@Y#f2LtVjEw0f4Mf+DZBAiDsYrw?!&ayFHNZ)nTKdTg=k|N8%1WCB=YSL&DM>R(!D=d61b1yt$;+^&ml}I0g9@3A0AUNfBh>Y zNKQYK=iW`2iQN4vxarc6R!IKFl=4lCI6GQg%;0((O-(7S_b9lF?*m3+cvhUuW=UJj zioe0Onw03}ndj3o^++jkBrz0w%eh%%I9qBU&=*tpD(Z?>?1VGX8{MJgaCUUjG89L? zodHowfZW_k=Ecqjim-oyHT0Fo!b87B?t>Wd_23zka+YmUKEmCjGkz@vd>Ro&(C*i1Tv_JUz~lmaN{~T)bNaKFB8S7V(H2+ zWc#Oo{|jO%AH2<2N_^b%8lJ*K+gMN8rcZg79o+w0NO!QP6 zzIZWO(P!R~HWH_JJkH&~;Zsj;R;`dQ}K8o-5$Gz`>=QYL> zsJ5wl7v7VI4dxnW{RSewm=9MbWBi=iyMHtb-}o1}kD0F&;PnBSf8@9DqmMpMEUd73 z$D^;u%y07b=>>Sz3;g)~-gf@(1K*=WPIDg~?bBl;`v4Bu(Gwkt@tZup6=vcZkcID7 z7C{WEhEE-rS7yYmDaT5T{Iz}QVet;rVu^76g$ z*^S<6ku!VwC9`Lna_3N^3?o_U!0$P;-M}NSoScfVPnuX;9rT83w4xg2AdU8$DREZ= zm&~an-bK%(InGX`yA-%4Pis(o6K)I;+I zYG`?AHxu;MD188pBbT#WVrbqvyy+f}jG3M?gfNG{9~eJloVTjsc?~}e$Z#6hL(c3* z%!MU$B(`!4ovnFmYC>2&66a>%q;0OP%owiBQL%EWi8-@&8~I#vePZ^T{y5Ya*@nfrB)K7qu^&S)NWmL-J&I0J;KEA3%N88e&->R+2mV&fp9~Bj=jkn z2qLaR4X}q5YRD36+^$P;sQj+oQT#vt@)G_l=VkI*02(|0=Vy8U!zubQ=bhYs2>AD) zEJksE!Q5#W`}7pL{tSIjX7u~fUYjQhFLzz;Um^T6-~h3pe32-uF02+yZp;(6-Lm9H zQS26z7b3lBa&cLU*(HigL}3YDaxX0LuM=|NNaqO|L#w@kyAYsEi!QNPrZjC_U*Q}C zkIb=*hC*aiY*E~wZsiYt*k`#AZI|#WA@eBKWRb`9Mw~LOc%2$4)dYS_GWRk_(hz8f zm=WZnK6zphdaz42d<(+NohKG7m{W3TvBo81?km1LwI7(9Aa_A?hcF45n`daXSg7__ zgr?kX)5%UH^`#k`pW2CCVtJlm!X$~wV(n_-EtXfFC@n^^#Z@x4wL`fOJi@JBl)8&$ z16xC>#49d#FI)(WF%j^aB;^(}6TncwnOj_(CnlSF4e}IhleU-wRlXYYrGhPiD*|@~ zf@=dBY^QmvxzEFn{Gn6YCs=}5uQvq)vooA}v4&rDMdiM)QWkOYJXW%zgRP8JO25r@ z&GoO~orVma+EB1ju3j82A`OiQ9{j*c9%ES7cq3kt6M0Byf6YZc8)Bem{u%AYk4oJp%&x)=~aek-rV+#e1?L+}GjhiYUW4U$ena`~-fsC$!CW2ip$R zr=gyTf}i`z--Y7_IJose{1^x|=i*sZ@G8J){>2ynUVt^}Dd^OJ(u4AAly^~%p-g

97NRUisYO|X@&L+XC{Lkup!A^p8s%M-V<;1K%tyHZ<#LpTD9cf5QP!Y5 zfbtm1Qz#uMJt)6Mc^Bmv%0&F_g)>nsIa%js$er2Wf%gOGD_;Csu@kTa@X>^FAOm&- z?#+Pt;@(IG%y<8OkpcSw|0)CKS^nQM;A+4(Wx&e;|3?PA8u0G{Tku#!;sg=0!D_yOqVs$hSi7IIJoT!AZz%l;6G5>E_$rY~0 zZ>}TW)xw24Mqj8&xNu7-!J`i5tsA~K`T#i_`-I)M> zyX^}3{KQv{CVzy~@so8|1UGfURSN(^K^}L6%U54jizg{Q;i`@VLt!vb)t%KK1R~zX zhH7vNVj@0VlA4;i8uzR&by$deCi*_NgSn1z&io|*?g;?qFYB__0Q>ODp2U-Xp9BM% zg@jsu=Zd-zg?W|qm}{>G-cl6y@gg3}3=}-HmU)r6cq=AcjJ}icE`cnYsP30)xt}nO+5Ne{@t81WiNufEIhvBVc|Kj zr#Q+^jrZLQJpK?jA9xlG45i!K(58*aSN=Vova!F#gD#0jzx^YM#g~6;V6beA28JXa z>HiqT!sA(Cs7#1w(Pv%6VfiVFg|`jw;cvSZK46D=X=dGtn*1pr-%4$tkH0N&3cLdt d&*&D!`}>RztI1m07&WhD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#else -#include "windows.h" -#include -#include "ftd2xx.h" -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifndef PLATFORM_WINDOWS -typedef struct -{ - int handle; - char *device; - struct termios old_params; -}port_t; - -extern int port_open(port_t **port, char *device); -#else -typedef struct port_t -{ - FT_HANDLE handle; - int device; - HANDLE event_handle; -}port_t; - -extern int port_open(port_t **port, int device); -#endif - -extern int port_close(port_t *port); -extern int port_write(port_t *port, unsigned char *buffer, size_t buflen); -extern int port_read(port_t *port, unsigned char *buffer, size_t buflen); -extern int port_get(port_t *port, unsigned char *buffer, int timeout); -extern int port_set_params(port_t *port, uint32_t speed, uint8_t rtscts); -extern int port_dtr_set(port_t *port); -extern int port_dtr_clear(port_t *port); -extern int port_rts_set(port_t *port); -extern int port_rts_clear(port_t *port); -extern int port_readline(port_t *port, unsigned char *buffer, int buf_size, int timeout); -extern int port_write_echo(port_t *port, char *string); -extern int port_write_8byte_no_echo(port_t *port, int dlen, char *string); - -#ifdef __cplusplus -} -#endif -#endif /* _PORT_H */ diff --git a/tools/sensinode/nano_programmer/programmer.c b/tools/sensinode/nano_programmer/programmer.c deleted file mode 100644 index ee82c9389..000000000 --- a/tools/sensinode/nano_programmer/programmer.c +++ /dev/null @@ -1,440 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#include -#include -#include - -#include "port.h" -#include "programmer.h" - -#include - -extern int cdi_programmer(conf_opts_t *conf, char *filename); - -void usage(char *prg_name) -{ - printf("\nUsage: %s [-d device]\n", prg_name); - printf("General options:\n"); - printf(" -V/--version Get programmer version\n"); - printf(" -1/--d100 Use D100 board (default D200)\n"); - printf("Operating modes:\n"); - printf(" -b/--bios to get programmer BIOS version\n"); - printf(" -P/--program [ihex file] Do a complete programming sequence (write and verify)\n"); - printf(" -v/--verify [ihex file] Verify against ihex file\n"); - printf(" -r/--read [ihex file] Read program code into ihex file\n"); - printf(" -m/--mac Read device MAC address\n"); - printf(" -Q/--write-mac [MAC address] Write device MAC address\n"); - printf(" -e/--erase Erase flash (erases MAC address!)\n"); - printf("Programming options:\n"); - printf(" -l/--linear Force linear model for extended addresses (not SDCC file)\n"); - printf(" -s/--sdcc Force SDCC model for extended addresses (SDCC file)\n"); - printf("Defaults:\n"); -#ifndef PLATFORM_WINDOWS - printf("device /dev/ttyUSB0\n"); -#else - printf("device 0\n"); -#endif -} - -conf_opts_t conf_opts; - -static int option_index = 0; - -int do_exit = 0; - -#define OPTIONS_STRING "d:ec1lsmVbP:v:r:Q:" -/* long option list */ -static struct option long_options[] = -{ - {"device", 1, NULL, 'd'}, - {"psoc", 0, NULL, 'p'}, - {"d100", 0, NULL, '1'}, - {"erase", 0, NULL, 'e'}, - {"mac", 0, NULL, 'm'}, - {"linear", 0, NULL, 'l'}, - {"sdcc", 0, NULL, 's'}, - {"cdi", 0, NULL, 'c'}, - {"version", 0, NULL, 'V'}, - {"bios", 0, NULL, 'b'}, - {"program", 1, NULL, 'P'}, - {"verify", 1, NULL, 'v'}, - {"read", 1, NULL, 'r'}, - {"write-mac", 1, NULL, 'Q'}, - {0, 0, 0, 0} -}; - -int parse_opts(int count, char* param[]) -{ - int opt; - int error=0; - - conf_opts.target_type = CDI; - while ((opt = getopt_long(count, param, OPTIONS_STRING, - long_options, &option_index)) != -1) - { - switch(opt) - { - case 'V': - conf_opts.target_type = VERSION; - break; - - case '1': - conf_opts.prg_type = 1; - break; - - case 'c': - conf_opts.target_type = CDI; - break; - - case 'd': -#ifdef PLATFORM_WINDOWS - if (sscanf(optarg, "%d", &conf_opts.device) != 1) - { - printf("Device ID must be a positive integer.\n"); - conf_opts.action = ' '; - } -#else - printf("device:%s\n", optarg); - strcpy(conf_opts.device, optarg); -#endif - break; - - case 'P': - printf("Programming mode.\n"); - conf_opts.action = 'P'; - strcpy(conf_opts.ihex_file, optarg); - break; - - case 's': - if (conf_opts.page_mode == PAGE_UNDEFINED) - { - conf_opts.page_mode = PAGE_SDCC; - } - else - { - printf("Only one paging option allowed.\n"); - error = -1; - } - break; - - case 'l': - if (conf_opts.page_mode == PAGE_UNDEFINED) - { - conf_opts.page_mode = PAGE_LINEAR; - } - else - { - printf("Only one paging option allowed.\n"); - error = -1; - } - break; - - case 'e': - printf("Erase.\n"); - conf_opts.action = 'e'; - break; - - case 'm': - printf("Get MAC.\n"); - conf_opts.action = 'm'; - break; - - case 'b': - printf("Get BIOS version\n"); - conf_opts.action = 'b'; - break; - - case 'Q': - printf("Write MAC.\n"); - conf_opts.action = 'Q'; - if (sscanf(optarg, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", - &conf_opts.write_mac[0], &conf_opts.write_mac[1], - &conf_opts.write_mac[2], &conf_opts.write_mac[3], - &conf_opts.write_mac[4], &conf_opts.write_mac[5], - &conf_opts.write_mac[6], &conf_opts.write_mac[7]) != 8) - { - printf("Invalid MAC.\n"); - conf_opts.action = ' '; - } - break; - - case 'v': - printf("Verify by comparing to ihex file:%s\n", optarg); - conf_opts.action = 'v'; - strcpy(conf_opts.ihex_file, optarg); - break; - - case 'r': - printf("Read program to ihex file:%s\n", optarg); - conf_opts.action = 'r'; - strcpy(conf_opts.ihex_file, optarg); - break; - - case '?': - printf("Duh\n"); - error = -1; - break; - } - } - - if (!error && (conf_opts.target_type == CDI) ) - { -#ifdef PLATFORM_WINDOWS - printf("Setup: Device %d.\n", conf_opts.device); -#else - printf("Setup: Device %s.\n", conf_opts.device); -#endif - } - - return error; -} -/* -int port_write_8byte_echo(port_t *port, char *string) -{ - int length = 0; - int total_len; - int i, j; - struct pollfd pfds; - unsigned int nfds = 1; - int rval = 0; - - int wrbytes = 2; - unsigned char byte8[wrbytes]; - - pfds.fd = (int)(port->handle); - pfds.events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL; - - total_len = strlen(string); - - while(total_len > length) - { - if(total_len - length >= wrbytes) - { - i=0; - port_write(port, (unsigned char *)&string[length], wrbytes); - - if((rval = poll(&pfds, nfds, 100)) == 0) - { - printf("Timed out...\n"); - return(-1); - } - else - { - while(i %.2x\n", string[length+j], byte8[j]); - } - - return(-1); - } - else - { - printf("8Bwok - "); - fflush(stdout); - length += wrbytes; - } - - } - } - else - { - i=0; - port_write(port, (unsigned char *)&string[length], total_len - length); - - if((rval = poll(&pfds, nfds, 100)) == 0) - { - printf("Timed out...\n"); - return(-1); - } - else - { - while(i<(total_len-length)) - { - i = port_read(port, &byte8[i], total_len - length); - } - if(i != total_len - length || memcmp(byte8, &string[length], total_len - length) != 0) - { - printf("Got wrong length or wrong bytes back.\n"); - for(j=0;j %.2x\n", string[length+j], byte8[j]); - } - - return(-1); - } - else - { - printf("<8Bwok - \n"); - fflush(stdout); - length += (total_len - length); - } - } - } - - usleep(5000); - - } - - return(length); -} -*/ -#ifdef PLATFORM_WINDOWS -int programmer_init(int device, port_t **port) -#else -int programmer_init(char *device, port_t **port) -#endif -{ - int error = port_open(port, device); - uint8_t buffer[8]; - - buffer[0] = 0; - - if (error >= 0) - { - if (conf_opts.prg_type == 1) - { - int retry = 0; - port_set_params(*port, 9600, 0); - // Activate programming... - port_dtr_clear(*port); - port_rts_clear(*port); - sleep(1); - printf("Select D100.\n"); - port_rts_set(*port); - sleep(1); - buffer[0] = '\r'; - while (retry++ < 3) - { - int length; - port_write_echo(*port, "q\r"); - length = port_readline(*port, buffer, sizeof(buffer), 800); - if (length) - { - if (*buffer == '!') - { - printf("D100 found.\n"); - return 0; - } - } - } - printf("No programmer found.\n"); - return -1; - } - else - { - port_set_params(*port, 57600, 0); - // Activate programming... - port_dtr_clear(*port); - port_rts_clear(*port); - usleep(300000); - printf("Select D200.\n"); - port_rts_set(*port); - usleep(200000); - port_set_params(*port, 57600, 1); - port_write(*port, (uint8_t *)"\r", 1); - usleep(100000); - if ((port_get(*port, buffer, 500) >= 1) && (buffer[0] == '!')) - { - printf("D200 found.\n"); - return 0; - } - printf("No programmer found.\n"); - return -1; - } - } - return error; -} - -void programmer_close(port_t *port) -{ - if (port) - { - port_rts_clear(port); - port_dtr_set(port); - sleep(1); - port_close(port); - printf("Port closed.\n"); - } -} - -int main(int argc, char *argv[]) -{ - int error = 0; - - conf_opts.target_type = 0; - conf_opts.action = 0; - conf_opts.prg_type = 2; - - -#ifndef PLATFORM_WINDOWS - strncpy(conf_opts.device, "/dev/ttyUSB0", 12); -/* Install a new handler for SIGIO. - * - * According to man 7 signal this signal is by default ignored by most systems. - * It seems that pre FC7 this was true for Fedoras also. We have noticed that at least - * on some FC7 installations the default action has changed. We avoid abnormal program - * exits by defining the SIGIO as SIG_IGN (ignore). - mjs - */ - if(signal(SIGIO, SIG_IGN) == SIG_ERR) - { - printf("%s error: failed to install SIGIO handler. Exit.\n", argv[0]); - exit(EXIT_FAILURE); - } -#else - conf_opts.device = 0; -#endif - - conf_opts.page_mode = PAGE_UNDEFINED; - - if ( (argc <= 1) || (error = parse_opts(argc, argv)) ) - { - usage(argv[0]); - if (error < 0) return error; - else return 0; - } - - if(conf_opts.target_type == CDI) - { /*CDI*/ - error = cdi_programmer(&conf_opts, conf_opts.ihex_file); - } - else - { - printf("\nSensinode Nano series programmer "PROGRAMMER_VERSION "\n"); - } - return error; -} diff --git a/tools/sensinode/nano_programmer/programmer.h b/tools/sensinode/nano_programmer/programmer.h deleted file mode 100644 index d8eab549e..000000000 --- a/tools/sensinode/nano_programmer/programmer.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#define PROGRAMMER_VERSION "v1.3" - -typedef enum -{ - PAGE_SDCC, - PAGE_LINEAR, - PAGE_UNDEFINED -}page_mode_t; - -typedef struct { -#ifdef PLATFORM_WINDOWS - int device; -#else - char device[128]; -#endif - int target_type; - int prg_type; - int action; - char ihex_file[128]; - unsigned char write_mac[8]; - page_mode_t page_mode; -}conf_opts_t; - -enum target { UNDEFINED, VERSION, CDI }; - -#ifdef PLATFORM_WINDOWS -extern int programmer_init(int device, port_t **port); -#else -extern int programmer_init(char *device, port_t **port); -#endif - -extern void programmer_close(port_t *port); - diff --git a/tools/sensinode/nano_programmer/windows/port.c b/tools/sensinode/nano_programmer/windows/port.c deleted file mode 100644 index 5b9a09f9c..000000000 --- a/tools/sensinode/nano_programmer/windows/port.c +++ /dev/null @@ -1,383 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#include "port.h" -#include - -int port_open(port_t **port, int device) -{ - port_t *new_port = (port_t *) malloc(sizeof(port_t)); - FT_STATUS status; - - *port = new_port; - - new_port->device = device; - new_port->handle = 0; - - status = FT_Open(device, &(new_port->handle)); - - if (status != FT_OK) - { - new_port->handle = 0; - - printf("Serial port open failed with error message: %d.\n", (int)status); - return(-1); - } - else - { - DWORD mask; - new_port->event_handle = CreateEvent(NULL, TRUE, FALSE, "SN_USB_UART_EVENTS"); - if (new_port->event_handle == NULL) - { - printf("Event handle creation failed.\n"); - FT_Close(new_port->handle); - new_port->handle = 0; - return(-1); - } - mask = FT_EVENT_RXCHAR | FT_EVENT_MODEM_STATUS; - status = FT_SetEventNotification(new_port->handle,mask,new_port->event_handle); - if (status != FT_OK) - { - printf("Setting event notification failed.\n"); - } - FT_SetTimeouts(new_port->handle,400,0); - return(0); - } -} - -int port_close(port_t *port) -{ - if (!port) - return(-1); - - if ((port->event_handle) != NULL) - { - CloseHandle(port->event_handle); - port->event_handle = NULL; - - FT_Purge(port->handle, FT_PURGE_RX | FT_PURGE_TX); - FT_Close(port->handle); - port->handle = 0; - } - - port->device = 0; - free(port); - - return(1); -} - -int port_set_params(port_t *port, uint32_t speed, uint8_t rtscts) -{ - FT_STATUS status; - - if (!port) return -1; - status = FT_SetBaudRate (port->handle, speed); - if (status != FT_OK) return -1; - if (speed == 9600) - { - status = FT_SetDataCharacteristics(port->handle, FT_BITS_8, FT_STOP_BITS_2, FT_PARITY_NONE); - } - else - { - status = FT_SetDataCharacteristics(port->handle, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_NONE); - } - - if (status != FT_OK) return -1; - - if (rtscts) - { - status = FT_SetFlowControl(port->handle, FT_FLOW_RTS_CTS, 0, 0); - } - else - { - status = FT_SetFlowControl(port->handle, FT_FLOW_NONE, 0, 0); - } - - if (status != FT_OK) return -1; - - FT_Purge(port->handle, FT_PURGE_RX | FT_PURGE_TX); - - return(0); -} - -int port_dtr_set(port_t *port) -{ - FT_STATUS status; - - if (!port) return(-1); - - status = FT_SetDtr(port->handle); - if (status != FT_OK) - { - printf("Control failed.\n"); - return -1; - } - return 0; -} - -int port_dtr_clear(port_t *port) -{ - FT_STATUS status; - - if (!port) return(-1); - - status = FT_ClrDtr(port->handle); - if (status != FT_OK) - { - printf("Control failed.\n"); - return -1; - } - return 0; -} - -int port_rts_set(port_t *port) -{ - FT_STATUS status; - - if (!port) return(-1); - - status = FT_SetRts(port->handle); - if (status != FT_OK) - { - printf("Control failed.\n"); - return -1; - } - return 0; -} - -int port_rts_clear(port_t *port) -{ - FT_STATUS status; - - if (!port) return(-1); - - status = FT_ClrRts(port->handle); - if (status != FT_OK) - { - printf("Control failed.\n"); - return -1; - } - return 0; -} - -int port_write(port_t *port, unsigned char *buffer, size_t buflen) -{ - FT_STATUS status; - DWORD bytes_out; - - if (!port) return -1; - -// FT_Purge(port->handle, FT_PURGE_RX); - - status = FT_Write (port->handle, (LPVOID) buffer, (DWORD) buflen,&bytes_out); - if (status != FT_OK) return -1; - - return 0; -} - -int port_read(port_t *port, unsigned char *buffer, size_t buflen) -{ - DWORD l = 0; - FT_STATUS status; - status = FT_Read(port->handle, buffer, buflen, &l); - return((int) l); -} - -int port_get(port_t *port, unsigned char *buffer, int timeout) -{ - DWORD bytes = 0; - FT_STATUS status; - - FT_SetTimeouts(port->handle, timeout, 0); - - status = FT_Read(port->handle, buffer, 1, &bytes); - if (status != FT_OK) - { - return(-1); - } - return bytes; -} - -int port_readline(port_t *port, unsigned char *buffer, int buf_size, int timeout) -{ - int length = 0; - DWORD bytes = 0; - FT_STATUS status; - - FT_SetTimeouts(port->handle, timeout, 0); - - do - { - status = FT_Read(port->handle, &buffer[length], 1, &bytes); - length += bytes; - if ((status != FT_OK) || (bytes == 0)) - { - return(length); - } - else - { - if (buffer[length-1] == '\n') - { - buf_size = length; - } - } - }while(length < buf_size); - - buffer[length] = 0; - - if(length != 0) - return length; - else - return(-1); -} - -int port_write_echo(port_t *port, char *string) -{ - int length = 0; - int retry = 0; - unsigned char byte; - DWORD bytes_out; - FT_STATUS status; - - FT_Purge(port->handle, FT_PURGE_RX | FT_PURGE_TX); - - while( (string[length]) && (retry < 100) ) - { - retry = 0; - while (retry++ < 100) - { - status = FT_Write (port->handle, (LPVOID) &string[length], (DWORD) 1,&bytes_out); - if (status != FT_OK) return -1; - if (port_get(port, &byte, 1000) == 1) - { -/* printf("%c",byte);*/ - if (byte == string[length]) - { - retry = 0; - length++; - break; - } - else retry = 100; - } - else usleep(500); - } - } - if ((string[strlen(string)-1] == '\r') && (retry < 100) ) - { /*wait for \n*/ - retry = 0; - while (retry++ < 100) - { - if (port_get(port, &byte, 1000) == 1) - { -/* printf("%c",byte);*/ - break; - } - else usleep(500); - } - } - - if (retry >= 100) return 0; - else return length; -} - -#if 0 - -int port_write_echo(port_t *port, char *string) -{ - int length = 0; - int retry = 0; - unsigned char byte; - - while( (string[length]) && (retry < 100) ) - { - port_write(port, (unsigned char *) &string[length], 1); - while (retry++ < 100) - { - if (port_read(port, &byte, 1) == 1) - { -/* printf("%c",byte);*/ - if (byte == string[length]) - { - retry = 0; - length++; - break; - } - else retry = 100; - } - else usleep(1000); - } - } - if ((string[strlen(string)-1] == '\r') && (retry < 100) ) - { /*wait for \n*/ - retry = 0; - while (retry++ < 100) - { - if (port_read(port, &byte, 1) == 1) - { -/* printf("%c",byte);*/ - break; - } - else usleep(1000); - } - } - - if (retry >= 100) return 0; - else return length; -} - - -int port_write_8byte_no_echo(port_t *port, int dlen, char *string) -{ - int length = 0; - int total_len; - int wrbytes = 4; - - total_len = dlen; - -/* printf("total: %d, length: %d, dlen: %d.\n", total_len, length, dlen); */ - while(total_len > length) - { - if((total_len - length) >= wrbytes) - { - port_write(port, (unsigned char *)&string[length], wrbytes); - length += wrbytes; - } - else - { - port_write(port, (unsigned char *)&string[length], total_len - length); - length += total_len - length; - } - usleep(1250); - - } - - return(length); -} - -#endif diff --git a/tools/sensinode/nano_usb_programmer/Makefile b/tools/sensinode/nano_usb_programmer/Makefile deleted file mode 100644 index 2c1e40988..000000000 --- a/tools/sensinode/nano_usb_programmer/Makefile +++ /dev/null @@ -1,32 +0,0 @@ -EXE_MAKE=$(notdir $(shell which "make.exe")) -ifeq "$(EXE_MAKE)" "make.exe" -PLATFORM=windows -else -PLATFORM=linux -endif - -include Rules.make - -APP = nano_usb_programmer$(SUFFIX) -OBJS = $(SOURCES:.c=.o) - -all: $(APP) - -$(APP): $(OBJS) Makefile $(SOURCES) - $(CC) -o $(APP) $(CFLAGS) $(OBJS) $(LDFLAGS) - -platform-test: - @echo $(PLATFORM) - -clean: - rm -f *.o ; rm -f $(APP) - -.c.o: - $(CC) -c -o $(<:.c=.o) $(CFLAGS) $< - -ftd2xx.def: - echo EXPORTS > ftd2xx.def - nm ftd2xx.lib | grep ' T _' | sed 's/.* T _//' >> ftd2xx.def - -ftd2xx.dll.a: ftd2xx.def - dlltool --def ftd2xx.def --dllname ftd2xx.dll --output-lib ftd2xx.dll.a diff --git a/tools/sensinode/nano_usb_programmer/README.md b/tools/sensinode/nano_usb_programmer/README.md deleted file mode 100644 index c5ea77f8b..000000000 --- a/tools/sensinode/nano_usb_programmer/README.md +++ /dev/null @@ -1,60 +0,0 @@ -Nano USB Programmer -=================== - -An USB programmer for the Sensinode NanoRouter N600. - -Copyright 2007-2008 Sensinode Ltd. - -Installation ------------- - -### Linux - -The installation is quite simple but requires the user to obtain the FTDI -development library. The installation also requires root privileges in some -phases (the ldconfig command to be more specific). Running the -Nano_USB_Programmer executable might also require root privileges. - -- unpack the Nano_USB_Programmer-v[xxx].zip to a directory -- get the FTDI development library from - [http://www.ftdichip.com/Drivers/D2XX/Linux/libftd2xx0.4.13.tar.gz](http://www.ftdichip.com/Drivers/D2XX/Linux/libftd2xx0.4.13.tar.gz) -- unpack the ftdi archive -- copy the library static_lib/libftd2xx.a.[version] into /usr/lib -- copy the library libftd2xx.so.[version] into /usr/lib -- make a symbolic link to the library, for example: ln -s - /usr/lib/libftd2xx.so.0.4.13 /usr/lib/libftd2xx.so -- run ldconfig -- copy the header files into the nano_usb_programmer/ftdi_linux/ directory -- go to the programmer directory and run make - -### Windows/Cygwin - -- The FTDI library can be downloaded at: - -[http://www.ftdichip.com/Drivers/CDM/CDM%202.02.04%20WHQL%20Certified.zip](http://www.ftdichip.com/Drivers/CDM/CDM%202.02.04%20WHQL%20Certified.zip) - -- Copy header files (ftd2xx.h), ftd2xx.lib and ftd2xx.dll to nano_usb_programmer/ftdi_win32 -- Copy the ftd2xx.dll to your windows system32 directory - -Usage ------ - -Usage info for the Nano_USB_Programmer is available with command -./nano_usb_programmer --help. Note that use might require root/administrator -privileges depending on system configuration. - -Known problems (Linux) ----------------------- - -There's one known problem at the moment. The N600 must be unplugged and plugged -in again after it has been programmed or the MAC address has been read from it -before it can respond to the programmer again. The reason for this is the FTDI -library is not perfectly integrated with the Linux serial driver. - -README Version --------------- - -v1.0 2007-11-14 Mikko Saarnivala Initial release -v1.1 2007-11-15 Mikko Saarnivala A small error in the instructions fixed -v1.2 2007-11-19 Mikko Saarnivala Added the FTDI CBUS2 value handling -v1.3 2008-01-31 Martti Huttunen Multi-platform build and updated instructions diff --git a/tools/sensinode/nano_usb_programmer/Rules.make b/tools/sensinode/nano_usb_programmer/Rules.make deleted file mode 100644 index 034cd0321..000000000 --- a/tools/sensinode/nano_usb_programmer/Rules.make +++ /dev/null @@ -1,14 +0,0 @@ -ifeq "$(PLATFORM)" "linux" -CC=gcc -CFLAGS= -I. -I./ftdi_linux -L. -L./ftdi_linux -DPLATFORM_LINUX -LDFLAGS= -lftd2xx -Wl,-rpath /usr/local/lib -SOURCES=main.c prog.c cdi.c ihex.c -SUFFIX= -else -CC=gcc -CFLAGS=-I. -I./ftdi_win32 -L. -L./ftdi_win32 -DPLATFORM_WINDOWS -CFLAGS+= -mwin32 -LDFLAGS=ftdi_win32/ftd2xx.lib -lkernel32 -SOURCES=main.c prog.c cdi.c ihex.c -SUFFIX=.exe -endif diff --git a/tools/sensinode/nano_usb_programmer/cdi.c b/tools/sensinode/nano_usb_programmer/cdi.c deleted file mode 100644 index 2d490869f..000000000 --- a/tools/sensinode/nano_usb_programmer/cdi.c +++ /dev/null @@ -1,506 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#include -#ifdef PLATFORM_WINDOWS -#include -#endif -#include "cdi.h" - -/*read none/8*/ -#define CDI_CHIP_ERASE 0x10 -#define CDI_WR_CONFIG 0x19 -#define CDI_SET_HW_BRKPNT 0x3B - -/*read 8*/ -#define CDI_RD_CONFIG 0x24 -#define CDI_READ_STATUS 0x34 -#define CDI_HALT 0x44 -#define CDI_RESUME 0x4C -#define CDI_STEP_INSTR 0x5C - -/*variable len, add data length to command byte*/ -#define CDI_DBGINSTR 0x54 -#define CDI_STEP_REPLACE 0x64 - -/*response = 16 bits*/ -#define CDI_GET_PC 0x28 -#define CDI_GET_CHIP_ID 0x68 - - -/* internals */ -void cdi_command_push(uint8_t *byte, uint8_t bytes_out, uint16_t *retval, uint8_t return_bits); - -void cdi_flash_bank(uint8_t bank, uint8_t unif_mode); - -void cdi_dptr_write(uint16_t value); - -uint8_t cdi_reg_read(uint8_t reg_addr); -void cdi_reg_write(uint8_t reg_addr, uint8_t value); - -void cdi_xdata_write(uint8_t value); -uint8_t cdi_xdata_read(void); - -void cdi_flash_init(void); -void cdi_flash_write_page(void); - -uint32_t cdi_addr = 0; - -#define pause_ms(x) usleep(x*1000) -#define pause_us(x) usleep(x) - -void cdi_command_push(uint8_t *byte, uint8_t bytes_out, uint16_t *retval, uint8_t return_bits) -{ - uint8_t i, val; - - for (i=0; i>= 3; - for (i=0; i> 8); /*immediateh*/ - out[3] = value; /*immediatel*/ - cdi_command_push(out, 4, &retval, 8); -} - - -uint8_t cdi_reg_read(uint8_t reg_addr) -{ - uint8_t out[3]; - uint16_t retval; - - out[0] = CDI_DBGINSTR + 2; /*command length 2 bytes*/ - out[1] = 0xE5; /*mov a, sfr*/ - out[2] = reg_addr; /*sfr = reg_addr*/ - cdi_command_push(out, 3, &retval, 8); - - return (uint8_t) retval; -} - - -void cdi_flash_bank(uint8_t bank, uint8_t unif_mode) -{ - uint8_t out; - - out = (bank << 4) + 1; - out &= 0x31; - if (unif_mode) out |= 0x40; /*set unified memory model*/ - - cdi_reg_write(0xC7, out); -} - - -void cdi_flash_read(uint8_t *ptr, uint16_t bytes) -{ - uint16_t i; - uint8_t out[4]; - uint16_t retval; - - cdi_flash_bank((cdi_addr >> 15), 0); - - cdi_dptr_write(cdi_addr | 0x8000); - - for (i=0; i> 10) & 0x7F); /*sfr = FADDRH*/ - cdi_reg_write(0xAC, (cdi_addr >> 2)); /*sfr = FADDRL*/ - - /*erase page*/ - cdi_reg_write(0xAE, 0x01); - pause_ms(40); - - /*set program counter*/ - out[0] = CDI_DBGINSTR + 3; /*command length 3 bytes*/ - out[1] = 0x02; /*ljmp immediate16*/ - out[2] = 0xE0; /*immediateh*/ - out[3] = 0x00; /*immediatel*/ - cdi_command_push(out, 4, &retval, 8); - - /*set breakpoint*/ - out[0] = CDI_SET_HW_BRKPNT; /*command length 3 bytes*/ - out[1] = 0x04; - out[2] = 0xE0; /*immediateh*/ - out[3] = sizeof(cdi_ram_code)-2; /*immediatel*/ - cdi_command_push(out, 4, &retval, 0); - - cdi_dptr_write(0xE800); /*data area, set your page data here*/ - /*execute*/ - out[0] = CDI_RESUME; /*command length 3 bytes*/ - cdi_command_push(out, 1, &retval, 8); - - pause_ms(30); - out[3]= 0; - do - { - pause_ms(20); - out[0] = CDI_READ_STATUS; - cdi_command_push(out, 1, &retval, 8); - printf("-"); - fflush(stdout); - }while( ((retval & 0x20) == 0) && (out[3]++ < 200) ); -} - -int cdi_flash_write(uint8_t *ptr, uint16_t length) -{ - uint16_t i, retval; - uint8_t out[3]; - - if (length > 2048) return -1; - - cdi_addr &= 0x1F800; /*make sure address is on page boundary*/ - - printf("0x%6.6X: ", cdi_addr); - fflush(stdout); - cdi_dptr_write(0xE800); /*our page data buffer is here*/ - for (i=0; i< length; i++) - { - cdi_xdata_write(*ptr++); - if ((i & 0x3F) == 0) - { - printf("."); - } - if ((i & 0x0F) == 0x00) - { - printf("\bo"); - } - if ((i & 0x0F) == 0x08) - { - printf("\b."); - } - fflush(stdout); - } - while(i<2048) - { - cdi_xdata_write(0xFF); - if ((i & 0x3F) == 0) - { - printf("."); - } - if ((i & 0x0F) == 0x00) - { - printf("\bo"); - } - if ((i & 0x0F) == 0x08) - { - printf("\b."); - } - fflush(stdout); - i++; - } - - out[0] = CDI_HALT; - cdi_command_push(out, 1, &retval, 8); - - out[0] = CDI_READ_STATUS; - retval = 0; - cdi_command_push(out, 1, &retval, 8); - if ((retval & 0xFF) == 0xB2) - { - /*restore config*/ - out[0] = CDI_WR_CONFIG; /*command length 3 bytes*/ - out[1] = 0x0E; /*write flash area*/ - cdi_command_push(out, 2, &retval, 0); - /*set flash timings and copy code to ram*/ - cdi_flash_init(); - /*write page*/ - cdi_flash_write_page(); - cdi_addr += 2048; /*increment page address*/ - pause_ms(10); - } - else - { - return -1; - } - return 0; -} - -int cdi_flash_write_mac(uint8_t *ptr) -{ - uint16_t i, retval; - uint8_t out[3]; - - cdi_addr = 0x1F800; /*last page*/ - - printf("0x%6.6X", cdi_addr); - fflush(stdout); - cdi_dptr_write(0xEFF8); /*our page data buffer is here*/ - for (i=0; i<8; i++) - { - cdi_xdata_write(*ptr++); - if ((i & 0x0F) == 0) - { - printf("."); - fflush(stdout); - } - } - - out[0] = CDI_HALT; - cdi_command_push(out, 1, &retval, 8); - - out[0] = CDI_READ_STATUS; - retval = 0; - cdi_command_push(out, 1, &retval, 8); - if ((retval & 0xFF) == 0xB2) - { - /*restore config*/ - out[0] = CDI_WR_CONFIG; /*command length 3 bytes*/ - out[1] = 0x0E; /*write flash area*/ - cdi_command_push(out, 2, &retval, 0); - /*set flash timings and copy code to ram*/ - cdi_flash_init(); - /*write page*/ - cdi_flash_write_page(); - cdi_addr += 2048; /*increment page address*/ - pause_ms(10); - } - else - { - return -1; - } - return 0; -} - -int cdi_start(uint16_t *chip_id) -{ - uint8_t out[3]; - uint16_t retval; - - prog_start(); /*do the CDI startup sequence*/ - - out[0] = CDI_READ_STATUS; - cdi_command_push(out, 1, &retval, 8); - - printf("Status: %2.2X.\n", retval & 0xFF); - - out[0] = CDI_GET_CHIP_ID; - cdi_command_push(out, 1, &retval, 16); - - *chip_id = retval; - - out[0] = CDI_HALT; - cdi_command_push(out, 1, &retval, 8); - - pause_ms(100); - - out[0] = CDI_WR_CONFIG; /*command length 3 bytes*/ - out[1] = 0x0E; /*write flash area*/ - cdi_command_push(out, 2, &retval, 0); - - pause_ms(10); - - cdi_reg_write(0xC6, 0xC9); /*sfr = CLKCON*/ - - pause_ms(10); - - cdi_reg_write(0xAB, 0x15); /*sfr = FWT*/ - - cdi_addr = 0; - - return 0; -} - -int cdi_erase(void) -{ - uint8_t out[3]; - uint16_t retval; - uint8_t i; - - out[0] = CDI_WR_CONFIG; - out[1] = 0x0E; - cdi_command_push(out, 2, &retval, 0); - out[0] = CDI_CHIP_ERASE; - cdi_command_push(out, 1, &retval, 0); - retval = 0; - i = 0; - do - { - pause_ms(30); - out[0] = CDI_READ_STATUS; - cdi_command_push(out, 1, &retval, 8); - }while( ((retval & 0x84) != 0x80) && (i++ < 100) ); - - cdi_addr = 0; - - if (i >= 100) - { - return -1; - } - return 0; -} - -void cdi_set_address(uint32_t address) -{ - cdi_addr = address; -} diff --git a/tools/sensinode/nano_usb_programmer/cdi.h b/tools/sensinode/nano_usb_programmer/cdi.h deleted file mode 100644 index 40e909178..000000000 --- a/tools/sensinode/nano_usb_programmer/cdi.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#ifndef _CDI_H -#define _CDI_H - -#include "prog.h" - -/* export these */ -extern int cdi_start(uint16_t *chip_id); -extern int cdi_erase(void); - -extern void cdi_set_address(uint32_t address); - -extern void cdi_flash_read(uint8_t *ptr, uint16_t bytes); -extern int cdi_flash_write(uint8_t *ptr, uint16_t length); - -#endif diff --git a/tools/sensinode/nano_usb_programmer/ftdi_linux/WinTypes.h b/tools/sensinode/nano_usb_programmer/ftdi_linux/WinTypes.h deleted file mode 100644 index 4def457b7..000000000 --- a/tools/sensinode/nano_usb_programmer/ftdi_linux/WinTypes.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#ifndef __WINDOWS_TYPES__ -#define __WINDOWS_TYPES__ - -#define MAX_NUM_DEVICES 50 -#include - -typedef unsigned long DWORD; -typedef unsigned long ULONG; -typedef unsigned short USHORT; -typedef short SHORT; -typedef unsigned char UCHAR; -typedef unsigned short WORD; -typedef unsigned char BYTE; -typedef unsigned char *LPBYTE; -typedef int BOOL; -typedef char BOOLEAN; -typedef char CHAR; -typedef int *LPBOOL; -typedef unsigned char *PUCHAR; -typedef const char *LPCSTR; -typedef char *PCHAR; -typedef void *PVOID; -typedef void *HANDLE; -typedef long LONG; -typedef int INT; -typedef unsigned int UINT; -typedef char *LPSTR; -typedef char *LPTSTR; -typedef DWORD *LPDWORD; -typedef WORD *LPWORD; -typedef ULONG *PULONG; -typedef PVOID LPVOID; -typedef void VOID; -typedef unsigned long long int ULONGLONG; - -typedef struct _OVERLAPPED { - DWORD Internal; - DWORD InternalHigh; - DWORD Offset; - DWORD OffsetHigh; - HANDLE hEvent; -} OVERLAPPED, *LPOVERLAPPED; - -typedef struct _SECURITY_ATTRIBUTES { - DWORD nLength; - LPVOID lpSecurityDescriptor; - BOOL bInheritHandle; -} SECURITY_ATTRIBUTES , *LPSECURITY_ATTRIBUTES; - -typedef struct timeval SYSTEMTIME; -typedef struct timeval FILETIME; -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif - -// -// Modem Status Flags -// -#define MS_CTS_ON ((DWORD)0x0010) -#define MS_DSR_ON ((DWORD)0x0020) -#define MS_RING_ON ((DWORD)0x0040) -#define MS_RLSD_ON ((DWORD)0x0080) - -// -// Error Flags -// - -#define CE_RXOVER 0x0001 // Receive Queue overflow -#define CE_OVERRUN 0x0002 // Receive Overrun Error -#define CE_RXPARITY 0x0004 // Receive Parity Error -#define CE_FRAME 0x0008 // Receive Framing error -#define CE_BREAK 0x0010 // Break Detected -#define CE_TXFULL 0x0100 // TX Queue is full -#define CE_PTO 0x0200 // LPTx Timeout -#define CE_IOE 0x0400 // LPTx I/O Error -#define CE_DNS 0x0800 // LPTx Device not selected -#define CE_OOP 0x1000 // LPTx Out-Of-Paper -#define CE_MODE 0x8000 // Requested mode unsupported - -#ifndef INVALID_HANDLE_VALUE -#define INVALID_HANDLE_VALUE 0xFFFFFFFF -#endif - -#endif diff --git a/tools/sensinode/nano_usb_programmer/ftdi_linux/ftd2xx.h b/tools/sensinode/nano_usb_programmer/ftdi_linux/ftd2xx.h deleted file mode 100644 index f4146f1d8..000000000 --- a/tools/sensinode/nano_usb_programmer/ftdi_linux/ftd2xx.h +++ /dev/null @@ -1,975 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -/*++ - -Copyright (c) 2001-2006 Future Technology Devices International Ltd. - -Module Name: - - ftd2xx.h - -Abstract: - - Native USB interface for FTDI FT8U232/245/2232C - FTD2XX library definitions - -Environment: - - kernel & user mode - -Revision History: - - 13/03/01 awm Created. - 13/01/03 awm Added device information support. - 19/03/03 awm Added FT_W32_CancelIo. - 12/06/03 awm Added FT_StopInTask and FT_RestartInTask. - 18/09/03 awm Added FT_SetResetPipeRetryCount. - 10/10/03 awm Added FT_ResetPort. - /03/04 st modified for linux users - 12/10/04 st added FT_SetVIDPID - - ---*/ - - -#ifndef FTD2XX_H -#define FTD2XX_H - -#ifndef _WINDOWS -#include -#define WINAPI -#endif - -// The following ifdef block is the standard way of creating macros -// which make exporting from a DLL simpler. All files within this DLL -// are compiled with the FTD2XX_EXPORTS symbol defined on the command line. -// This symbol should not be defined on any project that uses this DLL. -// This way any other project whose source files include this file see -// FTD2XX_API functions as being imported from a DLL, whereas this DLL -// sees symbols defined with this macro as being exported. - -#ifdef FTD2XX_EXPORTS -#define FTD2XX_API __declspec(dllexport) -#else -#define FTD2XX_API __declspec(dllimport) -#endif - -#ifndef _WINDOWS -#include "WinTypes.h" - -#ifdef FTD2XX_API -#undef FTD2XX_API -#define FTD2XX_API -#endif -#endif -typedef struct _EVENT_HANDLE{ - pthread_cond_t eCondVar; - pthread_mutex_t eMutex; - int iVar; -} EVENT_HANDLE; - -typedef DWORD *FT_HANDLE; - -typedef ULONG FT_STATUS; - -// -// Device status -// -enum { - FT_OK, - FT_INVALID_HANDLE, - FT_DEVICE_NOT_FOUND, - FT_DEVICE_NOT_OPENED, - FT_IO_ERROR, - FT_INSUFFICIENT_RESOURCES, - FT_INVALID_PARAMETER, - FT_INVALID_BAUD_RATE, //7 - - FT_DEVICE_NOT_OPENED_FOR_ERASE, - FT_DEVICE_NOT_OPENED_FOR_WRITE, - FT_FAILED_TO_WRITE_DEVICE, - FT_EEPROM_READ_FAILED, - FT_EEPROM_WRITE_FAILED, - FT_EEPROM_ERASE_FAILED, - FT_EEPROM_NOT_PRESENT, - FT_EEPROM_NOT_PROGRAMMED, - FT_INVALID_ARGS, - FT_NOT_SUPPORTED, - FT_OTHER_ERROR -}; - - -#define FT_SUCCESS(status) ((status) == FT_OK) - -// -// FT_OpenEx Flags -// - -#define FT_OPEN_BY_SERIAL_NUMBER 1 -#define FT_OPEN_BY_DESCRIPTION 2 - -// -// FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags -// - -#define FT_LIST_NUMBER_ONLY 0x80000000 -#define FT_LIST_BY_INDEX 0x40000000 -#define FT_LIST_ALL 0x20000000 - -#define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL) - -// -// Baud Rates -// - -#define FT_BAUD_300 300 -#define FT_BAUD_600 600 -#define FT_BAUD_1200 1200 -#define FT_BAUD_2400 2400 -#define FT_BAUD_4800 4800 -#define FT_BAUD_9600 9600 -#define FT_BAUD_14400 14400 -#define FT_BAUD_19200 19200 -#define FT_BAUD_38400 38400 -#define FT_BAUD_57600 57600 -#define FT_BAUD_115200 115200 -#define FT_BAUD_230400 230400 -#define FT_BAUD_460800 460800 -#define FT_BAUD_921600 921600 - -// -// Word Lengths -// - -#define FT_BITS_8 (UCHAR) 8 -#define FT_BITS_7 (UCHAR) 7 -#define FT_BITS_6 (UCHAR) 6 -#define FT_BITS_5 (UCHAR) 5 - -// -// Stop Bits -// - -#define FT_STOP_BITS_1 (UCHAR) 0 -#define FT_STOP_BITS_1_5 (UCHAR) 1 -#define FT_STOP_BITS_2 (UCHAR) 2 - -// -// Parity -// - -#define FT_PARITY_NONE (UCHAR) 0 -#define FT_PARITY_ODD (UCHAR) 1 -#define FT_PARITY_EVEN (UCHAR) 2 -#define FT_PARITY_MARK (UCHAR) 3 -#define FT_PARITY_SPACE (UCHAR) 4 - -// -// Flow Control -// - -#define FT_FLOW_NONE 0x0000 -#define FT_FLOW_RTS_CTS 0x0100 -#define FT_FLOW_DTR_DSR 0x0200 -#define FT_FLOW_XON_XOFF 0x0400 - -// -// Purge rx and tx buffers -// -#define FT_PURGE_RX 1 -#define FT_PURGE_TX 2 - -// -// Events -// - -typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD); - -#define FT_EVENT_RXCHAR 1 -#define FT_EVENT_MODEM_STATUS 2 - -// -// Timeouts -// - -#define FT_DEFAULT_RX_TIMEOUT 300 -#define FT_DEFAULT_TX_TIMEOUT 300 - -// -// Device types -// - -typedef ULONG FT_DEVICE; - -enum { - FT_DEVICE_BM, - FT_DEVICE_AM, - FT_DEVICE_100AX, - FT_DEVICE_UNKNOWN, - FT_DEVICE_2232C, - FT_DEVICE_232R - }; - - -#ifdef __cplusplus -extern "C" { -#endif - -FTD2XX_API -FT_STATUS WINAPI FT_Open( - int deviceNumber, - FT_HANDLE *pHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_OpenEx( - PVOID pArg1, - DWORD Flags, - FT_HANDLE *pHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ListDevices( - PVOID pArg1, - PVOID pArg2, - DWORD Flags - ); - -FTD2XX_API -FT_STATUS FT_SetVIDPID( - DWORD dwVID, - DWORD dwPID - ); - -FTD2XX_API -FT_STATUS FT_GetVIDPID( - DWORD * pdwVID, - DWORD * pdwPID - ); - -FTD2XX_API -FT_STATUS WINAPI FT_Close( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_Read( - FT_HANDLE ftHandle, - LPVOID lpBuffer, - DWORD nBufferSize, - LPDWORD lpBytesReturned - ); - -FTD2XX_API -FT_STATUS WINAPI FT_Write( - FT_HANDLE ftHandle, - LPVOID lpBuffer, - DWORD nBufferSize, - LPDWORD lpBytesWritten - ); - -FTD2XX_API -FT_STATUS WINAPI FT_IoCtl( // Linux, OS X: Not supported - FT_HANDLE ftHandle, - DWORD dwIoControlCode, - LPVOID lpInBuf, - DWORD nInBufSize, - LPVOID lpOutBuf, - DWORD nOutBufSize, - LPDWORD lpBytesReturned, - LPOVERLAPPED lpOverlapped - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetBaudRate( - FT_HANDLE ftHandle, - ULONG BaudRate - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetDivisor( - FT_HANDLE ftHandle, - USHORT Divisor - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetDataCharacteristics( - FT_HANDLE ftHandle, - UCHAR WordLength, - UCHAR StopBits, - UCHAR Parity - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetFlowControl( - FT_HANDLE ftHandle, - USHORT FlowControl, - UCHAR XonChar, - UCHAR XoffChar - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ResetDevice( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetDtr( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ClrDtr( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetRts( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ClrRts( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetModemStatus( - FT_HANDLE ftHandle, - ULONG *pModemStatus - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetChars( - FT_HANDLE ftHandle, - UCHAR EventChar, - UCHAR EventCharEnabled, - UCHAR ErrorChar, - UCHAR ErrorCharEnabled - ); - -FTD2XX_API -FT_STATUS WINAPI FT_Purge( - FT_HANDLE ftHandle, - ULONG Mask - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetTimeouts( - FT_HANDLE ftHandle, - ULONG ReadTimeout, - ULONG WriteTimeout - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetQueueStatus( - FT_HANDLE ftHandle, - DWORD *dwRxBytes - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetEventNotification( - FT_HANDLE ftHandle, - DWORD Mask, - PVOID Param - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetStatus( - FT_HANDLE ftHandle, - DWORD *dwRxBytes, - DWORD *dwTxBytes, - DWORD *dwEventDWord - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetBreakOn( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetBreakOff( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetWaitMask( // Linux, OS X: Not supported - FT_HANDLE ftHandle, - DWORD Mask - ); - -FTD2XX_API -FT_STATUS WINAPI FT_WaitOnMask( // Linux, OS X: Not supported - FT_HANDLE ftHandle, - DWORD *Mask - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetEventStatus( - FT_HANDLE ftHandle, - DWORD *dwEventDWord - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ReadEE( - FT_HANDLE ftHandle, - DWORD dwWordOffset, - LPWORD lpwValue - ); - -FTD2XX_API -FT_STATUS WINAPI FT_WriteEE( - FT_HANDLE ftHandle, - DWORD dwWordOffset, - WORD wValue - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EraseEE( - FT_HANDLE ftHandle - ); - -// -// structure to hold program data for FT_Program function -// -typedef struct ft_program_data { - - DWORD Signature1; // Header - must be 0x00000000 - DWORD Signature2; // Header - must be 0xffffffff - DWORD Version; // Header - FT_PROGRAM_DATA version - // 0 = original - // 1 = FT2232C extensions - // 2 = FT232R extensions - - WORD VendorId; // 0x0403 - WORD ProductId; // 0x6001 - char *Manufacturer; // "FTDI" - char *ManufacturerId; // "FT" - char *Description; // "USB HS Serial Converter" - char *SerialNumber; // "FT000001" if fixed, or NULL - WORD MaxPower; // 0 < MaxPower <= 500 - WORD PnP; // 0 = disabled, 1 = enabled - WORD SelfPowered; // 0 = bus powered, 1 = self powered - WORD RemoteWakeup; // 0 = not capable, 1 = capable - // - // Rev4 extensions - // - UCHAR Rev4; // non-zero if Rev4 chip, zero otherwise - UCHAR IsoIn; // non-zero if in endpoint is isochronous - UCHAR IsoOut; // non-zero if out endpoint is isochronous - UCHAR PullDownEnable; // non-zero if pull down enabled - UCHAR SerNumEnable; // non-zero if serial number to be used - UCHAR USBVersionEnable; // non-zero if chip uses USBVersion - WORD USBVersion; // BCD (0x0200 => USB2) - // - // FT2232C extensions - // - UCHAR Rev5; // non-zero if Rev5 chip, zero otherwise - UCHAR IsoInA; // non-zero if in endpoint is isochronous - UCHAR IsoInB; // non-zero if in endpoint is isochronous - UCHAR IsoOutA; // non-zero if out endpoint is isochronous - UCHAR IsoOutB; // non-zero if out endpoint is isochronous - UCHAR PullDownEnable5; // non-zero if pull down enabled - UCHAR SerNumEnable5; // non-zero if serial number to be used - UCHAR USBVersionEnable5; // non-zero if chip uses USBVersion - WORD USBVersion5; // BCD (0x0200 => USB2) - UCHAR AIsHighCurrent; // non-zero if interface is high current - UCHAR BIsHighCurrent; // non-zero if interface is high current - UCHAR IFAIsFifo; // non-zero if interface is 245 FIFO - UCHAR IFAIsFifoTar; // non-zero if interface is 245 FIFO CPU target - UCHAR IFAIsFastSer; // non-zero if interface is Fast serial - UCHAR AIsVCP; // non-zero if interface is to use VCP drivers - UCHAR IFBIsFifo; // non-zero if interface is 245 FIFO - UCHAR IFBIsFifoTar; // non-zero if interface is 245 FIFO CPU target - UCHAR IFBIsFastSer; // non-zero if interface is Fast serial - UCHAR BIsVCP; // non-zero if interface is to use VCP drivers - // - // FT232R extensions - // - UCHAR UseExtOsc; // Use External Oscillator - UCHAR HighDriveIOs; // High Drive I/Os - UCHAR EndpointSize; // Endpoint size - - UCHAR PullDownEnableR; // non-zero if pull down enabled - UCHAR SerNumEnableR; // non-zero if serial number to be used - - UCHAR InvertTXD; // non-zero if invert TXD - UCHAR InvertRXD; // non-zero if invert RXD - UCHAR InvertRTS; // non-zero if invert RTS - UCHAR InvertCTS; // non-zero if invert CTS - UCHAR InvertDTR; // non-zero if invert DTR - UCHAR InvertDSR; // non-zero if invert DSR - UCHAR InvertDCD; // non-zero if invert DCD - UCHAR InvertRI; // non-zero if invert RI - - UCHAR Cbus0; // Cbus Mux control - UCHAR Cbus1; // Cbus Mux control - UCHAR Cbus2; // Cbus Mux control - UCHAR Cbus3; // Cbus Mux control - UCHAR Cbus4; // Cbus Mux control - - UCHAR RIsVCP; // zero if using VCP drivers - -} FT_PROGRAM_DATA, *PFT_PROGRAM_DATA; - - -FTD2XX_API -FT_STATUS WINAPI FT_EE_Program( - FT_HANDLE ftHandle, - PFT_PROGRAM_DATA pData - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_ProgramEx( - FT_HANDLE ftHandle, - PFT_PROGRAM_DATA lpData, - char *Manufacturer, - char *ManufacturerId, - char *Description, - char *SerialNumber - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_Read( - FT_HANDLE ftHandle, - PFT_PROGRAM_DATA pData - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_ReadEx( - FT_HANDLE ftHandle, - PFT_PROGRAM_DATA lpData, - char *Manufacturer, - char *ManufacturerId, - char *Description, - char *SerialNumber - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_UASize( - FT_HANDLE ftHandle, - LPDWORD lpdwSize - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_UAWrite( - FT_HANDLE ftHandle, - PUCHAR pucData, - DWORD dwDataLen - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_UARead( - FT_HANDLE ftHandle, - PUCHAR pucData, - DWORD dwDataLen, - LPDWORD lpdwBytesRead - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetLatencyTimer( - FT_HANDLE ftHandle, - UCHAR ucLatency - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetLatencyTimer( - FT_HANDLE ftHandle, - PUCHAR pucLatency - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetBitMode( - FT_HANDLE ftHandle, - UCHAR ucMask, - UCHAR ucEnable - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetBitMode( - FT_HANDLE ftHandle, - PUCHAR pucMode - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetUSBParameters( - FT_HANDLE ftHandle, - ULONG ulInTransferSize, - ULONG ulOutTransferSize - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetDeadmanTimeout( - FT_HANDLE ftHandle, - ULONG ulDeadmanTimeout - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetDeviceInfo( - FT_HANDLE ftHandle, - FT_DEVICE *lpftDevice, - LPDWORD lpdwID, - PCHAR SerialNumber, - PCHAR Description, - LPVOID Dummy - ); - -FTD2XX_API -FT_STATUS WINAPI FT_StopInTask( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_RestartInTask( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetResetPipeRetryCount( // Linux, OS X: Not supported - FT_HANDLE ftHandle, - DWORD dwCount - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ResetPort( // Linux, OS X: Not supported - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_CyclePort( // Linux, OS X: Not supported - FT_HANDLE ftHandle - ); - - -// -// Win32-type functions -// - -FTD2XX_API -FT_HANDLE WINAPI FT_W32_CreateFile( - LPCSTR lpszName, - DWORD dwAccess, - DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreate, - DWORD dwAttrsAndFlags, - HANDLE hTemplate - ); - -FTD2XX_API -BOOL WINAPI FT_W32_CloseHandle( - FT_HANDLE ftHandle - ); - -FTD2XX_API -BOOL WINAPI FT_W32_ReadFile( - FT_HANDLE ftHandle, - LPVOID lpBuffer, - DWORD nBufferSize, - LPDWORD lpBytesReturned, - LPOVERLAPPED lpOverlapped - ); - -FTD2XX_API -BOOL WINAPI FT_W32_WriteFile( - FT_HANDLE ftHandle, - LPVOID lpBuffer, - DWORD nBufferSize, - LPDWORD lpBytesWritten, - LPOVERLAPPED lpOverlapped - ); - -FTD2XX_API -DWORD WINAPI FT_W32_GetLastError( - FT_HANDLE ftHandle - ); - -FTD2XX_API -BOOL WINAPI FT_W32_GetOverlappedResult( // Linux, OS X: Not supported - FT_HANDLE ftHandle, - LPOVERLAPPED lpOverlapped, - LPDWORD lpdwBytesTransferred, - BOOL bWait - ); - -FTD2XX_API -BOOL WINAPI FT_W32_CancelIo( // Linux, OS X: Not supported - FT_HANDLE ftHandle - ); - - -// -// Win32 COMM API type functions -// -typedef struct _FTCOMSTAT { - DWORD fCtsHold : 1; - DWORD fDsrHold : 1; - DWORD fRlsdHold : 1; - DWORD fXoffHold : 1; - DWORD fXoffSent : 1; - DWORD fEof : 1; - DWORD fTxim : 1; - DWORD fReserved : 25; - DWORD cbInQue; - DWORD cbOutQue; -} FTCOMSTAT, *LPFTCOMSTAT; - -typedef struct _FTDCB { - DWORD DCBlength; /* sizeof(FTDCB) */ - DWORD BaudRate; /* Baudrate at which running */ - DWORD fBinary: 1; /* Binary Mode (skip EOF check) */ - DWORD fParity: 1; /* Enable parity checking */ - DWORD fOutxCtsFlow:1; /* CTS handshaking on output */ - DWORD fOutxDsrFlow:1; /* DSR handshaking on output */ - DWORD fDtrControl:2; /* DTR Flow control */ - DWORD fDsrSensitivity:1; /* DSR Sensitivity */ - DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */ - DWORD fOutX: 1; /* Enable output X-ON/X-OFF */ - DWORD fInX: 1; /* Enable input X-ON/X-OFF */ - DWORD fErrorChar: 1; /* Enable Err Replacement */ - DWORD fNull: 1; /* Enable Null stripping */ - DWORD fRtsControl:2; /* Rts Flow control */ - DWORD fAbortOnError:1; /* Abort all reads and writes on Error */ - DWORD fDummy2:17; /* Reserved */ - WORD wReserved; /* Not currently used */ - WORD XonLim; /* Transmit X-ON threshold */ - WORD XoffLim; /* Transmit X-OFF threshold */ - BYTE ByteSize; /* Number of bits/byte, 4-8 */ - BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */ - BYTE StopBits; /* 0,1,2 = 1, 1.5, 2 */ - char XonChar; /* Tx and Rx X-ON character */ - char XoffChar; /* Tx and Rx X-OFF character */ - char ErrorChar; /* Error replacement char */ - char EofChar; /* End of Input character */ - char EvtChar; /* Received Event character */ - WORD wReserved1; /* Fill for now. */ -} FTDCB, *LPFTDCB; - -typedef struct _FTTIMEOUTS { - DWORD ReadIntervalTimeout; /* Maximum time between read chars. */ - DWORD ReadTotalTimeoutMultiplier; /* Multiplier of characters. */ - DWORD ReadTotalTimeoutConstant; /* Constant in milliseconds. */ - DWORD WriteTotalTimeoutMultiplier; /* Multiplier of characters. */ - DWORD WriteTotalTimeoutConstant; /* Constant in milliseconds. */ -} FTTIMEOUTS,*LPFTTIMEOUTS; - - -FTD2XX_API -BOOL WINAPI FT_W32_ClearCommBreak( - FT_HANDLE ftHandle - ); - -FTD2XX_API -BOOL WINAPI FT_W32_ClearCommError( - FT_HANDLE ftHandle, - LPDWORD lpdwErrors, - LPFTCOMSTAT lpftComstat - ); - -FTD2XX_API -BOOL WINAPI FT_W32_EscapeCommFunction( - FT_HANDLE ftHandle, - DWORD dwFunc - ); - -FTD2XX_API -BOOL WINAPI FT_W32_GetCommModemStatus( - FT_HANDLE ftHandle, - LPDWORD lpdwModemStatus - ); - -FTD2XX_API -BOOL WINAPI FT_W32_GetCommState( - FT_HANDLE ftHandle, - LPFTDCB lpftDcb - ); - -FTD2XX_API -BOOL WINAPI FT_W32_GetCommTimeouts( - FT_HANDLE ftHandle, - FTTIMEOUTS *pTimeouts - ); - -FTD2XX_API -BOOL WINAPI FT_W32_PurgeComm( - FT_HANDLE ftHandle, - DWORD dwMask - ); - -FTD2XX_API -BOOL WINAPI FT_W32_SetCommBreak( - FT_HANDLE ftHandle - ); - -FTD2XX_API -BOOL WINAPI FT_W32_SetCommMask( - FT_HANDLE ftHandle, - ULONG ulEventMask - ); - -FTD2XX_API -BOOL WINAPI FT_W32_SetCommState( - FT_HANDLE ftHandle, - LPFTDCB lpftDcb - ); - -FTD2XX_API -BOOL WINAPI FT_W32_SetCommTimeouts( - FT_HANDLE ftHandle, - FTTIMEOUTS *pTimeouts - ); - -FTD2XX_API -BOOL WINAPI FT_W32_SetupComm( - FT_HANDLE ftHandle, - DWORD dwReadBufferSize, - DWORD dwWriteBufferSize - ); - -FTD2XX_API -BOOL WINAPI FT_W32_WaitCommEvent( - FT_HANDLE ftHandle, - PULONG pulEvent, - LPOVERLAPPED lpOverlapped - ); - -// -// Device information -// - -typedef struct _ft_device_list_info_node { - ULONG Flags; - ULONG Type; - ULONG ID; - DWORD LocId; - char SerialNumber[16]; - char Description[64]; - FT_HANDLE ftHandle; -} FT_DEVICE_LIST_INFO_NODE; - -FTD2XX_API -FT_STATUS WINAPI FT_CreateDeviceInfoList( - LPDWORD lpdwNumDevs - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetDeviceInfoList( - FT_DEVICE_LIST_INFO_NODE *pDest, - LPDWORD lpdwNumDevs - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetDeviceInfoDetail( - DWORD dwIndex, - LPDWORD lpdwFlags, - LPDWORD lpdwType, - LPDWORD lpdwID, - LPDWORD lpdwLocId, - LPVOID lpSerialNumber, - LPVOID lpDescription, - FT_HANDLE *pftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetDriverVersion( - FT_HANDLE ftHandle, - LPDWORD lpdwVersion - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetLibraryVersion( - LPDWORD lpdwVersion - ); - -// -// Events -// - -#define EV_RXCHAR 0x0001 // Any Character received -#define EV_RXFLAG 0x0002 // Received certain character -#define EV_TXEMPTY 0x0004 // Transmitt Queue Empty -#define EV_CTS 0x0008 // CTS changed state -#define EV_DSR 0x0010 // DSR changed state -#define EV_RLSD 0x0020 // RLSD changed state -#define EV_BREAK 0x0040 // BREAK received -#define EV_ERR 0x0080 // Line status error occurred -#define EV_RING 0x0100 // Ring signal detected -#define EV_PERR 0x0200 // Printer error occured -#define EV_RX80FULL 0x0400 // Receive buffer is 80 percent full -#define EV_EVENT1 0x0800 // Provider specific event 1 -#define EV_EVENT2 0x1000 // Provider specific event 2 - -// -// Escape Functions -// - -#define SETXOFF 1 // Simulate XOFF received -#define SETXON 2 // Simulate XON received -#define SETRTS 3 // Set RTS high -#define CLRRTS 4 // Set RTS low -#define SETDTR 5 // Set DTR high -#define CLRDTR 6 // Set DTR low -#define RESETDEV 7 // Reset device if possible -#define SETBREAK 8 // Set the device break line. -#define CLRBREAK 9 // Clear the device break line. - -// -// PURGE function flags. -// -#define PURGE_TXABORT 0x0001 // Kill the pending/current writes to the comm port. -#define PURGE_RXABORT 0x0002 // Kill the pending/current reads to the comm port. -#define PURGE_TXCLEAR 0x0004 // Kill the transmit queue if there. -#define PURGE_RXCLEAR 0x0008 // Kill the typeahead buffer if there. - - - - - - - - - - - - - - -#ifdef __cplusplus -} -#endif - - -#endif /* FTD2XX_H */ - - - - - - diff --git a/tools/sensinode/nano_usb_programmer/ftdi_win32/ftd2xx.h b/tools/sensinode/nano_usb_programmer/ftdi_win32/ftd2xx.h deleted file mode 100644 index 3ee1da36d..000000000 --- a/tools/sensinode/nano_usb_programmer/ftdi_win32/ftd2xx.h +++ /dev/null @@ -1,922 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -/*++ - -Copyright (c) 2001-2006 Future Technology Devices International Ltd. - -Module Name: - - ftd2xx.h - -Abstract: - - Native USB device driver for FTDI FT8U232/245 - FTD2XX library definitions - -Environment: - - kernel & user mode - -Revision History: - - 13/03/01 awm Created. - 13/01/03 awm Added device information support. - 19/03/03 awm Added FT_W32_CancelIo. - 12/06/03 awm Added FT_StopInTask and FT_RestartInTask. - 18/09/03 awm Added FT_SetResetPipeRetryCount. - 10/10/03 awm Added FT_ResetPort. - 23/01/04 awm Added support for open-by-location. - 16/03/04 awm Added support for FT2232C. - 23/09/04 awm Added support for FT232R. - 20/10/04 awm Added FT_CyclePort. - 18/01/05 awm Added FT_DEVICE_LIST_INFO_NODE type. - 11/02/05 awm Added LocId to FT_DEVICE_LIST_INFO_NODE. - 25/08/05 awm Added FT_SetDeadmanTimeout. - 02/12/05 awm Removed obsolete references. - 05/12/05 awm Added FT_GetVersion, FT_GetVersionEx. - 08/09/06 awm Added FT_W32_GetCommMask. - 11/09/06 awm Added FT_Rescan. - - ---*/ - - -#ifndef FTD2XX_H -#define FTD2XX_H - -// The following ifdef block is the standard way of creating macros -// which make exporting from a DLL simpler. All files within this DLL -// are compiled with the FTD2XX_EXPORTS symbol defined on the command line. -// This symbol should not be defined on any project that uses this DLL. -// This way any other project whose source files include this file see -// FTD2XX_API functions as being imported from a DLL, whereas this DLL -// sees symbols defined with this macro as being exported. - -#ifdef FTD2XX_EXPORTS -#define FTD2XX_API __declspec(dllexport) -#else -#define FTD2XX_API __declspec(dllimport) -#endif - - -typedef PVOID FT_HANDLE; -typedef ULONG FT_STATUS; - -// -// Device status -// -enum { - FT_OK, - FT_INVALID_HANDLE, - FT_DEVICE_NOT_FOUND, - FT_DEVICE_NOT_OPENED, - FT_IO_ERROR, - FT_INSUFFICIENT_RESOURCES, - FT_INVALID_PARAMETER, - FT_INVALID_BAUD_RATE, - - FT_DEVICE_NOT_OPENED_FOR_ERASE, - FT_DEVICE_NOT_OPENED_FOR_WRITE, - FT_FAILED_TO_WRITE_DEVICE, - FT_EEPROM_READ_FAILED, - FT_EEPROM_WRITE_FAILED, - FT_EEPROM_ERASE_FAILED, - FT_EEPROM_NOT_PRESENT, - FT_EEPROM_NOT_PROGRAMMED, - FT_INVALID_ARGS, - FT_NOT_SUPPORTED, - FT_OTHER_ERROR, - FT_DEVICE_LIST_NOT_READY, -}; - - -#define FT_SUCCESS(status) ((status) == FT_OK) - -// -// FT_OpenEx Flags -// - -#define FT_OPEN_BY_SERIAL_NUMBER 1 -#define FT_OPEN_BY_DESCRIPTION 2 -#define FT_OPEN_BY_LOCATION 4 - -// -// FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags -// - -#define FT_LIST_NUMBER_ONLY 0x80000000 -#define FT_LIST_BY_INDEX 0x40000000 -#define FT_LIST_ALL 0x20000000 - -#define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL) - -// -// Baud Rates -// - -#define FT_BAUD_300 300 -#define FT_BAUD_600 600 -#define FT_BAUD_1200 1200 -#define FT_BAUD_2400 2400 -#define FT_BAUD_4800 4800 -#define FT_BAUD_9600 9600 -#define FT_BAUD_14400 14400 -#define FT_BAUD_19200 19200 -#define FT_BAUD_38400 38400 -#define FT_BAUD_57600 57600 -#define FT_BAUD_115200 115200 -#define FT_BAUD_230400 230400 -#define FT_BAUD_460800 460800 -#define FT_BAUD_921600 921600 - -// -// Word Lengths -// - -#define FT_BITS_8 (UCHAR) 8 -#define FT_BITS_7 (UCHAR) 7 -#define FT_BITS_6 (UCHAR) 6 -#define FT_BITS_5 (UCHAR) 5 - -// -// Stop Bits -// - -#define FT_STOP_BITS_1 (UCHAR) 0 -#define FT_STOP_BITS_1_5 (UCHAR) 1 -#define FT_STOP_BITS_2 (UCHAR) 2 - -// -// Parity -// - -#define FT_PARITY_NONE (UCHAR) 0 -#define FT_PARITY_ODD (UCHAR) 1 -#define FT_PARITY_EVEN (UCHAR) 2 -#define FT_PARITY_MARK (UCHAR) 3 -#define FT_PARITY_SPACE (UCHAR) 4 - -// -// Flow Control -// - -#define FT_FLOW_NONE 0x0000 -#define FT_FLOW_RTS_CTS 0x0100 -#define FT_FLOW_DTR_DSR 0x0200 -#define FT_FLOW_XON_XOFF 0x0400 - -// -// Purge rx and tx buffers -// -#define FT_PURGE_RX 1 -#define FT_PURGE_TX 2 - -// -// Events -// - -typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD); - -#define FT_EVENT_RXCHAR 1 -#define FT_EVENT_MODEM_STATUS 2 - -// -// Timeouts -// - -#define FT_DEFAULT_RX_TIMEOUT 300 -#define FT_DEFAULT_TX_TIMEOUT 300 - -// -// Device types -// - -typedef ULONG FT_DEVICE; - -enum { - FT_DEVICE_BM, - FT_DEVICE_AM, - FT_DEVICE_100AX, - FT_DEVICE_UNKNOWN, - FT_DEVICE_2232C, - FT_DEVICE_232R -}; - - -#ifdef __cplusplus -extern "C" { -#endif - - -FTD2XX_API -FT_STATUS WINAPI FT_Open( - int deviceNumber, - FT_HANDLE *pHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_OpenEx( - PVOID pArg1, - DWORD Flags, - FT_HANDLE *pHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ListDevices( - PVOID pArg1, - PVOID pArg2, - DWORD Flags - ); - -FTD2XX_API -FT_STATUS WINAPI FT_Close( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_Read( - FT_HANDLE ftHandle, - LPVOID lpBuffer, - DWORD nBufferSize, - LPDWORD lpBytesReturned - ); - -FTD2XX_API -FT_STATUS WINAPI FT_Write( - FT_HANDLE ftHandle, - LPVOID lpBuffer, - DWORD nBufferSize, - LPDWORD lpBytesWritten - ); - -FTD2XX_API -FT_STATUS WINAPI FT_IoCtl( - FT_HANDLE ftHandle, - DWORD dwIoControlCode, - LPVOID lpInBuf, - DWORD nInBufSize, - LPVOID lpOutBuf, - DWORD nOutBufSize, - LPDWORD lpBytesReturned, - LPOVERLAPPED lpOverlapped - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetBaudRate( - FT_HANDLE ftHandle, - ULONG BaudRate - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetDivisor( - FT_HANDLE ftHandle, - USHORT Divisor - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetDataCharacteristics( - FT_HANDLE ftHandle, - UCHAR WordLength, - UCHAR StopBits, - UCHAR Parity - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetFlowControl( - FT_HANDLE ftHandle, - USHORT FlowControl, - UCHAR XonChar, - UCHAR XoffChar - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ResetDevice( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetDtr( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ClrDtr( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetRts( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ClrRts( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetModemStatus( - FT_HANDLE ftHandle, - ULONG *pModemStatus - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetChars( - FT_HANDLE ftHandle, - UCHAR EventChar, - UCHAR EventCharEnabled, - UCHAR ErrorChar, - UCHAR ErrorCharEnabled - ); - -FTD2XX_API -FT_STATUS WINAPI FT_Purge( - FT_HANDLE ftHandle, - ULONG Mask - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetTimeouts( - FT_HANDLE ftHandle, - ULONG ReadTimeout, - ULONG WriteTimeout - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetQueueStatus( - FT_HANDLE ftHandle, - DWORD *dwRxBytes - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetEventNotification( - FT_HANDLE ftHandle, - DWORD Mask, - PVOID Param - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetStatus( - FT_HANDLE ftHandle, - DWORD *dwRxBytes, - DWORD *dwTxBytes, - DWORD *dwEventDWord - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetBreakOn( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetBreakOff( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetWaitMask( - FT_HANDLE ftHandle, - DWORD Mask - ); - -FTD2XX_API -FT_STATUS WINAPI FT_WaitOnMask( - FT_HANDLE ftHandle, - DWORD *Mask - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetEventStatus( - FT_HANDLE ftHandle, - DWORD *dwEventDWord - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ReadEE( - FT_HANDLE ftHandle, - DWORD dwWordOffset, - LPWORD lpwValue - ); - -FTD2XX_API -FT_STATUS WINAPI FT_WriteEE( - FT_HANDLE ftHandle, - DWORD dwWordOffset, - WORD wValue - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EraseEE( - FT_HANDLE ftHandle - ); - -// -// structure to hold program data for FT_Program function -// -typedef struct ft_program_data { - - DWORD Signature1; // Header - must be 0x00000000 - DWORD Signature2; // Header - must be 0xffffffff - DWORD Version; // Header - FT_PROGRAM_DATA version - // 0 = original - // 1 = FT2232C extensions - // 2 = FT232R extensions - - WORD VendorId; // 0x0403 - WORD ProductId; // 0x6001 - char *Manufacturer; // "FTDI" - char *ManufacturerId; // "FT" - char *Description; // "USB HS Serial Converter" - char *SerialNumber; // "FT000001" if fixed, or NULL - WORD MaxPower; // 0 < MaxPower <= 500 - WORD PnP; // 0 = disabled, 1 = enabled - WORD SelfPowered; // 0 = bus powered, 1 = self powered - WORD RemoteWakeup; // 0 = not capable, 1 = capable - // - // Rev4 extensions - // - UCHAR Rev4; // non-zero if Rev4 chip, zero otherwise - UCHAR IsoIn; // non-zero if in endpoint is isochronous - UCHAR IsoOut; // non-zero if out endpoint is isochronous - UCHAR PullDownEnable; // non-zero if pull down enabled - UCHAR SerNumEnable; // non-zero if serial number to be used - UCHAR USBVersionEnable; // non-zero if chip uses USBVersion - WORD USBVersion; // BCD (0x0200 => USB2) - // - // FT2232C extensions - // - UCHAR Rev5; // non-zero if Rev5 chip, zero otherwise - UCHAR IsoInA; // non-zero if in endpoint is isochronous - UCHAR IsoInB; // non-zero if in endpoint is isochronous - UCHAR IsoOutA; // non-zero if out endpoint is isochronous - UCHAR IsoOutB; // non-zero if out endpoint is isochronous - UCHAR PullDownEnable5; // non-zero if pull down enabled - UCHAR SerNumEnable5; // non-zero if serial number to be used - UCHAR USBVersionEnable5; // non-zero if chip uses USBVersion - WORD USBVersion5; // BCD (0x0200 => USB2) - UCHAR AIsHighCurrent; // non-zero if interface is high current - UCHAR BIsHighCurrent; // non-zero if interface is high current - UCHAR IFAIsFifo; // non-zero if interface is 245 FIFO - UCHAR IFAIsFifoTar; // non-zero if interface is 245 FIFO CPU target - UCHAR IFAIsFastSer; // non-zero if interface is Fast serial - UCHAR AIsVCP; // non-zero if interface is to use VCP drivers - UCHAR IFBIsFifo; // non-zero if interface is 245 FIFO - UCHAR IFBIsFifoTar; // non-zero if interface is 245 FIFO CPU target - UCHAR IFBIsFastSer; // non-zero if interface is Fast serial - UCHAR BIsVCP; // non-zero if interface is to use VCP drivers - // - // FT232R extensions - // - UCHAR UseExtOsc; // Use External Oscillator - UCHAR HighDriveIOs; // High Drive I/Os - UCHAR EndpointSize; // Endpoint size - - UCHAR PullDownEnableR; // non-zero if pull down enabled - UCHAR SerNumEnableR; // non-zero if serial number to be used - - UCHAR InvertTXD; // non-zero if invert TXD - UCHAR InvertRXD; // non-zero if invert RXD - UCHAR InvertRTS; // non-zero if invert RTS - UCHAR InvertCTS; // non-zero if invert CTS - UCHAR InvertDTR; // non-zero if invert DTR - UCHAR InvertDSR; // non-zero if invert DSR - UCHAR InvertDCD; // non-zero if invert DCD - UCHAR InvertRI; // non-zero if invert RI - - UCHAR Cbus0; // Cbus Mux control - UCHAR Cbus1; // Cbus Mux control - UCHAR Cbus2; // Cbus Mux control - UCHAR Cbus3; // Cbus Mux control - UCHAR Cbus4; // Cbus Mux control - - UCHAR RIsD2XX; // non-zero if using D2XX driver - -} FT_PROGRAM_DATA, *PFT_PROGRAM_DATA; - -FTD2XX_API -FT_STATUS WINAPI FT_EE_Program( - FT_HANDLE ftHandle, - PFT_PROGRAM_DATA pData - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_ProgramEx( - FT_HANDLE ftHandle, - PFT_PROGRAM_DATA pData, - char *Manufacturer, - char *ManufacturerId, - char *Description, - char *SerialNumber - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_Read( - FT_HANDLE ftHandle, - PFT_PROGRAM_DATA pData - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_ReadEx( - FT_HANDLE ftHandle, - PFT_PROGRAM_DATA pData, - char *Manufacturer, - char *ManufacturerId, - char *Description, - char *SerialNumber - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_UASize( - FT_HANDLE ftHandle, - LPDWORD lpdwSize - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_UAWrite( - FT_HANDLE ftHandle, - PUCHAR pucData, - DWORD dwDataLen - ); - -FTD2XX_API -FT_STATUS WINAPI FT_EE_UARead( - FT_HANDLE ftHandle, - PUCHAR pucData, - DWORD dwDataLen, - LPDWORD lpdwBytesRead - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetLatencyTimer( - FT_HANDLE ftHandle, - UCHAR ucLatency - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetLatencyTimer( - FT_HANDLE ftHandle, - PUCHAR pucLatency - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetBitMode( - FT_HANDLE ftHandle, - UCHAR ucMask, - UCHAR ucEnable - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetBitMode( - FT_HANDLE ftHandle, - PUCHAR pucMode - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetUSBParameters( - FT_HANDLE ftHandle, - ULONG ulInTransferSize, - ULONG ulOutTransferSize - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetDeadmanTimeout( - FT_HANDLE ftHandle, - ULONG ulDeadmanTimeout - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetDeviceInfo( - FT_HANDLE ftHandle, - FT_DEVICE *lpftDevice, - LPDWORD lpdwID, - PCHAR SerialNumber, - PCHAR Description, - LPVOID Dummy - ); - -FTD2XX_API -FT_STATUS WINAPI FT_StopInTask( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_RestartInTask( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_SetResetPipeRetryCount( - FT_HANDLE ftHandle, - DWORD dwCount - ); - -FTD2XX_API -FT_STATUS WINAPI FT_ResetPort( - FT_HANDLE ftHandle - ); - -FTD2XX_API -FT_STATUS WINAPI FT_CyclePort( - FT_HANDLE ftHandle - ); - - -// -// Win32-type functions -// - -FTD2XX_API -FT_HANDLE WINAPI FT_W32_CreateFile( - LPCTSTR lpszName, - DWORD dwAccess, - DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, - DWORD dwCreate, - DWORD dwAttrsAndFlags, - HANDLE hTemplate - ); - -FTD2XX_API -BOOL WINAPI FT_W32_CloseHandle( - FT_HANDLE ftHandle - ); - -FTD2XX_API -BOOL WINAPI FT_W32_ReadFile( - FT_HANDLE ftHandle, - LPVOID lpBuffer, - DWORD nBufferSize, - LPDWORD lpBytesReturned, - LPOVERLAPPED lpOverlapped - ); - -FTD2XX_API -BOOL WINAPI FT_W32_WriteFile( - FT_HANDLE ftHandle, - LPVOID lpBuffer, - DWORD nBufferSize, - LPDWORD lpBytesWritten, - LPOVERLAPPED lpOverlapped - ); - -FTD2XX_API -DWORD WINAPI FT_W32_GetLastError( - FT_HANDLE ftHandle - ); - -FTD2XX_API -BOOL WINAPI FT_W32_GetOverlappedResult( - FT_HANDLE ftHandle, - LPOVERLAPPED lpOverlapped, - LPDWORD lpdwBytesTransferred, - BOOL bWait - ); - -FTD2XX_API -BOOL WINAPI FT_W32_CancelIo( - FT_HANDLE ftHandle - ); - - -// -// Win32 COMM API type functions -// -typedef struct _FTCOMSTAT { - DWORD fCtsHold : 1; - DWORD fDsrHold : 1; - DWORD fRlsdHold : 1; - DWORD fXoffHold : 1; - DWORD fXoffSent : 1; - DWORD fEof : 1; - DWORD fTxim : 1; - DWORD fReserved : 25; - DWORD cbInQue; - DWORD cbOutQue; -} FTCOMSTAT, *LPFTCOMSTAT; - -typedef struct _FTDCB { - DWORD DCBlength; /* sizeof(FTDCB) */ - DWORD BaudRate; /* Baudrate at which running */ - DWORD fBinary: 1; /* Binary Mode (skip EOF check) */ - DWORD fParity: 1; /* Enable parity checking */ - DWORD fOutxCtsFlow:1; /* CTS handshaking on output */ - DWORD fOutxDsrFlow:1; /* DSR handshaking on output */ - DWORD fDtrControl:2; /* DTR Flow control */ - DWORD fDsrSensitivity:1; /* DSR Sensitivity */ - DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */ - DWORD fOutX: 1; /* Enable output X-ON/X-OFF */ - DWORD fInX: 1; /* Enable input X-ON/X-OFF */ - DWORD fErrorChar: 1; /* Enable Err Replacement */ - DWORD fNull: 1; /* Enable Null stripping */ - DWORD fRtsControl:2; /* Rts Flow control */ - DWORD fAbortOnError:1; /* Abort all reads and writes on Error */ - DWORD fDummy2:17; /* Reserved */ - WORD wReserved; /* Not currently used */ - WORD XonLim; /* Transmit X-ON threshold */ - WORD XoffLim; /* Transmit X-OFF threshold */ - BYTE ByteSize; /* Number of bits/byte, 4-8 */ - BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */ - BYTE StopBits; /* 0,1,2 = 1, 1.5, 2 */ - char XonChar; /* Tx and Rx X-ON character */ - char XoffChar; /* Tx and Rx X-OFF character */ - char ErrorChar; /* Error replacement char */ - char EofChar; /* End of Input character */ - char EvtChar; /* Received Event character */ - WORD wReserved1; /* Fill for now. */ -} FTDCB, *LPFTDCB; - -typedef struct _FTTIMEOUTS { - DWORD ReadIntervalTimeout; /* Maximum time between read chars. */ - DWORD ReadTotalTimeoutMultiplier; /* Multiplier of characters. */ - DWORD ReadTotalTimeoutConstant; /* Constant in milliseconds. */ - DWORD WriteTotalTimeoutMultiplier; /* Multiplier of characters. */ - DWORD WriteTotalTimeoutConstant; /* Constant in milliseconds. */ -} FTTIMEOUTS,*LPFTTIMEOUTS; - - -FTD2XX_API -BOOL WINAPI FT_W32_ClearCommBreak( - FT_HANDLE ftHandle - ); - -FTD2XX_API -BOOL WINAPI FT_W32_ClearCommError( - FT_HANDLE ftHandle, - LPDWORD lpdwErrors, - LPFTCOMSTAT lpftComstat - ); - -FTD2XX_API -BOOL WINAPI FT_W32_EscapeCommFunction( - FT_HANDLE ftHandle, - DWORD dwFunc - ); - -FTD2XX_API -BOOL WINAPI FT_W32_GetCommModemStatus( - FT_HANDLE ftHandle, - LPDWORD lpdwModemStatus - ); - -FTD2XX_API -BOOL WINAPI FT_W32_GetCommState( - FT_HANDLE ftHandle, - LPFTDCB lpftDcb - ); - -FTD2XX_API -BOOL WINAPI FT_W32_GetCommTimeouts( - FT_HANDLE ftHandle, - FTTIMEOUTS *pTimeouts - ); - -FTD2XX_API -BOOL WINAPI FT_W32_PurgeComm( - FT_HANDLE ftHandle, - DWORD dwMask - ); - -FTD2XX_API -BOOL WINAPI FT_W32_SetCommBreak( - FT_HANDLE ftHandle - ); - -FTD2XX_API -BOOL WINAPI FT_W32_SetCommMask( - FT_HANDLE ftHandle, - ULONG ulEventMask - ); - -FTD2XX_API -BOOL WINAPI FT_W32_GetCommMask( - FT_HANDLE ftHandle, - LPDWORD lpdwEventMask - ); - -FTD2XX_API -BOOL WINAPI FT_W32_SetCommState( - FT_HANDLE ftHandle, - LPFTDCB lpftDcb - ); - -FTD2XX_API -BOOL WINAPI FT_W32_SetCommTimeouts( - FT_HANDLE ftHandle, - FTTIMEOUTS *pTimeouts - ); - -FTD2XX_API -BOOL WINAPI FT_W32_SetupComm( - FT_HANDLE ftHandle, - DWORD dwReadBufferSize, - DWORD dwWriteBufferSize - ); - -FTD2XX_API -BOOL WINAPI FT_W32_WaitCommEvent( - FT_HANDLE ftHandle, - PULONG pulEvent, - LPOVERLAPPED lpOverlapped - ); - - -// -// Device information -// - -typedef struct _ft_device_list_info_node { - ULONG Flags; - ULONG Type; - ULONG ID; - DWORD LocId; - char SerialNumber[16]; - char Description[64]; - FT_HANDLE ftHandle; -} FT_DEVICE_LIST_INFO_NODE; - - -FTD2XX_API -FT_STATUS WINAPI FT_CreateDeviceInfoList( - LPDWORD lpdwNumDevs - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetDeviceInfoList( - FT_DEVICE_LIST_INFO_NODE *pDest, - LPDWORD lpdwNumDevs - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetDeviceInfoDetail( - DWORD dwIndex, - LPDWORD lpdwFlags, - LPDWORD lpdwType, - LPDWORD lpdwID, - LPDWORD lpdwLocId, - LPVOID lpSerialNumber, - LPVOID lpDescription, - FT_HANDLE *pftHandle - ); - - -// -// Version information -// - -FTD2XX_API -FT_STATUS WINAPI FT_GetDriverVersion( - FT_HANDLE ftHandle, - LPDWORD lpdwVersion - ); - -FTD2XX_API -FT_STATUS WINAPI FT_GetLibraryVersion( - LPDWORD lpdwVersion - ); - - -FTD2XX_API -FT_STATUS WINAPI FT_Rescan( - void - ); - -FTD2XX_API -FT_STATUS WINAPI FT_Reload( - WORD wVid, - WORD wPid - ); - - -#ifdef __cplusplus -} -#endif - - -#endif /* FTD2XX_H */ diff --git a/tools/sensinode/nano_usb_programmer/ihex.c b/tools/sensinode/nano_usb_programmer/ihex.c deleted file mode 100644 index a7889e57b..000000000 --- a/tools/sensinode/nano_usb_programmer/ihex.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#include -#include -#include -#include - -#include - -int hexfile_build_tables(char *ihexfile, unsigned char *page_buffer, unsigned char *page_table) -{ - unsigned char buffer[256]; - int length; - int i; - int pages; - - unsigned long ext_addr=0; - unsigned short int addr=0; - FILE *ihex_fp; - - if((ihex_fp = (FILE *)fopen(ihexfile, "r")) == NULL) - { - printf("Failed to open .ihex file %s\n", ihexfile); - return(-1); - } - else - { - printf(".ihex file ok.\n"); - } - - bzero(buffer, sizeof(buffer)); - - /*initialize page data*/ - memset(page_table, 0, 64); - memset(page_buffer, 0xFF, sizeof(page_buffer)); - pages = 0; - - while((fscanf(ihex_fp, "%s", buffer) == 1)) - { - unsigned char data_len = 0; - - if (memcmp(&buffer[7], "00", 2) == 0) - { /*Data record*/ - i=0; - sscanf((char *)&buffer[1], "%2hhx", &data_len); - sscanf((char *)&(buffer[3]),"%4hx", &addr); - while(i> 8; - cksum += *addr & 0xFF; - cksum += *type; - - i = 0; - if (retval == 3) - { - while(i < row_len) - { - - if (sscanf(&line[row_index], "%2x", &tmp) == 1) - { - cksum += tmp; - buffer[i++] = (unsigned char) tmp; - row_index += 2; - } - else return -1; - } - if (sscanf(&line[row_index], "%2x", &tmp) == 1) - { - if ((cksum + (uint8_t) tmp) == 0) return row_len; - } - } - return -1; -} - -int hexfile_out(char *line, unsigned int type, unsigned int address, unsigned char *data, unsigned int bytes) -{ - uint8_t cksum = 0; - uint8_t i = 0; - char tmp[8]; - - sprintf(line, ":%2.2X%4.4X%2.2X", bytes, address, type); - cksum -= bytes; - cksum -= address >> 8; - cksum -= address & 0xFF; - cksum -= type; - - for (i=0; i -#include -#include -#include -#include - -#include -#ifdef PLATFORM_WINDOWS -#include -#endif -#include "prog.h" - -#define PRG_VERSION "1.3" - -typedef enum -{ - USAGE, - VERSION, - SCAN, - WRITE, - READ, - WRITE_MAC, - READ_MAC, - ERASE -}mode_t; - -typedef struct opts_t -{ - int port; - mode_t mode; - uint8_t write_mac[8]; - char *filename; -}opts_t; - -opts_t opts; - -void usage(char *prg_name) -{ - printf("\nUsage: %s [-p port] [-h] [-v] [-f file] [-r] [-w] [-m] [-M ]\n", prg_name); - printf("General options:\n"); - printf(" -p/--port [port] Select FTDI device\n"); - printf(" -f/--file [filename] File to read/write\n"); - printf("Operating modes:\n"); - printf(" -d/--devices Scan available devices\n"); - printf(" -v/--version Print program version\n"); - printf(" -r/--read Read program code into ihex file (see -f)\n"); - printf(" -w/--write Program firmware from ihex file (see -f)\n"); - printf(" -m/--read-mac Read device MAC address\n"); - printf(" -M/--write-mac xx:xx:xx:xx:xx:xx:xx:xx Write device MAC address\n"); - printf(" -e/--erase Erase flash (erases MAC address!)\n"); - printf("Defaults:\n"); - printf("mode = usage\n"); - printf("port = undefined\n"); - printf("file = stdout\n"); -} - -int main(int argc, char *argv[]) -{ - DWORD dwBytesInQueue = 0; - FT_STATUS ftStatus; - FT_HANDLE ftHandle; - unsigned char ucMode = 0x00; - int i=0; - unsigned char wr[1] = { 0x30 }; - unsigned char rd[1]; - uint16_t chip_id; - - if (opts_parse(argc, argv) < 0) - { - usage(argv[0]); - return -1; - } - switch(opts.mode) - { - case VERSION: - printf("Sensinode Nano USB Programmer version %s\n", PRG_VERSION); - return 0; - - case USAGE: - usage(argv[0]); - return 0; - - case SCAN: - prog_scan(); - return 0; - - case ERASE: - case READ: - case WRITE: - case READ_MAC: - case WRITE_MAC: - break; - } - - printf("Opening programmer.\n"); - ftHandle = prog_open(opts.port); - if (ftHandle == 0) - { - return (-1); - } - - cdi_start(&chip_id); - - printf("Chip ID = %4.4hX.\n", chip_id); - - if ((chip_id & 0xFF00) == 0x8500) - { - printf("CC2430 chip found.\n"); - } - else if ((chip_id & 0xFF00) == 0x8900) - { - printf("CC2431 chip found.\n"); - } - else - { - printf("Unknown chip found.\n"); - opts.mode = USAGE; - } - - switch(opts.mode) - { - case VERSION: - case USAGE: - break; - - case ERASE: - printf("Erase.\n"); - break; - - case READ: - printf("Read Flash.\n"); - cdi_set_address(0); - break; - - case WRITE: - { - int rval; - unsigned char page_table[64]; - unsigned char page_buffer[128*1024]; - - printf("Write Flash.\n"); - - if((rval = hexfile_build_tables(opts.filename, page_buffer, page_table)) == -1) - { - printf("Error\n"); - return(-1); - } - else if(rval == 0) - { - printf(".ihex file OK but nothing to write...\n"); - return(1); - } - - hexfile_program(page_buffer, page_table); - - break; - } - case READ_MAC: - printf("Read MAC: "); - cdi_set_address(0x1FFF8); - { - uint8_t mac[8]; - - cdi_flash_read(mac, 8); - for (i=0; i<8; i++) - { - if (i) printf(":"); - printf("%2.2X", mac[i]); - } - printf("\n"); - } - break; - - case WRITE_MAC: - printf("Write MAC: "); -/* cdi_set_address(0x1F800); - { - uint8_t block[2048]; - - memset(block, 0xFF, 2048); - for (i=0; i<8; i++) - { - block[2040+i] = opts.write_mac[i]; - } - cdi_flash_write(block, 2048); - printf("\n"); - }*/ - cdi_flash_write_mac(opts.write_mac); - printf("\n"); - break; - - default: - printf("Duh\n"); - break; - } - - - printf("Closing programmer.\n"); - prog_close(); -} - -static int option_index = 0; - -int do_exit = 0; - -#define OPTIONS_STRING "p:vdhf:rwmM:e" -/* long option list */ -static struct option long_options[] = -{ - {"port", 1, NULL, 'p'}, - {"version", 0, NULL, 'v'}, - {"devices", 0, NULL, 'd'}, - {"help", 0, NULL, 'h'}, - {"file", 1, NULL, 'f'}, - {"read", 0, NULL, 'r'}, - {"write", 0, NULL, 'w'}, - {"read-mac", 0, NULL, 'm'}, - {"write-mac", 1, NULL, 'M'}, - {"erase", 0, NULL, 'e'}, - {0, 0, 0, 0} -}; - -int opts_parse(int count, char* param[]) -{ - int opt; - int error=0; - - opts.mode = USAGE; - opts.filename = 0; - while ((opt = getopt_long(count, param, OPTIONS_STRING, - long_options, &option_index)) != -1) - { - fflush(stdout); - switch(opt) - { - case 'p': - opts.port = 0; - if (sscanf(optarg, "%d", &(opts.port)) != 1) - { - if (sscanf(optarg, "/dev/ttyUSB%d", &(opts.port)) != 1) - { - printf("Invalid port.\n"); - opts.mode = USAGE; - return 0; - } - } - printf("Port %d.\n", opts.port); - break; - - case 'v': - opts.mode = VERSION; - return 0; - - case 'd': - opts.mode = SCAN; - return 0; - - case 'h': - opts.mode = USAGE; - return 0; - - case 'e': - opts.mode = ERASE; - break; - - case 'f': - printf("Filename: %s\n", optarg); - opts.filename = malloc(strlen(optarg)+1); - strcpy(opts.filename, optarg); - break; - - case 'r': - opts.mode = READ; - break; - - case 'w': - opts.mode = WRITE; - break; - - case 'm': - opts.mode = READ_MAC; - break; - - case 'M': - opts.mode = WRITE_MAC; - if (sscanf(optarg, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", - &opts.write_mac[0], &opts.write_mac[1], - &opts.write_mac[2], &opts.write_mac[3], - &opts.write_mac[4], &opts.write_mac[5], - &opts.write_mac[6], &opts.write_mac[7]) != 8) - { - printf("Invalid MAC.\n"); - opts.mode = USAGE; - } - else - { - printf("MAC to write: %2.2hhX:%2.2hhX:%2.2hhX:%2.2hhX:%2.2hhX:%2.2hhX:%2.2hhX:%2.2hhX\n", - opts.write_mac[0], opts.write_mac[1], - opts.write_mac[2], opts.write_mac[3], - opts.write_mac[4], opts.write_mac[5], - opts.write_mac[6], opts.write_mac[7]); - } - break; - - case '?': - printf("Duh\n"); - error = -1; - break; - } - } - - return error; -} - diff --git a/tools/sensinode/nano_usb_programmer/prog.c b/tools/sensinode/nano_usb_programmer/prog.c deleted file mode 100644 index 1cce8ec83..000000000 --- a/tools/sensinode/nano_usb_programmer/prog.c +++ /dev/null @@ -1,372 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#include -#include -#ifdef PLATFORM_WINDOWS -#include -#endif -#include - -FT_HANDLE curr_handle = 0; -uint8_t curr_mode = 0; /* 0 = in, 1=out */ - -/* - * This function checks if the CBUS2 ise set to SLEEP and modifies it if necessary. - * The CBUS2 must be set to sleep in order the programming to succeed. - */ -int check_cbus2(FT_HANDLE fthandle) -{ - FT_PROGRAM_DATA eeprom_data; - char manufacturer_buf[32]; - char manufacturer_id[16]; - char description_buf[64]; - char serialnumber_buf[16]; - eeprom_data.Signature1 = 0x00000000; // This is a given value from the FT232R programming guide - eeprom_data.Signature2 = 0xffffffff; // This is a given value from the FT232R programming guide - eeprom_data.Version = 0x00000002; // This is a given value from the FT232R programming guide - eeprom_data.Manufacturer = manufacturer_buf; - eeprom_data.ManufacturerId = manufacturer_id; - eeprom_data.Description = description_buf; - eeprom_data.SerialNumber = serialnumber_buf; - - - if(FT_EE_Read(fthandle, &eeprom_data) != FT_OK) - { - printf("FTDI EEPROM read failed.\n"); - return(-1); - } - - if(eeprom_data.Cbus2 != 0x05) - { - printf("Need to re-program the CBUS2 to 0x05\n"); - eeprom_data.Cbus2 = 0x05; - - if(FT_EE_Program(fthandle, &eeprom_data) != FT_OK) - { - printf("FTDI EEPROM program error.\n"); - return(-1); - } - else - { - printf("FTDI EEPROM program ok\n"); - return(1); - } - } - else - { - return(1); - } - - return(1); -} - - -void prog_scan(void) -{ - FT_STATUS ftStatus; - FT_DEVICE_LIST_INFO_NODE *info; - unsigned long n_devices = 0; - uint8_t out; - - ftStatus = FT_CreateDeviceInfoList(&n_devices); - if (ftStatus == FT_OK) - { - FT_DEVICE_LIST_INFO_NODE devices[n_devices]; - - ftStatus = FT_GetDeviceInfoList(devices,&n_devices); - if (ftStatus == FT_OK) - { - for (out = 0; out < n_devices; out++) - { - printf("Dev %d:",n_devices - out -1); - printf(" Type=0x%x",devices[n_devices - out -1].Type); - printf(" SerialNumber=%s",devices[n_devices - out -1].SerialNumber); - printf(" Description=%s\n",devices[n_devices - out -1].Description); - } - } - else - { - printf("Failed to fetch device list.\n"); - } - } - else - { - printf("Failed to fetch device list.\n"); - } -} - -FT_HANDLE prog_open(int iport) -{ - FT_HANDLE ftHandle; - FT_STATUS ftStatus; - FT_DEVICE_LIST_INFO_NODE *info; - unsigned long n_devices = 0; - uint8_t out; - - if (curr_handle) return 0; - - ftStatus = FT_CreateDeviceInfoList(&n_devices); - if (ftStatus == FT_OK) - { - FT_DEVICE_LIST_INFO_NODE devices[n_devices]; - - ftStatus = FT_GetDeviceInfoList(devices,&n_devices); - if (ftStatus == FT_OK) - { - iport = n_devices - iport - 1; - - if (iport < 0) - { - printf("Invalid port id.\n"); - for (out = 0; out < n_devices; out++) - { - printf("Dev %d:",n_devices - out -1); - printf(" Type=0x%x",devices[n_devices - out -1].Type); - printf(" SerialNumber=%s",devices[n_devices - out -1].SerialNumber); - printf(" Description=%s\n",devices[n_devices - out -1].Description); - } - return 0; - } - } - } - - ftStatus = FT_Open(iport, &ftHandle); - if(ftStatus != FT_OK) { - /* - This can fail if the ftdi_sio driver is loaded - use lsmod to check this and rmmod ftdi_sio to remove - also rmmod usbserial - */ - printf("FT_Open(%d) failed\n", iport); - return 0; - } - - if(check_cbus2(ftHandle) < 0) - { - printf("Nano USB Programmer exiting...\n"); - return(0); - } - - FT_ResetDevice(ftHandle); - - FT_SetBaudRate(ftHandle, 115200); - - FT_SetUSBParameters(ftHandle, 64, 0); - - out = 0x04; - - ftStatus = FT_SetBitMode(ftHandle, out, 0x20); - if (ftStatus == FT_OK) - { - ftStatus = FT_SetLatencyTimer(ftHandle, 2); - } - if (ftStatus == FT_OK) - { - DWORD bytes; - out = 0xE0; - ftStatus = FT_SetBitMode(ftHandle, out, 0x04); - out = 0x80; - FT_Write(ftHandle, &out, 1, &bytes); /*write reset high*/ - FT_Read(ftHandle, &out, 1, &bytes); /*read out*/ - curr_mode = 1; - } - if (ftStatus != FT_OK) - { - printf("Failed to set CBUS2/bit bang mode.\n"); - - FT_ResetDevice(ftHandle); - sleep(3); - FT_Close(ftHandle); - ftHandle = 0; - } - curr_handle = ftHandle; - return ftHandle; -} - -void prog_close(void) -{ - FT_STATUS ftStatus; - DWORD bytes; - - if (curr_handle) - { - FT_HANDLE ftHandle = curr_handle; - uint8_t out = 0x00; - - FT_Write(ftHandle, &out, 1, &bytes); /*write reset low*/ - FT_Read(ftHandle, &out, 1, &bytes); /*read out*/ - sleep(1); - out = 0x80; - FT_Write(ftHandle, &out, 1, &bytes); /*write reset high*/ - FT_Read(ftHandle, &out, 1, &bytes); /*read out*/ - sleep(1); - out = 0x00; - ftStatus = FT_SetBitMode(ftHandle, out, 0x04); - FT_ResetDevice(ftHandle); - FT_Close(ftHandle); - - ftHandle = 0; - curr_handle = ftHandle; - } -} - -int prog_write(uint8_t byte) -{ - FT_STATUS ftStatus; - uint8_t out[16]; - uint8_t mask = 0x80; - int i; - DWORD bytes; - - if (curr_mode == 0) - { - out[0] = 0xE0; - ftStatus = FT_SetBitMode(curr_handle, out[0], 0x04); /*Set DD as output*/ - if (ftStatus != FT_OK) - { printf("!WR"); - fflush(stdout); - return -1; - } - curr_mode = 1; - } - i = 0; - while (mask) - { - out[i] = 0xC0; /*clock high, reset high*/ - if (byte & mask) out[i] |= 0x20; - i++; - out[i] = 0x80; /*clock low, reset high*/ - if (byte & mask) out[i] |= 0x20; - i++; - mask >>= 1; - } - ftStatus = FT_Write(curr_handle, out, 16, &bytes); /*write clock high and data bit*/ - if (ftStatus != FT_OK) - { - printf("!W"); - fflush(stdout); - return -1; - } - - if(FT_Read(curr_handle, out, 16, &bytes) != FT_OK) - { - printf("!R"); - return(-1); - } - - return 0; -} - -int prog_read(uint8_t *byte) -{ - FT_STATUS ftStatus; - uint8_t rd; - uint8_t mask = 0x80; - DWORD bytes; - uint8_t out[17]; - uint8_t i=0; - - *byte = 0; - if (curr_mode == 1) - { - out[0] = 0xC0; - ftStatus = FT_SetBitMode(curr_handle, out[0], 0x04); /*Set DD as input*/ - if (ftStatus != FT_OK) - { printf("!RD"); - fflush(stdout); - return -1; - } - curr_mode = 0; - } - - while (mask) - { - out[i] = 0xC0; /*clock high, reset high*/ - if (*byte & mask) out[i] |= 0x20; - i++; - out[i] = 0x80; /*clock low, reset high*/ - if (*byte & mask) out[i] |= 0x20; - i++; - mask >>= 1; - } - - out[16] = out[15]; - - ftStatus = FT_Write(curr_handle, out, 17, &bytes); /*write clock high and data bit*/ - - if(FT_Read(curr_handle, out, 17, &bytes) != FT_OK) - { - printf("!R"); - return(-1); - } - - mask = 0x80; - i = 1; - while (mask) - { - if (out[i] & 0x20) *byte |= mask; - mask >>= 1; - i+=2; - } - - return 0; -} - -int prog_start(void) -{ - FT_STATUS ftStatus; - uint8_t wr; - uint8_t mask = 0x80; - DWORD bytes; - uint8_t out[16] = { 0x80, 0x00, 0x40, 0x00, 0x40, 0x00, 0x80 }; - - printf("prog_start()\n"); - - if (curr_mode == 0) - { - wr = 0xE0; - - ftStatus = FT_SetBitMode(curr_handle, wr, 0x04); /*Set DD as output*/ - curr_mode = 1; - } - - if(FT_Write(curr_handle, out, 7, &bytes) != FT_OK) - { - printf("!W\n"); - return(-1); - } - - if(FT_Read(curr_handle, out, 7, &bytes) != FT_OK) - { - printf("!R\n"); - return(-1); - } - -} diff --git a/tools/sensinode/nano_usb_programmer/prog.h b/tools/sensinode/nano_usb_programmer/prog.h deleted file mode 100644 index fc2107d47..000000000 --- a/tools/sensinode/nano_usb_programmer/prog.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - NanoStack: MCU software and PC tools for IP-based wireless sensor networking. - - Copyright (C) 2006-2007 Sensinode Ltd. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - Address: - Sensinode Ltd. - Teknologiantie 6 - 90570 Oulu, Finland - - E-mail: - info@sensinode.com -*/ - - -#ifndef _PROG_H -#define _PROG_H - -#include "ftd2xx.h" -#include - -extern FT_HANDLE prog_open(int iport); -extern void prog_close(void); - -extern int prog_write(uint8_t byte); -extern int prog_read(uint8_t *byte); - -extern int prog_start(void); - -extern int check_cbus2(FT_HANDLE fthandle); - -#endif