diff --git a/platform/micaz/Makefile.micaz b/platform/micaz/Makefile.micaz new file mode 100755 index 000000000..51dfaa2b8 --- /dev/null +++ b/platform/micaz/Makefile.micaz @@ -0,0 +1,54 @@ +CONTIKI_TARGET_DIRS = . dev dev/sensors +CONTIKI_CORE=contiki-micaz +CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o + +SENSOR_BOARD_SOURCEFILES = mts300.c + +CONTIKI_TARGET_SOURCEFILES += rs232.c cfs-eeprom.c contiki-micaz-main.c \ + leds-arch.c cc2420.c init-net-rime.c node-id.c \ + clock.c spi.c cc2420-arch.c rtimer-arch.c + +CONTIKI_TARGET_SOURCEFILES += $(SENSOR_BOARD_SOURCEFILES) + +CONTIKIAVR=$(CONTIKI)/cpu/avr +CONTIKIBOARD=. + +# MicaZ runs on Clock rate 7.3728 MHz +CONTIKI_PLAT_DEFS = -DF_CPU=7372800UL -DAUTO_CRC_PADDING=2 + +MCU=atmega128 + +include $(CONTIKIAVR)/Makefile.avr + + +%.od: %.$(TARGET) + avr-objdump -zhD $< > $@ + + +ifndef WINDIR + ifdef OS + ifneq (,$(findstring Windows,$(OS))) + WINDIR := Windows + endif + endif +endif + +ifeq ($(PRGBOARD), ) + PRGBOARD = mib510 +endif + +ifeq ($(PORT), ) + ifndef WINDIR + PORT = /dev/ttyS0 + else + PORT = COM1 + endif +endif + +PRGBOARD_FILE = $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.$(PRGBOARD) +HAVE_PRGBOARD_FILE = $(wildcard $(PRGBOARD_FILE)) + +ifneq ($(strip $(HAVE_PRGBOARD_FILE)), ) + include $(PRGBOARD_FILE) +endif + diff --git a/platform/micaz/apps/mts310/Makefile b/platform/micaz/apps/mts310/Makefile new file mode 100755 index 000000000..744dd1613 --- /dev/null +++ b/platform/micaz/apps/mts310/Makefile @@ -0,0 +1,5 @@ +CONTIKI = ../../../.. + +all: accel-test light-test magnet-test mic-test + +include $(CONTIKI)/Makefile.include diff --git a/platform/micaz/apps/mts310/accel-test.c b/platform/micaz/apps/mts310/accel-test.c new file mode 100755 index 000000000..94de0c474 --- /dev/null +++ b/platform/micaz/apps/mts310/accel-test.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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 +#include "contiki.h" +#include "dev/sensors/mts300.h" + +/*---------------------------------------------------------------------------*/ +PROCESS(test_accel_process, "Accel test"); +AUTOSTART_PROCESSES(&test_accel_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(test_accel_process, ev, data) +{ + static struct etimer et; + + PROCESS_BEGIN(); + + while(1) { + + printf("AccX : %d\n",get_accx()); + printf("AccY : %d\n",get_accy()); + + etimer_set(&et, CLOCK_SECOND / 2); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/micaz/apps/mts310/light-test.c b/platform/micaz/apps/mts310/light-test.c new file mode 100644 index 000000000..8c24489a0 --- /dev/null +++ b/platform/micaz/apps/mts310/light-test.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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/sensors/mts300.h" +#include + +/*---------------------------------------------------------------------------*/ +PROCESS(test_light_process, "light test"); +AUTOSTART_PROCESSES(&test_light_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(test_light_process, ev, data) +{ + static struct etimer et; + + PROCESS_BEGIN(); + + while(1) { + + printf("Light : %d\n",get_light()); + printf("Temp : %d\n",get_temp()); + + etimer_set(&et, CLOCK_SECOND / 2); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/micaz/apps/mts310/magnet-test.c b/platform/micaz/apps/mts310/magnet-test.c new file mode 100755 index 000000000..2b22436b5 --- /dev/null +++ b/platform/micaz/apps/mts310/magnet-test.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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/sensors/mts300.h" +#include + +/*---------------------------------------------------------------------------*/ +PROCESS(test_sounder_process, "Sounder test"); +AUTOSTART_PROCESSES(&test_sounder_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(test_sounder_process, ev, data) +{ + static struct etimer et; + + PROCESS_BEGIN(); + + while(1) { + + sounder_on(); + etimer_set(&et, 1); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + + sounder_off(); + etimer_set(&et, 1); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/micaz/apps/mts310/mic-test.c b/platform/micaz/apps/mts310/mic-test.c new file mode 100755 index 000000000..bb4ec62d9 --- /dev/null +++ b/platform/micaz/apps/mts310/mic-test.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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/sensors/mts300.h" +#include + +/*---------------------------------------------------------------------------*/ +PROCESS(test_mic_process, "Mic test"); +AUTOSTART_PROCESSES(&test_mic_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(test_mic_process, ev, data) +{ + static struct etimer et; + + PROCESS_BEGIN(); + + while(1) { + + printf("Mic : %d\n",get_mic()); + etimer_set(&et, CLOCK_SECOND / 8); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); +; + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/micaz/buildscripts/Makefile.mib510 b/platform/micaz/buildscripts/Makefile.mib510 new file mode 100644 index 000000000..365c9e4d3 --- /dev/null +++ b/platform/micaz/buildscripts/Makefile.mib510 @@ -0,0 +1,2 @@ +%.upload: %.srec + uisp -dprog=mib510 -dserial=$(PORT) --wr_fuse_h=0xd9 -dpart=ATmega128 --wr_fuse_e=ff --erase --upload if=$< --verify diff --git a/platform/micaz/contiki-conf.h b/platform/micaz/contiki-conf.h new file mode 100644 index 000000000..54d33f49a --- /dev/null +++ b/platform/micaz/contiki-conf.h @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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 + * Configuration for MICAz platform. + * + * \author + * Kasun Hewage + */ + +#ifndef __CONTIKI_CONF_H__ +#define __CONTIKI_CONF_H__ + +#define HAVE_STDINT_H +#include "avrdef.h" + + +/* + * MCU and clock rate. + * MICAZ runs on 7.3728 MHz clock. + */ +#define MCU_MHZ 7 + +#define PLATFORM PLATFORM_AVR + +/* Clock ticks per second */ +#define CLOCK_CONF_SECOND 128 + +/* COM port to be used for SLIP connection */ +#define SLIP_PORT RS232_PORT_0 + +/* Pre-allocated memory for loadable modules heap space (in bytes)*/ +#define MMEM_CONF_SIZE 256 + +/* Use the following address for code received via the codeprop + * facility + */ +#define EEPROMFS_ADDR_CODEPROP 0x8000 + +#define TIMESYNCH_CONF_ENABLED 1 +#define CC2420_CONF_TIMESTAMPS 1 + +#define WITH_NULLMAC 0 + +#define CCIF +#define CLIF + + +#ifdef WITH_UIP6 + +#define RIMEADDR_CONF_SIZE 8 + +#define UIP_CONF_LL_802154 1 +#define UIP_CONF_LLH_LEN 0 + +#define UIP_CONF_IPV6 1 +#define UIP_CONF_IPV6_QUEUE_PKT 1 +#define UIP_CONF_IPV6_CHECKS 1 +#define UIP_CONF_IPV6_REASSEMBLY 0 +#define UIP_CONF_NETIF_MAX_ADDRESSES 3 +#define UIP_CONF_ND6_MAX_PREFIXES 3 +#define UIP_CONF_ND6_MAX_NEIGHBORS 4 +#define UIP_CONF_ND6_MAX_DEFROUTERS 2 +#define UIP_CONF_IP_FORWARD 0 + +#define SICSLOWPAN_CONF_COMPRESSION_IPV6 0 +#define SICSLOWPAN_CONF_COMPRESSION_HC1 1 +#define SICSLOWPAN_CONF_COMPRESSION_HC01 2 +#define SICSLOWPAN_CONF_COMPRESSION SICS_LOWPAN_CONF_COMPRESSION_HC1 +#define SICSLOWPAN_CONF_FRAG 0 +#define SICSLOWPAN_CONF_CONVENTIONAL_MAC 1 +#else +#define UIP_CONF_IP_FORWARD 1 +#endif /* WITH_UIP6 */ + +#define UIP_CONF_ICMP_DEST_UNREACH 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 8 +#define UIP_CONF_UDP_CONNS 12 +#define UIP_CONF_FWCACHE_SIZE 30 +#define UIP_CONF_BROADCAST 1 +#define UIP_ARCH_IPCHKSUM 1 +#define UIP_CONF_UDP_CHECKSUMS 1 +#define UIP_CONF_PINGADDRCONF 0 +#define UIP_CONF_LOGGING 0 + +#define UIP_CONF_TCP_SPLIT 0 + + + + + +/* LEDs ports. */ +#define LEDS_PxDIR DDRA // port direction register +#define LEDS_PxOUT PORTA // port register +#define LEDS_CONF_RED 0x04 //red led +#define LEDS_CONF_GREEN 0x02 // green led +#define LEDS_CONF_YELLOW 0x01 // yellow led + + +/* + * SPI bus configuration for the MicaZ. + */ + +/* SPI input/output registers. */ +#define SPI_TXBUF SPDR +#define SPI_RXBUF SPDR + +#define BV(bitno) _BV(bitno) + +#define SPI_WAITFOREOTx() do { while (!(SPSR & BV(SPIF))); } while (0) +#define SPI_WAITFOREORx() do { while (!(SPSR & BV(SPIF))); } while (0) + +#define SCK 1 /* - Output: SPI Serial Clock (SCLK) - ATMEGA128 PORTB, PIN1 */ +#define MOSI 2 /* - Output: SPI Master out - slave in (MOSI) - ATMEGA128 PORTB, PIN2 */ +#define MISO 3 /* - Input: SPI Master in - slave out (MISO) - ATMEGA128 PORTB, PIN3 */ + +/* + * SPI bus - CC2420 pin configuration. + */ + +#define FIFO_P 6 /* - Input: FIFOP from CC2420 - ATMEGA128 PORTE, PIN6 */ +#define FIFO 7 /* - Input: FIFO from CC2420 - ATMEGA128 PORTB, PIN7 */ +#define CCA 6 /* - Input: CCA from CC2420 - ATMEGA128 PORTD, PIN6 */ + +#define SFD 4 /* - Input: SFD from CC2420 - ATMEGA128 PORTD, PIN4 */ +#define CSN 0 /* - Output: SPI Chip Select (CS_N) - ATMEGA128 PORTB, PIN0 */ +#define VREG_EN 5 /* - Output: VREG_EN to CC2420 - ATMEGA128 PORTA, PIN5 */ +#define RESET_N 6 /* - Output: RESET_N to CC2420 - ATMEGA128 PORTA, PIN6 */ + +/* Pin status. */ + +#define FIFO_IS_1 (!!(PINB & BV(FIFO))) +#define CCA_IS_1 (!!(PIND & BV(CCA) )) +#define RESET_IS_1 (!!(PINA & BV(RESET_N))) +#define VREG_IS_1 (!!(PINA & BV(VREG_EN))) +#define FIFOP_IS_1 (!!(PINE & BV(FIFO_P))) +#define SFD_IS_1 (!!(PIND & BV(SFD))) + +/* The CC2420 reset pin. */ +#define SET_RESET_INACTIVE() ( PORTA |= BV(RESET_N) ) +#define SET_RESET_ACTIVE() ( PORTA &= ~BV(RESET_N) ) + +/* CC2420 voltage regulator enable pin. */ +#define SET_VREG_ACTIVE() ( PORTA |= BV(VREG_EN) ) +#define SET_VREG_INACTIVE() ( PORTA &= ~BV(VREG_EN) ) + +/* CC2420 rising edge trigger for external interrupt 6 (FIFOP). + * Enable the external interrupt request for INT6. + * See Atmega128 datasheet about EICRB Register + */ +#define FIFOP_INT_INIT() do {\ + EICRB |= 0x30; \ + CLEAR_FIFOP_INT(); \ +} while (0) + +/* FIFOP on external interrupt 6. */ +#define ENABLE_FIFOP_INT() do { EIMSK |= 0x40; } while (0) +#define DISABLE_FIFOP_INT() do { EIMSK &= ~0x40; } while (0) +#define CLEAR_FIFOP_INT() do { EIFR = 0x40; } 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() ( PORTB &= ~BV(CSN) ) /* ENABLE CSn (active low) */ +#define SPI_DISABLE() ( PORTB |= BV(CSN) ) /* DISABLE CSn (active low) */ + +typedef unsigned short clock_time_t; +typedef unsigned short uip_stats_t; +typedef unsigned long off_t; + +void clock_delay(unsigned int us2); +void clock_wait(int ms10); +void clock_set_seconds(unsigned long s); +unsigned long clock_seconds(void); + +#endif /* __CONTIKI_CONF_H__ */ diff --git a/platform/micaz/contiki-micaz-main.c b/platform/micaz/contiki-micaz-main.c new file mode 100644 index 000000000..5e5d4663d --- /dev/null +++ b/platform/micaz/contiki-micaz-main.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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 + * Main file of the MICAz port. + * + * \author + * Kasun Hewage + */ + +#include + +#include "contiki.h" +#include "contiki-lib.h" + +#include "dev/leds.h" +#include "dev/rs232.h" +#include "dev/watchdog.h" + +#include "net/rime.h" +#include "net/mac/nullmac.h" +#include "net/mac/lpp.h" + +#include "node-id.h" + +void +init_usart(void) +{ + /* Second rs232 port for debugging */ + rs232_init(RS232_PORT_0, USART_BAUD_115200, + USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); + + /* Redirect stdout to second port */ + rs232_redirect_stdout(RS232_PORT_0); + +} + +int +main(void) +{ + + leds_init(); + + leds_on(LEDS_ALL); + + /* Initialize USART */ + init_usart(); + + /* Clock */ + clock_init(); + + random_init(0); + + rtimer_init(); + + /* Process subsystem */ + process_init(); + + process_start(&etimer_process, NULL); + + ctimer_init(); + + init_net(); + + printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u, using %s.\n"), + node_id, rime_mac->name); + + leds_off(LEDS_ALL); + + /* Autostart processes */ + autostart_start(autostart_processes); + + /* Main scheduler loop */ + do { + + process_run(); + + }while(1); + + return 0; +} diff --git a/platform/micaz/dev/cc2420-arch.c b/platform/micaz/dev/cc2420-arch.c new file mode 100644 index 000000000..285fe08ed --- /dev/null +++ b/platform/micaz/dev/cc2420-arch.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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 + +#include "contiki.h" +#include "contiki-net.h" + +#include "dev/spi.h" +#include "dev/cc2420.h" +#include "dev/leds.h" + +void +cc2420_arch_init(void) +{ + SFIOR |= BV(PUD); /* Beware, disable all pull-ups. */ + + spi_init(); + + DDRA |= BV(RESET_N); + DDRA |= BV(VREG_EN); + DDRB &= ~BV(FIFO); + DDRD &= ~BV(CCA); + DDRD &= ~BV(SFD); + DDRE &= ~BV(FIFO_P); + + PORTA |= BV(RESET_N); + PORTB |= BV(CSN); + + SPI_DISABLE(); /* Unselect radio. */ +} + +ISR(INT6_vect) +{ + /* TODO : wakeup from sleep mode */ + cc2420_interrupt(); + +} diff --git a/platform/micaz/dev/clock.c b/platform/micaz/dev/clock.c new file mode 100644 index 000000000..d69b7a83d --- /dev/null +++ b/platform/micaz/dev/clock.c @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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 "sys/clock.h" +#include "sys/etimer.h" + +#include +#include + +static volatile clock_time_t count, scount; +static volatile unsigned long seconds; + +/*---------------------------------------------------------------------------*/ +ISR(TIMER0_COMP_vect) +{ + count++; + if(++scount == CLOCK_SECOND) { + scount = 0; + seconds++; + } + if(etimer_pending()) { + etimer_request_poll(); + } +} + +/*---------------------------------------------------------------------------*/ +void +clock_init(void) +{ + /* Disable interrupts*/ + cli(); + + /* Disable compare match interrupts and overflow interrupts. */ + TIMSK &= ~( _BV(TOIE0) | _BV(OCIE0) ); + + /** + * set Timer/Counter0 to be asynchronous + * from the CPU clock with a second external + * clock(32,768kHz) driving it. + */ + ASSR |= _BV(AS0); + + /* + * Set timer control register: + * - prescale: 32 (CS00 and CS01) + * - counter reset via comparison register (WGM01) + */ + TCCR0 = _BV(CS00) | _BV(CS01) | _BV(WGM01); + + /* Set counter to zero */ + TCNT0 = 0; + + /* + * 128 clock ticks per second. + * 32,768 = 32 * 8 * 128 + */ + OCR0 = 8; + + /* Clear interrupt flag register */ + TIFR = 0x00; + + /** + * Wait for TCN0UB, OCR0UB, and TCR0UB. + * + */ + while(ASSR & 0x07); + + /* Raise interrupt when value in OCR0 is reached. */ + TIMSK |= _BV(OCIE0); + + count = 0; + + /* enable all interrupts*/ + sei(); + +} +/*---------------------------------------------------------------------------*/ +clock_time_t +clock_time(void) +{ + clock_time_t tmp; + do { + tmp = count; + } while(tmp != count); + return tmp; +} +/*---------------------------------------------------------------------------*/ +/** + * Delay the CPU for a multiple of TODO + */ +void +clock_delay(unsigned int i) +{ + for (; i > 0; i--) { /* Needs fixing XXX */ + unsigned j; + for (j = 50; j > 0; j--) + asm volatile("nop"); + } +} + +/*---------------------------------------------------------------------------*/ +/** + * Wait for a multiple of 1 / 128 sec = 7.8125 ms. + * + */ +void +clock_wait(int i) +{ + clock_time_t start; + + start = clock_time(); + while(clock_time() - start < (clock_time_t)i); +} +/*---------------------------------------------------------------------------*/ +void +clock_set_seconds(unsigned long sec) +{ + // TODO +} +/*---------------------------------------------------------------------------*/ +unsigned long +clock_seconds(void) +{ + unsigned long tmp; + do { + tmp = seconds; + } while(tmp != seconds); + return tmp; +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/micaz/dev/leds-arch.c b/platform/micaz/dev/leds-arch.c new file mode 100644 index 000000000..a23366f02 --- /dev/null +++ b/platform/micaz/dev/leds-arch.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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 + * LED architecture of the MICAz port. + * \author + * Kasun Hewage + */ + +#include "contiki-conf.h" +#include "dev/leds.h" +#include + + +/*---------------------------------------------------------------------------*/ +void leds_arch_init(void) +{ + LEDS_PxDIR |= (LEDS_CONF_RED | LEDS_CONF_GREEN | LEDS_CONF_YELLOW); + LEDS_PxOUT |= (LEDS_CONF_RED | LEDS_CONF_GREEN | LEDS_CONF_YELLOW); +} +/*---------------------------------------------------------------------------*/ +unsigned char leds_arch_get(void) +{ + return ((LEDS_PxOUT & LEDS_CONF_RED) ? 0 : LEDS_RED) + | ((LEDS_PxOUT & LEDS_CONF_GREEN) ? 0 : LEDS_GREEN) + | ((LEDS_PxOUT & LEDS_CONF_YELLOW) ? 0 : LEDS_YELLOW); +} +/*---------------------------------------------------------------------------*/ +void leds_arch_set(unsigned char leds) +{ + LEDS_PxOUT = (LEDS_PxOUT & ~(LEDS_CONF_RED|LEDS_CONF_GREEN|LEDS_CONF_YELLOW)) + | ((leds & LEDS_RED) ? 0 : LEDS_CONF_RED) + | ((leds & LEDS_GREEN) ? 0 : LEDS_CONF_GREEN) + | ((leds & LEDS_YELLOW) ? 0 : LEDS_CONF_YELLOW); +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/micaz/dev/sensors/mts300.c b/platform/micaz/dev/sensors/mts300.c new file mode 100644 index 000000000..4104e46f7 --- /dev/null +++ b/platform/micaz/dev/sensors/mts300.c @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * @(#)$$ + */ + +/** + * \file + * Device drivers implementation for MTS300 sensor board. + * \author + * Kasun Hewage + */ + +#include "mts300.h" +/*---------------------------------------------------------------------------*/ +void +sounder_on() +{ SOUNDER_DDR |= SOUNDER_MASK; + SOUNDER_PORT &= ~SOUNDER_MASK; + SOUNDER_PORT |= SOUNDER_MASK; +} +/*---------------------------------------------------------------------------*/ +void +sounder_off() +{ + SOUNDER_PORT &= ~(SOUNDER_MASK); + SOUNDER_DDR &= ~(SOUNDER_MASK); +} +/*---------------------------------------------------------------------------*/ +void +adc_init() +{ + ADMUX = 0; + /* AVCC with external capacitor at AREF pin. */ + //ADMUX |= _BV(REFS0) + /* Disable ADC interrupts. */ + ADCSRA &= ~( _BV(ADIE) | _BV(ADIF) ); + /* Set ADC prescaler to 64 and clear interrupt flag. */ + ADCSRA |= _BV(ADPS2) | _BV(ADPS1) | _BV(ADIE); + +} +/*---------------------------------------------------------------------------*/ +/* Poll based approach. The interrupt based adc is currently not used. + The ADC result is right adjusted. First 8 bits(from left) are in ADCL and + other two bits are in ADCH. See Atmega128 datasheet page 228. */ +uint16_t +get_adc(int channel) +{ + uint16_t reading; + + ADMUX |= (channel & 0x1F); + + /* Disable ADC interrupts. */ + ADCSRA &= ~_BV(ADIE); + /* Clear previous interrupts. */ + ADCSRA |= _BV(ADIF); + /* Enable ADC and start conversion. */ + ADCSRA |= _BV(ADEN) | _BV(ADSC); + /* Wait until conversion is completed. */ + while ( ADCSRA & _BV(ADSC) ); + /* Get first 8 bits. */ + reading = ADCL; + /* Get last two bits. */ + reading |= (ADCH & 3) << 8; + /* Disable ADC. */ + ADCSRA &= ~_BV(ADEN); + return reading; +} +/*---------------------------------------------------------------------------*/ +uint16_t +get_light() +{ + uint16_t reading; + + /* Enable light sensor. */ + LIGHT_PORT |= LIGHT_PIN_MASK; + LIGHT_PORT_DDR |= LIGHT_PIN_MASK; + /* Disable temperature sensor. */ + TEMP_PORT_DDR &= ~TEMP_PIN_MASK; + TEMP_PORT &= ~TEMP_PIN_MASK; + /* Read ADC. */ + reading = get_adc(LIGHT_ADC_CHANNEL); + /* Disable light sensor. */ + LIGHT_PORT &= ~LIGHT_PIN_MASK; + LIGHT_PORT_DDR &= ~LIGHT_PIN_MASK; + return reading; +} +/*---------------------------------------------------------------------------*/ +uint16_t +get_temp() +{ + uint16_t reading; + + /* Disable light sensor. */ + LIGHT_PORT &= ~LIGHT_PIN_MASK; + LIGHT_PORT_DDR &= ~LIGHT_PIN_MASK; + /* Enable temperature sensor. */ + TEMP_PORT_DDR |= TEMP_PIN_MASK; + TEMP_PORT |= TEMP_PIN_MASK; + /* Read ADC. */ + reading = get_adc(TEMP_ADC_CHANNEL); + /* Disable temperature sensor. */ + TEMP_PORT_DDR &= ~TEMP_PIN_MASK; + TEMP_PORT &= ~TEMP_PIN_MASK; + + return reading; +} +/*---------------------------------------------------------------------------*/ +uint16_t +get_accx() +{ + uint16_t reading; + + /* Enable accelerometer. */ + ACCEL_PORT_DDR |= ACCEL_PIN_MASK; + ACCEL_PORT |= ACCEL_PIN_MASK; + /* Read ADC. */ + reading = get_adc(ACCELX_ADC_CHANNEL); + /* Enable accelerometer. */ + ACCEL_PORT_DDR &= ~ACCEL_PIN_MASK; + ACCEL_PORT &= ~ACCEL_PIN_MASK; + + return reading; +} +/*---------------------------------------------------------------------------*/ +uint16_t +get_accy() +{ + uint16_t reading; + + /* Enable accelerometer. */ + ACCEL_PORT_DDR |= ACCEL_PIN_MASK; + ACCEL_PORT |= ACCEL_PIN_MASK; + /* Read ADC. */ + reading = get_adc(ACCELY_ADC_CHANNEL); + /* Enable accelerometer. */ + ACCEL_PORT_DDR &= ~ACCEL_PIN_MASK; + ACCEL_PORT &= ~ACCEL_PIN_MASK; + + return reading; +} +/*---------------------------------------------------------------------------*/ +uint16_t +get_magx() +{ + uint16_t reading; + + /* Enable magnetometer. */ + MAGNET_PORT_DDR |= MAGNET_PIN_MASK; + MAGNET_PORT |= MAGNET_PIN_MASK; + /* Read ADC. */ + reading = get_adc(MAGNETX_ADC_CHANNEL); + /* Enable magnetometer. */ + MAGNET_PORT_DDR &= ~MAGNET_PIN_MASK; + MAGNET_PORT &= ~MAGNET_PIN_MASK; + + return reading; +} +/*---------------------------------------------------------------------------*/ +uint16_t +get_magy() +{ + uint16_t reading; + + /* Enable magnetometer. */ + MAGNET_PORT_DDR |= MAGNET_PIN_MASK; + MAGNET_PORT |= MAGNET_PIN_MASK; + /* Read ADC. */ + reading = get_adc(MAGNETY_ADC_CHANNEL); + /* Enable magnetometer. */ + MAGNET_PORT_DDR &= ~MAGNET_PIN_MASK; + MAGNET_PORT &= ~MAGNET_PIN_MASK; + + return reading; +} +/*---------------------------------------------------------------------------*/ +uint16_t +get_mic() +{ + uint16_t reading; + + /* Enable mic. */ + MIC_PORT_DDR |= MIC_PIN_MASK; + MIC_PORT |= MIC_PIN_MASK; + /* Read ADC. */ + reading = get_adc(MIC_ADC_CHANNEL); + /* Enable mic. */ + MIC_PORT_DDR &= ~MIC_PIN_MASK; + MIC_PORT &= ~MIC_PIN_MASK; + + return reading; +} +/*---------------------------------------------------------------------------*/ + diff --git a/platform/micaz/dev/sensors/mts300.h b/platform/micaz/dev/sensors/mts300.h new file mode 100644 index 000000000..ca43229a1 --- /dev/null +++ b/platform/micaz/dev/sensors/mts300.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + * @(#)$$ + */ + +/** + * \file + * Device drivers header file for MTS300 sensor board. + * \author + * Kasun Hewage + */ + +#ifndef __MTS300_H__ +#define __MTS300_H__ + +#include +#include "contiki-conf.h" + +#define SOUNDER_PORT PORTC +#define SOUNDER_MASK _BV(2) +#define SOUNDER_DDR DDRC + +/* MTS300CA and MTS310CA, the light sensor power is controlled + * by setting signal INT1(PORTE pin 5). + * Both light and thermistor use the same ADC channel. + */ +#define LIGHT_PORT_DDR DDRE +#define LIGHT_PORT PORTE +#define LIGHT_PIN_MASK _BV(5) +#define LIGHT_ADC_CHANNEL 1 + +/* MTS300CA and MTS310CA, the thermistor power is controlled + * by setting signal INT2(PORTE pin 6). + * Both light and thermistor use the same ADC channel. + */ +#define TEMP_PORT_DDR DDRE +#define TEMP_PORT PORTE +#define TEMP_PIN_MASK _BV(6) +#define TEMP_ADC_CHANNEL 1 + +/* Power is controlled to the accelerometer by setting signal + * PW4(PORTC pin 4), and the analog data is sampled on ADC3 and ADC4. + */ +#define ACCEL_PORT_DDR DDRC +#define ACCEL_PORT PORTC +#define ACCEL_PIN_MASK _BV(4) +#define ACCELX_ADC_CHANNEL 3 +#define ACCELY_ADC_CHANNEL 4 + +/* Power is controlled to the magnetometer by setting signal + * PW5(PORTC pin 5), and the analog data is sampled on ADC5 and ADC6. + */ +#define MAGNET_PORT_DDR DDRC +#define MAGNET_PORT PORTC +#define MAGNET_PIN_MASK _BV(5) +#define MAGNETX_ADC_CHANNEL 5 +#define MAGNETY_ADC_CHANNEL 6 + + +#define MIC_PORT_DDR DDRC +#define MIC_PORT PORTC +#define MIC_PIN_MASK _BV(3) +#define MIC_ADC_CHANNEL 2 + +void sounder_on(); +void sounder_off(); + +uint16_t get_light(); +uint16_t get_temp(); + +uint16_t get_accx(); +uint16_t get_accy(); + +uint16_t get_magx(); +uint16_t get_magy(); + +uint16_t get_mic(); + +void mts300_init(); + +#endif /* __MTS300_H__ */ + + + diff --git a/platform/micaz/init-net-rime.c b/platform/micaz/init-net-rime.c new file mode 100644 index 000000000..b73285e39 --- /dev/null +++ b/platform/micaz/init-net-rime.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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 + * Rime initialization for the MICAz port. + * \author + * Kasun Hewage + */ + +#include "contiki.h" +#include "node-id.h" +#include "dev/cc2420.h" +#include "net/mac/nullmac.h" +#include "net/mac/lpp.h" +#include "net/rime.h" + +#ifndef RF_CHANNEL +#define RF_CHANNEL 26 +#endif + +void +init_net(void) +{ + rimeaddr_t rimeaddr; + cc2420_init(); + cc2420_set_channel(RF_CHANNEL); +#if WITH_NULLMAC + rime_init(nullmac_init(&cc2420_driver)); +#else + rime_init(lpp_init(&cc2420_driver)); +#endif + rimeaddr.u8[0] = node_id & 0xff; + rimeaddr.u8[1] = node_id >> 8; + rimeaddr_set_node_addr(&rimeaddr); +} diff --git a/platform/micaz/node-id.c b/platform/micaz/node-id.c new file mode 100644 index 000000000..26998c416 --- /dev/null +++ b/platform/micaz/node-id.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2009, University of Colombo School of Computing + * 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 "node-id.h" + +uint16_t node_id = 0; + +/*---------------------------------------------------------------------------*/ +void +node_id_restore(void) +{ + +} +/*---------------------------------------------------------------------------*/ +void +node_id_burn(uint16_t id) +{ + +} +/*---------------------------------------------------------------------------*/ diff --git a/platform/micaz/node-id.h b/platform/micaz/node-id.h new file mode 100644 index 000000000..6c3a2d9c7 --- /dev/null +++ b/platform/micaz/node-id.h @@ -0,0 +1,45 @@ +/* + * 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 + * + */ + +#ifndef NODE_ID_H +#define NODE_ID_H + +#include "contiki-conf.h" + +void node_id_restore(void); +void node_id_burn(uint16_t node_id); + +extern uint16_t node_id; + +#endif /* !NODE_ID_H */