Import of files for the Tmote sky platform.
This commit is contained in:
parent
87b0aa552a
commit
7b791de692
116
platform/sky/Makefile
Normal file
116
platform/sky/Makefile
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
# $Id: Makefile,v 1.1 2006/08/02 14:44:46 bg- Exp $
|
||||||
|
#
|
||||||
|
# This makefile requires GNU make!
|
||||||
|
|
||||||
|
LIB = libcontiki.a
|
||||||
|
KERNELS = gateway.ihex dhclient.ihex
|
||||||
|
PROGS = loadable_prg.ko udpsend.ko udprecv.ko
|
||||||
|
TOOLS = tunslip scat codeprop
|
||||||
|
|
||||||
|
all: $(LIB) $(KERNELS) $(PROGS) $(TOOLS)
|
||||||
|
|
||||||
|
gateway.out: gateway.o $(LIB)
|
||||||
|
dhclient.out: dhclient.o $(LIB)
|
||||||
|
|
||||||
|
CORE = ../../core
|
||||||
|
INCDIRS = -I. -I../../cpu/msp430 -I$(CORE) -I../../apps
|
||||||
|
SRCDIRS = dev ../../cpu/msp430 ${addprefix $(CORE)/,sys dev net lib loader} ../../apps/codeprop
|
||||||
|
|
||||||
|
MCU=msp430x1611
|
||||||
|
|
||||||
|
ARCH=msp430.o leds.o leds-arch.o watchdog.o lpm.o light.o button.o spi.o ds2411.o rom.o xmem.o
|
||||||
|
SYSTEM=process.o procinit.o service.o clock.o etimer.o timer.o \
|
||||||
|
elfloader.o symtab.o
|
||||||
|
UIP=uip.o uiplib.o tcpip.o uip-fw.o uip-fw-service.o uipbuf.o \
|
||||||
|
tcpdump.o psock.o dhcpc.o uaodv.o uaodv-rt.o
|
||||||
|
UIPDRIVERS=slip.o slip_uart1.o \
|
||||||
|
cc2420.o cc2420_uart0.o cc2420_send_ip.o cc2420_send_uaodv.o
|
||||||
|
LIBS=memb.o list.o malloc.o realloc.o malloc_compact.o rand.o crtk.o
|
||||||
|
SYSAPPS=tcp_loader.o
|
||||||
|
LIBFILES=$(SYSTEM) $(ARCH) $(UIP) $(UIPDRIVERS) $(LIBS) $(SYSAPPS)
|
||||||
|
|
||||||
|
CP=cp
|
||||||
|
LIBC=-lgcc -lc -lgcc
|
||||||
|
CC=msp430-gcc
|
||||||
|
LD=msp430-ld
|
||||||
|
AS=msp430-as
|
||||||
|
OBJCOPY=msp430-objcopy
|
||||||
|
STRIP=msp430-strip
|
||||||
|
AR=msp430-ar
|
||||||
|
RANLIB=msp430-ranlib
|
||||||
|
BSL=msp430-bsl
|
||||||
|
CFLAGS=-mmcu=$(MCU) $(INCDIRS) -Wall -Os
|
||||||
|
LDFLAGS=-mmcu=$(MCU)
|
||||||
|
|
||||||
|
# Setup directory search path for source files
|
||||||
|
vpath %.c $(SRCDIRS) ${filter-out CVS,${wildcard labs/*}}
|
||||||
|
|
||||||
|
# Set COM port if not already set.
|
||||||
|
# DOS: 1 => COM2, 2 => COM3, etc.
|
||||||
|
# Linux: /dev/ttyUSB0, /dev/ttyUSB1, etc.
|
||||||
|
# FreeBSD: /dev/ttyU0, /dev/ttyU1, etc.
|
||||||
|
ifndef COMPORT
|
||||||
|
COMPORT := /dev/ttyUSB0
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $(notdir $(<:.c=.o))
|
||||||
|
|
||||||
|
# Transform one .o to a .ko
|
||||||
|
%.ko: %.o
|
||||||
|
$(STRIP) -K _init -K _fini --strip-unneeded -g -x $< -o $@
|
||||||
|
|
||||||
|
# Combine several .o:s to one .ko
|
||||||
|
# The msp430-ld can't do incremental linking, bogus output
|
||||||
|
#%.ko %.o: $^
|
||||||
|
# /opt/msp430/bin/msp430-ld -r $< -o $@
|
||||||
|
# $(STRIP) -K _init -K _fini --strip-unneeded -g -x $@
|
||||||
|
|
||||||
|
%.ihex: %.out
|
||||||
|
$(OBJCOPY) $^ -O ihex $@
|
||||||
|
|
||||||
|
#%.out:
|
||||||
|
# $(if $^,$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^,$(error "NO TARGET $@"))
|
||||||
|
|
||||||
|
# Add a namelist to the kernel
|
||||||
|
%.out: $^
|
||||||
|
-test -f $@_nm.c || echo "unsigned symbols[1];" > $@_nm.c
|
||||||
|
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBC) $@_nm.c
|
||||||
|
../../tools/msp430-make-symbols $@ > $@_tmp.c && mv $@_tmp.c $@_nm.c
|
||||||
|
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBC) $@_nm.c
|
||||||
|
|
||||||
|
%.u: %.ihex
|
||||||
|
$(BSL) --telosb -D -c $(COMPORT) -r -e -I -p $<
|
||||||
|
|
||||||
|
$(LIB): $(LIBFILES)
|
||||||
|
$(AR) rcf $@ $^
|
||||||
|
$(RANLIB) $@
|
||||||
|
|
||||||
|
codeprop: ../../tools/codeprop.c
|
||||||
|
cc -g -Wall $< -o $@
|
||||||
|
|
||||||
|
tunslip: ../../tools/tunslip.c
|
||||||
|
cc -g -Wall $< -o $@
|
||||||
|
|
||||||
|
scat: ../../tools/scat.c
|
||||||
|
cc -g -Wall $< -o $@
|
||||||
|
|
||||||
|
### TEST ###
|
||||||
|
|
||||||
|
test.out: test.o $(LIB)
|
||||||
|
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^
|
||||||
|
|
||||||
|
depend: $(LIBFILES:.o=.c)
|
||||||
|
-$(CC) $(CCDEPFLAGS) -MM $(CFLAGS) $(INCDIRS) $^ *.c >Makefile.depend
|
||||||
|
|
||||||
|
tags: $(LIBFILES:.o=.c)
|
||||||
|
etags $^
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o *.ko *~ *.core *.out *.ihex *_nm.c
|
||||||
|
rm -f $(LIB) $(KERNELS) $(TOOLS)
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
|
||||||
|
-include Makefile.depend
|
160
platform/sky/contiki-conf.h
Normal file
160
platform/sky/contiki-conf.h
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
/* -*- C -*- */
|
||||||
|
/* @(#)$Id: contiki-conf.h,v 1.1 2006/08/02 14:44:46 bg- Exp $ */
|
||||||
|
|
||||||
|
#ifndef CONTIKI_CONF_H
|
||||||
|
#define CONTIKI_CONF_H
|
||||||
|
|
||||||
|
/* This is still experimental. /bg */
|
||||||
|
#define UAODV_BAD_ROUTE
|
||||||
|
|
||||||
|
/* Helper prototypes that should go somewhere. */
|
||||||
|
void splx_(int);
|
||||||
|
int splhigh_(void);
|
||||||
|
void msp430_cpu_init(void); /* Rename to cpu_init() later! */
|
||||||
|
|
||||||
|
#define cpu_init() msp430_cpu_init()
|
||||||
|
#define splhigh() splhigh_()
|
||||||
|
#define splx(sr) __asm__ __volatile__("bis %0, r2" : : "r" (sr))
|
||||||
|
|
||||||
|
#define TMOTE_SKY 1
|
||||||
|
#define WITH_UIP 1
|
||||||
|
#define WITH_ASCII 1
|
||||||
|
|
||||||
|
#define PROCESS_CONF_FASTPOLL 4
|
||||||
|
|
||||||
|
/* Our clock resolution, this is the same as Unix HZ. */
|
||||||
|
#define CLOCK_CONF_SECOND 64
|
||||||
|
|
||||||
|
#define UIP_CONF_DHCP_LIGHT
|
||||||
|
#define UIP_CONF_LLH_LEN 0
|
||||||
|
#define UIP_CONF_BUFFER_SIZE 116
|
||||||
|
#define UIP_CONF_RECEIVE_WINDOW (UIP_CONF_BUFFER_SIZE - 40)
|
||||||
|
#define UIP_CONF_MAX_CONNECTIONS 4
|
||||||
|
#define UIP_CONF_MAX_LISTENPORTS 8
|
||||||
|
#define UIP_CONF_UDP_CONNS 6
|
||||||
|
#define UIP_CONF_FWCACHE_SIZE 5
|
||||||
|
#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
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Definitions below are dictated by the hardware and not really
|
||||||
|
* changeable!
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* LED ports */
|
||||||
|
#define LEDS_PxDIR P5DIR
|
||||||
|
#define LEDS_PxOUT P5OUT
|
||||||
|
#define LEDS_CONF_RED 0x10
|
||||||
|
#define LEDS_CONF_GREEN 0x20
|
||||||
|
#define LEDS_CONF_YELLOW 0x40
|
||||||
|
|
||||||
|
/* Button sensors. */
|
||||||
|
#define IRQ_PORT2 0x02
|
||||||
|
|
||||||
|
/* Reserve 64 bytes (only) for the runtime stack. */
|
||||||
|
#define __malloc_heap_start ((char *)&__bss_end)
|
||||||
|
#define __malloc_heap_end (((char *)&__stack) - 64)
|
||||||
|
|
||||||
|
typedef unsigned char u8_t;
|
||||||
|
typedef unsigned short u16_t;
|
||||||
|
typedef unsigned long u32_t;
|
||||||
|
typedef unsigned short uip_stats_t;
|
||||||
|
typedef unsigned short clock_time_t;
|
||||||
|
|
||||||
|
typedef unsigned long off_t;
|
||||||
|
#define ROM_ERASE_UNIT_SIZE 512
|
||||||
|
#define XMEM_ERASE_UNIT_SIZE (64*1024L)
|
||||||
|
|
||||||
|
/* Use the first 64k of external flash for codeprop. */
|
||||||
|
#define EEPROMFS_ADDR_CODEPROP 0x00000
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SPI bus configuration for the TMote Sky.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* SPI input/output registers. */
|
||||||
|
#define SPI_TXBUF U0TXBUF
|
||||||
|
#define SPI_RXBUF U0RXBUF
|
||||||
|
|
||||||
|
/* USART0 Tx buffer ready? */
|
||||||
|
#define SPI_WAITFOREOTx() while ((U0TCTL & TXEPT) == 0)
|
||||||
|
/* USART0 Rx buffer ready? */
|
||||||
|
#define SPI_WAITFOREORx() while ((IFG1 & URXIFG0) == 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 FIFO_P 0 /* P1.0 - Input: FIFOP from CC2420 */
|
||||||
|
#define FIFO 3 /* P1.3 - Input: FIFO from CC2420 */
|
||||||
|
#define CCA 4 /* P1.4 - Input: CCA from CC2420 */
|
||||||
|
|
||||||
|
#define SFD 1 /* P4.1 - Input: SFD from CC2420 */
|
||||||
|
#define CSN 2 /* P4.2 - Output: SPI Chip Select (CS_N) */
|
||||||
|
#define VREG_EN 5 /* P4.5 - Output: VREG_EN to CC2420 */
|
||||||
|
#define RESET_N 6 /* P4.6 - Output: RESET_N to CC2420 */
|
||||||
|
|
||||||
|
/* Pin status. */
|
||||||
|
|
||||||
|
#define FIFO_IS_1 (!!(P1IN & BV(FIFO)))
|
||||||
|
#define CCA_IS_1 (!!(P1IN & BV(CCA) ))
|
||||||
|
#define RESET_IS_1 (!!(P4IN & BV(RESET_N)))
|
||||||
|
#define VREG_IS_1 (!!(P4IN & BV(VREG_EN)))
|
||||||
|
#define FIFOP_IS_1 (!!(P1IN & BV(FIFO_P)))
|
||||||
|
#define SFD_IS_1 (!!(P4IN & BV(SFD)))
|
||||||
|
|
||||||
|
/* The CC2420 reset pin. */
|
||||||
|
#define SET_RESET_INACTIVE() ( P4OUT |= BV(RESET_N) )
|
||||||
|
#define SET_RESET_ACTIVE() ( P4OUT &= ~BV(RESET_N) )
|
||||||
|
|
||||||
|
/* CC2420 voltage regulator enable pin. */
|
||||||
|
#define SET_VREG_ACTIVE() ( P4OUT |= BV(VREG_EN) )
|
||||||
|
#define SET_VREG_INACTIVE() ( P4OUT &= ~BV(VREG_EN) )
|
||||||
|
|
||||||
|
/* CC2420 rising edge trigger for external interrupt 0 (FIFOP). */
|
||||||
|
#define FIFOP_INT_INIT() do {\
|
||||||
|
P1IES &= ~BV(FIFO_P);\
|
||||||
|
CLEAR_FIFOP_INT();\
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* FIFOP on external interrupt 0. */
|
||||||
|
#define ENABLE_FIFOP_INT() do { P1IE |= BV(FIFO_P); } while (0)
|
||||||
|
#define DISABLE_FIFOP_INT() do { P1IE &= ~BV(FIFO_P); } while (0)
|
||||||
|
#define CLEAR_FIFOP_INT() do { P1IFG &= ~BV(FIFO_P); } while (0)
|
||||||
|
|
||||||
|
/* Enables/disables CC2420 access to the SPI bus (not the bus).
|
||||||
|
*
|
||||||
|
* These guys should really be renamed but are compatible with the
|
||||||
|
* original Chipcon naming.
|
||||||
|
*
|
||||||
|
* SPI_CC2420_ENABLE/SPI_CC2420_DISABLE???
|
||||||
|
* CC2420_ENABLE_SPI/CC2420_DISABLE_SPI???
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define SPI_ENABLE() ( P4OUT &= ~BV(CSN) ) /* ENABLE CSn (active low) */
|
||||||
|
#define SPI_DISABLE() ( P4OUT |= BV(CSN) ) /* DISABLE CSn (active low) */
|
||||||
|
|
||||||
|
#endif /* CONTIKI_CONF_H */
|
130
platform/sky/dev/light.c
Normal file
130
platform/sky/dev/light.c
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This file is part of the Contiki operating system.
|
||||||
|
*
|
||||||
|
* @(#)$Id: light.c,v 1.1 2006/08/02 14:44:46 bg- Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <io.h>
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "dev/light.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize periodic readings from the 2 photo diodes. The most
|
||||||
|
* recent readings will be stored in ADC internal registers/memory.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
sensors_light_init(void)
|
||||||
|
{
|
||||||
|
P6SEL |= 0x30;
|
||||||
|
P6DIR = 0xff;
|
||||||
|
P6OUT = 0x00;
|
||||||
|
|
||||||
|
/* Set up the ADC. */
|
||||||
|
ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC; // Setup ADC12, ref., sampling time
|
||||||
|
ADC12CTL1 = SHP + CONSEQ_3 + CSTARTADD_0; // Use sampling timer, repeat-sequenc-of-channels
|
||||||
|
|
||||||
|
ADC12MCTL0 = (INCH_4 + SREF_0); // photodiode 1 (P64)
|
||||||
|
ADC12MCTL1 = (INCH_5 + SREF_0); // photodiode 2 (P65)
|
||||||
|
|
||||||
|
ADC12CTL0 |= ADC12ON + REFON;
|
||||||
|
|
||||||
|
ADC12CTL0 |= ENC; // enable conversion
|
||||||
|
ADC12CTL0 |= ADC12SC; // sample & convert
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Photosynthetically Active Radiation. */
|
||||||
|
unsigned
|
||||||
|
sensors_light1(void)
|
||||||
|
{
|
||||||
|
return ADC12MEM0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Total Solar Radiation. */
|
||||||
|
unsigned
|
||||||
|
sensors_light2(void)
|
||||||
|
{
|
||||||
|
return ADC12MEM1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Most of this information taken from
|
||||||
|
* http://www.moteiv.com/community/Getting_Data_from_Tmote_Sky%27s_Sensors
|
||||||
|
*
|
||||||
|
* The Photosynthetically Active Radiation (PAR) sensor as well as the
|
||||||
|
* Total Solar Radiation (TSR) sensor uses the 2.5V reference voltage
|
||||||
|
* to produce the raw ADC value.
|
||||||
|
|
||||||
|
* The voltage across each sensor is:
|
||||||
|
*
|
||||||
|
* VsensorPAR = ADCValuePAR/4096 * Vref (1a)
|
||||||
|
* VsensorTSR = ADCValueTSR/4096 * Vref (1b)
|
||||||
|
* where Vref = 2.5V
|
||||||
|
*
|
||||||
|
* This voltage creates a current through a resistor R=100KOhm and this
|
||||||
|
* current has a linear relationship with the light intensity in Lux.
|
||||||
|
* IPAR = VsensorPAR / 100,000 (2a)
|
||||||
|
* ITSR = VsensorTSR / 100,000 (2b)
|
||||||
|
*
|
||||||
|
* S1087 (PAR) lx = 1e6 * IPAR * 1000 (3a)
|
||||||
|
* S1087-01 (TSR) lx = 1e5 * ITSR * 1000 (3b)
|
||||||
|
*
|
||||||
|
* lxPAR = 10e9 * ADCValuePAR *(1/4096)* Vref * 10e-5 or
|
||||||
|
* lxPAR = 3125* ADCvaluePAR / 512
|
||||||
|
* and
|
||||||
|
* lxTSR = 10e8 * ADCValueTSR *(1/4096)* Vref * 10e-5 or
|
||||||
|
* lxTSR = 625* ADCvalueTSR / 1024
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* Photosynthetically Active Radiation in Lux units. */
|
||||||
|
unsigned
|
||||||
|
sensors_light1_lux(void)
|
||||||
|
{
|
||||||
|
unsigned temp;
|
||||||
|
temp = (uint32_t)ADC12MEM0;
|
||||||
|
|
||||||
|
temp = (temp*3125)>> 9;
|
||||||
|
return (uint16_t)(temp & 0xFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Total Solar Radiation in Lux units. */
|
||||||
|
unsigned
|
||||||
|
sensors_light2_lux(void)
|
||||||
|
{
|
||||||
|
unsigned temp;
|
||||||
|
temp = (uint32_t)ADC12MEM1;
|
||||||
|
|
||||||
|
temp = (temp*625)>> 10;
|
||||||
|
return (uint16_t)(temp & 0xFFFF);
|
||||||
|
}
|
||||||
|
#endif
|
41
platform/sky/dev/light.h
Normal file
41
platform/sky/dev/light.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This file is part of the Contiki operating system.
|
||||||
|
*
|
||||||
|
* @(#)$Id: light.h,v 1.1 2006/08/02 14:44:46 bg- Exp $
|
||||||
|
*/
|
||||||
|
#ifndef __LIGHT_H__
|
||||||
|
#define __LIGHT_H__
|
||||||
|
|
||||||
|
void sensors_light_init(void);
|
||||||
|
|
||||||
|
unsigned sensors_light1(void);
|
||||||
|
unsigned sensors_light2(void);
|
||||||
|
|
||||||
|
#endif /* __LIGHT_H__ */
|
243
platform/sky/dev/xmem.c
Normal file
243
platform/sky/dev/xmem.c
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006, Swedish Institute of Computer Science
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)$Id: xmem.c,v 1.1 2006/08/02 14:44:46 bg- Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Device driver for the ST M25P80 40MHz 1Mbyte external memory.
|
||||||
|
*
|
||||||
|
* Data is written bit inverted (~-operator) to flash so that
|
||||||
|
* unwritten data will read as zeros (UNIX style).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <io.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
|
||||||
|
#include "dev/spi.h"
|
||||||
|
#include "dev/xmem.h"
|
||||||
|
|
||||||
|
#define SPI_FLASH_INS_WREN 0x06
|
||||||
|
#define SPI_FLASH_INS_WRDI 0x04
|
||||||
|
#define SPI_FLASH_INS_RDSR 0x05
|
||||||
|
#define SPI_FLASH_INS_WRSR 0x01
|
||||||
|
#define SPI_FLASH_INS_READ 0x03
|
||||||
|
#define SPI_FLASH_INS_FAST_READ 0x0b
|
||||||
|
#define SPI_FLASH_INS_PP 0x02
|
||||||
|
#define SPI_FLASH_INS_SE 0xd8
|
||||||
|
#define SPI_FLASH_INS_BE 0xc7
|
||||||
|
#define SPI_FLASH_INS_DP 0xb9
|
||||||
|
#define SPI_FLASH_INS_RES 0xab
|
||||||
|
|
||||||
|
static void
|
||||||
|
write_enable(void)
|
||||||
|
{
|
||||||
|
int s;
|
||||||
|
|
||||||
|
s = splhigh();
|
||||||
|
SPI_FLASH_ENABLE();
|
||||||
|
|
||||||
|
FASTSPI_TX(SPI_FLASH_INS_WREN);
|
||||||
|
|
||||||
|
SPI_FLASH_DISABLE();
|
||||||
|
splx(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned
|
||||||
|
read_status_register(void)
|
||||||
|
{
|
||||||
|
unsigned char u;
|
||||||
|
|
||||||
|
int s;
|
||||||
|
|
||||||
|
s = splhigh();
|
||||||
|
SPI_FLASH_ENABLE();
|
||||||
|
|
||||||
|
FASTSPI_TX(SPI_FLASH_INS_RDSR);
|
||||||
|
|
||||||
|
FASTSPI_CLEAR_RX();
|
||||||
|
FASTSPI_RX(u);
|
||||||
|
|
||||||
|
SPI_FLASH_DISABLE();
|
||||||
|
splx(s);
|
||||||
|
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wait for a write operation to finish.
|
||||||
|
*/
|
||||||
|
static unsigned
|
||||||
|
eeprom_finish(void)
|
||||||
|
{
|
||||||
|
unsigned u;
|
||||||
|
do {
|
||||||
|
u = read_status_register();
|
||||||
|
} while(u & 0x01); /* WIP=1, write in progress */
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Erase 64kBytes of date, it takes about 1s before WIP goes low!
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
sector_erase(unsigned long offset)
|
||||||
|
{
|
||||||
|
int s;
|
||||||
|
|
||||||
|
eeprom_finish();
|
||||||
|
|
||||||
|
write_enable();
|
||||||
|
|
||||||
|
s = splhigh();
|
||||||
|
SPI_FLASH_ENABLE();
|
||||||
|
|
||||||
|
FASTSPI_TX(SPI_FLASH_INS_SE);
|
||||||
|
FASTSPI_TX(offset >> 16); /* MSB */
|
||||||
|
FASTSPI_TX(offset >> 8);
|
||||||
|
FASTSPI_TX(offset >> 0); /* LSB */
|
||||||
|
|
||||||
|
SPI_FLASH_DISABLE();
|
||||||
|
splx(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize external flash *and* SPI bus!
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
xmem_init(void)
|
||||||
|
{
|
||||||
|
spi_init();
|
||||||
|
|
||||||
|
P4DIR |= BV(FLASH_CS) | BV(FLASH_HOLD) | BV(FLASH_PWR);
|
||||||
|
P4OUT |= BV(FLASH_PWR); /* P4.3 Output, turn on power! */
|
||||||
|
|
||||||
|
SPI_FLASH_DISABLE(); /* Unselect flash. */
|
||||||
|
SPI_FLASH_UNHOLD();
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xmem_pread(void *_p, int size, off_t offset)
|
||||||
|
{
|
||||||
|
unsigned char *p = _p;
|
||||||
|
const unsigned char *end = p + size;
|
||||||
|
int s;
|
||||||
|
|
||||||
|
eeprom_finish();
|
||||||
|
|
||||||
|
s = splhigh();
|
||||||
|
SPI_FLASH_ENABLE();
|
||||||
|
|
||||||
|
FASTSPI_TX(SPI_FLASH_INS_READ);
|
||||||
|
FASTSPI_TX(offset >> 16); /* MSB */
|
||||||
|
FASTSPI_TX(offset >> 8);
|
||||||
|
FASTSPI_TX(offset >> 0); /* LSB */
|
||||||
|
|
||||||
|
FASTSPI_CLEAR_RX();
|
||||||
|
for(; p < end; p++) {
|
||||||
|
unsigned char u;
|
||||||
|
FASTSPI_RX(u);
|
||||||
|
*p = ~u;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPI_FLASH_DISABLE();
|
||||||
|
splx(s);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
eeprom_page_program(unsigned long offset, const unsigned char *p, int nbytes)
|
||||||
|
{
|
||||||
|
const unsigned char *end = p + nbytes;
|
||||||
|
int s;
|
||||||
|
|
||||||
|
eeprom_finish();
|
||||||
|
|
||||||
|
write_enable();
|
||||||
|
|
||||||
|
s = splhigh();
|
||||||
|
SPI_FLASH_ENABLE();
|
||||||
|
|
||||||
|
FASTSPI_TX(SPI_FLASH_INS_PP);
|
||||||
|
FASTSPI_TX(offset >> 16); /* MSB */
|
||||||
|
FASTSPI_TX(offset >> 8);
|
||||||
|
FASTSPI_TX(offset >> 0); /* LSB */
|
||||||
|
|
||||||
|
for(; p < end; p++) {
|
||||||
|
FASTSPI_TX(~*p);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPI_FLASH_DISABLE();
|
||||||
|
splx(s);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xmem_pwrite(const void *_buf, int size, off_t addr)
|
||||||
|
{
|
||||||
|
const unsigned char *buf = _buf;
|
||||||
|
unsigned i, next_page, end;
|
||||||
|
const char *p = buf;
|
||||||
|
|
||||||
|
end = addr + size;
|
||||||
|
for(i = addr; i < end;) {
|
||||||
|
next_page = (i | 0xff) + 1;
|
||||||
|
if(next_page > end)
|
||||||
|
next_page = end;
|
||||||
|
p = eeprom_page_program(i, p, next_page - i);
|
||||||
|
i = next_page;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xmem_erase(long size, off_t addr)
|
||||||
|
{
|
||||||
|
off_t end = addr + size;
|
||||||
|
|
||||||
|
if(size % XMEM_ERASE_UNIT_SIZE != 0) {
|
||||||
|
printf("xmem_erase: bad size\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(addr % XMEM_ERASE_UNIT_SIZE != 0) {
|
||||||
|
printf("xmem_erase: bad offset\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; addr < end; addr += XMEM_ERASE_UNIT_SIZE)
|
||||||
|
sector_erase(addr);
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
266
platform/sky/dhclient.c
Normal file
266
platform/sky/dhclient.c
Normal file
@ -0,0 +1,266 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006, Swedish Institute of Computer Science
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)$Id: dhclient.c,v 1.1 2006/08/02 14:44:46 bg- Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Example mote configuration with one radio interface that uses DHCP
|
||||||
|
* to configure its IP stack.
|
||||||
|
*
|
||||||
|
* The gateway systems must be configured to find what DHCP server to
|
||||||
|
* use, this can be done with an extra argument to tunslip, example:
|
||||||
|
*
|
||||||
|
* sliphost# ./tunslip 172.16.0.1 255.255.0.0 193.10.66.195
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* This kernel has no application code but new modules can be uploaded
|
||||||
|
* using the codeprop program, example:
|
||||||
|
*
|
||||||
|
* datan$ ./codeprop 172.16.0.1 loadable_prg.ko
|
||||||
|
* File successfully sent (1116 bytes)
|
||||||
|
* Reply: ok
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
|
||||||
|
/* Also IP output. */
|
||||||
|
#include "net/uip-fw-service.h"
|
||||||
|
#include "net/uaodv.h"
|
||||||
|
#include "net/dhcpc.h"
|
||||||
|
#include "dev/slip.h"
|
||||||
|
#include "dev/cc2420.h"
|
||||||
|
|
||||||
|
#include "dev/lpm.h"
|
||||||
|
#include "dev/ds2411.h"
|
||||||
|
#include "dev/leds.h"
|
||||||
|
#include "dev/light.h"
|
||||||
|
#include "dev/xmem.h"
|
||||||
|
|
||||||
|
#include "dev/button.h"
|
||||||
|
|
||||||
|
#include "codeprop/codeprop.h"
|
||||||
|
|
||||||
|
/* This is how we force inclusion of the psock library. */
|
||||||
|
#include "net/psock.h"
|
||||||
|
void *force_psock_inclusion = &psock_init;
|
||||||
|
|
||||||
|
void uip_log(char *msg) { puts(msg); }
|
||||||
|
|
||||||
|
struct uip_fw_netif cc2420if =
|
||||||
|
{UIP_FW_NETIF(0,0,0,0, 255,255,255,255, cc2420_send_uaodv)};
|
||||||
|
|
||||||
|
PROCESS(button_process, "Button process");
|
||||||
|
PROCESS(dhclient_process, "Dhclient process");
|
||||||
|
|
||||||
|
/* Radio stuff in network byte order. */
|
||||||
|
static u16_t panId = HTONS(0x2024);
|
||||||
|
|
||||||
|
#define RF_CHANNEL 26
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Initalize hardware.
|
||||||
|
*/
|
||||||
|
msp430_cpu_init();
|
||||||
|
clock_init();
|
||||||
|
leds_init();
|
||||||
|
leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE);
|
||||||
|
slip_arch_init(); /* Must come before first printf */
|
||||||
|
printf("Starting %s "
|
||||||
|
"($Id: dhclient.c,v 1.1 2006/08/02 14:44:46 bg- Exp $)\n", __FILE__);
|
||||||
|
ds2411_init();
|
||||||
|
sensors_light_init();
|
||||||
|
cc2420_init();
|
||||||
|
xmem_init();
|
||||||
|
button_init(&button_process);
|
||||||
|
leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE);
|
||||||
|
/*
|
||||||
|
* Hardware initialization done!
|
||||||
|
*/
|
||||||
|
|
||||||
|
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||||
|
ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3],
|
||||||
|
ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);
|
||||||
|
|
||||||
|
srand((ds2411_id[3]<<8) + (ds2411_id[4]<<6) + (ds2411_id[5]<<4) +
|
||||||
|
(ds2411_id[6]<<2) + ds2411_id[7]);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize Contiki and our processes.
|
||||||
|
*/
|
||||||
|
process_init();
|
||||||
|
process_start(&etimer_process, NULL);
|
||||||
|
|
||||||
|
/* Configure IP stack. */
|
||||||
|
uip_init();
|
||||||
|
|
||||||
|
/* Start IP stack. */
|
||||||
|
process_start(&tcpip_process, NULL);
|
||||||
|
process_start(&uip_fw_process, NULL); /* Start IP output */
|
||||||
|
process_start(&cc2420_process, NULL);
|
||||||
|
cc2420_on();
|
||||||
|
process_start(&dhclient_process, NULL);
|
||||||
|
|
||||||
|
process_start(&button_process, NULL);
|
||||||
|
process_start(&tcp_loader_process, NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the scheduler loop.
|
||||||
|
*/
|
||||||
|
printf("process_run()...\n");
|
||||||
|
lpm_on();
|
||||||
|
while (1) {
|
||||||
|
do {
|
||||||
|
/* Reset watchdog. */
|
||||||
|
} while(process_run() > 0);
|
||||||
|
/* Idle processing. */
|
||||||
|
LPM_SLEEP();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PROCESS_THREAD(button_process, ev, data)
|
||||||
|
{
|
||||||
|
static struct etimer etimer;
|
||||||
|
|
||||||
|
PROCESS_EXITHANDLER(goto exit);
|
||||||
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
printf("button_process starting\n");
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
PROCESS_WAIT_EVENT();
|
||||||
|
|
||||||
|
if(ev == PROCESS_EVENT_MSG && data != NULL
|
||||||
|
&& ((struct button_msg *)data)->type == BUTTON_MSG_TYPE) {
|
||||||
|
printf("button press\n");
|
||||||
|
|
||||||
|
leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE);
|
||||||
|
etimer_set(&etimer, CLOCK_SECOND);
|
||||||
|
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
|
||||||
|
leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
printf("button_process exiting\n");
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
PROCESS_THREAD(dhclient_process, ev, data)
|
||||||
|
{
|
||||||
|
PROCESS_EXITHANDLER(goto exit);
|
||||||
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
printf("dhclient_process starting\n");
|
||||||
|
|
||||||
|
leds_on(LEDS_GREEN);
|
||||||
|
|
||||||
|
uip_setipid(rand());
|
||||||
|
|
||||||
|
/* For now use 0.0.0.0 as our IP address. */
|
||||||
|
uip_ipaddr(&uip_hostaddr, 0,0,0,0);
|
||||||
|
cc2420_set_chan_pan_addr(RF_CHANNEL, panId, uip_hostaddr[1], ds2411_id);
|
||||||
|
|
||||||
|
/* Use only radio interface and enable forwarding. */
|
||||||
|
uip_fw_default(&cc2420if);
|
||||||
|
tcpip_set_forwarding(1);
|
||||||
|
/* No default router yet. */
|
||||||
|
|
||||||
|
dhcpc_init(ds2411_id, sizeof(ds2411_id));
|
||||||
|
dhcpc_request();
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
PROCESS_WAIT_EVENT();
|
||||||
|
dhcpc_appcall(ev, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
printf("dhclient_process exiting\n");
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
static char is_configured;
|
||||||
|
|
||||||
|
#define ip2quad(p) uip_ipaddr1(p),uip_ipaddr2(p),uip_ipaddr3(p),uip_ipaddr4(p)
|
||||||
|
|
||||||
|
void
|
||||||
|
dhcpc_configured(const struct dhcpc_state *s)
|
||||||
|
{
|
||||||
|
if(is_configured)
|
||||||
|
printf("dhcp reconfigure %d.%d.%d.%d\n", ip2quad(&s->ipaddr));
|
||||||
|
else {
|
||||||
|
printf("dhcpc_configured %d.%d.%d.%d\n", ip2quad(&s->ipaddr));
|
||||||
|
leds_off(LEDS_GREEN);
|
||||||
|
is_configured = 1;
|
||||||
|
process_start(&uaodv_process, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
uip_sethostaddr(s->ipaddr);
|
||||||
|
uip_setnetmask(s->netmask);
|
||||||
|
uip_setdraddr(s->default_router);
|
||||||
|
|
||||||
|
uip_ipaddr_copy(&cc2420if.ipaddr, s->ipaddr);
|
||||||
|
uip_ipaddr_copy(&cc2420if.netmask, s->netmask);
|
||||||
|
/* resolv_conf(s->dnsaddr); */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now we also have a new short MAC address!
|
||||||
|
*/
|
||||||
|
cc2420_set_chan_pan_addr(RF_CHANNEL, panId, uip_hostaddr[1], ds2411_id);
|
||||||
|
|
||||||
|
/* Use only radio interface and enable forwarding. */
|
||||||
|
uip_fw_init();
|
||||||
|
tcpip_set_forwarding(1);
|
||||||
|
uip_fw_default(&cc2420if);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
dhcpc_unconfigured(const struct dhcpc_state *s)
|
||||||
|
{
|
||||||
|
printf("dhcpc_unconfigured\n");
|
||||||
|
leds_on(LEDS_GREEN);
|
||||||
|
is_configured = 0;
|
||||||
|
process_exit(&uaodv_process);
|
||||||
|
|
||||||
|
uip_ipaddr(uip_hostaddr, 0,0,0,0);
|
||||||
|
uip_ipaddr(uip_netmask, 0,0,0,0);
|
||||||
|
uip_ipaddr(uip_draddr, 0,0,0,0);
|
||||||
|
|
||||||
|
/* New short MAC address. */
|
||||||
|
cc2420_set_chan_pan_addr(RF_CHANNEL, panId, uip_hostaddr[1], ds2411_id);
|
||||||
|
}
|
169
platform/sky/gateway.c
Normal file
169
platform/sky/gateway.c
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006, Swedish Institute of Computer Science
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* @(#)$Id: gateway.c,v 1.1 2006/08/02 14:44:46 bg- Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Example gateway configuration with two IP interfaces, one SLIP over
|
||||||
|
* USB and one over 802.11.4 radio.
|
||||||
|
*
|
||||||
|
* The IP address is hardcoded to 172.16.0.1 and the 172.16/16 network
|
||||||
|
* is on the radio interface.
|
||||||
|
*
|
||||||
|
* The default route is over the SLIP interface.
|
||||||
|
*
|
||||||
|
* On the SLIP host run a standard SLIP implementation or the tunslip
|
||||||
|
* program that can also view debug printfs, example:
|
||||||
|
*
|
||||||
|
* sliphost# ./tunslip 172.16.0.1 255.255.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* This kernel has no application code but new modules can be uploaded
|
||||||
|
* using the codeprop program, example:
|
||||||
|
*
|
||||||
|
* datan$ ./codeprop 172.16.0.1 loadable_prg.ko
|
||||||
|
* File successfully sent (1116 bytes)
|
||||||
|
* Reply: ok
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
|
||||||
|
/* Also IP output. */
|
||||||
|
#include "net/uip-fw-service.h"
|
||||||
|
#include "net/uaodv.h"
|
||||||
|
#include "dev/slip.h"
|
||||||
|
#include "dev/cc2420.h"
|
||||||
|
|
||||||
|
#include "dev/lpm.h"
|
||||||
|
#include "dev/ds2411.h"
|
||||||
|
#include "dev/leds.h"
|
||||||
|
#include "dev/light.h"
|
||||||
|
#include "dev/xmem.h"
|
||||||
|
|
||||||
|
#include "dev/button.h"
|
||||||
|
|
||||||
|
#include "codeprop/codeprop.h"
|
||||||
|
|
||||||
|
#define ip2quad(p) uip_ipaddr1(p),uip_ipaddr2(p),uip_ipaddr3(p),uip_ipaddr4(p)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is how we force inclusion of the psock library and the button
|
||||||
|
* device driver.
|
||||||
|
*/
|
||||||
|
#include "net/psock.h"
|
||||||
|
void *force_psock_inclusion = &psock_init;
|
||||||
|
void *force_button_inclusion = &button_init;
|
||||||
|
|
||||||
|
void uip_log(char *msg) { puts(msg); }
|
||||||
|
|
||||||
|
/* We have two IP interfaces. */
|
||||||
|
struct uip_fw_netif cc2420if =
|
||||||
|
{UIP_FW_NETIF(172,16,0,1, 255,255,0,0, cc2420_send_uaodv)};
|
||||||
|
|
||||||
|
static struct uip_fw_netif slipif =
|
||||||
|
{UIP_FW_NETIF(0,0,0,0, 255,255,255,255, slip_send)};
|
||||||
|
|
||||||
|
/* Radio stuff in network byte order. */
|
||||||
|
static u16_t panId = HTONS(0x2024);
|
||||||
|
|
||||||
|
#define RF_CHANNEL 26
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Initalize hardware.
|
||||||
|
*/
|
||||||
|
msp430_cpu_init();
|
||||||
|
clock_init();
|
||||||
|
leds_init();
|
||||||
|
leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE);
|
||||||
|
slip_arch_init(); /* Must come before first printf */
|
||||||
|
printf("Starting %s "
|
||||||
|
"($Id: gateway.c,v 1.1 2006/08/02 14:44:46 bg- Exp $)\n", __FILE__);
|
||||||
|
ds2411_init();
|
||||||
|
sensors_light_init();
|
||||||
|
cc2420_init();
|
||||||
|
xmem_init();
|
||||||
|
leds_toggle(LEDS_RED | LEDS_GREEN | LEDS_BLUE);
|
||||||
|
/*
|
||||||
|
* Hardware initialization done!
|
||||||
|
*/
|
||||||
|
|
||||||
|
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||||
|
ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3],
|
||||||
|
ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7]);
|
||||||
|
|
||||||
|
uip_ipaddr_copy(&uip_hostaddr, &cc2420if.ipaddr);
|
||||||
|
uip_ipaddr_copy(&uip_netmask, &cc2420if.netmask);
|
||||||
|
printf("IP %d.%d.%d.%d netmask %d.%d.%d.%d\n",
|
||||||
|
ip2quad(&uip_hostaddr), ip2quad(&uip_netmask));
|
||||||
|
cc2420_set_chan_pan_addr(RF_CHANNEL, panId, uip_hostaddr[1], ds2411_id);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize Contiki and our processes.
|
||||||
|
*/
|
||||||
|
process_init();
|
||||||
|
process_start(&etimer_process, NULL);
|
||||||
|
|
||||||
|
/* Configure IP stack. */
|
||||||
|
uip_init();
|
||||||
|
uip_fw_default(&slipif); /* Point2point, no default router. */
|
||||||
|
uip_fw_register(&cc2420if);
|
||||||
|
tcpip_set_forwarding(1);
|
||||||
|
|
||||||
|
/* Start IP stack. */
|
||||||
|
process_start(&tcpip_process, NULL);
|
||||||
|
process_start(&uip_fw_process, NULL); /* Start IP output */
|
||||||
|
process_start(&slip_process, NULL);
|
||||||
|
process_start(&cc2420_process, NULL);
|
||||||
|
cc2420_on();
|
||||||
|
process_start(&uaodv_process, NULL);
|
||||||
|
|
||||||
|
process_start(&tcp_loader_process, NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the scheduler loop.
|
||||||
|
*/
|
||||||
|
printf("process_run()...\n");
|
||||||
|
lpm_on();
|
||||||
|
while (1) {
|
||||||
|
do {
|
||||||
|
/* Reset watchdog. */
|
||||||
|
} while(process_run() > 0);
|
||||||
|
/* Idle processing. */
|
||||||
|
LPM_SLEEP();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
82
platform/sky/loadable_prg.c
Normal file
82
platform/sky/loadable_prg.c
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This file is part of the Contiki operating system.
|
||||||
|
*
|
||||||
|
* @(#)$Id: loadable_prg.c,v 1.1 2006/08/02 14:44:46 bg- Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
|
||||||
|
#include "dev/leds.h"
|
||||||
|
|
||||||
|
PROCESS(test_process, "Test process");
|
||||||
|
|
||||||
|
PROCESS_THREAD(test_process, ev, data)
|
||||||
|
{
|
||||||
|
static struct etimer etimer;
|
||||||
|
|
||||||
|
PROCESS_EXITHANDLER(goto exit);
|
||||||
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
printf("test_process starting\n");
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
leds_on(LEDS_RED);
|
||||||
|
etimer_set(&etimer, CLOCK_SECOND);
|
||||||
|
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
|
||||||
|
leds_off(LEDS_RED);
|
||||||
|
etimer_set(&etimer, CLOCK_SECOND);
|
||||||
|
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
printf("test_process exiting\n");
|
||||||
|
leds_off(LEDS_RED);
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize this kernel module.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_init(void)
|
||||||
|
{
|
||||||
|
process_start(&test_process, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When this module is unloaded we must clean up!
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_fini(void)
|
||||||
|
{
|
||||||
|
process_exit(&test_process);
|
||||||
|
}
|
91
platform/sky/udprecv.c
Normal file
91
platform/sky/udprecv.c
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This file is part of the Contiki operating system.
|
||||||
|
*
|
||||||
|
* @(#)$Id: udprecv.c,v 1.1 2006/08/02 14:44:46 bg- Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "net/uip.h"
|
||||||
|
|
||||||
|
PROCESS(udprecv_process, "UDP recv process");
|
||||||
|
|
||||||
|
PROCESS_THREAD(udprecv_process, ev, data)
|
||||||
|
{
|
||||||
|
static struct uip_udp_conn *c;
|
||||||
|
|
||||||
|
PROCESS_EXITHANDLER(goto exit);
|
||||||
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
printf("udprecv_process starting\n");
|
||||||
|
|
||||||
|
{
|
||||||
|
uip_ipaddr_t any;
|
||||||
|
uip_ipaddr(&any, 0,0,0,0);
|
||||||
|
c = udp_new(any, HTONS(0), NULL);
|
||||||
|
uip_udp_bind(c, HTONS(4321));
|
||||||
|
}
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
PROCESS_YIELD();
|
||||||
|
|
||||||
|
if(ev == tcpip_event && uip_newdata()) {
|
||||||
|
u8_t *src = (u8_t *)((struct uip_udpip_hdr *)uip_buf)->srcipaddr;
|
||||||
|
printf("%d.%d.%d.%d: %s\n",
|
||||||
|
src[0], src[1], src[2], src[3], (char *)uip_appdata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
/* Contiki does automatic garbage collection of uIP state and we
|
||||||
|
* need not worry about that. */
|
||||||
|
printf("udprecv_process exiting\n");
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize this kernel module.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_init(void)
|
||||||
|
{
|
||||||
|
process_start(&udprecv_process, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When this module is unloaded we must clean up!
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_fini(void)
|
||||||
|
{
|
||||||
|
process_exit(&udprecv_process);
|
||||||
|
}
|
102
platform/sky/udpsend.c
Normal file
102
platform/sky/udpsend.c
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the Institute nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This file is part of the Contiki operating system.
|
||||||
|
*
|
||||||
|
* @(#)$Id: udpsend.c,v 1.1 2006/08/02 14:44:46 bg- Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Set the IP destination address to something different from the
|
||||||
|
* broadcast address. Use commas (",") rather than the normal dots
|
||||||
|
* (".") in addresses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "net/uip.h"
|
||||||
|
|
||||||
|
#include "dev/leds.h"
|
||||||
|
#include "dev/light.h"
|
||||||
|
|
||||||
|
PROCESS(udpsend_process, "UDP send process");
|
||||||
|
|
||||||
|
PROCESS_THREAD(udpsend_process, ev, data)
|
||||||
|
{
|
||||||
|
static struct etimer etimer;
|
||||||
|
static struct uip_udp_conn *c;
|
||||||
|
|
||||||
|
PROCESS_EXITHANDLER(goto exit);
|
||||||
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
printf("udpsend_process starting\n");
|
||||||
|
|
||||||
|
{
|
||||||
|
uip_ipaddr_t addr;
|
||||||
|
uip_ipaddr(&addr, 255,255,255,255); /* Change address here! */
|
||||||
|
c = udp_new(addr, HTONS(4321), NULL);
|
||||||
|
c->ttl = 1; /* One hop only. */
|
||||||
|
}
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
etimer_set(&etimer, CLOCK_SECOND);
|
||||||
|
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer));
|
||||||
|
|
||||||
|
tcpip_poll_udp(c);
|
||||||
|
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
|
||||||
|
|
||||||
|
char buf[64];
|
||||||
|
sprintf(buf, "light sensors %d %d", sensors_light1(), sensors_light2());
|
||||||
|
uip_send(buf, strlen(buf) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
/* Contiki does automatic garbage collection of uIP state and we
|
||||||
|
* need not worry about that. */
|
||||||
|
printf("udpsend_process exiting\n");
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize this kernel module.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_init(void)
|
||||||
|
{
|
||||||
|
process_start(&udpsend_process, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When this module is unloaded we must clean up!
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_fini(void)
|
||||||
|
{
|
||||||
|
process_exit(&udpsend_process);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user