Removed old, unused msp430-based platforms

This commit is contained in:
Adam Dunkels 2013-11-18 23:54:01 +01:00
parent 6265219775
commit 44370be06f
140 changed files with 0 additions and 15776 deletions

View file

@ -1,87 +0,0 @@
# $Id: Makefile.esb,v 1.15 2010/03/02 22:40:39 nifi Exp $
SENSORS = sensors.c irq.c button-sensor.c pir-sensor.c vib-sensor.c \
sound-sensor.c radio-sensor.c ctsrts-sensor.c battery-sensor.c \
temperature-sensor.c
ESB = ir.c beep.c ds1629.c tr1001-gcr.c gcr.c \
esb-sensors.c node-id.c eeprom.c \
uip-driver.c uip-ipchksum.c
CFS_EEPROM = cfs-eeprom.c
CFS_COFFEE = cfs-coffee.c cfs-coffee-arch.c
CONTIKI_TARGET_DIRS = . dev apps net loader
ifndef CONTIKI_TARGET_MAIN
CONTIKI_TARGET_MAIN = contiki-esb-main.c
endif
CONTIKI_TARGET_SOURCEFILES += $(SENSORS) $(ESB) \
contiki-esb-default-init-lowlevel.c \
contiki-esb-default-init-apps.c \
rs232.c rs232-putchar.c fader.c
ifdef WITH_CODEPROP
CONTIKI_TARGET_DIRS += ../../apps/codeprop
CONTIKI_TARGET_SOURCEFILES += codeprop-tmp.c
WITH_UIP=1
endif
ifdef GCC
CFLAGS+=-Os -g
endif
ifdef IAR
CFLAGS += -D__MSP430F149__=1 -e --vla -Ohz --multiplier=16s --core=430 --double=32
CFLAGSNO = --dlib_config "$(IAR_PATH)/LIB/DLIB/dl430fn.h" $(CFLAGSWERROR)
endif
ifdef WITH_UIP
ifndef WITH_SLIP
WITH_SLIP=1
endif
CFLAGS += -DWITH_UIP=1 -DWITH_SLIP=${WITH_SLIP}
endif
ifeq ($(CFS),coffee)
CONTIKI_TARGET_SOURCEFILES += $(CFS_COFFEE)
else
CONTIKI_TARGET_SOURCEFILES += $(CFS_EEPROM)
endif
include $(CONTIKI)/platform/$(TARGET)/apps/Makefile.apps
MCU=msp430f149
include $(CONTIKI)/cpu/msp430/Makefile.msp430
ifdef IAR
LDFLAGSNO += -xm "$(IAR_PATH)/lib/dlib/dl430fn.r43" -f "$(IAR_PATH)/config/lnk430f149.xcl"
LDFLAGS += $(LDFLAGSNO) -Felf -yn
endif # IAR
contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
# $(AR) rcf $@ $^
ifndef BASE_IP
BASE_IP := 172.16.1.1
endif
send: $(CONTIKI)/tools/codeprop.c
cc -Wall $^ -o send
%.send: %.cm send
send $(BASE_IP) $<
### System dependent Makefile
ifeq ($(HOST_OS),FreeBSD)
# settings for FreeBSD
-include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.freebsd
else
ifeq ($(HOST_OS),Windows)
# settings for Windows
-include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.win
else
# settings for an arbitary unix-like platform
-include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.unix
endif
endif

View file

@ -1,4 +0,0 @@
burn-nodeid: burn-nodeid.c
helloworld: helloworld.c
radio-test: radio-test.c
radio-sniffer: radio-sniffer.c

View file

@ -1,85 +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-esb.h"
PROCESS(beeper_process, "Beeper");
AUTOSTART_PROCESSES(&beeper_process);
static struct etimer etimer;
static struct pt beeper_pt;
static
PT_THREAD(beeper_thread(struct pt *pt))
{
PT_BEGIN(pt);
while(1) {
PT_WAIT_UNTIL(pt, etimer_expired(&etimer));
etimer_reset(&etimer);
leds_invert(LEDS_RED);
beep();
PT_WAIT_UNTIL(pt, etimer_expired(&etimer));
etimer_reset(&etimer);
leds_invert(LEDS_RED);
}
PT_END(pt);
}
PROCESS_THREAD(beeper_process, ev, data)
{
PROCESS_BEGIN();
etimer_set(&etimer, CLOCK_SECOND / 2);
PT_INIT(&beeper_pt);
button_sensor.configure(SENSORS_ACTIVE, 1);
while(1) {
beeper_thread(&beeper_pt);
PROCESS_WAIT_EVENT();
if(ev == PROCESS_EVENT_EXIT) {
break;
} else if(ev == sensors_event &&
data == &button_sensor) {
leds_invert(LEDS_YELLOW);
}
}
PROCESS_END();
}

View file

@ -1,70 +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 brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "sys/node-id.h"
#include "contiki.h"
#include "dev/esb-sensors.h"
#include "dev/rs232.h"
#include <stdio.h>
PROCESS(burn_process, "Burn node id");
AUTOSTART_PROCESSES(&burn_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(burn_process, ev, data)
{
PROCESS_BEGIN();
#if NODEID
printf("Burning node id %d\n", NODEID);
node_id_burn(NODEID);
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
while(1) {
PROCESS_WAIT_EVENT();
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void init_net(void) {}
void init_lowlevel(void) {esb_sensors_init(); esb_sensors_on(); rs232_init();}

View file

@ -1,136 +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-esb.h"
PROCESS(fader_process, "LED fader");
AUTOSTART_PROCESSES(&fader_process);
#define ON 1
#define OFF 0
static unsigned char onoroff;
static struct etimer etimer;
static struct pt fade_pt, fade_in_pt, fade_out_pt;
/*---------------------------------------------------------------------------*/
static
PT_THREAD(fade_in(struct pt *pt))
{
static int delay;
PT_BEGIN(pt);
for(delay = 3980; delay > 20; delay -= 20) {
leds_on(LEDS_ALL);
clock_delay(4000 - delay);
leds_off(LEDS_ALL);
clock_delay(delay);
PT_YIELD(pt);
}
PT_END(pt);
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(fade_out(struct pt *pt))
{
static int delay;
PT_BEGIN(pt);
for(delay = 20; delay < 3980; delay += 20) {
leds_on(LEDS_ALL);
clock_delay(4000 - delay);
leds_off(LEDS_ALL);
clock_delay(delay);
PT_YIELD(pt);
}
PT_END(pt);
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(fade(struct pt *pt))
{
PT_BEGIN(pt);
PT_SPAWN(pt, &fade_in_pt, fade_in(&fade_in_pt));
PT_SPAWN(pt, &fade_out_pt, fade_out(&fade_out_pt));
etimer_set(&etimer, CLOCK_SECOND * 10);
PT_WAIT_UNTIL(pt, etimer_expired(&etimer));
PT_END(pt);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(fader_process, ev, data)
{
PROCESS_BEGIN();
PT_INIT(&fade_pt);
PT_INIT(&fade_in_pt);
PT_INIT(&fade_out_pt);
onoroff = ON;
etimer_set(&etimer, CLOCK_SECOND * 32);
while(1) {
PROCESS_WAIT_EVENT();
if(ev == PROCESS_EVENT_TIMER) {
etimer_reset(&etimer);
PT_INIT(&fade_pt);
process_poll(&fader_process);
}
if(onoroff == ON &&
PT_SCHEDULE(fade(&fade_pt))) {
process_poll(&fader_process);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
fader_on(void)
{
onoroff = ON;
process_poll(&fader_process);
}
/*---------------------------------------------------------------------------*/
void
fader_off(void)
{
onoroff = OFF;
}
/*---------------------------------------------------------------------------*/

View file

@ -1,44 +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>
*
*/
#ifndef __FADER_H__
#define __FADER_H__
#include "contiki.h"
PROCESS_NAME(fader_process);
void fader_on(void);
void fader_off(void);
#endif /* __FADER_H__ */

View file

@ -1,66 +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 Configurable Sensor Network Application
* Architecture for sensor nodes running the Contiki operating system.
*
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2006-03-07
* Updated : $Date: 2006/06/18 07:48:48 $
* $Revision: 1.1 $
*/
#include "contiki-esb.h"
#include <stdio.h>
PROCESS(helloworld_process, "Helloworld");
AUTOSTART_PROCESSES(&helloworld_process);
static struct etimer timer;
/*---------------------------------------------------------------------*/
PROCESS_THREAD(helloworld_process, ev, data)
{
PROCESS_BEGIN();
etimer_set(&timer, CLOCK_SECOND * 2);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
etimer_reset(&timer);
leds_invert(LEDS_YELLOW);
printf("Hello world!\n");
}
PROCESS_END();
}
/*---------------------------------------------------------------------*/

View file

@ -1,198 +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-esb.h"
#include <stdio.h>
PROCESS(pinger, "Pinger");
static struct uip_udp_conn *conn;
struct data {
uint8_t dummy_data[20];
uint16_t id;
uint16_t seqno;
uint8_t pingpong;
#define PING 0
#define PONG 1
};
static unsigned char pingeron;
static struct etimer etimer;
static unsigned short sent_seqno, last_seqno;
#define PORT 9145
static int place_id = 0, packet_count = 0;
/*---------------------------------------------------------------------------*/
static void
quit(void)
{
process_exit(&pinger);
LOADER_UNLOAD();
}
/*---------------------------------------------------------------------------*/
static void
udp_appcall(void *arg)
{
struct data *d;
/* char buf[50];*/
d = (struct data *)uip_appdata;
if(uip_newdata()) {
leds_toggle(LEDS_YELLOW);
/* beep();*/
/* if(uip_htons(d->seqno) != last_seqno + 1) {
leds_toggle(LEDS_RED);
beep_quick(2);
}*/
/* last_seqno = uip_htons(d->seqno);*/
/* uip_udp_send(sizeof(struct data));*/
/* snprintf(buf, sizeof(buf), "Packet received id %d signal %u\n",
d->id, tr1001_sstrength());
rs232_print(buf);*/
/* if(d->pingpong == PING) {
d->pingpong = PONG;
} else {
d->pingpong = PING;
d->seqno = uip_htons(uip_htons(d->seqno) + 1);
}*/
/* uip_udp_send(sizeof(struct data));
timer_restart(&timer);*/
} else if(uip_poll()) {
if(pingeron && etimer_expired(&etimer) && packet_count > 0) {
--packet_count;
d->id = place_id;
d->pingpong = PING;
d->seqno = uip_htons(sent_seqno);
++sent_seqno;
uip_udp_send(sizeof(struct data));
etimer_reset(&etimer);
leds_toggle(LEDS_GREEN);
}
if(packet_count == 0) {
pingeron = 0;
}
}
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(config_thread(struct pt *pt, process_event_t ev, process_data_t data))
{
static struct etimer pushtimer;
static int counter;
PT_BEGIN(pt);
while(1) {
PT_WAIT_UNTIL(pt, ev == sensors_event && data == &button_sensor);
beep();
leds_on(LEDS_YELLOW);
etimer_set(&pushtimer, CLOCK_SECOND);
for(counter = 0; !etimer_expired(&pushtimer); ++counter) {
etimer_restart(&pushtimer);
PT_YIELD_UNTIL(pt, (ev == sensors_event && data == &button_sensor) ||
etimer_expired(&pushtimer));
}
place_id = counter;
beep_quick(place_id);
pingeron = 1;
packet_count = 20;
etimer_set(&etimer, CLOCK_SECOND / 2);
leds_off(LEDS_YELLOW);
leds_on(LEDS_RED);
PT_WAIT_UNTIL(pt, packet_count == 0);
pingeron = 0;
leds_off(LEDS_RED);
}
PT_END(pt);
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(pinger, ev, data)
{
static struct pt config_pt;
PROCESS_BEGIN();
pingeron = 0;
conn = udp_broadcast_new(UIP_HTONS(PORT), NULL);
PT_INIT(&config_pt);
button_sensor.configure(SENSORS_ACTIVE, 1);
while(1) {
config_thread(&config_pt, ev, data);
PROCESS_WAIT_EVENT();
printf("Event %d\n", ev);
beep();
if(ev == tcpip_event) {
udp_appcall(data);
}
if(ev == PROCESS_EVENT_TIMER && etimer_expired(&etimer)) {
tcpip_poll_udp(conn);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

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

View file

@ -1,85 +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 brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "radio-sniffer.h"
#include "contiki-net.h"
#include "contiki-esb.h"
#include "net/hc.h"
#include "net/tcpdump.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
PROCESS(radio_sniffer_process, "Radio sniffer");
AUTOSTART_PROCESSES(&radio_sniffer_process);
/*---------------------------------------------------------------------------*/
static void
sniffer_callback(const struct radio_driver *driver)
{
static char buf[40];
static uint8_t packet[UIP_BUFSIZE];
static int len;
len = driver->read(packet, sizeof(packet));
if(len > 0) {
leds_blink();
len = hc_inflate(packet, len);
tcpdump_format(packet, len, buf, sizeof(buf));
printf("radio-sniffer %d: packet length %d, %s\n", node_id, len, buf);
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(radio_sniffer_process, ev, data)
{
PROCESS_BEGIN();
tr1001_init();
tr1001_driver.set_receive_function(sniffer_callback);
printf("Radio sniffer started.\n");
while(1) {
PROCESS_WAIT_EVENT();
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
init_net(void)
{
}
/*---------------------------------------------------------------------------*/

View file

@ -1,46 +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 brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __RADIO_SNIFFER_H__
#define __RADIO_SNIFFER_H__
#include "contiki.h"
PROCESS_NAME(radio_sniffer_process);
#endif /* __RADIO_SNIFFER_H__ */

View file

@ -1,154 +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 : 2006-03-07
* Updated : $Date: 2010/10/19 18:29:05 $
* $Revision: 1.3 $
*
* Simple application to indicate connectivity between two nodes:
*
* - Red led indicates a packet sent via radio (one packet sent each second)
* - Yellow led indicates that this node can hear the other node but not
* necessary vice versa (unidirectional communication).
* - Green led indicates that both nodes can communicate with each
* other (bidirectional communication)
*/
#include "contiki-esb.h"
#include <string.h>
PROCESS(radio_test_process, "Radio test");
AUTOSTART_PROCESSES(&radio_test_process);
#define ON 1
#define OFF 0
#define HEADER "RTST"
#define PACKET_SIZE 20
#define PORT 2345
struct indicator {
int onoff;
int led;
clock_time_t interval;
struct etimer timer;
};
/*---------------------------------------------------------------------*/
static void
set(struct indicator *indicator, int onoff) {
if(indicator->onoff ^ onoff) {
indicator->onoff = onoff;
if(onoff) {
leds_on(indicator->led);
} else {
leds_off(indicator->led);
}
}
if(onoff) {
etimer_set(&indicator->timer, indicator->interval);
}
}
/*---------------------------------------------------------------------*/
PROCESS_THREAD(radio_test_process, ev, data)
{
static struct etimer send_timer;
static struct uip_udp_conn *conn;
static struct indicator recv, other, flash;
PROCESS_BEGIN();
/* Initialize the indicators */
recv.onoff = other.onoff = flash.onoff = OFF;
recv.interval = other.interval = CLOCK_SECOND;
flash.interval = 1;
recv.led = LEDS_YELLOW;
other.led = LEDS_GREEN;
flash.led = LEDS_RED;
conn = udp_broadcast_new(UIP_HTONS(PORT), NULL);
etimer_set(&send_timer, CLOCK_SECOND);
while(1) {
PROCESS_WAIT_EVENT();
if(ev == PROCESS_EVENT_TIMER) {
if(data == &send_timer) {
etimer_reset(&send_timer);
tcpip_poll_udp(conn);
} else if(data == &other.timer) {
set(&other, OFF);
} else if(data == &recv.timer) {
set(&recv, OFF);
} else if(data == &flash.timer) {
set(&flash, OFF);
}
} else if(ev == tcpip_event) {
if(uip_poll()) {
/* send packet */
memcpy(uip_appdata, HEADER, sizeof(HEADER));
((char *)uip_appdata)[sizeof(HEADER)] = recv.onoff;
/* send arbitrary data to fill the packet size */
uip_send(uip_appdata, PACKET_SIZE);
set(&flash, ON);
}
if(uip_newdata()) {
/* packet received */
if(uip_datalen() < PACKET_SIZE
|| strncmp((char *)uip_appdata, HEADER, sizeof(HEADER))) {
/* invalid message */
leds_blink();
} else {
set(&recv, ON);
set(&other, ((char *)uip_appdata)[sizeof(HEADER)] ? ON : OFF);
/* synchronize the sending to keep the nodes from sending
simultaneously */
etimer_set(&send_timer, CLOCK_SECOND);
etimer_adjust(&send_timer, - (int) (CLOCK_SECOND >> 1));
beep();
}
}
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------*/

View file

@ -1,65 +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-esb.h"
#include <stdio.h>
PROCESS(sensor_output_process, "Sensor output");
AUTOSTART_PROCESSES(&sensor_output_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sensor_output_process, ev, data)
{
struct sensors_sensor *s;
PROCESS_BEGIN();
/* Activate some sensors to get sensor events */
button_sensor.configure(SENSORS_ACTIVE, 1);
pir_sensor.configure(SENSORS_ACTIVE, 1);
vib_sensor.configure(SENSORS_ACTIVE, 1);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event);
s = (struct sensors_sensor *)data;
printf("%s %d\n", s->type, s->value(0));
if (data == &button_sensor) leds_invert(LEDS_YELLOW);
if (data == &pir_sensor) leds_invert(LEDS_GREEN);
if (data == &vib_sensor) leds_invert(LEDS_RED);
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

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

View file

@ -1,65 +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 : 2006-03-07
* Updated : $Date: 2010/10/19 18:29:05 $
* $Revision: 1.2 $
*/
#include "contiki-esb.h"
#include <stdio.h>
PROCESS(test_receiver_process, "Test - Receiver");
AUTOSTART_PROCESSES(&test_receiver_process);
#define PORT 1234
PROCESS_THREAD(test_receiver_process, ev, data)
{
static struct uip_udp_conn *conn;
PROCESS_BEGIN();
conn = udp_broadcast_new(UIP_HTONS(PORT), NULL);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event && uip_newdata());
leds_invert(LEDS_YELLOW);
/* Make sure the message is null terminated */
((char *) uip_appdata)[uip_datalen()] = 0;
printf("RECV: %s\n", (char *) uip_appdata);
}
PROCESS_END();
}
/*---------------------------------------------------------------------*/

View file

@ -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 : 2006-03-07
* Updated : $Date: 2010/10/19 18:29:05 $
* $Revision: 1.2 $
*/
#include "contiki-esb.h"
PROCESS(test_sender_process, "Test - Sender");
AUTOSTART_PROCESSES(&test_sender_process);
#define PORT 1234
PROCESS_THREAD(test_sender_process, ev, data)
{
static struct etimer timer;
static struct uip_udp_conn *conn;
PROCESS_BEGIN();
conn = udp_broadcast_new(UIP_HTONS(PORT), NULL);
etimer_set(&timer, CLOCK_SECOND * 2);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
etimer_reset(&timer);
/* Send packet */
tcpip_poll_udp(conn);
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event && uip_poll());
leds_invert(LEDS_YELLOW);
uip_send("Hello world", sizeof("Hello world"));
}
PROCESS_END();
}
/*---------------------------------------------------------------------*/

View file

@ -1,18 +0,0 @@
ifndef JTAG
JTAG := $(CONTIKI)/platform/$(TARGET)/buildscripts/jtag/pyjtag/jtag.py
endif
ifndef JTAG_PORT
JTAG_PORT = /dev/ppi0
endif
%.u: %.$(TARGET)
$(JTAG) -l $(JTAG_PORT) -e
$(JTAG) -l $(JTAG_PORT) -D -D -S -R 2048 -p $^
$(JTAG) -l $(JTAG_PORT) -D -r
r:
$(JTAG) -l $(JTAG_PORT) -r
erase:
$(JTAG) -l $(JTAG_PORT) -e

View file

@ -1,2 +0,0 @@
%.u: %.ihex
msp430-jtag -eI $^

View file

@ -1,11 +0,0 @@
%.u: %.ihex
ifdef JTAG_PORT
msp430-jtag -l $(JTAG_PORT) -eI $^
else
msp430-jtag -eI $^
endif
#CW=cw23
#%.u: %.ihex
# $(CW) -d f430p $^

View file

@ -1,318 +0,0 @@
#!/usr/bin/env python
import struct
# ELF object file reader
# (C) 2003 cliechti@gmx.net
# Python license
# size alignment
# Elf32_Addr 4 4 Unsigned program address
# Elf32_Half 2 2 Unsigned medium integer
# Elf32_Off 4 4 Unsigned file offset
# Elf32_Sword 4 4 Signed large integer
# Elf32_Word 4 4 Unsigned large integer
# unsignedchar 1 1 Unsigned small integer
#define EI_NIDENT 16
#~ typedef struct{
#~ unsigned char e_ident[EI_NIDENT];
#~ Elf32_Half e_type;
#~ Elf32_Half e_machine;
#~ Elf32_Word e_version;
#~ Elf32_Addr e_entry;
#~ Elf32_Off e_phoff;
#~ Elf32_Off e_shoff;
#~ Elf32_Word e_flags;
#~ Elf32_Half e_ehsize;
#~ Elf32_Half e_phentsize;
#~ Elf32_Half e_phnum;
#~ Elf32_Half e_shentsize;
#~ Elf32_Half e_shnum;
#~ Elf32_Half e_shstrndx;
#~ } Elf32_Ehdr;
#Section Header
#~ typedef struct {
#~ Elf32_Word sh_name;
#~ Elf32_Word sh_type;
#~ Elf32_Word sh_flags;
#~ Elf32_Addr sh_addr;
#~ Elf32_Off sh_offset;
#~ Elf32_Word sh_size;
#~ Elf32_Word sh_link;
#~ Elf32_Word sh_info;
#~ Elf32_Word sh_addralign;
#~ Elf32_Word sh_entsize;
#~ } Elf32_Shdr;
#~ typedef struct {
#~ Elf32_Word p_type;
#~ Elf32_Off p_offset;
#~ Elf32_Addr p_vaddr;
#~ Elf32_Addr p_paddr;
#~ Elf32_Word p_filesz;
#~ Elf32_Word p_memsz;
#~ Elf32_Word p_flags;
#~ Elf32_Word p_align;
#~ } Elf32_Phdr;
class ELFException(Exception): pass
class ELFSection:
"""read and store a section"""
Elf32_Shdr = "<IIIIIIIIII" #header format
#section types
SHT_NULL = 0
SHT_PROGBITS = 1
SHT_SYMTAB = 2
SHT_STRTAB = 3
SHT_RELA = 4
SHT_HASH = 5
SHT_DYNAMIC = 6
SHT_NOTE = 7
SHT_NOBITS = 8
SHT_REL = 9
SHT_SHLIB = 10
SHT_DYNSYM = 11
SHT_LOPROC = 0x70000000L
SHT_HIPROC = 0x7fffffffL
SHT_LOUSER = 0x80000000L
SHT_HIUSER = 0xffffffffL
#section attribute flags
SHF_WRITE = 0x1
SHF_ALLOC = 0x2
SHF_EXECINSTR = 0x4
SHF_MASKPROC = 0xf0000000
def __init__(self):
"""creat a new empty section object"""
(self.sh_name, self.sh_type, self.sh_flags, self.sh_addr,
self.sh_offset, self.sh_size, self.sh_link, self.sh_info,
self.sh_addralign, self.sh_entsize) = [0]*10
self.name = None
self.data = None
self.lma = None
def fromString(self, s):
"""get section header from string"""
(self.sh_name, self.sh_type, self.sh_flags, self.sh_addr,
self.sh_offset, self.sh_size, self.sh_link, self.sh_info,
self.sh_addralign, self.sh_entsize) = struct.unpack(self.Elf32_Shdr, s)
def __str__(self):
"""pretty print for debug..."""
return "%s(%s, sh_type=%s, sh_flags=%s, "\
"sh_addr=0x%04x, sh_offset=0x%04x, sh_size=%s, sh_link=%s, "\
"sh_info=%s, sh_addralign=%s, sh_entsize=%s, lma=0x%04x)" % (
self.__class__.__name__,
self.name is not None and "%r" % self.name or "sh_name=%s" % self.sh_name,
self.sh_type, self.sh_flags, self.sh_addr,
self.sh_offset, self.sh_size, self.sh_link, self.sh_info,
self.sh_addralign, self.sh_entsize, self.lma)
class ELFProgramHeader:
"""Store and parse a program header"""
Elf32_Phdr = "<IIIIIIII" #header format
#segmet types
PT_NULL = 0
PT_LOAD = 1
PT_DYNAMIC = 2
PT_INTERP = 3
PT_NOTE = 4
PT_SHLIB = 5
PT_PHDR = 6
PT_LOPROC = 0x70000000L
PT_HIPROC = 0x7fffffffL
#segment flags
PF_R = 0x4 #segment is readable
PF_W = 0x2 #segment is writable
PF_X = 0x1 #segment is executable
def __init__(self):
"""create a new, empty segment/program header"""
(self.p_type, self.p_offset, self.p_vaddr, self.p_paddr,
self.p_filesz, self.p_memsz, self.p_flags, self.p_align) = [0]*8
self.data = None
def fromString(self, s):
"""parse header info from string"""
(self.p_type, self.p_offset, self.p_vaddr, self.p_paddr,
self.p_filesz, self.p_memsz, self.p_flags,
self.p_align) = struct.unpack(self.Elf32_Phdr, s)
def __str__(self):
"""pretty print for debug..."""
return "%s(p_type=%s, p_offset=0x%04x, p_vaddr=0x%04x, p_paddr=0x%04x, "\
"p_filesz=%s, p_memsz=%s, p_flags=%s, "\
"p_align=%s)" % (
self.__class__.__name__,
self.p_type, self.p_offset, self.p_vaddr, self.p_paddr,
self.p_filesz, self.p_memsz, self.p_flags,
self.p_align)
class ELFObject:
"""Object to read and handle an LEF object file"""
#header information
Elf32_Ehdr = "<16sHHIIIIIHHHHHH"
#offsets within e_ident
EI_MAG0 = 0 #File identification
EI_MAG1 = 1 #File identification
EI_MAG2 = 2 #File identification
EI_MAG3 = 3 #File identification
EI_CLASS = 4 #File class
EI_DATA = 5 #Data encoding
EI_VERSION = 6 #File version
EI_PAD = 7 #Start of padding bytes
EI_NIDENT = 16 #Size of e_ident[]
#elf file type flags
ET_NONE = 0 #No file type
ET_REL = 1 #Relocatable file
ET_EXEC = 2 #Executable file
ET_DYN = 3 #Shared object file
ET_CORE = 4 #Core file
ET_LOPROC = 0xff00 #Processor-specific
ET_HIPROC = 0xffff #Processor-specific
#ELF format
ELFCLASSNONE = 0 #Invalid class
ELFCLASS32 = 1 #32-bit objects
ELFCLASS64 = 2 #64-bit objects
#encoding
ELFDATANONE = 0 #Invalid data encoding
ELFDATA2LSB = 1 #See below
ELFDATA2MSB = 2 #See below
def __init__(self):
"""create a new elf object"""
(self.e_ident, self.e_type, self.e_machine, self.e_version,
self.e_entry, self.e_phoff, self.e_shoff,
self.e_flags, self.e_ehsize, self.e_phentsize, self.e_phnum,
self.e_shentsize, self.e_shnum, self.e_shstrndx) = [0]*14
def fromFile(self, fileobj):
"""read all relevant data from fileobj.
the file must be seekable"""
#get file header
(self.e_ident, self.e_type, self.e_machine, self.e_version,
self.e_entry, self.e_phoff, self.e_shoff,
self.e_flags, self.e_ehsize, self.e_phentsize, self.e_phnum,
self.e_shentsize, self.e_shnum, self.e_shstrndx) = struct.unpack(
self.Elf32_Ehdr, fileobj.read(struct.calcsize(self.Elf32_Ehdr)))
#verify if its a known format and realy an ELF file
if self.e_ident[0:4] != '\x7fELF' and\
self.e_ident[self.EI_CLASS] != self.ELFCLASS32 and\
self.e_ident[self.EI_DATA] != self.ELFDATA2LSB and\
self.e_ident[self.EI_VERSION] != 1:
raise ELFException("Not a valid ELF file")
#load programm headers
self.programmheaders = []
if self.e_phnum:
#load program headers
fileobj.seek(self.e_phoff)
for sectionnum in range(self.e_phnum):
shdr = (fileobj.read(self.e_phentsize) + '\0'* struct.calcsize(ELFProgramHeader.Elf32_Phdr))[0:struct.calcsize(ELFProgramHeader.Elf32_Phdr)]
psection = ELFProgramHeader()
psection.fromString(shdr)
if psection.p_offset: #skip if section has invalid offset in file
self.programmheaders.append(psection)
#~ #get the segment data from the file for each prg header
#~ for phdr in self.programmheaders:
#~ fileobj.seek(phdr.p_offset)
#~ phdr.data = fileobj.read(phdr.p_filesz)
#~ #pad if needed
#~ if phdr.p_filesz < phdr.p_memsz:
#~ phdr.data = phdr.data + '\0' * (phdr.p_memsz-phdr.p_filesz)
#load sections
self.sections = []
fileobj.seek(self.e_shoff)
for sectionnum in range(self.e_shnum):
shdr = (fileobj.read(self.e_shentsize) + '\0'* struct.calcsize(ELFSection.Elf32_Shdr))[0:struct.calcsize(ELFSection.Elf32_Shdr)]
elfsection = ELFSection()
elfsection.fromString(shdr)
self.sections.append(elfsection)
#load data for all sections
for section in self.sections:
fileobj.seek(section.sh_offset)
data = fileobj.read(section.sh_size)
section.data = data
if section.sh_type == ELFSection.SHT_STRTAB:
section.values = data.split('\0')
section.lma = self.getLMA(section)
#get section names
for section in self.sections:
start = self.sections[self.e_shstrndx].data[section.sh_name:]
section.name = start.split('\0')[0]
def getSection(self, name):
"""get section by name"""
for section in self.sections:
if section.name == '.text':
return section
def getProgrammableSections(self):
"""get all program headers that are marked as executable and
have suitable attributes to be code"""
res = []
for p in self.programmheaders:
#~ print p
#~ if section.sh_flags & self.SHF_ALLOC and section.name not in ('.data', '.data1', '.bss'):
#~ if p.p_type == ELFProgramHeader.PT_LOAD:# and p.p_paddr == p.p_vaddr and p.p_flags & ELFProgramHeader.PF_X:
if p.p_type == ELFProgramHeader.PT_LOAD:
res.append(p)
return res
def getLMA(self, section):
#magic load memory address calculation ;-)
for p in self.programmheaders:
if (p.p_paddr != 0 and \
p.p_type == ELFProgramHeader.PT_LOAD and \
p.p_vaddr != p.p_paddr and \
p.p_vaddr <= section.sh_addr and \
(p.p_vaddr + p.p_memsz >= section.sh_addr + section.sh_size) \
and (not (section.sh_flags & ELFSection.SHF_ALLOC and section.sh_type != ELFSection.SHT_NOBITS) \
or (p.p_offset <= section.sh_offset \
and (p.p_offset + p.p_filesz >= section.sh_offset + section.sh_size)))):
return section.sh_addr + p.p_paddr - p.p_vaddr
return section.sh_addr
def getSections(self):
"""get sections relevant for the application"""
res = []
for section in self.sections:
if section.sh_flags & ELFSection.SHF_ALLOC and section.sh_type != ELFSection.SHT_NOBITS:
res.append(section)
return res
def __str__(self):
"""pretty print for debug..."""
return "%s(self.e_type=%r, self.e_machine=%r, self.e_version=%r, sections=%r)" % (
self.__class__.__name__,
self.e_type, self.e_machine, self.e_version,
[section.name for section in self.sections])
if __name__ == '__main__':
print "This is only a module test!"
elf = ELFObject()
elf.fromFile(open("test.elf"))
if elf.e_type != ELFObject.ET_EXEC:
raise Exception("No executable")
print elf
#~ print repr(elf.getSection('.text').data)
#~ print [(s.name, hex(s.sh_addr)) for s in elf.getSections()]
print "-"*20
for p in elf.sections: print p
print "-"*20
for p in elf.getSections(): print p
print "-"*20
for p in elf.getProgrammableSections(): print p

View file

@ -1,49 +0,0 @@
#!/usr/bin/env python
"""Test File generator.
This tool generates a hex file, of given size, ending on address
0xffff.
USAGE: hen-ihex.py size_in_kilobyte
The resulting Intel-hex file is output to stdout, use redirection
to save the data to a file.
"""
#return a string with data in intel hex format
def makeihex(address, data):
out = []
start = 0
while start<len(data):
end = start + 16
if end > len(data): end = len(data)
out.append(_ihexline(address, [ord(x) for x in data[start:end]]))
start += 16
address += 16
out.append(_ihexline(address, [], end=1)) #append no data but an end line
return ''.join(out)
def _ihexline(address, buffer, end=0):
out = []
if end:
type = 1
else:
type = 0
out.append( ':%02X%04X%02X' % (len(buffer),address&0xffff,type) )
sum = len(buffer) + ((address>>8)&255) + (address&255)
for b in buffer:
if b == None: b = 0 #substitute nonexistent values with zero
out.append('%02X' % (b&255) )
sum += b&255
out.append('%02X\n' %( (-sum)&255))
return ''.join(out)
if __name__ == '__main__':
import struct, sys
if len(sys.argv) != 2:
print __doc__
sys.exit(1)
size = int(sys.argv[1]) #in kilo
startadr = 0x10000 - 1024*size
data = ''.join([struct.pack(">H", x) for x in range(startadr, startadr+ 1024*size, 2)])
print makeihex(startadr, data)

View file

@ -1,108 +0,0 @@
Name "install-pyjtag"
OutFile "install-pyjtag.exe"
!define SF_SELECTED 1
!define SF_SUBSEC 2
!define SF_SUBSECEND 4
!define SF_BOLD 8
!define SF_RO 16
!define SF_EXPAND 32
!define SECTION_OFF 0xFFFFFFFE
LicenseText License
LicenseData license.txt
SetOverwrite on
SetDateSave on
; The default installation directory
InstallDir $PROGRAMFILES\mspgcc
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM SOFTWARE\mspgcc "rootdir"
; The text to prompt the user to enter a directory
DirText "This will install the pyjtag executables. You can choose the same \
directory as for the other mspgcc tools."
; The text to prompt the user to enter a directory
ComponentText "Select which optional things you want installed."
Section "msp430-jtag (required)"
SectionIn RO
SetOutPath $INSTDIR
File /r bin
File /oname=license-pyjtag.txt license.txt
File /oname=readme-pyjtag.txt readme.txt
File /oname=bin\jtag.py jtag.py
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\mspgcc "rootdir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\mspgcc-pyjtag" "DisplayName" "mspgcc pyjtag (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\mspgcc-pyjtag" "UninstallString" '"$INSTDIR\uninstall-pyjtag.exe"'
WriteUninstaller "uninstall-pyjtag.exe"
SectionEnd
Section "giveio (needed on Win NT/2k/XP, but NOT on 9x/ME)"
SetOutPath $INSTDIR\bin
File ..\jtag\hardware_access\giveio\giveio.sys
File ..\jtag\hardware_access\giveio\loaddrv.exe
SetOutPath $INSTDIR
nsExec::ExecToLog '$INSTDIR\bin\loaddrv.exe install giveio $INSTDIR\bin\giveio.sys'
Pop $0 ;return value/error/timeout
IntCmp $0 2 ext_here ;assume its alredy installed
IntCmp $0 0 0 ext_err ext_err ;if not 0 -> error
nsExec::ExecToLog '$INSTDIR\bin\loaddrv.exe start giveio'
Pop $0 ;return value/error/timeout
IntCmp $0 0 0 ext_err ext_err ;if not 0 -> error
nsExec::ExecToLog '$INSTDIR\bin\loaddrv.exe starttype giveio auto'
Pop $0 ;return value/error/timeout
IntCmp $0 0 0 ext_err ext_err ;if not 0 -> error
WriteRegStr HKLM SOFTWARE\mspgcc "giveio" "started"
Goto ext_ok
ext_err:
DetailPrint "Error while installing and starting giveio"
MessageBox MB_OK|MB_ICONSTOP "Error while installing and starting giveio"
Goto ext_ok
ext_here:
DetailPrint "Installing giveio gave an error, assuming its already installed"
ext_ok:
SectionEnd
; special uninstall section.
Section "Uninstall"
; remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\mspgcc-pyjtag"
DeleteRegKey HKLM SOFTWARE\NSIS_Example2
; remove files
Delete $INSTDIR\bin\msp430-jtag.exe
Delete $INSTDIR\bin\_parjtag.pyd
Delete $INSTDIR\bin\jtag.py
Delete $INSTDIR\bin\HIL.dll
Delete $INSTDIR\bin\MSP430mspgcc.dll
;XXX python22.dll is left installed as it is used by pybsl and other tools
Delete $INSTDIR\license-pyjtag.txt
Delete $INSTDIR\readme-pyjtag.txt
; giveio
; if it was started by us, stop it
ReadRegStr $0 HKLM SOFTWARE\mspgcc "giveio"
StrCmp $0 '' no_giveio
nsExec::ExecToLog '$INSTDIR\bin\loaddrv.exe stop giveio'
Pop $0 ;return value/error/timeout
IntCmp $0 0 0 giveio_err giveio_err ;if not 0 -> error
nsExec::ExecToLog '$INSTDIR\bin\loaddrv.exe remove giveio'
Pop $0 ;return value/error/timeout
IntCmp $0 0 0 giveio_err giveio_err ;if not 0 -> error
Goto no_giveio
giveio_err:
DetailPrint "Error while uninstalling giveio service"
MessageBox MB_OK|MB_ICONSTOP "Error while uninstalling giveio service"
no_giveio:
Delete loaddrv.exe
Delete giveio.sys
; MUST REMOVE UNINSTALLER, too
Delete $INSTDIR\uninstall-pyjtag.exe
SectionEnd

View file

@ -1,604 +0,0 @@
#!/usr/bin/env python
#Parallel JTAG programmer for the MSP430 embedded proccessor.
#
#(C) 2002 Chris Liechti <cliechti@gmx.net>
#this is distributed under a free software license, see license.txt
#
#Requires Python 2+ and the binary extension _parjtag.
import sys
import _parjtag
VERSION = "1.3"
DEBUG = 0 #disable debug messages by default
#frame specific consts
ERASE_MASS = 2
ERASE_MAIN = 1
ERASE_SGMT = 0
#states
FREERUNNING = 0
STOPPED = 1
#Configurations of the MSP430 driver
VERIFICATION_MODE = 0 #Verify data downloaded to FLASH memories.
RAMSIZE_OPTION = 1 #Change RAM used to download and program flash blocks
DEBUG_OPTION = 2 #Set debug level. Enables debug outputs.
#enumeration of output formats for uploads
HEX = 0
INTELHEX = 1
BINARY = 2
#exceptions
class JTAGException(Exception): pass
#for the use with memread
def hexdump( (adr, memstr) ):
"""Print a hex dump of data collected with memread
arg1: tuple with adress, memory
return None"""
count = 0
ascii = ''
for value in map(ord, memstr):
if not count: print "%04x: " % adr,
print "%02x" % value,
ascii += (32 <= value < 128) and chr(value) or '.'
count += 1
adr += 1
if count == 16:
count = 0
print " ", ascii
ascii = ''
if count < 16: print " "*(16-count), " ", ascii
def makeihex( (address, data) ):
"""work though the data and output lines in inzel hex format.
and end tag is appended"""
start = 0
while start<len(data):
end = start + 16
if end > len(data): end = len(data)
_ihexline(address, [ord(x) for x in data[start:end]])
start += 16
address += 16
_ihexline(address, [], type=1) #append no data but an end line
def _ihexline(address, buffer, type=0):
"""encode one line, output with checksum"""
sys.stdout.write( ':%02X%04X%02X' % (len(buffer), address & 0xffff, type) )
sum = len(buffer) + ((address >> 8) & 255) + (address & 255)
for b in buffer:
if b == None: b = 0 #substitute nonexistent values with zero
sys.stdout.write('%02X' % (b & 255))
sum += b&255
sys.stdout.write('%02X\n' %( (-sum) & 255))
class Segment:
"""store a string with memory contents along with its startaddress"""
def __init__(self, startaddress = 0, data=None):
if data is None:
self.data = ''
else:
self.data = data
self.startaddress = startaddress
def __getitem__(self, index):
return self.data[index]
def __len__(self):
return len(self.data)
def __repr__(self):
return "Segment(startaddress = 0x%04x, data=%r)" % (self.startaddress, self.data)
class Memory:
"""represent memory contents. with functions to load files"""
def __init__(self, filename=None):
self.segments = []
if filename:
self.filename = filename
self.loadFile(filename)
def append(self, seg):
self.segments.append(seg)
def __getitem__(self, index):
return self.segments[index]
def __len__(self):
return len(self.segments)
def loadIHex(self, file):
"""load data from a (opened) file in Intel-HEX format"""
segmentdata = []
currentAddr = 0
startAddr = 0
lines = file.readlines()
for l in lines:
if not l.strip(): continue #skip empty lines
if l[0] != ':': raise Exception("File Format Error\n")
l = l.strip() #fix CR-LF issues...
length = int(l[1:3],16)
address = int(l[3:7],16)
type = int(l[7:9],16)
check = int(l[-2:],16)
if type == 0x00:
if currentAddr != address:
if segmentdata:
self.segments.append( Segment(startAddr, ''.join(segmentdata)) )
startAddr = currentAddr = address
segmentdata = []
for i in range(length):
segmentdata.append( chr(int(l[9+2*i:11+2*i],16)) )
currentAddr = length + currentAddr
elif type == 0x01:
pass
else:
sys.stderr.write("Ignored unknown field (type 0x%02x) in ihex file.\n" % type)
if segmentdata:
self.segments.append( Segment(startAddr, ''.join(segmentdata)) )
def loadTIText(self, file):
"""load data from a (opened) file in TI-Text format"""
next = 1
currentAddr = 0
startAddr = 0
segmentdata = []
#Convert data for MSP430, TXT-File is parsed line by line
while next >= 1:
#Read one line
l = file.readline()
if not l: break #EOF
l = l.strip()
if l[0] == 'q': break
elif l[0] == '@': #if @ => new address => send frame and set new addr.
#create a new segment
if segmentdata:
self.segments.append( Segment(startAddr, ''.join(segmentdata)) )
startAddr = currentAddr = int(l[1:],16)
segmentdata = []
else:
for i in l.split():
segmentdata.append(chr(int(i,16)))
if segmentdata:
self.segments.append( Segment(startAddr, ''.join(segmentdata)) )
def loadELF(self, file):
"""load data from a (opened) file in ELF object format.
File must be seekable"""
import elf
obj = elf.ELFObject()
obj.fromFile(file)
if obj.e_type != elf.ELFObject.ET_EXEC:
raise Exception("No executable")
for section in obj.getSections():
if DEBUG:
sys.stderr.write("ELF section %s at 0x%04x %d bytes\n" % (section.name, section.lma, len(section.data)))
if len(section.data):
self.segments.append( Segment(section.lma, section.data) )
def loadFile(self, filename):
"""fill memory with the contents of a file. file type is determined from extension"""
#TODO: do a contents based detection
if filename[-4:].lower() == '.txt':
self.loadTIText(open(filename, "rb"))
elif filename[-4:].lower() in ('.a43', '.hex'):
self.loadIHex(open(filename, "rb"))
else:
self.loadELF(open(filename, "rb"))
def getMemrange(self, fromadr, toadr):
"""get a range of bytes from the memory. unavailable values are filled with 0xff."""
res = ''
toadr = toadr + 1 #python indxes are excluding end, so include it
while fromadr < toadr:
for seg in self.segments:
segend = seg.startaddress + len(seg.data)
if seg.startaddress <= fromadr and fromadr < segend:
if toadr > segend: #not all data in segment
catchlength = segend-fromadr
else:
catchlength = toadr-fromadr
res = res + seg.data[fromadr-seg.startaddress : fromadr-seg.startaddress+catchlength]
fromadr = fromadr + catchlength #adjust start
if len(res) >= toadr-fromadr:
break #return res
else: #undefined memory is filled with 0xff
res = res + chr(255)
fromadr = fromadr + 1 #adjust start
return res
class JTAG:
"""wrap the _parjtag extension"""
def __init__(self):
self.showprogess = 0
def connect(self, lpt=None):
"""connect to specified or default port"""
if lpt is None:
_parjtag.connect()
else:
_parjtag.connect(lpt)
def close(self):
"""release JTAG"""
_parjtag.release()
def uploadData(self, startaddress, size):
"""upload a datablock"""
if DEBUG > 1: sys.stderr.write("* uploadData()\n")
return _parjtag.memread(startaddress, size)
def actionMassErase(self):
"""Erase the flash memory completely (with mass erase command)"""
sys.stderr.write("Mass Erase...\n")
_parjtag.memerase(ERASE_MASS)
def actionMainErase(self):
"""Erase the MAIN flash memory, leave the INFO mem"""
sys.stderr.write("Erase Main Flash...\n")
_parjtag.memerase(ERASE_MAIN, 0xfffe)
def makeActionSegmentErase(self, address):
"""Selective segment erase"""
class SegmentEraser:
def __init__(self, segaddr):
self.address = segaddr
def __call__(self):
sys.stderr.write("Erase Segment @ 0x%04x...\n" % self.address)
_parjtag.memerase(ERASE_SGMT, self.address)
return SegmentEraser(address)
def actionEraseCheck(self):
"""check the erasure of required flash cells."""
sys.stderr.write("Erase Check by file ...\n")
if self.data is not None:
for seg in self.data:
data = _parjtag.memread(seg.startaddress, len(seg.data))
if data != '\xff'*len(seg.data): raise JTAGException("Erase check failed")
else:
raise JTAGException("cannot do erase check against data with not knowing the actual data")
def progess_update(self, count, total):
sys.stderr.write("\r%d%%" % (100*count/total))
def actionProgram(self):
"""program data into flash memory."""
if self.data is not None:
sys.stderr.write("Program ...\n")
if self.showprogess:
_parjtag.set_flash_callback(self.progess_update)
bytes = 0
for seg in self.data:
_parjtag.memwrite(seg.startaddress, seg.data)
bytes += len(seg.data)
if self.showprogess:
sys.stderr.write("\r")
sys.stderr.write("%i bytes programmed.\n" % bytes)
else:
raise JTAGException("programming without data not possible")
def actionVerify(self):
"""Verify programmed data"""
if self.data is not None:
sys.stderr.write("Verify ...\n")
for seg in self.data:
data = _parjtag.memread(seg.startaddress, len(seg.data))
if data != seg.data: raise JTAGException("Verify failed")
else:
raise JTAGException("verify without data not possible")
def actionReset(self):
"""perform a reset"""
sys.stderr.write("Reset device ...\n")
_parjtag.reset(0, 0)
def actionRun(self, address):
"""start program at specified address"""
raise NotImplementedError
#sys.stderr.write("Load PC with 0x%04x ...\n" % address)
def funclet(self):
"""download and start funclet"""
sys.stderr.write("Download and execute of funclet...\n")
if len(self.data) > 1:
raise JTAGException("don't know how to handle multiple segments in funclets")
_parjtag.funclet(self.data[0].data)
sys.stderr.write("Funclet OK.\n")
def usage():
"""print some help message"""
sys.stderr.write("""
USAGE: %s [options] [file]
Version: %s
If "-" is specified as file the data is read from the stdinput.
A file ending with ".txt" is considered to be in TIText format all
other filenames are considered IntelHex.
General options:
-h, --help Show this help screen.
-l, --lpt=name Specify an other parallel port.
(defaults to LPT1 (/dev/parport0 on unix)
-D, --debug Increase level of debug messages. This won't be
very useful for the average user...
-I, --intelhex Force fileformat to IntelHex
-T, --titext Force fileformat to be TIText
-f, --funclet The given file is a funclet (a small program to
be run in RAM)
-R, --ramsize Specify the amont of RAM to be used to program
flash (default 256).
Program Flow Specifiers:
-e, --masserase Mass Erase (clear all flash memory)
-m, --mainerase Erase main flash memory only
--eraseinfo Erase info flash memory only (0x1000-0x10ff)
--erase=address Selectively erase segment at the specified address
-E, --erasecheck Erase Check by file
-p, --program Program file
-v, --verify Verify by file
The order of the above options matters! The table is ordered by normal
execution order. For the options "Epv" a file must be specified.
Program flow specifiers default to "p" if a file is given.
Don't forget to specify "e" or "eE" when programming flash!
"p" already verifies the programmed data, "v" adds an additional
verification though uploading the written data for a 1:1 compare.
No default action is taken if "p" and/or "v" is given, say specifying
only "v" does a check by file of a programmed device.
Data retreiving:
-u, --upload=addr Upload a datablock (see also: -s).
-s, --size=num Size of the data block do upload. (Default is 2)
-x, --hex Show a hexadecimal display of the uploaded data.
(Default)
-b, --bin Get binary uploaded data. This can be used
to redirect the output into a file.
-i, --ihex Uploaded data is output in Intel HEX format.
This can be used to clone a device.
Do before exit:
-g, --go=address Start programm execution at specified address.
This implies option "w" (wait)
-r, --reset Reset connected MSP430. Starts application.
This is a normal device reset and will start
the programm that is specified in the reset
interrupt vector. (see also -g)
-w, --wait Wait for <ENTER> before closing parallel port.
""" % (sys.argv[0], VERSION))
def main():
global DEBUG
import getopt
filetype = None
filename = None
reset = 0
wait = 0
goaddr = None
jtag = JTAG()
toinit = []
todo = []
startaddr = None
size = 2
outputformat= HEX
lpt = None
funclet = None
ramsize = None
sys.stderr.write("MSP430 parallel JTAG programmer Version: %s\n" % VERSION)
try:
opts, args = getopt.getopt(sys.argv[1:],
"hl:weEmpvrg:Du:d:s:xbiITfR:S",
["help", "lpt=", "wait"
"masserase", "erasecheck", "mainerase", "program",
"erase=", "eraseinfo",
"verify", "reset", "go=", "debug",
"upload=", "download=", "size=", "hex", "bin", "ihex",
"intelhex", "titext", "funclet", "ramsize=", "progress"]
)
except getopt.GetoptError:
# print help information and exit:
usage()
sys.exit(2)
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-l", "--lpt"):
lpt = a
elif o in ("-w", "--wait"):
wait = 1
elif o in ("-e", "--masserase"):
toinit.append(jtag.actionMassErase) #Erase Flash
elif o in ("-E", "--erasecheck"):
toinit.append(jtag.actionEraseCheck) #Erase Check (by file)
elif o in ("-m", "--mainerase"):
toinit.append(jtag.actionMainErase) #Erase main Flash
elif o == "--erase":
try:
seg = int(a, 0)
toinit.append(jtag.makeActionSegmentErase(seg))
except ValueError:
sys.stderr.write("segment address must be a valid number in dec, hex or octal\n")
sys.exit(2)
elif o == "--eraseinfo":
toinit.append(jtag.makeActionSegmentErase(0x1000))
toinit.append(jtag.makeActionSegmentErase(0x1080))
elif o in ("-p", "--program"):
todo.append(jtag.actionProgram) #Program file
elif o in ("-v", "--verify"):
todo.append(jtag.actionVerify) #Verify file
elif o in ("-r", "--reset"):
reset = 1
elif o in ("-g", "--go"):
try:
goaddr = int(a, 0) #try to convert decimal
except ValueError:
sys.stderr.write("upload address must be a valid number in dec, hex or octal\n")
sys.exit(2)
elif o in ("-D", "--debug"):
DEBUG = DEBUG + 1
elif o in ("-u", "--upload"):
try:
startaddr = int(a, 0) #try to convert number of any base
except ValueError:
sys.stderr.write("upload address must be a valid number in dec, hex or octal\n")
sys.exit(2)
elif o in ("-s", "--size"):
try:
size = int(a, 0)
except ValueError:
sys.stderr.write("upload address must be a valid number in dec, hex or octal\n")
sys.exit(2)
#outut formats
elif o in ("-x", "--hex"):
outputformat = HEX
elif o in ("-b", "--bin"):
outputformat = BINARY
elif o in ("-i", "--ihex"):
outputformat = INTELHEX
#input formats
elif o in ("-I", "--intelhex"):
filetype = 0
elif o in ("-T", "--titext"):
filetype = 1
#others
elif o in ("-f", "--funclet"):
funclet = 1
elif o in ("-R", "--ramsize"):
try:
ramsize = int(a, 0)
except ValueError:
sys.stderr.write("ramsize must be a valid number in dec, hex or octal\n")
sys.exit(2)
elif o in ("-S", "--progress"):
jtag.showprogess = 1
if len(args) == 0:
sys.stderr.write("Use -h for help\n")
elif len(args) == 1: #a filename is given
if not funclet:
if not todo: #if there are no actions yet
todo.extend([ #add some useful actions...
jtag.actionProgram,
])
filename = args[0]
else: #number of args is wrong
usage()
sys.exit(2)
if DEBUG: #debug infos
sys.stderr.write("debug level set to %d\n" % DEBUG)
_parjtag.configure(DEBUG_OPTION, DEBUG)
sys.stderr.write("python version: %s\n" % sys.version)
#sanity check of options
if goaddr and reset:
sys.stderr.write("Warning: option --reset ignored as --go is specified!\n")
reset = 0
if startaddr and reset:
sys.stderr.write("Warning: option --reset ignored as --upload is specified!\n")
reset = 0
#prepare data to download
jtag.data = Memory() #prepare downloaded data
if filetype is not None: #if the filetype is given...
if filename is None:
raise ValueError("no filename but filetype specified")
if filename == '-': #get data from stdin
file = sys.stdin
else:
file = open(filename,"rb") #or from a file
if filetype == 0: #select load function
jtag.data.loadIHex(file) #intel hex
elif filetype == 1:
jtag.data.loadTIText(file) #TI's format
else:
raise ValueError("illegal filetype specified")
else: #no filetype given...
if filename == '-': #for stdin:
jtag.data.loadIHex(sys.stdin) #assume intel hex
elif filename:
jtag.data.loadFile(filename) #autodetect otherwise
if DEBUG > 5: sys.stderr.write("File: %r\n" % filename)
try:
jtag.connect(lpt) #try to open port
except IOError:
raise #do not handle here
else: #continue if open was successful
if ramsize is not None:
_parjtag.configure(RAMSIZE_OPTION, ramsize)
#initialization list
if toinit: #erase and erase check
if DEBUG: sys.stderr.write("Preparing device ...\n")
for f in toinit: f()
#work list
if todo:
if DEBUG > 0: #debug
#show a nice list of sheduled actions
sys.stderr.write("TODO list:\n")
for f in todo:
try:
sys.stderr.write(" %s\n" % f.func_name)
except AttributeError:
sys.stderr.write(" %r\n" % f)
for f in todo: f() #work through todo list
if reset: #reset device first if desired
jtag.actionReset()
if funclet is not None: #download and start funclet
jtag.funclet()
if goaddr is not None: #start user programm at specified address
jtag.actionRun(goaddr) #load PC and execute
#upload datablock and output
if startaddr is not None:
if goaddr: #if a program was started...
raise NotImplementedError
#TODO:
#sys.stderr.write("Waiting to device for reconnect for upload: ")
data = jtag.uploadData(startaddr, size) #upload data
if outputformat == HEX: #depending on output format
hexdump( (startaddr, data) ) #print a hex display
elif outputformat == INTELHEX:
makeihex( (startaddr, data) ) #ouput a intel-hex file
else:
sys.stdout.write(data) #binary output w/o newline!
wait = 0 #wait makes no sense as after the upload the device is still stopped
if wait: #wait at the end if desired
sys.stderr.write("Press <ENTER> ...\n") #display a prompt
raw_input() #wait for newline
_parjtag.reset(1, 1) #reset and release target
#~ jtag.actionReset()
jtag.close() #Release communication port
if __name__ == '__main__':
try:
main()
except SystemExit:
raise #let pass exit() calls
except KeyboardInterrupt:
if DEBUG: raise #show full trace in debug mode
sys.stderr.write("user abort.\n") #short messy in user mode
sys.exit(1) #set errorlevel for script usage
except Exception, msg: #every Exception is caught and displayed
if DEBUG: raise #show full trace in debug mode
sys.stderr.write("\nAn error occoured:\n%s\n" % msg) #short messy in user mode
sys.exit(1) #set errorlevel for script usage

View file

@ -1,62 +0,0 @@
Copyright (c) 2001-2002 Chris Liechti <cliechti@gmx.net>
All Rights Reserved.
This is the Python license. In short, you can use this product in
commercial and non-commercial applications, modify it, redistribute it.
A notification to the author when you use and/or modify it is welcome.
TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING THIS SOFTWARE
============================================
LICENSE AGREEMENT
-----------------
1. This LICENSE AGREEMENT is between the copyright holder of this
product, and the Individual or Organization ("Licensee") accessing
and otherwise using this product in source or binary form and its
associated documentation.
2. Subject to the terms and conditions of this License Agreement,
the copyright holder hereby grants Licensee a nonexclusive,
royalty-free, world-wide license to reproduce, analyze, test,
perform and/or display publicly, prepare derivative works, distribute,
and otherwise use this product alone or in any derivative version,
provided, however, that copyright holders License Agreement and
copyright holders notice of copyright are retained in this product
alone or in any derivative version prepared by Licensee.
3. In the event Licensee prepares a derivative work that is based on
or incorporates this product or any part thereof, and wants to make
the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to this product.
4. The copyright holder is making this product available to Licensee
on an "AS IS" basis. THE COPYRIGHT HOLDER MAKES NO REPRESENTATIONS
OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT
LIMITATION, THE COPYRIGHT HOLDER MAKES NO AND DISCLAIMS ANY
REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR
ANY PARTICULAR PURPOSE OR THAT THE USE OF THIS PRODUCT WILL
NOT INFRINGE ANY THIRD PARTY RIGHTS.
5. THE COPYRIGHT HOLDER SHALL NOT BE LIABLE TO LICENSEE OR ANY
OTHER USERS OF THIS PRODUCT FOR ANY INCIDENTAL, SPECIAL, OR
CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING,
DISTRIBUTING, OR OTHERWISE USING THIS PRODUCT, OR ANY
DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY
THEREOF.
6. This License Agreement will automatically terminate upon a
material breach of its terms and conditions.
7. Nothing in this License Agreement shall be deemed to create any
relationship of agency, partnership, or joint venture between the
copyright holder and Licensee. This License Agreement does not grant
permission to use trademarks or trade names from the copyright holder
in a trademark sense to endorse or promote products or services of
Licensee, or any third party.
8. By copying, installing or otherwise using this product, Licensee
agrees to be bound by the terms and conditions of this License
Agreement.

View file

@ -1,33 +0,0 @@
.PHONY: all FORCE clean windist
all: windist
#wrap py to exe and build windows installer
windist:
python setup.py py2exe
rm -r bin
mv dist/jtag/jtag.exe dist/msp430-jtag.exe
mv dist/jtag/* dist/
rmdir dist/jtag
mv dist bin
rm -r build
#generate test files
fill60k.a43:
python gen-ihex.py 60 >$@
fill48k.a43:
python gen-ihex.py 48 >$@
fill32k.a43:
python gen-ihex.py 32 >$@
fill16k.a43:
python gen-ihex.py 16 >$@
fill8k.a43:
python gen-ihex.py 8 >$@
fill4k.a43:
python gen-ihex.py 4 >$@
#clean up the mess...
clean:
rm -r dist build bin

View file

@ -1,182 +0,0 @@
pyJTAG
------
Software to talk to the parallel port JTAG PCB as seen with the FET kits.
It is released under a free software license,
see license.txt for more details.
(C) 2002-2003 Chris Liechti <cliechti@gmx.net>
Features
--------
- understands TI-Text and Intel-hex
- download to Flash and/or RAM, erase, verify
- reset device
- load addres into R0/PC and run
- upload a memory block MSP->PC (output as binary data or hex dump)
- written in Python, runs on Win32, Linux, BSD
- use per command line, or in a Python script
Requirements
------------
- Linux, BSD, Un*x or Windows PC
- Python 2.0 or newer, 2.2 recomeded
- Parallel JTAG hardware with an MSP430 device connected
Installation
------------
Python installations are available from www.python.org. On Windows simply
use the installer. The win32all package has an installer too. These
installations should run fine with the deafults.
On Linux just Python is needed. On some distributions is Python 1.5.2
installed per default. You may meed to change the first line in the script
from "python" to "python2". Maybe Python 2.x is in a separate package that
has to be installed. There are rpm and deb binary packages and a source
tarball available through the Python homepage.
The pyjtag archive can simply be unpacked to a directory, Windows users
can use WinZip or WinRar among others to extract the gzipped tar file.
If you want to run it from everywhere the directory where the file jtag.py
is, should be added to the PATH.
Look at "~/.profile", "/etc/profile" on Linux, "autoexec.bat" on Win9x/ME,
System Properties/Environment in Win2000/NT/XP.
_parjtag.so/dll from the jtag archive must be copied to the same directory as
jtag.py. On Windows also MSP430mspgcc.dll and HIL.dll must be located in the
same dir or somewhere in the PATH.
Short introduction
------------------
This software uses the JTAG hardware that comes with the FET kits. It is
connected to the parallel port.
The program can be started by typing "python jtag.py" in a console. Often
it works also with just "jtag.py" or "./jtag.py".
USAGE: jtag.py [options] [file]
If "-" is specified as file the data is read from the stdinput.
A file ending with ".txt" is considered to be in TIText format all
other filenames are considered IntelHex.
General options:
-h, --help Show this help screen.
-l, --lpt=name Specify an other parallel port.
(defaults to LPT1 (/dev/parport0 on unix)
-D, --debug Increase level of debug messages. This won't be
very useful for the average user...
-I, --intelhex Force fileformat to IntelHex
-T, --titext Force fileformat to be TIText
-f, --funclet The given file is a funclet (a small program to
be run in RAM)
-R, --ramsize Specify the amont of RAM to be used to program
flash (default 256).
Program Flow Specifiers:
-e, --masserase Mass Erase (clear all flash memory)
-m, --mainerase Erase main flash memory only
--eraseinfo Erase info flash memory only (0x1000-0x10ff)
--erase=address Selectively erase segment at the specified address
-E, --erasecheck Erase Check by file
-p, --program Program file
-v, --verify Verify by file
The order of the above options matters! The table is ordered by normal
execution order. For the options "Epv" a file must be specified.
Program flow specifiers default to "p" if a file is given.
Don't forget to specify "e" or "eE" when programming flash!
"p" already verifies the programmed data, "v" adds an additional
verification though uploading the written data for a 1:1 compare.
No default action is taken if "p" and/or "v" is given, say specifying
only "v" does a check by file of a programmed device.
Data retreiving:
-u, --upload=addr Upload a datablock (see also: -s).
-s, --size=num Size of the data block do upload. (Default is 2)
-x, --hex Show a hexadecimal display of the uploaded data.
(Default)
-b, --bin Get binary uploaded data. This can be used
to redirect the output into a file.
-i, --ihex Uploaded data is output in Intel HEX format.
This can be used to clone a device.
Do before exit:
-g, --go=address Start programm execution at specified address.
This implies option "w" (wait)
-r, --reset Reset connected MSP430. Starts application.
This is a normal device reset and will start
the programm that is specified in the reset
interrupt vector. (see also -g)
-w, --wait Wait for <ENTER> before closing parallel port.
Examples
--------
These examples assume that you have added the installation directory to
the PATH. Type the full path to jtag.py otherwise and maybe use
"python jtag.py". Depending on installation it may also appear under the
name "msp430-jtag".
jtag.py -e
Only erase flash.
jtag.py -eErw 6port.a43
Erase flash, erase check, download an executable, run it (reset)
and wait.
jtag.py -mS -R 2048 6port.a43
Use ramsize option on a device with 2k RAM to speed up
download. Of course any value from 128B up to the maximum
a device has is allowed.
The progress and mainerase options are also activated.
Only erasing the main memory is useful to keep calibration
data in the information memory.
jtag.py 6port.a43
Download of an executable to en empty (new or erased) device.
(Note that in new devices some of the first bytes in the
information memory are random data. If data should be
downloaded there, specify -eE.)
jtag.py --go=0x220 ramtest.a43
Download a program into RAM and run it, may not work
with all devices.
jtag.py -f blinking.a43
Download a program into RAM and run it. It must be
a special format with "startadr", "entrypoint",
"exitpoint" as the first three words in the data
and it must end on "jmp $". See MSP430debug sources
for more info.
jtag.py -u 0x0c00 -s 1024
Get a memory dump in HEX, from the bootstrap loader.
or save the binary in a file:
"python jtag.py -u 0x0c00 -s 1024 -b >dump.bin"
or as an intel-hex file:
"python jtag.py -u 0x0c00 -s 1024 -i >dump.a43"
jtag.py -r
Just start the user program (with a reset).
cat 6port.a43|jtag.py -e -
Pipe the data from "cat" to jtag.py to erase and program the
flash. (un*x example, don't forget the dash at the end of the
line)
History
-------
1.0 public release
1.1 fix of verify error
1.2 use the verification during programming
1.3 meinerase, progress options, ihex output
References
----------
- Python: http://www.python.org
- Texas Instruments MSP430 Homepage, links to Datasheets and Application
Notes: http://www.ti.com/sc/msp430

View file

@ -1,9 +0,0 @@
# setup.py
from distutils.core import setup
import glob
import py2exe
setup(
name="msp430-jtag",
scripts=["jtag.py"],
)

View file

@ -1,58 +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 functionality for the ESB platform.
* \author
* Nicolas Tsiftes <nvt@sics.se>
* Niclas Finne <nfi@sics.se>
*/
#include "cfs-coffee-arch.h"
static const unsigned char nullb[COFFEE_SECTOR_SIZE < 32 ? COFFEE_SECTOR_SIZE : 32] = {0};
void
cfs_coffee_arch_erase(uint16_t sector)
{
unsigned int i;
for(i = 0; i <= COFFEE_SECTOR_SIZE - sizeof(nullb); i += sizeof(nullb)) {
eeprom_write(COFFEE_START + sector * COFFEE_SECTOR_SIZE + i,
(unsigned char *)nullb, sizeof(nullb));
}
if(i < COFFEE_SECTOR_SIZE) {
eeprom_write(COFFEE_START + sector * COFFEE_SECTOR_SIZE + i,
(unsigned char *)nullb, COFFEE_SECTOR_SIZE - i);
}
}

View file

@ -1,77 +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 ESB platform.
* \author
* Nicolas Tsiftes <nvt@sics.se>
* Niclas Finne <nfi@sics.se>
*/
#ifndef CFS_COFFEE_ARCH_H
#define CFS_COFFEE_ARCH_H
#include "contiki-conf.h"
#include "dev/eeprom.h"
#define COFFEE_SECTOR_SIZE 1024UL
#define COFFEE_PAGE_SIZE 64UL
#define COFFEE_START COFFEE_SECTOR_SIZE
#define COFFEE_SIZE (32 * 1024U - COFFEE_START)
#define COFFEE_NAME_LENGTH 16
#define COFFEE_MAX_OPEN_FILES 2
#define COFFEE_FD_SET_SIZE 2
#define COFFEE_LOG_TABLE_LIMIT 16
#define COFFEE_DYN_SIZE 1024
#define COFFEE_LOG_SIZE 256
#define COFFEE_MICRO_LOGS 0
#if COFFEE_START < CFS_EEPROM_CONF_OFFSET
#error COFFEE_START must be at least as large as CFS_EEPROM_CONF_OFFSET
#error Change in cfs-coffee-arch.h
#endif /* COFFEE_START < CFS_EEPROM_CONF_OFFSET */
#define COFFEE_WRITE(buf, size, offset) \
eeprom_write(COFFEE_START + (offset), (unsigned char *)(buf), (size))
#define COFFEE_READ(buf, size, offset) \
eeprom_read(COFFEE_START + (offset), (unsigned char *)(buf), (size))
#define COFFEE_ERASE(sector) cfs_coffee_arch_erase(sector)
void cfs_coffee_arch_erase(uint16_t sector);
typedef int16_t coffee_page_t;
#endif /* !COFFEE_ARCH_H */

View file

@ -1,124 +0,0 @@
#ifndef __CONTIKI_CONF_H__
#define __CONTIKI_CONF_H__
#define PLATFORM_HAS_LEDS 1
#define PLATFORM_HAS_BUTTON 1
#define PLATFORM_HAS_BATTERY 1
/* DCO speed resynchronization for more robust UART, etc. */
#define DCOSYNCH_CONF_ENABLED 1
#define DCOSYNCH_CONF_PERIOD 30
#define SERIAL_LINE_CONF_BUFSIZE 64
#define TIMESYNCH_CONF_ENABLED 0
#define PROFILE_CONF_ON 0
#define ENERGEST_CONF_ON 1
#define HAVE_STDINT_H
#include "msp430def.h"
#define PROCESS_CONF_NUMEVENTS 8
#define PROCESS_CONF_STATS 0
/* CPU target speed in Hz */
#define F_CPU 2457600uL
/* Our clock resolution, this is the same as Unix HZ. Must be a power
of two (see clock.c for details). */
#define CLOCK_CONF_SECOND 64UL
#define NODE_ID_EEPROM_OFFSET 0x0010 /* - 0x0014 */
#define CFS_EEPROM_CONF_OFFSET 0x0040
#define CC_CONF_REGISTER_ARGS 1
#define CC_CONF_FUNCTION_POINTER_ARGS 1
#define CC_CONF_VA_ARGS 1
#define CCIF
#define CLIF
typedef unsigned long clock_time_t;
#define LOG_CONF_ENABLED 0
#define PACKETBUF_CONF_ATTRS_INLINE 1
#define NETSTACK_CONF_RADIO tr1001_driver
#if WITH_UIP
/* Network setup for IPv4 */
#define NETSTACK_CONF_NETWORK uip_driver
#define NETSTACK_CONF_MAC nullmac_driver
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_FRAMER framer_nullmac
#define QUEUEBUF_CONF_NUM 0
#define QUEUEBUF_CONF_REF_NUM 0
#define ROUTE_CONF_ENTRIES 0
#else /* WITH_UIP */
/* Network setup for non-IPv4 (rime). */
#define NETSTACK_CONF_NETWORK rime_driver
#define NETSTACK_CONF_MAC nullmac_driver
#define NETSTACK_CONF_RDC nullrdc_driver
#define NETSTACK_CONF_FRAMER framer_nullmac
#define QUEUEBUF_CONF_NUM 1
#define QUEUEBUF_CONF_REF_NUM 1
#define ROUTE_CONF_ENTRIES 4
#endif /* WITH_UIP */
/**
* The statistics data type.
*
* This datatype determines how high the statistics counters are able
* to count.
*/
typedef unsigned short uip_stats_t;
#define UIP_CONF_ICMP_DEST_UNREACH 1
#define UIP_CONF_IP_FORWARD 1
#define UIP_CONF_DHCP_LIGHT
#define UIP_CONF_LLH_LEN 0
#define UIP_CONF_BUFFER_SIZE 110
#define UIP_CONF_RECEIVE_WINDOW (UIP_CONF_BUFFER_SIZE - 40)
#define UIP_CONF_MAX_CONNECTIONS 4
#define UIP_CONF_MAX_LISTENPORTS 4
#define UIP_CONF_UDP_CONNS 3
#define UIP_CONF_FWCACHE_SIZE 1
#define UIP_CONF_BROADCAST 1
#define UIP_ARCH_IPCHKSUM 1
#define UIP_CONF_UDP_CHECKSUMS 1
#define UIP_CONF_PINGADDRCONF 0
#define UIP_CONF_LOGGING 0
#define UIP_CONF_RESOLV_ENTRIES 1
#define UIP_CONF_TCP_SPLIT 0
#define LOADER_CONF_ARCH "loader/loader-arch.h"
#define ELFLOADER_CONF_TEXT_IN_ROM 1
#define ELFLOADER_CONF_DATAMEMORY_SIZE 100
#define ELFLOADER_CONF_TEXTMEMORY_SIZE 0x1000
#define WEBSERVER_CONF_CGI_CONNS 1
/* LEDs ports. */
#define LEDS_PxDIR P2DIR
#define LEDS_PxOUT P2OUT
#define LEDS_CONF_RED 0x01
#define LEDS_CONF_GREEN 0x02
#define LEDS_CONF_YELLOW 0x04
#ifdef PROJECT_CONF_H
#include PROJECT_CONF_H
#endif /* PROJECT_CONF_H */
#endif /* __CONTIKI_CONF_H__ */

View file

@ -1,35 +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.
*
*/
void
init_apps(void)
{
}

View file

@ -1,43 +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-esb.h"
#include "dev/esb-sensors.h"
void
init_lowlevel(void)
{
esb_sensors_init();
esb_sensors_on();
leds_init();
rs232_init();
}

View file

@ -1,319 +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 <stdio.h>
#include <string.h>
#include "contiki.h"
#include "contiki-esb.h"
#include "dev/watchdog.h"
#include "sys/autostart.h"
#include "net/uip-driver.h"
#include "net/netstack.h"
#if WITH_UIP
static struct uip_fw_netif tr1001if =
{UIP_FW_NETIF(0,0,0,0, 0,0,0,0, uip_driver_send)};
#if WITH_SLIP
static struct uip_fw_netif slipif =
{UIP_FW_NETIF(172,16,0,0, 255,255,255,0, slip_send)};
#endif /* WITH_SLIP */
#endif /* WITH_UIP */
#ifdef DCOSYNCH_CONF_PERIOD
#define DCOSYNCH_PERIOD DCOSYNCH_CONF_PERIOD
#else
#define DCOSYNCH_PERIOD 30
#endif /* DCOSYNCH_CONF_PERIOD */
#ifdef DCOSYNCH_CONF_ENABLED
#define DCOSYNCH_ENABLED DCOSYNCH_CONF_ENABLED
#else
#define DCOSYNCH_ENABLED 0
#endif /* DCOSYNCH_CONF_ENABLED */
#if DCOSYNCH_ENABLED
static struct timer dco_timer;
#endif /* DCOSYNCH_ENABLED */
SENSORS(&button_sensor, &sound_sensor, &vib_sensor,
&pir_sensor, &radio_sensor, &battery_sensor, &ctsrts_sensor,
&temperature_sensor);
/*---------------------------------------------------------------------------*/
static void
set_rime_addr(void)
{
int i;
rimeaddr_t rimeaddr;
rimeaddr.u8[0] = node_id & 0xff;
rimeaddr.u8[1] = node_id >> 8;
rimeaddr_set_node_addr(&rimeaddr);
printf("Rime started with address ");
for(i = 0; i < sizeof(rimeaddr.u8) - 1; i++) {
printf("%u.", rimeaddr.u8[i]);
}
printf("%u\n", rimeaddr.u8[i]);
}
/*---------------------------------------------------------------------------*/
#if WITH_UIP
static void
init_uip_net(void)
{
uip_ipaddr_t hostaddr;
uip_init();
uip_fw_init();
process_start(&tcpip_process, NULL);
#if WITH_SLIP
process_start(&slip_process, NULL);
rs232_set_input(slip_input_byte);
#endif /* WITH_SLIP */
process_start(&uip_fw_process, NULL);
if (node_id > 0) {
/* node id is set, construct an ip address based on the node id */
uip_ipaddr(&hostaddr, 172, 16, 1, node_id & 0xff);
uip_sethostaddr(&hostaddr);
}
#if WITH_SLIP
uip_fw_register(&slipif);
#endif /* WITH_SLIP */
uip_fw_default(&tr1001if);
}
#endif /* WITH_UIP */
/*---------------------------------------------------------------------------*/
static void
print_processes(struct process * const processes[])
{
printf("Starting");
while(*processes != NULL) {
printf(" '%s'", (*processes)->name);
processes++;
}
/* Needed to force link with putchar */
putchar('\n');
}
/*---------------------------------------------------------------------------*/
static void init_ports_toberemoved() {
////////// Port 1 ////
P1SEL = 0x00;
P1DIR = 0x81; // Outputs: P10=IRSend, P17=RS232RTS
// Inputs: P11=Light, P12=IRRec, P13=PIR, P14=Vibration,
// P15=Clockalarm, P16=RS232CTS
P1OUT = 0x00;
////////// Port 2 ////
P2SEL = 0x00; // No Sels
P2DIR = 0x7F; // Outpus: P20..P23=Leds+Beeper, P24..P26=Poti
// Inputs: P27=Taster
P2OUT = 0x77;
////////// Port 3 ////
P3SEL = 0xE0; // Sels for P34..P37 to activate UART,
P3DIR = 0x5F; // Inputs: P30..P33=CON4, P35/P37=RXD Transceiver/RS232
// OutPuts: P36/P38=TXD Transceiver/RS232
P3OUT = 0xE0; // Output a Zero on P34(TXD Transceiver) and turn SELECT off when receiving!!!
////////// Port 4 ////
P4SEL = 0x00; // CON5 Stecker
P4DIR = 0xFF;
P4OUT = 0x00;
////////// Port 5 ////
P5SEL = 0x00; // P50/P51= Clock SDA/SCL, P52/P53/P54=EEPROM SDA/SCL/WP
P5DIR = 0xDA; // P56/P57=Transceiver CNTRL0/1
P5OUT = 0x0F;
////////// Port 6 ////
P6SEL = 0x00; // P60=Microphone, P61=PIR digital (same as P13), P62=PIR analog
P6DIR = 0x00; // P63=extern voltage, P64=battery voltage, P65=Receive power
P6OUT = 0x00;
}
/*---------------------------------------------------------------------------*/
int
main(void)
{
msp430_cpu_init();
init_ports_toberemoved();
init_lowlevel();
clock_init();
rtimer_init();
process_init();
random_init(0);
node_id_restore();
process_start(&etimer_process, NULL);
process_start(&sensors_process, NULL);
ctimer_init();
set_rime_addr();
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");
}
netstack_init();
printf("%s %s, channel check rate %lu Hz\n",
NETSTACK_MAC.name, NETSTACK_RDC.name,
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
NETSTACK_RDC.channel_check_interval()));
beep_spinup();
leds_on(LEDS_RED);
clock_delay(100);
leds_off(LEDS_RED);
#if !WITH_SLIP
rs232_set_input(serial_line_input_byte);
serial_line_init();
#endif
#if WITH_UIP
init_uip_net();
#endif /* WITH_UIP */
#if PROFILE_CONF_ON
profile_init();
#endif /* PROFILE_CONF_ON */
#if ENERGEST_CONF_ON
energest_init();
ENERGEST_ON(ENERGEST_TYPE_CPU);
#endif /* ENERGEST_CONF_ON */
init_apps();
print_processes(autostart_processes);
autostart_start(autostart_processes);
#if DCOSYNCH_ENABLED
timer_set(&dco_timer, DCOSYNCH_PERIOD * CLOCK_SECOND);
#endif /* DCOSYNCH_ENABLED */
/*
* This is the scheduler loop.
*/
watchdog_start();
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.
*/
dint();
if(process_nevents() != 0) {
eint();
} else {
#if ENERGEST_CONF_ON
static unsigned long irq_energest = 0;
#endif /* ENERGEST_CONF_ON */
#if DCOSYNCH_CONF_ENABLED
/* before going down to sleep possibly do some management */
if(timer_expired(&dco_timer)) {
timer_reset(&dco_timer);
msp430_sync_dco();
}
#endif /* DCOSYNCH_CONF_ENABLED */
#if ENERGEST_CONF_ON
/* 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);
#endif /* ENERGEST_CONF_ON */
watchdog_stop();
_BIS_SR(GIE | SCG0 | CPUOFF); /* LPM1 sleep. */
#if ENERGEST_CONF_ON
/* 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();
ENERGEST_OFF(ENERGEST_TYPE_LPM);
ENERGEST_ON(ENERGEST_TYPE_CPU);
#endif /* ENERGEST_CONF_ON */
watchdog_start();
}
}
}
/*---------------------------------------------------------------------------*/
/* char *arg_alloc(char size) {return NULL;} */
/* void arg_init(void) {} */
/* void arg_free(char *arg) {} */
/*---------------------------------------------------------------------------*/
#if UIP_LOGGING
void
uip_log(char *m)
{
printf("uIP log: '%s'\n", m);
}
#endif /* UIP_LOGGING */

View file

@ -1,72 +0,0 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#ifndef __CONTIKI_ESB_H__
#define __CONTIKI_ESB_H__
#include "contiki.h"
#include "contiki-net.h"
#include "contiki-lib.h"
#include "lib/sensors.h"
#include "dev/hwconf.h"
#include "dev/lpm.h"
#include "dev/rs232.h"
#include "dev/serial-line.h"
#include "dev/slip.h"
#include "sys/node-id.h"
#include "dev/vib-sensor.h"
#include "dev/pir-sensor.h"
#include "dev/button-sensor.h"
#include "dev/radio-sensor.h"
#include "dev/sound-sensor.h"
#include "dev/battery-sensor.h"
#include "dev/temperature-sensor.h"
#include "dev/ctsrts-sensor.h"
#include "dev/beep.h"
#include "dev/ir.h"
#include "dev/leds.h"
#include "sys/node-id.h"
void msp430_cpu_init(void);
void init_lowlevel(void);
void init_apps(void);
#endif /* __CONTIKI_ESB_H__ */

View file

@ -1,44 +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-esb.h"
#include "codeprop-tmp.h"
#include <stdio.h>
#include <stdlib.h>
AUTOSTART_PROCESSES(&codeprop_process);
int core_dummy_4711(int len) {
char t[1];
int l = snprintf(t, sizeof(t), "%d", len % 9);
printf("%d\n", l / 2);
return len / 4;
}

View file

@ -1,91 +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/02/08 00:00:45 $
* $Revision: 1.6 $
*/
#include "contiki.h"
#include "dev/battery-sensor.h"
#include "dev/irq.h"
const struct sensors_sensor battery_sensor;
static unsigned int battery_value;
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
battery_value = ADC12MEM6;
return 0;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
return ADC12MEM6/*battery_value*/;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
battery_value = 0;
return 1;
case SENSORS_ACTIVE:
if(value) {
if(!irq_adc12_active(6)) {
irq_adc12_activate(6, (INCH_4 + SREF_0), irq);
}
} else {
irq_adc12_deactivate(6);
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return irq_adc12_active(6);
}
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR,
value, configure, status);

View file

@ -1,47 +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: 2006/06/18 08:07:30 $
* $Revision: 1.3 $
*/
#ifndef __BATTERY_SENSOR_H__
#define __BATTERY_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor battery_sensor;
#define BATTERY_SENSOR "Battery"
#endif /* __BATTERY_SENSOR_H__ */

View file

@ -1,167 +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 "contiki-esb.h"
#include "sys/clock.h"
#define ON 1
#define OFF 0
/*
* Flag to indicate if any of these functions should generate a sound
* or not. The function beep_off() is used to change this flag so none
* of the functions will generate sounds and beep_on() to turn sound
* back on.
*/
static char onoroff = ON;
/*
* BEEPER_BIT is the bit in the io-register that is connected to the actual
* beeper, setting the bit high vill generate a high pitch tone.
*/
#define BEEPER_BIT 0x08
/*-----------------------------------------------------------------------------------*/
void
beep_alarm(int alarmmode, int len)
{
len = len / 200;
while(len > 0) {
/*
* Check here if we should beep or not since if we do it outside the
* while loop the call to this function would take muck less time, i.e.
* beep_on()/beep_off() would have side effects that might not be
* predictable.
*/
if(onoroff == ON) {
if((alarmmode == BEEP_ALARM1) && ((len & 7) > 4)) {
P2OUT |= BEEPER_BIT;
} else if((alarmmode == BEEP_ALARM2) && ((len & 15) > 12)) {
P2OUT |= BEEPER_BIT;
} else {
P2OUT &= ~BEEPER_BIT;
}
}
clock_delay(200);
len--;
}
P2OUT &= ~BEEPER_BIT;
}
/*-----------------------------------------------------------------------------------*/
void
beep_beep(int i)
{
if(onoroff == ON) {
/* Beep. */
P2OUT |= BEEPER_BIT;
clock_delay(i);
P2OUT &= ~BEEPER_BIT;
}
}
/*-----------------------------------------------------------------------------------*/
void
beep(void)
{
beep_beep(20);
}
/*-----------------------------------------------------------------------------------*/
void
beep_down(int d)
{
int i;
for(i = 8; i < d; i += i / 8) {
beep_beep(10);
clock_delay(i);
}
}
/*-----------------------------------------------------------------------------------*/
void
beep_on(void)
{
onoroff = ON;
}
/*-----------------------------------------------------------------------------------*/
void
beep_off(void)
{
onoroff = OFF;
}
/*-----------------------------------------------------------------------------------*/
void
beep_spinup(void)
{
unsigned int i;
for(i = 10000; i > 80; i -= i / 20) {
beep_beep(2);
clock_delay(i);
}
for(i = 4980; i > 2000; i -= 20) {
leds_on(LEDS_ALL);
clock_delay(5000 - i);
leds_off(LEDS_ALL);
clock_delay(i);
}
}
/*-----------------------------------------------------------------------------------*/
void
beep_quick(int n)
{
int i;
for(i = 0; i < n; ++i) {
beep_beep(2000);
clock_delay(20000);
}
}
/*-----------------------------------------------------------------------------------*/
void beep_long(clock_time_t len) {
/*
* Check if the beeper is turned on or off, i.e. if a call should generate
* a noise or not.
*/
if(onoroff == ON) {
/* Turn on the beeper. */
P2OUT |= BEEPER_BIT;
}
clock_wait(len);
if(onoroff == ON) {
/* Turn the beeper off. */
P2OUT &= ~BEEPER_BIT;
}
}
/*-----------------------------------------------------------------------------------*/

View file

@ -1,162 +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.
*
*/
/**
* \addtogroup esb
* @{
*/
/**
* \defgroup beeper Beeper interface
* @{
*/
/**
* \file
* Interface to the beeper.
* \author Adam Dunkels <adam@sics.se>
*
*/
#ifndef __BEEP_H__
#define __BEEP_H__
#define BEEP_ALARM1 1
#define BEEP_ALARM2 2
#include "sys/clock.h"
/**
* Beep for a specified time.
*
* This function causes the beeper to beep for the specified time. The
* time is measured in the same units as for the clock_delay()
* function.
*
* \note This function will hang the CPU during the beep.
*
* \note This function will stop any beep that was on previously when this
* function ends.
*
* \note If the beeper is turned off with beep_off() this call will still
* take the same time, though it will be silent.
*
* \param len The length of the beep.
*
*/
void beep_beep(int len);
/**
* Beep an alarm for a specified time.
*
* This function causes the beeper to beep for the specified time. The
* time is measured in the same units as for the clock_delay()
* function.
*
* \note This function will hang the CPU during the beep.
*
* \note This function will stop any beep that was on previously when this
* function ends.
*
* \note If the beeper is turned off with beep_off() this call will still
* take the same time, though it will be silent.
*
* \param alarmmode The alarm mode (BEEP_ALARM1,BEEP_ALARM2)
* \param len The length of the beep.
*
*/
void beep_alarm(int alarmmode, int len);
/**
* Produces a quick click-like beep.
*
* This function produces a short beep that sounds like a click.
*
*/
void beep(void);
/**
* A beep with a pitch-bend down.
*
* This function produces a pitch-bend sound with deecreasing
* frequency.
*
* \param len The length of the pitch-bend.
*
*/
void beep_down(int len);
/**
* Turn the beeper on.
*
* This function turns on the beeper. The beeper is turned off with
* the beep_off() function.
*/
void beep_on(void);
/**
* Turn the beeper off.
*
* This function turns the beeper off after it has been turned on with
* beep_on().
*/
void beep_off(void);
/**
* Produce a sound similar to a hard-drive spinup.
*
* This function produces a sound that is intended to be similar to
* the sound a hard-drive makes when it starts.
*
*/
void beep_spinup(void);
/**
* Beep for a long time (seconds)
*
* This function produces a beep with the specified length and will
* not return until the beep is complete. The length of the beep is
* specified using CLOCK_SECOND: a two second beep is CLOCK_SECOND *
* 2, and a quarter second beep is CLOCK_SECOND / 4.
*
* \note If the beeper is turned off with beep_off() this call will still
* take the same time, though it will be silent.
*
* \param len The length of the beep, measured in units of CLOCK_SECOND
*/
void beep_long(clock_time_t len);
void beep_quick(int num);
/** @} */
/** @} */
#endif /* __BEEP_H__ */

View file

@ -1,101 +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 "dev/button-sensor.h"
#include "dev/hwconf.h"
#include "isr_compat.h"
const struct sensors_sensor button_sensor;
static struct timer debouncetimer;
HWCONF_PIN(BUTTON, 2, 7);
HWCONF_IRQ(BUTTON, 2, 7);
/*---------------------------------------------------------------------------*/
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 value)
{
switch(type) {
case SENSORS_HW_INIT:
BUTTON_IRQ_EDGE_SELECTD();
BUTTON_SELECT();
BUTTON_MAKE_INPUT();
return 1;
case SENSORS_ACTIVE:
if(value) {
if(!BUTTON_IRQ_ENABLED()) {
timer_set(&debouncetimer, 0);
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

@ -1,145 +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.
*
*/
/**
* RTS/CTS (Request to Send/Clear to Send) are the signals used for hardware
* flow control. By setting the RTS line to "ON" the host tells the connected
* device that it is ready to receive data. Hardware flow control is not
* implemented yet. This implementation is just so some application can use
* the pins, it would also be possible for rs232.c to use it for hardware
* handshake but as said, that is not implemented yet.
*/
#include "dev/ctsrts-sensor.h"
#include "dev/irq.h"
#include "dev/hwconf.h"
const struct sensors_sensor ctsrts_sensor;
HWCONF_PIN(RS232RTS, 1, 7);
#define RS232CTS_IRQ() 6
HWCONF_PIN(RS232CTS, 1, RS232CTS_IRQ());
HWCONF_IRQ(RS232CTS, 1, RS232CTS_IRQ());
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
/* Change the flank triggering for the irq so we will detect next shift. */
if(RS232CTS_READ()) {
RS232CTS_IRQ_EDGE_SELECTD();
} else {
RS232CTS_IRQ_EDGE_SELECTU();
}
sensors_changed(&ctsrts_sensor);
return 1;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
/*
* Invert the bit and return.
* This is strange, accordingly to the MSP430 manual section 9.2.1, Input
* Register PxIN the bit should be low when input is low. In RealTerm on
* the PC I set RTS which is coupled to the CTS on the esb and I read a 0.
* Maybe RTS is defined active LOW on the PC? //Kalle
*/
return RS232CTS_READ() ? 0 : 1;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
RS232RTS_SELECT();
RS232RTS_MAKE_OUTPUT();
RS232RTS_CLEAR();
RS232CTS_SELECT();
RS232CTS_MAKE_INPUT();
return 1;
case SENSORS_ACTIVE:
if(value) {
if(!RS232CTS_IRQ_ENABLED()) {
/*
* Check current status on the CTS pin and set IRQ flank so we
* will detect a shift.
*/
if(RS232CTS_READ()) {
RS232CTS_IRQ_EDGE_SELECTD();
} else {
RS232CTS_IRQ_EDGE_SELECTU();
}
irq_port1_activate(RS232CTS_IRQ(), irq);
RS232CTS_ENABLE_IRQ();
}
} else {
RS232CTS_DISABLE_IRQ();
irq_port1_deactivate(RS232CTS_IRQ());
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return RS232CTS_IRQ_ENABLED();
}
return 0;
}
/*---------------------------------------------------------------------------*/
/**
* Indicate to host/client we are NOT ready to receive data. Sets the RTS pin
* to low.
*/
void ctsrts_rts_clear(void) {
RS232RTS_CLEAR();
}
/*---------------------------------------------------------------------------*/
/**
* Request host/client to send data. Sets the RTS pin to high.
*/
void ctsrts_rts_set(void) {
RS232RTS_SET();
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(ctsrts_sensor, CTSRTS_SENSOR,
value, configure, status);

View file

@ -1,61 +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.
*
*/
/**
* RTS/CTS (Request to Send/Clear to Send) are the signals used for hardware
* flow control. By setting the RTS line to "ON" the host tells the connected
* device that it is ready to receive data. Hardware flow control is not
* implemented yet. This implementation is just so some application can use
* the pins, it would also be possible for rs232.c to use it for hardware
* handshake but that is not implemented yet.
*/
#ifndef __CTSRTS_SENSOR_H__
#define __CTSRTS_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor ctsrts_sensor;
#define CTSRTS_SENSOR "CTSRTS"
/**
* Indicate to host/client we are NOT ready to receive data. Sets the RTS pin
* to low.
*/
void ctsrts_rts_clear(void);
/**
* Request host/client to send data. Sets the RTS pin to high.
*/
void ctsrts_rts_set(void);
#endif /* __CTSRTS_SENSOR_H__ */

View file

@ -1,228 +0,0 @@
/*
Copyright 2005, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of Freie Universitaet Berlin (FUB) 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 FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB 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 implementation was developed by the CST group at the FUB.
For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2005
*/
/**
* Part of the source code from ScatterWeb 2.2 (ScatterWeb.{Data,System}.c)
* released by Freie Universitaet Berlin has been reworked and
* reformatted to fit the Contiki ESB port.
*/
#include "contiki.h"
#include "dev/ds1629.h"
#define SDA_HIGH (P5OUT |= 0x01) /* RTC data line high */
#define SDA_LOW (P5OUT &= 0xFE) /* RTC data line low */
#define SCL_HIGH (P5OUT |= 0x02) /* RTC clock line high */
#define SCL_LOW (P5OUT &= 0xFD) /* RTC clock line low */
#define BUS_READ 0x9F
#define BUS_WRITE 0x9E
#define ACC_CSR 0xAC /* Access Configuration/Control Register */
#define ACC_CLOCK 0xC0 /* Access Clock Register */
#define ACC_CLOCK_ALARM 0xC7 /* Access Clock Alarm Register */
#define ACC_TH 0xA1 /* Access Thermostat Setpoint High */
#define ACC_TL 0xA2 /* Access Thermostat Setpoint Low */
#define ACC_CSRAM 0x17 /* Access Clock 32 byte SRAM */
#define ACC_RT 0xAA /* Access Read Temperatur Register */
#define CSR_OS1 (0x80)
#define CSR_OS0 (0x40)
#define CSR_A1 (0x20)
#define CSR_A0 (0x10)
#define CSR_CNV (0x04)
#define CSR_POL (0x02)
#define CSR_1SH (0x01)
#define CSR_DEFAULT (CSR_OS1 + CSR_OS0 + CSR_A1 + CSR_CNV + CSR_1SH + CSR_POL)
/**
* Temperature type (built on a signed int). It's a signed (twos complement)
* fixed point value with 8 bits before comma and 7 bits after. So Bit 15 is
* sign, Bit14-7 is before comma and Bit 6-0 after comma.
*
* @since 2.0
*/
typedef union { unsigned int u; signed int s; } temp_t;
/*--------------------------------------------------------------------------*/
/* Puts the start condition on bus. */
static void
cl_start(void)
{
P5DIR |= 0x03; /* ensure: P50(SDA), P51(SCL) output */
SCL_LOW; _NOP(); _NOP();
SDA_HIGH; _NOP(); _NOP();
SCL_HIGH; _NOP(); _NOP();
SDA_LOW; _NOP(); _NOP();
SCL_LOW; _NOP(); _NOP();
}
/*--------------------------------------------------------------------------*/
/* Puts the stop condition on bus. */
static void
cl_stop()
{
SCL_LOW; _NOP(); _NOP();
SDA_LOW; _NOP(); _NOP();
SCL_HIGH; _NOP(); _NOP();
SDA_HIGH; _NOP(); _NOP();
SCL_LOW; _NOP(); _NOP();
P5DIR &= ~0x03;
}
/*--------------------------------------------------------------------------*/
/* Writes a byte on the bus, returns the acknowledge bit. */
static uint16_t
cl_writeOnBus(uint8_t byte)
{
uint16_t i, ack;
for(i=0;i<8;i++) {
if(byte & 0x80) SDA_HIGH; else SDA_LOW;
SCL_HIGH;
byte = byte << 1; _NOP();
SCL_LOW; _NOP();
}
/* check ack */
P5DIR &= 0xFE; /* P50(SDA) input */
SCL_HIGH;
if(P5IN & 0x01) ack = 0; else ack = 1; /* test if ack=0, else error */
_NOP();
SCL_LOW;
P5DIR |= 0x01; /* P50(SDA) output */
return ack;
}
/*--------------------------------------------------------------------------*/
static uint8_t
cl_readFromBus(uint16_t ack)
{
uint16_t i;
uint8_t byte = 0;
P5DIR &= 0xFE; /* P50(SDA) input */
for(i=0;i<8;i++) {
byte = byte << 1;
SCL_HIGH;
if(P5IN & 0x01) byte |= 0x01; else byte &= 0xFE;
SCL_LOW;
}
P5DIR |= 0x01; /* P50(SDA) output */
if(ack) SDA_LOW; else SDA_HIGH;
SCL_HIGH;
SCL_LOW;
return byte;
}
/*--------------------------------------------------------------------------*/
static uint16_t
getReg16bit(uint8_t acc, uint16_t bitmask)
{
uint16_t config = 0;
do cl_start();
while(!cl_writeOnBus(BUS_WRITE));
cl_writeOnBus(acc);
cl_start();
cl_writeOnBus(BUS_READ);
config = cl_readFromBus(1);
config = config << 8;
config += cl_readFromBus(0);
cl_stop();
config &= bitmask;
_NOP();
_NOP();
return config;
}
/*--------------------------------------------------------------------------*/
/* Only first 8 bit of Configuration Status Register can be set */
static void
setCSReg(uint8_t setting)
{
do cl_start();
while(!cl_writeOnBus(BUS_WRITE));
cl_writeOnBus(ACC_CSR);
cl_writeOnBus(setting);
cl_stop();
_NOP();
_NOP();
_NOP();
_NOP();
}
/*--------------------------------------------------------------------------*/
static void
System_startConversion(void)
{
do cl_start(); /* do start until BUS_WRITE is acked */
while(!cl_writeOnBus(BUS_WRITE)); /* control byte */
cl_writeOnBus(0xEE); /* start conversion */
cl_stop();
}
/*--------------------------------------------------------------------------*/
/* RTC initialization. Initializes RTC with ::CSR_DEFAULT. */
static void
initClock(void)
{
uint8_t csr = getReg16bit(ACC_CSR,0xFF00) >> 8;
if(csr!=CSR_DEFAULT) setCSReg(CSR_DEFAULT); /* if desired config isnt in clock => set it */
/* IMPORTANT: Ensure quartz is generating 32768 Hz */
/* (sometimes CH bit gets set when clock is read while reset) */
do cl_start(); /* Do start until BUS_WRITE is acked. */
while(!cl_writeOnBus(BUS_WRITE)); /* Send control byte */
cl_writeOnBus(ACC_CLOCK); /* Send command byte ::ACC_CLOCK. */
cl_writeOnBus(0x00); /* Send starting address 0x00. */
cl_writeOnBus(0x00); /* Set CH to 0, tseconds and seconds will also be reset! */
cl_stop(); /* Stop condition. */
}
/*--------------------------------------------------------------------------*/
void
ds1629_init()
{
initClock();
}
/*--------------------------------------------------------------------------*/
void
ds1629_start()
{
System_startConversion();
}
/*--------------------------------------------------------------------------*/
signed int
ds1629_temperature()
{
temp_t temperature;
ds1629_start();
temperature.u = getReg16bit(ACC_RT,0xFFFF);
return temperature.s;
}

View file

@ -1,71 +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 Configurable Sensor Network Application
* Architecture for sensor nodes running the Contiki operating system.
*
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-08
* Updated : $Date: 2006/06/18 07:49:33 $
* $Revision: 1.1 $
*/
#ifndef __DS1629_H__
#define __DS1629_H__
/**
* DS1629 initialization function.
*
* This function should be called at startup to initialize the DS1629
* and its clock.
*/
void ds1629_init(void);
/**
* DS1629 start conversion function.
*
* This function should be called before requesting the temperature
* the first time.
*/
void ds1629_start(void);
/**
* Get the temperature.
*
* This function will return the current temperature as a signed 9 bit
* value in terms of a 0.5 degree Celsius least significant bit.
*
* MSB Sign 2^6 2^5 2^4 2^3 2^2 2^1 2^0
* LSB 2^-1 0 0 0 0 0 0 0
*/
signed int ds1629_temperature(void);
#endif /* __DS1629_H__ */

View file

@ -1,323 +0,0 @@
/**
* \file
* EEPROM functions.
* \author Adam Dunkels <adam@sics.se>
*/
/* Copyright (c) 2004 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. 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.
*
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/*
Copyright 2003/2004, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universit\x{FFFF}t Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of Freie Universitaet Berlin (FUB) 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 FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB 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 implementation was developed by the CST group at the FUB.
Contributors: Thomas Pietsch, Bjoern Lichtblau
For documentation and questions please use the web site
http://www.scatterweb.net and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2003/2004
*/
#include "contiki.h"
/* #include <msp430x14x.h> */
#include "dev/eeprom.h"
/* Temporary switch for the eeprom address. */
#define EEPROMADDRESS (0x00) /* use 8k EEPROM, future versions will have only one 64k eeprom at this address */
/*#define EEPROMADDRESS (0x02)*/ /* use 64k EEPROM */
/* must be set together with EEPROMADDRESS */
/*#define EEPROMPAGEMASK (0x1F) */ /* 8k EEPROM, 32b page writes possible */
#define EEPROMPAGEMASK (0x7F) /* 64k EEPROM, 128b page writes possible */
/*
* Macros for accessing the clock and data lines. Data is on P56 and
* clock on P57.
*/
#define SDA_HIGH (P5OUT |= 0x04) /**< EEPROM data line high */
#define SDA_LOW (P5OUT &= 0xFB) /**< EEPROM data line low */
#define SCL_HIGH (P5OUT |= 0x08) /**< EEPROM clock line high */
#define SCL_LOW (P5OUT &= 0xF7) /**< EEPROM clock line low */
/*-----------------------------------------------------------------------------------*/
/**
* \internal \name Basic functions for interfacing the i2c-like EEPROM bus.
*/
/** @{ */
/**
* \internal
* Put start condition on the bus.
*/
static void
start(void)
{
P5DIR |= 0x0C; /* ensure: P52(SDA), P53(SCL) output */
SCL_LOW; _NOP(); _NOP();
SDA_HIGH; _NOP(); _NOP();
SCL_HIGH; _NOP(); _NOP();
SDA_LOW; _NOP(); _NOP();
SCL_LOW; _NOP(); _NOP();
}
/*-----------------------------------------------------------------------------------*/
/**
* \internal
* Put stop condition on the bus.
*/
static void
stop(void)
{
//P5DIR |= 0x0C; /* ensure: P52(SDA), P53(SCL) output */
SCL_LOW; _NOP(); _NOP();
SDA_LOW; _NOP(); _NOP();
SCL_HIGH; _NOP(); _NOP();
SDA_HIGH; _NOP(); _NOP();
SCL_LOW; _NOP(); _NOP();
P5DIR &= ~0x0C;
}
/*-----------------------------------------------------------------------------------*/
/**
* \internal
* Write a byte on the bus, return the acknowledge bit.
*/
static int
write_bus(unsigned char byte)
{
int i, ack;
/* Write byte, one bit at a time. Start with the leftmost (most
significant) bit and roll in bits from the right. */
for(i = 0; i < 8; ++i) {
if(byte & 0x80) {
SDA_HIGH;
} else {
SDA_LOW;
}
_NOP();
_NOP();
SCL_HIGH;
_NOP();
_NOP();
byte = byte << 1;
SCL_LOW;
_NOP();
_NOP();
}
/* check ack */
P5DIR &= 0xFB; /* P52(SDA) input */
SCL_HIGH;
_NOP();
_NOP();
if(P5IN & 0x04) {
ack = 0;
} else {
ack = 1; /* test if ack=0, else error */
}
SCL_LOW;
_NOP();
_NOP();
P5DIR |= 0x04; /* P52(SDA) output */
_NOP();
_NOP();
_NOP();
return ack;
}
/*-----------------------------------------------------------------------------------*/
/**
* \internal
* Read one byte from the bus.
*
* \param ack If set, the ackbit after the received byte will be set.
*/
static unsigned char
read_bus(unsigned char ack)
{
int i;
unsigned char byte = 0;
P5DIR &= 0xFB; /* P52(SDA) input */
for(i = 0; i < 8; ++i) {
byte = byte << 1;
SCL_HIGH;
_NOP();
_NOP();
if(P5IN & 0x04) {
byte |= 0x01;
} else {
byte &= 0xFE;
}
_NOP();
SCL_LOW;
_NOP();
_NOP();
}
P5DIR |= 0x04; /* P52(SDA) output */
if(ack) {
SDA_LOW;
} else {
SDA_HIGH;
}
_NOP();
SCL_HIGH;
_NOP();
SCL_LOW;
_NOP();
return byte;
}
/** @} */
/*-----------------------------------------------------------------------------------*/
/**
* Read bytes from the EEPROM using sequential read.
*/
void
eeprom_read(unsigned short addr, unsigned char *buf, int size)
{
unsigned int i;
if(size <= 0) {
return;
}
do {
/* Wait if the writecycle has not finished. */
start();
/* 1010 control, 000 address, 0=write --- but only inits address */
} while(!write_bus(0xa0 | EEPROMADDRESS));
/* Write address to bus, low byte first. */
write_bus(addr >> 8);
write_bus(addr & 0xff);
start();
/* 1010 control, 000 address, 1=read */
write_bus(0xa1 | EEPROMADDRESS);
for(i = 0; i < (size - 1); ++i){
buf[i] = read_bus(1);
}
buf[size - 1] = read_bus(0);
stop();
}
/*-----------------------------------------------------------------------------------*/
/**
* Write bytes to EEPROM using sequencial write.
*/
void
eeprom_write(unsigned short addr, unsigned char *buf,
int size)
{
unsigned int i = 0;
unsigned int curaddr;
if(size <= 0) {
return;
}
/* Disable write protection. */
P5OUT &= 0xEF;
curaddr = addr;
for(i = 0; i < size; ++i) {
/* If we are writing the first byte or are on a 128b page boundary
we have to start a new write. */
if(i == 0 || (curaddr & EEPROMPAGEMASK) == 0) {
do {
start();
/* 1010 control, 000 addresse, 0=write */
} while(!write_bus(0xa0 | EEPROMADDRESS));
/* Write the new address to the bus. */
if(write_bus(curaddr >> 8) == 0) {
return;
}
if(write_bus(curaddr) == 0) {
return;
}
}
/* Write byte. */
if(write_bus(buf[i]) == 0) {
return;
}
/* If we are writing the last byte totally or of a 128b page
generate a stop condition */
if(i == size - 1 || (curaddr & EEPROMPAGEMASK) == EEPROMPAGEMASK) {
stop();
}
++curaddr;
}
/* Enable write protection. */
P5OUT |= 0x10;
}
/*-----------------------------------------------------------------------------------*/

View file

@ -1,72 +0,0 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Functions for turning the ESB sensors on or off
* \author
* Adam Dunkels <adam@sics.se>
*
* This file will eventually be changed into a better API. This is
* sufficient for now.
*/
#include "dev/hwconf.h"
#include "dev/irq.h"
#include "sys/energest.h"
HWCONF_PIN(SENSORSWITCH, 5, 5);
/*---------------------------------------------------------------------------*/
void
esb_sensors_init(void)
{
SENSORSWITCH_SELECT();
SENSORSWITCH_MAKE_OUTPUT();
irq_init();
}
/*---------------------------------------------------------------------------*/
void
esb_sensors_on(void)
{
SENSORSWITCH_CLEAR();
ENERGEST_ON(ENERGEST_TYPE_SENSORS);
}
/*---------------------------------------------------------------------------*/
void
esb_sensors_off(void)
{
SENSORSWITCH_SET();
ENERGEST_OFF(ENERGEST_TYPE_SENSORS);
}
/*---------------------------------------------------------------------------*/

View file

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

View file

@ -1,315 +0,0 @@
/* The software in this file is based on code from FU Berlin. */
/*
Copyright 2003/2004, Freie Universitaet Berlin. All rights reserved.
These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of Freie Universitaet Berlin (FUB) 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 FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB 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 implementation was developed by the CST group at the FUB.
Contributors: Thomas Pietsch, Bjoern Lichtblau
*/
/* \file recir.c
** \ingroup Firmware
** \brief Receiving RC5 via IR Receiving Diode.
**
** \code
** RC5: 1780 us bitlength (manchester encoded, so half bitlength of 890 us is important)
** Transferred packet (2 start + toggle bit + 5 address bits + 6 comand bits)):
** | S | S | T | A4 | A3 | A2 | A1 | A0 | C5 | C4 | C3 | C2 | C1 | C0 |
** irdata format: | ? | ? | error | newData | T | A4 | A3 | A2 | A1 | A0 | C5 | C4 | C3 | C2 | C1 | C0 |
** \endcode
**
** <img src="../pics/rc5.jpg">
** See detailed description at <a href="http://users.pandora.be/davshomepage/rc5.htm">http://users.pandora.be/davshomepage/rc5.htm</a>
**
** Some common addresses and commands:
** \code
** Address: Device: Command:
** 0 TV1 0...9 Numbers 0...9 (channel select)
** 1 TV2 12 Standby
** 5 VCR1 16 Master Volume +
** 6 VCR2 17 Master Volume -
** 17 Tuner 18 Brightness +
** 18 Audio Tape 19 Brightness -
** 20 CD Player 50 Fast rewind
** 52 Fast run forward
** 53 Play
** 54 Stop
** 55 Recording
** \endcode
**/
#include "contiki.h"
#include "dev/ir.h"
#include "dev/leds.h"
#include "dev/beep.h"
#include "isr_compat.h"
PROCESS(ir_process, "IR receiver");
process_event_t ir_event_received;
/*---------------------------------------------------------------------------*/
#define SIR1 (P1OUT |= 0x01) ///< MACRO: Puts IR sending diode high.
#define SIR0 (P1OUT &= 0xFE) ///< MACRO: Puts IR sending diode low.
#define BIT75 3282 ///< 3 quarters of a bit after start, 3282 cyc @ 2,4576Mhz = 1335us.
#define BIT50 2188 ///< Half of bit length, 2188 cyc @ 2,4576Mhz = 890 us.
/*---------------------------------------------------------------------------*/
/* Sends a logical one via IR, method is timed for the 2.4576Mhz SMCLK!!!
*/
static volatile void
send1bit(void)
{
volatile int i;
for(i = 0; i < 34; ++i) {
SIR1; SIR1; SIR1; SIR1;
SIR0; SIR0; SIR0; SIR0;
SIR0; SIR0; SIR0; SIR0;
SIR0;
}
}
/*---------------------------------------------------------------------------*/
/* Sends a logical 0 via IR, method is timed for the 2.4576Mhz SMCLK!!!
*/
static volatile void
send0bit(void)
{
volatile int i;
for(i = 0; i < 34; ++i) {
SIR0; SIR0; SIR0; SIR0;
SIR0; SIR0; SIR0; SIR0;
SIR0; SIR0; SIR0; SIR0;
SIR0;
}
}
/*---------------------------------------------------------------------------*/
/* Sends the lower 12 bits of data via IR, turns interrupt off while
it's sending.
*/
void
ir_send(unsigned short data)
{
volatile unsigned short mask = 0x2000;
data |= 0xF000;
dint();
while(mask != 0){
if(!(mask & data)){
send1bit();
send0bit();
} else {
send0bit();
send1bit();
}
mask /= 2;
}
eint();
}
/*---------------------------------------------------------------------------*/
/* Testroutine which repetedly sends two commands.
*/
/*void
ir_test_send(void)
{
volatile unsigned int i;
send12bits(0xF010);
for(i=0; i<0xFFFF; i++) nop();
send12bits(0xF011);
for(i=0; i<0xFFFF; i++) nop();
}*/
/*---------------------------------------------------------------------------*/
static void setErrorBit(void);
static void clearErrorBit(void);
static void setDataAvailableBit(void);
static void clearDataAvailableBit(void);
/// \name Internal variables.
//@{
static unsigned int ir_pos; ///< current position in frame
static unsigned int recvdata; ///< here a received packet is saved
static unsigned int recvdatabuffer; ///< temporary buffer for receiving
static unsigned char ir_temp; ///< saves the first half of the manchester bit
//@}
/// \name Public functions.
/// If ::recir_dataAvailable()==1 use the get* functions.
//@{
unsigned char recir_getCode(void){ return (recvdata & 0x003F); }
unsigned char recir_getAddress(void){ return ((recvdata & 0x07C0) >> 6); }
unsigned char recir_getToggle(void){ return ((recvdata & 0x0800) >> 11); }
unsigned char recir_getError(void){ return ((recvdata & 0x2000) >> 13); }
uint16_t
ir_data(void)
{
return recvdata;
}
uint8_t
ir_poll(void)
{
if(recvdata & 0x1000) {
clearDataAvailableBit();
return 1;
} else {
return 0;
}
}
///\name Internal functions.
//@{
static void setErrorBit(void){ recvdata |= 0x2000; }
static void clearErrorBit(void) { recvdata &= 0xDFFF; }
static void setDataAvailableBit(void){ recvdata |= 0x1000; }
static void clearDataAvailableBit(void){ recvdata &= 0xEFFF; }
/// Timer B0 interrupt service routine
ISR(TIMERB1, Timer_B1) {
/*P2OUT = (P2OUT & 0xf7) | (8 - (P2OUT & 0x08));*/
if(ir_pos <= 25) {
if(ir_pos % 2) { // odd position
if(ir_temp && !(P1IN & 0x04)) { // 1 - 0 --> write 1
recvdatabuffer +=1;
recvdatabuffer = recvdatabuffer << 1;
} else if(!ir_temp && (P1IN & 0x04)) { // 0 - 1 --> write 0
recvdatabuffer = recvdatabuffer << 1;
} else {
setErrorBit();
if(P1IN & 0x04) {
recvdatabuffer += 1;
}
recvdatabuffer = recvdatabuffer << 1;
}
} else { // even position
ir_temp = P1IN & 0x04;
}
}
if(ir_pos == 25) { // end reached
recvdatabuffer = recvdatabuffer >> 1;
if(!recir_getError() && ( (recvdatabuffer & 0x0FFF) != (recvdata & 0x0FFF) ) ){
recvdata = recvdatabuffer;
setDataAvailableBit();
} else {
_NOP();
}
}
if(ir_pos==27) {
TBCCTL1 &= ~CCIE;
//GREENOFF;
// temporary debug output
//sendRS232Address(recvdatabuffer);
//if(recir_getError()) sendRS232('E');
//sendRS232String("\r\n");
if(!recir_getError()) beep_beep(20);
// reenable interrupt for falling edge
P1IFG &= ~(0x04);
P1IE |= 0x04; // enable interrupt for recir RC5
leds_off(LEDS_RED);
}
ir_pos++;
TBCCR1 += BIT50; // set new interrupt
TBCCTL1 &= ~CCIFG;
}
/** \brief IR Interrupt routine
**
** For the falling edge (start of RC5 packet)( mid of first start bit ), IRReceiver is on P12
** real interrupt routine, which calls this, is in sensors.c */
void
ir_irq(void)
{
if(P1IN & 0x04) return; // high again, just a peak
ir_pos = 0;
recvdatabuffer = 0;
clearErrorBit();
// the first timer interrupt will occur in the mid of the first half of the second start bit
TBCCR1 = TBR + BIT75; // set first TBCCR1 IRQ to 75% of RC5 bitlength
TBCCTL1 &= ~CCIFG; // clear previous compare flag
TBCCTL1 |= CCIE; // CCR0 interrupt enabled, interrupt occurs when timer equals CCR0
P1IE &= ~0x04; // disable interrupt for P12 ( ReceiveIR )
leds_on(LEDS_RED);
//GREENON;
}
//@}
/*---------------------------------------------------------------------*/
PROCESS_THREAD(ir_process, ev, data)
{
PROCESS_BEGIN();
// init TIMERB ccr0 to run continouslycreate the 5 ms interval
// ccr1 is used for ir receiving (RC5)
TBCTL = TBSSEL1 + TBCLR; // select SMCLK (2.4576MHz), clear TBR
TBCTL |= MC1; // Start Timer_A in continuous mode
P1IES |= 0x04; // Important for IR-RC5 receive to detect the first FALLING edge
ir_event_received = process_alloc_event();
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_POLL);
if(ir_poll() == IR_DATA) {
unsigned short irdata;
irdata = ir_data() & 0x7ff;
process_post(PROCESS_BROADCAST, ir_event_received, (process_data_t)irdata);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------*/

View file

@ -1,70 +0,0 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#ifndef __IR_H__
#define __IR_H__
#include "contiki.h"
#include "contiki-net.h"
/**
* Initialize the IR driver.
*
* This function should be called from the main boot-up procedure in
* order to initialize the IR device driver.
*
*/
void ir_init(void);
void ir_send(unsigned short low12bits);
uint8_t ir_poll(void);
#define IR_NODATA 0
#define IR_DATA 1
uint16_t ir_data(void);
void ir_irq(void);
#define IR_STANDBY 0x0c
#define IR_VOLUME_UP 0x10
#define IR_VOLUME_DOWN 0x11
#define IR_VCR_PLAY 0x35
#define IR_VCR_STOP 0x36
#define IR_VCR_RECORD 0x37
#define IR_VCR_REWIND 0x32
#define IR_VCR_WIND 0x34
extern process_event_t ir_event_received;
PROCESS_NAME(ir_process);
#endif /* __IR_H__ */

View file

@ -1,216 +0,0 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#include "contiki.h"
#include "lib/sensors.h"
#include "dev/irq.h"
#include "dev/lpm.h"
#include "isr_compat.h"
#define ADC12MCTL_NO(adcno) ((unsigned char *) ADC12MCTL0_)[adcno]
static int (* adc12_irq[8])(void);
static int (* port1_irq[8])(void);
static unsigned char adcflags;
/*---------------------------------------------------------------------------*/
ISR(PORT1, irq_p1)
{
int i;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
for(i = 0; i < 8; i++) {
if((P1IFG & (1 << i)) && port1_irq[i] != NULL) {
if((port1_irq[i])()) {
LPM4_EXIT;
}
}
}
P1IFG = 0x00;
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
ISR(ADC, irq_adc)
{
int i;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
for(i = 0; i < 8; i++) {
if(adc12_irq[i] != NULL) {
if((adc12_irq[i])()) {
LPM4_EXIT;
}
}
}
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
void
irq_init(void)
{
int i;
adcflags = 0;
for(i = 0; i < 8; i++) {
adc12_irq[i] = NULL;
port1_irq[i] = NULL;
}
/* Setup ADC12, ref., sampling time */
ADC12CTL0 = REF2_5V | SHT0_10 | SHT1_10 | MSC;
/* Use sampling timer, repeat-sequence-of-channels */
/* ADC12CTL1 = SHP | CONSEQ_3 | ADC12DIV_3; */
ADC12CTL1 = SHP | CONSEQ_3 | ADC12DIV_7;
}
/*---------------------------------------------------------------------------*/
void
irq_port1_activate(unsigned char irqno, int (* irq)(void))
{
if(irqno < 8) {
port1_irq[irqno] = irq;
}
}
/*---------------------------------------------------------------------------*/
void
irq_port1_deactivate(unsigned char irqno)
{
if(irqno < 8) {
port1_irq[irqno] = NULL;
}
}
/*---------------------------------------------------------------------------*/
/* Set lowest ADC to be start in sequence and highest to be interrupt
enabled and set end-of-sequence on the highest active ADC */
static void
sethilo(void)
{
int c;
/* Clear start of sequence */
ADC12CTL1 &= ~(CSTARTADD_15);
/* Set new start of sequence to lowest active memory holder */
for(c = 0; c < 8; c++) {
if(adcflags & (1 << c)) {
ADC12CTL1 |= (c * CSTARTADD_1);
break;
}
}
/* Clear all interrupts and end-of-sequences */
ADC12IE = 0;
for(c = 0; c < 8; c++) {
ADC12MCTL_NO(c) &= ~EOS;
}
/* Set highest interrupt and end-of-sequence. This will generate one
interrupt for each sequence of conversions. */
for(c = 0; c < 8; c++) {
if(adcflags & (128 >> c)) {
ADC12IE |= 128 >> c;
ADC12MCTL_NO(7 - c) |= EOS;
break;
}
}
}
/*---------------------------------------------------------------------------*/
void
irq_adc12_activate(unsigned char adcno, unsigned char config,
int (* irq)(void))
{
if(adcno >= 8) {
return;
}
/* stop converting */
ADC12CTL0 &= ~ENC;
/* wait for conversion to stop */
while(ADC12CTL0 & ADC12BUSY);
ADC12CTL0 &= ~(ADC12ON | REFON);
ADC12IE = 0;
/* clear any pending interrupts */
ADC12IFG = 0;
adcflags |= (1 << adcno);
ADC12MCTL_NO(adcno) = config;
sethilo();
ADC12CTL0 |= ADC12ON | REFON;
adc12_irq[adcno] = irq;
/* Delay */
clock_delay(20000);
ADC12CTL0 |= ENC | ADC12SC;
}
/*---------------------------------------------------------------------------*/
void
irq_adc12_deactivate(unsigned char adcno)
{
if(adcno >= 8) {
return;
}
/* stop converting */
ADC12CTL0 &= ~ENC;
/* wait for conversion to stop */
while(ADC12CTL0 & ADC12BUSY);
ADC12CTL0 &= ~(ADC12ON | REFON);
ADC12IE = 0;
/* clear any pending interrupts */
ADC12IFG = 0;
adcflags &= ~(1 << adcno);
ADC12MCTL_NO(adcno) = 0;
sethilo();
adc12_irq[adcno] = NULL;
if(adcflags) {
/* Turn on the ADC12 */
ADC12CTL0 |= (ADC12ON | REFON);
/* Delay */
clock_delay(20000);
/* Still active. Turn on the conversion. */
ADC12CTL0 |= ENC | ADC12SC;
}
}
/*---------------------------------------------------------------------------*/
int
irq_adc12_active(unsigned char adcno)
{
return adcflags & (1 << adcno) ? 1 : 0;
}
/*---------------------------------------------------------------------------*/

View file

@ -1,46 +0,0 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#ifndef __IRQ_H__
#define __IRQ_H__
void irq_init(void);
void irq_port1_activate(unsigned char irqno, int (* irq)(void));
void irq_port1_deactivate(unsigned char irqno);
void irq_adc12_activate(unsigned char adcno, unsigned char config,
int (* irq)(void));
void irq_adc12_deactivate(unsigned char adcno);
int irq_adc12_active(unsigned char adcno);
#endif /* __IRQ_H__ */

View file

@ -1,96 +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 "dev/pir-sensor.h"
#include "dev/irq.h"
#include "dev/hwconf.h"
const struct sensors_sensor pir_sensor;
static unsigned int pir;
#define PIR_IRQ() 3
HWCONF_PIN(PIR, 1, PIR_IRQ());
HWCONF_IRQ(PIR, 1, PIR_IRQ());
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
++pir;
sensors_changed(&pir_sensor);
return 1;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
return pir;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
pir = 0;
PIR_SELECT();
PIR_MAKE_INPUT();
return 1;
case SENSORS_ACTIVE:
if(value) {
if(!PIR_IRQ_ENABLED()) {
irq_port1_activate(PIR_IRQ(), irq);
PIR_ENABLE_IRQ();
}
} else {
PIR_DISABLE_IRQ();
irq_port1_deactivate(PIR_IRQ());
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return PIR_IRQ_ENABLED();
}
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(pir_sensor, PIR_SENSOR,
value, configure, status);

View file

@ -1,41 +0,0 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#ifndef __PIR_SENSOR_H__
#define __PIR_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor pir_sensor;
#define PIR_SENSOR "PIR"
#endif /* __PIR_SENSOR_H__ */

View file

@ -1,96 +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 "dev/radio-sensor.h"
#include "dev/irq.h"
#include "dev/tr1001.h"
const struct sensors_sensor radio_sensor;
unsigned int radio_sensor_signal;
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
radio_sensor_signal = ADC12MEM5;
return 0;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
switch(type) {
case RADIO_SENSOR_LAST_PACKET:
return tr1001_sstrength();
case RADIO_SENSOR_LAST_VALUE:
default:
return radio_sensor_signal;
}
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
/* Initialization of ADC12 done by irq */
radio_sensor_signal = 0;
return 1;
case SENSORS_ACTIVE:
if(value) {
if(!irq_adc12_active(5)) {
irq_adc12_activate(5, (INCH_5 + SREF_0), irq);
}
} else {
irq_adc12_deactivate(5);
radio_sensor_signal = 0;
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return irq_adc12_active(5);
}
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR,
value, configure, status);

View file

@ -1,40 +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.
*
*/
#include "dev/rs232.h"
int
putchar(int c)
{
rs232_send(c);
return c;
}

View file

@ -1,153 +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.
*
*/
/** \addtogroup esbrs232
* @{ */
/**
* \file
* RS232 communication device driver for the MSP430.
* \author Adam Dunkels <adam@sics.se>
*
* This file contains an RS232 device driver for the MSP430 microcontroller.
*
*/
#include "contiki.h"
#include <string.h>
#include "contiki-esb.h"
#include "isr_compat.h"
static int (* input_handler)(unsigned char) = NULL;
/*---------------------------------------------------------------------------*/
ISR(UART1RX, rs232_rx_usart1)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
/* Check status register for receive errors. - before reading RXBUF since
it clears the error and interrupt flags */
if(!(URCTL1 & RXERR) && input_handler != NULL) {
if(input_handler(RXBUF1)) {
LPM4_EXIT;
}
} else {
/* Else read out the char to clear the I-flags, etc. */
RXBUF1;
}
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
/**
* Initalize the RS232 port.
*
*/
void
rs232_init(void)
{
/* RS232 */
UCTL1 = CHAR; /* 8-bit character */
UTCTL1 = SSEL1; /* UCLK = MCLK */
rs232_set_speed(RS232_57600);
input_handler = NULL;
ME2 |= (UTXE1 | URXE1); /* Enable USART1 TXD/RXD */
IE2 |= URXIE1; /* Enable USART1 RX interrupt */
}
/*---------------------------------------------------------------------------*/
void
rs232_send(char c)
{
ENERGEST_ON(ENERGEST_TYPE_SERIAL);
/* Loop until the transmission buffer is available. */
while((IFG2 & UTXIFG1) == 0) {
}
/* Transmit the data. */
TXBUF1 = c;
ENERGEST_OFF(ENERGEST_TYPE_SERIAL);
}
/*---------------------------------------------------------------------------*/
void
rs232_set_speed(unsigned char speed)
{
if(speed == RS232_19200) {
/* Set RS232 to 19200 */
UBR01 = 0x80; /* 2,457MHz/19200 = 128 -> 0x80 */
UBR11 = 0x00; /* */
UMCTL1 = 0x00; /* no modulation */
} else if(speed == RS232_38400) {
/* Set RS232 to 38400 */
UBR01 = 0x40; /* 2,457MHz/38400 = 64 -> 0x40 */
UBR11 = 0x00; /* */
UMCTL1 = 0x00; /* no modulation */
} else if(speed == RS232_57600) {
UBR01 = 0x2a; /* 2,457MHz/57600 = 42.7 -> 0x2A */
UBR11 = 0x00; /* */
UMCTL1 = 0x5b; /* */
} else if(speed == RS232_115200) {
UBR01 = 0x15; /* 2,457MHz/115200 = 21.4 -> 0x15 */
UBR11 = 0x00; /* */
UMCTL1 = 0x4a; /* */
} else {
rs232_set_speed(RS232_57600);
}
}
/*---------------------------------------------------------------------------*/
void
rs232_print(char *cptr)
{
while(*cptr != 0) {
rs232_send(*cptr);
++cptr;
}
}
/*---------------------------------------------------------------------------*/
void
rs232_set_input(int (*f)(unsigned char))
{
input_handler = f;
}
/*---------------------------------------------------------------------------*/
void
slip_arch_writeb(unsigned char c)
{
rs232_send(c);
}
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -1,118 +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.
*
*/
/** \addtogroup esb
* @{ */
/**
* \defgroup esbrs232 ESB RS232
*
* @{
*/
/**
* \file
* Header file for MSP430 RS232 driver.
* \author Adam Dunkels <adam@sics.se>
*
*/
#ifndef __RS232_H__
#define __RS232_H__
#define RS232_19200 1
#define RS232_38400 2
#define RS232_57600 3
#define RS232_115200 4
/**
* \brief Initialize the RS232 module
*
* This function is called from the boot up code to
* initalize the RS232 module.
*/
void rs232_init(void);
/**
* \brief Set an input handler for incoming RS232 data
* \param f A pointer to a byte input handler
*
* This function sets the input handler for incoming RS232
* data. The input handler function is called for every
* incoming data byte. The function is called from the
* RS232 interrupt handler, so care must be taken when
* implementing the input handler to avoid race
* conditions.
*
* The return value of the input handler affects the sleep
* mode of the CPU: if the input handler returns non-zero
* (true), the CPU is awakened to let other processing
* take place. If the input handler returns zero, the CPU
* is kept sleeping.
*/
void rs232_set_input(int (* f)(unsigned char));
/**
* \brief Configure the speed of the RS232 hardware
* \param speed The speed
*
* This function configures the speed of the RS232
* hardware. The allowed parameters are RS232_19200,
* RS232_38400, RS232_57600, and RS232_115200.
*/
void rs232_set_speed(unsigned char speed);
/**
* \brief Print a text string on RS232
* \param str A pointer to the string that is to be printed
*
* This function prints a string to RS232. The string must
* be terminated by a null byte. The RS232 module must be
* correctly initalized and configured for this function
* to work.
*/
void rs232_print(char *str);
/**
* \brief Print a character on RS232
* \param c The character to be printed
*
* This function prints a character to RS232. The RS232
* module must be correctly initalized and configured for
* this function to work.
*/
void rs232_send(char c);
#endif /* __RS232_H__ */
/** @} */
/** @} */

View file

@ -1,167 +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 "dev/sound-sensor.h"
#include "dev/irq.h"
#include <stdlib.h>
#define MIC_MIN_SENS 150
#define SAMPLE 1
const struct sensors_sensor sound_sensor;
static unsigned int sound, micdiff, micmax, avgmax;
static int8_t mode;
static int8_t sample_div;
static int8_t ctr;
static int16_t *sample_buffer;
static int buffer_size;
static int buf_pos;
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
micdiff = micdiff + abs(ADC12MEM4 - sound) - (micdiff >> 3);
sound = ADC12MEM4;
if(mode == SAMPLE) {
ctr++;
if(ctr >= sample_div) {
ctr = 0;
sample_buffer[buf_pos++] = sound;
if(buf_pos >= buffer_size) {
mode = 0;
sensors_changed(&sound_sensor);
return 1;
}
}
}
/* if(micdiff > MIC_MIN_SENS) { */
/* sensors_changed(&sound_sensor); */
/* } */
/* if(micdiff > (avgmax >> 2)) { */
/* if(micdiff % 10 == 0) beep_beep(10); */
/* // Subtract a little... */
/* micdiff = micdiff - (micdiff >> 4); */
/* } */
/* if(micmax < micdiff) { */
/* micmax = micdiff; */
/* } */
/* if(micdiff > 2000) { */
/* leds_on(LEDS_GREEN); */
/* } */
/* if(micdiff > 3000) { */
/* leds_on(LEDS_YELLOW); */
/* } */
/* if(micdiff > 4000) { */
/* leds_on(LEDS_RED); */
/* } */
return 0;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
/* try returning the max to see what values we get... */
/* int mictmp = micmax; */
/* avgmax = avgmax + micmax - (avgmax >> 3); */
/* micmax = micdiff; */
/* return mictmp; */
return micdiff;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
/* Initialization of ADC12 done by irq */
mode = 0;
buffer_size = 0;
return 1;
case SENSORS_ACTIVE:
if(value) {
if(!irq_adc12_active(4)) {
sound = micdiff = micmax = 0;
mode = 0;
ctr = 0;
sample_div = 0;
buf_pos = 0;
avgmax = 5000;
irq_adc12_activate(4, (INCH_0 + SREF_0), irq);
}
} else {
irq_adc12_deactivate(4);
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
return irq_adc12_active(4);
case SENSORS_READY:
return (mode != SAMPLE) && irq_adc12_active(4);
}
return 0;
}
/*---------------------------------------------------------------------------*/
void
sound_sensor_start_sample(void)
{
if(buffer_size > 0) {
buf_pos = 0;
ctr = 0;
mode = SAMPLE;
}
}
/*---------------------------------------------------------------------------*/
void
sound_sensor_set_buffer(int16_t *buffer, int buf_size, int divider)
{
sample_buffer = buffer;
buffer_size = buf_size;
sample_div = divider;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(sound_sensor, SOUND_SENSOR,
value, configure, status);

View file

@ -1,44 +0,0 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#ifndef __SOUND_SENSOR_H__
#define __SOUND_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor sound_sensor;
#define SOUND_SENSOR "Sound"
void sound_sensor_start_sample();
void sound_sensor_set_buffer(int16_t *buffer, int buf_size, int divider);
#endif /* __SOUND_SENSOR_H__ */

View file

@ -1,90 +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.
*
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01
* Updated : $Date: 2010/02/08 00:00:45 $
* $Revision: 1.3 $
*/
#include "dev/temperature-sensor.h"
#include "dev/ds1629.h"
const struct sensors_sensor temperature_sensor;
static int active;
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
unsigned int temp;
signed int t;
t = ds1629_temperature();
temp = ((t / 128) * 50);
return temp;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
active = 0;
ds1629_init();
return 1;
case SENSORS_ACTIVE:
if(value) {
if(!active) {
active = 1;
ds1629_start();
}
} else {
active = 0;
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return active;
}
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR,
value, configure, status);

View file

@ -1,47 +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.
*
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01
* Updated : $Date: 2006/06/18 07:49:33 $
* $Revision: 1.1 $
*/
#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__ */

View file

@ -1,787 +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.
*
*/
/**
* \addtogroup esb
* @{
*/
/**
* \defgroup tr1001 TR1001 radio tranciever device driver
* @{
*/
/**
* \file
* Device driver and packet framing for the RFM-TR1001 radio module.
* \author Adam Dunkels <adam@sics.se>
*
* This file implements a device driver for the RFM-TR1001 radio
* tranciever.
*
*/
#include "contiki.h"
#include "contiki-esb.h"
#include "dev/tr1001.h"
#include "dev/radio-sensor.h"
#include "lib/gcr.h"
#include "lib/crc16.h"
#include "net/netstack.h"
#include "net/rime/rimestats.h"
#include "isr_compat.h"
#include <string.h>
#ifdef TR1001_CONF_BEEP_ON_BAD_CRC
#define BEEP_ON_BAD_CRC TR1001_CONF_BEEP_ON_BAD_CRC
#else
#define BEEP_ON_BAD_CRC 1
#endif /* TR1001_CONF_BEEP_ON_BAD_CRC */
#if BEEP_ON_BAD_CRC
#include "dev/beep.h"
#define BEEP_BEEP(t) beep_beep(t)
#else
#define BEEP_BEEP(t)
#endif /* BEEP_ON_BAD_CRC */
#define RXSTATE_READY 0
#define RXSTATE_RECEIVING 1
#define RXSTATE_FULL 2
#define SYNCH1 0x3c
#define SYNCH2 0x03
#ifdef TR1001_CONF_BUFFER_SIZE
#define RXBUFSIZE TR1001_CONF_BUFFER_SIZE
#else
#define RXBUFSIZE PACKETBUF_SIZE
#endif /* TR1001_CONF_BUFFER_SIZE */
/*
* Pending data to send when using prepare/transmit functions.
*/
static const void *pending_data;
/*
* The buffer which holds incoming data.
*/
unsigned char tr1001_rxbuf[RXBUFSIZE];
/*
* The length of the packet that currently is being received.
*/
static unsigned short tr1001_rxlen = 0;
/*
* The reception state.
*/
volatile unsigned char tr1001_rxstate = RXSTATE_READY;
static uint16_t rxcrc, rxcrctmp;
/*
* The structure of the packet header.
*/
struct tr1001_hdr {
uint8_t len[2]; /**< The 16-bit length of the packet in network byte
order. */
};
/*
* The length of the packet header.
*/
#define TR1001_HDRLEN sizeof(struct tr1001_hdr)
#define OFF 0
#define ON 1
static uint8_t onoroff = OFF;
#define NUM_SYNCHBYTES 4
void tr1001_default_rxhandler(unsigned char c);
PT_THREAD(tr1001_default_rxhandler_pt(unsigned char c));
static struct pt rxhandler_pt;
/*
* This timer is used to keep track of when the last byte was received
* over the radio. If the inter-byte time is too large, the packet
* currently being received is discarded and a new packet reception is
* initiated.
*/
static struct timer rxtimer;
static unsigned short tmp_sstrength, sstrength;
static unsigned short tmp_count;
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define LOG(...) printf(__VA_ARGS__)
#else
#define LOG(...)
#endif
#define GCRLOG(...) /* printf(__VA_ARGS__)*/
/*---------------------------------------------------------------------------*/
PROCESS(tr1001_process, "TR1001 driver");
/*---------------------------------------------------------------------------*/
static int prepare_packet(const void *data, unsigned short len);
static int transmit_packet(unsigned short len);
static int receiving_packet(void);
static int pending_packet(void);
static int channel_clear(void);
static int tr1001_on(void);
static int tr1001_off(void);
const struct radio_driver tr1001_driver = {
tr1001_init,
prepare_packet,
transmit_packet,
tr1001_send,
tr1001_read,
channel_clear,
receiving_packet,
pending_packet,
tr1001_on,
tr1001_off
};
/*---------------------------------------------------------------------------*/
/*
* Turn on data transmission in On-Off-Keyed mode.
*/
static void
txook(void)
{
P3SEL = 0xf0;
P5OUT |= 0x40;
P5OUT &= 0x7f;
}
/*---------------------------------------------------------------------------*/
/*
* Turn on data reception for the radio tranceiver.
*/
static void
rxon(void)
{
P3SEL = 0xe0;
P5OUT |= 0xc0;
/* Enable the receiver. */
ME1 |= URXE0;
/* Turn on receive interrupt. */
IE1 |= URXIE0;
}
/*---------------------------------------------------------------------------*/
/*
* Turn off data reception for the radio tranceiver.
*/
static void
rxoff(void)
{
P5OUT &= 0x3f;
/* Disable the receiver. */
ME1 &= ~URXE0;
/* Turn off receive interrupt. */
IE1 &= ~URXIE0;
}
/*---------------------------------------------------------------------------*/
/*
* Clear the recevie buffer and reset the receiver state.
*/
static void
rxclear(void)
{
tr1001_rxstate = RXSTATE_READY;
}
/*---------------------------------------------------------------------------*/
/*
* Turn TR1001 radio transceiver off.
*/
/*---------------------------------------------------------------------------*/
static int
tr1001_off(void)
{
if(onoroff == OFF) {
return 1;
}
onoroff = OFF;
rxoff();
rxclear();
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
return 1;
}
/*---------------------------------------------------------------------------*/
/*
* Turn TR1001 radio transceiver on.
*/
/*---------------------------------------------------------------------------*/
static int
tr1001_on(void)
{
if(onoroff == ON) {
return 1;
}
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
onoroff = ON;
rxon();
rxclear();
return 1;
}
/*---------------------------------------------------------------------------*/
/*
* Send a byte of data over the radio.
*
* \param b The byte to be sent.
*/
static void
send(unsigned char b)
{
clock_time_t start;
start = clock_time();
/* Wait until the USART0 TX buffer is ready. */
while((IFG1 & UTXIFG0) == 0) {
/* Wait no more than one second. */
if((clock_time_t)(clock_time() - start) > (clock_time_t)CLOCK_SECOND) {
break;
}
}
/* Send the byte. */
TXBUF0 = b;
}
/*---------------------------------------------------------------------------*/
/*
* Send a byte of data and its logical negation (all bits inverted)
* over the radio.
*
* \param b The byte to be sent.
*/
static void
sendx(unsigned char b)
{
gcr_encode(b);
GCRLOG("(%02x)", b);
while(gcr_get_encoded(&b)) {
send(b);
GCRLOG("%02x ", b);
}
}
static uint16_t
sendx_crc16(unsigned char b, uint16_t crcacc)
{
gcr_encode(b);
GCRLOG("(%02x)", b);
crcacc = crc16_add(b, crcacc);
while(gcr_get_encoded(&b)) {
send(b);
GCRLOG("C%02x ", b);
}
return crcacc;
}
/*---------------------------------------------------------------------------*/
void
tr1001_set_txpower(unsigned char p)
{
int i;
/* Clamp maximum power. */
if(p > 100) {
p = 100;
}
/* First, run the potentiometer down to zero so that we know the
start value of the potentiometer. */
P2OUT &= 0xDF; /* P25 = 0 (down selected) */
P2OUT &= 0xBF; /* P26 = 0 (chipselect on) */
for(i = 0; i < 102; ++i) {
P2OUT &= 0xEF; /* P24 = 0 (inc) */
P2OUT |= 0x10;
}
/* Now, start to increase the value of the potentiometer until it
reaches the desired value.*/
P2OUT |= 0x20; /* P25 = 1 (up selected) */
for(i = 0; i < p; ++i) {
P2OUT &= 0xEF; /* P24 = 0 (inc) */
P2OUT |= 0x10;
}
P2OUT |= 0x40; /* P26 = 1 (chipselect off) */
}
/*---------------------------------------------------------------------------*/
int
tr1001_init(void)
{
PT_INIT(&rxhandler_pt);
onoroff = OFF;
UCTL0 = CHAR; /* 8-bit character */
UTCTL0 = SSEL1; /* UCLK = SMCLK */
tr1001_set_speed(TR1001_19200);
ME1 |= UTXE0 + URXE0; /* Enable USART0 TXD/RXD */
/* Turn on receive interrupt. */
IE1 |= URXIE0;
timer_set(&rxtimer, CLOCK_SECOND / 4);
tr1001_on();
tr1001_set_txpower(100);
/* Reset reception state. */
rxclear();
process_start(&tr1001_process, NULL);
return 1;
}
/*---------------------------------------------------------------------------*/
ISR(UART0RX, tr1001_rxhandler)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
tr1001_default_rxhandler_pt(RXBUF0);
if(tr1001_rxstate == RXSTATE_FULL) {
LPM4_EXIT;
}
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
#if DEBUG
static void
dump_packet(int len)
{
int i;
for(i = 0; i < len; ++i) {
LOG("%d: 0x%02x\n", i, tr1001_rxbuf[i]);
}
}
#endif /* DEBUG */
/*---------------------------------------------------------------------------*/
PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
{
static unsigned char rxtmp, tmppos;
if(timer_expired(&rxtimer) && tr1001_rxstate != RXSTATE_FULL) {
PT_INIT(&rxhandler_pt);
}
timer_restart(&rxtimer);
if(tr1001_rxstate == RXSTATE_RECEIVING) {
unsigned short signal = radio_sensor.value(0);
tmp_sstrength += (signal >> 2);
tmp_count++;
}
PT_BEGIN(&rxhandler_pt);
while(1) {
/* Reset reception state. */
rxclear();
/* Wait until we receive the first syncronization byte. */
PT_WAIT_UNTIL(&rxhandler_pt, incoming_byte == SYNCH1);
tr1001_rxstate = RXSTATE_RECEIVING;
/* Read all incoming syncronization bytes. */
PT_WAIT_WHILE(&rxhandler_pt, incoming_byte == SYNCH1);
/* We should receive the second synch byte by now, otherwise we'll
restart the protothread. */
if(incoming_byte != SYNCH2) {
PT_RESTART(&rxhandler_pt);
}
/* Start signal strength measurement */
tmp_sstrength = 0;
tmp_count = 0;
/* Reset the CRC. */
rxcrc = 0xffff;
gcr_init();
GCRLOG("RECV: ");
/* Read packet header. */
for(tmppos = 0; tmppos < TR1001_HDRLEN; ++tmppos) {
/* Wait for the first byte of the packet to arrive. */
do {
PT_YIELD(&rxhandler_pt);
GCRLOG("(%02x) ", incoming_byte);
gcr_decode(incoming_byte);
/* If the incoming byte isn't a valid GCR encoded byte,
we start again from the beginning. */
if(!gcr_valid()) {
BEEP_BEEP(1000);
LOG("Incorrect GCR in header at byte %d/1 %x\n", tmppos, incoming_byte);
RIMESTATS_ADD(badsynch);
PT_RESTART(&rxhandler_pt);
}
} while(!gcr_get_decoded(&rxtmp));
GCRLOG("%02x ", rxtmp);
tr1001_rxbuf[tmppos] = rxtmp;
/* Calculate the CRC. */
rxcrc = crc16_add(rxtmp, rxcrc);
}
/* Since we've got the header, we can grab the length from it. */
tr1001_rxlen = ((((struct tr1001_hdr *)tr1001_rxbuf)->len[0] << 8) +
((struct tr1001_hdr *)tr1001_rxbuf)->len[1]);
/* If the length is longer than we can handle, we'll start from
the beginning. */
if(tmppos + tr1001_rxlen > sizeof(tr1001_rxbuf)) {
RIMESTATS_ADD(toolong);
PT_RESTART(&rxhandler_pt);
}
/* Read packet data. */
for(; tmppos < tr1001_rxlen + TR1001_HDRLEN; ++tmppos) {
/* Wait for the first byte of the packet to arrive. */
do {
PT_YIELD(&rxhandler_pt);
GCRLOG("(%02x)", incoming_byte);
gcr_decode(incoming_byte);
/* If the incoming byte isn't a valid Manchester encoded byte,
we start again from the beinning. */
if(!gcr_valid()) {
BEEP_BEEP(1000);
LOG("Incorrect GCR 0x%02x at byte %d/1\n", incoming_byte,
tmppos - TR1001_HDRLEN);
RIMESTATS_ADD(badsynch);
PT_RESTART(&rxhandler_pt);
}
} while(!gcr_get_decoded(&rxtmp));
GCRLOG("%02x ", rxtmp);
tr1001_rxbuf[tmppos] = rxtmp;
/* Calculate the CRC. */
rxcrc = crc16_add(rxtmp, rxcrc);
}
/* Read the frame CRC. */
for(tmppos = 0; tmppos < 2; ++tmppos) {
do {
PT_YIELD(&rxhandler_pt);
GCRLOG("(%02x)", incoming_byte);
gcr_decode(incoming_byte);
if(!gcr_valid()) {
BEEP_BEEP(1000);
RIMESTATS_ADD(badsynch);
PT_RESTART(&rxhandler_pt);
}
} while(!gcr_get_decoded(&rxtmp));
GCRLOG("%02x ", rxtmp);
rxcrctmp = (rxcrctmp << 8) | rxtmp;
}
GCRLOG("\n");
if(rxcrctmp == rxcrc) {
/* A full packet has been received and the CRC checks out. We'll
request the driver to take care of the incoming data. */
RIMESTATS_ADD(llrx);
process_poll(&tr1001_process);
/* We'll set the receive state flag to signal that a full frame
is present in the buffer, and we'll wait until the buffer has
been taken care of. */
tr1001_rxstate = RXSTATE_FULL;
PT_WAIT_UNTIL(&rxhandler_pt, tr1001_rxstate != RXSTATE_FULL);
} else {
LOG("Incorrect CRC\n");
BEEP_BEEP(1000);
RIMESTATS_ADD(badcrc);
}
}
PT_END(&rxhandler_pt);
}
/*---------------------------------------------------------------------------*/
static int
prepare_packet(const void *data, unsigned short len)
{
pending_data = data;
return 0;
}
/*---------------------------------------------------------------------------*/
static int
transmit_packet(unsigned short len)
{
int ret = RADIO_TX_ERR;
if(pending_data != NULL) {
ret = tr1001_send(pending_data, len);
pending_data = NULL;
}
return ret;
}
/*---------------------------------------------------------------------------*/
int
tr1001_send(const void *packet, unsigned short len)
{
int i;
uint16_t crc16;
LOG("tr1001_send: sending %d bytes\n", len);
if(onoroff == ON) {
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
}
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
/* Prepare the transmission. */
/* Delay the transmission for a short random duration. */
clock_delay(random_rand() & 0x3ff);
/* Check that we don't currently are receiving a packet, and if so
we wait until the reception has been completed. Reception is done
with interrupts so it is OK for us to wait in a while() loop. */
while(tr1001_rxstate == RXSTATE_RECEIVING &&
!timer_expired(&rxtimer)) {
/* Delay the transmission for a short random duration. */
clock_delay(random_rand() & 0x7ff);
}
/* Turn on OOK mode with transmission. */
txook();
/* According to the datasheet, the transmitter must wait for 12 us
in order to settle. Empirical tests show that is it better to
wait for something like 283 us... */
clock_delay(200);
/* Transmit preamble and synch bytes. */
for(i = 0; i < 20; ++i) {
send(0xaa);
}
/* send(0xaa);
send(0xaa);*/
send(0xff);
for(i = 0; i < NUM_SYNCHBYTES; ++i) {
send(SYNCH1);
}
send(SYNCH2);
crc16 = 0xffff;
gcr_init();
GCRLOG("SEND: ");
/* Send packet header. */
crc16 = sendx_crc16(len >> 8, crc16);
crc16 = sendx_crc16(len & 0xff, crc16);
/* Send packet data. */
for(i = 0; i < len; ++i) {
crc16 = sendx_crc16(((uint8_t *)packet)[i], crc16);
}
/* Send CRC */
sendx(crc16 >> 8);
sendx(crc16 & 0xff);
/* if not encoding has sent all bytes - let it send another GCR specific */
if (!gcr_finished()) {
sendx(0);
}
GCRLOG("\n");
/* Send trailing bytes. */
send(0x33);
send(0xcc);
send(0x33);
send(0xcc);
/* Turn on (or off) reception again. */
if(onoroff == ON) {
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
rxon();
rxclear();
} else {
rxoff();
rxclear();
}
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
RIMESTATS_ADD(lltx);
return RADIO_TX_OK;
}
/*---------------------------------------------------------------------------*/
int
tr1001_read(void *buf, unsigned short bufsize)
{
unsigned short tmplen;
if(tr1001_rxstate == RXSTATE_FULL) {
#if DEBUG
dump_packet(tr1001_rxlen + 2);
#endif /* DEBUG */
tmplen = tr1001_rxlen;
if(tmplen > bufsize) {
LOG("tr1001_read: too large packet: %d/%d bytes\n", tmplen, bufsize);
rxclear();
RIMESTATS_ADD(toolong);
return -1;
}
memcpy(buf, &tr1001_rxbuf[TR1001_HDRLEN], tmplen);
/* header + content + CRC */
sstrength = (tmp_count ? ((tmp_sstrength / tmp_count) << 2) : 0);
rxclear();
LOG("tr1001_read: got %d bytes\n", tmplen);
return tmplen;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
receiving_packet(void)
{
return tr1001_rxstate == RXSTATE_RECEIVING &&
!timer_expired(&rxtimer);
}
/*---------------------------------------------------------------------------*/
static int
pending_packet(void)
{
return tr1001_rxstate == RXSTATE_FULL;
}
/*---------------------------------------------------------------------------*/
static int
channel_clear(void)
{
/* TODO add CCA functionality */
return 0;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tr1001_process, ev, data)
{
int len;
PROCESS_BEGIN();
/* Reset reception state now that the process is ready to receive data. */
rxclear();
while(1) {
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
packetbuf_clear();
len = tr1001_read(packetbuf_dataptr(), PACKETBUF_SIZE);
if(len > 0) {
packetbuf_set_datalen(len);
NETSTACK_RDC.input();
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
tr1001_set_speed(unsigned char speed)
{
if(speed == TR1001_19200) {
/* Set TR1001 to 19200 */
UBR00 = 0x80; /* 2,457MHz/19200 = 128 -> 0x80 */
UBR10 = 0x00; /* */
UMCTL0 = 0x00; /* no modulation */
} else if(speed == TR1001_38400) {
/* Set TR1001 to 38400 */
UBR00 = 0x40; /* 2,457MHz/38400 = 64 -> 0x40 */
UBR10 = 0x00; /* */
UMCTL0 = 0x00; /* no modulation */
} else if(speed == TR1001_57600) {
UBR00 = 0x2a; /* 2,457MHz/57600 = 42.7 -> 0x2A */
UBR10 = 0x00; /* */
UMCTL0 = 0x5b; /* */
} else if(speed == TR1001_115200) {
UBR00 = 0x15; /* 2,457MHz/115200 = 21.4 -> 0x15 */
UBR10 = 0x00; /* */
UMCTL0 = 0x4a; /* */
} else {
tr1001_set_speed(TR1001_19200);
}
}
/*---------------------------------------------------------------------------*/
unsigned short
tr1001_sstrength(void)
{
return sstrength;
}
/*---------------------------------------------------------------------------*/
/** @} */
/** @} */

View file

@ -1,773 +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.
*
*/
/**
* \addtogroup esb
* @{
*/
/**
* \defgroup tr1001 TR1001 radio tranciever device driver
* @{
*/
/**
* \file
* Device driver and packet framing for the RFM-TR1001 radio module.
* \author Adam Dunkels <adam@sics.se>
*
* This file implements a device driver for the RFM-TR1001 radio
* tranciever.
*
*/
#include "contiki.h"
#include "contiki-esb.h"
#include "dev/tr1001.h"
#include "dev/radio-sensor.h"
#include "lib/me.h"
#include "lib/crc16.h"
#include "net/netstack.h"
#include "net/rime/rimestats.h"
#include "isr_compat.h"
#include <string.h>
#ifdef TR1001_CONF_BEEP_ON_BAD_CRC
#define BEEP_ON_BAD_CRC TR1001_CONF_BEEP_ON_BAD_CRC
#else
#define BEEP_ON_BAD_CRC 1
#endif /* TR1001_CONF_BEEP_ON_BAD_CRC */
#if BEEP_ON_BAD_CRC
#include "dev/beep.h"
#define BEEP_BEEP(t) beep_beep(t)
#else
#define BEEP_BEEP(t)
#endif /* BEEP_ON_BAD_CRC */
#define RXSTATE_READY 0
#define RXSTATE_RECEIVING 1
#define RXSTATE_FULL 2
#define SYNCH1 0x3c
#define SYNCH2 0x03
#ifdef TR1001_CONF_BUFFER_SIZE
#define RXBUFSIZE TR1001_CONF_BUFFER_SIZE
#else
#define RXBUFSIZE PACKETBUF_SIZE
#endif /* TR1001_CONF_BUFFER_SIZE */
/*
* Pending data to send when using prepare/transmit functions.
*/
static const void *pending_data;
/*
* The buffer which holds incoming data.
*/
unsigned char tr1001_rxbuf[RXBUFSIZE];
/*
* The length of the packet that currently is being received.
*/
static unsigned short tr1001_rxlen = 0;
/*
* The reception state.
*/
volatile unsigned char tr1001_rxstate = RXSTATE_READY;
static uint16_t rxcrc, rxcrctmp;
/*
* The structure of the packet header.
*/
struct tr1001_hdr {
uint8_t len[2]; /**< The 16-bit length of the packet in network byte
order. */
};
/*
* The length of the packet header.
*/
#define TR1001_HDRLEN sizeof(struct tr1001_hdr)
#define OFF 0
#define ON 1
static uint8_t onoroff = OFF;
#define NUM_SYNCHBYTES 4
void tr1001_default_rxhandler(unsigned char c);
PT_THREAD(tr1001_default_rxhandler_pt(unsigned char c));
static struct pt rxhandler_pt;
/*
* This timer is used to keep track of when the last byte was received
* over the radio. If the inter-byte time is too large, the packet
* currently being received is discarded and a new packet reception is
* initiated.
*/
static struct timer rxtimer;
static unsigned short tmp_sstrength, sstrength;
static unsigned short tmp_count;
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define LOG(...) printf(__VA_ARGS__)
#else
#define LOG(...)
#endif
/*---------------------------------------------------------------------------*/
PROCESS(tr1001_process, "TR1001 driver");
/*---------------------------------------------------------------------------*/
static int prepare_packet(const void *data, unsigned short len);
static int transmit_packet(unsigned short len);
static int receiving_packet(void);
static int pending_packet(void);
static int channel_clear(void);
static int tr1001_on(void);
static int tr1001_off(void);
const struct radio_driver tr1001_driver = {
tr1001_init,
prepare_packet,
transmit_packet,
tr1001_send,
tr1001_read,
channel_clear,
receiving_packet,
pending_packet,
tr1001_on,
tr1001_off
};
/*---------------------------------------------------------------------------*/
/*
* Turn on data transmission in On-Off-Keyed mode.
*/
static void
txook(void)
{
P3SEL = 0xf0;
P5OUT |= 0x40;
P5OUT &= 0x7f;
}
/*---------------------------------------------------------------------------*/
/*
* Turn on data reception for the radio tranceiver.
*/
static void
rxon(void)
{
P3SEL = 0xe0;
P5OUT |= 0xc0;
/* Enable the receiver. */
ME1 |= URXE0;
/* Turn on receive interrupt. */
IE1 |= URXIE0;
}
/*---------------------------------------------------------------------------*/
/*
* Turn off data reception for the radio tranceiver.
*/
static void
rxoff(void)
{
P5OUT &= 0x3f;
/* Disable the receiver. */
ME1 &= ~URXE0;
/* Turn off receive interrupt. */
IE1 &= ~URXIE0;
}
/*---------------------------------------------------------------------------*/
/*
* Clear the recevie buffer and reset the receiver state.
*/
static void
rxclear(void)
{
tr1001_rxstate = RXSTATE_READY;
}
/*---------------------------------------------------------------------------*/
/*
* Turn TR1001 radio transceiver off.
*/
/*---------------------------------------------------------------------------*/
static int
tr1001_off(void)
{
if(onoroff == OFF) {
return 1;
}
onoroff = OFF;
rxoff();
rxclear();
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
return 1;
}
/*---------------------------------------------------------------------------*/
/*
* Turn TR1001 radio transceiver on.
*/
/*---------------------------------------------------------------------------*/
static int
tr1001_on(void)
{
if(onoroff == ON) {
return 1;
}
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
onoroff = ON;
rxon();
rxclear();
return 1;
}
/*---------------------------------------------------------------------------*/
/*
* Send a byte of data over the radio.
*
* \param b The byte to be sent.
*/
static void
send(unsigned char b)
{
clock_time_t start;
start = clock_time();
/* Wait until the USART0 TX buffer is ready. */
while((IFG1 & UTXIFG0) == 0) {
/* Wait no more than one second. */
if((clock_time_t)(clock_time() - start) > (clock_time_t)CLOCK_SECOND) {
break;
}
}
/* Send the byte. */
TXBUF0 = b;
}
/*---------------------------------------------------------------------------*/
/*
* Send a byte of data and its logical negation (all bits inverted)
* over the radio.
*
* \param b The byte to be sent.
*/
static void
send2(unsigned char b)
{
uint16_t m;
m = me_encode(b);
send(m >> 8);
send(m & 0xff);
}
static uint16_t
send2_crc16(unsigned char b, uint16_t crcacc)
{
uint16_t m;
m = me_encode(b);
send(m >> 8);
send(m & 0xff);
return crc16_add(b, crcacc);
}
/*---------------------------------------------------------------------------*/
void
tr1001_set_txpower(unsigned char p)
{
int i;
/* Clamp maximum power. */
if(p > 100) {
p = 100;
}
/* First, run the potentiometer down to zero so that we know the
start value of the potentiometer. */
P2OUT &= 0xDF; /* P25 = 0 (down selected) */
P2OUT &= 0xBF; /* P26 = 0 (chipselect on) */
for(i = 0; i < 102; ++i) {
P2OUT &= 0xEF; /* P24 = 0 (inc) */
P2OUT |= 0x10;
}
/* Now, start to increase the value of the potentiometer until it
reaches the desired value.*/
P2OUT |= 0x20; /* P25 = 1 (up selected) */
for(i = 0; i < p; ++i) {
P2OUT &= 0xEF; /* P24 = 0 (inc) */
P2OUT |= 0x10;
}
P2OUT |= 0x40; /* P26 = 1 (chipselect off) */
}
/*---------------------------------------------------------------------------*/
int
tr1001_init(void)
{
PT_INIT(&rxhandler_pt);
onoroff = OFF;
UCTL0 = CHAR; /* 8-bit character */
UTCTL0 = SSEL1; /* UCLK = SMCLK */
tr1001_set_speed(TR1001_19200);
ME1 |= UTXE0 + URXE0; /* Enable USART0 TXD/RXD */
/* Turn on receive interrupt. */
IE1 |= URXIE0;
timer_set(&rxtimer, CLOCK_SECOND / 4);
tr1001_on();
tr1001_set_txpower(100);
/* Reset reception state. */
rxclear();
process_start(&tr1001_process, NULL);
return 1;
}
/*---------------------------------------------------------------------------*/
ISR(UART0RX, tr1001_rxhandler)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
tr1001_default_rxhandler_pt(RXBUF0);
if(tr1001_rxstate == RXSTATE_FULL) {
LPM4_EXIT;
}
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
#if DEBUG
static void
dump_packet(int len)
{
int i;
for(i = 0; i < len; ++i) {
LOG("%d: 0x%02x\n", i, tr1001_rxbuf[i]);
}
}
#endif /* DEBUG */
/*---------------------------------------------------------------------------*/
PT_THREAD(tr1001_default_rxhandler_pt(unsigned char incoming_byte))
{
static unsigned char rxtmp, tmppos;
if(timer_expired(&rxtimer) && tr1001_rxstate != RXSTATE_FULL) {
PT_INIT(&rxhandler_pt);
}
timer_restart(&rxtimer);
if(tr1001_rxstate == RXSTATE_RECEIVING) {
unsigned short signal = radio_sensor.value(0);
tmp_sstrength += (signal >> 2);
tmp_count++;
}
PT_BEGIN(&rxhandler_pt);
while(1) {
/* Reset reception state. */
rxclear();
/* Wait until we receive the first syncronization byte. */
PT_WAIT_UNTIL(&rxhandler_pt, incoming_byte == SYNCH1);
tr1001_rxstate = RXSTATE_RECEIVING;
/* Read all incoming syncronization bytes. */
PT_WAIT_WHILE(&rxhandler_pt, incoming_byte == SYNCH1);
/* We should receive the second synch byte by now, otherwise we'll
restart the protothread. */
if(incoming_byte != SYNCH2) {
PT_RESTART(&rxhandler_pt);
}
/* Start signal strength measurement */
tmp_sstrength = 0;
tmp_count = 0;
/* Reset the CRC. */
rxcrc = 0xffff;
/* Read packet header. */
for(tmppos = 0; tmppos < TR1001_HDRLEN; ++tmppos) {
/* Wait for the first byte of the packet to arrive. */
PT_YIELD(&rxhandler_pt);
/* If the incoming byte isn't a valid Manchester encoded byte,
we start again from the beginning. */
if(!me_valid(incoming_byte)) {
BEEP_BEEP(1000);
LOG("Incorrect manchester in header at byte %d/1\n", tmppos);
RIMESTATS_ADD(badsynch);
PT_RESTART(&rxhandler_pt);
}
rxtmp = me_decode8(incoming_byte);
/* Wait for the next byte to arrive. */
PT_YIELD(&rxhandler_pt);
if(!me_valid(incoming_byte)) {
BEEP_BEEP(1000);
LOG("Incorrect manchester in header at byte %d/2\n", tmppos);
RIMESTATS_ADD(badsynch);
PT_RESTART(&rxhandler_pt);
}
/* Put together the two bytes into a single Manchester decoded
byte. */
tr1001_rxbuf[tmppos] = (rxtmp << 4) | me_decode8(incoming_byte);
/* Calculate the CRC. */
rxcrc = crc16_add(tr1001_rxbuf[tmppos], rxcrc);
}
/* Since we've got the header, we can grab the length from it. */
tr1001_rxlen = ((((struct tr1001_hdr *)tr1001_rxbuf)->len[0] << 8) +
((struct tr1001_hdr *)tr1001_rxbuf)->len[1]);
/* If the length is longer than we can handle, we'll start from
the beginning. */
if(tmppos + tr1001_rxlen > sizeof(tr1001_rxbuf)) {
RIMESTATS_ADD(toolong);
PT_RESTART(&rxhandler_pt);
}
/* Read packet data. */
for(; tmppos < tr1001_rxlen + TR1001_HDRLEN; ++tmppos) {
PT_YIELD(&rxhandler_pt);
if(!me_valid(incoming_byte)) {
LOG("Incorrect manchester 0x%02x at byte %d/1\n", incoming_byte,
tmppos - TR1001_HDRLEN);
BEEP_BEEP(1000);
RIMESTATS_ADD(badsynch);
PT_RESTART(&rxhandler_pt);
}
rxtmp = me_decode8(incoming_byte);
PT_YIELD(&rxhandler_pt);
if(!me_valid(incoming_byte)) {
LOG("Incorrect manchester at byte %d/2\n", tmppos - TR1001_HDRLEN);
BEEP_BEEP(1000);
RIMESTATS_ADD(badsynch);
PT_RESTART(&rxhandler_pt);
}
tr1001_rxbuf[tmppos] = (rxtmp << 4) | me_decode8(incoming_byte);
rxcrc = crc16_add(tr1001_rxbuf[tmppos], rxcrc);
}
/* Read the frame CRC. */
for(tmppos = 0; tmppos < 4; ++tmppos) {
PT_YIELD(&rxhandler_pt);
if(!me_valid(incoming_byte)) {
BEEP_BEEP(1000);
RIMESTATS_ADD(badsynch);
PT_RESTART(&rxhandler_pt);
}
rxcrctmp = (rxcrctmp << 4) | me_decode8(incoming_byte);
}
if(rxcrctmp == rxcrc) {
/* A full packet has been received and the CRC checks out. We'll
request the driver to take care of the incoming data. */
RIMESTATS_ADD(llrx);
process_poll(&tr1001_process);
/* We'll set the receive state flag to signal that a full frame
is present in the buffer, and we'll wait until the buffer has
been taken care of. */
tr1001_rxstate = RXSTATE_FULL;
PT_WAIT_UNTIL(&rxhandler_pt, tr1001_rxstate != RXSTATE_FULL);
} else {
LOG("Incorrect CRC\n");
BEEP_BEEP(1000);
RIMESTATS_ADD(badcrc);
}
}
PT_END(&rxhandler_pt);
}
/*---------------------------------------------------------------------------*/
static int
prepare_packet(const void *data, unsigned short len)
{
pending_data = data;
return 0;
}
/*---------------------------------------------------------------------------*/
static int
transmit_packet(unsigned short len)
{
int ret = RADIO_TX_ERR;
if(pending_data != NULL) {
ret = tr1001_send(pending_data, len);
pending_data = NULL;
}
return ret;
}
/*---------------------------------------------------------------------------*/
int
tr1001_send(const void *packet, unsigned short len)
{
int i;
uint16_t crc16;
LOG("tr1001_send: sending %d bytes\n", len);
if(onoroff == ON) {
ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
}
ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
/* Prepare the transmission. */
/* Delay the transmission for a short random duration. */
clock_delay(random_rand() & 0x3ff);
/* Check that we don't currently are receiving a packet, and if so
we wait until the reception has been completed. Reception is done
with interrupts so it is OK for us to wait in a while() loop. */
while(tr1001_rxstate == RXSTATE_RECEIVING &&
!timer_expired(&rxtimer)) {
/* Delay the transmission for a short random duration. */
clock_delay(random_rand() & 0x7ff);
}
/* Turn on OOK mode with transmission. */
txook();
/* According to the datasheet, the transmitter must wait for 12 us
in order to settle. Empirical tests show that is it better to
wait for something like 283 us... */
clock_delay(200);
/* Transmit preamble and synch bytes. */
for(i = 0; i < 20; ++i) {
send(0xaa);
}
/* send(0xaa);
send(0xaa);*/
send(0xff);
for(i = 0; i < NUM_SYNCHBYTES; ++i) {
send(SYNCH1);
}
send(SYNCH2);
crc16 = 0xffff;
/* Send packet header. */
crc16 = send2_crc16(len >> 8, crc16);
crc16 = send2_crc16(len & 0xff, crc16);
/* Send packet data. */
for(i = 0; i < len; ++i) {
crc16 = send2_crc16(((uint8_t *)packet)[i], crc16);
}
/* Send CRC */
send2(crc16 >> 8);
send2(crc16 & 0xff);
/* Send trailing bytes. */
send(0x33);
send(0xcc);
send(0x33);
send(0xcc);
/* Turn on (or off) reception again. */
if(onoroff == ON) {
ENERGEST_ON(ENERGEST_TYPE_LISTEN);
rxon();
rxclear();
} else {
rxoff();
rxclear();
}
ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
RIMESTATS_ADD(lltx);
return RADIO_TX_OK;
}
/*---------------------------------------------------------------------------*/
int
tr1001_read(void *buf, unsigned short bufsize)
{
unsigned short tmplen;
if(tr1001_rxstate == RXSTATE_FULL) {
#if DEBUG
dump_packet(tr1001_rxlen + 2);
#endif /* DEBUG */
tmplen = tr1001_rxlen;
if(tmplen > bufsize) {
LOG("tr1001_read: too large packet: %d/%d bytes\n", tmplen, bufsize);
rxclear();
RIMESTATS_ADD(toolong);
return -1;
}
memcpy(buf, &tr1001_rxbuf[TR1001_HDRLEN], tmplen);
/* header + content + CRC */
sstrength = (tmp_count ? ((tmp_sstrength / tmp_count) << 2) : 0);
rxclear();
LOG("tr1001_read: got %d bytes\n", tmplen);
return tmplen;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
receiving_packet(void)
{
return tr1001_rxstate == RXSTATE_RECEIVING &&
!timer_expired(&rxtimer);
}
/*---------------------------------------------------------------------------*/
static int
pending_packet(void)
{
return tr1001_rxstate == RXSTATE_FULL;
}
/*---------------------------------------------------------------------------*/
static int
channel_clear(void)
{
/* TODO add CCA functionality */
return 0;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tr1001_process, ev, data)
{
int len;
PROCESS_BEGIN();
/* Reset reception state now that the process is ready to receive data. */
rxclear();
while(1) {
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
packetbuf_clear();
len = tr1001_read(packetbuf_dataptr(), PACKETBUF_SIZE);
if(len > 0) {
packetbuf_set_datalen(len);
NETSTACK_RDC.input();
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
tr1001_set_speed(unsigned char speed)
{
if(speed == TR1001_19200) {
/* Set TR1001 to 19200 */
UBR00 = 0x80; /* 2,457MHz/19200 = 128 -> 0x80 */
UBR10 = 0x00; /* */
UMCTL0 = 0x00; /* no modulation */
} else if(speed == TR1001_38400) {
/* Set TR1001 to 38400 */
UBR00 = 0x40; /* 2,457MHz/38400 = 64 -> 0x40 */
UBR10 = 0x00; /* */
UMCTL0 = 0x00; /* no modulation */
} else if(speed == TR1001_57600) {
UBR00 = 0x2a; /* 2,457MHz/57600 = 42.7 -> 0x2A */
UBR10 = 0x00; /* */
UMCTL0 = 0x5b; /* */
} else if(speed == TR1001_115200) {
UBR00 = 0x15; /* 2,457MHz/115200 = 21.4 -> 0x15 */
UBR10 = 0x00; /* */
UMCTL0 = 0x4a; /* */
} else {
tr1001_set_speed(TR1001_19200);
}
}
/*---------------------------------------------------------------------------*/
unsigned short
tr1001_sstrength(void)
{
return sstrength;
}
/*---------------------------------------------------------------------------*/
/** @} */
/** @} */

View file

@ -1,137 +0,0 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#ifndef __TR1001_H__
#define __TR1001_H__
#include "contiki-net.h"
#include "dev/radio.h"
#include "contiki-conf.h"
/**
* Radio driver for TR1001
*/
extern const struct radio_driver tr1001_driver;
/**
* Initialize the radio transceiver.
*
* Turns on reception of bytes and installs the receive interrupt
* handler.
*/
int tr1001_init(void);
/**
* Set the speed of the TR1001 radio device.
*
* This function sets the speed of the TR1001 radio transceiver. Both
* the sender and the receiver must have the same speed for
* communication to work.
*
* \param speed The speed of the TR1001 radio: TR1001_19200,
* TR1001_38400, TR1001_57600 or TR1001_115200.
*
*/
void tr1001_set_speed(unsigned char s);
#define TR1001_19200 1
#define TR1001_38400 2
#define TR1001_57600 3
#define TR1001_115200 4
/**
* Set the transmission power of the transceiver.
*
* The sensor board is equipped with a DS1804 100 position trimmer
* potentiometer which is used to set the transmission input current
* to the radio transceiver chip, thus setting the transmission power
* of the radio transceiver.
*
* This function sets the trimmer potentiometer to a value between 1
* and 100.
*
* \param p The power of the transceiver, between 1 (lowest) and 100
* (highest).
*/
void tr1001_set_txpower(unsigned char p);
/**
* \brief The highest transmission power
*/
#define TR1001_TXPOWER_HIGHEST 100
/**
* \brief The lowest transmission power
*/
#define TR1001_TXPOWER_LOWEST 1
/**
* Send a packet.
*
* This function causes a packet to be sent out after a small random
* delay, but without doing any MAC layer collision detection or
* back-offs. The packet is sent with a 4 byte header that contains a
* a "type" identifier, an 8-bit packet ID field and the length of the
* packet in network byte order.
*
* This function should normally not be called from user
* programs. Rather, the uIP TCP/IP or Rime stack should be used.
*/
int tr1001_send(const void *packet, unsigned short len);
/**
* Check if an incoming packet has been received.
*
* This function checks the receive buffer to see if an entire packet
* has been received. The actual reception is handled by an interrupt
* handler.
*
* This function should normally not be called from user
* programs. Rather, the uIP TCP/IP or Rime stack should be used.
*
* \return The length of the received packet, or 0 if no packet has
* been received.
*/
int tr1001_read(void *buf, unsigned short bufsize);
extern unsigned char tr1001_rxbuf[];
extern volatile unsigned char tr1001_rxstate;
/**
* Calculate the signal strength of a received packet.
*
* This function calculates the received signal strength of the last
* received packet. This function typically is called when a packet
* has been received.
*/
unsigned short tr1001_sstrength(void);
#endif /* __TR1001_H__ */

View file

@ -1,96 +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 "dev/vib-sensor.h"
#include "dev/irq.h"
#include "dev/hwconf.h"
const struct sensors_sensor vib_sensor;
static unsigned int vib;
#define VIB_IRQ() 4
HWCONF_PIN(VIB, 1, VIB_IRQ());
HWCONF_IRQ(VIB, 1, VIB_IRQ());
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
++vib;
sensors_changed(&vib_sensor);
return 1;
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
return vib;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
vib = 0;
VIB_SELECT();
VIB_MAKE_INPUT();
return 1;
case SENSORS_ACTIVE:
if(value) {
if(!VIB_IRQ_ENABLED()) {
irq_port1_activate(VIB_IRQ(), irq);
VIB_ENABLE_IRQ();
}
} else {
VIB_DISABLE_IRQ();
irq_port1_deactivate(VIB_IRQ());
}
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
switch(type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return VIB_IRQ_ENABLED();
}
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(vib_sensor, VIB_SENSOR,
value, configure, status);

View file

@ -1,41 +0,0 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#ifndef __VIB_SENSOR_H__
#define __VIB_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor vib_sensor;
#define VIB_SENSOR "Vibration"
#endif /* __VIB_SENSOR_H__ */

View file

@ -1,7 +0,0 @@
/**
\defgroup doc Documentation
@{
*/
/** @} */

View file

@ -1,171 +0,0 @@
/** \addtogroup platform
* @{ **/
/**
\defgroup esb The ESB Embedded Sensor Board
The ESB (Embedded Sensor Board) is a prototype wireless sensor network
device developed at FU Berlin.
<img src="img/esb/esb.jpg" align="right">
The ESB consists of a Texas Instruments MSP430 low-power
microcontroller with 2k RAM and 60k flash ROM, a TR1001 radio
transceiver, a 32k serial EEPROM, an RS232 port, a JTAG port, a
beeper, and a number of sensors (passive IR, active IR
sender/receiver, vibration/tilt, microphone, temperature).
The Contiki/ESB port contains drivers for most of the sensors. The
drivers were mostly adapted from sources from FU Berlin.
\section esb-getting-started Getting started with Contiki for the ESB platform
The ESB is equipped with an MSP430 microcontroller. The first step to
getting started with Contiki for the ESB is to install the development
tools for compiling Contiki for the MSP430.
Windows users, see \ref esb-win-setup. FreeBSD users, see \ref esb-freebsd-setup
\section esb-win-setup Setting up the Windows environment
The Contiki development environment under Windows uses the Cygwin
environment. Cygwin is a Linux-like environment for Windows. Cygwin
can be found at http://www.cygwin.com. Click on the icon "Install
Cygwin Now" to the right to get the installation started.
Choose "Install from Internet" and then specify where you want to
install cygwin (recommended installation path:
<tt>C:\\cygwin</tt>). Continue with the installation until you are
asked to select packages. Most packages can be left as "Default" but
there is one package that are not installed by default. Install the
following package by clicking at "Default" until it changes to
"Install":
- Devel - contains things for developers (make, etc).
<img src="img/esb/cygwin6b.jpg" align="center">
When cygwin is installed there should be a cygwin icon that starts
up a cygwin bash when clicked on. Whenever it is time to compile and
send programs to the ESB nodes it will be done from a cygwin shell.
\subsection winintro-installing-editor C programming editor
If you do not already have a nice programming editor it is a good
idea to download and install one. The Crimson editor is a nice
windows based editor that is both easy to get started with and
fairly powerful.
Crimson Editor can be found at:
http://www.crimsoneditor.com/
The editor is useful both when editing C programs and when
modifying scripts and configuration files.
\subsection winintro-installing-compiler MSP430 Compiler and tools
A compiler is needed to compile the programs to the MSP430
microprocessor that is used on the ESB sensor nodes. Download and
install the GCC toolchain for MSP430 (recommended installation path:
C:\\MSP430\\).
The GCC toolchain for MSP430 can be found at:
http://sourceforge.net/projects/mspgcc/
When the above software is installed you also need to set-up the
PATH so that all of the necessary tools can be reached. In cygwin
this is done by the following line (given that you have installed
at recommended locations):
<tt>
export PATH=\$PATH:/cygdrive/c/MSP430/mspgcc/bin
</tt>
This line can also be added to the .profile startup file in your cygwin
home directory
(<tt>C:\\cygwin\\home\\\<YOUR USERNAME\>\\.profile</tt>).
If your home directory is located elsewhere you can find it by
starting cygwin and running \c cd followed by \c pwd.
\subsection winintro-installing-contiki The Contiki operating system, including examples
When programming the ESB sensor nodes it is very useful to have an
operating system that takes care of some of the low-level tasks and
also gives you as a programmer APIs for things like events, hardware
and networking. We will use the Contiki operating system developed by
Adam Dunkels, SICS, which is very well suited when programming small
embedded systems.
The Contiki OS can be found at:
http://www.sics.se/contiki/
Unzip the Contiki OS at (for example) C:\\
and you will get the following directories among others:
- contiki-2.x/core - the contiki operating system
- contiki-2.x/platform/esb - the contiki operating system drivers, etc for the ESB
- contiki-2.x/examples/esb/ - example applications for the ESB
\subsection winintro-testing Testing the tools
Now everything necessary to start developing Contiki-based sensor net
applications should be installed. Start cygwin and change to the
directory <tt>contiki-2.x/examples/esb/</tt>. Then call <tt>make
beeper.esb</tt>.
If you get an error about multiple cygwin dlls when compiling, you
need to delete <tt>cygwin1.dll</tt> from the MSP430 GCC toolchain
(<tt>C:\\MSP430\\bin\\cygwin1.dll</tt>).
Connect a node and turn it on. Upload the test application by calling
<tt>make beeper.u</tt>.
\subsection winintro-testing-development Development tools
- <tt>make \<SPEC\></tt> will compile and make a executable file ready
for sending to the ESB nodes. Depending on the \c SPEC it might even
startup the application that sends the executable to the
node. Typically you would write things like <tt>"make beeper.u"</tt>
to get the file <tt>beeper.c</tt> compiled, linked and sent out to the
ESB node.
\subsection winintro-testing-shell Some basic shell commands
- <tt> cd \<DIR\></tt> change to a specified directory (same as in DOS)
- <tt> pwd \<DIR\></tt> shows your current directory
- <tt> ls</tt> list the directory
- <tt> mkdir \<DIR\></tt> creates a new directory
- <tt> cp \<SRC\> \<DEST\></tt> copies a file
\section esb-freebsd-setup Setting up the FreeBSD environment
Download the msp430-gcc, msp430-binutils, and
msp430-libc packages from
http://www.sics.se/~adam/contiki/freebsd-packages/. Install the
packages (as root) with <tt>pkg_add</tt>.
\section esb-test-compilation Compiling your first Contiki system
\section esb-burn-node-id Burning node IDs to EEPROM
The Contiki ESB port comes with a small program, <tt>burn-nodeid</tt>
that semi-permanently stores a (unique) node ID number in the ESB
EEPROM. When the Contiki ESB port boots up, this node ID is restored
from the EEPROM. To compile and run this program, go into your project
directory and run
<tt>make burn-nodeid.u nodeid=X</tt>
where <tt>X</tt> is the node ID that will be burned into EEPROM. The
<tt>burn-nodeid</tt> program stores the node ID in EEPROM, reads it
back, and writes the output to the serial port.
@{
*/
/** @} */
/** @} */

View file

@ -1,18 +0,0 @@
/**
\addtogroup esb
\section esb-getting-started Getting started with Contiki for the ESB platform
The ESB is equipped with an MSP430 microcontroller. The first step to
getting started with Contiki for the ESB is to install the development
tools for compiling Contiki for the MSP430.
For Windows users, see \ref esb-win-setup
@{
*/
/**
@}
*/

View file

@ -1,78 +0,0 @@
/**
\defgroup quickref Function quick reference
@{
\section sensors Sensor functions
Each sensor has a set of functions for controlling it and query it for
its state. Some sensors also generate an events when the sensors
change. A sensor must be activated before it generates events or
relevant values.
- SENSORS_ACTIVATE(sensor) - activate the sensor
- SENSORS_DEACTIVATE(sensor) - deactivate the sensor
- sensor.value(0) - query the sensor for its last value
- \ref sensors_event - event sent when a sensor has changed (the data
argument will referer to the actual sensor)
Example for querying the button:
- \ref SENSORS_ACTIVATE(button_sensor) - activate the button sensor
- \ref button_sensor.value(0) - the button has been pressed or not
\subsection quickref-sensors Sensor on the ESB platform
- \ref battery_sensor - query the battery voltage level
- \ref button_sensor - query the on-board button
- \ref pir_sensor - query the passive IR sensor (motion detector)
- \ref radio_sensor - query the radio signal strength
- \ref sound_sensor - query the microphone
- \ref temperature_sensor - query the temperature sensor
- \ref vib_sensor - query the vibration sensor
\section quickref-leds LED functions
- leds_on() - turn LEDs on
- leds_off() - turn LEDs off
- leds_invert() - invert LEDs
- leds_blink() - blink all LEDs
\section quickref-beeper Beeper functions
- beep() - click the beeper
- beep_beep() - beep
- beep_down() - pitchbend down beep
- beep_quick() - a number of quick beeps
- beep_spinup() - pitchbend up beep
\section quickref-timers Timer functions
Contiki provides a set of timer libraries. Event timers generates an
event when the timer expires and callback timers call a function when
the timer expires. The simple timers on the other hand have to be
actively queried to check when they have expired.
\subsection quickref-etimer Event timers
- etimer_expired() - check if an event timer has expired
- etimer_set() - set an event timer
- etimer_reset() - set an expired event timer to the next interval
- etimer_restart() - restart an event timer from the current point in time
\subsection quickref-ctimer Callback timers
- ctimer_expired() - check if a callback timer has expired
- ctimer_set() - set a callback timer
- ctimer_reset() - set an expired callback timer to the next interval
- ctimer_restart() - restart a callback timer from the current point in time
\subsection quickref-timer Simple timers
- timer_expired() - check if a simple timer has expired
- timer_set() - set a simple timer
- timer_reset() - set a simple event timer to the next interval
- timer_restart() - restart a simple timer from the current point in time
*//** @{ */

View file

@ -1,127 +0,0 @@
/** \addtogroup esb
@{ */
/**
\defgroup slipintro Introduction to Over The Air Reprogramming under Windows
\author Joakim Eriksson, Niclas Finne
@{
\section slipintro-intro Introduction
This is a brief introduction how to program ESB sensor nodes over
radio under Windows. It is assumed that you already have the
environment setup for programming ESB sensor nodes using JTAG cable.
\section slipintro-configuring Configuring SLIP under Windows XP
This section describes how to setup a SLIP connection under Windows. A
SLIP connection forwards TCP/IP traffic to/from the sensor nodes and
lets you communicate with them using standard network tools such as
\c ping.
-# Click start button and choose 'My Computer'. Right-click 'My
Network Places' and choose 'Properties'.
<img src="img/esb/slip01.jpg" align="center">
-# Click 'Create a new connection'.
<img src="img/esb/slip02.jpg" align="center">
-# Select 'Set up an advanced connection'.
<img src="img/esb/slip03.jpg" align="center">
-# Select 'Connect directly to another computer'.
<img src="img/esb/slip04.jpg" align="center">
-# Select 'Guest'.
<img src="img/esb/slip05.jpg" align="center">
-# Select a name for the slip connection (for example 'ESB').
<img src="img/esb/slip06.jpg" align="center">
-# Select the serial port to use when communicating with the sensor
node.
<img src="img/esb/slip07.jpg" align="center">
-# Add the connection by clicking 'Finish'.
<img src="img/esb/slip08.jpg" align="center">
-# A connection window will open. Choose 'Properties'.
<img src="img/esb/slip09.jpg" align="center">
<img src="img/esb/slip10.jpg" align="center">
-# Click on 'Configure...' and deselect all selected
buttons. Choose the speed 57600 bps.
<img src="img/esb/slip11.jpg" align="center">
-# Close the modem configuration window, and go to the 'Options'
tab in the ESB properties. Deselect all except 'Display
progress...'.
<img src="img/esb/slip12.jpg" align="center">
-# Go to the 'Networking' tab. Change to 'SLIP: Unix Connection'
and deselect all except the first two items in the connection item
list.
<img src="img/esb/slip13.jpg" align="center">
-# Select 'Internet Protocol (TCP/IP)' and click
'Properties'. Enter the IP address '172.16.0.1'.
<img src="img/esb/slip14b.jpg" align="center">
-# Click 'Advanced' and deselect all checkboxes in the 'Advanced
TCP/IP Settings'. Go to the 'WINS' tab and deselect 'Enable LMHOSTS
lookup' if it is selected. Also select 'Disable NetBIOS over
TCP/IP'.
<img src="img/esb/slip15.jpg" align="center">
<img src="img/esb/slip16.jpg" align="center">
\section slipintro-setup Setup ESB for over the air programming
Make sure you have the latest version of Contiki (older versions of
Contiki might not work with SLIP under Windows).
-# Each node needs an IP address for OTA to work. The node id
is used to construct an IP address for the node. If you specify 2 as
node id, the node will have the IP address 172.16.1.2. Each node
should have its own unique node id. To set the node id move to the
directory '<tt>contiki-2.x/examples/esb</tt>' and run
\code
make burn-nodeid.u nodeid=X
\endcode
Use the number 1, 2, 3, etc, as the node id (\c X) for the nodes. This
will give the nodes the IP addresses 172.16.1.1, 172.16.1.2, etc. The
node id only needs to be set once for each node and it will remain
even when new applications are uploaded onto the node.
-# You need to compile a core and upload it onto the nodes. All nodes
must run the same core. Move to the directory
'<tt>contiki-2.x/examples/esb</tt>' and run
\code
make WITH_CODEPROP=1 core
make WITH_CODEPROP=1 core.u
\endcode
to upload the core to your nodes.
-# Attach the ESB node to the serial port and make sure it is
turned on. Select your ESB SLIP connection in your 'Network
Connections' and choose 'Connect' (or double click on it). If
everything works Windows should say that you have a new connection.
-# Set the IP address for the node by pinging it (it will claim the
IP address of the first ping it hears). Note that the slip interface
has IP address 172.16.0.1 but the node will have the IP address
172.16.1.1.
\code
ping 172.16.1.1
\endcode
If everything works the node should click and reply to the pings.
You also need a program to send the application to connected
nodes. Compile it by running
\code
make send
\endcode
\section slipintro-send Send programs over the air
Contiki applications to be installed via radio are compiled somewhat
different compared to normal applications.
Make sure you have a node with IP address 172.16.1.1 connected to your
serial port and have SLIP activated. Then compile and send a
testprogram by running
\code
make beeper.ce
./send 172.16.1.1 beeper.ce
\endcode
*/
/** @} */
/** @} */

View file

@ -1,73 +0,0 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
#ifndef __LOADER_ARCH_H__
#define __LOADER_ARCH_H__
/**
* Load a program from EEPROM.
*
* This function loads a program from EEPROM into the flash ROM (code) and RAM (data).
*
* \param code The address of the first byte of code in the EEPROM.
*
* \param codelen The length of the code.
*
* \param data The address of the first byte of data in the EEPROM.
*
* \param datalen The length of the data.
*
*/
void loader_arch_load(unsigned short startaddr);
/**
* Unload a program.
*
* This function should not be called directly, but accessed through
* the macro LOADER_UNLOAD(). The function unloads a program from both
* RAM and ROM.
*
* \param codeaddr A pointer to the first byte of program code.
*
* \param dataaddr A pointer to the first byte of program data.
*/
void loader_arch_free(void *codeaddr, void *dataaddr);
extern void *loader_arch_codeaddr, *loader_arch_dataaddr;
#ifndef LOADER_UNLOAD
#define LOADER_UNLOAD() loader_arch_free(&loader_arch_codeaddr, &loader_arch_dataaddr)
#endif
#define LOADER_ARCH_MAGIC 0x373a
#define LOADER_ARCH_VERSION 0x0001
#endif /* __LOADER_ARCH_H__ */

View file

@ -1,86 +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 brief description of what this file is
* \author
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/
#include "net/netstack.h"
#include "net/uip.h"
#include "net/tcpip.h"
#include "net/hc.h"
#include "net/packetbuf.h"
#include "net/uip-driver.h"
#include <string.h>
/*--------------------------------------------------------------------*/
static void
init(void)
{
/*
* Set out output function as the function to be called from uIP to
* send a packet.
*/
tcpip_set_outputfunc(uip_driver_send);
}
/*--------------------------------------------------------------------*/
static void
input(void)
{
if(packetbuf_datalen() > 0 &&
packetbuf_datalen() <= UIP_BUFSIZE - UIP_LLH_LEN) {
memcpy(&uip_buf[UIP_LLH_LEN], packetbuf_dataptr(), packetbuf_datalen());
uip_len = hc_inflate(&uip_buf[UIP_LLH_LEN], packetbuf_datalen());
tcpip_input();
}
}
/*--------------------------------------------------------------------*/
uint8_t
uip_driver_send(void)
{
uip_len = hc_compress(&uip_buf[UIP_LLH_LEN], uip_len);
packetbuf_copyfrom(&uip_buf[UIP_LLH_LEN], uip_len);
/* XXX we should provide a callback function that is called when the
packet is sent. For now, we just supply a NULL pointer. */
NETSTACK_MAC.send(NULL, NULL);
return 1;
}
/*--------------------------------------------------------------------*/
const struct network_driver uip_driver = {
"uip",
init,
input
};
/*--------------------------------------------------------------------*/

View file

@ -1,48 +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 brief description of what this file is
* \author
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/
#ifndef __UIP_DRIVER_H__
#define __UIP_DRIVER_H__
#include "net/netstack.h"
uint8_t uip_driver_send(void);
extern const struct network_driver uip_driver;
#endif /* __UIP_DRIVER_H__ */

View file

@ -1,71 +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 brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "sys/node-id.h"
#include "contiki-conf.h"
#include "dev/eeprom.h"
unsigned short node_id = 0;
/*---------------------------------------------------------------------------*/
void
node_id_restore(void)
{
unsigned char buf[2];
eeprom_read(NODE_ID_EEPROM_OFFSET, buf, 2);
if(buf[0] == 0xad &&
buf[1] == 0xde) {
eeprom_read(NODE_ID_EEPROM_OFFSET + 2, buf, 2);
node_id = (buf[0] << 8) | buf[1];
} else {
node_id = 0;
}
}
/*---------------------------------------------------------------------------*/
void
node_id_burn(unsigned short id)
{
unsigned char buf[2];
buf[0] = 0xad;
buf[1] = 0xde;
eeprom_write(NODE_ID_EEPROM_OFFSET, buf, 2);
buf[0] = id >> 8;
buf[1] = id & 0xff;
eeprom_write(NODE_ID_EEPROM_OFFSET + 2, buf, 2);
}
/*---------------------------------------------------------------------------*/

View file

@ -1,17 +0,0 @@
# Use custom platform configuration
CFLAGS += -DPLATFORM_CONF_H=\"platform-jcreate-conf.h\"
# Some drivers such as ds2411.c only compile under platform sky
CFLAGS += -DCONTIKI_TARGET_SKY
CONTIKI_TARGET_SOURCEFILES += contiki-jcreate-platform.c \
battery-sensor.c radio-sensor.c \
temperature-sensor.c acc-sensor.c ext-sensor.c
include $(CONTIKI)/platform/sky/Makefile.common
ifneq ($(TMOTE_BSL), 1)
${warning No $(TMOTE_BSL_FILE) command for jcreate found. Please install this command in $(CONTIKI)/tools/sky}
endif
CONTIKI_TARGET_DIRS += ${addprefix ../sky/,. dev apps}

View file

@ -1,43 +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: Niclas Finne <nfi@sics.se>, Joakim Eriksson <joakime@sics.se>
*
*/
#include "dev/battery-sensor.h"
SENSORS(&battery_sensor);
void
init_platform(void)
{
process_start(&sensors_process, NULL);
}

View file

@ -1,97 +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 : 2005-11-01
* Updated : $Date: 2010/08/25 19:34:42 $
* $Revision: 1.2 $
*/
#include "contiki.h"
#include "dev/acc-sensor.h"
#include "dev/sky-sensors.h"
/* Configure ADC12_2 to sample channel 4, 5, 6 and use */
/* the Vref+ as reference (SREF_1) since it is a stable reference */
#define INPUT_CHANNEL ((1 << INCH_4) | (1 << INCH_5) | (1 << INCH_6))
#define INPUT_REFERENCE SREF_1
#define ACC_MEM_X ADC12MEM4 /* Xout */
#define ACC_MEM_Y ADC12MEM5 /* Yout */
#define ACC_MEM_Z ADC12MEM6 /* Zout */
const struct sensors_sensor acc_sensor;
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
switch(type) {
case ACC_SENSOR_X:
return ACC_MEM_X;
case ACC_SENSOR_Y:
return ACC_MEM_Y;
case ACC_SENSOR_Z:
return ACC_MEM_Z;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int c)
{
if(type == SENSORS_ACTIVE) {
/* Sleep Mode P2.3 */
if(c) {
P2OUT |= 0x08;
P2DIR |= 0x08;
} else {
/* Sensor deactivated. Changed to sleep mode. */
P2OUT &= ~0x08;
}
} else if(type == ACC_SENSOR_SENSITIVITY) {
/* g-Select1 P2.0, g-Select2 P2.1 */
P2DIR |= 0x03;
P2OUT &= ~0x03;
P2OUT |= c & 0x03;
}
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
if(type == ACC_SENSOR_SENSITIVITY) {
return (P2OUT & P2DIR) & 0x03;
}
return sky_sensors_status(INPUT_CHANNEL, type);
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(acc_sensor, ACC_SENSOR, value, configure, status);

View file

@ -1,61 +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:34:42 $
* $Revision: 1.2 $
*/
#ifndef __ACC_SENSOR_H__
#define __ACC_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor acc_sensor;
#define ACC_SENSOR "Acc"
#define ACC_SENSOR_X 0
#define ACC_SENSOR_Y 1
#define ACC_SENSOR_Z 2
/*
Sensitivity configuration (g-Select1 and g-Select2)
Value g-Range Sensitivity
0 1.5g 800mV/g
1 2g 600mV/g
2 4g 300mV/g
3 6g 200mV/g
*/
#define ACC_SENSOR_SENSITIVITY 10
#endif /* __ACC_SENSOR_H__ */

View file

@ -1,92 +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, Marcus Lundén,
* Jesper Karlsson
* Created : 2005-11-01
* Updated : $Date: 2010/08/25 19:34:42 $
* $Revision: 1.2 $
*/
#include "contiki.h"
#include "dev/ext-sensor.h"
#include "dev/sky-sensors.h"
/* SREF_0 is AVCC */
/* SREF_1 is Vref+ */
/* ADC0 == P6.0/A0 == port "under" logo */
/* ADC1 == P6.1/A1 == port "over" logo */
/* ADC2 == P6.2/A2, bottom expansion port */
/* ADC3 == P6.1/A3, bottom expansion port, End Of (ADC-)Sequence */
#define INPUT_CHANNEL ((1 << INCH_0) | (1 << INCH_1) | \
(1 << INCH_2) | (1 << INCH_3))
#define INPUT_REFERENCE SREF_0
#define EXT_MEM0 ADC12MEM0
#define EXT_MEM1 ADC12MEM1
#define EXT_MEM2 ADC12MEM2
#define EXT_MEM3 ADC12MEM3
const struct sensors_sensor ext_sensor;
/*---------------------------------------------------------------------------*/
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 ADC0:
return EXT_MEM0;
case ADC1:
return EXT_MEM1;
case ADC2:
return EXT_MEM2;
case ADC3:
return EXT_MEM3;
}
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(ext_sensor, "Ext", value, configure, status);

View file

@ -1,52 +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 : Marcus Lundén
* Created : 2005-11-01
* Updated : $Date: 2010/05/03 21:57:35 $
* $Revision: 1.1 $
*/
#ifndef __EXT_SENSOR_H__
#define __EXT_SENSOR_H__
#include "lib/sensors.h"
#define ADC0 0
#define ADC1 1
#define ADC2 2
#define ADC3 3
extern const struct sensors_sensor ext_sensor;
#define EXT_SENSOR "Ext"
#endif /* __EXT_SENSOR_H__ */

View file

@ -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 leds implementation for the jcreate platform
* \author
* Adam Dunkels <adam@sics.se>
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/
#include "contiki.h"
#include "dev/leds.h"
/*---------------------------------------------------------------------------*/
void
leds_arch_init(void)
{
LEDS_PxDIR = 0xff;
LEDS_PxOUT = 0xff;
}
/*---------------------------------------------------------------------------*/
unsigned char
leds_arch_get(void)
{
return ~LEDS_PxOUT;
}
/*---------------------------------------------------------------------------*/
void
leds_arch_set(unsigned char leds)
{
LEDS_PxOUT = ~leds;
}
/*---------------------------------------------------------------------------*/

View file

@ -1,209 +0,0 @@
/*
* Copyright (c) 2011, 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 Sentilla JCreate
* \author
* Niclas Finne <nfi@sics.se>
* Joakim Eriksson <joakime@sics.se>
*/
#ifndef __PLATFORM_CONF_H__
#define __PLATFORM_CONF_H__
/*
* Definitions below are dictated by the hardware and not really
* changeable!
*/
/* Platform TMOTE_SKY */
#define TMOTE_SKY 1
#define LEDS_CONF_ALL 255
#define PLATFORM_HAS_LEDS 1
#define PLATFORM_HAS_BUTTON 0
/* CPU target speed in Hz */
#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 HAVE_STDINT_H
#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
/* LED ports */
#define LEDS_PxDIR P5DIR
#define LEDS_PxOUT P5OUT
#define LEDS_CONF_RED 0x10
#define LEDS_CONF_GREEN 0x20
#define LEDS_CONF_YELLOW 0x40
/* DCO speed resynchronization for more robust UART, etc. */
#ifndef DCOSYNCH_CONF_ENABLED
#define DCOSYNCH_CONF_ENABLED 1
#endif /* DCOSYNCH_CONF_ENABLED */
#ifndef DCOSYNCH_CONF_PERIOD
#define DCOSYNCH_CONF_PERIOD 30
#endif /* DCOSYNCH_CONF_PERIOD */
#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 U0TXBUF
#define SPI_RXBUF U0RXBUF
/* USART0 Tx ready? */
#define SPI_WAITFOREOTx() while ((U0TCTL & TXEPT) == 0)
/* USART0 Rx ready? */
#define SPI_WAITFOREORx() while ((IFG1 & URXIFG0) == 0)
/* USART0 Tx buffer ready? */
#define SPI_WAITFORTxREADY() while ((IFG1 & UTXIFG0) == 0)
#define SCK 1 /* P3.1 - Output: SPI Serial Clock (SCLK) */
#define MOSI 2 /* P3.2 - Output: SPI Master out - slave in (MOSI) */
#define MISO 3 /* P3.3 - Input: SPI Master in - slave out (MISO) */
/*
* SPI bus - M25P80 external flash configuration.
*/
#define FLASH_PWR 3 /* P4.3 Output */
#define FLASH_CS 4 /* P4.4 Output */
#define FLASH_HOLD 7 /* P4.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() ( P4OUT &= ~BV(FLASH_HOLD) )
#define SPI_FLASH_UNHOLD() ( P4OUT |= BV(FLASH_HOLD) )
/*
* SPI bus - CC2420 pin configuration.
*/
#define CC2420_CONF_SYMBOL_LOOP_COUNT 800
/* P1.0 - Input: FIFOP from CC2420 */
#define CC2420_FIFOP_PORT(type) P1##type
#define CC2420_FIFOP_PIN 0
/* 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
/* P4.2 - Output: SPI Chip Select (CS_N) */
#define CC2420_CSN_PORT(type) P4##type
#define CC2420_CSN_PIN 2
/* 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__ */

View file

@ -1,14 +0,0 @@
# $Id: Makefile,v 1.3 2007/08/17 13:10:16 nvt-se Exp $
all: test-abc
upload: test-abc test-abc.u
test-abc:
$(MAKE) test-abc.firmware && \
$(MAKE) test-abc.firmware && \
$(MAKE) test-abc.firmware
CONTIKI=../..
TARGET=msb430
include $(CONTIKI)/Makefile.include

View file

@ -1,74 +0,0 @@
SENSORS = sensors.c sht11.c
MSB = dma.c infomem.c node-id.c \
msb430-uart1.c rs232.c \
cc1020.c cc1020-uip.c adc.c \
msb430-slip-arch.c sd.c sd-arch.c \
cfs-coffee.c cfs-coffee-arch.c
CONTIKI_TARGET_DIRS = . dev apps loader
ifndef CONTIKI_TARGET_MAIN
CONTIKI_TARGET_MAIN = contiki-msb430-main.c
endif
CONTIKI_TARGET_SOURCEFILES += $(SENSORS) $(MSB) $(CONTIKI_TARGET_MAIN)
MCU=msp430f1612
include $(CONTIKI)/cpu/msp430/Makefile.msp430
contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
# $(AR) rcf $@ $^
ifndef BASE_IP
BASE_IP := 172.16.1.1
endif
### System dependent Makefile
ifeq ($(HOST_OS),FreeBSD)
# settings for FreeBSD
-include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.freebsd
else
ifeq ($(HOST_OS),Windows)
# settings for Windows
-include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.win
else
# settings for an arbitary unix-like platform
-include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.unix
endif
endif
# If we are not running under Windows, we assume Linux
ifndef MOTELIST
USBDEVPREFIX=
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux
MOTELIST = $(CONTIKI)/tools/sky/motelist-linux
MOTES = $(shell $(MOTELIST) 2>&- | grep USB | \
cut -f 4 -d \ | \
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')
CMOTES=$(MOTES)
endif
msb-motelist:
$(MOTELIST)
msb-motes:
@echo $(MOTES)
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

View file

@ -1,2 +0,0 @@
helloworld: helloworld.c
test-abc: test-abc.c

View file

@ -1,70 +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.
*
*/
#include "contiki.h"
#include "net/rime.h"
#include "dev/sd.h"
#include <io.h>
#include <stdio.h>
/*---------------------------------------------------------------------------*/
PROCESS(test_acc_process, "Accelerometer test");
AUTOSTART_PROCESSES(&test_acc_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_acc_process, ev, data)
{
static struct etimer et;
static int x, y, z;
static uint32_t xa, ya, za;
PROCESS_BEGIN();
while(1) {
etimer_set(&et, CLOCK_SECOND / 8);
PROCESS_WAIT_EVENT();
if (etimer_expired(&et)) {
adc_on();
x = ADC12MEM0;
y = ADC12MEM1;
z = ADC12MEM2;
xa = xa + x - (xa >> 4);
ya = ya + y - (ya >> 4);
za = za + z - (za >> 4);
adc_off();
printf("x=%ld, y=%ld, z=%ld\n",
(xa >> 4) - x, (ya >> 4) - y, (za >> 4) - z);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -1,94 +0,0 @@
/*
* Copyright (c) 2009, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Test for an SD driver.
* \author
* Nicolas Tsiftes <nvt@sics.se>
*/
#include "contiki.h"
#include "dev/sd.h"
#include "lib/random.h"
#include <stdio.h>
#include <string.h>
PROCESS(sd_test, "SD test process");
AUTOSTART_PROCESSES(&sd_test);
#define BUF_SIZE 64
PROCESS_THREAD(sd_test, event, data)
{
static unsigned long iter;
static unsigned long offset;
char buf[BUF_SIZE];
static struct etimer et;
int r, buflen;
PROCESS_BEGIN();
etimer_set(&et, CLOCK_SECOND / 16);
offset = 0;
for(iter = 1;; iter++) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
memset(buf, 0, sizeof(buf));
buflen = sprintf(buf, "(%ld) Testing the SD card (%ld)", iter, iter);
if((iter & 7) == 0) {
offset = random_rand() & 0xffff;
} else {
offset += random_rand() & 0xff;
}
r = sd_write(offset, buf, buflen + 1);
if(r > 0) {
memset(buf, 0, sizeof(buf));
r = sd_read(offset, buf, buflen + 1);
if(r > 0) {
printf("read %s (offset %lu)\n", buf, offset);
} else {
printf("read error: %d (%s)\n", r, sd_error_string(r));
}
} else {
printf("write error: %d (%s)\n", r, sd_error_string(r));
}
etimer_restart(&et);
}
PROCESS_END();
}

View file

@ -1,102 +0,0 @@
/*
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Testing the abc layer in Rime
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "contiki.h"
#include "net/rime.h"
#include "sys/node-id.h"
#include <stdio.h>
#ifndef SENDER_ID
#define SENDER_ID 1
#endif
#ifndef SEND_INTERVAL
#define SEND_INTERVAL (CLOCK_SECOND * 3)
#endif
/*---------------------------------------------------------------------------*/
PROCESS(test_abc_process, "ABC test");
AUTOSTART_PROCESSES(&test_abc_process);
/*---------------------------------------------------------------------------*/
static void
abc_recv(struct abc_conn *c)
{
char *s;
int i;
s = packetbuf_dataptr();
printf("abc message received '%s'\n", (char *)packetbuf_dataptr());
printf("message length: %u\n", packetbuf_datalen());
for (i = 0; i < packetbuf_datalen(); i++) {
printf("0x%x ", s[i]);
}
printf("\n");
}
const static struct abc_callbacks abc_call = {abc_recv};
static struct abc_conn abc;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_abc_process, ev, data)
{
static unsigned i;
static struct etimer et;
static int len;
static char buf[32];
PROCESS_EXITHANDLER(abc_close(&abc);)
PROCESS_BEGIN();
abc_open(&abc, 128, &abc_call);
while(1) {
etimer_set(&et, SEND_INTERVAL);
PROCESS_WAIT_EVENT();
if (etimer_expired(&et) && node_id == SENDER_ID) {
len = snprintf(buf, sizeof (buf), "%u", ++i);
printf("Sending packet %d\n", i);
packetbuf_copyfrom(buf, len + 1);
abc_send(&abc);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -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
* Testing the SHT11 sensor.
* \author
* Nicolas Tsiftes <nvt@sics.se>
*/
#include "contiki.h"
#include "dev/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();
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();
}

View file

@ -1,18 +0,0 @@
ifndef JTAG
JTAG := $(CONTIKI)/platform/$(TARGET)/buildscripts/jtag/pyjtag/jtag.py
endif
ifndef JTAG_PORT
JTAG_PORT = /dev/ppi0
endif
%.u: %.$(TARGET)
$(JTAG) -l $(JTAG_PORT) -m
$(JTAG) -l $(JTAG_PORT) -D -D -S -R 2048 -p $^
$(JTAG) -l $(JTAG_PORT) -D -r
r:
$(JTAG) -l $(JTAG_PORT) -r
erase:
$(JTAG) -l $(JTAG_PORT) -e

View file

@ -1,18 +0,0 @@
ifndef JTAG
JTAG := $(CONTIKI)/platform/$(TARGET)/buildscripts/jtag/pyjtag/jtag.py
endif
ifndef JTAG_PORT
JTAG_PORT = /dev/parport0
endif
%.u: %.$(TARGET)
$(JTAG) -l $(JTAG_PORT) -m
$(JTAG) -l $(JTAG_PORT) -D -D -S -R 2048 -p $^
$(JTAG) -l $(JTAG_PORT) -D -r
r:
$(JTAG) -l $(JTAG_PORT) -r
erase:
$(JTAG) -l $(JTAG_PORT) -e

View file

@ -1,15 +0,0 @@
ifndef JTAG_PORT
JTAG_PORT = LPT1
endif
ifdef DEBUG
DEBUG_ARGS = -D -D -D -D
endif
%.u: %.ihex
msp430-jtag $(DEBUG_ARGS) -l $(JTAG_PORT) -mI $^
#CW=cw23
#%.u: %.ihex
# $(CW) -d f430p $^

View file

@ -1,318 +0,0 @@
#!/usr/bin/env python
import struct
# ELF object file reader
# (C) 2003 cliechti@gmx.net
# Python license
# size alignment
# Elf32_Addr 4 4 Unsigned program address
# Elf32_Half 2 2 Unsigned medium integer
# Elf32_Off 4 4 Unsigned file offset
# Elf32_Sword 4 4 Signed large integer
# Elf32_Word 4 4 Unsigned large integer
# unsignedchar 1 1 Unsigned small integer
#define EI_NIDENT 16
#~ typedef struct{
#~ unsigned char e_ident[EI_NIDENT];
#~ Elf32_Half e_type;
#~ Elf32_Half e_machine;
#~ Elf32_Word e_version;
#~ Elf32_Addr e_entry;
#~ Elf32_Off e_phoff;
#~ Elf32_Off e_shoff;
#~ Elf32_Word e_flags;
#~ Elf32_Half e_ehsize;
#~ Elf32_Half e_phentsize;
#~ Elf32_Half e_phnum;
#~ Elf32_Half e_shentsize;
#~ Elf32_Half e_shnum;
#~ Elf32_Half e_shstrndx;
#~ } Elf32_Ehdr;
#Section Header
#~ typedef struct {
#~ Elf32_Word sh_name;
#~ Elf32_Word sh_type;
#~ Elf32_Word sh_flags;
#~ Elf32_Addr sh_addr;
#~ Elf32_Off sh_offset;
#~ Elf32_Word sh_size;
#~ Elf32_Word sh_link;
#~ Elf32_Word sh_info;
#~ Elf32_Word sh_addralign;
#~ Elf32_Word sh_entsize;
#~ } Elf32_Shdr;
#~ typedef struct {
#~ Elf32_Word p_type;
#~ Elf32_Off p_offset;
#~ Elf32_Addr p_vaddr;
#~ Elf32_Addr p_paddr;
#~ Elf32_Word p_filesz;
#~ Elf32_Word p_memsz;
#~ Elf32_Word p_flags;
#~ Elf32_Word p_align;
#~ } Elf32_Phdr;
class ELFException(Exception): pass
class ELFSection:
"""read and store a section"""
Elf32_Shdr = "<IIIIIIIIII" #header format
#section types
SHT_NULL = 0
SHT_PROGBITS = 1
SHT_SYMTAB = 2
SHT_STRTAB = 3
SHT_RELA = 4
SHT_HASH = 5
SHT_DYNAMIC = 6
SHT_NOTE = 7
SHT_NOBITS = 8
SHT_REL = 9
SHT_SHLIB = 10
SHT_DYNSYM = 11
SHT_LOPROC = 0x70000000L
SHT_HIPROC = 0x7fffffffL
SHT_LOUSER = 0x80000000L
SHT_HIUSER = 0xffffffffL
#section attribute flags
SHF_WRITE = 0x1
SHF_ALLOC = 0x2
SHF_EXECINSTR = 0x4
SHF_MASKPROC = 0xf0000000
def __init__(self):
"""creat a new empty section object"""
(self.sh_name, self.sh_type, self.sh_flags, self.sh_addr,
self.sh_offset, self.sh_size, self.sh_link, self.sh_info,
self.sh_addralign, self.sh_entsize) = [0]*10
self.name = None
self.data = None
self.lma = None
def fromString(self, s):
"""get section header from string"""
(self.sh_name, self.sh_type, self.sh_flags, self.sh_addr,
self.sh_offset, self.sh_size, self.sh_link, self.sh_info,
self.sh_addralign, self.sh_entsize) = struct.unpack(self.Elf32_Shdr, s)
def __str__(self):
"""pretty print for debug..."""
return "%s(%s, sh_type=%s, sh_flags=%s, "\
"sh_addr=0x%04x, sh_offset=0x%04x, sh_size=%s, sh_link=%s, "\
"sh_info=%s, sh_addralign=%s, sh_entsize=%s, lma=0x%04x)" % (
self.__class__.__name__,
self.name is not None and "%r" % self.name or "sh_name=%s" % self.sh_name,
self.sh_type, self.sh_flags, self.sh_addr,
self.sh_offset, self.sh_size, self.sh_link, self.sh_info,
self.sh_addralign, self.sh_entsize, self.lma)
class ELFProgramHeader:
"""Store and parse a program header"""
Elf32_Phdr = "<IIIIIIII" #header format
#segmet types
PT_NULL = 0
PT_LOAD = 1
PT_DYNAMIC = 2
PT_INTERP = 3
PT_NOTE = 4
PT_SHLIB = 5
PT_PHDR = 6
PT_LOPROC = 0x70000000L
PT_HIPROC = 0x7fffffffL
#segment flags
PF_R = 0x4 #segment is readable
PF_W = 0x2 #segment is writable
PF_X = 0x1 #segment is executable
def __init__(self):
"""create a new, empty segment/program header"""
(self.p_type, self.p_offset, self.p_vaddr, self.p_paddr,
self.p_filesz, self.p_memsz, self.p_flags, self.p_align) = [0]*8
self.data = None
def fromString(self, s):
"""parse header info from string"""
(self.p_type, self.p_offset, self.p_vaddr, self.p_paddr,
self.p_filesz, self.p_memsz, self.p_flags,
self.p_align) = struct.unpack(self.Elf32_Phdr, s)
def __str__(self):
"""pretty print for debug..."""
return "%s(p_type=%s, p_offset=0x%04x, p_vaddr=0x%04x, p_paddr=0x%04x, "\
"p_filesz=%s, p_memsz=%s, p_flags=%s, "\
"p_align=%s)" % (
self.__class__.__name__,
self.p_type, self.p_offset, self.p_vaddr, self.p_paddr,
self.p_filesz, self.p_memsz, self.p_flags,
self.p_align)
class ELFObject:
"""Object to read and handle an LEF object file"""
#header information
Elf32_Ehdr = "<16sHHIIIIIHHHHHH"
#offsets within e_ident
EI_MAG0 = 0 #File identification
EI_MAG1 = 1 #File identification
EI_MAG2 = 2 #File identification
EI_MAG3 = 3 #File identification
EI_CLASS = 4 #File class
EI_DATA = 5 #Data encoding
EI_VERSION = 6 #File version
EI_PAD = 7 #Start of padding bytes
EI_NIDENT = 16 #Size of e_ident[]
#elf file type flags
ET_NONE = 0 #No file type
ET_REL = 1 #Relocatable file
ET_EXEC = 2 #Executable file
ET_DYN = 3 #Shared object file
ET_CORE = 4 #Core file
ET_LOPROC = 0xff00 #Processor-specific
ET_HIPROC = 0xffff #Processor-specific
#ELF format
ELFCLASSNONE = 0 #Invalid class
ELFCLASS32 = 1 #32-bit objects
ELFCLASS64 = 2 #64-bit objects
#encoding
ELFDATANONE = 0 #Invalid data encoding
ELFDATA2LSB = 1 #See below
ELFDATA2MSB = 2 #See below
def __init__(self):
"""create a new elf object"""
(self.e_ident, self.e_type, self.e_machine, self.e_version,
self.e_entry, self.e_phoff, self.e_shoff,
self.e_flags, self.e_ehsize, self.e_phentsize, self.e_phnum,
self.e_shentsize, self.e_shnum, self.e_shstrndx) = [0]*14
def fromFile(self, fileobj):
"""read all relevant data from fileobj.
the file must be seekable"""
#get file header
(self.e_ident, self.e_type, self.e_machine, self.e_version,
self.e_entry, self.e_phoff, self.e_shoff,
self.e_flags, self.e_ehsize, self.e_phentsize, self.e_phnum,
self.e_shentsize, self.e_shnum, self.e_shstrndx) = struct.unpack(
self.Elf32_Ehdr, fileobj.read(struct.calcsize(self.Elf32_Ehdr)))
#verify if its a known format and realy an ELF file
if self.e_ident[0:4] != '\x7fELF' and\
self.e_ident[self.EI_CLASS] != self.ELFCLASS32 and\
self.e_ident[self.EI_DATA] != self.ELFDATA2LSB and\
self.e_ident[self.EI_VERSION] != 1:
raise ELFException("Not a valid ELF file")
#load programm headers
self.programmheaders = []
if self.e_phnum:
#load program headers
fileobj.seek(self.e_phoff)
for sectionnum in range(self.e_phnum):
shdr = (fileobj.read(self.e_phentsize) + '\0'* struct.calcsize(ELFProgramHeader.Elf32_Phdr))[0:struct.calcsize(ELFProgramHeader.Elf32_Phdr)]
psection = ELFProgramHeader()
psection.fromString(shdr)
if psection.p_offset: #skip if section has invalid offset in file
self.programmheaders.append(psection)
#~ #get the segment data from the file for each prg header
#~ for phdr in self.programmheaders:
#~ fileobj.seek(phdr.p_offset)
#~ phdr.data = fileobj.read(phdr.p_filesz)
#~ #pad if needed
#~ if phdr.p_filesz < phdr.p_memsz:
#~ phdr.data = phdr.data + '\0' * (phdr.p_memsz-phdr.p_filesz)
#load sections
self.sections = []
fileobj.seek(self.e_shoff)
for sectionnum in range(self.e_shnum):
shdr = (fileobj.read(self.e_shentsize) + '\0'* struct.calcsize(ELFSection.Elf32_Shdr))[0:struct.calcsize(ELFSection.Elf32_Shdr)]
elfsection = ELFSection()
elfsection.fromString(shdr)
self.sections.append(elfsection)
#load data for all sections
for section in self.sections:
fileobj.seek(section.sh_offset)
data = fileobj.read(section.sh_size)
section.data = data
if section.sh_type == ELFSection.SHT_STRTAB:
section.values = data.split('\0')
section.lma = self.getLMA(section)
#get section names
for section in self.sections:
start = self.sections[self.e_shstrndx].data[section.sh_name:]
section.name = start.split('\0')[0]
def getSection(self, name):
"""get section by name"""
for section in self.sections:
if section.name == '.text':
return section
def getProgrammableSections(self):
"""get all program headers that are marked as executable and
have suitable attributes to be code"""
res = []
for p in self.programmheaders:
#~ print p
#~ if section.sh_flags & self.SHF_ALLOC and section.name not in ('.data', '.data1', '.bss'):
#~ if p.p_type == ELFProgramHeader.PT_LOAD:# and p.p_paddr == p.p_vaddr and p.p_flags & ELFProgramHeader.PF_X:
if p.p_type == ELFProgramHeader.PT_LOAD:
res.append(p)
return res
def getLMA(self, section):
#magic load memory address calculation ;-)
for p in self.programmheaders:
if (p.p_paddr != 0 and \
p.p_type == ELFProgramHeader.PT_LOAD and \
p.p_vaddr != p.p_paddr and \
p.p_vaddr <= section.sh_addr and \
(p.p_vaddr + p.p_memsz >= section.sh_addr + section.sh_size) \
and (not (section.sh_flags & ELFSection.SHF_ALLOC and section.sh_type != ELFSection.SHT_NOBITS) \
or (p.p_offset <= section.sh_offset \
and (p.p_offset + p.p_filesz >= section.sh_offset + section.sh_size)))):
return section.sh_addr + p.p_paddr - p.p_vaddr
return section.sh_addr
def getSections(self):
"""get sections relevant for the application"""
res = []
for section in self.sections:
if section.sh_flags & ELFSection.SHF_ALLOC and section.sh_type != ELFSection.SHT_NOBITS:
res.append(section)
return res
def __str__(self):
"""pretty print for debug..."""
return "%s(self.e_type=%r, self.e_machine=%r, self.e_version=%r, sections=%r)" % (
self.__class__.__name__,
self.e_type, self.e_machine, self.e_version,
[section.name for section in self.sections])
if __name__ == '__main__':
print "This is only a module test!"
elf = ELFObject()
elf.fromFile(open("test.elf"))
if elf.e_type != ELFObject.ET_EXEC:
raise Exception("No executable")
print elf
#~ print repr(elf.getSection('.text').data)
#~ print [(s.name, hex(s.sh_addr)) for s in elf.getSections()]
print "-"*20
for p in elf.sections: print p
print "-"*20
for p in elf.getSections(): print p
print "-"*20
for p in elf.getProgrammableSections(): print p

View file

@ -1,49 +0,0 @@
#!/usr/bin/env python
"""Test File generator.
This tool generates a hex file, of given size, ending on address
0xffff.
USAGE: hen-ihex.py size_in_kilobyte
The resulting Intel-hex file is output to stdout, use redirection
to save the data to a file.
"""
#return a string with data in intel hex format
def makeihex(address, data):
out = []
start = 0
while start<len(data):
end = start + 16
if end > len(data): end = len(data)
out.append(_ihexline(address, [ord(x) for x in data[start:end]]))
start += 16
address += 16
out.append(_ihexline(address, [], end=1)) #append no data but an end line
return ''.join(out)
def _ihexline(address, buffer, end=0):
out = []
if end:
type = 1
else:
type = 0
out.append( ':%02X%04X%02X' % (len(buffer),address&0xffff,type) )
sum = len(buffer) + ((address>>8)&255) + (address&255)
for b in buffer:
if b == None: b = 0 #substitute nonexistent values with zero
out.append('%02X' % (b&255) )
sum += b&255
out.append('%02X\n' %( (-sum)&255))
return ''.join(out)
if __name__ == '__main__':
import struct, sys
if len(sys.argv) != 2:
print __doc__
sys.exit(1)
size = int(sys.argv[1]) #in kilo
startadr = 0x10000 - 1024*size
data = ''.join([struct.pack(">H", x) for x in range(startadr, startadr+ 1024*size, 2)])
print makeihex(startadr, data)

View file

@ -1,108 +0,0 @@
Name "install-pyjtag"
OutFile "install-pyjtag.exe"
!define SF_SELECTED 1
!define SF_SUBSEC 2
!define SF_SUBSECEND 4
!define SF_BOLD 8
!define SF_RO 16
!define SF_EXPAND 32
!define SECTION_OFF 0xFFFFFFFE
LicenseText License
LicenseData license.txt
SetOverwrite on
SetDateSave on
; The default installation directory
InstallDir $PROGRAMFILES\mspgcc
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM SOFTWARE\mspgcc "rootdir"
; The text to prompt the user to enter a directory
DirText "This will install the pyjtag executables. You can choose the same \
directory as for the other mspgcc tools."
; The text to prompt the user to enter a directory
ComponentText "Select which optional things you want installed."
Section "msp430-jtag (required)"
SectionIn RO
SetOutPath $INSTDIR
File /r bin
File /oname=license-pyjtag.txt license.txt
File /oname=readme-pyjtag.txt readme.txt
File /oname=bin\jtag.py jtag.py
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\mspgcc "rootdir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\mspgcc-pyjtag" "DisplayName" "mspgcc pyjtag (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\mspgcc-pyjtag" "UninstallString" '"$INSTDIR\uninstall-pyjtag.exe"'
WriteUninstaller "uninstall-pyjtag.exe"
SectionEnd
Section "giveio (needed on Win NT/2k/XP, but NOT on 9x/ME)"
SetOutPath $INSTDIR\bin
File ..\jtag\hardware_access\giveio\giveio.sys
File ..\jtag\hardware_access\giveio\loaddrv.exe
SetOutPath $INSTDIR
nsExec::ExecToLog '$INSTDIR\bin\loaddrv.exe install giveio $INSTDIR\bin\giveio.sys'
Pop $0 ;return value/error/timeout
IntCmp $0 2 ext_here ;assume its alredy installed
IntCmp $0 0 0 ext_err ext_err ;if not 0 -> error
nsExec::ExecToLog '$INSTDIR\bin\loaddrv.exe start giveio'
Pop $0 ;return value/error/timeout
IntCmp $0 0 0 ext_err ext_err ;if not 0 -> error
nsExec::ExecToLog '$INSTDIR\bin\loaddrv.exe starttype giveio auto'
Pop $0 ;return value/error/timeout
IntCmp $0 0 0 ext_err ext_err ;if not 0 -> error
WriteRegStr HKLM SOFTWARE\mspgcc "giveio" "started"
Goto ext_ok
ext_err:
DetailPrint "Error while installing and starting giveio"
MessageBox MB_OK|MB_ICONSTOP "Error while installing and starting giveio"
Goto ext_ok
ext_here:
DetailPrint "Installing giveio gave an error, assuming its already installed"
ext_ok:
SectionEnd
; special uninstall section.
Section "Uninstall"
; remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\mspgcc-pyjtag"
DeleteRegKey HKLM SOFTWARE\NSIS_Example2
; remove files
Delete $INSTDIR\bin\msp430-jtag.exe
Delete $INSTDIR\bin\_parjtag.pyd
Delete $INSTDIR\bin\jtag.py
Delete $INSTDIR\bin\HIL.dll
Delete $INSTDIR\bin\MSP430mspgcc.dll
;XXX python22.dll is left installed as it is used by pybsl and other tools
Delete $INSTDIR\license-pyjtag.txt
Delete $INSTDIR\readme-pyjtag.txt
; giveio
; if it was started by us, stop it
ReadRegStr $0 HKLM SOFTWARE\mspgcc "giveio"
StrCmp $0 '' no_giveio
nsExec::ExecToLog '$INSTDIR\bin\loaddrv.exe stop giveio'
Pop $0 ;return value/error/timeout
IntCmp $0 0 0 giveio_err giveio_err ;if not 0 -> error
nsExec::ExecToLog '$INSTDIR\bin\loaddrv.exe remove giveio'
Pop $0 ;return value/error/timeout
IntCmp $0 0 0 giveio_err giveio_err ;if not 0 -> error
Goto no_giveio
giveio_err:
DetailPrint "Error while uninstalling giveio service"
MessageBox MB_OK|MB_ICONSTOP "Error while uninstalling giveio service"
no_giveio:
Delete loaddrv.exe
Delete giveio.sys
; MUST REMOVE UNINSTALLER, too
Delete $INSTDIR\uninstall-pyjtag.exe
SectionEnd

View file

@ -1,604 +0,0 @@
#!/usr/bin/env python
#Parallel JTAG programmer for the MSP430 embedded proccessor.
#
#(C) 2002 Chris Liechti <cliechti@gmx.net>
#this is distributed under a free software license, see license.txt
#
#Requires Python 2+ and the binary extension _parjtag.
import sys
import _parjtag
VERSION = "1.3"
DEBUG = 0 #disable debug messages by default
#frame specific consts
ERASE_MASS = 2
ERASE_MAIN = 1
ERASE_SGMT = 0
#states
FREERUNNING = 0
STOPPED = 1
#Configurations of the MSP430 driver
VERIFICATION_MODE = 0 #Verify data downloaded to FLASH memories.
RAMSIZE_OPTION = 1 #Change RAM used to download and program flash blocks
DEBUG_OPTION = 2 #Set debug level. Enables debug outputs.
#enumeration of output formats for uploads
HEX = 0
INTELHEX = 1
BINARY = 2
#exceptions
class JTAGException(Exception): pass
#for the use with memread
def hexdump( (adr, memstr) ):
"""Print a hex dump of data collected with memread
arg1: tuple with adress, memory
return None"""
count = 0
ascii = ''
for value in map(ord, memstr):
if not count: print "%04x: " % adr,
print "%02x" % value,
ascii += (32 <= value < 128) and chr(value) or '.'
count += 1
adr += 1
if count == 16:
count = 0
print " ", ascii
ascii = ''
if count < 16: print " "*(16-count), " ", ascii
def makeihex( (address, data) ):
"""work though the data and output lines in inzel hex format.
and end tag is appended"""
start = 0
while start<len(data):
end = start + 16
if end > len(data): end = len(data)
_ihexline(address, [ord(x) for x in data[start:end]])
start += 16
address += 16
_ihexline(address, [], type=1) #append no data but an end line
def _ihexline(address, buffer, type=0):
"""encode one line, output with checksum"""
sys.stdout.write( ':%02X%04X%02X' % (len(buffer), address & 0xffff, type) )
sum = len(buffer) + ((address >> 8) & 255) + (address & 255)
for b in buffer:
if b == None: b = 0 #substitute nonexistent values with zero
sys.stdout.write('%02X' % (b & 255))
sum += b&255
sys.stdout.write('%02X\n' %( (-sum) & 255))
class Segment:
"""store a string with memory contents along with its startaddress"""
def __init__(self, startaddress = 0, data=None):
if data is None:
self.data = ''
else:
self.data = data
self.startaddress = startaddress
def __getitem__(self, index):
return self.data[index]
def __len__(self):
return len(self.data)
def __repr__(self):
return "Segment(startaddress = 0x%04x, data=%r)" % (self.startaddress, self.data)
class Memory:
"""represent memory contents. with functions to load files"""
def __init__(self, filename=None):
self.segments = []
if filename:
self.filename = filename
self.loadFile(filename)
def append(self, seg):
self.segments.append(seg)
def __getitem__(self, index):
return self.segments[index]
def __len__(self):
return len(self.segments)
def loadIHex(self, file):
"""load data from a (opened) file in Intel-HEX format"""
segmentdata = []
currentAddr = 0
startAddr = 0
lines = file.readlines()
for l in lines:
if not l.strip(): continue #skip empty lines
if l[0] != ':': raise Exception("File Format Error\n")
l = l.strip() #fix CR-LF issues...
length = int(l[1:3],16)
address = int(l[3:7],16)
type = int(l[7:9],16)
check = int(l[-2:],16)
if type == 0x00:
if currentAddr != address:
if segmentdata:
self.segments.append( Segment(startAddr, ''.join(segmentdata)) )
startAddr = currentAddr = address
segmentdata = []
for i in range(length):
segmentdata.append( chr(int(l[9+2*i:11+2*i],16)) )
currentAddr = length + currentAddr
elif type == 0x01:
pass
else:
sys.stderr.write("Ignored unknown field (type 0x%02x) in ihex file.\n" % type)
if segmentdata:
self.segments.append( Segment(startAddr, ''.join(segmentdata)) )
def loadTIText(self, file):
"""load data from a (opened) file in TI-Text format"""
next = 1
currentAddr = 0
startAddr = 0
segmentdata = []
#Convert data for MSP430, TXT-File is parsed line by line
while next >= 1:
#Read one line
l = file.readline()
if not l: break #EOF
l = l.strip()
if l[0] == 'q': break
elif l[0] == '@': #if @ => new address => send frame and set new addr.
#create a new segment
if segmentdata:
self.segments.append( Segment(startAddr, ''.join(segmentdata)) )
startAddr = currentAddr = int(l[1:],16)
segmentdata = []
else:
for i in l.split():
segmentdata.append(chr(int(i,16)))
if segmentdata:
self.segments.append( Segment(startAddr, ''.join(segmentdata)) )
def loadELF(self, file):
"""load data from a (opened) file in ELF object format.
File must be seekable"""
import elf
obj = elf.ELFObject()
obj.fromFile(file)
if obj.e_type != elf.ELFObject.ET_EXEC:
raise Exception("No executable")
for section in obj.getSections():
if DEBUG:
sys.stderr.write("ELF section %s at 0x%04x %d bytes\n" % (section.name, section.lma, len(section.data)))
if len(section.data):
self.segments.append( Segment(section.lma, section.data) )
def loadFile(self, filename):
"""fill memory with the contents of a file. file type is determined from extension"""
#TODO: do a contents based detection
if filename[-4:].lower() == '.txt':
self.loadTIText(open(filename, "rb"))
elif filename[-4:].lower() in ('.a43', '.hex'):
self.loadIHex(open(filename, "rb"))
else:
self.loadELF(open(filename, "rb"))
def getMemrange(self, fromadr, toadr):
"""get a range of bytes from the memory. unavailable values are filled with 0xff."""
res = ''
toadr = toadr + 1 #python indxes are excluding end, so include it
while fromadr < toadr:
for seg in self.segments:
segend = seg.startaddress + len(seg.data)
if seg.startaddress <= fromadr and fromadr < segend:
if toadr > segend: #not all data in segment
catchlength = segend-fromadr
else:
catchlength = toadr-fromadr
res = res + seg.data[fromadr-seg.startaddress : fromadr-seg.startaddress+catchlength]
fromadr = fromadr + catchlength #adjust start
if len(res) >= toadr-fromadr:
break #return res
else: #undefined memory is filled with 0xff
res = res + chr(255)
fromadr = fromadr + 1 #adjust start
return res
class JTAG:
"""wrap the _parjtag extension"""
def __init__(self):
self.showprogess = 0
def connect(self, lpt=None):
"""connect to specified or default port"""
if lpt is None:
_parjtag.connect()
else:
_parjtag.connect(lpt)
def close(self):
"""release JTAG"""
_parjtag.release()
def uploadData(self, startaddress, size):
"""upload a datablock"""
if DEBUG > 1: sys.stderr.write("* uploadData()\n")
return _parjtag.memread(startaddress, size)
def actionMassErase(self):
"""Erase the flash memory completely (with mass erase command)"""
sys.stderr.write("Mass Erase...\n")
_parjtag.memerase(ERASE_MASS)
def actionMainErase(self):
"""Erase the MAIN flash memory, leave the INFO mem"""
sys.stderr.write("Erase Main Flash...\n")
_parjtag.memerase(ERASE_MAIN, 0xfffe)
def makeActionSegmentErase(self, address):
"""Selective segment erase"""
class SegmentEraser:
def __init__(self, segaddr):
self.address = segaddr
def __call__(self):
sys.stderr.write("Erase Segment @ 0x%04x...\n" % self.address)
_parjtag.memerase(ERASE_SGMT, self.address)
return SegmentEraser(address)
def actionEraseCheck(self):
"""check the erasure of required flash cells."""
sys.stderr.write("Erase Check by file ...\n")
if self.data is not None:
for seg in self.data:
data = _parjtag.memread(seg.startaddress, len(seg.data))
if data != '\xff'*len(seg.data): raise JTAGException("Erase check failed")
else:
raise JTAGException("cannot do erase check against data with not knowing the actual data")
def progess_update(self, count, total):
sys.stderr.write("\r%d%%" % (100*count/total))
def actionProgram(self):
"""program data into flash memory."""
if self.data is not None:
sys.stderr.write("Program ...\n")
if self.showprogess:
_parjtag.set_flash_callback(self.progess_update)
bytes = 0
for seg in self.data:
_parjtag.memwrite(seg.startaddress, seg.data)
bytes += len(seg.data)
if self.showprogess:
sys.stderr.write("\r")
sys.stderr.write("%i bytes programmed.\n" % bytes)
else:
raise JTAGException("programming without data not possible")
def actionVerify(self):
"""Verify programmed data"""
if self.data is not None:
sys.stderr.write("Verify ...\n")
for seg in self.data:
data = _parjtag.memread(seg.startaddress, len(seg.data))
if data != seg.data: raise JTAGException("Verify failed")
else:
raise JTAGException("verify without data not possible")
def actionReset(self):
"""perform a reset"""
sys.stderr.write("Reset device ...\n")
_parjtag.reset(0, 0)
def actionRun(self, address):
"""start program at specified address"""
raise NotImplementedError
#sys.stderr.write("Load PC with 0x%04x ...\n" % address)
def funclet(self):
"""download and start funclet"""
sys.stderr.write("Download and execute of funclet...\n")
if len(self.data) > 1:
raise JTAGException("don't know how to handle multiple segments in funclets")
_parjtag.funclet(self.data[0].data)
sys.stderr.write("Funclet OK.\n")
def usage():
"""print some help message"""
sys.stderr.write("""
USAGE: %s [options] [file]
Version: %s
If "-" is specified as file the data is read from the stdinput.
A file ending with ".txt" is considered to be in TIText format all
other filenames are considered IntelHex.
General options:
-h, --help Show this help screen.
-l, --lpt=name Specify an other parallel port.
(defaults to LPT1 (/dev/parport0 on unix)
-D, --debug Increase level of debug messages. This won't be
very useful for the average user...
-I, --intelhex Force fileformat to IntelHex
-T, --titext Force fileformat to be TIText
-f, --funclet The given file is a funclet (a small program to
be run in RAM)
-R, --ramsize Specify the amont of RAM to be used to program
flash (default 256).
Program Flow Specifiers:
-e, --masserase Mass Erase (clear all flash memory)
-m, --mainerase Erase main flash memory only
--eraseinfo Erase info flash memory only (0x1000-0x10ff)
--erase=address Selectively erase segment at the specified address
-E, --erasecheck Erase Check by file
-p, --program Program file
-v, --verify Verify by file
The order of the above options matters! The table is ordered by normal
execution order. For the options "Epv" a file must be specified.
Program flow specifiers default to "p" if a file is given.
Don't forget to specify "e" or "eE" when programming flash!
"p" already verifies the programmed data, "v" adds an additional
verification though uploading the written data for a 1:1 compare.
No default action is taken if "p" and/or "v" is given, say specifying
only "v" does a check by file of a programmed device.
Data retreiving:
-u, --upload=addr Upload a datablock (see also: -s).
-s, --size=num Size of the data block do upload. (Default is 2)
-x, --hex Show a hexadecimal display of the uploaded data.
(Default)
-b, --bin Get binary uploaded data. This can be used
to redirect the output into a file.
-i, --ihex Uploaded data is output in Intel HEX format.
This can be used to clone a device.
Do before exit:
-g, --go=address Start programm execution at specified address.
This implies option "w" (wait)
-r, --reset Reset connected MSP430. Starts application.
This is a normal device reset and will start
the programm that is specified in the reset
interrupt vector. (see also -g)
-w, --wait Wait for <ENTER> before closing parallel port.
""" % (sys.argv[0], VERSION))
def main():
global DEBUG
import getopt
filetype = None
filename = None
reset = 0
wait = 0
goaddr = None
jtag = JTAG()
toinit = []
todo = []
startaddr = None
size = 2
outputformat= HEX
lpt = None
funclet = None
ramsize = None
sys.stderr.write("MSP430 parallel JTAG programmer Version: %s\n" % VERSION)
try:
opts, args = getopt.getopt(sys.argv[1:],
"hl:weEmpvrg:Du:d:s:xbiITfR:S",
["help", "lpt=", "wait"
"masserase", "erasecheck", "mainerase", "program",
"erase=", "eraseinfo",
"verify", "reset", "go=", "debug",
"upload=", "download=", "size=", "hex", "bin", "ihex",
"intelhex", "titext", "funclet", "ramsize=", "progress"]
)
except getopt.GetoptError:
# print help information and exit:
usage()
sys.exit(2)
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-l", "--lpt"):
lpt = a
elif o in ("-w", "--wait"):
wait = 1
elif o in ("-e", "--masserase"):
toinit.append(jtag.actionMassErase) #Erase Flash
elif o in ("-E", "--erasecheck"):
toinit.append(jtag.actionEraseCheck) #Erase Check (by file)
elif o in ("-m", "--mainerase"):
toinit.append(jtag.actionMainErase) #Erase main Flash
elif o == "--erase":
try:
seg = int(a, 0)
toinit.append(jtag.makeActionSegmentErase(seg))
except ValueError:
sys.stderr.write("segment address must be a valid number in dec, hex or octal\n")
sys.exit(2)
elif o == "--eraseinfo":
toinit.append(jtag.makeActionSegmentErase(0x1000))
toinit.append(jtag.makeActionSegmentErase(0x1080))
elif o in ("-p", "--program"):
todo.append(jtag.actionProgram) #Program file
elif o in ("-v", "--verify"):
todo.append(jtag.actionVerify) #Verify file
elif o in ("-r", "--reset"):
reset = 1
elif o in ("-g", "--go"):
try:
goaddr = int(a, 0) #try to convert decimal
except ValueError:
sys.stderr.write("upload address must be a valid number in dec, hex or octal\n")
sys.exit(2)
elif o in ("-D", "--debug"):
DEBUG = DEBUG + 1
elif o in ("-u", "--upload"):
try:
startaddr = int(a, 0) #try to convert number of any base
except ValueError:
sys.stderr.write("upload address must be a valid number in dec, hex or octal\n")
sys.exit(2)
elif o in ("-s", "--size"):
try:
size = int(a, 0)
except ValueError:
sys.stderr.write("upload address must be a valid number in dec, hex or octal\n")
sys.exit(2)
#outut formats
elif o in ("-x", "--hex"):
outputformat = HEX
elif o in ("-b", "--bin"):
outputformat = BINARY
elif o in ("-i", "--ihex"):
outputformat = INTELHEX
#input formats
elif o in ("-I", "--intelhex"):
filetype = 0
elif o in ("-T", "--titext"):
filetype = 1
#others
elif o in ("-f", "--funclet"):
funclet = 1
elif o in ("-R", "--ramsize"):
try:
ramsize = int(a, 0)
except ValueError:
sys.stderr.write("ramsize must be a valid number in dec, hex or octal\n")
sys.exit(2)
elif o in ("-S", "--progress"):
jtag.showprogess = 1
if len(args) == 0:
sys.stderr.write("Use -h for help\n")
elif len(args) == 1: #a filename is given
if not funclet:
if not todo: #if there are no actions yet
todo.extend([ #add some useful actions...
jtag.actionProgram,
])
filename = args[0]
else: #number of args is wrong
usage()
sys.exit(2)
if DEBUG: #debug infos
sys.stderr.write("debug level set to %d\n" % DEBUG)
_parjtag.configure(DEBUG_OPTION, DEBUG)
sys.stderr.write("python version: %s\n" % sys.version)
#sanity check of options
if goaddr and reset:
sys.stderr.write("Warning: option --reset ignored as --go is specified!\n")
reset = 0
if startaddr and reset:
sys.stderr.write("Warning: option --reset ignored as --upload is specified!\n")
reset = 0
#prepare data to download
jtag.data = Memory() #prepare downloaded data
if filetype is not None: #if the filetype is given...
if filename is None:
raise ValueError("no filename but filetype specified")
if filename == '-': #get data from stdin
file = sys.stdin
else:
file = open(filename,"rb") #or from a file
if filetype == 0: #select load function
jtag.data.loadIHex(file) #intel hex
elif filetype == 1:
jtag.data.loadTIText(file) #TI's format
else:
raise ValueError("illegal filetype specified")
else: #no filetype given...
if filename == '-': #for stdin:
jtag.data.loadIHex(sys.stdin) #assume intel hex
elif filename:
jtag.data.loadFile(filename) #autodetect otherwise
if DEBUG > 5: sys.stderr.write("File: %r\n" % filename)
try:
jtag.connect(lpt) #try to open port
except IOError:
raise #do not handle here
else: #continue if open was successful
if ramsize is not None:
_parjtag.configure(RAMSIZE_OPTION, ramsize)
#initialization list
if toinit: #erase and erase check
if DEBUG: sys.stderr.write("Preparing device ...\n")
for f in toinit: f()
#work list
if todo:
if DEBUG > 0: #debug
#show a nice list of sheduled actions
sys.stderr.write("TODO list:\n")
for f in todo:
try:
sys.stderr.write(" %s\n" % f.func_name)
except AttributeError:
sys.stderr.write(" %r\n" % f)
for f in todo: f() #work through todo list
if reset: #reset device first if desired
jtag.actionReset()
if funclet is not None: #download and start funclet
jtag.funclet()
if goaddr is not None: #start user programm at specified address
jtag.actionRun(goaddr) #load PC and execute
#upload datablock and output
if startaddr is not None:
if goaddr: #if a program was started...
raise NotImplementedError
#TODO:
#sys.stderr.write("Waiting to device for reconnect for upload: ")
data = jtag.uploadData(startaddr, size) #upload data
if outputformat == HEX: #depending on output format
hexdump( (startaddr, data) ) #print a hex display
elif outputformat == INTELHEX:
makeihex( (startaddr, data) ) #ouput a intel-hex file
else:
sys.stdout.write(data) #binary output w/o newline!
wait = 0 #wait makes no sense as after the upload the device is still stopped
if wait: #wait at the end if desired
sys.stderr.write("Press <ENTER> ...\n") #display a prompt
raw_input() #wait for newline
_parjtag.reset(1, 1) #reset and release target
#~ jtag.actionReset()
jtag.close() #Release communication port
if __name__ == '__main__':
try:
main()
except SystemExit:
raise #let pass exit() calls
except KeyboardInterrupt:
if DEBUG: raise #show full trace in debug mode
sys.stderr.write("user abort.\n") #short messy in user mode
sys.exit(1) #set errorlevel for script usage
except Exception, msg: #every Exception is caught and displayed
if DEBUG: raise #show full trace in debug mode
sys.stderr.write("\nAn error occoured:\n%s\n" % msg) #short messy in user mode
sys.exit(1) #set errorlevel for script usage

Some files were not shown because too many files have changed in this diff Show more