Removing platform z1
This commit is contained in:
parent
e7088ec6c4
commit
766c0e21dd
|
@ -41,7 +41,3 @@ endif
|
|||
ifeq ($(TARGET),sky)
|
||||
shell_src += shell-sky.c shell-exec.c
|
||||
endif
|
||||
|
||||
ifeq ($(TARGET),z1)
|
||||
shell_src += shell-sky.c shell-exec.c
|
||||
endif
|
||||
|
|
|
@ -139,7 +139,7 @@
|
|||
|
||||
#elif TSCH_CONF_DEFAULT_TIMESLOT_LENGTH == 65000U
|
||||
/* 65ms timeslot, i.e. nearly the max length allowed by standard (16-bit unsigned in micro-seconds).
|
||||
* Useful for running link-layer security on sky or z1 in Cooja, where only S/W security is supported.
|
||||
* Useful for running link-layer security on sky in Cooja, where only S/W security is supported.
|
||||
* Note: this slot timing would require a total of 120ms. If a slot overlaps with the next active slot,
|
||||
* the latter will be skipped.
|
||||
* This configuration is mostly a work-around to test link-layer security in Cooja, it is recommended
|
||||
|
|
|
@ -1,166 +0,0 @@
|
|||
# Common Makefile between the Z1 and Z1SP
|
||||
|
||||
ifdef GCC
|
||||
CFLAGS+=-Os -g
|
||||
endif
|
||||
|
||||
ifdef IAR
|
||||
CFLAGS += -D__MSP430F2617__=1 -e --vla -Ohz --multiplier=16s --core=430X --double=32
|
||||
else
|
||||
LDFLAGS += -Wl,--defsym -Wl,__P1SEL2=0x0041 -Wl,--defsym -Wl,__P5SEL2=0x0045
|
||||
endif
|
||||
|
||||
ARCH = msp430.c leds.c watchdog.c xmem.c i2cmaster.c \
|
||||
spi.c cc2420.c cc2420-arch.c cc2420-arch-sfd.c\
|
||||
node-id.c sensors.c button-sensor.c cfs-coffee.c \
|
||||
radio-sensor.c uart0.c uart0-putchar.c uip-ipchksum.c \
|
||||
slip.c slip_uart0.c z1-sensors.c adxl345.c temperature-sensor.c \
|
||||
z1-phidgets.c light-sensor.c battery-sensor.c sky-sensors.c tmp102.c
|
||||
|
||||
CONTIKI_TARGET_DIRS = . dev apps net
|
||||
ifndef CONTIKI_TARGET_MAIN
|
||||
CONTIKI_TARGET_MAIN = contiki-z1-main.c
|
||||
endif
|
||||
|
||||
ifdef nodemac
|
||||
CFLAGS += -DMACID=$(nodemac)
|
||||
endif
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS)
|
||||
|
||||
MCU=msp430f2617
|
||||
|
||||
# Platform has a MSP430X MCU with 20-bit support
|
||||
CPU_HAS_MSP430X=1
|
||||
|
||||
include $(CONTIKI)/drivers/cpu/msp430/Makefile.msp430
|
||||
|
||||
# Add LDFLAGS after IAR_PATH is set
|
||||
ifdef IAR
|
||||
LDFLAGSNO += -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f2617.xcl"
|
||||
LDFLAGS += $(LDFLAGSNO) -Felf -yn
|
||||
endif
|
||||
|
||||
NUMPAR=20
|
||||
IHEXFILE=tmpimage.ihex
|
||||
|
||||
ifeq ($(HOST_OS),Darwin)
|
||||
ifndef MOTELIST
|
||||
USBDEVPREFIX=
|
||||
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux
|
||||
MOTELIST = $(CONTIKI)/tools/zolertia/motelist-zolertia-macos
|
||||
BSL = $(CONTIKI)/tools/zolertia/z1-bsl-nopic --z1
|
||||
BSL_FILETYPE = -I
|
||||
MOTES = $(shell $(MOTELIST) -b z1 -c 2>&- | \
|
||||
cut -f 2 -d ,)
|
||||
REFNUM = $(shell $(MOTELIST) -c 2>&- | \
|
||||
cut -f 1 -d , | tail -c5 | sed 's/^0*//')
|
||||
ifneq (,$(REFNUM))
|
||||
# No device fo-und
|
||||
ifeq (,$(findstring und, $(REFNUM)))
|
||||
CFLAGS += -DSERIALNUM=$(REFNUM:0%=%)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
else
|
||||
# If we are not running under Mac, we assume Linux
|
||||
ifndef MOTELIST
|
||||
USBDEVPREFIX=
|
||||
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux
|
||||
MOTELIST = $(CONTIKI)/tools/zolertia/motelist-zolertia
|
||||
BSL = $(CONTIKI)/tools/zolertia/z1-bsl-nopic --z1
|
||||
BSL_FILETYPE = -I
|
||||
MOTES = $(shell $(MOTELIST) -b z1 -c 2>&- | \
|
||||
cut -f 2 -d , | \
|
||||
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')
|
||||
CMOTES=$(MOTES)
|
||||
REFNUM = $(shell $(MOTELIST) -c 2>&- | \
|
||||
cut -f 1 -d , | tail -c5 | sed 's/^0*//')
|
||||
ifneq (,$(REFNUM))
|
||||
# No device fo-und
|
||||
ifeq (,$(findstring und, $(REFNUM)))
|
||||
CFLAGS += -DSERIALNUM=$(REFNUM)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
motelist:
|
||||
$(MOTELIST)
|
||||
z1-motelist:
|
||||
$(MOTELIST) -b z1
|
||||
z1-motes:
|
||||
@echo $(MOTES)
|
||||
|
||||
ifdef MOTE
|
||||
%.upload: %.ihex
|
||||
cp $< $(IHEXFILE)
|
||||
$(MAKE) z1-u.$(subst /,-,$(word $(MOTE), $(MOTES)))
|
||||
else # MOTE
|
||||
%.upload: %.ihex
|
||||
cp $< $(IHEXFILE)
|
||||
@echo $(MOTES)
|
||||
$(MAKE) z1-reset z1-upload
|
||||
endif # MOTE
|
||||
|
||||
z1-upload: z1-reset
|
||||
$(MAKE) -j $(NUMPAR) z1-upload-sequence
|
||||
|
||||
z1-upload-sequence: $(foreach PORT, $(MOTES), z1-u.$(subst /,-,$(PORT)))
|
||||
@echo Done
|
||||
|
||||
z1-reset:
|
||||
$(MAKE) -k -j $(NUMPAR) z1-reset-sequence
|
||||
|
||||
z1-reset-sequence: $(foreach PORT, $(MOTES), z1-r.$(subst /,-,$(PORT)))
|
||||
@echo Done
|
||||
|
||||
z1-u.%:
|
||||
@echo +++++ Erasing $(subst -,/,$*); \
|
||||
$(BSL) -c $(subst -,/,$*) -e && sleep 2 ; \
|
||||
echo +++++ Programming $(subst -,/,$*) ; \
|
||||
$(BSL) -c $(subst -,/,$*) $(BSL_FILETYPE) -p $(IHEXFILE) && sleep 2 ; \
|
||||
echo +++++ Resetting $(subst -,/,$*) ; \
|
||||
$(BSL) -c $(subst -,/,$*) -r
|
||||
|
||||
z1-r.%:
|
||||
$(BSL) -c $(subst -,/,$*) -r
|
||||
|
||||
sizeplot:
|
||||
msp430-size $(OBJECTDIR)/*.o | $(CONTIKI)/tools/sky/check-size > size-data
|
||||
gnuplot $(CONTIKI)/tools/sky/plot-size
|
||||
gv size.pdf
|
||||
|
||||
winslip:
|
||||
ifdef INTERFACE
|
||||
$(CONTIKI)/tools/wpcapslip/wpcapslip -s $(USBDEVPREFIX)$(firstword $(CMOTES)) $(INTERFACE) 172.16.0.0 255.255.0.0
|
||||
else
|
||||
@echo "Usage: \"$(MAKE) $@ INTERFACE=<the IP address of a local network interface>\""
|
||||
@echo "Use the \"ipconfig\" command to find out the IP addresses of the local interfaces"
|
||||
endif
|
||||
|
||||
linslip: $(CONTIKI)/tools/tunslip
|
||||
$(CONTIKI)/tools/tunslip -s $(USBDEVPREFIX)$(firstword $(CMOTES)) 172.16.0.0 255.255.0.0
|
||||
|
||||
$(CONTIKI)/tools/tunslip:
|
||||
(cd $(CONTIKI)/tools; $(MAKE) tunslip)
|
||||
|
||||
ifdef MOTE
|
||||
serialdump:
|
||||
$(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES)) | $(CONTIKI)/tools/timestamp | tee serialdump-`date +%Y%m%d-%H%M`
|
||||
|
||||
serialview:
|
||||
$(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES)) | $(CONTIKI)/tools/timestamp
|
||||
|
||||
login:
|
||||
$(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES))
|
||||
else
|
||||
serialdump:
|
||||
$(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(firstword $(CMOTES)) | $(CONTIKI)/tools/timestamp | tee serialdump-`date +%Y%m%d-%H%M`
|
||||
|
||||
serialview:
|
||||
$(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(firstword $(CMOTES)) | $(CONTIKI)/tools/timestamp
|
||||
|
||||
login:
|
||||
$(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(firstword $(CMOTES))
|
||||
endif
|
|
@ -1,14 +0,0 @@
|
|||
# Common Makefile between Z1 and Z1SP
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += contiki-z1-platform.c
|
||||
CLEAN += *.z1
|
||||
|
||||
include $(CONTIKI)/drivers/platform/z1/Makefile.common
|
||||
|
||||
ifeq ($(ZOLERTIA_Z1SP),1)
|
||||
include $(CONTIKI)/drivers/platform/z1/Makefile.z1sp
|
||||
endif
|
||||
|
||||
MODULES += core/net \
|
||||
core/net/mac \
|
||||
drivers/dev/cc2420
|
|
@ -1,6 +0,0 @@
|
|||
# Makefile for Z1 Starter Platform
|
||||
|
||||
# This is the actual flag we need to include specific Z1SP components
|
||||
CFLAGS += -DZ1_IS_Z1SP
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += potentiometer-sensor.c
|
|
@ -1,9 +0,0 @@
|
|||
Using the Z1 starter platform (Z1SP)
|
||||
============================================
|
||||
|
||||
To enable the Z1SP components, you should include in your application Makefile
|
||||
the ZOLERTIA_Z1SP flag set to 1, see "examples/z1/Makefile".
|
||||
|
||||
For Z1SP specific information please go to:
|
||||
|
||||
http://zolertia.sourceforge.net/wiki/index.php/Mainpage:z1sp
|
|
@ -1,65 +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
|
||||
* A quick program that blinks the LEDs
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "dev/leds.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(blink_process, "Blink");
|
||||
AUTOSTART_PROCESSES(&blink_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(blink_process, ev, data)
|
||||
{
|
||||
PROCESS_EXITHANDLER(goto exit;)
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while(1) {
|
||||
static struct etimer et;
|
||||
etimer_set(&et, CLOCK_SECOND);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
leds_on(LEDS_ALL);
|
||||
etimer_set(&et, CLOCK_SECOND);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
leds_off(LEDS_ALL);
|
||||
}
|
||||
|
||||
exit:
|
||||
leds_off(LEDS_ALL);
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,81 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* A program for burning a node ID into the flash ROM of a Tmote Sky node.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "dev/leds.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "sys/node-id.h"
|
||||
#include "contiki.h"
|
||||
#include "sys/etimer.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static struct etimer etimer;
|
||||
|
||||
PROCESS(burn_process, "Burn node id");
|
||||
AUTOSTART_PROCESSES(&burn_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(burn_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
etimer_set(&etimer, 5*CLOCK_SECOND);
|
||||
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
|
||||
|
||||
watchdog_stop();
|
||||
leds_on(LEDS_RED);
|
||||
#if NODEID
|
||||
#warning "***** BURNING NODE ID"
|
||||
printf("Burning node id %d\n", NODEID);
|
||||
node_id_burn(NODEID);
|
||||
leds_on(LEDS_BLUE);
|
||||
node_id_restore();
|
||||
printf("Restored node id %d\n", node_id);
|
||||
#else
|
||||
#error "burn-nodeid must be compiled with nodeid=<the ID of the node>"
|
||||
node_id_restore();
|
||||
printf("Restored node id %d\n", node_id);
|
||||
#endif
|
||||
leds_off(LEDS_RED + LEDS_BLUE);
|
||||
watchdog_start();
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,173 +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.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "dev/leds.h"
|
||||
|
||||
PROCESS(fader_process, "LED fader");
|
||||
AUTOSTART_PROCESSES(&fader_process);
|
||||
|
||||
#define ON 1
|
||||
#define OFF 0
|
||||
|
||||
struct fader {
|
||||
struct pt fade_pt, fade_in_pt, fade_out_pt;
|
||||
struct etimer etimer;
|
||||
int led;
|
||||
int delay;
|
||||
};
|
||||
|
||||
static unsigned char onoroff;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(fade_in(struct fader *f))
|
||||
{
|
||||
PT_BEGIN(&f->fade_in_pt);
|
||||
|
||||
for(f->delay = 3980; f->delay > 20; f->delay -= 20) {
|
||||
leds_on(f->led);
|
||||
clock_delay(4000 - f->delay);
|
||||
leds_off(f->led);
|
||||
clock_delay(f->delay);
|
||||
PT_YIELD(&f->fade_in_pt);
|
||||
}
|
||||
|
||||
PT_END(&f->fade_in_pt);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(fade_out(struct fader *f))
|
||||
{
|
||||
PT_BEGIN(&f->fade_out_pt);
|
||||
|
||||
for(f->delay = 20; f->delay < 3980; f->delay += 20) {
|
||||
leds_on(f->led);
|
||||
clock_delay(4000 - f->delay);
|
||||
leds_off(f->led);
|
||||
clock_delay(f->delay);
|
||||
PT_YIELD(&f->fade_out_pt);
|
||||
}
|
||||
|
||||
PT_END(&f->fade_out_pt);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(fade(struct fader *f))
|
||||
{
|
||||
PT_BEGIN(&f->fade_pt);
|
||||
|
||||
while(1) {
|
||||
|
||||
PT_SPAWN(&f->fade_pt, &f->fade_in_pt, fade_in(f));
|
||||
PT_SPAWN(&f->fade_pt, &f->fade_out_pt, fade_out(f));
|
||||
|
||||
etimer_set(&f->etimer, CLOCK_SECOND * 4);
|
||||
PT_WAIT_UNTIL(&f->fade_pt, etimer_expired(&f->etimer));
|
||||
}
|
||||
|
||||
PT_END(&f->fade_pt);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
init_fader(struct fader *f, int led)
|
||||
{
|
||||
PT_INIT(&f->fade_pt);
|
||||
PT_INIT(&f->fade_in_pt);
|
||||
PT_INIT(&f->fade_out_pt);
|
||||
f->led = led;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(fader_process, ev, data)
|
||||
{
|
||||
static struct fader red, green, yellow;
|
||||
static struct timer timer;
|
||||
static struct etimer etimer;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
init_fader(&red, LEDS_RED);
|
||||
init_fader(&green, LEDS_GREEN);
|
||||
init_fader(&yellow, LEDS_YELLOW);
|
||||
|
||||
timer_set(&timer, CLOCK_SECOND/4);
|
||||
while(!timer_expired(&timer)) {
|
||||
PT_SCHEDULE(fade(&red));
|
||||
}
|
||||
timer_set(&timer, CLOCK_SECOND/4);
|
||||
while(!timer_expired(&timer)) {
|
||||
PT_SCHEDULE(fade(&red));
|
||||
PT_SCHEDULE(fade(&green));
|
||||
}
|
||||
|
||||
timer_set(&timer, CLOCK_SECOND/4);
|
||||
while(!timer_expired(&timer)) {
|
||||
PT_SCHEDULE(fade(&green));
|
||||
PT_SCHEDULE(fade(&yellow));
|
||||
}
|
||||
|
||||
etimer_set(&etimer, CLOCK_SECOND * 4);
|
||||
fader_on();
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
if(ev == PROCESS_EVENT_TIMER) {
|
||||
etimer_set(&etimer, CLOCK_SECOND * 4);
|
||||
process_poll(&fader_process);
|
||||
}
|
||||
|
||||
if(onoroff == ON &&
|
||||
PT_SCHEDULE(fade(&red)) &&
|
||||
PT_SCHEDULE(fade(&yellow)) &&
|
||||
PT_SCHEDULE(fade(&green))) {
|
||||
process_poll(&fader_process);
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
fader_on(void)
|
||||
{
|
||||
onoroff = ON;
|
||||
process_poll(&fader_process);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
fader_off(void)
|
||||
{
|
||||
onoroff = OFF;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 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
|
||||
* Coffee architecture-dependent header for the Zolertia Z1 platform.
|
||||
* \author
|
||||
* Nicolas Tsiftes <nvt@sics.se>
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>
|
||||
*/
|
||||
|
||||
#ifndef CFS_COFFEE_ARCH_H
|
||||
#define CFS_COFFEE_ARCH_H
|
||||
|
||||
#include "contiki-conf.h"
|
||||
#include "dev/xmem.h"
|
||||
|
||||
/*** M25P16 Memory Organization
|
||||
The memory is organized as:
|
||||
16Mbit = 2 097 152 bytes (8 bits each)
|
||||
32 sectors (512 Kbits, 65536 bytes each)
|
||||
8192 pages (256 bytes each).
|
||||
Each page can be individually programmed (bits are programmed from 1 to 0). The device is
|
||||
sector or bulk erasable (bits are erased from 0 to 1) but not page erasable
|
||||
*/
|
||||
#define COFFEE_XMEM_TOTAL_SIZE_KB 2048UL //Total size of the External Flash Memory in the Z1
|
||||
|
||||
/* Coffee configuration parameters. */
|
||||
#define COFFEE_SECTOR_SIZE 65536UL
|
||||
#define COFFEE_PAGE_SIZE 256UL
|
||||
#define COFFEE_START COFFEE_SECTOR_SIZE
|
||||
#define COFFEE_SIZE (COFFEE_XMEM_TOTAL_SIZE_KB * 1024UL - COFFEE_START)
|
||||
#define COFFEE_NAME_LENGTH 16
|
||||
#define COFFEE_MAX_OPEN_FILES 6
|
||||
#define COFFEE_FD_SET_SIZE 8
|
||||
#define COFFEE_LOG_TABLE_LIMIT 256
|
||||
#define COFFEE_DYN_SIZE 4*1024
|
||||
#define COFFEE_LOG_SIZE 1024
|
||||
|
||||
#define COFFEE_MICRO_LOGS 1
|
||||
|
||||
/* Flash operations. */
|
||||
#define COFFEE_WRITE(buf, size, offset) \
|
||||
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))
|
||||
|
||||
#define COFFEE_READ(buf, size, offset) \
|
||||
xmem_pread((char *)(buf), (size), COFFEE_START + (offset))
|
||||
|
||||
#define COFFEE_ERASE(sector) \
|
||||
xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE)
|
||||
|
||||
/* Coffee types. */
|
||||
typedef int16_t coffee_page_t;
|
||||
|
||||
#endif /* !COFFEE_ARCH_H */
|
|
@ -1,196 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CONTIKI_CONF_H
|
||||
#define CONTIKI_CONF_H
|
||||
|
||||
#include "platform-conf.h"
|
||||
|
||||
#ifdef PROJECT_CONF_H
|
||||
#include PROJECT_CONF_H
|
||||
#endif /* PROJECT_CONF_H */
|
||||
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
|
||||
/* Network setup for IPv6 */
|
||||
#ifndef NETSTACK_CONF_NETWORK
|
||||
#define NETSTACK_CONF_NETWORK sicslowpan_driver
|
||||
#endif
|
||||
|
||||
#ifndef NETSTACK_CONF_MAC
|
||||
#define NETSTACK_CONF_MAC csma_driver
|
||||
#endif
|
||||
|
||||
#ifndef NETSTACK_CONF_RDC
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
#endif
|
||||
|
||||
#ifndef NETSTACK_CONF_FRAMER
|
||||
#define NETSTACK_CONF_FRAMER framer_802154
|
||||
#endif
|
||||
|
||||
#define NETSTACK_CONF_RADIO cc2420_driver
|
||||
|
||||
/* Specify a minimum packet size for 6lowpan compression to be
|
||||
enabled. This is needed for ContikiMAC, which needs packets to be
|
||||
larger than a specified size, if no ContikiMAC header should be
|
||||
used. */
|
||||
#define SICSLOWPAN_CONF_COMPRESSION_THRESHOLD 63
|
||||
|
||||
#define CC2420_CONF_AUTOACK 1
|
||||
|
||||
#ifndef QUEUEBUF_CONF_NUM
|
||||
#define QUEUEBUF_CONF_NUM 4
|
||||
#endif
|
||||
|
||||
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||
|
||||
#define PACKETBUF_CONF_ATTRS_INLINE 1
|
||||
|
||||
#ifdef RF_CHANNEL
|
||||
#define CC2420_CONF_CHANNEL RF_CHANNEL
|
||||
#endif
|
||||
|
||||
#ifndef CC2420_CONF_CHANNEL
|
||||
#define CC2420_CONF_CHANNEL 26
|
||||
#endif /* CC2420_CONF_CHANNEL */
|
||||
|
||||
#ifndef CC2420_CONF_CCA_THRESH
|
||||
#define CC2420_CONF_CCA_THRESH -45
|
||||
#endif /* CC2420_CONF_CCA_THRESH */
|
||||
|
||||
#ifndef IEEE802154_CONF_PANID
|
||||
#define IEEE802154_CONF_PANID 0xABCD
|
||||
#endif
|
||||
|
||||
/* The TSCH default slot length of 10ms is a bit too short for this platform,
|
||||
* use 15ms instead. */
|
||||
#ifndef TSCH_CONF_DEFAULT_TIMESLOT_LENGTH
|
||||
#define TSCH_CONF_DEFAULT_TIMESLOT_LENGTH 15000
|
||||
#endif
|
||||
|
||||
#define SHELL_VARS_CONF_RAM_BEGIN 0x1100
|
||||
#define SHELL_VARS_CONF_RAM_END 0x2000
|
||||
|
||||
#define CFS_CONF_OFFSET_TYPE long
|
||||
|
||||
#define PROFILE_CONF_ON 0
|
||||
#define ENERGEST_CONF_ON 1
|
||||
|
||||
#define AODV_COMPLIANCE
|
||||
#define AODV_NUM_RT_ENTRIES 32
|
||||
|
||||
#define WITH_ASCII 1
|
||||
|
||||
#define PROCESS_CONF_NUMEVENTS 8
|
||||
#define PROCESS_CONF_STATS 1
|
||||
/*#define PROCESS_CONF_FASTPOLL 4*/
|
||||
|
||||
#define UART0_CONF_TX_WITH_INTERRUPT 0 /* So far, printfs without interrupt. */
|
||||
|
||||
#define UART0_CONF_RX_WITH_DMA 0
|
||||
|
||||
#ifdef NETSTACK_CONF_WITH_IPV6
|
||||
|
||||
#define LINKADDR_CONF_SIZE 8
|
||||
|
||||
#define UIP_CONF_LL_802154 1
|
||||
#define UIP_CONF_LLH_LEN 0
|
||||
|
||||
#define UIP_CONF_ROUTER 1
|
||||
|
||||
/* Handle 10 neighbors */
|
||||
#ifndef NBR_TABLE_CONF_MAX_NEIGHBORS
|
||||
#define NBR_TABLE_CONF_MAX_NEIGHBORS 15
|
||||
#endif
|
||||
|
||||
/* Handle 10 routes */
|
||||
#ifndef UIP_CONF_MAX_ROUTES
|
||||
#define UIP_CONF_MAX_ROUTES 15
|
||||
#endif
|
||||
|
||||
#define UIP_CONF_ND6_SEND_RA 0
|
||||
#define UIP_CONF_ND6_REACHABLE_TIME 600000
|
||||
#define UIP_CONF_ND6_RETRANS_TIMER 10000
|
||||
|
||||
#define NETSTACK_CONF_WITH_IPV6 1
|
||||
#define UIP_CONF_IPV6_QUEUE_PKT 0
|
||||
#define UIP_CONF_IPV6_CHECKS 1
|
||||
#define UIP_CONF_IPV6_REASSEMBLY 0
|
||||
#define UIP_CONF_NETIF_MAX_ADDRESSES 3
|
||||
#define UIP_CONF_IP_FORWARD 0
|
||||
|
||||
#ifndef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 140
|
||||
#endif
|
||||
|
||||
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
|
||||
#ifndef SICSLOWPAN_CONF_FRAG
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
#define SICSLOWPAN_CONF_MAXAGE 8
|
||||
#endif /* SICSLOWPAN_CONF_FRAG */
|
||||
#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2
|
||||
#else /* NETSTACK_CONF_WITH_IPV6 */
|
||||
#define UIP_CONF_IP_FORWARD 1
|
||||
|
||||
#ifndef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 108
|
||||
#endif
|
||||
|
||||
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||
|
||||
#define UIP_CONF_ICMP_DEST_UNREACH 1
|
||||
|
||||
#define UIP_CONF_DHCP_LIGHT
|
||||
#define UIP_CONF_LLH_LEN 0
|
||||
#ifndef UIP_CONF_RECEIVE_WINDOW
|
||||
#define UIP_CONF_RECEIVE_WINDOW 48
|
||||
#endif
|
||||
#define UIP_CONF_TCP_MSS 48
|
||||
#define UIP_CONF_MAX_CONNECTIONS 4
|
||||
#define UIP_CONF_MAX_LISTENPORTS 8
|
||||
#define UIP_CONF_UDP_CONNS 12
|
||||
#define UIP_CONF_FWCACHE_SIZE 30
|
||||
#define UIP_CONF_BROADCAST 1
|
||||
#define UIP_ARCH_IPCHKSUM 1
|
||||
#define UIP_CONF_UDP 1
|
||||
#define UIP_CONF_UDP_CHECKSUMS 1
|
||||
#define UIP_CONF_PINGADDRCONF 0
|
||||
#define UIP_CONF_LOGGING 0
|
||||
|
||||
#define UIP_CONF_TCP_SPLIT 0
|
||||
|
||||
#define BOARD_STRING "Zolertia Z1 platform"
|
||||
|
||||
#ifndef AES_128_CONF
|
||||
#define AES_128_CONF cc2420_aes_128_driver
|
||||
#endif /* AES_128_CONF */
|
||||
|
||||
#endif /* CONTIKI_CONF_H */
|
|
@ -1,484 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "cc2420.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/serial-line.h"
|
||||
#include "dev/slip.h"
|
||||
#include "dev/uart0.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/xmem.h"
|
||||
#include "lib/random.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/mac/frame802154.h"
|
||||
#include "net/queuebuf.h"
|
||||
#include "dev/adxl345.h"
|
||||
#include "sys/clock.h"
|
||||
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
#include "net/ipv6/uip-ds6.h"
|
||||
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||
|
||||
#include "sys/node-id.h"
|
||||
#include "cfs-coffee-arch.h"
|
||||
#include "cfs/cfs-coffee.h"
|
||||
#include "sys/autostart.h"
|
||||
|
||||
extern unsigned char node_mac[8];
|
||||
|
||||
#if DCOSYNCH_CONF_ENABLED
|
||||
static struct timer mgt_timer;
|
||||
#endif
|
||||
|
||||
#ifndef NETSTACK_CONF_WITH_IPV4
|
||||
#define NETSTACK_CONF_WITH_IPV4 0
|
||||
#endif
|
||||
|
||||
#if NETSTACK_CONF_WITH_IPV4
|
||||
#include "net/ip/uip.h"
|
||||
#include "net/ipv4/uip-fw.h"
|
||||
#include "net/ipv4/uip-fw-drv.h"
|
||||
#include "net/ipv4/uip-over-mesh.h"
|
||||
static struct uip_fw_netif slipif =
|
||||
{ UIP_FW_NETIF(192, 168, 1, 2, 255, 255, 255, 255, slip_send) };
|
||||
static struct uip_fw_netif meshif =
|
||||
{ UIP_FW_NETIF(172, 16, 0, 0, 255, 255, 0, 0, uip_over_mesh_send) };
|
||||
|
||||
#endif /* NETSTACK_CONF_WITH_IPV4 */
|
||||
|
||||
#define UIP_OVER_MESH_CHANNEL 8
|
||||
#if NETSTACK_CONF_WITH_IPV4
|
||||
static uint8_t is_gateway;
|
||||
#endif /* NETSTACK_CONF_WITH_IPV4 */
|
||||
|
||||
#ifdef EXPERIMENT_SETUP
|
||||
#include "experiment-setup.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
void init_platform(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef UART0_CONF_BAUD_RATE
|
||||
#define UART0_BAUD_RATE UART0_CONF_BAUD_RATE
|
||||
#else
|
||||
#define UART0_BAUD_RATE 115200
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
int
|
||||
force_float_inclusion()
|
||||
{
|
||||
extern int __fixsfsi;
|
||||
extern int __floatsisf;
|
||||
extern int __mulsf3;
|
||||
extern int __subsf3;
|
||||
|
||||
return __fixsfsi + __floatsisf + __mulsf3 + __subsf3;
|
||||
}
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
uip_log(char *msg)
|
||||
{
|
||||
puts(msg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
void
|
||||
force_inclusion(int d1, int d2)
|
||||
{
|
||||
snprintf(NULL, 0, "%d", d1 % d2);
|
||||
}
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_rime_addr(void)
|
||||
{
|
||||
linkaddr_t addr;
|
||||
int i;
|
||||
|
||||
memset(&addr, 0, sizeof(linkaddr_t));
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
memcpy(addr.u8, node_mac, sizeof(addr.u8));
|
||||
#else
|
||||
if(node_id == 0) {
|
||||
for(i = 0; i < sizeof(linkaddr_t); ++i) {
|
||||
addr.u8[i] = node_mac[7 - i];
|
||||
}
|
||||
} else {
|
||||
addr.u8[0] = node_id & 0xff;
|
||||
addr.u8[1] = node_id >> 8;
|
||||
}
|
||||
#endif
|
||||
linkaddr_set_node_addr(&addr);
|
||||
printf("Rime started with address ");
|
||||
for(i = 0; i < sizeof(addr.u8) - 1; i++) {
|
||||
printf("%d.", addr.u8[i]);
|
||||
}
|
||||
printf("%d\n", addr.u8[i]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
print_processes(struct process *const processes[])
|
||||
{
|
||||
/* const struct process * const * p = processes;*/
|
||||
printf("Starting");
|
||||
while(*processes != NULL) {
|
||||
printf(" '%s'", (*processes)->name);
|
||||
processes++;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if NETSTACK_CONF_WITH_IPV4
|
||||
static void
|
||||
set_gateway(void)
|
||||
{
|
||||
if(!is_gateway) {
|
||||
leds_on(LEDS_RED);
|
||||
printf("%d.%d: making myself the IP network gateway.\n\n",
|
||||
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
|
||||
printf("IPv4 address of the gateway: %d.%d.%d.%d\n\n",
|
||||
uip_ipaddr_to_quad(&uip_hostaddr));
|
||||
uip_over_mesh_set_gateway(&linkaddr_node_addr);
|
||||
uip_over_mesh_make_announced_gateway();
|
||||
is_gateway = 1;
|
||||
}
|
||||
}
|
||||
#endif /* NETSTACK_CONF_WITH_IPV4 */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
/*
|
||||
* Initalize hardware.
|
||||
*/
|
||||
msp430_cpu_init();
|
||||
clock_init();
|
||||
leds_init();
|
||||
leds_on(LEDS_RED);
|
||||
|
||||
clock_wait(100);
|
||||
|
||||
uart0_init(BAUD2UBR(UART0_BAUD_RATE)); /* Must come before first printf */
|
||||
#if NETSTACK_CONF_WITH_IPV4
|
||||
slip_arch_init(BAUD2UBR(UART0_BAUD_RATE));
|
||||
#endif /* NETSTACK_CONF_WITH_IPV4 */
|
||||
|
||||
xmem_init();
|
||||
|
||||
rtimer_init();
|
||||
/*
|
||||
* Hardware initialization done!
|
||||
*/
|
||||
|
||||
/* Restore node id if such has been stored in external mem */
|
||||
node_id_restore();
|
||||
|
||||
/* If no MAC address was burned, we use the node id or the Z1 product ID */
|
||||
if(!(node_mac[0] | node_mac[1] | node_mac[2] | node_mac[3] |
|
||||
node_mac[4] | node_mac[5] | node_mac[6] | node_mac[7])) {
|
||||
|
||||
#ifdef SERIALNUM
|
||||
if(!node_id) {
|
||||
PRINTF("Node id is not set, using Z1 product ID\n");
|
||||
node_id = SERIALNUM;
|
||||
}
|
||||
#endif
|
||||
node_mac[0] = 0xc1; /* Hardcoded for Z1 */
|
||||
node_mac[1] = 0x0c; /* Hardcoded for Revision C */
|
||||
node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that
|
||||
the 802.15.4 MAC address is compatible with
|
||||
an Ethernet MAC address - byte 0 (byte 2 in
|
||||
the DS ID) */
|
||||
node_mac[3] = 0x00; /* Hardcoded */
|
||||
node_mac[4] = 0x00; /* Hardcoded */
|
||||
node_mac[5] = 0x00; /* Hardcoded */
|
||||
node_mac[6] = node_id >> 8;
|
||||
node_mac[7] = node_id & 0xff;
|
||||
}
|
||||
|
||||
/* Overwrite node MAC if desired at compile time */
|
||||
#ifdef MACID
|
||||
#warning "***** CHANGING DEFAULT MAC *****"
|
||||
node_mac[0] = 0xc1; /* Hardcoded for Z1 */
|
||||
node_mac[1] = 0x0c; /* Hardcoded for Revision C */
|
||||
node_mac[2] = 0x00; /* Hardcoded to arbitrary even number so that
|
||||
the 802.15.4 MAC address is compatible with
|
||||
an Ethernet MAC address - byte 0 (byte 2 in
|
||||
the DS ID) */
|
||||
node_mac[3] = 0x00; /* Hardcoded */
|
||||
node_mac[4] = 0x00; /* Hardcoded */
|
||||
node_mac[5] = 0x00; /* Hardcoded */
|
||||
node_mac[6] = MACID >> 8;
|
||||
node_mac[7] = MACID & 0xff;
|
||||
#endif
|
||||
|
||||
#ifdef IEEE_802154_MAC_ADDRESS
|
||||
/* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
|
||||
{
|
||||
uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
|
||||
memcpy(node_mac, ieee, sizeof(uip_lladdr.addr));
|
||||
node_mac[7] = node_id & 0xff;
|
||||
}
|
||||
#endif /* IEEE_802154_MAC_ADDRESS */
|
||||
|
||||
/*
|
||||
* Initialize Contiki and our processes.
|
||||
*/
|
||||
random_init(node_mac[6] + node_mac[7]);
|
||||
process_init();
|
||||
process_start(&etimer_process, NULL);
|
||||
|
||||
ctimer_init();
|
||||
|
||||
init_platform();
|
||||
|
||||
set_rime_addr();
|
||||
|
||||
cc2420_init();
|
||||
SENSORS_ACTIVATE(adxl345);
|
||||
|
||||
{
|
||||
uint8_t longaddr[8];
|
||||
uint16_t shortaddr;
|
||||
|
||||
shortaddr = (linkaddr_node_addr.u8[0] << 8) +
|
||||
linkaddr_node_addr.u8[1];
|
||||
memset(longaddr, 0, sizeof(longaddr));
|
||||
linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_node_addr);
|
||||
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
|
||||
longaddr[0], longaddr[1], longaddr[2], longaddr[3],
|
||||
longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
|
||||
|
||||
cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
|
||||
}
|
||||
|
||||
leds_off(LEDS_ALL);
|
||||
|
||||
#ifdef SERIALNUM
|
||||
PRINTF("Ref ID: %u\n", SERIALNUM);
|
||||
#endif
|
||||
PRINTF(CONTIKI_VERSION_STRING " started. ");
|
||||
|
||||
if(node_id) {
|
||||
PRINTF("Node id is set to %u.\n", node_id);
|
||||
} else {
|
||||
PRINTF("Node id not set\n");
|
||||
}
|
||||
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
memcpy(&uip_lladdr.addr, node_mac, sizeof(uip_lladdr.addr));
|
||||
/* Setup nullmac-like MAC for 802.15.4 */
|
||||
/* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */
|
||||
/* printf(" %s channel %u\n", sicslowmac_driver.name, CC2420_CONF_CHANNEL); */
|
||||
|
||||
/* Setup X-MAC for 802.15.4 */
|
||||
queuebuf_init();
|
||||
|
||||
NETSTACK_RDC.init();
|
||||
NETSTACK_MAC.init();
|
||||
NETSTACK_NETWORK.init();
|
||||
|
||||
printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
|
||||
NETSTACK_MAC.name, NETSTACK_RDC.name,
|
||||
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
|
||||
NETSTACK_RDC.channel_check_interval()),
|
||||
CC2420_CONF_CHANNEL);
|
||||
|
||||
process_start(&tcpip_process, NULL);
|
||||
|
||||
printf("Tentative link-local IPv6 address ");
|
||||
{
|
||||
uip_ds6_addr_t *lladdr;
|
||||
int i;
|
||||
lladdr = uip_ds6_get_link_local(-1);
|
||||
for(i = 0; i < 7; ++i) {
|
||||
printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
|
||||
lladdr->ipaddr.u8[i * 2 + 1]);
|
||||
}
|
||||
printf("%02x%02x\n", lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
|
||||
}
|
||||
|
||||
if(!UIP_CONF_IPV6_RPL) {
|
||||
uip_ipaddr_t ipaddr;
|
||||
int i;
|
||||
uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
|
||||
printf("Tentative global IPv6 address ");
|
||||
for(i = 0; i < 7; ++i) {
|
||||
printf("%02x%02x:",
|
||||
ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
|
||||
}
|
||||
printf("%02x%02x\n",
|
||||
ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
|
||||
}
|
||||
|
||||
#else /* NETSTACK_CONF_WITH_IPV6 */
|
||||
|
||||
NETSTACK_RDC.init();
|
||||
NETSTACK_MAC.init
|
||||
NETSTACK_NETWORK.init();
|
||||
|
||||
printf("%s %s, channel check rate %lu Hz, radio channel %u\n",
|
||||
NETSTACK_MAC.name, NETSTACK_RDC.name,
|
||||
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1 :
|
||||
NETSTACK_RDC.channel_check_interval()),
|
||||
CC2420_CONF_CHANNEL);
|
||||
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||
|
||||
#if !NETSTACK_CONF_WITH_IPV4 && !NETSTACK_CONF_WITH_IPV6
|
||||
uart0_set_input(serial_line_input_byte);
|
||||
serial_line_init();
|
||||
#endif
|
||||
|
||||
leds_off(LEDS_GREEN);
|
||||
|
||||
#if TIMESYNCH_CONF_ENABLED
|
||||
timesynch_init();
|
||||
timesynch_set_authority_level(linkaddr_node_addr.u8[0]);
|
||||
#endif /* TIMESYNCH_CONF_ENABLED */
|
||||
|
||||
#if NETSTACK_CONF_WITH_IPV4
|
||||
process_start(&tcpip_process, NULL);
|
||||
process_start(&uip_fw_process, NULL); /* Start IP output */
|
||||
process_start(&slip_process, NULL);
|
||||
|
||||
slip_set_input_callback(set_gateway);
|
||||
|
||||
{
|
||||
uip_ipaddr_t hostaddr, netmask;
|
||||
|
||||
uip_init();
|
||||
|
||||
uip_ipaddr(&hostaddr, 172, 16,
|
||||
linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1]);
|
||||
uip_ipaddr(&netmask, 255, 255, 0, 0);
|
||||
uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
|
||||
|
||||
uip_sethostaddr(&hostaddr);
|
||||
uip_setnetmask(&netmask);
|
||||
uip_over_mesh_set_net(&hostaddr, &netmask);
|
||||
/* uip_fw_register(&slipif);*/
|
||||
uip_over_mesh_set_gateway_netif(&slipif);
|
||||
uip_fw_default(&meshif);
|
||||
uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
|
||||
printf("uIP started with IP address %d.%d.%d.%d\n",
|
||||
uip_ipaddr_to_quad(&hostaddr));
|
||||
}
|
||||
#endif /* NETSTACK_CONF_WITH_IPV4 */
|
||||
|
||||
energest_init();
|
||||
ENERGEST_ON(ENERGEST_TYPE_CPU);
|
||||
|
||||
print_processes(autostart_processes);
|
||||
autostart_start(autostart_processes);
|
||||
|
||||
/*
|
||||
* This is the scheduler loop.
|
||||
*/
|
||||
#if DCOSYNCH_CONF_ENABLED
|
||||
timer_set(&mgt_timer, DCOSYNCH_PERIOD * CLOCK_SECOND);
|
||||
#endif
|
||||
watchdog_start();
|
||||
/* watchdog_stop();*/
|
||||
while(1) {
|
||||
int r;
|
||||
do {
|
||||
/* Reset watchdog. */
|
||||
watchdog_periodic();
|
||||
r = process_run();
|
||||
} while(r > 0);
|
||||
|
||||
/*
|
||||
* Idle processing.
|
||||
*/
|
||||
int s = splhigh(); /* Disable interrupts. */
|
||||
/* uart0_active is for avoiding LPM3 when still sending or receiving */
|
||||
if(process_nevents() != 0 || uart0_active()) {
|
||||
splx(s); /* Re-enable interrupts. */
|
||||
} else {
|
||||
static unsigned long irq_energest = 0;
|
||||
|
||||
#if DCOSYNCH_CONF_ENABLED
|
||||
/* before going down to sleep possibly do some management */
|
||||
if(timer_expired(&mgt_timer)) {
|
||||
timer_reset(&mgt_timer);
|
||||
msp430_sync_dco();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Re-enable interrupts and go to sleep atomically. */
|
||||
ENERGEST_SWITCH(ENERGEST_TYPE_CPU, ENERGEST_TYPE_LPM);
|
||||
/* We only want to measure the processing done in IRQs when we
|
||||
are asleep, so we discard the processing time done when we
|
||||
were awake. */
|
||||
energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);
|
||||
watchdog_stop();
|
||||
_BIS_SR(GIE | SCG0 | SCG1 | CPUOFF); /* LPM3 sleep. This
|
||||
statement will block
|
||||
until the CPU is
|
||||
woken up by an
|
||||
interrupt that sets
|
||||
the wake up flag. */
|
||||
|
||||
/* We get the current processing time for interrupts that was
|
||||
done during the LPM and store it for next time around. */
|
||||
dint();
|
||||
irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
|
||||
eint();
|
||||
watchdog_start();
|
||||
ENERGEST_SWITCH(ENERGEST_TYPE_LPM, ENERGEST_TYPE_CPU);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if LOG_CONF_ENABLED
|
||||
void
|
||||
log_message(char *m1, char *m2)
|
||||
{
|
||||
printf("%s%s\n", m1, m2);
|
||||
}
|
||||
#endif /* LOG_CONF_ENABLED */
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Author: Enric M. Calvo <ecalvo@zolertia.com> based on previous work by
|
||||
* Niclas Finne <nfi@sics.se>, Joakim Eriksson <joakime@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
|
||||
void
|
||||
init_platform(void)
|
||||
{
|
||||
process_start(&sensors_process, NULL);
|
||||
}
|
|
@ -1,414 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2016, Zolertia <http://www.zolertia.com>
|
||||
* 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
|
||||
* Device drivers for adxl345 accelerometer in Zolertia Z1.
|
||||
* \author
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
* Enric M. Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "adxl345.h"
|
||||
#include "cc2420.h"
|
||||
#include "i2cmaster.h"
|
||||
#include "isr_compat.h"
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t enabled;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Callback pointers when interrupt occurs */
|
||||
void (*accm_int1_cb)(uint8_t reg);
|
||||
void (*accm_int2_cb)(uint8_t reg);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Bitmasks for the interrupts */
|
||||
static uint16_t int1_mask = 0, int2_mask = 0;
|
||||
|
||||
/* Default values for adxl345 at startup.
|
||||
* This will be sent to the adxl345 in a
|
||||
* stream at init to set it up in a default state
|
||||
*/
|
||||
|
||||
static uint8_t adxl345_default_settings[] = {
|
||||
/* Note, as the two first two bulks are to be written in a stream, they contain
|
||||
* the register address as first byte in that section.
|
||||
* 0--14 are in one stream, start at ADXL345_THRESH_TAP
|
||||
*/
|
||||
/* XXX NB Register address, not register value!! */
|
||||
ADXL345_THRESH_TAP,
|
||||
ADXL345_THRESH_TAP_DEFAULT,
|
||||
ADXL345_OFSX_DEFAULT,
|
||||
ADXL345_OFSY_DEFAULT,
|
||||
ADXL345_OFSZ_DEFAULT,
|
||||
ADXL345_DUR_DEFAULT,
|
||||
ADXL345_LATENT_DEFAULT,
|
||||
ADXL345_WINDOW_DEFAULT,
|
||||
ADXL345_THRESH_ACT_DEFAULT,
|
||||
ADXL345_THRESH_INACT_DEFAULT,
|
||||
ADXL345_TIME_INACT_DEFAULT,
|
||||
ADXL345_ACT_INACT_CTL_DEFAULT,
|
||||
ADXL345_THRESH_FF_DEFAULT,
|
||||
ADXL345_TIME_FF_DEFAULT,
|
||||
ADXL345_TAP_AXES_DEFAULT,
|
||||
|
||||
/* 15--19 start at ADXL345_BW_RATE */
|
||||
/* XXX NB Register address, not register value!! */
|
||||
ADXL345_BW_RATE,
|
||||
ADXL345_BW_RATE_DEFAULT,
|
||||
ADXL345_POWER_CTL_DEFAULT,
|
||||
ADXL345_INT_ENABLE_DEFAULT,
|
||||
ADXL345_INT_MAP_DEFAULT,
|
||||
|
||||
/* These two: 20, 21 write separately */
|
||||
ADXL345_DATA_FORMAT_DEFAULT,
|
||||
ADXL345_FIFO_CTL_DEFAULT
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(accmeter_process, "Accelerometer process");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
accm_write_reg(uint8_t reg, uint8_t val)
|
||||
{
|
||||
uint8_t tx_buf[] = {reg, val};
|
||||
|
||||
i2c_transmitinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
PRINTF("ADXL345: I2C Ready to TX\n");
|
||||
|
||||
i2c_transmit_n(2, tx_buf);
|
||||
while (i2c_busy());
|
||||
PRINTF("ADXL345: WRITE_REG 0x%02X @ reg 0x%02X\n", val, reg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* First byte in stream must be the register address to begin writing to.
|
||||
* The data is then written from second byte and increasing.
|
||||
*/
|
||||
static void
|
||||
accm_write_stream(uint8_t len, uint8_t *data)
|
||||
{
|
||||
i2c_transmitinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
PRINTF("ADXL345: I2C Ready to TX(stream)\n");
|
||||
|
||||
i2c_transmit_n(len, data); // start tx and send conf reg
|
||||
while (i2c_busy());
|
||||
PRINTF("ADXL345: WRITE_STR %u B to 0x%02X\n", len, data[0]);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
accm_read_reg(uint8_t reg)
|
||||
{
|
||||
uint8_t retVal = 0;
|
||||
uint8_t rtx = reg;
|
||||
PRINTF("ADXL345: READ_REG 0x%02X\n", reg);
|
||||
|
||||
/* transmit the register to read */
|
||||
i2c_transmitinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while (i2c_busy());
|
||||
|
||||
/* receive the data */
|
||||
i2c_receiveinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
i2c_receive_n(1, &retVal);
|
||||
while (i2c_busy());
|
||||
|
||||
return retVal;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
accm_read_stream(uint8_t reg, uint8_t len, uint8_t *whereto)
|
||||
{
|
||||
uint8_t rtx = reg;
|
||||
PRINTF("ADXL345: READ_STR %u B from 0x%02X\n", len, reg);
|
||||
|
||||
/* transmit the register to start reading from */
|
||||
i2c_transmitinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while (i2c_busy());
|
||||
|
||||
/* receive the data */
|
||||
i2c_receiveinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
i2c_receive_n(len, whereto);
|
||||
while (i2c_busy());
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Read an axis of the accelerometer (x, y or z). Return value is a signed
|
||||
* 10 bit int.
|
||||
* The resolution of the acceleration measurement can be increased up to 13 bit,
|
||||
* but will change the data format of this read out. Refer to the data sheet if
|
||||
* so is wanted/needed.
|
||||
*/
|
||||
int16_t
|
||||
accm_read_axis(enum ADXL345_AXIS axis)
|
||||
{
|
||||
int16_t rd = 0;
|
||||
uint8_t tmp[2];
|
||||
if(axis > Z_AXIS){
|
||||
return 0;
|
||||
}
|
||||
accm_read_stream(ADXL345_DATAX0 + axis, 2, &tmp[0]);
|
||||
rd = (int16_t)(tmp[0] | (tmp[1]<<8));
|
||||
return rd;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
accm_set_grange(uint8_t grange)
|
||||
{
|
||||
uint8_t tempreg = 0;
|
||||
|
||||
if(grange > ADXL345_RANGE_16G) {
|
||||
PRINTF("ADXL345: grange invalid: %u\n", grange);
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
if(!enabled) {
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
/* Keep the previous contents of the register, zero out the last two bits */
|
||||
tempreg = (accm_read_reg(ADXL345_DATA_FORMAT) & 0xFC);
|
||||
tempreg |= grange;
|
||||
accm_write_reg(ADXL345_DATA_FORMAT, tempreg);
|
||||
return ADXL345_SUCCESS;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
accm_init(void)
|
||||
{
|
||||
PRINTF("ADXL345: init\n");
|
||||
accm_int1_cb = NULL;
|
||||
accm_int2_cb = NULL;
|
||||
|
||||
/* Set up ports and pins for interrups. */
|
||||
ADXL345_DIR &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
ADXL345_SEL &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
ADXL345_SEL2 &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
|
||||
/* Set up ports and pins for I2C communication */
|
||||
i2c_enable();
|
||||
|
||||
/* set default register values. */
|
||||
accm_write_stream(15, &adxl345_default_settings[0]);
|
||||
accm_write_stream(5, &adxl345_default_settings[15]);
|
||||
accm_write_reg(ADXL345_DATA_FORMAT, adxl345_default_settings[20]);
|
||||
accm_write_reg(ADXL345_FIFO_CTL, adxl345_default_settings[21]);
|
||||
|
||||
process_start(&accmeter_process, NULL);
|
||||
|
||||
/* Enable msp430 interrupts on the two interrupt pins. */
|
||||
dint();
|
||||
/* low to high transition interrupts */
|
||||
ADXL345_IES &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
/* enable interrupts */
|
||||
ADXL345_IE |= (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
eint();
|
||||
|
||||
enabled = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
accm_stop(void)
|
||||
{
|
||||
dint();
|
||||
ADXL345_IE &= ~(ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
accm_write_reg(ADXL345_INT_ENABLE, ~(int1_mask | int2_mask));
|
||||
accm_write_reg(ADXL345_INT_MAP, ~int2_mask);
|
||||
eint();
|
||||
enabled = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
accm_set_irq(uint8_t int1, uint8_t int2)
|
||||
{
|
||||
if(!enabled) {
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
/* Set the corresponding interrupt mapping to INT1 or INT2 */
|
||||
PRINTF("ADXL345: IRQs set to INT1: 0x%02X IRQ2: 0x%02X\n", int1, int2);
|
||||
|
||||
int1_mask = int1;
|
||||
int2_mask = int2;
|
||||
|
||||
accm_write_reg(ADXL345_INT_ENABLE, (int1 | int2));
|
||||
/* int1 bits are zeroes in the map register so this is for both ints */
|
||||
accm_write_reg(ADXL345_INT_MAP, int2);
|
||||
return ADXL345_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Invoked after an interrupt happened. Reads the interrupt source reg at the
|
||||
* accelerometer, which resets the interrupts, and invokes the corresponding
|
||||
* callback. It passes the source register value so the callback can determine
|
||||
* what interrupt happened, if several interrupts are mapped to the same pin.
|
||||
*/
|
||||
static void
|
||||
poll_handler(void)
|
||||
{
|
||||
uint8_t ireg = 0;
|
||||
ireg = accm_read_reg(ADXL345_INT_SOURCE);
|
||||
|
||||
/* Invoke callbacks for the corresponding interrupts */
|
||||
if(ireg & int1_mask){
|
||||
if(accm_int1_cb != NULL){
|
||||
PRINTF("ADXL345: INT1 cb invoked\n");
|
||||
accm_int1_cb(ireg);
|
||||
}
|
||||
} else if(ireg & int2_mask){
|
||||
if(accm_int2_cb != NULL){
|
||||
PRINTF("ADXL345: INT2 cb invoked\n");
|
||||
accm_int2_cb(ireg);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* This process is sleeping until an interrupt from the accelerometer occurs,
|
||||
* which polls this process from the interrupt service routine. */
|
||||
PROCESS_THREAD(accmeter_process, ev, data)
|
||||
{
|
||||
PROCESS_POLLHANDLER(poll_handler());
|
||||
PROCESS_EXITHANDLER();
|
||||
PROCESS_BEGIN();
|
||||
while(1){
|
||||
PROCESS_WAIT_EVENT_UNTIL(0);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* This interrupt vector is shared with the interrupts from CC2420, so that
|
||||
* was moved here
|
||||
*/
|
||||
static struct timer suppressTimer1, suppressTimer2;
|
||||
|
||||
ISR(PORT1, port1_isr)
|
||||
{
|
||||
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
||||
|
||||
/* ADXL345_IFG.x goes high when interrupt occurs, use to check what
|
||||
* interrupted
|
||||
*/
|
||||
if((ADXL345_IFG & ADXL345_INT1_PIN) && !(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){
|
||||
/* Check if this should be suppressed or not */
|
||||
if(timer_expired(&suppressTimer1)) {
|
||||
timer_set(&suppressTimer1, SUPPRESS_TIME_INT1);
|
||||
ADXL345_IFG &= ~ADXL345_INT1_PIN; // clear interrupt flag
|
||||
process_poll(&accmeter_process);
|
||||
LPM4_EXIT;
|
||||
}
|
||||
} else if((ADXL345_IFG & ADXL345_INT2_PIN) &&
|
||||
!(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){
|
||||
/* Check if this should be suppressed or not */
|
||||
if(timer_expired(&suppressTimer2)) {
|
||||
timer_set(&suppressTimer2, SUPPRESS_TIME_INT2);
|
||||
/* clear interrupt flag */
|
||||
ADXL345_IFG &= ~ADXL345_INT2_PIN;
|
||||
process_poll(&accmeter_process);
|
||||
LPM4_EXIT;
|
||||
}
|
||||
} else {
|
||||
/* CC2420 interrupt */
|
||||
if(cc2420_interrupt()) {
|
||||
LPM4_EXIT;
|
||||
}
|
||||
}
|
||||
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
if(type != SENSORS_ACTIVE) {
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
if(value) {
|
||||
accm_init();
|
||||
} else {
|
||||
accm_stop();
|
||||
}
|
||||
enabled = value;
|
||||
return ADXL345_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return enabled;
|
||||
}
|
||||
return ADXL345_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
if(!enabled) {
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
if((type != X_AXIS) && (type != Y_AXIS) && (type != Z_AXIS)) {
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case X_AXIS:
|
||||
return accm_read_axis(X_AXIS);
|
||||
case Y_AXIS:
|
||||
return accm_read_axis(Y_AXIS);
|
||||
case Z_AXIS:
|
||||
return accm_read_axis(Z_AXIS);
|
||||
default:
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(adxl345, ADXL345_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,246 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2016, Zolertia <http://www.zolertia.com>
|
||||
* 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
|
||||
* Device drivers header file for adxl345 accelerometer in Zolertia Z1.
|
||||
* \author
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
* Enric Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef ADXL345_H_
|
||||
#define ADXL345_H_
|
||||
#include <stdio.h>
|
||||
#include "dev/i2cmaster.h"
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Used in accm_read_axis(), eg accm_read_axis(X_AXIS) */
|
||||
enum ADXL345_AXIS {
|
||||
X_AXIS = 0,
|
||||
Y_AXIS = 2,
|
||||
Z_AXIS = 4,
|
||||
};
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Init the accelerometer: ports, pins, registers, interrupts (none enabled),
|
||||
* I2C, default threshold values etc.
|
||||
*/
|
||||
void accm_init(void);
|
||||
|
||||
/* Read an axis of the accelerometer (x, y or z). Return value is a signed 10
|
||||
* bit int.
|
||||
* The resolution of the acceleration measurement can be increased up to 13 bit,
|
||||
* but will change the data format of this read out. Refer to the data sheet if
|
||||
* so is wanted/needed.
|
||||
*/
|
||||
int16_t accm_read_axis(enum ADXL345_AXIS axis);
|
||||
|
||||
/* Sets the g-range, ie the range the accelerometer measures (ie 2g means -2 to
|
||||
* +2 g on every axis). Possible values:
|
||||
* - ADXL345_RANGE_2G
|
||||
* - ADXL345_RANGE_4G
|
||||
* - ADXL345_RANGE_8G
|
||||
* - ADXL345_RANGE_16G
|
||||
*/
|
||||
int accm_set_grange(uint8_t grange);
|
||||
|
||||
/* Map interrupt (FF, tap, dbltap etc) to interrupt pin (IRQ_INT1, IRQ_INT2).
|
||||
* This must come after accm_init() as the registers will otherwise be
|
||||
* overwritten.
|
||||
*/
|
||||
int accm_set_irq(uint8_t int1, uint8_t int2);
|
||||
|
||||
/* Macros for setting the pointers to callback functions from the interrupts.
|
||||
* The function will be called with an uint8_t as parameter, containing the
|
||||
* interrupt flag register from the ADXL345. That way, several interrupts can be
|
||||
* mapped to the same pin and be read
|
||||
*/
|
||||
#define ACCM_REGISTER_INT1_CB(ptr) accm_int1_cb = ptr;
|
||||
#define ACCM_REGISTER_INT2_CB(ptr) accm_int2_cb = ptr;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Application definitions, change if required by application. */
|
||||
|
||||
/* Time after an interrupt that subsequent interrupts are suppressed. Should
|
||||
* later be turned into one specific time per type of interrupt (tap, freefall.
|
||||
* etc)
|
||||
*/
|
||||
#define SUPPRESS_TIME_INT1 CLOCK_SECOND/4
|
||||
#define SUPPRESS_TIME_INT2 CLOCK_SECOND/4
|
||||
|
||||
/* Suggested defaults according to the data sheet etc */
|
||||
#define ADXL345_THRESH_TAP_DEFAULT 0x48 /* 4.5g (0x30 == 3.0g) */
|
||||
#define ADXL345_OFSX_DEFAULT 0x00 /* for calibration only */
|
||||
#define ADXL345_OFSY_DEFAULT 0x00
|
||||
#define ADXL345_OFSZ_DEFAULT 0x00
|
||||
#define ADXL345_DUR_DEFAULT 0x20 /* 20 ms (datasheet: 10ms++) */
|
||||
#define ADXL345_LATENT_DEFAULT 0x50 /* 100 ms (datasheet: 20ms++) */
|
||||
#define ADXL345_WINDOW_DEFAULT 0xFF /* 320 ms (datasheet: 80ms++) */
|
||||
#define ADXL345_THRESH_ACT_DEFAULT 0x15 /* 1.3g (62.5 mg/LSB) */
|
||||
#define ADXL345_THRESH_INACT_DEFAULT 0x08 /* 0.5g (62.5 mg/LSB) */
|
||||
#define ADXL345_TIME_INACT_DEFAULT 0x02 /* 2 s (1 s/LSB) */
|
||||
#define ADXL345_ACT_INACT_CTL_DEFAULT 0xFF /* all axis, ac-coupled */
|
||||
#define ADXL345_THRESH_FF_DEFAULT 0x09 /* 563 mg */
|
||||
#define ADXL345_TIME_FF_DEFAULT 0x20 /* 60 ms */
|
||||
#define ADXL345_TAP_AXES_DEFAULT 0x07 /* all axis, no suppression */
|
||||
|
||||
#define ADXL345_BW_RATE_DEFAULT (0x00 | ADXL345_SRATE_100) /* 100 Hz */
|
||||
/* link bit set, no autosleep, start normal measuring */
|
||||
#define ADXL345_POWER_CTL_DEFAULT 0x28
|
||||
#define ADXL345_INT_ENABLE_DEFAULT 0x00 /* no interrupts enabled */
|
||||
#define ADXL345_INT_MAP_DEFAULT 0x00 /* all mapped to int_1 */
|
||||
|
||||
/* XXX NB: In the data format register, data format of axis readings is chosen
|
||||
* between left or right justify. This affects the position of the MSB/LSB and is
|
||||
* different depending on g-range and resolution. If changed, make sure this is
|
||||
* reflected in the _read_axis() function. Also, the resolution can be increased
|
||||
* from 10 bit to at most 13 bit, but this also changes position of MSB etc on data
|
||||
* format so check this in read_axis() too.
|
||||
*/
|
||||
/* right-justify, 2g, 10-bit mode, int is active high */
|
||||
#define ADXL345_DATA_FORMAT_DEFAULT (0x00 | ADXL345_RANGE_2G)
|
||||
#define ADXL345_FIFO_CTL_DEFAULT 0x00 /* FIFO bypass mode */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Reference definitions, should not be changed */
|
||||
/* adxl345 slave address */
|
||||
#define ADXL345_ADDR 0x53
|
||||
|
||||
/* ADXL345 registers */
|
||||
#define ADXL345_DEVID 0x00
|
||||
/* registers 0x01 to 0x1C are reserved, do not access */
|
||||
#define ADXL345_THRESH_TAP 0x1D
|
||||
#define ADXL345_OFSX 0x1E
|
||||
#define ADXL345_OFSY 0x1F
|
||||
#define ADXL345_OFSZ 0x20
|
||||
#define ADXL345_DUR 0x21
|
||||
#define ADXL345_LATENT 0x22
|
||||
#define ADXL345_WINDOW 0x23
|
||||
#define ADXL345_THRESH_ACT 0x24
|
||||
#define ADXL345_THRESH_INACT 0x25
|
||||
#define ADXL345_TIME_INACT 0x26
|
||||
#define ADXL345_ACT_INACT_CTL 0x27
|
||||
#define ADXL345_THRESH_FF 0x28
|
||||
#define ADXL345_TIME_FF 0x29
|
||||
#define ADXL345_TAP_AXES 0x2A
|
||||
#define ADXL345_ACT_TAP_STATUS 0x2B
|
||||
#define ADXL345_BW_RATE 0x2C
|
||||
#define ADXL345_POWER_CTL 0x2D
|
||||
#define ADXL345_INT_ENABLE 0x2E
|
||||
#define ADXL345_INT_MAP 0x2F
|
||||
#define ADXL345_INT_SOURCE 0x30
|
||||
#define ADXL345_DATA_FORMAT 0x31
|
||||
#define ADXL345_DATAX0 0x32 /* read only, LSByte X, two's complement */
|
||||
#define ADXL345_DATAX1 0x33 /* read only, MSByte X */
|
||||
#define ADXL345_DATAY0 0x34 /* read only, LSByte Y */
|
||||
#define ADXL345_DATAY1 0x35 /* read only, MSByte X */
|
||||
#define ADXL345_DATAZ0 0x36 /* read only, LSByte Z */
|
||||
#define ADXL345_DATAZ1 0x37 /* read only, MSByte X */
|
||||
#define ADXL345_FIFO_CTL 0x38
|
||||
#define ADXL345_FIFO_STATUS 0x39 /* read only */
|
||||
|
||||
/* ADXL345 interrupts */
|
||||
#define ADXL345_INT_DISABLE 0X00 /* used for disabling interrupts */
|
||||
#define ADXL345_INT_OVERRUN 0X01
|
||||
#define ADXL345_INT_WATERMARK 0X02
|
||||
#define ADXL345_INT_FREEFALL 0X04
|
||||
#define ADXL345_INT_INACTIVITY 0X08
|
||||
#define ADXL345_INT_ACTIVITY 0X10
|
||||
#define ADXL345_INT_DOUBLETAP 0X20
|
||||
#define ADXL345_INT_TAP 0X40
|
||||
#define ADXL345_INT_DATAREADY 0X80
|
||||
|
||||
/* Accelerometer hardware ports, pins and registers on the msp430 µC */
|
||||
#define ADXL345_DIR P1DIR
|
||||
#define ADXL345_PIN P1PIN
|
||||
#define ADXL345_REN P1REN
|
||||
#define ADXL345_SEL P1SEL
|
||||
#define ADXL345_SEL2 P1SEL2
|
||||
#define ADXL345_INT1_PIN (1<<6) /* P1.6 */
|
||||
#define ADXL345_INT2_PIN (1<<7) /* P1.7 */
|
||||
#define ADXL345_IES P1IES
|
||||
#define ADXL345_IE P1IE
|
||||
#define ADXL345_IFG P1IFG
|
||||
#define ADXL345_VECTOR PORT1_VECTOR
|
||||
|
||||
/* g-range for DATA_FORMAT register */
|
||||
#define ADXL345_RANGE_2G 0x00
|
||||
#define ADXL345_RANGE_4G 0x01
|
||||
#define ADXL345_RANGE_8G 0x02
|
||||
#define ADXL345_RANGE_16G 0x03
|
||||
|
||||
|
||||
/* The adxl345 has programmable sample rates, but unexpected results may occur
|
||||
* if the wrong rate and I2C bus speed is used (see datasheet p 17). Sample
|
||||
* rates in Hz. This setting does not change the internal sampling rate, just
|
||||
* how often it is piped to the output registers (ie the interrupt features use
|
||||
* the full sample rate internally).
|
||||
* Example use:
|
||||
* adxl345_set_reg(ADXL345_BW_RATE, ((_ADXL345_STATUS & LOW_POWER)
|
||||
* | ADXL345_SRATE_50));
|
||||
*/
|
||||
|
||||
/* XXX NB don't use at all as I2C data rate<= 400kHz */
|
||||
#define ADXL345_SRATE_3200 0x0F
|
||||
/* XXX NB don't use at all as I2C data rate<= 400kHz */
|
||||
#define ADXL345_SRATE_1600 0x0E
|
||||
#define ADXL345_SRATE_800 0x0D /* when I2C data rate == 400 kHz */
|
||||
#define ADXL345_SRATE_400 0x0C /* when I2C data rate == 400 kHz */
|
||||
#define ADXL345_SRATE_200 0x0B /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_100 0x0A /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_50 0x09 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_25 0x08 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_12_5 0x07 /* 12.5 Hz, when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_6_25 0x06 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_3_13 0x05 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_1_56 0x04 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_0_78 0x03 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_0_39 0x02 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_0_20 0x01 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_0_10 0x00 /* 0.10 Hz, when I2C data rate >= 100 kHz */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Callback pointers for the interrupts */
|
||||
extern void (*accm_int1_cb)(uint8_t reg);
|
||||
extern void (*accm_int2_cb)(uint8_t reg);
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define ACCM_INT1 0x01
|
||||
#define ACCM_INT2 0x02
|
||||
#define ADXL345_SUCCESS 0x00
|
||||
#define ADXL345_ERROR (-1)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define ADXL345_SENSOR "ADXL345 sensor"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
extern const struct sensors_sensor adxl345;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef ADXL345_H_ */
|
|
@ -1,67 +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.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
|
||||
* Created : 2005-11-01
|
||||
* Updated : $Date: 2010/08/25 19:30:52 $
|
||||
* $Revision: 1.11 $
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "dev/battery-sensor.h"
|
||||
#include "dev/sky-sensors.h"
|
||||
|
||||
/* Configure ADC12_2 to sample channel 11 (voltage) and use */
|
||||
/* the Vref+ as reference (SREF_1) since it is a stable reference */
|
||||
#define INPUT_CHANNEL (1 << INCH_11)
|
||||
#define INPUT_REFERENCE SREF_1
|
||||
#define BATTERY_MEM ADC12MEM11
|
||||
|
||||
const struct sensors_sensor battery_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return BATTERY_MEM;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status);
|
|
@ -1,104 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/hwconf.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "isr_compat.h"
|
||||
|
||||
const struct sensors_sensor button_sensor;
|
||||
|
||||
static struct timer debouncetimer;
|
||||
static int status(int type);
|
||||
|
||||
HWCONF_PIN(BUTTON, 2, 5);
|
||||
HWCONF_IRQ(BUTTON, 2, 5);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(PORT2, irq_p2)
|
||||
{
|
||||
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
||||
|
||||
if(BUTTON_CHECK_IRQ()) {
|
||||
if(timer_expired(&debouncetimer)) {
|
||||
timer_set(&debouncetimer, CLOCK_SECOND / 4);
|
||||
sensors_changed(&button_sensor);
|
||||
LPM4_EXIT;
|
||||
}
|
||||
}
|
||||
P2IFG = 0x00;
|
||||
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return BUTTON_READ() || !timer_expired(&debouncetimer);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
switch (type) {
|
||||
case SENSORS_ACTIVE:
|
||||
if (c) {
|
||||
if(!status(SENSORS_ACTIVE)) {
|
||||
timer_set(&debouncetimer, 0);
|
||||
BUTTON_IRQ_EDGE_SELECTD();
|
||||
|
||||
BUTTON_SELECT();
|
||||
BUTTON_MAKE_INPUT();
|
||||
|
||||
BUTTON_ENABLE_IRQ();
|
||||
}
|
||||
} else {
|
||||
BUTTON_DISABLE_IRQ();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return BUTTON_IRQ_ENABLED();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
|
||||
value, configure, status);
|
|
@ -1,78 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "dev/spi.h"
|
||||
#include "cc2420.h"
|
||||
#include "isr_compat.h"
|
||||
|
||||
#ifdef CC2420_CONF_SFD_TIMESTAMPS
|
||||
#define CONF_SFD_TIMESTAMPS CC2420_CONF_SFD_TIMESTAMPS
|
||||
#endif /* CC2420_CONF_SFD_TIMESTAMPS */
|
||||
|
||||
#ifndef CONF_SFD_TIMESTAMPS
|
||||
#define CONF_SFD_TIMESTAMPS 0
|
||||
#endif /* CONF_SFD_TIMESTAMPS */
|
||||
|
||||
#ifdef CONF_SFD_TIMESTAMPS
|
||||
#include "cc2420-arch-sfd.h"
|
||||
#endif /* CONF_SFD_TIMESTAMPS */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
// this is now handled in the ADXL345 accelerometer code as it uses irq on port1 too.
|
||||
ISR(CC2420_IRQ, cc24240_port1_interrupt)
|
||||
{
|
||||
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
||||
if(cc2420_interrupt()) {
|
||||
LPM4_EXIT;
|
||||
}
|
||||
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
||||
}
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
cc2420_arch_init(void)
|
||||
{
|
||||
spi_init();
|
||||
|
||||
/* all input by default, set these as output */
|
||||
CC2420_CSN_PORT(DIR) |= BV(CC2420_CSN_PIN);
|
||||
CC2420_VREG_PORT(DIR) |= BV(CC2420_VREG_PIN);
|
||||
CC2420_RESET_PORT(DIR) |= BV(CC2420_RESET_PIN);
|
||||
|
||||
#if CONF_SFD_TIMESTAMPS
|
||||
cc2420_arch_sfd_init();
|
||||
#endif /* CONF_SFD_TIMESTAMPS */
|
||||
|
||||
CC2420_SPI_DISABLE(); /* Unselect radio. */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,228 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* I2C communication device drivers for Zolertia Z1 sensor node.
|
||||
* \author
|
||||
* Enric M. Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
*/
|
||||
|
||||
#include "i2cmaster.h"
|
||||
#include "isr_compat.h"
|
||||
|
||||
signed char tx_byte_ctr, rx_byte_ctr;
|
||||
unsigned char rx_buf[2];
|
||||
unsigned char *tx_buf_ptr;
|
||||
unsigned char *rx_buf_ptr;
|
||||
unsigned char receive_data;
|
||||
unsigned char transmit_data1;
|
||||
unsigned char transmit_data2;
|
||||
unsigned char prescale_lsb = I2C_PRESC_Z1_LSB;
|
||||
unsigned char prescale_msb = I2C_PRESC_Z1_MSB;
|
||||
volatile unsigned int i; /* volatile to prevent optimization */
|
||||
|
||||
/* ------------------------------------------------------------------------------
|
||||
* Change the data rate prior initializing transmission or reception
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
i2c_setrate(uint8_t p_lsb, uint8_t p_msb)
|
||||
{
|
||||
prescale_lsb = p_lsb;
|
||||
prescale_lsb = p_msb;
|
||||
}
|
||||
/* ------------------------------------------------------------------------------
|
||||
* This function initializes the USCI module for master-receive operation.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
i2c_receiveinit(uint8_t slave_address)
|
||||
{
|
||||
UCB1CTL1 = UCSWRST; /* Enable SW reset */
|
||||
UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; /* I2C Master, synchronous mode */
|
||||
UCB1CTL1 = UCSSEL_2 | UCSWRST; /* Use SMCLK, keep SW reset */
|
||||
UCB1BR0 = prescale_lsb; /* prescaler (default 400 kHz) */
|
||||
UCB1BR1 = prescale_msb;
|
||||
UCB1I2CSA = slave_address; /* set slave address */
|
||||
UCB1CTL1 &= ~UCTR; /* I2C Receiver */
|
||||
UCB1CTL1 &= ~UCSWRST; /* Clear SW reset, resume operation */
|
||||
UCB1I2CIE = UCNACKIE;
|
||||
#if I2C_RX_WITH_INTERRUPT
|
||||
UC1IE = UCB1RXIE; /* Enable RX interrupt if desired */
|
||||
#endif
|
||||
}
|
||||
/* ------------------------------------------------------------------------------
|
||||
* Initializes USCI for master-transmit operation.
|
||||
* ------------------------------------------------------------------------------ */
|
||||
void
|
||||
i2c_transmitinit(uint8_t slave_address)
|
||||
{
|
||||
UCB1CTL1 |= UCSWRST; /* Enable SW reset */
|
||||
UCB1CTL0 |= (UCMST | UCMODE_3 | UCSYNC); /* I2C Master, synchronous mode */
|
||||
UCB1CTL1 = UCSSEL_2 + UCSWRST; /* Use SMCLK, keep SW reset */
|
||||
UCB1BR0 = prescale_lsb; /* prescaler (default 400 kHz) */
|
||||
UCB1BR1 = prescale_msb;
|
||||
UCB1I2CSA = slave_address; /* Set slave address */
|
||||
UCB1CTL1 &= ~UCSWRST; /* Clear SW reset, resume operation */
|
||||
UCB1I2CIE = UCNACKIE;
|
||||
UC1IE = UCB1TXIE; /* Enable TX ready interrupt */
|
||||
}
|
||||
/* ------------------------------------------------------------------------------
|
||||
* This function is used to start an I2C communication in master-receiver mode WITHOUT INTERRUPTS
|
||||
* for more than 1 byte
|
||||
* ------------------------------------------------------------------------------ */
|
||||
static volatile uint8_t rx_byte_tot = 0;
|
||||
uint8_t
|
||||
i2c_receive_n(uint8_t byte_ctr, uint8_t *rx_buf)
|
||||
{
|
||||
|
||||
rx_byte_tot = byte_ctr;
|
||||
rx_byte_ctr = byte_ctr;
|
||||
rx_buf_ptr = rx_buf;
|
||||
|
||||
while((UCB1CTL1 & UCTXSTT) || (UCB1STAT & UCNACKIFG)) /* Slave acks address or not? */
|
||||
PRINTFDEBUG("____ UCTXSTT not clear OR NACK received\n");
|
||||
|
||||
#if I2C_RX_WITH_INTERRUPT
|
||||
PRINTFDEBUG(" RX Interrupts: YES \n");
|
||||
|
||||
/* SPECIAL-CASE: Stop condition must be sent while receiving the 1st byte for 1-byte only read operations */
|
||||
if(rx_byte_tot == 1) { /* See page 537 of slau144e.pdf */
|
||||
dint();
|
||||
UCB1CTL1 |= UCTXSTT; /* I2C start condition */
|
||||
while(UCB1CTL1 & UCTXSTT) /* Waiting for Start bit to clear */
|
||||
PRINTFDEBUG("____ STT clear wait\n");
|
||||
UCB1CTL1 |= UCTXSTP; /* I2C stop condition */
|
||||
eint();
|
||||
} else { /* all other cases */
|
||||
UCB1CTL1 |= UCTXSTT; /* I2C start condition */
|
||||
}
|
||||
return 0;
|
||||
|
||||
#else
|
||||
uint8_t n_received = 0;
|
||||
|
||||
PRINTFDEBUG(" RX Interrupts: NO \n");
|
||||
|
||||
UCB1CTL1 |= UCTXSTT; /* I2C start condition */
|
||||
|
||||
while(rx_byte_ctr > 0) {
|
||||
if(UC1IFG & UCB1RXIFG) { /* Waiting for Data */
|
||||
rx_buf[rx_byte_tot - rx_byte_ctr] = UCB1RXBUF;
|
||||
rx_byte_ctr--;
|
||||
UC1IFG &= ~UCB1RXIFG; /* Clear USCI_B1 RX int flag */
|
||||
n_received++;
|
||||
}
|
||||
}
|
||||
UCB1CTL1 |= UCTXSTP; /* I2C stop condition */
|
||||
return n_received;
|
||||
#endif
|
||||
}
|
||||
/* ------------------------------------------------------------------------------
|
||||
* This function is used to check if there is communication in progress.
|
||||
* ------------------------------------------------------------------------------ */
|
||||
uint8_t
|
||||
i2c_busy(void)
|
||||
{
|
||||
return UCB1STAT & UCBBUSY;
|
||||
}
|
||||
/*----------------------------------------------------------------------------
|
||||
* Setup ports and pins for I2C use.
|
||||
* ------------------------------------------------------------------------------ */
|
||||
|
||||
void
|
||||
i2c_enable(void)
|
||||
{
|
||||
I2C_PxSEL |= (I2C_SDA | I2C_SCL); /* Secondary function (USCI) selected */
|
||||
I2C_PxSEL2 |= (I2C_SDA | I2C_SCL); /* Secondary function (USCI) selected */
|
||||
I2C_PxDIR |= I2C_SCL; /* SCL is output (not needed?) */
|
||||
I2C_PxDIR &= ~I2C_SDA; /* SDA is input (not needed?) */
|
||||
I2C_PxREN |= (I2C_SDA | I2C_SCL); /* Activate internal pull-up/-down resistors */
|
||||
I2C_PxOUT |= (I2C_SDA | I2C_SCL); /* Select pull-up resistors */
|
||||
}
|
||||
void
|
||||
i2c_disable(void)
|
||||
{
|
||||
I2C_PxSEL &= ~(I2C_SDA | I2C_SCL); /* GPIO function selected */
|
||||
I2C_PxSEL2 &= ~(I2C_SDA | I2C_SCL); /* GPIO function selected */
|
||||
I2C_PxREN &= ~(I2C_SDA | I2C_SCL); /* Deactivate internal pull-up/-down resistors */
|
||||
I2C_PxOUT &= ~(I2C_SDA | I2C_SCL); /* Select pull-up resistors */
|
||||
}
|
||||
/* ------------------------------------------------------------------------------
|
||||
* This function is used to start an I2C communication in master-transmit mode.
|
||||
* ------------------------------------------------------------------------------ */
|
||||
static volatile uint8_t tx_byte_tot = 0;
|
||||
void
|
||||
i2c_transmit_n(uint8_t byte_ctr, uint8_t *tx_buf)
|
||||
{
|
||||
tx_byte_tot = byte_ctr;
|
||||
tx_byte_ctr = byte_ctr;
|
||||
tx_buf_ptr = tx_buf;
|
||||
UCB1CTL1 |= UCTR + UCTXSTT; /* I2C TX, start condition */
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
ISR(USCIAB1TX, i2c_tx_interrupt)
|
||||
{
|
||||
/* TX Part */
|
||||
if(UC1IFG & UCB1TXIFG) { /* TX int. condition */
|
||||
if(tx_byte_ctr == 0) {
|
||||
UCB1CTL1 |= UCTXSTP; /* I2C stop condition */
|
||||
UC1IFG &= ~UCB1TXIFG; /* Clear USCI_B1 TX int flag */
|
||||
} else {
|
||||
UCB1TXBUF = tx_buf_ptr[tx_byte_tot - tx_byte_ctr];
|
||||
tx_byte_ctr--;
|
||||
}
|
||||
}
|
||||
/* RX Part */
|
||||
#if I2C_RX_WITH_INTERRUPT
|
||||
else if(UC1IFG & UCB1RXIFG) { /* RX int. condition */
|
||||
rx_buf_ptr[rx_byte_tot - rx_byte_ctr] = UCB1RXBUF;
|
||||
rx_byte_ctr--;
|
||||
if(rx_byte_ctr == 1) { /* stop condition should be set before receiving last byte */
|
||||
/* Only for 1-byte transmissions, STOP is handled in receive_n_int */
|
||||
if(rx_byte_tot != 1) {
|
||||
UCB1CTL1 |= UCTXSTP; /* I2C stop condition */
|
||||
}
|
||||
UC1IFG &= ~UCB1RXIFG; /* Clear USCI_B1 RX int flag. XXX Just in case, check if necessary */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ISR(USCIAB1RX, i2c_rx_interrupt)
|
||||
{
|
||||
if(UCB1STAT & UCNACKIFG) {
|
||||
PRINTFDEBUG("!!! NACK received in RX\n");
|
||||
UCB1CTL1 |= UCTXSTP;
|
||||
UCB1STAT &= ~UCNACKIFG;
|
||||
}
|
||||
}
|
|
@ -1,65 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* I2C communication device driver header file for Zolertia Z1 sensor node.
|
||||
* \author
|
||||
* Enric Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef I2CMASTER_H_
|
||||
#define I2CMASTER_H_
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
void i2c_enable(void);
|
||||
void i2c_disable(void);
|
||||
|
||||
void i2c_receiveinit(uint8_t slave_address);
|
||||
uint8_t i2c_receive_n(uint8_t byte_ctr, uint8_t *rx_buf);
|
||||
|
||||
void i2c_transmitinit(uint8_t slave_address);
|
||||
void i2c_transmit_n(uint8_t byte_ctr, uint8_t *tx_buf);
|
||||
|
||||
uint8_t i2c_busy(void);
|
||||
void i2c_setrate(uint8_t p_lsb, uint8_t p_msb);
|
||||
|
||||
#if 0
|
||||
#include <stdio.h>
|
||||
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTFDEBUG(...)
|
||||
#endif
|
||||
|
||||
#endif /* #ifdef I2CMASTER_H_ */
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2005-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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/sky-sensors.h"
|
||||
#include "dev/light-sensor.h"
|
||||
#include "dev/potentiometer-sensor.h"
|
||||
|
||||
/* Photodiode 1 (P64) on INCH_4 */
|
||||
/* Photodiode 2 (P65) on INCH_5 */
|
||||
//Enric#define INPUT_CHANNEL ((1 << INCH_4) | (1 << INCH_5))
|
||||
#ifndef INPUT_CHANNEL
|
||||
#define INPUT_CHANNEL (1 << INCH_4)
|
||||
#endif
|
||||
|
||||
#ifndef INPUT_REFERENCE
|
||||
#define INPUT_REFERENCE SREF_0
|
||||
#endif
|
||||
|
||||
#ifdef POTENTIOMETER_MEM
|
||||
#define PHOTOSYNTHETIC_MEM POTENTIOMETER_MEM
|
||||
#define TOTAL_SOLAR_MEM POTENTIOMETER_MEM
|
||||
#else
|
||||
#define PHOTOSYNTHETIC_MEM ADC12MEM4
|
||||
#define TOTAL_SOLAR_MEM ADC12MEM4
|
||||
#endif
|
||||
|
||||
|
||||
const struct sensors_sensor light_sensor;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
switch(type) {
|
||||
/* Photosynthetically Active Radiation. */
|
||||
case LIGHT_SENSOR_PHOTOSYNTHETIC:
|
||||
return PHOTOSYNTHETIC_MEM;
|
||||
|
||||
/* Total Solar Radiation. */
|
||||
case LIGHT_SENSOR_TOTAL_SOLAR:
|
||||
return TOTAL_SOLAR_MEM;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(light_sensor, "Light", value, configure, status);
|
|
@ -1,50 +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.
|
||||
*
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
|
||||
* Created : 2010-01-08
|
||||
* Updated : $Date: 2010/01/14 20:23:02 $
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
|
||||
#ifndef LIGHT_SENSOR_H_
|
||||
#define LIGHT_SENSOR_H_
|
||||
|
||||
#include "lib/sensors.h"
|
||||
|
||||
extern const struct sensors_sensor light_sensor;
|
||||
|
||||
#define LIGHT_SENSOR_PHOTOSYNTHETIC 0
|
||||
#define LIGHT_SENSOR_TOTAL_SOLAR 1
|
||||
|
||||
|
||||
#endif /* LIGHT-SENSOR_H_ */
|
|
@ -1,219 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Device drivers for light ziglet sensor in Zolertia Z1.
|
||||
* It is recommended to use with a 100KHz data rate
|
||||
* \author
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "i2cmaster.h"
|
||||
#include "light-ziglet.h"
|
||||
|
||||
#if 0
|
||||
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTFDEBUG(...)
|
||||
#endif
|
||||
|
||||
/* Bitmasks and bit flag variable for keeping track of tmp102 status. */
|
||||
enum TSL2563_STATUSTYPES {
|
||||
/* must be a bit and not more, not using 0x00. */
|
||||
INITED = 0x01,
|
||||
RUNNING = 0x02,
|
||||
STOPPED = 0x04,
|
||||
};
|
||||
|
||||
static enum TSL2563_STATUSTYPES _TSL2563_STATUS = 0x00;
|
||||
|
||||
uint16_t
|
||||
calculateLux(uint16_t *buffer)
|
||||
{
|
||||
uint32_t ch0, ch1 = 0;
|
||||
uint32_t aux = (1 << 14);
|
||||
uint32_t ratio, lratio, tmp = 0;
|
||||
|
||||
ch0 = (buffer[0] * aux) >> 10;
|
||||
ch1 = (buffer[1] * aux) >> 10;
|
||||
|
||||
PRINTFDEBUG("B0 %u, B1 %u\n", buffer[0], buffer[1]);
|
||||
PRINTFDEBUG("ch0 %lu, ch1 %lu\n", ch0, ch1);
|
||||
|
||||
ratio = (ch1 << 10);
|
||||
ratio = ratio / ch0;
|
||||
lratio = (ratio + 1) >> 1;
|
||||
|
||||
PRINTFDEBUG("ratio %lu, lratio %lu\n", ratio, lratio);
|
||||
|
||||
if((lratio >= 0) && (lratio <= K1T)) {
|
||||
tmp = (ch0 * B1T) - (ch1 * M1T);
|
||||
} else if(lratio <= K2T) {
|
||||
tmp = (ch0 * B2T) - (ch1 * M2T);
|
||||
} else if(lratio <= K3T) {
|
||||
tmp = (ch0 * B3T) - (ch1 * M3T);
|
||||
} else if(lratio <= K4T) {
|
||||
tmp = (ch0 * B4T) - (ch1 * M4T);
|
||||
} else if(lratio <= K5T) {
|
||||
tmp = (ch0 * B5T) - (ch1 * M5T);
|
||||
} else if(lratio <= K6T) {
|
||||
tmp = (ch0 * B6T) - (ch1 * M6T);
|
||||
} else if(lratio <= K7T) {
|
||||
tmp = (ch0 * B7T) - (ch1 * M7T);
|
||||
} else if(lratio > K8T) {
|
||||
tmp = (ch0 * B8T) - (ch1 * M8T);
|
||||
}
|
||||
|
||||
if(tmp < 0) {
|
||||
tmp = 0;
|
||||
}
|
||||
|
||||
tmp += (1 << 13);
|
||||
|
||||
PRINTFDEBUG("tmp %lu\n", tmp);
|
||||
|
||||
return tmp >> 14;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Init the light ziglet sensor: ports, pins, registers, interrupts (none enabled), I2C,
|
||||
default threshold values etc. */
|
||||
|
||||
void
|
||||
light_ziglet_init(void)
|
||||
{
|
||||
if(!(_TSL2563_STATUS & INITED)) {
|
||||
PRINTFDEBUG("light ziglet init\n");
|
||||
_TSL2563_STATUS |= INITED;
|
||||
|
||||
/* Set up ports and pins for I2C communication */
|
||||
i2c_enable();
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Write to a 16-bit register.
|
||||
args:
|
||||
reg register to write to
|
||||
val value to write
|
||||
*/
|
||||
|
||||
void
|
||||
tsl2563_write_reg(uint8_t reg, uint16_t val)
|
||||
{
|
||||
uint8_t tx_buf[] = { reg, 0x00, 0x00 };
|
||||
|
||||
tx_buf[1] = (uint8_t)(val >> 8);
|
||||
tx_buf[2] = (uint8_t)(val & 0x00FF);
|
||||
|
||||
i2c_transmitinit(TSL2563_ADDR);
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("I2C Ready to TX\n");
|
||||
|
||||
i2c_transmit_n(3, tx_buf);
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("WRITE_REG 0x%04X @ reg 0x%02X\n", val, reg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Read register.
|
||||
args:
|
||||
reg what register to read
|
||||
returns the value of the read register type uint16_t
|
||||
*/
|
||||
|
||||
uint16_t
|
||||
tsl2563_read_reg(uint8_t reg)
|
||||
{
|
||||
uint16_t readBuf[] = { 0x00, 0x00 };
|
||||
uint8_t buf[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
uint16_t retVal = 0;
|
||||
uint8_t rtx = reg;
|
||||
|
||||
/* Transmit the register to read */
|
||||
i2c_transmitinit(TSL2563_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while(i2c_busy());
|
||||
|
||||
/* Receive the data */
|
||||
i2c_receiveinit(TSL2563_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_receive_n(4, buf);
|
||||
while(i2c_busy());
|
||||
|
||||
PRINTFDEBUG("\nb0 %u, b1 %u, b2 %u, b3 %u\n", buf[0], buf[1], buf[2], buf[3]);
|
||||
|
||||
readBuf[0] = (buf[1] << 8 | (buf[0]));
|
||||
readBuf[1] = (buf[3] << 8 | (buf[2]));
|
||||
|
||||
retVal = calculateLux(readBuf);
|
||||
return retVal;
|
||||
}
|
||||
uint16_t
|
||||
light_ziglet_on(void)
|
||||
{
|
||||
uint16_t data;
|
||||
uint8_t regon = TSL2563_PWRN;
|
||||
/* Turn on the sensor */
|
||||
i2c_transmitinit(TSL2563_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, ®on);
|
||||
while(i2c_busy());
|
||||
data = (uint16_t)tsl2563_read_reg(TSL2563_READ);
|
||||
return data;
|
||||
}
|
||||
void
|
||||
light_ziglet_off(void)
|
||||
{
|
||||
uint8_t regoff = 0x00;
|
||||
/* Turn off the sensor */
|
||||
i2c_transmitinit(TSL2563_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, ®off);
|
||||
while(i2c_busy());
|
||||
return;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Read light ziglet sensor
|
||||
*/
|
||||
|
||||
uint16_t
|
||||
light_ziglet_read(void)
|
||||
{
|
||||
uint16_t lux = 0;
|
||||
lux = light_ziglet_on();
|
||||
light_ziglet_off();
|
||||
return lux;
|
||||
}
|
|
@ -1,123 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Device drivers header file for light ziglet sensor in Zolertia Z1 WSN Platform.
|
||||
* \author
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef LIGHT_ZIGLET_H_
|
||||
#define LIGHT_ZIGLET_H_
|
||||
#include <stdio.h>
|
||||
#include "i2cmaster.h"
|
||||
|
||||
/* Init the light ziglet sensor: ports, pins, I2C, interrupts */
|
||||
void light_ziglet_init(void);
|
||||
|
||||
/* Write to a register.
|
||||
args:
|
||||
reg register to write to
|
||||
val value to write
|
||||
*/
|
||||
void tsl2563_write_reg(uint8_t reg, uint16_t val);
|
||||
|
||||
/* Read one register.
|
||||
args:
|
||||
reg what register to read
|
||||
returns the value of the read register
|
||||
*/
|
||||
uint16_t tsl2563_read_reg(uint8_t reg);
|
||||
|
||||
/* Takes a single light reading
|
||||
args: none
|
||||
returns a lux value
|
||||
*/
|
||||
uint16_t light_ziglet_read();
|
||||
|
||||
/* Calculates the lux values from the calibration table
|
||||
args: raw values from sensor
|
||||
returns a lux value
|
||||
*/
|
||||
uint16_t calculateLux(uint16_t *readRaw);
|
||||
|
||||
/* Turns the light ziglet ON and polls the sensor for a light reading */
|
||||
uint16_t light_ziglet_on(void);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Reference definitions */
|
||||
|
||||
/* TSL2563 slave address */
|
||||
#define TSL2563_ADDR 0x39
|
||||
|
||||
/* Registers */
|
||||
#define TSL2563_READ 0xAC
|
||||
#define TSL2563_PWRN 0x03
|
||||
|
||||
/* Calibration settings */
|
||||
#define K1T 0X0040
|
||||
#define B1T 0x01f2
|
||||
#define M1T 0x01b2
|
||||
|
||||
#define K2T 0x0080
|
||||
#define B2T 0x0214
|
||||
#define M2T 0x02d1
|
||||
|
||||
#define K3T 0x00c0
|
||||
#define B3T 0x023f
|
||||
#define M3T 0x037b
|
||||
|
||||
#define K4T 0x0100
|
||||
#define B4T 0x0270
|
||||
#define M4T 0x03fe
|
||||
|
||||
#define K5T 0x0138
|
||||
#define B5T 0x016f
|
||||
#define M5T 0x01fc
|
||||
|
||||
#define K6T 0x019a
|
||||
#define B6T 0x00d2
|
||||
#define M6T 0x00fb
|
||||
|
||||
#define K7T 0x029a
|
||||
#define B7T 0x0018
|
||||
#define M7T 0x0012
|
||||
|
||||
#define K8T 0x029a
|
||||
#define B8T 0x0000
|
||||
#define M8T 0x0000
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef LIGHT_ZIGLET_H_ */
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Zolertia(TM) is a trademark by Advancare,SL
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Enric M. Calvo (based on work by A. Dunkels, J. Eriksson, N. Finne)
|
||||
* Created : 2011-02-22
|
||||
* $Revision: 1.0 $
|
||||
*/
|
||||
|
||||
#include "dev/potentiometer-sensor.h"
|
||||
#include "dev/sky-sensors.h"
|
||||
#include "contiki.h"
|
||||
|
||||
/* Configure ADC12_2 to sample channel 11 (voltage) and use */
|
||||
/* the Vref+ as reference (SREF_1) since it is a stable reference */
|
||||
#define INPUT_CHANNEL (1 << INCH_4)
|
||||
#define INPUT_REFERENCE SREF_0
|
||||
#define POTENTIOMETER_MEM ADC12MEM4
|
||||
|
||||
const struct sensors_sensor potentiometer_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return POTENTIOMETER_MEM;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(potentiometer_sensor, POTENTIOMETER_SENSOR, value, configure, status);
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Zolertia(TM) is a trademark by Advancare,SL
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Enric M. Calvo (based on work by A. Dunkels, J. Eriksson, N. Finne)
|
||||
* Created : 2011-02-22
|
||||
* $Revision: 1.0 $
|
||||
*/
|
||||
|
||||
#ifndef POTENTIOMETER_SENSOR_H_
|
||||
#define POTENTIOMETER_SENSOR_H_
|
||||
|
||||
#include "lib/sensors.h"
|
||||
|
||||
extern const struct sensors_sensor potentiometer_sensor;
|
||||
|
||||
#define POTENTIOMETER_SENSOR "Potentiometer"
|
||||
|
||||
#endif /* POTENTIOMETER_SENSOR_H_ */
|
|
@ -1,75 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lib/sensors.h"
|
||||
#include "cc2420.h"
|
||||
#include "dev/radio-sensor.h"
|
||||
|
||||
const struct sensors_sensor radio_sensor;
|
||||
static int active;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case RADIO_SENSOR_LAST_PACKET:
|
||||
return cc2420_last_correlation;
|
||||
case RADIO_SENSOR_LAST_VALUE:
|
||||
default:
|
||||
return cc2420_last_rssi;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
if(type == SENSORS_ACTIVE) {
|
||||
active = c;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return active;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR,
|
||||
value, configure, status);
|
|
@ -1,122 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* 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
|
||||
* Reed sensor driver file
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/reed-sensor.h"
|
||||
#include "sys/process.h"
|
||||
#include "sys/ctimer.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef REED_CHECK_PERIOD
|
||||
#define REED_CHECK_PERIOD CLOCK_SECOND
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int current_status = -1;
|
||||
static struct ctimer change_timer;
|
||||
process_event_t reed_sensor_event_changed;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return ~(REED_PORT_DIR & REED_READ_PIN);
|
||||
}
|
||||
return REED_SENSOR_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
if((!status(SENSORS_ACTIVE)) || (type != REED_SENSOR_VAL)) {
|
||||
return REED_SENSOR_ERROR;
|
||||
}
|
||||
return (REED_PORT_READ & REED_READ_PIN) ? REED_CLOSED : REED_OPEN;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
check_callback(void *data)
|
||||
{
|
||||
static int new_status;
|
||||
if(current_status == -1) {
|
||||
ctimer_stop(&change_timer);
|
||||
return;
|
||||
}
|
||||
|
||||
new_status = value(REED_SENSOR_VAL);
|
||||
if(new_status != current_status) {
|
||||
current_status = new_status;
|
||||
process_post(PROCESS_BROADCAST, reed_sensor_event_changed, ¤t_status);
|
||||
}
|
||||
ctimer_reset(&change_timer);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
if(c) {
|
||||
if(!status(SENSORS_ACTIVE)) {
|
||||
REED_PORT_SEL |= REED_READ_PIN;
|
||||
REED_PORT_DIR &= ~REED_READ_PIN;
|
||||
REED_PORT_REN |= REED_READ_PIN;
|
||||
REED_PORT_PRES |= REED_READ_PIN;
|
||||
}
|
||||
} else {
|
||||
REED_PORT_DIR |= REED_READ_PIN;
|
||||
REED_PORT_REN &= ~REED_READ_PIN;
|
||||
}
|
||||
return REED_SENSOR_SUCCESS;
|
||||
case REED_SENSOR_MODE:
|
||||
if(c == REED_SENSOR_EVENT_MODE) {
|
||||
current_status = value(REED_SENSOR_VAL);
|
||||
ctimer_set(&change_timer, REED_CHECK_PERIOD, check_callback, NULL);
|
||||
} else if(c == REED_SENSOR_EVENT_POLL) {
|
||||
current_status = -1;
|
||||
ctimer_stop(&change_timer);
|
||||
} else {
|
||||
return REED_SENSOR_ERROR;
|
||||
}
|
||||
return REED_SENSOR_SUCCESS;
|
||||
}
|
||||
return REED_SENSOR_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(reed_sensor, REED_SENSOR, value, configure, status);
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Header file for the reed sensor
|
||||
*
|
||||
* The Reed sensor allows to be used either by polling the sensor status or by
|
||||
* setting up a timer on the background ticking every REED_CHECK_PERIOD, posting
|
||||
* a reed_sensor_event_changed event, informing the application about a change
|
||||
* in the sensor status (basically open or closed). To enable each mode
|
||||
* (default is polling) call the configure() function with REED_SENSOR_MODE
|
||||
* using REED_SENSOR_EVENT_MODE or REED_SENSOR_POLL_MODE, after having
|
||||
* initialized the device using SENSORS_ACTIVATE(reed_sensor).
|
||||
*
|
||||
* \file
|
||||
* Reed sensor header file
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
#include "lib/sensors.h"
|
||||
|
||||
#ifndef REED_SENSOR_H_
|
||||
#define REED_SENSOR_H_
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define REED_SENSOR_ERROR -1
|
||||
#define REED_SENSOR_SUCCESS 0x00
|
||||
#define REED_SENSOR_VAL 0x01
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define REED_OPEN 0x00
|
||||
#define REED_CLOSED 0x01
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define REED_SENSOR_MODE 0x01
|
||||
#define REED_SENSOR_EVENT_MODE 0x0A
|
||||
#define REED_SENSOR_EVENT_POLL 0x0B
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define REED_PORT_DIR P4DIR
|
||||
#define REED_PORT_SEL P4SEL
|
||||
#define REED_PORT_REN P4REN
|
||||
#define REED_PORT_READ P4IN
|
||||
#define REED_PORT_PRES P4OUT
|
||||
#define REED_READ_PIN (1 << 2)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define REED_SENSOR "Reed Sensor"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
extern const struct sensors_sensor reed_sensor;
|
||||
extern process_event_t reed_sensor_event_changed;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef REED_SENSOR_H_ */
|
|
@ -1,105 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* \file
|
||||
* Device simple driver for generic relay in phidget port of Zolertia Z1
|
||||
* \author
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "relay-phidget.h"
|
||||
|
||||
static uint8_t controlPin;
|
||||
|
||||
enum PHIDGET_RELAY_STATUSTYPES {
|
||||
/* must be a bit and not more, not using 0x00. */
|
||||
INITED = 0x01,
|
||||
RUNNING = 0x02,
|
||||
STOPPED = 0x04,
|
||||
};
|
||||
|
||||
static enum PHIDGET_RELAY_STATUSTYPES _RELAY_STATUS = 0x00;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
relay_enable(uint8_t pin)
|
||||
{
|
||||
|
||||
if(!(_RELAY_STATUS & INITED)) {
|
||||
|
||||
_RELAY_STATUS |= INITED;
|
||||
|
||||
/* Selects the pin to be configure as the control pin of the relay module */
|
||||
controlPin = (1 << pin);
|
||||
|
||||
/* Configures the control pin */
|
||||
P6SEL &= ~controlPin;
|
||||
P6DIR |= controlPin;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
relay_on()
|
||||
{
|
||||
if((_RELAY_STATUS & INITED)) {
|
||||
P6OUT |= controlPin;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
relay_off()
|
||||
{
|
||||
if((_RELAY_STATUS & INITED)) {
|
||||
P6OUT &= ~controlPin;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
int8_t
|
||||
relay_toggle()
|
||||
{
|
||||
if((_RELAY_STATUS & INITED)) {
|
||||
P6OUT ^= controlPin;
|
||||
if((P6OUT & controlPin)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
@ -1,49 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* \file
|
||||
* Device simple driver for generic relay in phidget port of Zolertia Z1
|
||||
* \author
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RELAY_PHIDGET_H_
|
||||
#define RELAY_PHIDGETS_H_
|
||||
|
||||
void relay_enable(uint8_t pin);
|
||||
|
||||
void relay_on();
|
||||
void relay_off();
|
||||
int8_t relay_toggle();
|
||||
|
||||
#endif /* RELAY_PHIDGET_H_ */
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
|
||||
* 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
|
||||
* Architecture-specific definitions for the SHT11 sensor on Zolertia Z1
|
||||
* when connected to the Ziglet port.
|
||||
* \author
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>, adapted from work by
|
||||
* Nicolas Tsiftes <nvt@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef SHT11_ARCH_H
|
||||
#define SHT11_ARCH_H
|
||||
|
||||
// Architecture-specific definitions for the SHT11 sensor on Zolertia Z1
|
||||
// when connected to the Ziglet port.
|
||||
// CAUTION: I2C needs to be disabled to use the bitbang protocol of SHT11
|
||||
|
||||
#define SHT11_ARCH_SDA 1 /* P5.1 */
|
||||
#define SHT11_ARCH_SCL 2 /* P5.2 */
|
||||
// SHT11_ARCH_PWR is not needed, but until and *-arch abstraction exists, this
|
||||
// should fix it
|
||||
#define SHT11_ARCH_PWR 3 /* P5.3 -- unused pin */
|
||||
|
||||
#define SHT11_PxDIR P5DIR
|
||||
#define SHT11_PxIN P5IN
|
||||
#define SHT11_PxOUT P5OUT
|
||||
#define SHT11_PxSEL P5SEL
|
||||
#define SHT11_PxREN P5REN
|
||||
|
||||
#endif
|
|
@ -1,134 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* 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
|
||||
* SHT25 temperature and humidity sensor driver
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "i2cmaster.h"
|
||||
#include "dev/sht25.h"
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t enabled;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
if(type != SENSORS_ACTIVE) {
|
||||
return SHT25_ERROR;
|
||||
}
|
||||
if(value) {
|
||||
i2c_enable();
|
||||
} else {
|
||||
i2c_disable();
|
||||
}
|
||||
enabled = value;
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return enabled;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint16_t
|
||||
sht25_read_reg(uint8_t reg)
|
||||
{
|
||||
uint8_t buf[] = { 0x00, 0x00 };
|
||||
uint16_t retval;
|
||||
uint8_t rtx = reg;
|
||||
|
||||
/* transmit the register to read */
|
||||
i2c_transmitinit(SHT25_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while(i2c_busy());
|
||||
/* receive the data */
|
||||
i2c_receiveinit(SHT25_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_receive_n(2, &buf[0]);
|
||||
while(i2c_busy());
|
||||
|
||||
retval = (uint16_t)(buf[0] << 8 | (buf[1]));
|
||||
return retval;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int16_t
|
||||
sht25_convert(uint8_t variable, uint16_t value)
|
||||
{
|
||||
int16_t rd;
|
||||
uint32_t buff;
|
||||
buff = (uint32_t)value;
|
||||
if(variable == SHT25_VAL_TEMP) {
|
||||
buff *= 17572;
|
||||
buff = buff >> 16;
|
||||
rd = (int16_t)buff - 4685;
|
||||
} else {
|
||||
buff *= 12500;
|
||||
buff = buff >> 16;
|
||||
rd = (int16_t)buff - 600;
|
||||
rd = (rd > 10000) ? 10000 : rd;
|
||||
}
|
||||
return rd;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int16_t
|
||||
sht25_read(uint8_t variable)
|
||||
{
|
||||
int16_t rd;
|
||||
uint16_t raw;
|
||||
|
||||
if((variable != SHT25_VAL_TEMP) && (variable != SHT25_VAL_HUM)) {
|
||||
return SHT25_ERROR;
|
||||
}
|
||||
raw = sht25_read_reg(variable);
|
||||
rd = sht25_convert(variable, raw);
|
||||
return rd;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return sht25_read(type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(sht25, SHT25_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* 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
|
||||
* SHT25 temperature and humidity sensor driver
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
#include "lib/sensors.h"
|
||||
|
||||
#ifndef SHT25_H_
|
||||
#define SHT25_H_
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT25_ADDR 0x40
|
||||
#define SHT25_TEMP_HOLD 0xE3
|
||||
#define SHT25_HUM_HOLD 0xE5
|
||||
#define SHT25_TEMP_NO_HOLD 0xF3
|
||||
#define SHT25_HUM_NO_HOLD 0xF5
|
||||
#define SHT2X_UREG_WRITE 0xE6
|
||||
#define SHT2X_UREG_READ 0xE7
|
||||
#define SHT2X_SOFT_RESET 0XFE
|
||||
#define SHT2X_NULL 0x00
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT2X_RES_14T_12RH 0x00
|
||||
#define SHT2X_RES_12T_08RH 0x01
|
||||
#define SHT2X_RES_13T_10RH 0x80
|
||||
#define SHT2X_RES_11T_11RH 0x81
|
||||
#define SHT2X_HEATER_ON 0x04
|
||||
#define SHT2X_HEATER_OFF 0x00
|
||||
#define SHT2X_OTP_RELOAD_EN 0x00
|
||||
#define SHT2X_OTP_RELOAD_DIS 0x02
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT25_VAL_TEMP SHT25_TEMP_HOLD
|
||||
#define SHT25_VAL_HUM SHT25_HUM_HOLD
|
||||
#define SHT25_ERROR -1
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT25_SENSOR "SHT25 Sensor"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
extern const struct sensors_sensor sht25;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef SHT25_H_ */
|
|
@ -1,152 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Joakim Eriksson
|
||||
* Created : 2010-02-02
|
||||
* Updated : $Date: 2010/08/25 19:30:53 $
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
|
||||
#define ADC12MCTL_NO(adcno) ((unsigned char *) ADC12MCTL0_)[adcno]
|
||||
|
||||
static uint16_t adc_on;
|
||||
static uint16_t ready;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static CC_INLINE void
|
||||
start(void)
|
||||
{
|
||||
uint16_t c, last;
|
||||
|
||||
/* Set up the ADC. */
|
||||
P6DIR = 0xff;
|
||||
P6OUT = 0x00;
|
||||
|
||||
/* Setup ADC12, ref., sampling time */
|
||||
/* XXX Note according to the specification a minimum of 17 ms should
|
||||
be allowed after turn on of the internal reference generator. */
|
||||
ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC + REFON;
|
||||
/* Use sampling timer, repeat-sequence-of-channels */
|
||||
ADC12CTL1 = SHP + CONSEQ_3;
|
||||
|
||||
last = 15;
|
||||
for(c = 0; c < 16; c++) {
|
||||
/* Clear all end-of-sequences */
|
||||
ADC12MCTL_NO(c) &= ~EOS;
|
||||
if(adc_on & (1 << c)) {
|
||||
if(last == 15) {
|
||||
/* Set new start of sequence to lowest active memory holder */
|
||||
ADC12CTL1 |= (c * CSTARTADD_1);
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set highest end-of-sequence. */
|
||||
ADC12MCTL_NO(last) |= EOS;
|
||||
|
||||
ADC12CTL0 |= ADC12ON;
|
||||
ADC12CTL0 |= ENC; /* enable conversion */
|
||||
ADC12CTL0 |= ADC12SC; /* sample & convert */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static CC_INLINE void
|
||||
stop(void)
|
||||
{
|
||||
/* stop converting immediately, turn off reference voltage, etc. */
|
||||
|
||||
ADC12CTL0 &= ~ENC;
|
||||
/* need to remove CONSEQ_3 if not EOS is configured */
|
||||
ADC12CTL1 &= ~CONSEQ_3;
|
||||
|
||||
/* wait for conversion to stop */
|
||||
while(ADC12CTL1 & ADC12BUSY);
|
||||
|
||||
/* clear any pending interrupts */
|
||||
ADC12IFG = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
sky_sensors_status(uint16_t input, int type)
|
||||
{
|
||||
if(type == SENSORS_ACTIVE) {
|
||||
return (adc_on & input) == input;
|
||||
}
|
||||
if(type == SENSORS_READY) {
|
||||
ready |= ADC12IFG & adc_on & input;
|
||||
return (ready & adc_on & input) == input;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
sky_sensors_configure(uint16_t input, uint8_t ref, int type, int value)
|
||||
{
|
||||
uint16_t c;
|
||||
|
||||
if(type == SENSORS_ACTIVE) {
|
||||
stop();
|
||||
|
||||
if(value) {
|
||||
adc_on |= input;
|
||||
P6SEL |= input & 0xff;
|
||||
|
||||
/* Set ADC config */
|
||||
for(c = 0; c < 16; c++) {
|
||||
if(input & (1 << c)) {
|
||||
ADC12MCTL_NO(c) = (c * INCH_1) | ref;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
adc_on &= ~input;
|
||||
ready &= ~input;
|
||||
P6SEL &= ~(input & 0xff);
|
||||
}
|
||||
|
||||
if(adc_on == 0) {
|
||||
P6DIR = 0x00;
|
||||
P6SEL = 0x00;
|
||||
|
||||
/* Turn off ADC and internal reference generator */
|
||||
ADC12CTL0 = 0;
|
||||
ADC12CTL1 = 0;
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,46 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Joakim Eriksson
|
||||
* Created : 2010-02-02
|
||||
* Updated : $Date: 2010/08/25 19:30:53 $
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
|
||||
#ifndef SKY_SENSORS_H_
|
||||
#define SKY_SENSORS_H_
|
||||
|
||||
int sky_sensors_status(uint16_t input, int type);
|
||||
int sky_sensors_configure(uint16_t input, uint8_t reference,
|
||||
int type, int value);
|
||||
|
||||
#endif /* SKY_SENSORS_H_ */
|
|
@ -1,70 +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
|
||||
* Sensor driver for reading the built-in temperature sensor in the CPU.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
*/
|
||||
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "dev/sky-sensors.h"
|
||||
#include "contiki.h"
|
||||
|
||||
#define INPUT_CHANNEL (1 << INCH_10)
|
||||
#define INPUT_REFERENCE SREF_1
|
||||
#define TEMPERATURE_MEM ADC12MEM10
|
||||
|
||||
const struct sensors_sensor temperature_sensor;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return TEMPERATURE_MEM;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR,
|
||||
value, configure, status);
|
|
@ -1,49 +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
|
||||
* Temperature sensor header file.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef TEMPERATURE_SENSOR_H_
|
||||
#define TEMPERATURE_SENSOR_H_
|
||||
|
||||
#include "lib/sensors.h"
|
||||
|
||||
extern const struct sensors_sensor temperature_sensor;
|
||||
|
||||
#define TEMPERATURE_SENSOR "Temperature"
|
||||
|
||||
#endif /* TEMPERATURE_SENSOR_H_ */
|
|
@ -1,185 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Jelmer Tiete.
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Device drivers for tlc59116 i2c led driver on Zolertia Z1.
|
||||
* See http://www.ti.com/product/tlc59116 for datasheet.
|
||||
* \author
|
||||
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "tlc59116.h"
|
||||
#include "i2cmaster.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Write to a register.
|
||||
* args:
|
||||
* reg register to write to
|
||||
* val value to write
|
||||
*/
|
||||
|
||||
void
|
||||
tlc59116_write_reg(uint8_t reg, uint8_t val)
|
||||
{
|
||||
uint8_t tx_buf[] = { reg, val };
|
||||
|
||||
i2c_transmitinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("I2C Ready to TX\n");
|
||||
|
||||
i2c_transmit_n(2, tx_buf);
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("WRITE_REG 0x%02X @ reg 0x%02X\n", val, reg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Write several registers from a stream.
|
||||
* args:
|
||||
* len number of bytes to write
|
||||
* data pointer to where the data is written from
|
||||
*
|
||||
* First byte in stream must be the register address to begin writing to.
|
||||
* The data is then written from second byte and increasing.
|
||||
*/
|
||||
|
||||
void
|
||||
tlc59116_write_stream(uint8_t len, uint8_t *data)
|
||||
{
|
||||
i2c_transmitinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("I2C Ready to TX(stream)\n");
|
||||
|
||||
i2c_transmit_n(len, data); /* start tx and send conf reg */
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("WRITE_STR %u B to 0x%02X\n", len, data[0]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Read one register.
|
||||
* args:
|
||||
* reg what register to read
|
||||
* returns the value of the read register
|
||||
*/
|
||||
|
||||
uint8_t
|
||||
tlc59116_read_reg(uint8_t reg)
|
||||
{
|
||||
uint8_t retVal = 0;
|
||||
uint8_t rtx = reg;
|
||||
|
||||
PRINTFDEBUG("READ_REG 0x%02X\n", reg);
|
||||
|
||||
/* transmit the register to read */
|
||||
i2c_transmitinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while(i2c_busy());
|
||||
|
||||
/* receive the data */
|
||||
i2c_receiveinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_receive_n(1, &retVal);
|
||||
while(i2c_busy());
|
||||
|
||||
return retVal;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Read several registers in a stream.
|
||||
* args:
|
||||
* reg what register to start reading from
|
||||
* len number of bytes to read
|
||||
* whereto pointer to where the data is saved
|
||||
*/
|
||||
|
||||
void
|
||||
tlc59116_read_stream(uint8_t reg, uint8_t len, uint8_t *whereto)
|
||||
{
|
||||
uint8_t rtx = reg;
|
||||
|
||||
PRINTFDEBUG("READ_STR %u B from 0x%02X\n", len, reg);
|
||||
|
||||
/* transmit the register to start reading from */
|
||||
i2c_transmitinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while(i2c_busy());
|
||||
|
||||
/* receive the data */
|
||||
i2c_receiveinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_receive_n(len, whereto);
|
||||
while(i2c_busy());
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Set pwm value for individual led. Make sure PWM mode is enabled.
|
||||
* args:
|
||||
* led led output -> 0 till 15
|
||||
* pwm led pwm value
|
||||
*/
|
||||
|
||||
void
|
||||
tlc59116_led(uint8_t led, uint8_t pwm)
|
||||
{
|
||||
if((led < 0) || (led > 15)) {
|
||||
PRINTFDEBUG("TLC59116: wrong led value.");
|
||||
} else {
|
||||
tlc59116_write_reg(led + TLC59116_PWM0, pwm);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Init the led driver: ports, pins, registers, interrupts (none enabled), I2C,
|
||||
* default threshold values etc.
|
||||
*/
|
||||
|
||||
void
|
||||
tlc59116_init(void)
|
||||
{
|
||||
/* Set up ports and pins for I2C communication */
|
||||
i2c_enable();
|
||||
|
||||
/* set default register values. */
|
||||
tlc59116_write_reg(TLC59116_MODE1, TLC59116_MODE1_DEFAULT);
|
||||
tlc59116_write_reg(TLC59116_MODE2, TLC59116_MODE2_DEFAULT);
|
||||
|
||||
/*Set all PWM values to 0x00 (off) */
|
||||
/*This would maybe be better with a SWRST */
|
||||
uint8_t tx_buf[] =
|
||||
{ TLC59116_PWM0_AUTOINCR, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
tlc59116_write_stream(17, tx_buf);
|
||||
|
||||
/* set all leds to PWM control */
|
||||
tlc59116_write_reg(TLC59116_LEDOUT0, TLC59116_LEDOUT_PWM);
|
||||
tlc59116_write_reg(TLC59116_LEDOUT1, TLC59116_LEDOUT_PWM);
|
||||
tlc59116_write_reg(TLC59116_LEDOUT2, TLC59116_LEDOUT_PWM);
|
||||
tlc59116_write_reg(TLC59116_LEDOUT3, TLC59116_LEDOUT_PWM);
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Jelmer Tiete.
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Device drivers header file for TLC59116 i2c led driver on Zolertia Z1.
|
||||
* See http://www.ti.com/product/tlc59116 for datasheet.
|
||||
* \author
|
||||
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
||||
*/
|
||||
|
||||
#ifndef TLC59116_H_
|
||||
#define TLC59116_H_
|
||||
#include <stdio.h>
|
||||
#include "dev/i2cmaster.h"
|
||||
|
||||
#if 0
|
||||
#include <stdio.h>
|
||||
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTFDEBUG(...)
|
||||
#endif
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Init the led driver: ports, pins, registers, I2C*/
|
||||
void tlc59116_init(void);
|
||||
|
||||
/* Write to a register.
|
||||
* args:
|
||||
* reg register to write to
|
||||
* val value to write
|
||||
*/
|
||||
void tlc59116_write_reg(uint8_t reg, uint8_t val);
|
||||
|
||||
/* Write several registers from a stream.
|
||||
* args:
|
||||
* len number of bytes to read
|
||||
* data pointer to where the data is read from
|
||||
* First byte in stream must be the register address to begin writing to.
|
||||
* The data is then written from the second byte and increasing. The address byte
|
||||
* is not included in length len.
|
||||
*/
|
||||
void tlc59116_write_stream(uint8_t len, uint8_t * data);
|
||||
|
||||
/* Read one register.
|
||||
* args:
|
||||
* reg what register to read
|
||||
* returns the value of the read register
|
||||
*/
|
||||
uint8_t tlc59116_read_reg(uint8_t reg);
|
||||
|
||||
/* Read several registers in a stream.
|
||||
* args:
|
||||
* reg what register to start reading from
|
||||
* len number of bytes to read
|
||||
* whereto pointer to where the data is saved
|
||||
*/
|
||||
void tlc59116_read_stream(uint8_t reg, uint8_t len, uint8_t * whereto);
|
||||
|
||||
/* Set pwm value for individual led
|
||||
* args:
|
||||
* led led output -> 0 till 15
|
||||
* pwm led pwm value
|
||||
*/
|
||||
void tlc59116_led(uint8_t led, uint8_t pwm);
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Application definitions, change if required by application. */
|
||||
|
||||
/* Suggested defaults according to the data sheet etc */
|
||||
#define TLC59116_MODE1_DEFAULT 0x00 // Default (no sub or all call) + OSC on
|
||||
#define TLC59116_MODE2_DEFAULT 0x00 // Default (output change on stop)
|
||||
|
||||
#define TLC59116_LEDOUT_PWM 0xAA // LDRx = 01 -> PWM; 4 leds per reg: 01010101b -> 0xAA
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Reference definitions, should not be changed */
|
||||
/* TLC59116 slave address */
|
||||
#define TLC59116_ADDR 0x60 //7bit adress, 8bit write adress: 0xC0
|
||||
//address with all address pins pulled to ground
|
||||
/* TLC59116 registers */
|
||||
#define TLC59116_MODE1 0x00
|
||||
#define TLC59116_MODE2 0x01
|
||||
#define TLC59116_PWM0_AUTOINCR 0xA2 //auto increment address for first pwm register
|
||||
#define TLC59116_PWM0 0x02
|
||||
#define TLC59116_PWM1 0x03
|
||||
#define TLC59116_PWM2 0x04
|
||||
#define TLC59116_PWM3 0x05
|
||||
#define TLC59116_PWM4 0x06
|
||||
#define TLC59116_PWM5 0x07
|
||||
#define TLC59116_PWM6 0x08
|
||||
#define TLC59116_PWM7 0x09
|
||||
#define TLC59116_PWM8 0x0A
|
||||
#define TLC59116_PWM9 0x0B
|
||||
#define TLC59116_PWM10 0x0C
|
||||
#define TLC59116_PWM11 0x0D
|
||||
#define TLC59116_PWM12 0x0E
|
||||
#define TLC59116_PWM13 0x0F
|
||||
#define TLC59116_PWM14 0x10
|
||||
#define TLC59116_PWM15 0x11
|
||||
#define TLC59116_GRPPWM 0x12
|
||||
#define TLC59116_GRPFREQ 0x13
|
||||
#define TLC59116_LEDOUT0 0x14
|
||||
#define TLC59116_LEDOUT1 0x15
|
||||
#define TLC59116_LEDOUT2 0x16
|
||||
#define TLC59116_LEDOUT3 0x17
|
||||
|
||||
/* More registers follow, but not used in this implementation */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef TLC59116_H_ */
|
|
@ -1,193 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2016, Zolertia <http://www.zolertia.com>
|
||||
* 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
|
||||
* Device drivers for tmp102 temperature sensor in Zolertia Z1.
|
||||
* \author
|
||||
* Enric M. Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "i2cmaster.h"
|
||||
#include "tmp102.h"
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t enabled;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tmp102_init(void)
|
||||
{
|
||||
/* Power Up TMP102 via pin */
|
||||
TMP102_PWR_DIR |= TMP102_PWR_PIN;
|
||||
TMP102_PWR_SEL &= ~TMP102_PWR_SEL;
|
||||
TMP102_PWR_SEL2 &= ~TMP102_PWR_SEL;
|
||||
TMP102_PWR_REN &= ~TMP102_PWR_SEL;
|
||||
TMP102_PWR_OUT |= TMP102_PWR_PIN;
|
||||
|
||||
/* Set up ports and pins for I2C communication */
|
||||
i2c_enable();
|
||||
|
||||
enabled = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tmp102_stop(void)
|
||||
{
|
||||
/* Power off */
|
||||
TMP102_PWR_OUT &= ~TMP102_PWR_PIN;
|
||||
enabled = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tmp102_write_reg(uint8_t reg, uint16_t val)
|
||||
{
|
||||
uint8_t tx_buf[] = { reg, 0x00, 0x00 };
|
||||
|
||||
tx_buf[1] = (uint8_t)(val >> 8);
|
||||
tx_buf[2] = (uint8_t)(val & 0x00FF);
|
||||
|
||||
i2c_transmitinit(TMP102_ADDR);
|
||||
while(i2c_busy());
|
||||
PRINTF("I2C Ready to TX\n");
|
||||
|
||||
i2c_transmit_n(3, tx_buf);
|
||||
while(i2c_busy());
|
||||
PRINTF("WRITE_REG 0x%04X @ reg 0x%02X\n", val, reg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint16_t
|
||||
tmp102_read_reg(uint8_t reg)
|
||||
{
|
||||
uint8_t buf[] = { 0x00, 0x00 };
|
||||
uint16_t retVal = 0;
|
||||
uint8_t rtx = reg;
|
||||
PRINTF("READ_REG 0x%02X\n", reg);
|
||||
|
||||
/* transmit the register to read */
|
||||
i2c_transmitinit(TMP102_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while(i2c_busy());
|
||||
|
||||
/* receive the data */
|
||||
i2c_receiveinit(TMP102_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_receive_n(2, &buf[0]);
|
||||
while(i2c_busy());
|
||||
|
||||
retVal = (uint16_t)(buf[0] << 8 | (buf[1]));
|
||||
|
||||
return retVal;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint16_t
|
||||
tmp102_read_temp_raw(void)
|
||||
{
|
||||
uint16_t rd = 0;
|
||||
rd = tmp102_read_reg(TMP102_TEMP);
|
||||
return rd;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int16_t
|
||||
tmp102_read_temp_x100(void)
|
||||
{
|
||||
int16_t raw = 0;
|
||||
int16_t sign = 1;
|
||||
int16_t abstemp, temp_int;
|
||||
|
||||
raw = (int16_t)tmp102_read_reg(TMP102_TEMP);
|
||||
if(raw < 0) {
|
||||
abstemp = (raw ^ 0xFFFF) + 1;
|
||||
sign = -1;
|
||||
} else {
|
||||
abstemp = raw;
|
||||
}
|
||||
|
||||
/* Integer part of the temperature value and percents*/
|
||||
temp_int = (abstemp >> 8) * sign * 100;
|
||||
temp_int += ((abstemp & 0xff) * 100) / 0x100;
|
||||
return temp_int;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int8_t
|
||||
tmp102_read_temp_simple(void)
|
||||
{
|
||||
/* Casted to int8_t: We don't expect temperatures outside -128 to 127 C */
|
||||
return tmp102_read_temp_x100() / 100;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
if(type != SENSORS_ACTIVE) {
|
||||
return TMP102_ERROR;
|
||||
}
|
||||
if(value) {
|
||||
tmp102_init();
|
||||
} else {
|
||||
tmp102_stop();
|
||||
}
|
||||
enabled = value;
|
||||
return TMP102_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return enabled;
|
||||
}
|
||||
return TMP102_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return (int)tmp102_read_temp_x100();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(tmp102, TMP102_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2016, Zolertia <http://www.zolertia.com>
|
||||
* 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
|
||||
* Device drivers header file for tmp102 temperature sensor in Zolertia
|
||||
* Z1 WSN Platform.
|
||||
* \author
|
||||
* Enric M. Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*/
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#ifndef TMP102_H_
|
||||
#define TMP102_H_
|
||||
#include <stdio.h>
|
||||
#include "lib/sensors.h"
|
||||
#include "i2cmaster.h"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
void tmp102_init(void);
|
||||
void tmp102_write_reg(uint8_t reg, uint16_t val);
|
||||
uint16_t tmp102_read_reg(uint8_t reg);
|
||||
uint16_t tmp102_read_temp_raw();
|
||||
int8_t tmp102_read_temp_simple();
|
||||
int16_t tmp102_read_temp_x100();
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define TMP102_ADDR 0x48
|
||||
#define TMP102_TEMP 0x00
|
||||
#define TMP102_CONF 0x01
|
||||
#define TMP102_TLOW 0x02
|
||||
#define TMP102_THIGH 0x03
|
||||
|
||||
/* TMP102 pin-out */
|
||||
#define TMP102_PWR_DIR P5DIR
|
||||
#define TMP102_PWR_SEL P5SEL
|
||||
#define TMP102_PWR_SEL2 P5SEL2
|
||||
#define TMP102_PWR_REN P5REN
|
||||
#define TMP102_PWR_OUT P5OUT
|
||||
#define TMP102_PWR_PIN (1<<0) /* P5.0 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define TMP102_SUCCESS 0
|
||||
#define TMP102_ERROR (-1)
|
||||
#define TMP102_READ 0x01
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define TMP102_SENSOR "TMP102 sensor"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
extern const struct sensors_sensor tmp102;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef TMP102_H_ */
|
|
@ -1,264 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Device driver for the ST M25P16 40MHz 1Mbyte external memory.
|
||||
* \author
|
||||
* Björn Grönvall <bg@sics.se>
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>
|
||||
*
|
||||
* Data is written bit inverted (~-operator) to flash so that
|
||||
* unwritten data will read as zeros (UNIX style).
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "dev/spi.h"
|
||||
#include "dev/xmem.h"
|
||||
#include "dev/watchdog.h"
|
||||
|
||||
#if 1
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
#define SPI_FLASH_INS_WREN 0x06
|
||||
#define SPI_FLASH_INS_WRDI 0x04
|
||||
#define SPI_FLASH_INS_RDSR 0x05
|
||||
#define SPI_FLASH_INS_WRSR 0x01
|
||||
#define SPI_FLASH_INS_READ 0x03
|
||||
#define SPI_FLASH_INS_FAST_READ 0x0b
|
||||
#define SPI_FLASH_INS_PP 0x02
|
||||
#define SPI_FLASH_INS_SE 0xd8
|
||||
#define SPI_FLASH_INS_BE 0xc7
|
||||
#define SPI_FLASH_INS_DP 0xb9
|
||||
#define SPI_FLASH_INS_RES 0xab
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
write_enable(void)
|
||||
{
|
||||
int s;
|
||||
|
||||
s = splhigh();
|
||||
SPI_FLASH_ENABLE();
|
||||
|
||||
SPI_WRITE(SPI_FLASH_INS_WREN);
|
||||
|
||||
SPI_FLASH_DISABLE();
|
||||
splx(s);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned
|
||||
read_status_register(void)
|
||||
{
|
||||
unsigned char u;
|
||||
|
||||
int s;
|
||||
|
||||
s = splhigh();
|
||||
SPI_FLASH_ENABLE();
|
||||
|
||||
|
||||
SPI_WRITE(SPI_FLASH_INS_RDSR);
|
||||
|
||||
SPI_FLUSH();
|
||||
SPI_READ(u);
|
||||
|
||||
SPI_FLASH_DISABLE();
|
||||
splx(s);
|
||||
|
||||
return u;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Wait for a write/erase operation to finish.
|
||||
*/
|
||||
static unsigned
|
||||
wait_ready(void)
|
||||
{
|
||||
unsigned u;
|
||||
do {
|
||||
u = read_status_register();
|
||||
watchdog_periodic();
|
||||
} while(u & 0x01); /* WIP=1, write in progress */
|
||||
return u;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Erase 64k bytes of data. It takes about 1s before WIP goes low!
|
||||
*/
|
||||
static void
|
||||
erase_sector(unsigned long offset)
|
||||
{
|
||||
int s;
|
||||
wait_ready();
|
||||
|
||||
write_enable();
|
||||
|
||||
s = splhigh();
|
||||
SPI_FLASH_ENABLE();
|
||||
|
||||
SPI_WRITE_FAST(SPI_FLASH_INS_SE);
|
||||
SPI_WRITE_FAST(offset >> 16); /* MSB */
|
||||
SPI_WRITE_FAST(offset >> 8);
|
||||
SPI_WRITE_FAST(offset >> 0); /* LSB */
|
||||
SPI_WAITFORTx_ENDED();
|
||||
|
||||
SPI_FLASH_DISABLE();
|
||||
splx(s);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Initialize external flash *and* SPI bus!
|
||||
*/
|
||||
void
|
||||
xmem_init(void)
|
||||
{
|
||||
spi_init();
|
||||
|
||||
P4DIR |= BV(FLASH_CS); // Unnecessary for Zolertia Z1 | BV(FLASH_PWR);
|
||||
P5DIR |= BV(FLASH_HOLD); // In P5 for Z1
|
||||
|
||||
SPI_FLASH_DISABLE(); /* Unselect flash. */
|
||||
SPI_FLASH_UNHOLD();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
xmem_pread(void *_p, int size, unsigned long offset)
|
||||
{
|
||||
unsigned char *p = _p;
|
||||
const unsigned char *end = p + size;
|
||||
int s;
|
||||
wait_ready();
|
||||
|
||||
ENERGEST_ON(ENERGEST_TYPE_FLASH_READ);
|
||||
|
||||
s = splhigh();
|
||||
SPI_FLASH_ENABLE();
|
||||
|
||||
SPI_WRITE_FAST(SPI_FLASH_INS_READ);
|
||||
SPI_WRITE_FAST(offset >> 16); /* MSB */
|
||||
SPI_WRITE_FAST(offset >> 8);
|
||||
SPI_WRITE_FAST(offset >> 0); /* LSB */
|
||||
SPI_WAITFORTx_ENDED();
|
||||
|
||||
SPI_FLUSH();
|
||||
for(; p < end; p++) {
|
||||
unsigned char u;
|
||||
SPI_READ(u);
|
||||
*p = ~u;
|
||||
}
|
||||
|
||||
SPI_FLASH_DISABLE();
|
||||
splx(s);
|
||||
|
||||
ENERGEST_OFF(ENERGEST_TYPE_FLASH_READ);
|
||||
|
||||
return size;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const unsigned char *
|
||||
program_page(unsigned long offset, const unsigned char *p, int nbytes)
|
||||
{
|
||||
const unsigned char *end = p + nbytes;
|
||||
int s;
|
||||
|
||||
wait_ready();
|
||||
|
||||
write_enable();
|
||||
|
||||
s = splhigh();
|
||||
SPI_FLASH_ENABLE();
|
||||
|
||||
SPI_WRITE_FAST(SPI_FLASH_INS_PP);
|
||||
SPI_WRITE_FAST(offset >> 16); /* MSB */
|
||||
SPI_WRITE_FAST(offset >> 8);
|
||||
SPI_WRITE_FAST(offset >> 0); /* LSB */
|
||||
|
||||
for(; p < end; p++) {
|
||||
SPI_WRITE_FAST(~*p);
|
||||
}
|
||||
SPI_WAITFORTx_ENDED();
|
||||
|
||||
SPI_FLASH_DISABLE();
|
||||
splx(s);
|
||||
|
||||
return p;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
xmem_pwrite(const void *_buf, int size, unsigned long addr)
|
||||
{
|
||||
const unsigned char *p = _buf;
|
||||
const unsigned long end = addr + size;
|
||||
unsigned long i, next_page;
|
||||
|
||||
ENERGEST_ON(ENERGEST_TYPE_FLASH_WRITE);
|
||||
|
||||
for(i = addr; i < end;) {
|
||||
next_page = (i | 0xff) + 1;
|
||||
if(next_page > end) {
|
||||
next_page = end;
|
||||
}
|
||||
p = program_page(i, p, next_page - i);
|
||||
i = next_page;
|
||||
}
|
||||
|
||||
ENERGEST_OFF(ENERGEST_TYPE_FLASH_WRITE);
|
||||
|
||||
return size;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
xmem_erase(long size, unsigned long addr)
|
||||
{
|
||||
unsigned long end = addr + size;
|
||||
|
||||
if(size % XMEM_ERASE_UNIT_SIZE != 0) {
|
||||
PRINTF("xmem_erase: bad size\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(addr % XMEM_ERASE_UNIT_SIZE != 0) {
|
||||
PRINTF("xmem_erase: bad offset\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (; addr < end; addr += XMEM_ERASE_UNIT_SIZE) {
|
||||
erase_sector(addr);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,153 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Joakim Eriksson
|
||||
* Created : 2010-02-02
|
||||
* Updated : $Date: 2010/11/05 10:31:57 $
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/z1-phidgets.h"
|
||||
|
||||
static uint8_t adc_on;
|
||||
static uint8_t active;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
sensors_activate(uint8_t type)
|
||||
{
|
||||
uint8_t pre = adc_on;
|
||||
|
||||
adc_on |= type;
|
||||
|
||||
if(pre == 0 && adc_on > 0) {
|
||||
P6DIR = 0xff;
|
||||
P6OUT = 0x00;
|
||||
P6SEL |= 0x8b; /* bit 7 + 3 + 1 + 0 */
|
||||
|
||||
/* if nothing was started before, start up the ADC system */
|
||||
/* Set up the ADC. */
|
||||
ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC; /* Setup ADC12, ref., sampling time */
|
||||
ADC12CTL1 = SHP + CONSEQ_3 + CSTARTADD_0; /* Use sampling timer, repeat-sequenc-of-channels */
|
||||
/* convert up to MEM4 */
|
||||
ADC12MCTL4 |= EOS;
|
||||
|
||||
ADC12CTL0 |= ADC12ON + REFON;
|
||||
ADC12CTL0 |= ENC; /* enable conversion */
|
||||
ADC12CTL0 |= ADC12SC; /* sample & convert */
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
sensors_deactivate(uint8_t type)
|
||||
{
|
||||
adc_on &= ~type;
|
||||
|
||||
if(adc_on == 0) {
|
||||
/* stop converting immediately, turn off reference voltage, etc. */
|
||||
/* wait for conversion to stop */
|
||||
|
||||
ADC12CTL0 &= ~ENC;
|
||||
/* need to remove CONSEQ_3 if not EOS is configured */
|
||||
ADC12CTL1 &= ~CONSEQ_3;
|
||||
|
||||
while(ADC12CTL1 & ADC12BUSY);
|
||||
|
||||
ADC12CTL0 = 0;
|
||||
ADC12CTL1 = 0;
|
||||
|
||||
P6DIR = 0x00;
|
||||
P6OUT = 0x00;
|
||||
P6SEL = 0x00;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
/* ADC0 corresponds to the port under the logo, ADC1 to the port over the logo,
|
||||
ADC2 and ADC3 corresponds to port on the JCreate bottom expansion port) */
|
||||
switch(type) {
|
||||
case PHIDGET5V_1:
|
||||
return ADC12MEM0;
|
||||
case PHIDGET5V_2:
|
||||
return ADC12MEM1;
|
||||
case PHIDGET3V_1:
|
||||
return ADC12MEM2;
|
||||
case PHIDGET3V_2:
|
||||
return ADC12MEM3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return active;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
if(c) {
|
||||
if(!status(SENSORS_ACTIVE)) {
|
||||
/* SREF_1 is Vref+ */
|
||||
/* MemReg6 == P6.0/A0 == 5V 1 */
|
||||
ADC12MCTL0 = (INCH_0 + SREF_0);
|
||||
/* MemReg7 == P6.3/A3 == 5V 2 */
|
||||
ADC12MCTL1 = (INCH_3 + SREF_0);
|
||||
/* MemReg8 == P6.1/A1 == 3V 1 */
|
||||
ADC12MCTL2 = (INCH_1 + SREF_0);
|
||||
/* MemReg9 == P6.7/A7 == 3V_2 */
|
||||
ADC12MCTL3 = (INCH_7 + SREF_0);
|
||||
|
||||
sensors_activate(0x0F);
|
||||
active = 1;
|
||||
}
|
||||
} else {
|
||||
sensors_deactivate(0x0F);
|
||||
active = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(phidgets, "Phidgets", value, configure, status);
|
|
@ -1,49 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Joakim Eriksson
|
||||
* Created : 2010-08-26
|
||||
* Updated : $Date: 2010/08/27 12:58:57 $
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
#ifndef Z1_PHIDGETS_H_
|
||||
#define Z1_PHIDGETS_H_
|
||||
|
||||
#define PHIDGET5V_1 0
|
||||
#define PHIDGET5V_2 1
|
||||
#define PHIDGET3V_1 2
|
||||
#define PHIDGET3V_2 3
|
||||
|
||||
extern const struct sensors_sensor phidgets;
|
||||
|
||||
#endif /* Z1_PHIDGETS_H_ */
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Zolertia - http://www.zolertia.com
|
||||
* 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 copyright holder 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 COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER 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
|
||||
* Zolertia Z1 on-board sensors
|
||||
* \author
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/tmp102.h"
|
||||
#include "dev/adxl345.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \brief Exports global symbols for the sensor API */
|
||||
SENSORS(&button_sensor, &adxl345, &tmp102);
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,75 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Utility to store a node id in the external flash
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "sys/node-id.h"
|
||||
#include "contiki-conf.h"
|
||||
#include "dev/xmem.h"
|
||||
#include <string.h>
|
||||
|
||||
unsigned short node_id = 0;
|
||||
unsigned char node_mac[8];
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
node_id_restore(void)
|
||||
{
|
||||
unsigned char buf[12];
|
||||
xmem_pread(buf, 12, NODE_ID_XMEM_OFFSET);
|
||||
if(buf[0] == 0xad &&
|
||||
buf[1] == 0xde) {
|
||||
node_id = (buf[2] << 8) | buf[3];
|
||||
memcpy(node_mac, &buf[4], 8);
|
||||
} else {
|
||||
node_id = 0;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
node_id_burn(unsigned short id)
|
||||
{
|
||||
unsigned char buf[12];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
buf[0] = 0xad;
|
||||
buf[1] = 0xde;
|
||||
buf[2] = id >> 8;
|
||||
buf[3] = id & 0xff;
|
||||
xmem_erase(XMEM_ERASE_UNIT_SIZE, NODE_ID_XMEM_OFFSET);
|
||||
xmem_pwrite(buf, 12, NODE_ID_XMEM_OFFSET);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,281 +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
|
||||
* Platform configuration for the Z1 platform
|
||||
* \author
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef PLATFORM_CONF_H_
|
||||
#define PLATFORM_CONF_H_
|
||||
|
||||
/*
|
||||
* Definitions below are dictated by the hardware and not really
|
||||
* changeable!
|
||||
*/
|
||||
#define ZOLERTIA_Z1 1 /* Enric */
|
||||
|
||||
/* Delay between GO signal and SFD: radio fixed delay + 4Bytes preample + 1B SFD -- 1Byte time is 32us
|
||||
* ~327us + 129preample = 456 us */
|
||||
#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(456))
|
||||
/* Delay between GO signal and start listening
|
||||
* ~50us delay + 129preample + ?? = 183 us */
|
||||
#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(183))
|
||||
/* Delay between the SFD finishes arriving and it is detected in software */
|
||||
#define RADIO_DELAY_BEFORE_DETECT 0
|
||||
|
||||
#define PLATFORM_HAS_LEDS 1
|
||||
#define PLATFORM_HAS_BUTTON 1
|
||||
#define PLATFORM_HAS_RADIO 1
|
||||
#define PLATFORM_HAS_BATTERY 1
|
||||
|
||||
/* CPU target speed in Hz */
|
||||
#define F_CPU 8000000uL /* 8MHz by default */
|
||||
|
||||
/* Our clock resolution, this is the same as Unix HZ. */
|
||||
#define CLOCK_CONF_SECOND 128UL
|
||||
|
||||
#define BAUD2UBR(baud) ((F_CPU / baud))
|
||||
|
||||
#define CCIF
|
||||
#define CLIF
|
||||
|
||||
#define HAVE_STDINT_H
|
||||
#include "msp430def.h"
|
||||
|
||||
/* XXX Temporary place for defines that are lacking in mspgcc4's gpio.h */
|
||||
#ifdef __IAR_SYSTEMS_ICC__
|
||||
#ifndef P1SEL2_
|
||||
#define P1SEL2_ (0x0041u) /* Port 1 Selection 2*/
|
||||
DEFC(P1SEL2, P1SEL2_)
|
||||
#endif
|
||||
#ifndef P5SEL2_
|
||||
#define P5SEL2_ (0x0045u) /* Port 5 Selection 2*/
|
||||
DEFC(P5SEL2, P5SEL2_)
|
||||
#endif
|
||||
#else /* __IAR_SYSTEMS_ICC__ */
|
||||
#ifdef __GNUC__
|
||||
#ifndef P1SEL2_
|
||||
#define P1SEL2_ 0x0041 /* Port 1 Selection 2*/
|
||||
sfrb(P1SEL2, P1SEL2_);
|
||||
#endif
|
||||
#ifndef P5SEL2_
|
||||
#define P5SEL2_ 0x0045 /* Port 5 Selection 2*/
|
||||
sfrb(P5SEL2, P5SEL2_);
|
||||
#endif
|
||||
#endif /* __GNUC__ */
|
||||
#endif /* __IAR_SYSTEMS_ICC__ */
|
||||
|
||||
/* Types for clocks and uip_stats */
|
||||
typedef unsigned short uip_stats_t;
|
||||
typedef unsigned long clock_time_t;
|
||||
typedef unsigned long off_t;
|
||||
|
||||
/* the low-level radio driver */
|
||||
#define NETSTACK_CONF_RADIO cc2420_driver
|
||||
|
||||
/*
|
||||
* Definitions below are dictated by the hardware and not really
|
||||
* changeable!
|
||||
*/
|
||||
|
||||
/* LED ports */
|
||||
#ifdef Z1_IS_Z1SP
|
||||
#define LEDS_PxDIR P4DIR
|
||||
#define LEDS_PxOUT P4OUT
|
||||
#define LEDS_CONF_RED 0x04
|
||||
#define LEDS_CONF_GREEN 0x01
|
||||
#define LEDS_CONF_YELLOW 0x80
|
||||
#else
|
||||
#define LEDS_PxDIR P5DIR
|
||||
#define LEDS_PxOUT P5OUT
|
||||
#define LEDS_CONF_RED 0x10
|
||||
#define LEDS_CONF_GREEN 0x40
|
||||
#define LEDS_CONF_YELLOW 0x20
|
||||
#endif /* Z1_IS_Z1SP */
|
||||
|
||||
/* DCO speed resynchronization for more robust UART, etc. */
|
||||
#define DCOSYNCH_CONF_ENABLED 0
|
||||
#define DCOSYNCH_CONF_PERIOD 30
|
||||
|
||||
#define ROM_ERASE_UNIT_SIZE 512
|
||||
#define XMEM_ERASE_UNIT_SIZE (64 * 1024L)
|
||||
|
||||
#define CFS_CONF_OFFSET_TYPE long
|
||||
|
||||
/* Use the first 64k of external flash for node configuration */
|
||||
#define NODE_ID_XMEM_OFFSET (0 * XMEM_ERASE_UNIT_SIZE)
|
||||
|
||||
/* Use the second 64k of external flash for codeprop. */
|
||||
#define EEPROMFS_ADDR_CODEPROP (1 * XMEM_ERASE_UNIT_SIZE)
|
||||
|
||||
#define CFS_XMEM_CONF_OFFSET (2 * XMEM_ERASE_UNIT_SIZE)
|
||||
#define CFS_XMEM_CONF_SIZE (1 * XMEM_ERASE_UNIT_SIZE)
|
||||
|
||||
#define CFS_RAM_CONF_SIZE 4096
|
||||
|
||||
/*
|
||||
* SPI bus configuration for the Z1 mote.
|
||||
*/
|
||||
|
||||
/* SPI input/output registers. */
|
||||
#define SPI_TXBUF UCB0TXBUF
|
||||
#define SPI_RXBUF UCB0RXBUF
|
||||
|
||||
/* USART0 Tx ready? */
|
||||
#define SPI_WAITFOREOTx() while((UCB0STAT & UCBUSY) != 0)
|
||||
/* USART0 Rx ready? */
|
||||
#define SPI_WAITFOREORx() while((IFG2 & UCB0RXIFG) == 0)
|
||||
/* USART0 Tx buffer ready? */
|
||||
#define SPI_WAITFORTxREADY() while((IFG2 & UCB0TXIFG) == 0)
|
||||
|
||||
#define MOSI 1 /* P3.1 - Output: SPI Master out - slave in (MOSI) */
|
||||
#define MISO 2 /* P3.2 - Input: SPI Master in - slave out (MISO) */
|
||||
#define SCK 3 /* P3.3 - Output: SPI Serial Clock (SCLK) */
|
||||
|
||||
/*
|
||||
* SPI bus - M25P80 external flash configuration.
|
||||
*/
|
||||
/* FLASH_PWR P4.3 Output ALWAYS POWERED ON Z1 */
|
||||
#define FLASH_CS 4 /* P4.4 Output */
|
||||
#define FLASH_HOLD 7 /* P5.7 Output */
|
||||
|
||||
/* Enable/disable flash access to the SPI bus (active low). */
|
||||
|
||||
#define SPI_FLASH_ENABLE() (P4OUT &= ~BV(FLASH_CS))
|
||||
#define SPI_FLASH_DISABLE() (P4OUT |= BV(FLASH_CS))
|
||||
|
||||
#define SPI_FLASH_HOLD() (P5OUT &= ~BV(FLASH_HOLD))
|
||||
#define SPI_FLASH_UNHOLD() (P5OUT |= BV(FLASH_HOLD))
|
||||
|
||||
/*
|
||||
* SPI bus - CC2420 pin configuration.
|
||||
*/
|
||||
|
||||
#define CC2420_CONF_SYMBOL_LOOP_COUNT 1302 /* 326us msp430X @ 8MHz */
|
||||
|
||||
/* P1.2 - Input: FIFOP from CC2420 */
|
||||
#define CC2420_FIFOP_PORT(type) P1##type
|
||||
#define CC2420_FIFOP_PIN 2
|
||||
/* P1.3 - Input: FIFO from CC2420 */
|
||||
#define CC2420_FIFO_PORT(type) P1##type
|
||||
#define CC2420_FIFO_PIN 3
|
||||
/* P1.4 - Input: CCA from CC2420 */
|
||||
#define CC2420_CCA_PORT(type) P1##type
|
||||
#define CC2420_CCA_PIN 4
|
||||
/* P4.1 - Input: SFD from CC2420 */
|
||||
#define CC2420_SFD_PORT(type) P4##type
|
||||
#define CC2420_SFD_PIN 1
|
||||
/* P3.0 - Output: SPI Chip Select (CS_N) */
|
||||
#define CC2420_CSN_PORT(type) P3##type
|
||||
#define CC2420_CSN_PIN 0
|
||||
/* P4.5 - Output: VREG_EN to CC2420 */
|
||||
#define CC2420_VREG_PORT(type) P4##type
|
||||
#define CC2420_VREG_PIN 5
|
||||
/* P4.6 - Output: RESET_N to CC2420 */
|
||||
#define CC2420_RESET_PORT(type) P4##type
|
||||
#define CC2420_RESET_PIN 6
|
||||
|
||||
#define CC2420_IRQ_VECTOR PORT1_VECTOR
|
||||
|
||||
/* Pin status. */
|
||||
#define CC2420_FIFOP_IS_1 (!!(CC2420_FIFOP_PORT(IN) & BV(CC2420_FIFOP_PIN)))
|
||||
#define CC2420_FIFO_IS_1 (!!(CC2420_FIFO_PORT(IN) & BV(CC2420_FIFO_PIN)))
|
||||
#define CC2420_CCA_IS_1 (!!(CC2420_CCA_PORT(IN) & BV(CC2420_CCA_PIN)))
|
||||
#define CC2420_SFD_IS_1 (!!(CC2420_SFD_PORT(IN) & BV(CC2420_SFD_PIN)))
|
||||
|
||||
/* The CC2420 reset pin. */
|
||||
#define SET_RESET_INACTIVE() (CC2420_RESET_PORT(OUT) |= BV(CC2420_RESET_PIN))
|
||||
#define SET_RESET_ACTIVE() (CC2420_RESET_PORT(OUT) &= ~BV(CC2420_RESET_PIN))
|
||||
|
||||
/* CC2420 voltage regulator enable pin. */
|
||||
#define SET_VREG_ACTIVE() (CC2420_VREG_PORT(OUT) |= BV(CC2420_VREG_PIN))
|
||||
#define SET_VREG_INACTIVE() (CC2420_VREG_PORT(OUT) &= ~BV(CC2420_VREG_PIN))
|
||||
|
||||
/* CC2420 rising edge trigger for external interrupt 0 (FIFOP). */
|
||||
#define CC2420_FIFOP_INT_INIT() do { \
|
||||
CC2420_FIFOP_PORT(IES) &= ~BV(CC2420_FIFOP_PIN); \
|
||||
CC2420_CLEAR_FIFOP_INT(); \
|
||||
} while(0)
|
||||
|
||||
/* FIFOP on external interrupt 0. */
|
||||
#define CC2420_ENABLE_FIFOP_INT() do { CC2420_FIFOP_PORT(IE) |= BV(CC2420_FIFOP_PIN); } while(0)
|
||||
#define CC2420_DISABLE_FIFOP_INT() do { CC2420_FIFOP_PORT(IE) &= ~BV(CC2420_FIFOP_PIN); } while(0)
|
||||
#define CC2420_CLEAR_FIFOP_INT() do { CC2420_FIFOP_PORT(IFG) &= ~BV(CC2420_FIFOP_PIN); } while(0)
|
||||
|
||||
/*
|
||||
* Enables/disables CC2420 access to the SPI bus (not the bus).
|
||||
* (Chip Select)
|
||||
*/
|
||||
|
||||
/* ENABLE CSn (active low) */
|
||||
#define CC2420_SPI_ENABLE() (CC2420_CSN_PORT(OUT) &= ~BV(CC2420_CSN_PIN))
|
||||
/* DISABLE CSn (active low) */
|
||||
#define CC2420_SPI_DISABLE() (CC2420_CSN_PORT(OUT) |= BV(CC2420_CSN_PIN))
|
||||
#define CC2420_SPI_IS_ENABLED() ((CC2420_CSN_PORT(OUT) & BV(CC2420_CSN_PIN)) != BV(CC2420_CSN_PIN))
|
||||
|
||||
/*
|
||||
* I2C configuration
|
||||
*/
|
||||
|
||||
#define I2C_PxDIR P5DIR
|
||||
#define I2C_PxIN P5IN
|
||||
#define I2C_PxOUT P5OUT
|
||||
#define I2C_PxSEL P5SEL
|
||||
#define I2C_PxSEL2 P5SEL2
|
||||
#define I2C_PxREN P5REN
|
||||
|
||||
#define I2C_SDA (1 << 1) /* SDA == P5.1 */
|
||||
#define I2C_SCL (1 << 2) /* SCL == P5.2 */
|
||||
#define I2C_PRESC_1KHZ_LSB 0x00
|
||||
#define I2C_PRESC_1KHZ_MSB 0x20
|
||||
#define I2C_PRESC_100KHZ_LSB 0x50
|
||||
#define I2C_PRESC_100KHZ_MSB 0x00
|
||||
#define I2C_PRESC_400KHZ_LSB 0x14
|
||||
#define I2C_PRESC_400KHZ_MSB 0x00
|
||||
|
||||
/* Set rate as high as possible by default */
|
||||
#ifndef I2C_PRESC_Z1_LSB
|
||||
#define I2C_PRESC_Z1_LSB I2C_PRESC_400KHZ_LSB
|
||||
#endif
|
||||
|
||||
#ifndef I2C_PRESC_Z1_MSB
|
||||
#define I2C_PRESC_Z1_MSB I2C_PRESC_400KHZ_MSB
|
||||
#endif
|
||||
|
||||
/* I2C configuration with RX interrupts */
|
||||
#ifdef I2C_CONF_RX_WITH_INTERRUPT
|
||||
#define I2C_RX_WITH_INTERRUPT I2C_CONF_RX_WITH_INTERRUPT
|
||||
#else /* I2C_CONF_RX_WITH_INTERRUPT */
|
||||
#define I2C_RX_WITH_INTERRUPT 1
|
||||
#endif /* I2C_CONF_RX_WITH_INTERRUPT */
|
||||
|
||||
#endif /* PLATFORM_CONF_H_ */
|
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011-2012, 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
|
||||
* Websense for Z1 mote
|
||||
* \author
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
* Joel Hoglund <joel@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/tmp102.h"
|
||||
#include "dev/z1-phidgets.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "jsontree.h"
|
||||
#include "json-ws.h"
|
||||
|
||||
/* It seems like there normally is an offset of some degrees for the tmp102 */
|
||||
#define TMP102_OFFSET -150
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
PROCESS(websense_process, "Websense (z1)");
|
||||
AUTOSTART_PROCESSES(&websense_process);
|
||||
|
||||
static int
|
||||
output_sensor(struct jsontree_context *path)
|
||||
{
|
||||
char buf[10];
|
||||
int tmp;
|
||||
int tmp2;
|
||||
|
||||
tmp = tmp102_read_temp_x100();
|
||||
tmp2 = tmp - TMP102_OFFSET;
|
||||
tmp = tmp2 / 100;
|
||||
|
||||
snprintf(buf, sizeof(buf), "%2d.%02d", tmp, tmp2 - (100 * tmp));
|
||||
jsontree_write_atom(path, buf);
|
||||
return 0;
|
||||
}
|
||||
static struct jsontree_callback sensor_callback =
|
||||
JSONTREE_CALLBACK(output_sensor, NULL);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
static struct jsontree_string desc = JSONTREE_STRING("Zolertia Z1");
|
||||
static struct jsontree_string unit = JSONTREE_STRING("Celcius");
|
||||
|
||||
JSONTREE_OBJECT(node_tree,
|
||||
JSONTREE_PAIR("node-type", &desc),
|
||||
JSONTREE_PAIR("time", &json_time_callback));
|
||||
|
||||
JSONTREE_OBJECT(sensor_tree,
|
||||
JSONTREE_PAIR("unit", &unit),
|
||||
JSONTREE_PAIR("value", &sensor_callback));
|
||||
|
||||
JSONTREE_OBJECT(rsc_tree,
|
||||
JSONTREE_PAIR("temperature", &sensor_tree),
|
||||
JSONTREE_PAIR("leds", &json_leds_callback));
|
||||
|
||||
/* complete node tree */
|
||||
JSONTREE_OBJECT(tree,
|
||||
JSONTREE_PAIR("node", &node_tree),
|
||||
JSONTREE_PAIR("rsc", &rsc_tree),
|
||||
JSONTREE_PAIR("cfg", &json_subscribe_callback));
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* for cosm plugin */
|
||||
#if WITH_COSM
|
||||
/* set COSM value callback to be the temp sensor */
|
||||
struct jsontree_callback cosm_value_callback =
|
||||
JSONTREE_CALLBACK(output_sensor, NULL);
|
||||
#endif
|
||||
|
||||
PROCESS_THREAD(websense_process, ev, data)
|
||||
{
|
||||
static struct etimer timer;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
json_ws_init(&tree);
|
||||
|
||||
tmp102_init();
|
||||
|
||||
json_ws_set_callback("rsc");
|
||||
|
||||
while(1) {
|
||||
/* Alive indication with the LED */
|
||||
etimer_set(&timer, CLOCK_SECOND * 5);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
|
||||
leds_on(LEDS_RED);
|
||||
etimer_set(&timer, CLOCK_SECOND / 8);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
|
||||
leds_off(LEDS_RED);
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -175,15 +175,7 @@ PROCESS_THREAD(node_process, ev, data)
|
|||
|
||||
int coordinator_candidate = 0;
|
||||
|
||||
#ifdef CONTIKI_TARGET_Z1
|
||||
/* Set node with MAC address c1:0c:00:00:00:00:01 as coordinator,
|
||||
* convenient in cooja for regression tests using z1 nodes
|
||||
* */
|
||||
extern unsigned char node_mac[8];
|
||||
unsigned char coordinator_mac[8] = { 0xc1, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
|
||||
|
||||
coordinator_candidate = (memcmp(node_mac, coordinator_mac, 8) == 0);
|
||||
#elif CONTIKI_TARGET_COOJA
|
||||
#if CONTIKI_TARGET_COOJA
|
||||
coordinator_candidate = (node_id == 1);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -139,36 +139,6 @@
|
|||
/************* Other system configuration **************/
|
||||
/*******************************************************/
|
||||
|
||||
#if CONTIKI_TARGET_Z1
|
||||
/* Save some space to fit the limited RAM of the z1 */
|
||||
#undef UIP_CONF_TCP
|
||||
#define UIP_CONF_TCP 0
|
||||
#undef QUEUEBUF_CONF_NUM
|
||||
#define QUEUEBUF_CONF_NUM 3
|
||||
#undef RPL_NS_CONF_LINK_NUM
|
||||
#define RPL_NS_CONF_LINK_NUM 8
|
||||
#undef NBR_TABLE_CONF_MAX_NEIGHBORS
|
||||
#define NBR_TABLE_CONF_MAX_NEIGHBORS 8
|
||||
#undef UIP_CONF_ND6_SEND_NS
|
||||
#define UIP_CONF_ND6_SEND_NS 0
|
||||
#undef SICSLOWPAN_CONF_FRAG
|
||||
#define SICSLOWPAN_CONF_FRAG 0
|
||||
|
||||
#if WITH_SECURITY
|
||||
/* Note: on sky or z1 in cooja, crypto operations are done in S/W and
|
||||
* cannot be accommodated in normal slots. Use 65ms slots instead, and
|
||||
* a very short 6TiSCH minimal schedule length */
|
||||
#undef TSCH_CONF_DEFAULT_TIMESLOT_LENGTH
|
||||
#define TSCH_CONF_DEFAULT_TIMESLOT_LENGTH 65000
|
||||
#undef TSCH_SCHEDULE_CONF_DEFAULT_LENGTH
|
||||
#define TSCH_SCHEDULE_CONF_DEFAULT_LENGTH 2
|
||||
/* Reduce log level to make space for security on z1 */
|
||||
#undef TSCH_LOG_CONF_LEVEL
|
||||
#define TSCH_LOG_CONF_LEVEL 0
|
||||
#endif /* WITH_SECURITY */
|
||||
|
||||
#endif /* CONTIKI_TARGET_Z1 */
|
||||
|
||||
#if CONTIKI_TARGET_CC2538DK || CONTIKI_TARGET_ZOUL || \
|
||||
CONTIKI_TARGET_OPENMOTE_CC2538
|
||||
#define TSCH_CONF_HW_FRAME_FILTERING 0
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<motetype>
|
||||
org.contikios.cooja.contikimote.ContikiMoteType
|
||||
<identifier>mtype660</identifier>
|
||||
<description>Cooja Mote Type #z11</description>
|
||||
<description>RPL/TSCH Node</description>
|
||||
<source>[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c</source>
|
||||
<commands>make TARGET=cooja clean
|
||||
make TARGET=cooja node.cooja</commands>
|
||||
|
|
|
@ -1,267 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<simconf>
|
||||
<project EXPORT="discard">[APPS_DIR]/mrm</project>
|
||||
<project EXPORT="discard">[APPS_DIR]/mspsim</project>
|
||||
<project EXPORT="discard">[APPS_DIR]/avrora</project>
|
||||
<project EXPORT="discard">[APPS_DIR]/serial_socket</project>
|
||||
<project EXPORT="discard">[APPS_DIR]/collect-view</project>
|
||||
<project EXPORT="discard">[APPS_DIR]/powertracker</project>
|
||||
<simulation>
|
||||
<title>RPL+TSCH</title>
|
||||
<randomseed>123456</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
org.contikios.cooja.radiomediums.UDGM
|
||||
<transmitting_range>50.0</transmitting_range>
|
||||
<interference_range>100.0</interference_range>
|
||||
<success_ratio_tx>1.0</success_ratio_tx>
|
||||
<success_ratio_rx>1.0</success_ratio_rx>
|
||||
</radiomedium>
|
||||
<events>
|
||||
<logoutput>40000</logoutput>
|
||||
</events>
|
||||
<motetype>
|
||||
org.contikios.cooja.mspmote.Z1MoteType
|
||||
<identifier>z11</identifier>
|
||||
<description>Z1 Mote Type #z11</description>
|
||||
<source EXPORT="discard">[CONFIG_DIR]/node.c</source>
|
||||
<commands EXPORT="discard">make node.z1 TARGET=z1</commands>
|
||||
<firmware EXPORT="copy">[CONFIG_DIR]/node.z1</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDefaultSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
</motetype>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>-1.285769821276336</x>
|
||||
<y>38.58045647334346</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspClock
|
||||
<deviation>1.0</deviation>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>1</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>-19.324109516886306</x>
|
||||
<y>76.23135780254927</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspClock
|
||||
<deviation>1.0</deviation>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>2</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>5.815501305791592</x>
|
||||
<y>76.77463755494317</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspClock
|
||||
<deviation>1.0</deviation>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>3</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>31.920697784030082</x>
|
||||
<y>50.5212265977149</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspClock
|
||||
<deviation>1.0</deviation>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>4</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>47.21747673247198</x>
|
||||
<y>30.217765340599726</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspClock
|
||||
<deviation>1.0</deviation>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>5</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>10.622284947035123</x>
|
||||
<y>109.81862399725188</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspClock
|
||||
<deviation>1.0</deviation>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>6</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>52.41150716335335</x>
|
||||
<y>109.93228340481916</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspClock
|
||||
<deviation>1.0</deviation>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>7</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>70.18727461718498</x>
|
||||
<y>70.06861701541145</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspClock
|
||||
<deviation>1.0</deviation>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>8</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>80.29870484201041</x>
|
||||
<y>99.37351603835938</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspClock
|
||||
<deviation>1.0</deviation>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>9</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.SimControl
|
||||
<width>242</width>
|
||||
<z>3</z>
|
||||
<height>160</height>
|
||||
<location_x>11</location_x>
|
||||
<location_y>241</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.Visualizer
|
||||
<plugin_config>
|
||||
<moterelations>true</moterelations>
|
||||
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.GridVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.TrafficVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
|
||||
<viewport>1.7405603810040515 0.0 0.0 1.7405603810040515 47.95980153208088 -42.576134155447555</viewport>
|
||||
</plugin_config>
|
||||
<width>236</width>
|
||||
<z>2</z>
|
||||
<height>230</height>
|
||||
<location_x>1</location_x>
|
||||
<location_y>1</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.LogListener
|
||||
<plugin_config>
|
||||
<filter>ID:1</filter>
|
||||
<formatted_time />
|
||||
<coloring />
|
||||
</plugin_config>
|
||||
<width>1031</width>
|
||||
<z>0</z>
|
||||
<height>394</height>
|
||||
<location_x>273</location_x>
|
||||
<location_y>6</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.TimeLine
|
||||
<plugin_config>
|
||||
<mote>0</mote>
|
||||
<mote>1</mote>
|
||||
<mote>2</mote>
|
||||
<mote>3</mote>
|
||||
<mote>4</mote>
|
||||
<mote>5</mote>
|
||||
<mote>6</mote>
|
||||
<mote>7</mote>
|
||||
<mote>8</mote>
|
||||
<showRadioRXTX />
|
||||
<showRadioHW />
|
||||
<showLEDs />
|
||||
<zoomfactor>16529.88882215865</zoomfactor>
|
||||
</plugin_config>
|
||||
<width>1304</width>
|
||||
<z>1</z>
|
||||
<height>311</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>412</location_y>
|
||||
</plugin>
|
||||
</simconf>
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
ifndef TARGET
|
||||
TARGET=z1
|
||||
endif
|
||||
|
||||
# Enable to pull-in Z1SP specific test/source files
|
||||
ZOLERTIA_Z1SP=0
|
||||
|
||||
CONTIKI_PROJECT = test-phidgets blink test-adxl345 test-tmp102 test-light-ziglet
|
||||
CONTIKI_PROJECT += test-battery test-relay-phidget test-tlc59116 test-sht25
|
||||
|
||||
CONTIKI_SOURCEFILES += reed-sensor.c sht25.c tlc59116.c light-ziglet.c \
|
||||
relay-phidget.c
|
||||
|
||||
MODULES += drivers/dev/sht11
|
||||
|
||||
ifeq ($(ZOLERTIA_Z1SP),1)
|
||||
CONTIKI_PROJECT += test-potent
|
||||
endif
|
||||
|
||||
all: $(CONTIKI_PROJECT)
|
||||
CONTIKI = ../../../..
|
||||
CONTIKI_WITH_RIME = 1
|
||||
include $(CONTIKI)/Makefile.include
|
|
@ -1,25 +0,0 @@
|
|||
all: z1-websense
|
||||
|
||||
CONTIKI = ../../../../..
|
||||
|
||||
APPS += webserver webbrowser
|
||||
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
CONTIKI_SOURCEFILES += wget.c
|
||||
PROJECTDIRS += ../../../../ipv6/rpl-border-router
|
||||
PROJECT_SOURCEFILES += httpd-simple.c
|
||||
|
||||
CONTIKI_WITH_IPV6 = 1
|
||||
include $(CONTIKI)/Makefile.include
|
||||
|
||||
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
|
||||
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
|
||||
|
||||
connect-router: $(CONTIKI)/tools/tunslip6
|
||||
sudo $(CONTIKI)/tools/tunslip6 fd00::1/64
|
||||
|
||||
connect-router-cooja: $(CONTIKI)/tools/tunslip6
|
||||
sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 fd00::1/64
|
||||
|
||||
CUSTOM_RULE_LINK=1
|
||||
%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a $(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@ -lm
|
|
@ -1 +0,0 @@
|
|||
TARGET = z1
|
|
@ -1,45 +0,0 @@
|
|||
Z1 websense
|
||||
===========
|
||||
|
||||
This example features a simple webserver running on top of the IPv6 contiki
|
||||
stack on Zolertia Z1 motes to provide sensor values, and with a RPL border
|
||||
router to bridge the sensor network to Internet.
|
||||
|
||||
|
||||
To test the example in COOJA under Linux
|
||||
----------------------------------------
|
||||
|
||||
1. Start COOJA and load the simulation "example-z1-websense.csc"
|
||||
|
||||
make TARGET=cooja example-z1-websense.csc
|
||||
|
||||
2. Connect to the COOJA simulation using tunslip6:
|
||||
|
||||
make connect-router-cooja
|
||||
|
||||
3. You should now be able to browse to the nodes using your web browser:
|
||||
|
||||
Router: http://[fd00::0212:7401:0001:0101]/
|
||||
Node 2: http://[fd00::0212:7402:0002:0202]/
|
||||
|
||||
|
||||
To run the example on real nodes under Linux
|
||||
--------------------------------------------
|
||||
|
||||
1. Program the nodes with the websense application
|
||||
|
||||
make TARGET=z1 z1-websense.upload
|
||||
|
||||
2. Disconnect the nodes and program one node with the RPL border router
|
||||
|
||||
cd examples/ipv6/rpl-border-router && make TARGET=z1 border-router.upload
|
||||
|
||||
3. Connect to the border router using tunslip6:
|
||||
|
||||
make connect-router
|
||||
|
||||
4. Reboot the router and note the router IP address
|
||||
|
||||
5. You should now be able to browse to your router node using your web
|
||||
browser: http://[<ROUTER IPv6 ADDRESS>]/. On this page you should
|
||||
see a list of all accessible nodes with their IP adresses.
|
|
@ -1,201 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<simconf>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
|
||||
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
|
||||
<simulation>
|
||||
<title>Z1 Websense with RPL router</title>
|
||||
<delaytime>0</delaytime>
|
||||
<randomseed>123456</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
org.contikios.cooja.radiomediums.UDGM
|
||||
<transmitting_range>50.0</transmitting_range>
|
||||
<interference_range>50.0</interference_range>
|
||||
<success_ratio_tx>1.0</success_ratio_tx>
|
||||
<success_ratio_rx>1.0</success_ratio_rx>
|
||||
</radiomedium>
|
||||
<events>
|
||||
<logoutput>40000</logoutput>
|
||||
</events>
|
||||
<motetype>
|
||||
org.contikios.cooja.mspmote.Z1MoteType
|
||||
<identifier>rplroot</identifier>
|
||||
<description>Z1 RPL Root</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/rpl-border-router/border-router.c</source>
|
||||
<commands EXPORT="discard">make border-router.z1 TARGET=z1</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/ipv6/rpl-border-router/border-router.z1</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
</motetype>
|
||||
<motetype>
|
||||
org.contikios.cooja.mspmote.Z1MoteType
|
||||
<identifier>Z1web</identifier>
|
||||
<description>Z1 Websense</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/zolertia/z1/ipv6/z1-websense/z1-websense.c</source>
|
||||
<commands EXPORT="discard">make z1-websense.z1 TARGET=z1</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/zolertia/z1/ipv6/z1-websense/z1-websense.z1</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
</motetype>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>33.260163187353555</x>
|
||||
<y>30.643217359962595</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>1</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>rplroot</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>62.239287566073514</x>
|
||||
<y>34.43810269527116</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>2</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>Z1web</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>56.71945435107925</x>
|
||||
<y>20.293530081848317</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>3</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>Z1web</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>75.34889145168493</x>
|
||||
<y>24.43340499309403</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>4</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>Z1web</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>92.59837024854205</x>
|
||||
<y>38.57797760651687</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>5</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>Z1web</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>47.68359039801751</x>
|
||||
<y>47.26544238238854</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>6</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>Z1web</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.SimControl
|
||||
<width>259</width>
|
||||
<z>4</z>
|
||||
<height>179</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>0</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.Visualizer
|
||||
<plugin_config>
|
||||
<skin>org.contikios.cooja.plugins.skins.IDVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.UDGMVisualizerSkin</skin>
|
||||
<skin>org.contikios.cooja.plugins.skins.MoteTypeVisualizerSkin</skin>
|
||||
<viewport>2.898638306051894 0.0 0.0 2.898638306051894 -68.40918308040007 -27.82360366026197</viewport>
|
||||
</plugin_config>
|
||||
<width>258</width>
|
||||
<z>2</z>
|
||||
<height>209</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>178</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.LogListener
|
||||
<plugin_config>
|
||||
<filter />
|
||||
</plugin_config>
|
||||
<width>1024</width>
|
||||
<z>3</z>
|
||||
<height>311</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>385</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.RadioLogger
|
||||
<plugin_config>
|
||||
<split>150</split>
|
||||
<analyzers name="6lowpan" />
|
||||
</plugin_config>
|
||||
<width>769</width>
|
||||
<z>0</z>
|
||||
<height>342</height>
|
||||
<location_x>255</location_x>
|
||||
<location_y>-1</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.serialsocket.SerialSocketServer
|
||||
<mote_arg>0</mote_arg>
|
||||
<width>422</width>
|
||||
<z>1</z>
|
||||
<height>74</height>
|
||||
<location_x>601</location_x>
|
||||
<location_y>310</location_y>
|
||||
</plugin>
|
||||
</simconf>
|
|
@ -1,46 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PROJECT_RPL_WEB_CONF_H_
|
||||
#define PROJECT_RPL_WEB_CONF_H_
|
||||
|
||||
#undef QUEUEBUF_CONF_NUM
|
||||
#define QUEUEBUF_CONF_NUM 4
|
||||
|
||||
#undef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 140
|
||||
|
||||
#undef UIP_CONF_RECEIVE_WINDOW
|
||||
#define UIP_CONF_RECEIVE_WINDOW 60
|
||||
|
||||
#undef WEBSERVER_CONF_CFS_CONNS
|
||||
#define WEBSERVER_CONF_CFS_CONNS 2
|
||||
|
||||
#endif /* PROJECT_RPL_WEB_CONF_H_ */
|
|
@ -1,170 +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 simple example using HTTP to control and be controlled
|
||||
* \author
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/leds.h"
|
||||
#include "wget.h"
|
||||
#include "webserver-nogui.h"
|
||||
#include "httpd-simple.h"
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* The address of the server to register the services for this node */
|
||||
#define SERVER "fd00::1"
|
||||
|
||||
/* This command registers two services (/0 and /1) to turn the leds on or off */
|
||||
#define REGISTER_COMMAND "/r?p=0&d=Turn%20off%20leds&p=1&d=Turn%20on%20leds"
|
||||
|
||||
/* The address of the other node to control */
|
||||
#define OTHER_NODE "fd00::212:7403:3:303"
|
||||
|
||||
/* The commands to send to the other node */
|
||||
#define SET_LEDS_ON "/1"
|
||||
#define SET_LEDS_OFF "/0"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(websense_remote_process, "Websense Remote");
|
||||
AUTOSTART_PROCESSES(&websense_remote_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const char *TOP = "<html><head><title>Contiki Websense Remote</title></head><body>\n";
|
||||
static const char *BOTTOM = "</body></html>\n";
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(handle_command(struct httpd_state *s))
|
||||
{
|
||||
PSOCK_BEGIN(&s->sout);
|
||||
|
||||
SEND_STRING(&s->sout, TOP);
|
||||
|
||||
if(s->filename[1] == '0') {
|
||||
/* Turn off leds */
|
||||
leds_off(LEDS_ALL);
|
||||
SEND_STRING(&s->sout, "Turned off leds!");
|
||||
} else if(s->filename[1] == '1') {
|
||||
/* Turn on leds */
|
||||
leds_on(LEDS_ALL);
|
||||
SEND_STRING(&s->sout, "Turned on leds!");
|
||||
} else {
|
||||
SEND_STRING(&s->sout, "Unknown command");
|
||||
}
|
||||
|
||||
SEND_STRING(&s->sout, BOTTOM);
|
||||
|
||||
PSOCK_END(&s->sout);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
httpd_simple_script_t
|
||||
httpd_simple_get_script(const char *name)
|
||||
{
|
||||
return handle_command;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
wget_done(int status)
|
||||
{
|
||||
switch(status) {
|
||||
case WGET_OK:
|
||||
printf("Command sent.\n");
|
||||
break;
|
||||
case WGET_TIMEDOUT:
|
||||
printf("Command timedout.\n");
|
||||
break;
|
||||
case WGET_ABORTED:
|
||||
printf("Connection aborted.\n");
|
||||
break;
|
||||
case WGET_CONNECT_FAILED:
|
||||
printf("Failed to connect.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
static const struct wget_callbacks callbacks = {
|
||||
NULL, wget_done
|
||||
};
|
||||
static void
|
||||
send_command(const char *server, const char *command)
|
||||
{
|
||||
int ret;
|
||||
printf("Sending to [%s]: %s\n", server, command);
|
||||
ret = wget_get(server, 80, command, &callbacks);
|
||||
if(ret != WGET_OK) {
|
||||
if(ret == WGET_ALREADY_RUNNING) {
|
||||
printf("Waiting for previous command to finish.\n");
|
||||
} else {
|
||||
printf("Failed to send command: %u\n", ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(websense_remote_process, ev, data)
|
||||
{
|
||||
static int mode;
|
||||
static struct etimer timer;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
mode = 0;
|
||||
wget_init();
|
||||
process_start(&webserver_nogui_process, NULL);
|
||||
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
|
||||
/* Give the node some time to join the network before registering
|
||||
the available services. */
|
||||
etimer_set(&timer, CLOCK_SECOND * 30);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
if(ev == sensors_event && data == &button_sensor) {
|
||||
/* The button has been pressed. Send command to the other node. */
|
||||
if(mode) {
|
||||
/* Turn on leds */
|
||||
send_command(OTHER_NODE, SET_LEDS_OFF);
|
||||
} else {
|
||||
send_command(OTHER_NODE, SET_LEDS_ON);
|
||||
}
|
||||
/* Alternate between the two commands */
|
||||
mode = !mode;
|
||||
} else if(ev == PROCESS_EVENT_TIMER && etimer_expired(&timer)) {
|
||||
printf("Registering services\n");
|
||||
send_command(SERVER, REGISTER_COMMAND);
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,203 +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 simple wget implementation
|
||||
* \author
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "webclient.h"
|
||||
#include "wget.h"
|
||||
#include "dev/leds.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBUG DEBUG_NONE
|
||||
#include "net/ip/uip-debug.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBUG_LEDS 0
|
||||
#undef LEDS_ON
|
||||
#undef LEDS_OFF
|
||||
|
||||
#if DEBUG_LEDS
|
||||
#define LEDS_ON(led) leds_on(led)
|
||||
#define LEDS_OFF(led) leds_off(led)
|
||||
#else
|
||||
#define LEDS_ON(led)
|
||||
#define LEDS_OFF(led)
|
||||
#endif /* DEBUG_LEDS */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int fetch_running;
|
||||
|
||||
#define STATS ((DEBUG)&DEBUG_PRINT) && 1
|
||||
#if STATS
|
||||
static clock_time_t fetch_started;
|
||||
static unsigned long fetch_counter;
|
||||
#endif /* STATUS */
|
||||
|
||||
static const char *server;
|
||||
static const char *file;
|
||||
static uint16_t port;
|
||||
static const struct wget_callbacks *callbacks;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(wget_process, "wget");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
call_done(int status)
|
||||
{
|
||||
if(callbacks != NULL && callbacks->done != NULL) {
|
||||
callbacks->done(status);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(wget_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
PRINTF("wget: fetching %s\n", file);
|
||||
#if STATS
|
||||
fetch_counter = 0;
|
||||
fetch_started = clock_time();
|
||||
#endif /* STATS */
|
||||
LEDS_ON(LEDS_YELLOW);
|
||||
if(webclient_get(server, port, file) == 0) {
|
||||
PRINTF("wget: failed to connect\n");
|
||||
LEDS_OFF(LEDS_YELLOW);
|
||||
fetch_running = 0;
|
||||
call_done(WGET_CONNECT_FAILED);
|
||||
} else {
|
||||
while(fetch_running) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
if(ev == tcpip_event) {
|
||||
webclient_appcall(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
webclient_datahandler(char *data, uint16_t len)
|
||||
{
|
||||
if(len == 0) {
|
||||
#if STATS
|
||||
clock_time_t elapsed;
|
||||
elapsed = clock_time() - fetch_started;
|
||||
PRINTF("wget: recv %lu bytes during %lu sec (",
|
||||
fetch_counter, (elapsed / CLOCK_SECOND));
|
||||
#if CLOCK_SECOND == 128
|
||||
PRINTF("%lu.%02lus, ", (unsigned long)elapsed >> 7,
|
||||
(unsigned long)((elapsed & 127) * 100) / 128);
|
||||
PRINTF("%lu byte/sec ", (fetch_counter * 128L) / elapsed);
|
||||
#endif
|
||||
PRINTF("%lu tick): ", (unsigned long)elapsed);
|
||||
if(elapsed > CLOCK_SECOND) {
|
||||
PRINTF("%lu", fetch_counter / (elapsed / CLOCK_SECOND));
|
||||
} else {
|
||||
PRINTF("-");
|
||||
}
|
||||
PRINTF(" byte/sec\n");
|
||||
#else /* STATS */
|
||||
PRINTF("wget: complete\n");
|
||||
#endif /* STATS */
|
||||
|
||||
fetch_running = 0;
|
||||
call_done(WGET_OK);
|
||||
LEDS_OFF(LEDS_RED | LEDS_YELLOW);
|
||||
} else {
|
||||
#if STATS
|
||||
fetch_counter += len;
|
||||
#endif /* STATS */
|
||||
if(callbacks != NULL && callbacks->data != NULL) {
|
||||
/* Assume the buffer is large enough for ending zero */
|
||||
data[len] = '\0';
|
||||
callbacks->data(data, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
webclient_connected(void)
|
||||
{
|
||||
LEDS_OFF(LEDS_YELLOW);
|
||||
LEDS_ON(LEDS_RED);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
webclient_timedout(void)
|
||||
{
|
||||
PRINTF("wget: timedout\n");
|
||||
LEDS_OFF(LEDS_RED | LEDS_YELLOW);
|
||||
fetch_running = 0;
|
||||
call_done(WGET_TIMEDOUT);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
webclient_aborted(void)
|
||||
{
|
||||
PRINTF("wget: aborted\n");
|
||||
LEDS_OFF(LEDS_RED | LEDS_YELLOW);
|
||||
fetch_running = 0;
|
||||
call_done(WGET_ABORTED);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
webclient_closed(void)
|
||||
{
|
||||
PRINTF("wget: closed\n");
|
||||
fetch_running = 0;
|
||||
LEDS_OFF(LEDS_RED | LEDS_YELLOW);
|
||||
call_done(WGET_CLOSED);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
wget_init(void)
|
||||
{
|
||||
webclient_init();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
wget_get(const char *s, uint16_t p, const char *f,
|
||||
const struct wget_callbacks *c)
|
||||
{
|
||||
if(fetch_running) {
|
||||
return WGET_ALREADY_RUNNING;
|
||||
}
|
||||
fetch_running = 1;
|
||||
server = s;
|
||||
port = p;
|
||||
file = f;
|
||||
callbacks = c;
|
||||
process_start(&wget_process, NULL);
|
||||
return WGET_OK;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,62 +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 simple wget implementation
|
||||
* \author
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef WGET_H_
|
||||
#define WGET_H_
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
struct wget_callbacks {
|
||||
void (*data)(const char *data, uint16_t len);
|
||||
void (*done)(int status);
|
||||
};
|
||||
|
||||
void wget_init(void);
|
||||
int wget_get(const char *server, uint16_t port, const char *file,
|
||||
const struct wget_callbacks *c);
|
||||
|
||||
enum {
|
||||
WGET_OK,
|
||||
WGET_ALREADY_RUNNING,
|
||||
WGET_TIMEDOUT,
|
||||
WGET_ABORTED,
|
||||
WGET_CONNECT_FAILED,
|
||||
WGET_CLOSED
|
||||
};
|
||||
|
||||
#endif /* WGET_H_ */
|
|
@ -1,190 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark by Advancare,SL
|
||||
* 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
|
||||
* Battery and Temperature IPv6 Demo for Zolertia Z1
|
||||
* \author
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
* Joel Hoglund <joel@sics.se>
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "httpd-simple.h"
|
||||
#include "webserver-nogui.h"
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "dev/battery-sensor.h"
|
||||
#include "cc2420.h"
|
||||
#include "dev/leds.h"
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
float
|
||||
floor(float x)
|
||||
{
|
||||
if(x >= 0.0f) {
|
||||
return (float)((int)x);
|
||||
} else { return (float)((int)x - 1);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(web_sense_process, "Sense Web Demo");
|
||||
AUTOSTART_PROCESSES(&web_sense_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define HISTORY 16
|
||||
static int temperature[HISTORY];
|
||||
static int battery1[HISTORY];
|
||||
static int sensors_pos;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
get_battery(void)
|
||||
{
|
||||
return battery_sensor.value(0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
get_temp(void)
|
||||
{
|
||||
return temperature_sensor.value(0);
|
||||
}
|
||||
static float
|
||||
get_mybatt(void)
|
||||
{
|
||||
return (float)((get_battery() * 2.500 * 2) / 4096);
|
||||
}
|
||||
static float
|
||||
get_mytemp(void)
|
||||
{
|
||||
return (float)(((get_temp() * 2.500) / 4096) - 0.986) * 282;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const char *TOP = "<html><head><title>Contiki Web Sense</title></head><body>\n";
|
||||
static const char *BOTTOM = "</body></html>\n";
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Only one single request at time */
|
||||
static char buf[256];
|
||||
static int blen;
|
||||
#define ADD(...) do { \
|
||||
blen += snprintf(&buf[blen], sizeof(buf) - blen, __VA_ARGS__); \
|
||||
} while(0)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
generate_chart(const char *title, const char *unit, int min, int max,
|
||||
int *values)
|
||||
{
|
||||
int i;
|
||||
blen = 0;
|
||||
ADD("<h1>%s</h1>\n"
|
||||
"<img src=\"http://chart.apis.google.com/chart?"
|
||||
"cht=lc&chs=400x300&chxt=x,x,y,y&chxp=1,50|3,50&"
|
||||
"chxr=2,%d,%d|0,0,30&chds=%d,%d&chxl=1:|Time|3:|%s&chd=t:",
|
||||
title, min, max, min, max, unit);
|
||||
for(i = 0; i < HISTORY; i++) {
|
||||
ADD("%s%d", i > 0 ? "," : "", values[(sensors_pos + i) % HISTORY]);
|
||||
}
|
||||
ADD("\">");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(send_values(struct httpd_state *s))
|
||||
{
|
||||
PSOCK_BEGIN(&s->sout);
|
||||
|
||||
SEND_STRING(&s->sout, TOP);
|
||||
|
||||
if(strncmp(s->filename, "/index", 6) == 0 ||
|
||||
s->filename[1] == '\0') {
|
||||
/* Default page: show latest sensor values as text (does not
|
||||
require Internet connection to Google for charts). */
|
||||
blen = 0;
|
||||
float mybatt = get_mybatt();
|
||||
float mytemp = get_mytemp();
|
||||
ADD("<h1>Current readings</h1>\n"
|
||||
"Battery: %ld.%03d V<br>"
|
||||
"Temperature: %ld.%03d ° C",
|
||||
(long)mybatt, (unsigned)((mybatt - floor(mybatt)) * 1000),
|
||||
(long)mytemp, (unsigned)((mytemp - floor(mytemp)) * 1000));
|
||||
SEND_STRING(&s->sout, buf);
|
||||
} else if(s->filename[1] == '0') {
|
||||
/* Turn off leds */
|
||||
leds_off(LEDS_ALL);
|
||||
SEND_STRING(&s->sout, "Turned off leds!");
|
||||
} else if(s->filename[1] == '1') {
|
||||
/* Turn on leds */
|
||||
leds_on(LEDS_ALL);
|
||||
SEND_STRING(&s->sout, "Turned on leds!");
|
||||
} else {
|
||||
if(s->filename[1] != 't') {
|
||||
generate_chart("Battery", "mV", 0, 4000, battery1);
|
||||
SEND_STRING(&s->sout, buf);
|
||||
}
|
||||
if(s->filename[1] != 'b') {
|
||||
generate_chart("Temperature", "Celsius", 0, 50, temperature);
|
||||
SEND_STRING(&s->sout, buf);
|
||||
}
|
||||
}
|
||||
|
||||
SEND_STRING(&s->sout, BOTTOM);
|
||||
|
||||
PSOCK_END(&s->sout);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
httpd_simple_script_t
|
||||
httpd_simple_get_script(const char *name)
|
||||
{
|
||||
return send_values;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(web_sense_process, ev, data)
|
||||
{
|
||||
static struct etimer timer;
|
||||
PROCESS_BEGIN();
|
||||
cc2420_set_txpower(31);
|
||||
|
||||
sensors_pos = 0;
|
||||
process_start(&webserver_nogui_process, NULL);
|
||||
|
||||
etimer_set(&timer, CLOCK_SECOND * 2);
|
||||
SENSORS_ACTIVATE(battery_sensor);
|
||||
SENSORS_ACTIVATE(temperature_sensor);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
|
||||
etimer_reset(&timer);
|
||||
|
||||
battery1[sensors_pos] = get_mybatt() * 1000;
|
||||
temperature[sensors_pos] = get_mytemp();
|
||||
sensors_pos = (sensors_pos + 1) % HISTORY;
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,165 +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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* A simple program for testing the adxl345 on-board accelerometer of the
|
||||
* Zolertia Z1. Enables interrupts and registers callbacks for them. Then
|
||||
* starts a constantly running readout of acceleration data.
|
||||
* \author
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
* Enric M. Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/adxl345.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define LED_INT_ONTIME (CLOCK_SECOND / 2)
|
||||
#define ACCM_READ_INTERVAL CLOCK_SECOND
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static process_event_t led_off_event;
|
||||
static struct etimer led_etimer;
|
||||
static struct etimer et;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(accel_process, "Test Accel process");
|
||||
PROCESS(led_process, "LED handling process");
|
||||
AUTOSTART_PROCESSES(&accel_process, &led_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* As several interrupts can be mapped to one interrupt pin, when interrupt
|
||||
* strikes, the adxl345 interrupt source register is read. This function prints
|
||||
* out which interrupts occurred. Note that this will include all interrupts,
|
||||
* even those mapped to 'the other' pin, and those that will always signal even
|
||||
* if not enabled (such as watermark).
|
||||
*/
|
||||
void
|
||||
print_int(uint16_t reg)
|
||||
{
|
||||
if(reg & ADXL345_INT_FREEFALL) {
|
||||
printf("Freefall ");
|
||||
}
|
||||
if(reg & ADXL345_INT_INACTIVITY) {
|
||||
printf("InActivity ");
|
||||
}
|
||||
if(reg & ADXL345_INT_ACTIVITY) {
|
||||
printf("Activity ");
|
||||
}
|
||||
if(reg & ADXL345_INT_DOUBLETAP) {
|
||||
printf("DoubleTap ");
|
||||
}
|
||||
if(reg & ADXL345_INT_TAP) {
|
||||
printf("Tap ");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* accelerometer free fall detection callback */
|
||||
|
||||
void
|
||||
accm_ff_cb(uint8_t reg)
|
||||
{
|
||||
leds_on(LEDS_BLUE);
|
||||
process_post(&led_process, led_off_event, NULL);
|
||||
printf("~~[%u] Freefall detected! (0x%02X) -- ",
|
||||
((uint16_t)clock_time()) / 128, reg);
|
||||
print_int(reg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* accelerometer tap and double tap detection callback */
|
||||
|
||||
void
|
||||
accm_tap_cb(uint8_t reg)
|
||||
{
|
||||
process_post(&led_process, led_off_event, NULL);
|
||||
if(reg & ADXL345_INT_DOUBLETAP) {
|
||||
leds_on(LEDS_GREEN);
|
||||
printf("~~[%u] DoubleTap detected! (0x%02X) -- ",
|
||||
((uint16_t)clock_time()) / 128, reg);
|
||||
} else {
|
||||
leds_on(LEDS_RED);
|
||||
printf("~~[%u] Tap detected! (0x%02X) -- ",
|
||||
((uint16_t)clock_time()) / 128, reg);
|
||||
}
|
||||
print_int(reg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(led_process, ev, data) {
|
||||
PROCESS_BEGIN();
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == led_off_event);
|
||||
etimer_set(&led_etimer, LED_INT_ONTIME);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&led_etimer));
|
||||
leds_off(LEDS_RED + LEDS_GREEN + LEDS_BLUE);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Main process, setups */
|
||||
PROCESS_THREAD(accel_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
int16_t x, y, z;
|
||||
|
||||
/* Register the event used for lighting up an LED when interrupt strikes. */
|
||||
led_off_event = process_alloc_event();
|
||||
|
||||
/* Start and setup the accelerometer with default values, eg no interrupts
|
||||
* enabled.
|
||||
*/
|
||||
SENSORS_ACTIVATE(adxl345);
|
||||
|
||||
/* Register the callback functions for each interrupt */
|
||||
ACCM_REGISTER_INT1_CB(accm_ff_cb);
|
||||
ACCM_REGISTER_INT2_CB(accm_tap_cb);
|
||||
|
||||
/* Set what strikes the corresponding interrupts. Several interrupts per
|
||||
* pin is possible. For the eight possible interrupts, see adxl345.h and
|
||||
* adxl345 datasheet.
|
||||
*/
|
||||
accm_set_irq(ADXL345_INT_FREEFALL, ADXL345_INT_TAP + ADXL345_INT_DOUBLETAP);
|
||||
|
||||
while(1) {
|
||||
x = adxl345.value(X_AXIS);
|
||||
y = adxl345.value(Y_AXIS);
|
||||
z = adxl345.value(Z_AXIS);
|
||||
printf("x: %d y: %d z: %d\n", x, y, z);
|
||||
|
||||
etimer_set(&et, ACCM_READ_INTERVAL);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
|
||||
* 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 internal MSP430 battery sensor on the Zolertia Z1 Platform.
|
||||
* \author
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/battery-sensor.h"
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
float
|
||||
floor(float x)
|
||||
{
|
||||
if(x >= 0.0f) {
|
||||
return (float)((int)x);
|
||||
} else {
|
||||
return (float)((int)x - 1);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_battery_process, "Battery Sensor Test");
|
||||
AUTOSTART_PROCESSES(&test_battery_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_battery_process, ev, data)
|
||||
{
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
SENSORS_ACTIVATE(battery_sensor);
|
||||
|
||||
while(1) {
|
||||
uint16_t bateria = battery_sensor.value(0);
|
||||
float mv = (bateria * 2.500 * 2) / 4096;
|
||||
printf("Battery: %i (%ld.%03d mV)\n", bateria, (long)mv,
|
||||
(unsigned)((mv - floor(mv)) * 1000));
|
||||
}
|
||||
|
||||
SENSORS_DEACTIVATE(battery_sensor);
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
|
||||
* 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 quick program for testing the light ziglet driver in the Z1 platform
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/i2cmaster.h"
|
||||
#include "dev/light-ziglet.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define SENSOR_READ_INTERVAL (CLOCK_SECOND / 2)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_process, "Test light ziglet process");
|
||||
AUTOSTART_PROCESSES(&test_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Initialize driver and set a slower data rate */
|
||||
light_ziglet_init();
|
||||
i2c_setrate(I2C_PRESC_100KHZ_LSB, I2C_PRESC_100KHZ_MSB);
|
||||
|
||||
while(1) {
|
||||
etimer_set(&et, SENSOR_READ_INTERVAL);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
printf("Light = %u\n", light_ziglet_read());
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,77 +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
|
||||
* An example of how to use the button and read the ADC ports
|
||||
* \author
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/z1-phidgets.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_button_process, "Test Button & ADC");
|
||||
AUTOSTART_PROCESSES(&test_button_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_button_process, ev, data)
|
||||
{
|
||||
/* static struct etimer et; */
|
||||
PROCESS_BEGIN();
|
||||
SENSORS_ACTIVATE(phidgets);
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
|
||||
while(1) {
|
||||
printf("Please press the User Button\n");
|
||||
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
|
||||
data == &button_sensor);
|
||||
|
||||
leds_toggle(LEDS_GREEN);
|
||||
|
||||
printf("Phidget 5V 1:%d\n", phidgets.value(PHIDGET5V_1));
|
||||
printf("Phidget 5V 2:%d\n", phidgets.value(PHIDGET5V_2));
|
||||
printf("Phidget 3V 1:%d\n", phidgets.value(PHIDGET3V_1));
|
||||
printf("Phidget 3V 2:%d\n", phidgets.value(PHIDGET3V_2));
|
||||
|
||||
if(phidgets.value(PHIDGET3V_1) < 100) {
|
||||
leds_on(LEDS_RED);
|
||||
} else {
|
||||
leds_off(LEDS_RED);
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
|
||||
* 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 Potentiometer in Zolertia Z1 Starter Platform.
|
||||
* \author
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/potentiometer-sensor.h"
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_potent_process, "Testing Potentiometer in Z1SP");
|
||||
AUTOSTART_PROCESSES(&test_potent_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_potent_process, ev, data)
|
||||
{
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
SENSORS_ACTIVATE(potentiometer_sensor);
|
||||
|
||||
while(1) {
|
||||
uint16_t value = potentiometer_sensor.value(0);
|
||||
|
||||
printf("Potentiometer Value: %u\n", value);
|
||||
}
|
||||
|
||||
SENSORS_DEACTIVATE(potentiometer_sensor);
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* 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 quick program for testing a reed sensor.
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "reed-sensor.h"
|
||||
#define REED_READ_INTERVAL (CLOCK_SECOND / 4)
|
||||
#define REED_EXAMPLE_EVENT 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_process, "Reed test process");
|
||||
AUTOSTART_PROCESSES(&test_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
SENSORS_ACTIVATE(reed_sensor);
|
||||
#if REED_EXAMPLE_EVENT
|
||||
reed_sensor.configure(REED_SENSOR_MODE, REED_SENSOR_EVENT_MODE);
|
||||
#else
|
||||
etimer_set(&et, REED_READ_INTERVAL);
|
||||
#endif
|
||||
|
||||
while(1) {
|
||||
|
||||
PROCESS_YIELD();
|
||||
|
||||
if(ev == PROCESS_EVENT_TIMER) {
|
||||
printf("Reed poll status [%d]\n", reed_sensor.value(REED_SENSOR_VAL));
|
||||
etimer_restart(&et);
|
||||
} else if(ev == reed_sensor_event_changed) {
|
||||
printf("Reed sensor event --> %d\n", (*((int *)data)));
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
|
||||
* 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 quick program for testing a generic relay device connected in the
|
||||
* phidget port
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/relay-phidget.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define RELAY_INTERVAL (CLOCK_SECOND)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_process, "Relay test process");
|
||||
AUTOSTART_PROCESSES(&test_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
static int8_t status;
|
||||
|
||||
PROCESS_THREAD(test_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Selects P6.7 as control pin of the relay module */
|
||||
relay_enable(7);
|
||||
|
||||
while(1) {
|
||||
etimer_set(&et, RELAY_INTERVAL);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
|
||||
status = relay_toggle();
|
||||
PRINTF("Relay [%d]\n", status);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
|
||||
* 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 SHT11 sensor on the Zolertia Z1 Platform.
|
||||
* \author
|
||||
* Nicolas Tsiftes <nvt@sics.se>
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/sht11/sht11.h"
|
||||
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_sht11_process, "SHT11 test");
|
||||
AUTOSTART_PROCESSES(&test_sht11_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_sht11_process, ev, data)
|
||||
{
|
||||
static struct etimer et;
|
||||
static unsigned rh;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
sht11_init();
|
||||
|
||||
for(etimer_set(&et, CLOCK_SECOND);; etimer_reset(&et)) {
|
||||
PROCESS_YIELD();
|
||||
printf("Temperature: %u degrees Celsius\n",
|
||||
(unsigned)(-39.60 + 0.01 * sht11_temp()));
|
||||
rh = sht11_humidity();
|
||||
printf("Rel. humidity: %u%%\n",
|
||||
(unsigned)(-4 + 0.0405 * rh - 2.8e-6 * (rh * rh)));
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* 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 quick program for testing the SHT25 temperature and humidity sensor
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/sht25.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_sht25_process, "SHT25 test");
|
||||
AUTOSTART_PROCESSES(&test_sht25_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_sht25_process, ev, data)
|
||||
{
|
||||
int16_t temperature, humidity;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
SENSORS_ACTIVATE(sht25);
|
||||
|
||||
while(1) {
|
||||
etimer_set(&et, CLOCK_SECOND);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
temperature = sht25.value(SHT25_VAL_TEMP);
|
||||
printf("Temperature %d.%d ºC\n", temperature / 100, temperature % 100);
|
||||
humidity = sht25.value(SHT25_VAL_HUM);
|
||||
printf("Humidity %d.%d %%RH\n", humidity / 100, humidity % 100);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Jelmer Tiete.
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* A simple program for testing the TLC59116 I2C led driver.
|
||||
* All 16 outputs will sequencially light up.
|
||||
* \author
|
||||
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/tlc59116.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BLINK_INTERVAL (CLOCK_SECOND / 25)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(tlc59116_process, "Test tlc59116 process");
|
||||
AUTOSTART_PROCESSES(&tlc59116_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Main process, setups */
|
||||
|
||||
static struct etimer et;
|
||||
static uint8_t count = 0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(tlc59116_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
{
|
||||
|
||||
/* Start and setup the led driver with default values, eg outputs on and pwm enabled and 0. */
|
||||
tlc59116_init();
|
||||
|
||||
while(1) {
|
||||
|
||||
tlc59116_led(count, 0x00);
|
||||
tlc59116_led((count + 1) % 16, 0x20);
|
||||
tlc59116_led((count + 2) % 16, 0x40);
|
||||
tlc59116_led((count + 3) % 16, 0xFF);
|
||||
|
||||
count++;
|
||||
if(count > 15) {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
etimer_set(&et, BLINK_INTERVAL);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
}
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2016, Zolertia <http://www.zolertia.com>
|
||||
* 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 quick program for testing the tmp102 sensor in the Z1 platform
|
||||
* \author
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/i2cmaster.h"
|
||||
#include "dev/tmp102.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define TMP102_READ_INTERVAL (CLOCK_SECOND / 2)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(temp_process, "TMP102 Temperature sensor process");
|
||||
AUTOSTART_PROCESSES(&temp_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(temp_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
int16_t temp;
|
||||
|
||||
SENSORS_ACTIVATE(tmp102);
|
||||
|
||||
while(1) {
|
||||
etimer_set(&et, TMP102_READ_INTERVAL);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
temp = tmp102.value(TMP102_READ);
|
||||
printf("Temp = %d\n", temp);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,8 +1,6 @@
|
|||
DEFINES=PROJECT_CONF_H=\"project-conf.h\"
|
||||
|
||||
ifndef TARGET
|
||||
TARGET = z1
|
||||
endif
|
||||
TARGET ?= sky
|
||||
|
||||
CONTIKI = ../..
|
||||
|
||||
|
|
|
@ -4,11 +4,8 @@ TOOLSDIR=../../tools
|
|||
EXAMPLES = \
|
||||
hello-world/native \
|
||||
hello-world/sky \
|
||||
hello-world/z1 \
|
||||
eeprom-test/native \
|
||||
platform-specific/zolertia/z1/z1 \
|
||||
ipv6/multicast/sky \
|
||||
sensniff/z1 \
|
||||
|
||||
TOOLS=
|
||||
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<simconf>
|
||||
<simulation>
|
||||
<title>Hello World (Z1)</title>
|
||||
<randomseed>generated</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
org.contikios.cooja.radiomediums.UDGM
|
||||
<transmitting_range>50.0</transmitting_range>
|
||||
<interference_range>100.0</interference_range>
|
||||
<success_ratio_tx>1.0</success_ratio_tx>
|
||||
<success_ratio_rx>1.0</success_ratio_rx>
|
||||
</radiomedium>
|
||||
<events>
|
||||
<logoutput>40000</logoutput>
|
||||
</events>
|
||||
<motetype>
|
||||
org.contikios.cooja.mspmote.Z1MoteType
|
||||
<identifier>z11</identifier>
|
||||
<description>Z1 Mote Type #z11</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/hello-world/hello-world.c</source>
|
||||
<commands EXPORT="discard">make hello-world.z1 TARGET=z1</commands>
|
||||
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/hello-world/hello-world.z1</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.RimeAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.MoteAttributes</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.Msp802154Radio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDefaultSerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspLED</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
|
||||
</motetype>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>94.96401380574989</x>
|
||||
<y>21.247662337471553</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>1</id>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.SimControl
|
||||
<width>280</width>
|
||||
<z>2</z>
|
||||
<height>160</height>
|
||||
<location_x>38</location_x>
|
||||
<location_y>13</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.LogListener
|
||||
<plugin_config>
|
||||
<filter />
|
||||
</plugin_config>
|
||||
<width>680</width>
|
||||
<z>1</z>
|
||||
<height>240</height>
|
||||
<location_x>109</location_x>
|
||||
<location_y>377</location_y>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.ScriptRunner
|
||||
<plugin_config>
|
||||
<scriptfile>[CONFIG_DIR]/hello-world.js</scriptfile>
|
||||
<active>true</active>
|
||||
</plugin_config>
|
||||
<width>600</width>
|
||||
<z>0</z>
|
||||
<height>700</height>
|
||||
<location_x>330</location_x>
|
||||
<location_y>24</location_y>
|
||||
</plugin>
|
||||
</simconf>
|
||||
|
|
@ -22,8 +22,8 @@
|
|||
</events>
|
||||
<motetype>
|
||||
org.contikios.cooja.contikimote.ContikiMoteType
|
||||
<identifier>z11</identifier>
|
||||
<description>Cooja Mote Type #z11</description>
|
||||
<identifier>mtype1</identifier>
|
||||
<description>Cooja Mote Type #mtype1</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c</source>
|
||||
<commands EXPORT="discard">make TARGET=cooja clean
|
||||
make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</commands>
|
||||
|
@ -61,7 +61,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -79,7 +79,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -97,7 +97,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -115,7 +115,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -133,7 +133,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -151,7 +151,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -169,7 +169,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -187,7 +187,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype1</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -205,7 +205,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype1</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
|
|
|
@ -22,13 +22,13 @@
|
|||
</events>
|
||||
<motetype>
|
||||
org.contikios.cooja.contikimote.ContikiMoteType
|
||||
<identifier>z11</identifier>
|
||||
<description>Cooja Mote Type #z11</description>
|
||||
<identifier>mtype11</identifier>
|
||||
<description>Cooja Mote Type #mtype11</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c</source>
|
||||
<commands EXPORT="discard">make TARGET=cooja clean
|
||||
make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</commands>
|
||||
<firmware
|
||||
EXPORT="copy">[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.z1</firmware>
|
||||
EXPORT="copy">[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.mtype1</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Battery</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiVib</moteinterface>
|
||||
|
@ -63,7 +63,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -81,7 +81,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -99,7 +99,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -117,7 +117,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -135,7 +135,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -153,7 +153,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -171,7 +171,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -189,7 +189,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -207,7 +207,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=1 MAKE_WITH_SECURITY=0</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
</events>
|
||||
<motetype>
|
||||
org.contikios.cooja.contikimote.ContikiMoteType
|
||||
<identifier>z11</identifier>
|
||||
<description>Cooja Mote Type #z11</description>
|
||||
<identifier>mtype11</identifier>
|
||||
<description>Cooja Mote Type #mtype11</description>
|
||||
<source EXPORT="discard">[CONTIKI_DIR]/examples/ipv6/rpl-tsch/node.c</source>
|
||||
<commands EXPORT="discard">make TARGET=cooja clean
|
||||
make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</commands>
|
||||
|
@ -61,7 +61,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -79,7 +79,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -97,7 +97,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -115,7 +115,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -133,7 +133,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -151,7 +151,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -169,7 +169,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -187,7 +187,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
<mote>
|
||||
<breakpoints />
|
||||
|
@ -205,7 +205,7 @@ make node.cooja TARGET=cooja MAKE_WITH_ORCHESTRA=0 MAKE_WITH_SECURITY=1</command
|
|||
org.contikios.cooja.contikimote.interfaces.ContikiRadio
|
||||
<bitrate>250.0</bitrate>
|
||||
</interface_config>
|
||||
<motetype_identifier>z11</motetype_identifier>
|
||||
<motetype_identifier>mtype11</motetype_identifier>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
|
|
|
@ -58,7 +58,7 @@ typedef struct {
|
|||
#define NODE2 {{ 0xc1, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}
|
||||
|
||||
/*
|
||||
* The following vectors are obtained with
|
||||
* The following vectors are obtained with the former
|
||||
* examples/ipv6/rpl-tsch/rpl-tsch-z1.csc except for the enhanced beacon for
|
||||
* ALL_ENABLED. The raw frame was generated with rpl-tsch-cooja.csc because
|
||||
* there is an issue in TSCH Timeslot IE generated by z1 mote.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue