create iris directory
This commit is contained in:
parent
6355545ded
commit
9a201f6934
55
platform/iris/Makefile.micaz
Normal file
55
platform/iris/Makefile.micaz
Normal file
@ -0,0 +1,55 @@
|
||||
CONTIKI_TARGET_DIRS = . dev dev/sensors
|
||||
CONTIKI_CORE=contiki-micaz
|
||||
CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o
|
||||
|
||||
SENSOR_BOARD_SOURCEFILES = mts300.c
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += adc.c rs232.c cfs-eeprom.c contiki-micaz-main.c \
|
||||
leds-arch.c cc2420.c init-net.c node-id.c \
|
||||
clock.c spi.c cc2420-arch.c rtimer-arch.c ds2401.c \
|
||||
battery-sensor.c slip.c slip_uart0.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
|
||||
|
5
platform/iris/apps/Makefile
Normal file
5
platform/iris/apps/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
CONTIKI = ../../..
|
||||
|
||||
all: battery-monitor
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
34
platform/iris/apps/battery-monitor.c
Normal file
34
platform/iris/apps/battery-monitor.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include "contiki.h"
|
||||
#include "dev/battery-sensor.h"
|
||||
#include "lib/sensors.h"
|
||||
#include <stdio.h> /* For printf() */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(battery_monitor_process, "Battery Voltage Monitor");
|
||||
AUTOSTART_PROCESSES(&battery_monitor_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(battery_monitor_process, ev, data)
|
||||
{
|
||||
static struct etimer et;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
SENSORS_ACTIVATE(battery_sensor);
|
||||
|
||||
while(1) {
|
||||
|
||||
etimer_set(&et, CLOCK_SECOND * 2);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
|
||||
/*
|
||||
* Battery voltage calculation formula
|
||||
*
|
||||
* V(Battery Voltage) = v(Voltage Reference) * 1024 / ADC
|
||||
*
|
||||
* Where:
|
||||
* v = 1.223
|
||||
*
|
||||
*/
|
||||
printf("ADC value : %d\n", battery_sensor.value(0));
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
5
platform/iris/apps/mts310/Makefile
Normal file
5
platform/iris/apps/mts310/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
CONTIKI = ../../../..
|
||||
|
||||
all: accel-test light-test magnet-test mic-test
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
59
platform/iris/apps/mts310/accel-test.c
Normal file
59
platform/iris/apps/mts310/accel-test.c
Normal file
@ -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 <stdio.h>
|
||||
#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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
60
platform/iris/apps/mts310/light-test.c
Normal file
60
platform/iris/apps/mts310/light-test.c
Normal file
@ -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 <stdio.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
61
platform/iris/apps/mts310/magnet-test.c
Normal file
61
platform/iris/apps/mts310/magnet-test.c
Normal file
@ -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 <stdio.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
58
platform/iris/apps/mts310/mic-test.c
Normal file
58
platform/iris/apps/mts310/mic-test.c
Normal file
@ -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 <stdio.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
5
platform/iris/buildscripts/Makefile.mib510
Normal file
5
platform/iris/buildscripts/Makefile.mib510
Normal file
@ -0,0 +1,5 @@
|
||||
%.upload: %.srec
|
||||
uisp -dprog=mib510 -dserial=$(PORT) -dpart=ATmega128 --wr_fuse_h=0xd1 --wr_fuse_e=ff --erase --upload if=$< --verify
|
||||
|
||||
erase:
|
||||
uisp -dprog=mib510 -dserial=$(PORT) -dpart=ATmega128 --wr_fuse_h=0xd9 --wr_fuse_e=ff --erase
|
201
platform/iris/contiki-conf.h
Normal file
201
platform/iris/contiki-conf.h
Normal file
@ -0,0 +1,201 @@
|
||||
/*
|
||||
* 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 <kasun.ch@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef __CONTIKI_CONF_H__
|
||||
#define __CONTIKI_CONF_H__
|
||||
|
||||
#define HAVE_STDINT_H
|
||||
#include "avrdef.h"
|
||||
|
||||
#include "platform-conf.h"
|
||||
|
||||
#if WITH_UIP6
|
||||
|
||||
/* Network setup for IPv6 */
|
||||
#define NETSTACK_CONF_NETWORK sicslowpan_driver
|
||||
#define NETSTACK_CONF_MAC csma_driver
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
#define NETSTACK_CONF_FRAMER framer_802154
|
||||
|
||||
#define CC2420_CONF_AUTOACK 1
|
||||
#define MAC_CONF_CHANNEL_CHECK_RATE 8
|
||||
#define RIME_CONF_NO_POLITE_ANNOUCEMENTS 0
|
||||
#define CXMAC_CONF_ANNOUNCEMENTS 0
|
||||
|
||||
#else /* WITH_UIP6 */
|
||||
|
||||
/* Network setup for non-IPv6 (rime). */
|
||||
|
||||
#define NETSTACK_CONF_NETWORK rime_driver
|
||||
#define NETSTACK_CONF_MAC csma_driver
|
||||
#define NETSTACK_CONF_RDC cxmac_driver
|
||||
#define NETSTACK_CONF_FRAMER framer_802154
|
||||
|
||||
#define CC2420_CONF_AUTOACK 1
|
||||
#define MAC_CONF_CHANNEL_CHECK_RATE 8
|
||||
|
||||
#define COLLECT_CONF_ANNOUNCEMENTS 1
|
||||
#define RIME_CONF_NO_POLITE_ANNOUCEMENTS 1
|
||||
#define CXMAC_CONF_ANNOUNCEMENTS 0
|
||||
#define CXMAC_CONF_COMPOWER 1
|
||||
#define CONTIKIMAC_CONF_ANNOUNCEMENTS 0
|
||||
#define CONTIKIMAC_CONF_COMPOWER 1
|
||||
|
||||
#define COLLECT_NEIGHBOR_CONF_MAX_NEIGHBORS 32
|
||||
|
||||
#endif /* WITH_UIP6 */
|
||||
|
||||
#define PACKETBUF_CONF_ATTRS_INLINE 1
|
||||
|
||||
#ifndef RF_CHANNEL
|
||||
#define RF_CHANNEL 26
|
||||
#endif /* RF_CHANNEL */
|
||||
|
||||
#define CONTIKIMAC_CONF_BROADCAST_RATE_LIMIT 0
|
||||
|
||||
#define IEEE802154_CONF_PANID 0xABCD
|
||||
|
||||
|
||||
#define AODV_COMPLIANCE
|
||||
#define AODV_NUM_RT_ENTRIES 32
|
||||
|
||||
#define WITH_ASCII 1
|
||||
|
||||
#define PROCESS_CONF_NUMEVENTS 8
|
||||
#define PROCESS_CONF_STATS 1
|
||||
|
||||
#ifdef WITH_UIP6
|
||||
|
||||
#define RIMEADDR_CONF_SIZE 8
|
||||
|
||||
#define UIP_CONF_LL_802154 1
|
||||
#define UIP_CONF_LLH_LEN 0
|
||||
|
||||
#define UIP_CONF_ROUTER 1
|
||||
#define UIP_CONF_IPV6_RPL 1
|
||||
|
||||
/* configure number of neighbors and routes */
|
||||
#define UIP_CONF_DS6_NBR_NBU 5
|
||||
#define UIP_CONF_DS6_ROUTE_NBU 5
|
||||
|
||||
#define RPL_CONF_MAX_PARENTS 4
|
||||
#define NEIGHBOR_CONF_MAX_NEIGHBORS 8
|
||||
|
||||
#define UIP_CONF_ND6_SEND_RA 0
|
||||
#define UIP_CONF_ND6_REACHABLE_TIME 600000
|
||||
#define UIP_CONF_ND6_RETRANS_TIMER 10000
|
||||
|
||||
#define UIP_CONF_IPV6 1
|
||||
#define UIP_CONF_IPV6_QUEUE_PKT 0
|
||||
#define UIP_CONF_IPV6_CHECKS 1
|
||||
#define UIP_CONF_IPV6_REASSEMBLY 0
|
||||
#define UIP_CONF_NETIF_MAX_ADDRESSES 3
|
||||
#define UIP_CONF_ND6_MAX_PREFIXES 3
|
||||
#define UIP_CONF_ND6_MAX_NEIGHBORS 4
|
||||
#define UIP_CONF_ND6_MAX_DEFROUTERS 2
|
||||
#define UIP_CONF_IP_FORWARD 0
|
||||
#define UIP_CONF_BUFFER_SIZE 240
|
||||
|
||||
#define SICSLOWPAN_CONF_COMPRESSION_IPV6 0
|
||||
#define SICSLOWPAN_CONF_COMPRESSION_HC1 1
|
||||
#define SICSLOWPAN_CONF_COMPRESSION_HC01 2
|
||||
#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_COMPRESSION_HC06
|
||||
#ifndef SICSLOWPAN_CONF_FRAG
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
#define SICSLOWPAN_CONF_MAXAGE 8
|
||||
#endif /* SICSLOWPAN_CONF_FRAG */
|
||||
#define SICSLOWPAN_CONF_CONVENTIONAL_MAC 1
|
||||
#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2
|
||||
#else /* WITH_UIP6 */
|
||||
#define UIP_CONF_IP_FORWARD 1
|
||||
#define UIP_CONF_BUFFER_SIZE 128
|
||||
#endif /* WITH_UIP6 */
|
||||
|
||||
#define UIP_CONF_ICMP_DEST_UNREACH 1
|
||||
|
||||
#if !WITH_UIP && !WITH_UIP6
|
||||
#define QUEUEBUF_CONF_NUM 8
|
||||
#else
|
||||
#define QUEUEBUF_CONF_NUM 4
|
||||
#endif
|
||||
|
||||
#define TIMESYNCH_CONF_ENABLED 1
|
||||
#define CC2420_CONF_TIMESTAMPS 1
|
||||
#define CC2420_CONF_SYMBOL_LOOP_COUNT 500
|
||||
|
||||
#define WITH_NULLMAC 0
|
||||
|
||||
#define CCIF
|
||||
#define CLIF
|
||||
|
||||
/* The process names are not used to save RAM */
|
||||
#define PROCESS_CONF_NO_PROCESS_NAMES 1
|
||||
|
||||
#define UIP_CONF_ICMP_DEST_UNREACH 1
|
||||
|
||||
#define UIP_CONF_DHCP_LIGHT
|
||||
#define UIP_CONF_LLH_LEN 0
|
||||
#define UIP_CONF_RECEIVE_WINDOW 48
|
||||
#define UIP_CONF_TCP_MSS 48
|
||||
#define UIP_CONF_MAX_CONNECTIONS 4
|
||||
#define UIP_CONF_MAX_LISTENPORTS 8
|
||||
#define UIP_CONF_UDP_CONNS 12
|
||||
#define UIP_CONF_FWCACHE_SIZE 15
|
||||
#define UIP_CONF_BROADCAST 1
|
||||
//#define UIP_ARCH_IPCHKSUM 1
|
||||
#define UIP_CONF_UDP 1
|
||||
#define UIP_CONF_UDP_CHECKSUMS 1
|
||||
#define UIP_CONF_PINGADDRCONF 0
|
||||
#define UIP_CONF_LOGGING 0
|
||||
|
||||
#define UIP_CONF_TCP_SPLIT 0
|
||||
|
||||
|
||||
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__ */
|
124
platform/iris/contiki-micaz-main.c
Normal file
124
platform/iris/contiki-micaz-main.c
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 <kasun.ch@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-lib.h"
|
||||
#include "net/rime.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/rs232.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/slip.h"
|
||||
|
||||
#include "init-net.h"
|
||||
#include "dev/ds2401.h"
|
||||
#include "node-id.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
init_usart(void)
|
||||
{
|
||||
/* First rs232 port for debugging */
|
||||
rs232_init(RS232_PORT_0, USART_BAUD_115200,
|
||||
USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||
|
||||
#if WITH_UIP || WITH_UIP6
|
||||
slip_arch_init(USART_BAUD_115200);
|
||||
#else
|
||||
rs232_redirect_stdout(RS232_PORT_0);
|
||||
#endif /* WITH_UIP */
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
leds_init();
|
||||
|
||||
leds_on(LEDS_RED);
|
||||
|
||||
/* Initialize USART */
|
||||
init_usart();
|
||||
|
||||
/* Clock */
|
||||
clock_init();
|
||||
|
||||
leds_on(LEDS_GREEN);
|
||||
|
||||
ds2401_init();
|
||||
|
||||
node_id_restore();
|
||||
|
||||
random_init(ds2401_id[0] + node_id);
|
||||
|
||||
rtimer_init();
|
||||
|
||||
/* Process subsystem */
|
||||
process_init();
|
||||
|
||||
process_start(&etimer_process, NULL);
|
||||
|
||||
ctimer_init();
|
||||
|
||||
leds_on(LEDS_YELLOW);
|
||||
|
||||
init_net();
|
||||
|
||||
printf_P(PSTR(CONTIKI_VERSION_STRING " started. Node id %u\n"), node_id);
|
||||
|
||||
leds_off(LEDS_ALL);
|
||||
|
||||
/* Autostart processes */
|
||||
autostart_start(autostart_processes);
|
||||
|
||||
/* Main scheduler loop */
|
||||
do {
|
||||
|
||||
process_run();
|
||||
|
||||
}while(1);
|
||||
|
||||
return 0;
|
||||
}
|
76
platform/iris/dev/adc.c
Normal file
76
platform/iris/dev/adc.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 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 <avr/io.h>
|
||||
#include "dev/adc.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
40
platform/iris/dev/adc.h
Normal file
40
platform/iris/dev/adc.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __ADC_H__
|
||||
#define __ADC_H__
|
||||
|
||||
void adc_init();
|
||||
|
||||
uint16_t get_adc(int channel);
|
||||
|
||||
#endif /* __ADC_H__ */
|
69
platform/iris/dev/cc2420-arch.c
Normal file
69
platform/iris/dev/cc2420-arch.c
Normal file
@ -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 <avr/io.h>
|
||||
|
||||
#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(CC2420_RESET_PIN);
|
||||
DDRA |= BV(CC2420_VREG_PIN);
|
||||
DDRB &= ~BV(CC2420_FIFO_PIN);
|
||||
DDRD &= ~BV(CC2420_CCA_PIN);
|
||||
DDRD &= ~BV(CC2420_SFD_PIN);
|
||||
DDRE &= ~BV(CC2420_FIFOP_PIN);
|
||||
|
||||
PORTA |= BV(CC2420_RESET_PIN);
|
||||
PORTB |= BV(CC2420_CSN_PIN);
|
||||
|
||||
CC2420_SPI_DISABLE(); /* Unselect radio. */
|
||||
}
|
||||
|
||||
ISR(CC2420_IRQ_VECTOR)
|
||||
{
|
||||
/* TODO : wakeup from sleep mode */
|
||||
cc2420_interrupt();
|
||||
|
||||
}
|
160
platform/iris/dev/clock.c
Normal file
160
platform/iris/dev/clock.c
Normal file
@ -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 <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
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;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
244
platform/iris/dev/ds2401.c
Normal file
244
platform/iris/dev/ds2401.c
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Device driver for the Dallas Semiconductor DS2401 chip. Heavily
|
||||
* based on the application note 126 "1-Wire Communications Through
|
||||
* Software".
|
||||
*
|
||||
* http://www.maxim-ic.com/appnotes.cfm/appnote_number/126
|
||||
*/
|
||||
|
||||
/*
|
||||
* For now we stuff in Crossbow Technology, Inc's unique OUI.
|
||||
* 00:1A:4C Crossbow Technology, Inc
|
||||
*
|
||||
* The EUI-64 is a concatenation of the 24-bit OUI value assigned by
|
||||
* the IEEE Registration Authority and a 40-bit extension identifier
|
||||
* assigned by the organization with that OUI assignment.
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <string.h>
|
||||
#include "contiki.h"
|
||||
|
||||
#include "ds2401.h"
|
||||
|
||||
unsigned char ds2401_id[8];
|
||||
|
||||
/* 1-wire is at PortA.4 */
|
||||
#define SERIAL_ID_PIN_READ PINA
|
||||
#define SERIAL_ID_PIN_MASK _BV(4)
|
||||
#define SERIAL_ID_PxOUT PORTA
|
||||
#define SERIAL_ID_PxDIR DDRA
|
||||
|
||||
#define SET_PIN_INPUT() (SERIAL_ID_PxDIR &= ~SERIAL_ID_PIN_MASK)
|
||||
#define SET_PIN_OUTPUT() (SERIAL_ID_PxDIR |= SERIAL_ID_PIN_MASK)
|
||||
|
||||
#define OUTP_0() (SERIAL_ID_PxOUT &= ~SERIAL_ID_PIN_MASK)
|
||||
#define OUTP_1() (SERIAL_ID_PxOUT |= SERIAL_ID_PIN_MASK)
|
||||
|
||||
#define PIN_INIT() do{ \
|
||||
SET_PIN_INPUT(); \
|
||||
OUTP_0(); \
|
||||
} while(0)
|
||||
|
||||
|
||||
/* Drive the one wire interface low */
|
||||
#define OW_DRIVE() do { \
|
||||
SET_PIN_OUTPUT(); \
|
||||
OUTP_0(); \
|
||||
} while (0)
|
||||
|
||||
/* Release the one wire by turning on the internal pull-up. */
|
||||
#define OW_RELEASE() do { \
|
||||
SET_PIN_INPUT(); \
|
||||
OUTP_1(); \
|
||||
} while (0)
|
||||
|
||||
/* Read one bit. */
|
||||
#define INP() (SERIAL_ID_PIN_READ & SERIAL_ID_PIN_MASK)
|
||||
|
||||
/*
|
||||
* Delay times in us.
|
||||
*/
|
||||
#define tA 6 /* min-5, recommended-6, max-15 */
|
||||
#define tB 64 /* min-59, recommended-64, max-N/A */
|
||||
#define tC 60 /* min-60, recommended-60, max-120 */
|
||||
#define tD 10 /* min-5.3, recommended-10, max-N/A */
|
||||
#define tE 9 /* min-0.3, recommended-9, max-9.3 */
|
||||
#define tF 55 /* min-50, recommended-55, max-N/A */
|
||||
#define tG 0 /* min-0, recommended-0, max-0 */
|
||||
#define tH 480 /* min-480, recommended-480, max-640 */
|
||||
#define tI 70 /* min-60.3, recommended-70, max-75.3 */
|
||||
#define tJ 410 /* min-410, recommended-410, max-N/A */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* The delay caused by calling the delay_loop is given by the following
|
||||
* formula.
|
||||
* delay(us) = (4n + 1)/XTAL
|
||||
* where n is the number of iterations and XTAL is the clock frequency(in MHz).
|
||||
* TODO: Moving the delay_loop to dev/clock.c
|
||||
*/
|
||||
static void
|
||||
delay_loop(uint16_t __count)
|
||||
{
|
||||
asm volatile ("1: sbiw %0,1" "\n\t"
|
||||
"brne 1b"
|
||||
: "=w" (__count)
|
||||
: "0" (__count)
|
||||
);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* This macro relies on the compiler doing the arithmetic during compile time
|
||||
* for the needed iterations.!!
|
||||
* In MICAz, XTAL = 7.3728 MHz
|
||||
*/
|
||||
#define udelay(u) delay_loop(((7.3728F * u)-1)/4)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
reset(void)
|
||||
{
|
||||
uint8_t result;
|
||||
OW_DRIVE();
|
||||
udelay(500); /* 480 < tH < 640 */
|
||||
OW_RELEASE(); /* Releases the bus */
|
||||
udelay(tI);
|
||||
result = INP();
|
||||
udelay(tJ);
|
||||
return result;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
write_byte(uint8_t byte)
|
||||
{
|
||||
uint8_t i = 7;
|
||||
do {
|
||||
if (byte & 0x01) {
|
||||
OW_DRIVE();
|
||||
udelay(tA);
|
||||
OW_RELEASE(); /* Releases the bus */
|
||||
udelay(tB);
|
||||
} else {
|
||||
OW_DRIVE();
|
||||
udelay(tC);
|
||||
OW_RELEASE(); /* Releases the bus */
|
||||
udelay(tD);
|
||||
}
|
||||
if (i == 0)
|
||||
return;
|
||||
i--;
|
||||
byte >>= 1;
|
||||
} while (1);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned
|
||||
read_byte(void)
|
||||
{
|
||||
unsigned result = 0;
|
||||
int i = 7;
|
||||
do {
|
||||
OW_DRIVE();
|
||||
udelay(tA);
|
||||
OW_RELEASE(); /* Releases the bus */
|
||||
udelay(tE);
|
||||
if (INP())
|
||||
result |= 0x80; /* LSbit first */
|
||||
udelay(tF);
|
||||
if (i == 0)
|
||||
return result;
|
||||
i--;
|
||||
result >>= 1;
|
||||
} while (1);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Polynomial ^8 + ^5 + ^4 + 1 */
|
||||
static unsigned
|
||||
crc8_add(unsigned acc, unsigned byte)
|
||||
{
|
||||
int i;
|
||||
acc ^= byte;
|
||||
for (i = 0; i < 8; i++)
|
||||
if (acc & 1)
|
||||
acc = (acc >> 1) ^ 0x8c;
|
||||
else
|
||||
acc >>= 1;
|
||||
|
||||
return acc;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
ds2401_init()
|
||||
{
|
||||
int i;
|
||||
uint8_t volatile sreg;
|
||||
unsigned family, crc, acc;
|
||||
|
||||
PIN_INIT();
|
||||
|
||||
sreg = SREG; /* Save status register before disabling interrupts. */
|
||||
cli(); /* Disable interrupts. */
|
||||
|
||||
if (reset() == 0) {
|
||||
write_byte(0x33); /* Read ROM command. */
|
||||
family = read_byte();
|
||||
for (i = 7; i >= 2; i--) {
|
||||
ds2401_id[i] = read_byte();
|
||||
}
|
||||
crc = read_byte();
|
||||
|
||||
SREG = sreg; /* Enable interrupts. */
|
||||
|
||||
if(family != 0x01) {
|
||||
goto fail;
|
||||
}
|
||||
acc = crc8_add(0x0, family);
|
||||
for (i = 7; i >= 2; i--) {
|
||||
acc = crc8_add(acc, ds2401_id[i]);
|
||||
}
|
||||
if (acc == crc) {
|
||||
/* 00:1A:4C OUI for Crossbow Technology, Inc. */
|
||||
ds2401_id[0] = 0x00;
|
||||
ds2401_id[1] = 0x1A;
|
||||
ds2401_id[2] = 0x4C;
|
||||
return 1; /* Success! */
|
||||
}
|
||||
} else {
|
||||
SREG = sreg; /* Enable interrupts. */
|
||||
}
|
||||
|
||||
fail:
|
||||
memset(ds2401_id, 0x0, sizeof(ds2401_id));
|
||||
return 0; /* Fail! */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
39
platform/iris/dev/ds2401.h
Normal file
39
platform/iris/dev/ds2401.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DS2401_H
|
||||
#define DS2401_H
|
||||
|
||||
extern unsigned char ds2401_id[8];
|
||||
extern int ds2401_init();
|
||||
|
||||
#endif /* DS2401_H */
|
67
platform/iris/dev/leds-arch.c
Normal file
67
platform/iris/dev/leds-arch.c
Normal file
@ -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 <kasun.ch@gmail.com>
|
||||
*/
|
||||
|
||||
#include "contiki-conf.h"
|
||||
#include "dev/leds.h"
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
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);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
103
platform/iris/dev/sensors/battery-sensor.c
Normal file
103
platform/iris/dev/sensors/battery-sensor.c
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 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
|
||||
* Battery sensor driver.
|
||||
* \author
|
||||
* Kasun Hewage <kasun.ch@gmail.com>
|
||||
*/
|
||||
|
||||
#include <avr/io.h>
|
||||
#include "dev/battery-sensor.h"
|
||||
#include "dev/adc.h"
|
||||
|
||||
|
||||
#define BAT_MONITOR_PORT PORTF
|
||||
#define BAT_MONITOR_PIN_MASK _BV(1)
|
||||
#define BAT_MONITOR_PORT_DDR DDRF
|
||||
#define BAT_MONITOR_ADC_CHANNEL 30
|
||||
|
||||
const struct sensors_sensor battery_sensor;
|
||||
static uint8_t active;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
activate(void)
|
||||
{
|
||||
/* This assumes that some other sensor system already did setup the ADC */
|
||||
adc_init();
|
||||
|
||||
/* Enable battery sensor. */
|
||||
BAT_MONITOR_PORT |= BAT_MONITOR_PIN_MASK;
|
||||
BAT_MONITOR_PORT_DDR |= BAT_MONITOR_PIN_MASK;
|
||||
|
||||
active = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
deactivate(void)
|
||||
{
|
||||
active = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return get_adc(BAT_MONITOR_ADC_CHANNEL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
if (c) {
|
||||
activate();
|
||||
} else {
|
||||
deactivate();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return active;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR,
|
||||
value, configure, status);
|
221
platform/iris/dev/sensors/mts300.c
Normal file
221
platform/iris/dev/sensors/mts300.c
Normal file
@ -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 <kasun.ch@gmail.com>
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
112
platform/iris/dev/sensors/mts300.h
Normal file
112
platform/iris/dev/sensors/mts300.h
Normal file
@ -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 <kasun.ch@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef __MTS300_H__
|
||||
#define __MTS300_H__
|
||||
|
||||
#include <avr/io.h>
|
||||
#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__ */
|
||||
|
||||
|
||||
|
93
platform/iris/dev/slip_uart0.c
Normal file
93
platform/iris/dev/slip_uart0.c
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 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
|
||||
* Machine dependent AVR SLIP routines for UART0.
|
||||
* \author
|
||||
* Kasun Hewage <kasun.ch@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/rs232.h"
|
||||
#include "slip.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
slip_putchar(char c, FILE *stream)
|
||||
{
|
||||
#define SLIP_END 0300
|
||||
static char debug_frame = 0;
|
||||
|
||||
if (!debug_frame) { /* Start of debug output */
|
||||
slip_arch_writeb(SLIP_END);
|
||||
slip_arch_writeb('\r'); /* Type debug line == '\r' */
|
||||
debug_frame = 1;
|
||||
}
|
||||
|
||||
slip_arch_writeb((unsigned char)c);
|
||||
|
||||
/*
|
||||
* Line buffered output, a newline marks the end of debug output and
|
||||
* implicitly flushes debug output.
|
||||
*/
|
||||
if (c == '\n') {
|
||||
slip_arch_writeb(SLIP_END);
|
||||
debug_frame = 0;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static FILE slip_stdout = FDEV_SETUP_STREAM(slip_putchar, NULL,
|
||||
_FDEV_SETUP_WRITE);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
slip_arch_init(unsigned long ubr)
|
||||
{
|
||||
rs232_set_input(RS232_PORT_0, slip_input_byte);
|
||||
stdout = &slip_stdout;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
XXX:
|
||||
Currently, the following function is in cpu/avr/dev/rs232.c file. this
|
||||
should be moved to here from there hence this is a platform specific slip
|
||||
related function.
|
||||
void
|
||||
slip_arch_writeb(unsigned char c)
|
||||
{
|
||||
rs232_send(RS232_PORT_0, c);
|
||||
}
|
||||
*/
|
245
platform/iris/init-net.c
Normal file
245
platform/iris/init-net.c
Normal file
@ -0,0 +1,245 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 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
|
||||
* Network initialization for the MICAz port.
|
||||
* \author
|
||||
* Kasun Hewage <kasun.ch@gmail.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#include "contiki.h"
|
||||
#include "dev/cc2420.h"
|
||||
#include "dev/rs232.h"
|
||||
#include "dev/slip.h"
|
||||
#include "dev/leds.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/mac/frame802154.h"
|
||||
|
||||
#include "dev/ds2401.h"
|
||||
#include "node-id.h"
|
||||
|
||||
#if WITH_UIP6
|
||||
#include "net/uip-ds6.h"
|
||||
#endif /* WITH_UIP6 */
|
||||
|
||||
#if WITH_UIP
|
||||
#include "net/uip.h"
|
||||
#include "net/uip-fw.h"
|
||||
#include "net/uip-fw-drv.h"
|
||||
#include "net/uip-over-mesh.h"
|
||||
static struct uip_fw_netif slipif =
|
||||
{UIP_FW_NETIF(192,168,1,2, 255,255,255,255, slip_send)};
|
||||
static struct uip_fw_netif meshif =
|
||||
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
|
||||
|
||||
static uint8_t is_gateway;
|
||||
|
||||
#endif /* WITH_UIP */
|
||||
|
||||
#define UIP_OVER_MESH_CHANNEL 8
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
set_rime_addr(void)
|
||||
{
|
||||
rimeaddr_t addr;
|
||||
int i;
|
||||
|
||||
memset(&addr, 0, sizeof(rimeaddr_t));
|
||||
#if UIP_CONF_IPV6
|
||||
memcpy(addr.u8, ds2401_id, sizeof(addr.u8));
|
||||
#else
|
||||
if(node_id == 0) {
|
||||
for(i = 0; i < sizeof(rimeaddr_t); ++i) {
|
||||
addr.u8[i] = ds2401_id[7 - i];
|
||||
}
|
||||
} else {
|
||||
addr.u8[0] = node_id & 0xff;
|
||||
addr.u8[1] = node_id >> 8;
|
||||
}
|
||||
#endif
|
||||
rimeaddr_set_node_addr(&addr);
|
||||
printf_P(PSTR("Rime started with address "));
|
||||
for(i = 0; i < sizeof(addr.u8) - 1; i++) {
|
||||
printf_P(PSTR("%d."), addr.u8[i]);
|
||||
}
|
||||
printf_P(PSTR("%d\n"), addr.u8[i]);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
#if WITH_UIP
|
||||
static void
|
||||
set_gateway(void)
|
||||
{
|
||||
if(!is_gateway) {
|
||||
leds_on(LEDS_RED);
|
||||
printf_P(PSTR("%d.%d: making myself the IP network gateway.\n\n"),
|
||||
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
|
||||
printf_P(PSTR("IPv4 address of the gateway: %d.%d.%d.%d\n\n"),
|
||||
uip_ipaddr_to_quad(&uip_hostaddr));
|
||||
uip_over_mesh_set_gateway(&rimeaddr_node_addr);
|
||||
uip_over_mesh_make_announced_gateway();
|
||||
is_gateway = 1;
|
||||
}
|
||||
}
|
||||
#endif /* WITH_UIP */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
init_net(void)
|
||||
{
|
||||
|
||||
set_rime_addr();
|
||||
cc2420_init();
|
||||
{
|
||||
uint8_t longaddr[8];
|
||||
uint16_t shortaddr;
|
||||
|
||||
shortaddr = (rimeaddr_node_addr.u8[0] << 8) +
|
||||
rimeaddr_node_addr.u8[1];
|
||||
memset(longaddr, 0, sizeof(longaddr));
|
||||
rimeaddr_copy((rimeaddr_t *)&longaddr, &rimeaddr_node_addr);
|
||||
printf_P(PSTR("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n"),
|
||||
longaddr[0], longaddr[1], longaddr[2], longaddr[3],
|
||||
longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
|
||||
|
||||
cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr);
|
||||
}
|
||||
cc2420_set_channel(RF_CHANNEL);
|
||||
|
||||
|
||||
#if WITH_UIP6
|
||||
memcpy(&uip_lladdr.addr, ds2401_id, sizeof(uip_lladdr.addr));
|
||||
/* Setup nullmac-like MAC for 802.15.4 */
|
||||
/* sicslowpan_init(sicslowmac_init(&cc2420_driver)); */
|
||||
/* printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); */
|
||||
|
||||
/* Setup X-MAC for 802.15.4 */
|
||||
queuebuf_init();
|
||||
NETSTACK_RDC.init();
|
||||
NETSTACK_MAC.init();
|
||||
NETSTACK_NETWORK.init();
|
||||
|
||||
printf_P(PSTR("%s %s, channel check rate %d Hz, radio channel %d\n"),
|
||||
NETSTACK_MAC.name, NETSTACK_RDC.name,
|
||||
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0 ? 1:
|
||||
NETSTACK_RDC.channel_check_interval()),
|
||||
RF_CHANNEL);
|
||||
|
||||
process_start(&tcpip_process, NULL);
|
||||
|
||||
printf_P(PSTR("Tentative link-local IPv6 address "));
|
||||
{
|
||||
uip_ds6_addr_t *lladdr;
|
||||
int i;
|
||||
lladdr = uip_ds6_get_link_local(-1);
|
||||
for(i = 0; i < 7; ++i) {
|
||||
printf_P(PSTR("%02x%02x:"), lladdr->ipaddr.u8[i * 2],
|
||||
lladdr->ipaddr.u8[i * 2 + 1]);
|
||||
}
|
||||
printf_P(PSTR("%02x%02x\n"), lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
|
||||
}
|
||||
|
||||
if(!UIP_CONF_IPV6_RPL) {
|
||||
uip_ipaddr_t ipaddr;
|
||||
int i;
|
||||
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
|
||||
uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
|
||||
uip_ds6_addr_add(&ipaddr, 0, ADDR_TENTATIVE);
|
||||
printf_P(PSTR("Tentative global IPv6 address "));
|
||||
for(i = 0; i < 7; ++i) {
|
||||
printf_P(PSTR("%02x%02x:"),
|
||||
ipaddr.u8[i * 2], ipaddr.u8[i * 2 + 1]);
|
||||
}
|
||||
printf_P(PSTR("%02x%02x\n"),
|
||||
ipaddr.u8[7 * 2], ipaddr.u8[7 * 2 + 1]);
|
||||
}
|
||||
|
||||
#else /* WITH_UIP6 */
|
||||
|
||||
NETSTACK_RDC.init();
|
||||
NETSTACK_MAC.init();
|
||||
NETSTACK_NETWORK.init();
|
||||
|
||||
printf_P(PSTR("%s %s, channel check rate %d Hz, radio channel %d\n"),
|
||||
NETSTACK_MAC.name, NETSTACK_RDC.name,
|
||||
CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval() == 0? 1:
|
||||
NETSTACK_RDC.channel_check_interval()),
|
||||
RF_CHANNEL);
|
||||
#endif /* WITH_UIP6 */
|
||||
|
||||
|
||||
#if WITH_UIP
|
||||
uip_ipaddr_t hostaddr, netmask;
|
||||
|
||||
uip_init();
|
||||
uip_fw_init();
|
||||
|
||||
process_start(&tcpip_process, NULL);
|
||||
process_start(&slip_process, NULL);
|
||||
process_start(&uip_fw_process, NULL);
|
||||
|
||||
slip_set_input_callback(set_gateway);
|
||||
|
||||
/* Construct ip address from four bytes. */
|
||||
uip_ipaddr(&hostaddr, 172, 16, rimeaddr_node_addr.u8[0],
|
||||
rimeaddr_node_addr.u8[1]);
|
||||
/* Construct netmask from four bytes. */
|
||||
uip_ipaddr(&netmask, 255,255,0,0);
|
||||
|
||||
uip_ipaddr_copy(&meshif.ipaddr, &hostaddr);
|
||||
/* Set the IP address for this host. */
|
||||
uip_sethostaddr(&hostaddr);
|
||||
/* Set the netmask for this host. */
|
||||
uip_setnetmask(&netmask);
|
||||
|
||||
uip_over_mesh_set_net(&hostaddr, &netmask);
|
||||
|
||||
/* Register slip interface with forwarding module. */
|
||||
//uip_fw_register(&slipif);
|
||||
uip_over_mesh_set_gateway_netif(&slipif);
|
||||
/* Set slip interface to be a default forwarding interface . */
|
||||
uip_fw_default(&meshif);
|
||||
uip_over_mesh_init(UIP_OVER_MESH_CHANNEL);
|
||||
printf_P(PSTR("uIP started with IP address %d.%d.%d.%d\n"),
|
||||
uip_ipaddr_to_quad(&hostaddr));
|
||||
#endif /* WITH_UIP */
|
||||
|
||||
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
46
platform/iris/init-net.h
Normal file
46
platform/iris/init-net.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 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
|
||||
* Network initialization for the MICAz port.
|
||||
* \author
|
||||
* Kasun Hewage <kasun.ch@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef __INIT_NET_H__
|
||||
#define __INIT_NET_H__
|
||||
|
||||
void init_net(void);
|
||||
|
||||
#endif /* __INIT_NET_H__ */
|
63
platform/iris/node-id.c
Normal file
63
platform/iris/node-id.c
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
uint16_t newid[2];
|
||||
uint8_t volatile sreg;
|
||||
|
||||
sreg = SREG; /* Save status register before disabling interrupts. */
|
||||
cli(); /* Disable interrupts. */
|
||||
eeprom_read(EEPROM_NODE_ID_START, (unsigned char *)newid, sizeof(newid));
|
||||
node_id = (newid[0] == 0xdead) ? newid[1] : 0;
|
||||
SREG = sreg; /* Enable interrupts. */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
node_id_burn(uint16_t id)
|
||||
{
|
||||
uint16_t buffer[2] = { 0xdead, id };
|
||||
uint8_t volatile sreg;
|
||||
|
||||
sreg = SREG; /* Save status register before disabling interrupts. */
|
||||
cli(); /* Disable interrupts. */
|
||||
eeprom_write(EEPROM_NODE_ID_START, (unsigned char *)buffer, sizeof(buffer));
|
||||
SREG = sreg; /* Enable interrupts. */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
45
platform/iris/node-id.h
Normal file
45
platform/iris/node-id.h
Normal file
@ -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 <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#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 */
|
195
platform/iris/platform-conf.h
Normal file
195
platform/iris/platform-conf.h
Normal file
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: platform-conf.h,v 1.1 2010/06/23 10:25:54 joxe Exp $
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* A brief description of what this file is
|
||||
* \author
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef __PLATFORM_CONF_H__
|
||||
#define __PLATFORM_CONF_H__
|
||||
|
||||
/*
|
||||
* Definitions below are dictated by the hardware and not really
|
||||
* changeable!
|
||||
*/
|
||||
#define PLATFORM PLATFORM_AVR
|
||||
|
||||
/*
|
||||
* MCU and clock rate.
|
||||
* MICAZ runs on 7.3728 MHz clock.
|
||||
*/
|
||||
#define MCU_MHZ 7
|
||||
|
||||
/* Clock ticks per second */
|
||||
#define CLOCK_CONF_SECOND 128
|
||||
|
||||
|
||||
/* LED 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
|
||||
|
||||
/* 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 EEPROM_NODE_ID_START 0x00
|
||||
|
||||
|
||||
#define NETSTACK_CONF_RADIO cc2420_driver
|
||||
|
||||
|
||||
/*
|
||||
* SPI bus configuration for the TMote Sky.
|
||||
*/
|
||||
|
||||
/* 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 - M25P80 external flash configuration.
|
||||
*/
|
||||
|
||||
#define FLASH_PWR 3 /* P4.3 Output */
|
||||
#define FLASH_CS 4 /* P4.4 Output */
|
||||
#define FLASH_HOLD 7 /* P4.7 Output */
|
||||
|
||||
/* Enable/disable flash access to the SPI bus (active low). */
|
||||
|
||||
#define SPI_FLASH_ENABLE() ( P4OUT &= ~BV(FLASH_CS) )
|
||||
#define SPI_FLASH_DISABLE() ( P4OUT |= BV(FLASH_CS) )
|
||||
|
||||
#define SPI_FLASH_HOLD() ( P4OUT &= ~BV(FLASH_HOLD) )
|
||||
#define SPI_FLASH_UNHOLD() ( P4OUT |= BV(FLASH_HOLD) )
|
||||
|
||||
/*
|
||||
* SPI bus - CC2420 pin configuration.
|
||||
*/
|
||||
|
||||
#define CC2420_CONF_SYMBOL_LOOP_COUNT 500
|
||||
|
||||
/*
|
||||
* SPI bus - CC2420 pin configuration.
|
||||
*/
|
||||
|
||||
#define FIFO_P 6
|
||||
#define FIFO 7
|
||||
#define CCA 6
|
||||
|
||||
#define SFD 4
|
||||
#define CSN 0
|
||||
#define VREG_EN 5
|
||||
#define RESET_N 6
|
||||
|
||||
|
||||
/* - Input: FIFOP from CC2420 - ATMEGA128 PORTE, PIN6 */
|
||||
#define CC2420_FIFOP_PORT(type) P##type##E
|
||||
#define CC2420_FIFOP_PIN 6
|
||||
/* - Input: FIFO from CC2420 - ATMEGA128 PORTB, PIN7 */
|
||||
#define CC2420_FIFO_PORT(type) P##type##B
|
||||
#define CC2420_FIFO_PIN 7
|
||||
/* - Input: CCA from CC2420 - ATMEGA128 PORTD, PIN6 */
|
||||
#define CC2420_CCA_PORT(type) P##type##D
|
||||
#define CC2420_CCA_PIN 6
|
||||
/* - Input: SFD from CC2420 - ATMEGA128 PORTD, PIN4 */
|
||||
#define CC2420_SFD_PORT(type) P##type##D
|
||||
#define CC2420_SFD_PIN 4
|
||||
/* - Output: SPI Chip Select (CS_N) - ATMEGA128 PORTB, PIN0 */
|
||||
#define CC2420_CSN_PORT(type) P##type##B
|
||||
#define CC2420_CSN_PIN 0
|
||||
/* - Output: VREG_EN to CC2420 - ATMEGA128 PORTA, PIN5 */
|
||||
#define CC2420_VREG_PORT(type) P##type##A
|
||||
#define CC2420_VREG_PIN 5
|
||||
/* - Output: RESET_N to CC2420 - ATMEGA128 PORTA, PIN6 */
|
||||
#define CC2420_RESET_PORT(type) P##type##A
|
||||
#define CC2420_RESET_PIN 6
|
||||
|
||||
#define CC2420_IRQ_VECTOR INT6_vect
|
||||
|
||||
/* Pin status. */
|
||||
#define CC2420_FIFOP_IS_1 (!!(CC2420_FIFOP_PORT(IN) & BV(CC2420_FIFOP_PIN)))
|
||||
#define CC2420_FIFO_IS_1 (!!(CC2420_FIFO_PORT(IN) & BV(CC2420_FIFO_PIN)))
|
||||
#define CC2420_CCA_IS_1 (!!(CC2420_CCA_PORT(IN) & BV(CC2420_CCA_PIN)))
|
||||
#define CC2420_SFD_IS_1 (!!(CC2420_SFD_PORT(IN) & BV(CC2420_SFD_PIN)))
|
||||
|
||||
/* The CC2420 reset pin. */
|
||||
#define SET_RESET_INACTIVE() (CC2420_RESET_PORT(ORT) |= BV(CC2420_RESET_PIN))
|
||||
#define SET_RESET_ACTIVE() (CC2420_RESET_PORT(ORT) &= ~BV(CC2420_RESET_PIN))
|
||||
|
||||
/* CC2420 voltage regulator enable pin. */
|
||||
#define SET_VREG_ACTIVE() (CC2420_VREG_PORT(ORT) |= BV(CC2420_VREG_PIN))
|
||||
#define SET_VREG_INACTIVE() (CC2420_VREG_PORT(ORT) &= ~BV(CC2420_VREG_PIN))
|
||||
|
||||
/* CC2420 rising edge trigger for external interrupt 6 (FIFOP).
|
||||
* Enable the external interrupt request for INT6.
|
||||
* See Atmega128 datasheet about EICRB Register
|
||||
*/
|
||||
#define CC2420_FIFOP_INT_INIT() do {\
|
||||
EICRB |= 0x30; \
|
||||
CC2420_CLEAR_FIFOP_INT(); \
|
||||
} while (0)
|
||||
|
||||
/* FIFOP on external interrupt 6. */
|
||||
#define CC2420_ENABLE_FIFOP_INT() do { EIMSK |= 0x40; } while (0)
|
||||
#define CC2420_DISABLE_FIFOP_INT() do { EIMSK &= ~0x40; } while (0)
|
||||
#define CC2420_CLEAR_FIFOP_INT() do { EIFR = 0x40; } while (0)
|
||||
|
||||
/*
|
||||
* Enables/disables CC2420 access to the SPI bus (not the bus).
|
||||
* (Chip Select)
|
||||
*/
|
||||
#define CC2420_SPI_ENABLE() (PORTB &= ~BV(CSN)) /* ENABLE CSn (active low) */
|
||||
#define CC2420_SPI_DISABLE() (PORTB |= BV(CSN)) /* DISABLE CSn (active low) */
|
||||
|
||||
#endif /* __PLATFORM_CONF_H__ */
|
Loading…
Reference in New Issue
Block a user