added Z1 platform

This commit is contained in:
joxe 2010-08-24 16:26:38 +00:00
parent b04ebb2b29
commit 645c48a332
15 changed files with 2530 additions and 0 deletions

121
platform/z1/Makefile.z1 Normal file
View File

@ -0,0 +1,121 @@
# $Id: Makefile.z1,v 1.1 2010/08/24 16:26:38 joxe Exp $
CFLAGS+=-Os -g
ARCH=msp430.c leds.c watchdog.c \
spix.c cc2420.c cc2420-aes.c cc2420-arch.c cc2420-arch-sfd.c\
node-id.c sensors.c button-sensor.c cfs-coffee.c \
radio-sensor.c uart0x.c uart0-putchar.c uip-ipchksum.c \
checkpoint-arch.c slip.c slip_uart0.c
CONTIKI_TARGET_DIRS = . dev apps net
ifndef CONTIKI_TARGET_MAIN
CONTIKI_TARGET_MAIN = contiki-z1-main.c
endif
ifdef UIP_CONF_IPV6
CFLAGS += -DWITH_UIP6=1
endif
CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS) $(CONTIKI_TARGET_MAIN)
MCU=msp430x2617
include $(CONTIKI)/cpu/msp430/Makefile.msp430
contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
# $(AR) rcf $@ $^
NUMPAR=20
IHEXFILE=tmpimage.ihex
# If we are not running under Windows, we assume Linux
ifndef MOTELIST
USBDEVPREFIX=
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux
MOTELIST = $(CONTIKI)/tools/z1/motelist-z1
BSL = $(CONTIKI)/tools/z1/z1-bsl-nopic --z1
BSL_FILETYPE = -I
MOTES = $(shell $(MOTELIST) -c 2>&- | \
cut -f 2 -d , | \
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')
CMOTES=$(MOTES)
endif
z1-motelist:
$(MOTELIST)
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

66
platform/z1/apps/blink.c Normal file
View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* $Id: blink.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
/**
* \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();
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,81 @@
/*
* 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.
*
* $Id: burn-nodeid.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
/**
* \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 "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
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();
}
/*---------------------------------------------------------------------------*/

174
platform/z1/apps/fader.c Normal file
View File

@ -0,0 +1,174 @@
/*
* 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>
*
* $Id: fader.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
#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;
}
/*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,77 @@
/*
* 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 Tmote Sky platform.
* \author
* Nicolas Tsiftes <nvt@sics.se>
*/
#ifndef CFS_COFFEE_ARCH_H
#define CFS_COFFEE_ARCH_H
#include "contiki-conf.h"
#include "dev/xmem.h"
#include "dev/watchdog.h"
/* Coffee configuration parameters. */
#define COFFEE_SECTOR_SIZE 65536UL
#define COFFEE_PAGE_SIZE 256UL
#define COFFEE_START COFFEE_SECTOR_SIZE
#define COFFEE_SIZE (1024UL * 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
#define COFFEE_WATCHDOG_START() watchdog_start()
#define COFFEE_WATCHDOG_STOP() watchdog_stop()
/* 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 */

View File

@ -0,0 +1,372 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Checkpoint library implementation for the Tmote Sky platform.
* \author
* Fredrik Osterlind <fros@sics.se>
*/
#include "contiki.h"
#include "lib/checkpoint.h"
#include "sys/rtimer.h"
#include "sys/mt.h"
#include "cfs/cfs.h"
#include "cfs/cfs-coffee.h"
#include "dev/leds.h"
#include "dev/watchdog.h"
#include <io.h>
#include <signal.h>
#include <stdio.h>
#define DEBUG 1
#if DEBUG
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
#define COMMAND_ROLLBACK 1
#define COMMAND_CHECKPOINT 2
#define COMMAND_TBR 3
#define DATA_AS_HEX 0 /* If false, store binary data */
#define INCLUDE_RAM 1 /* Less then 10240 bytes */
#define INCLUDE_TIMERS 1 /* 16 bytes */
#define INCLUDE_LEDS 1 /* 1 bytes */
// 8kB memory
#define RAM_START 0x1100
#define RAM_END 0x30FF
#define STOP_TIMERS() TACTL &= ~(MC1); TBCTL &= ~(MC1); watchdog_stop();
#define START_TIMERS() watchdog_start(); TACTL |= MC1; TBCTL |= MC1;
static struct mt_thread checkpoint_thread;
static uint8_t preset_cmd;
static int preset_fd;
typedef union {
unsigned char u8[2];
unsigned short u16;
} word_union_t;
/*---------------------------------------------------------------------------*/
static void
write_byte(int fd, uint8_t c)
{
#if DATA_AS_HEX
uint8_t hex[2];
sprintf(hex, "%02x", c);
if(cfs_write(fd, hex, 2) != 2) {
printf("err #1\n");
}
#else /* DATA_AS_HEX */
if(cfs_write(fd, &c, 1) != 1) {
printf("err #2\n");
}
#endif /* DATA_AS_HEX */
}/*---------------------------------------------------------------------------*/
#if 0
static void
write_array(int fd, unsigned char *mem, uint16_t len)
{
#if DATA_AS_HEX
int i;
for(i = 0; i < len; i++) {
write_byte(fd, mem[i]);
}
#else /* DATA_AS_HEX */
cfs_write(fd, mem, len);
#endif /* DATA_AS_HEX */
}
#endif /* 0 */
/*---------------------------------------------------------------------------*/
static void
write_word(int fd, uint16_t w)
{
word_union_t tmp;
tmp.u16 = w;
write_byte(fd, tmp.u8[0]);
write_byte(fd, tmp.u8[1]);
}
/*---------------------------------------------------------------------------*/
static uint8_t
read_byte(int fd)
{
#if DATA_AS_HEX
uint8_t hex[2];
cfs_read(fd, hex, 2);
if(hex[0] >= 'A' && hex[0] <= 'F') {
hex[0] = (hex[0] - 'A' + 0xa);
} else if(hex[0] >= 'a' && hex[0] <= 'f') {
hex[0] = (hex[0] - 'a' + 0xa);
} else {
hex[0] = (hex[0] - '0');
}
if(hex[1] >= 'A' && hex[1] <= 'F') {
hex[1] = (hex[1] - 'A' + 0xa);
} else if(hex[1] >= 'a' && hex[1] <= 'f') {
hex[1] = (hex[1] - 'a' + 0xa);
} else {
hex[1] = (hex[1] - '0');
}
return (uint8_t)((hex[0]<<4)&0xf0) | (hex[1]&0x0f);
#else /* DATA_AS_HEX */
uint8_t c;
cfs_read(fd, &c, 1);
return c;
#endif /* DATA_AS_HEX */
}
/*---------------------------------------------------------------------------*/
static uint16_t
read_word(int fd)
{
word_union_t tmp;
tmp.u8[0] = read_byte(fd);
tmp.u8[1] = read_byte(fd);
return tmp.u16;
}
/*---------------------------------------------------------------------------*/
static void
thread_checkpoint(int fd)
{
#if INCLUDE_RAM
unsigned char *addr;
uint16_t size = 0;
unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack;
unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1;
unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size);
unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
#endif /* INCLUDE_RAM */
/*printf("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/
/*printf("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/
/* RAM */
#if INCLUDE_RAM
for(addr = (unsigned char *)RAM_START;
addr < (unsigned char *)RAM_END;
addr++) {
if((addr >= thread_mem_start && addr <= thread_mem_end)) {
/* Writing dummy memory */
/*write_byte(fd, 1);*/
continue;
}
if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
/* Writing dummy memory */
/*write_byte(fd, 2);*/
continue;
}
/* TODO Use write_array() */
write_byte(fd, *addr);
if(((int)addr % 512) == 0) {
PRINTF(".");
}
}
#endif /* INCLUDE_RAM */
/* Timers */
#if INCLUDE_TIMERS
write_word(fd, TACTL);
write_word(fd, TACCTL1);
write_word(fd, TACCR1);
write_word(fd, TAR);
write_word(fd, TBCTL);
write_word(fd, TBCCTL1);
write_word(fd, TBCCR1);
write_word(fd, TBR);
#endif /* INCLUDE_TIMERS */
/* LEDs */
#if INCLUDE_LEDS
write_byte(fd, leds_arch_get());
#endif /* INCLUDE_LEDS */
/* Radio */
/* ADC */
/* ... */
write_byte(fd, -1); /* Coffee padding byte */
}
/*---------------------------------------------------------------------------*/
static void
thread_rollback(int fd)
{
#if INCLUDE_RAM
unsigned char *addr;
uint16_t size = 0;
unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack;
unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1;
unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size);
unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
#endif /* INCLUDE_RAM */
/*printf("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/
/*printf("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/
/* RAM */
#if INCLUDE_RAM
for(addr = (unsigned char *)RAM_START;
addr < (unsigned char *)RAM_END;
addr++) {
if((addr >= thread_mem_start && addr <= thread_mem_end)) {
/* Ignoring incoming memory */
/*read_byte(fd);*/
continue;
}
if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
/* Ignoring incoming memory */
/*read_byte(fd);*/
continue;
}
*addr = read_byte(fd);
if(((int)addr % 512) == 0) {
PRINTF(".");
}
}
#endif /* INCLUDE_RAM */
/* Timers */
#if INCLUDE_TIMERS
TACTL = read_word(fd);
TACCTL1 = read_word(fd);
TACCR1 = read_word(fd);
TAR = read_word(fd);
TBCTL = read_word(fd);
TBCCTL1 = read_word(fd);
TBCCR1 = read_word(fd);
TBR = read_word(fd);
#endif /* INCLUDE_TIMERS */
/* LEDs */
#if INCLUDE_LEDS
leds_arch_set(read_byte(fd));
#endif /* INCLUDE_LEDS */
/* Radio */
/* ADC */
/* ... */
read_byte(fd); /* Coffee padding byte */
}
/*---------------------------------------------------------------------------*/
static void
thread_loop(void *data)
{
uint8_t cmd;
int fd;
while(1) {
/* Store command and file descriptor on stack */
cmd = preset_cmd;
fd = preset_fd;
/* Handle command */
if(cmd == COMMAND_ROLLBACK) {
PRINTF("Rolling back");
thread_rollback(fd);
PRINTF(" done!\n");
} else if(cmd == COMMAND_CHECKPOINT) {
PRINTF("Checkpointing");
thread_checkpoint(fd);
PRINTF(" done!\n");
} else if(cmd == COMMAND_TBR) {
PRINTF("Writing TBR");
write_word(fd, TBR);
PRINTF(" done!\n");
} else {
printf("Error: unknown command: %u\n", cmd);
}
/* Return to main Contiki thread */
mt_yield();
}
}
/*---------------------------------------------------------------------------*/
int
checkpoint_arch_size()
{
return 10258;
}
/*---------------------------------------------------------------------------*/
void
checkpoint_arch_checkpoint(int fd)
{
STOP_TIMERS();
preset_cmd = COMMAND_CHECKPOINT;
preset_fd = fd;
mt_exec(&checkpoint_thread);
START_TIMERS();
}
/*---------------------------------------------------------------------------*/
void
checkpoint_arch_rollback(int fd)
{
STOP_TIMERS();
preset_cmd = COMMAND_ROLLBACK;
preset_fd = fd;
mt_exec(&checkpoint_thread);
START_TIMERS();
}
/*---------------------------------------------------------------------------*/
void
checkpoint_arch_init(void)
{
mt_init();
mt_start(&checkpoint_thread, thread_loop, NULL);
/*mt_stop(&checkpoint_thread);*/
/*mt_remove();*/
}
/*---------------------------------------------------------------------------*/

197
platform/z1/contiki-conf.h Normal file
View File

@ -0,0 +1,197 @@
/*
* 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"
#define XMAC_CONF_COMPOWER 1
#define CXMAC_CONF_COMPOWER 1
#if WITH_UIP6
/* Network setup for IPv6 */
#define NETSTACK_CONF_NETWORK sicslowpan_driver
/* #define NETSTACK_CONF_MAC nullmac_driver */
/* #define NETSTACK_CONF_RDC sicslowmac_driver */
#define NETSTACK_CONF_MAC csma_driver
#define NETSTACK_CONF_RDC contikimac_driver
#define NETSTACK_CONF_RADIO cc2420_driver
#define NETSTACK_CONF_FRAMER framer_802154
#define CC2420_CONF_AUTOACK 1
#define MAC_CONF_CHANNEL_CHECK_RATE 8
#define RIME_CONF_NO_POLITE_ANNOUCEMENTS 0
#define CXMAC_CONF_ANNOUNCEMENTS 0
#define XMAC_CONF_ANNOUNCEMENTS 0
#define QUEUEBUF_CONF_NUM 4
#else /* WITH_UIP6 */
/* Network setup for non-IPv6 (rime). */
#define NETSTACK_CONF_NETWORK rime_driver
#define NETSTACK_CONF_MAC csma_driver
/* #define NETSTACK_CONF_RDC contikimac_driver */
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_FRAMER framer_802154
#define CC2420_CONF_AUTOACK 0
#define MAC_CONF_CHANNEL_CHECK_RATE 8
#define COLLECT_CONF_ANNOUNCEMENTS 1
#define RIME_CONF_NO_POLITE_ANNOUCEMENTS 0
#define CXMAC_CONF_ANNOUNCEMENTS 0
#define XMAC_CONF_ANNOUNCEMENTS 0
#define CONTIKIMAC_CONF_ANNOUNCEMENTS 0
#define CONTIKIMAC_CONF_COMPOWER 1
#define XMAC_CONF_COMPOWER 1
#define CXMAC_CONF_COMPOWER 1
#define COLLECT_NEIGHBOR_CONF_MAX_NEIGHBORS 32
#define QUEUEBUF_CONF_NUM 8
#endif /* WITH_UIP6 */
#define PACKETBUF_CONF_ATTRS_INLINE 1
#ifndef RF_CHANNEL
#define RF_CHANNEL 26
#endif /* RF_CHANNEL */
#define IEEE802154_CONF_PANID 0xABCD
#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 0
#define ELFLOADER_CONF_TEXT_IN_ROM 0
#define ELFLOADER_CONF_DATAMEMORY_SIZE 0x400
#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x800
#define CCIF
#define CLIF
#define CC_CONF_INLINE inline
#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.
#ifdef WITH_UIP6
#define RIMEADDR_CONF_SIZE 8
#define UIP_CONF_LL_802154 1
#define UIP_CONF_LLH_LEN 0
#define UIP_CONF_ROUTER 1
#define UIP_CONF_IPV6_RPL 1
/* Handle 10 neighbors */
#define UIP_CONF_DS6_NBR_NBU 15
/* Handle 10 routes */
#define UIP_CONF_DS6_ROUTE_NBU 15
#define UIP_CONF_ND6_SEND_RA 0
#define UIP_CONF_ND6_REACHABLE_TIME 600000
#define UIP_CONF_ND6_RETRANS_TIMER 10000
#define UIP_CONF_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_ND6_MAX_PREFIXES 3
#define UIP_CONF_ND6_MAX_NEIGHBORS 4
#define UIP_CONF_ND6_MAX_DEFROUTERS 2
#define UIP_CONF_IP_FORWARD 0
#define UIP_CONF_BUFFER_SIZE 140
#define SICSLOWPAN_CONF_COMPRESSION_IPV6 0
#define SICSLOWPAN_CONF_COMPRESSION_HC1 1
#define SICSLOWPAN_CONF_COMPRESSION_HC01 2
#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_CONVENTIONAL_MAC 1
#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2
#else /* WITH_UIP6 */
#define UIP_CONF_IP_FORWARD 1
#define UIP_CONF_BUFFER_SIZE 108
#endif /* WITH_UIP6 */
#define UIP_CONF_ICMP_DEST_UNREACH 1
#define UIP_CONF_DHCP_LIGHT
#define UIP_CONF_LLH_LEN 0
#define UIP_CONF_RECEIVE_WINDOW 48
#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
#ifdef PROJECT_CONF_H
#include PROJECT_CONF_H
#endif /* PROJECT_CONF_H */
#endif /* CONTIKI_CONF_H */

View File

@ -0,0 +1,483 @@
/*
* 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.
*
* @(#)$Id: contiki-z1-main.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h> //Enric_Joakim
#include <io.h>
#include "contiki.h"
#include "dev/cc2420.h"
#include "dev/leds.h"
#include "dev/serial-line.h"
#include "dev/slip.h"
#include "dev/uart0.h"
#include "dev/watchdog.h"
#if 0
//todo
#include "dev/xmem.h"
#endif
#include "lib/random.h"
#include "net/netstack.h"
#include "net/mac/frame802154.h"
#if WITH_UIP6
#include "net/uip-ds6.h"
#endif /* WITH_UIP6 */
#include "net/rime.h"
#include "node-id.h"
#include "cfs-coffee-arch.h"
#include "cfs/cfs-coffee.h"
#include "sys/autostart.h"
#include "sys/profile.h"
#include "dev/battery-sensor.h"
#include "dev/button-sensor.h"
#include "dev/sht11-sensor.h"
SENSORS(&button_sensor);
#if DCOSYNCH_CONF_ENABLED
static struct timer mgt_timer;
#endif
#ifndef WITH_UIP
#define WITH_UIP 0
#endif
#if WITH_UIP
#include "net/uip.h"
#include "net/uip-fw.h"
#include "net/uip-fw-drv.h"
#include "net/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 /* WITH_UIP */
#define UIP_OVER_MESH_CHANNEL 8
#if WITH_UIP
static uint8_t is_gateway;
#endif /* WITH_UIP */
#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
/*---------------------------------------------------------------------------*/
#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); }
/*---------------------------------------------------------------------------*/
#ifndef RF_CHANNEL
#define RF_CHANNEL 26
#endif
/*---------------------------------------------------------------------------*/
#if 0
void
force_inclusion(int d1, int d2)
{
snprintf(NULL, 0, "%d", d1 % d2);
}
#endif
/*---------------------------------------------------------------------------*/
static void
set_rime_addr(void)
{
rimeaddr_t addr;
int i;
memset(&addr, 0, sizeof(rimeaddr_t));
#if UIP_CONF_IPV6
memcpy(addr.u8, node_mac, sizeof(addr.u8));
#else
if(node_id == 0) {
for(i = 0; i < sizeof(rimeaddr_t); ++i) {
addr.u8[i] = node_mac[7 - i];
}
} else {
addr.u8[0] = node_id & 0xff;
addr.u8[1] = node_id >> 8;
}
#endif
rimeaddr_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 WITH_UIP
static void
set_gateway(void)
{
if(!is_gateway) {
leds_on(LEDS_RED);
printf("%d.%d: making myself the IP network gateway.\n\n",
rimeaddr_node_addr.u8[0], rimeaddr_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(&rimeaddr_node_addr);
uip_over_mesh_make_announced_gateway();
is_gateway = 1;
}
}
#endif /* WITH_UIP */
/*---------------------------------------------------------------------------*/
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(115200)); /* Must come before first printf */
#if WITH_UIP
slip_arch_init(BAUD2UBR(115200));
#endif /* WITH_UIP */
/* XXX hack: Fix it so that the 802.15.4 MAC address is compatible
with an Ethernet MAC address - byte 0 (byte 2 in the DS ID)
cannot be odd. */
//Enric node_mac[2] &= 0xfe;
node_mac[0] = 0x00;
node_mac[1] = 0x12;
node_mac[2] = 0x76;
node_mac[3] = 0x01;
node_mac[4] = 0x02;
node_mac[5] = 0x03;
node_mac[2] = 0x04;
node_mac[7] = 0x05;
//xmem_init(); TODO
rtimer_init();
/*
* Hardware initialization done!
*/
/* Restore node id if such has been stored in external mem */
//Enric node_id_restore();
/* for setting "hardcoded" IEEE 802.15.4 MAC addresses */
#ifdef IEEE_802154_MAC_ADDRESS
{
uint8_t ieee[] = IEEE_802154_MAC_ADDRESS;
memcpy(node_mac, ieee, sizeof(uip_lladdr.addr));
node_mac[7] = node_id & 0xff;
}
#endif
//Enric random_init(node_mac[0] + node_id);
/*
* Initialize Contiki and our processes.
*/
process_init();
process_start(&etimer_process, NULL);
//process_start(&sensors_process, NULL);
PRINTF("process_sensors() skipped \n");
ctimer_init();
set_rime_addr();
cc2420_init();
{
uint8_t longaddr[8];
uint16_t shortaddr;
shortaddr = (rimeaddr_node_addr.u8[0] << 8) +
rimeaddr_node_addr.u8[1];
memset(longaddr, 0, sizeof(longaddr));
rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_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);
}
cc2420_set_channel(RF_CHANNEL);
leds_off(LEDS_ALL);
PRINTF(CONTIKI_VERSION_STRING " started. ");
if(node_id > 0) {
PRINTF("Node id is set to %u.\n", node_id);
} else {
PRINTF("Node id is not set.\n");
}
//Enric printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
//Enric node_mac[0], node_mac[1], node_mac[2], node_mac[3],
//Enric node_mac[4], node_mac[5], node_mac[6], node_mac[7]);
#if WITH_UIP6
PRINTF("in WITH_UIP6\n"); //Enric
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, RF_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()),
RF_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, 0xaaaa, 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 /* WITH_UIP6 */
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()),
RF_CHANNEL);
#endif /* WITH_UIP6 */
#if !WITH_UIP && !WITH_UIP6
uart0_set_input(serial_line_input_byte);
serial_line_init();
#endif
#if PROFILE_CONF_ON
profile_init();
#endif /* PROFILE_CONF_ON */
leds_off(LEDS_GREEN);
#if TIMESYNCH_CONF_ENABLED
timesynch_init();
timesynch_set_authority_level(rimeaddr_node_addr.u8[0]);
#endif /* TIMESYNCH_CONF_ENABLED */
#if WITH_UIP
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,
rimeaddr_node_addr.u8[0],rimeaddr_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 /* WITH_UIP */
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;
#if PROFILE_CONF_ON
profile_episode_start();
#endif /* PROFILE_CONF_ON */
do {
/* Reset watchdog. */
watchdog_periodic();
r = process_run();
} while(r > 0);
#if PROFILE_CONF_ON
profile_episode_end();
#endif /* PROFILE_CONF_ON */
/*
* 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_OFF(ENERGEST_TYPE_CPU);
ENERGEST_ON(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_OFF(ENERGEST_TYPE_LPM);
ENERGEST_ON(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 */

View File

@ -0,0 +1,97 @@
/*
* 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.
*
* $Id: battery-sensor.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01
* Updated : $Date: 2010/08/24 16:26:38 $
* $Revision: 1.1 $
*/
#include "dev/battery-sensor.h"
#include "dev/sky-sensors.h"
#include <io.h>
const struct sensors_sensor battery_sensor;
static uint8_t active;
/*---------------------------------------------------------------------------*/
static void
activate(void)
{
/* Configure ADC12_2 to sample channel 11 (voltage) and use */
/* the Vref+ as reference (SREF_1) since it is a stable reference */
ADC12MCTL2 = (INCH_11 + SREF_1);
sky_sensors_activate(0x80);
active = 1;
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
sky_sensors_deactivate(0x80);
active = 0;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
return ADC12MEM2/*battery_value*/;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int c)
{
switch(type) {
case SENSORS_ACTIVE:
if(c) {
activate();
} else {
deactivate();
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return active;
}
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR,
value, configure, status);

View File

@ -0,0 +1,104 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: button-sensor.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
#include "lib/sensors.h"
#include "dev/hwconf.h"
#include "dev/button-sensor.h"
#include <signal.h>
const struct sensors_sensor button_sensor;
static struct timer debouncetimer;
static int status(int type);
HWCONF_PIN(BUTTON, 2, 7);
HWCONF_IRQ(BUTTON, 2, 7);
/*---------------------------------------------------------------------------*/
interrupt(PORT2_VECTOR)
irq_p2(void)
{
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);

View File

@ -0,0 +1,66 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: radio-sensor.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
#include "lib/sensors.h"
#include "dev/cc2420.h"
#include "dev/radio-sensor.h"
const struct sensors_sensor radio_sensor;
/*---------------------------------------------------------------------------*/
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)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR,
value, configure, status);

376
platform/z1/msp430.c Normal file
View File

@ -0,0 +1,376 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: msp430.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
#include <io.h>
#include <signal.h>
#include <sys/unistd.h>
#include "msp430.h"
#include "dev/watchdog.h"
#include "net/uip.h"
/*---------------------------------------------------------------------------*/
#if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND
void *
w_memcpy(void *out, const void *in, size_t n)
{
uint8_t *src, *dest;
src = (uint8_t *) in;
dest = (uint8_t *) out;
while(n-- > 0) {
*dest++ = *src++;
}
return out;
}
#endif /* __GNUC__ && __MSP430__ && MSP430_MEMCPY_WORKAROUND */
/*---------------------------------------------------------------------------*/
#if defined(__MSP430__) && defined(__GNUC__) && MSP430_MEMCPY_WORKAROUND
void *
w_memset(void *out, int value, size_t n)
{
uint8_t *dest;
dest = (uint8_t *) out;
while(n-- > 0) {
*dest++ = value & 0xff;
}
return out;
}
#endif /* __GNUC__ && __MSP430__ && MSP430_MEMCPY_WORKAROUND */
/*---------------------------------------------------------------------------*/
void
msp430_init_dco(void)
{
if(CALBC1_8MHZ != 0xFF) {
DCOCTL = 0x00;
BCSCTL1 = CALBC1_8MHZ; /*Set DCO to 8MHz */
DCOCTL = CALDCO_8MHZ;
} else { /*start using reasonable values at 8 Mhz */
DCOCTL = 0x00;
BCSCTL1 = 0x8D;
DCOCTL = 0x88;
}
/*BCSCTL1 |= XT2OFF; // Make sure XT2 is off */
/* BCSCTL2 = 0x00; // MCLK = DCOCLK/1 */
/* SMCLK = DCOCLK/1 */
/* DCO Internal Resistor */
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Start CPU with full speed (? good or bad?) and go downwards */
/*---------------------------------------------------------------------------*/
void
msp430_quick_synch_dco(void) {
uint16_t last;
uint16_t diff;
uint16_t dco_reg = 0x0fff;
uint8_t current_bit = 12;
uint16_t i;
/* DELTA_2 assumes an ACLK of 32768 Hz */
#define DELTA_2 ((MSP430_CPU_SPEED) / 32768)
/* Select SMCLK clock, and capture on ACLK for TBCCR6 */
TBCTL = TBSSEL1 | TBCLR;
TBCCTL6 = CCIS0 + CM0 + CAP;
/* start the timer */
TBCTL |= MC1;
BCSCTL1 = 0x8D | 7;
DCOCTL = 0xff; /* MAX SPEED ?? */
/* IDEA: do binary search - check MSB first, etc... */
/* 1 set current bit to zero - if to slow, put back to 1 */
while(current_bit--) {
/* first set the current bit to zero and check - we know that it is
set from start so ^ works (first bit = bit 11) */
dco_reg = dco_reg ^ (1 << current_bit); /* clear bit 11..10..9.. */
/* set dco registers */
DCOCTL = dco_reg & 0xff;
BCSCTL1 = (BCSCTL1 & 0xf8) | (dco_reg >> 8);
/* some delay to make clock stable - could possibly be made using
captures too ... */
for(i=0; i < 1000; i++) {
i = i | 1;
}
/* do capture... */
while(!(TBCCTL6 & CCIFG));
last = TBCCR6;
TBCCTL6 &= ~CCIFG;
/* wait for next Capture - and calculate difference */
while(!(TBCCTL6 & CCIFG));
diff = TBCCR6 - last;
/* /\* store what was run during the specific test *\/ */
/* dcos[current_bit] = dco_reg; */
/* vals[current_bit] = diff; */
/* should we keep the bit cleared or not ? */
if (diff < DELTA_2) { /* DCO is too slow - fewer ticks than desired */
/* toggle bit again to get it back to one */
dco_reg = dco_reg ^ (1 << current_bit);
}
}
}
/*---------------------------------------------------------------------------*/
void
msp430_init_dco_old(void) /*Enric NOT IN USE, RIGHT NOW */
{
/* This code taken from the FU Berlin sources and reformatted. */
#define DELTA ((MSP430_CPU_SPEED) / (32768 / 8))
unsigned int compare, oldcapture = 0;
unsigned int i;
BCSCTL1 = 0xa4; /* ACLK is devided by 4. RSEL=6 no division for MCLK
and SSMCLK. XT2 is off. */
BCSCTL2 = 0x00; /* Init FLL to desired frequency using the 32762Hz
crystal DCO frquenzy = 2,4576 MHz */
BCSCTL1 |= DIVA1 + DIVA0; /* ACLK = LFXT1CLK/8 */
for(i = 0xffff; i > 0; i--) { /* Delay for XTAL to settle */
asm("nop");
}
CCTL2 = CCIS0 + CM0 + CAP; /* Define CCR2, CAP, ACLK */
TACTL = TASSEL1 + TACLR + MC1; // SMCLK, continous mode
while(1) {
while((CCTL2 & CCIFG) != CCIFG); /* Wait until capture occured! */
CCTL2 &= ~CCIFG; /* Capture occured, clear flag */
compare = CCR2; /* Get current captured SMCLK */
compare = compare - oldcapture; /* SMCLK difference */
oldcapture = CCR2; /* Save current captured SMCLK */
if(DELTA == compare) {
break; /* if equal, leave "while(1)" */
} else if(DELTA < compare) { /* DCO is too fast, slow it down */
DCOCTL--;
if(DCOCTL == 0xFF) { /* Did DCO role under? */
BCSCTL1--;
}
} else { /* -> Select next lower RSEL */
DCOCTL++;
if(DCOCTL == 0x00) { /* Did DCO role over? */
BCSCTL1++;
}
/* -> Select next higher RSEL */
}
}
CCTL2 = 0; /* Stop CCR2 function */
TACTL = 0; /* Stop Timer_A */
BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */
}
/*---------------------------------------------------------------------------*/
static void
init_ports(void)
{
/* Turn everything off, device drivers enable what is needed. */
/* All configured for digital I/O */
#ifdef P1SEL
P1SEL = 0;
#endif
#ifdef P2SEL
P2SEL = 0;
#endif
#ifdef P3SEL
P3SEL = 0;
#endif
#ifdef P4SEL
P4SEL = 0;
#endif
#ifdef P5SEL
P5SEL = 0;
#endif
#ifdef P6SEL
P6SEL = 0;
#endif
/* All available inputs */
#ifdef P1DIR
P1DIR = 0;
P1OUT = 0;
#endif
#ifdef P2DIR
P2DIR = 0;
P2OUT = 0;
#endif
#ifdef P3DIR
P3DIR = 0;
P3OUT = 0;
#endif
#ifdef P4DIR
P4DIR = 0;
P4OUT = 0;
#endif
#ifdef P5DIR
P5DIR = 0;
P5OUT = 0;
#endif
#ifdef P6DIR
P6DIR = 0;
P6OUT = 0;
#endif
P1IE = 0;
P2IE = 0;
}
/*---------------------------------------------------------------------------*/
/* msp430-ld may align _end incorrectly. Workaround in cpu_init. */
extern int _end; /* Not in sys/unistd.h */
static char *cur_break = (char *)&_end;
void
msp430_cpu_init(void)
{
dint();
watchdog_init();
init_ports();
msp430_quick_synch_dco();
eint();
if((uintptr_t)cur_break & 1) { /* Workaround for msp430-ld bug! */
cur_break++;
}
}
/*---------------------------------------------------------------------------*/
#define asmv(arg) __asm__ __volatile__(arg)
#define STACK_EXTRA 32
/*
* Allocate memory from the heap. Check that we don't collide with the
* stack right now (some other routine might later). A watchdog might
* be used to check if cur_break and the stack pointer meet during
* runtime.
*/
void *
sbrk(int incr)
{
char *stack_pointer;
asmv("mov r1, %0" : "=r" (stack_pointer));
stack_pointer -= STACK_EXTRA;
if(incr > (stack_pointer - cur_break))
return (void *)-1; /* ENOMEM */
void *old_break = cur_break;
cur_break += incr;
/*
* If the stack was never here then [old_break .. cur_break] should
* be filled with zeros.
*/
return old_break;
}
/*---------------------------------------------------------------------------*/
/*
* Mask all interrupts that can be masked.
*/
int
splhigh_(void)
{
/* Clear the GIE (General Interrupt Enable) flag. */
int sr;
asmv("mov r2, %0" : "=r" (sr));
asmv("bic %0, r2" : : "i" (GIE));
return sr & GIE; /* Ignore other sr bits. */
}
/*---------------------------------------------------------------------------*/
/*
* Restore previous interrupt mask.
*/
void
splx_(int sr)
{
/* If GIE was set, restore it. */
asmv("bis %0, r2" : : "r" (sr));
}
/*---------------------------------------------------------------------------*/
/* this code will always start the TimerB if not already started */
void
msp430_sync_dco(void) {
uint16_t last;
uint16_t diff;
/* uint32_t speed; */
/* DELTA_2 assumes an ACLK of 32768 Hz */
#define DELTA_2 ((MSP430_CPU_SPEED) / 32768)
/* Select SMCLK clock, and capture on ACLK for TBCCR6 */
TBCTL = TBSSEL1 | TBCLR;
TBCCTL6 = CCIS0 + CM0 + CAP;
/* start the timer */
TBCTL |= MC1;
/* wait for next Capture */
TBCCTL6 &= ~CCIFG;
while(!(TBCCTL6 & CCIFG));
last = TBCCR6;
TBCCTL6 &= ~CCIFG;
/* wait for next Capture - and calculate difference */
while(!(TBCCTL6 & CCIFG));
diff = TBCCR6 - last;
/* Stop timer - conserves energy according to user guide */
TBCTL = 0;
/* speed = diff; */
/* speed = speed * 32768; */
/* printf("Last TAR diff:%d target: %ld ", diff, DELTA_2); */
/* printf("CPU Speed: %lu DCOCTL: %d\n", speed, DCOCTL); */
/* resynchronize the DCO speed if not at target */
if(DELTA_2 < diff) { /* DCO is too fast, slow it down */
DCOCTL--;
if(DCOCTL == 0xFF) { /* Did DCO role under? */
BCSCTL1--;
}
} else if (DELTA_2 > diff) {
DCOCTL++;
if(DCOCTL == 0x00) { /* Did DCO role over? */
BCSCTL1++;
}
}
}
/*---------------------------------------------------------------------------*/

60
platform/z1/node-id.c Normal file
View File

@ -0,0 +1,60 @@
/*
* 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.
*
* $Id: node-id.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
/**
* \file
* Utility to store a node id in the external flash
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "node-id.h"
#include "contiki-conf.h"
unsigned short node_id = 0;
unsigned char node_mac[8];
/*---------------------------------------------------------------------------*/
void
node_id_restore(void)
{
//TODO
}
/*---------------------------------------------------------------------------*/
void
node_id_burn(unsigned short id)
{
//TODO
}
/*---------------------------------------------------------------------------*/

45
platform/z1/node-id.h Normal file
View File

@ -0,0 +1,45 @@
/*
* 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.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: node-id.h,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
#ifndef __NODE_ID_H__
#define __NODE_ID_H__
void node_id_restore(void);
void node_id_burn(unsigned short node_id);
extern unsigned short node_id;
extern unsigned char node_mac[8];
#endif /* __NODE_ID_H__ */

211
platform/z1/platform-conf.h Normal file
View File

@ -0,0 +1,211 @@
/*
* 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.
*
* $Id: platform-conf.h,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
/**
* \file
* A brief description of what this file is
* \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 */
/* CPU target speed in Hz */
/* CPU target speed in Hz */
#define F_CPU 8000000uL // 8MHz by default
//Enric #define F_CPU 3900000uL /*2457600uL*/
/* 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 CC_CONF_INLINE inline
#define HAVE_STDINT_H
#define MSP430_MEMCPY_WORKAROUND 1
#include "msp430def.h"
/* 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 */
#define LEDS_PxDIR P5DIR
#define LEDS_PxOUT P5OUT
#define LEDS_CONF_RED 0x10
#define LEDS_CONF_GREEN 0x40
#define LEDS_CONF_YELLOW 0x20
/* 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 TMote Sky.
*/
/* 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.
*/
//#define FLASH_PWR 3 /* 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))
#endif /* __PLATFORM_CONF_H__ */