Enhanced UI in tos-deluge (more explicit messages for -p, progress-bar for -i and messages explaining what should happen).
Script for testing more than one mote.
{
dbg("BlinkC", "Timer 0 fired @ %s.\n", sim_time_string());
#ifndef BLINK_REVERSE
- call Leds.led1Toggle();
+ call Leds.led0Toggle();
#else
call Leds.led2Toggle();
#endif
make clean
-echo ==================== Compile and load Blink ====================
+echo ============================ Compile and load Blink ============================
if [ $PLATFORM == 'micaz' ]
then
- CFLAGS=-DDELUGE_BASESTATION make $PLATFORM install mib510,$PORT
+ CFLAGS=-DDELUGE_BASESTATION make ${PLATFORM} install mib510,${PORT}
elif [ $PLATFORM == 'telosb' ]
then
- CFLAGS=-DDELUGE_BASESTATION make $PLATFORM install bsl,$PORT
+ CFLAGS=-DDELUGE_BASESTATION make ${PLATFORM} install bsl,${PORT}
fi
-echo ==================== Compile a new Blink ====================
-CFLAGS=-DBLINK_REVERSE\ -DDELUGE_BASESTATION make $PLATFORM
+echo ' +-------------------------------------------------------+'
+echo ' | |'
+echo ' | At this point the first led (red) should be blinking. |'
+echo ' | |'
+echo ' | Press ENTER to continue... |'
+echo ' | |'
+echo ' +-------------------------------------------------------+'
+read
-echo ==================== Upload the image ====================
-${TOS_DELUGE} $PORT $PLATFORM -i 0 build/$PLATFORM/tos_image.xml
+echo ============================= Compile a new Blink ==============================
+CFLAGS=-DBLINK_REVERSE\ -DDELUGE_BASESTATION make ${PLATFORM}
-echo ==================== Reboot ====================
-${TOS_DELUGE} $PORT $PLATFORM -r 0
+echo =============================== Upload the image ===============================
+${TOS_DELUGE} ${PORT} ${PLATFORM} -i 0 build/${PLATFORM}/tos_image.xml
+
+echo ' +----------------------------------------------------------------+'
+echo ' | |'
+echo ' | After pressing enter the following things will take place: |'
+echo ' | - mote will be rebooted |'
+echo ' | - all the leds will blink for some time as the |'
+echo ' | reprogramming by tosboot takes place. |'
+echo ' | - a fading of the leds will indicate the exiting from tosboot. |'
+echo ' | - the mote should start blinking the 3rd led (blue/yellow). |'
+echo ' | |'
+echo ' | Press ENTER to continue... |'
+echo ' | |'
+echo ' +----------------------------------------------------------------+'
+read
+
+echo =========================== Reboot the base station ============================
+${TOS_DELUGE} ${PORT} ${PLATFORM} -b 0
--- /dev/null
+#!/bin/bash
+
+TOS_DELUGE=`type -p tos-deluge`
+if [[ ! -x ${TOS_DELUGE} ]] ; then
+ TOS_DELUGE=../../../../tools/tinyos/misc/tos-deluge
+fi
+
+echo ${TOS_DELUGE}
+
+if [ $# -ne 2 ]; then
+ echo "Usage: $0 <platform> <number of motes>"
+ echo "<platform> \"micaz\", \"telosb\""
+ echo "<number of motes> how many motes will be used in the test"
+ exit 2
+fi
+
+PLATFORM=$1
+NO_MOTES=$2
+
+if [ ${PLATFORM} != 'micaz' -a ${PLATFORM} != 'telosb' ]; then
+ echo "\"$2\" is not a supported platform"
+ exit 2
+fi
+
+echo ================================ Compile Blink =================================
+make clean
+CFLAGS=-DDELUGE_BASESTATION make ${PLATFORM}
+ID=0
+
+function burn_one() {
+ ID=`expr $ID + 1`
+ echo -n ">>> Please plug mote $ID and type the port to continue: "
+ read PORT
+
+ if [ ${PLATFORM} == 'micaz' ]
+ then
+ CFLAGS=-DDELUGE_BASESTATION make ${PLATFORM} reinstall,$ID mib510,${PORT}
+ elif [ ${PLATFORM} == 'telosb' ]
+ then
+ CFLAGS=-DDELUGE_BASESTATION make ${PLATFORM} reinstall,$ID bsl,${PORT}
+ fi
+
+}
+
+while [[ ${NO_MOTES} > 0 ]]
+do
+ burn_one
+ NO_MOTES=`expr ${NO_MOTES} - 1`
+done
+
+echo ' +------------------------------------------------------------------------+'
+echo ' | |'
+echo ' | At this point the first led (red) of all the motes should be blinking. |'
+echo ' | |'
+echo ' | Press ENTER to continue... |'
+echo ' | |'
+echo ' +------------------------------------------------------------------------+'
+read
+
+echo ============================= Compile a new Blink ==============================
+CFLAGS=-DBLINK_REVERSE\ -DDELUGE_BASESTATION make ${PLATFORM}
+
+echo ========= Upload the new image to the external flash of the last mote ==========
+${TOS_DELUGE} ${PORT} ${PLATFORM} -i 0 build/${PLATFORM}/tos_image.xml
+
+echo ' +-----------------------------------------+'
+echo ' | |'
+echo ' | Press ENTER to start the dissemination. |'
+echo ' | |'
+echo ' +-----------------------------------------+'
+read
+
+echo ============================= Start dissemination ==============================
+${TOS_DELUGE} ${PORT} ${PLATFORM} -d 0
+
+echo ' +--------------------------------------------------+'
+echo ' | |'
+echo ' | Press ENTER when the second led (green) from all |'
+echo ' | the motes except the last one stops blinking. |'
+echo ' | |'
+echo ' +--------------------------------------------------+'
+read
+
+echo ===================== Trigger the reboot in the new image ======================
+${TOS_DELUGE} ${PORT} ${PLATFORM} -r 0
+
+echo ' +-------------------------------------------------------------+'
+echo ' | |'
+echo ' | All the motes except the last one should reboot, reprogram |'
+echo ' | the internal flash with the new image and start running it. |'
+echo ' | The end result should be that the last led (blue/yellow) |'
+echo ' | from all the motes except the last one is blinking. |'
+echo ' | |'
+echo ' +-------------------------------------------------------------+'
+
DELUGE_DIR ?= $(TOSDIR)/lib/net/Deluge
DELUGE_EXTRA ?= $(DELUGE_DIR)/extra
-TOSBOOT_DIR ?= $(TOSDIR)/lib/TOSBoot/build
+TOSBOOT_DIR ?= $(TOSDIR)/lib/tosboot/build
ifeq ($(TINYOS_NP),BNP)
# "./tos-deluge"
###############################################################################
-import sys, os, stat, struct, subprocess
+import sys, os, stat, struct, subprocess, time
import tinyos
from datetime import datetime
import os.path
return r
+# Checks for valid CRC and image timestamp
+def verifyMetaData(r):
+ if r != None:
+ if crc16(r[6:8]) == toInt(r[8:10]) and r[84:88] != [0xFF, 0xFF, 0xFF, 0xFF]:
+ return True
+ else:
+ print "WARNING: Invalid image format detected"
+
+ return False
+
# Returns the metadata (first 16 bytes of the image) plus the "ident"
# (DELUGE_IDENT_SIZE bytes after CRC)
def getMetaData(s, img_num):
temp = op_read(s, img_num, DELUGE_IDENT_OFFSET, DELUGE_IDENT_SIZE)
if temp != None:
r.extend(temp)
- else:
- r = None
-
- # Checks for valid CRC and image timestamp
- if r != None:
- if crc16(r[6:8]) == toInt(r[8:10]) and r[84:88] != [0xFF, 0xFF, 0xFF, 0xFF]:
return r
-
- print "ERROR: Unable to retrieve image information"
+
+ print "ERROR: Unable to retrieve image information over serial"
return None
# Prints status of the image in the external flash
def op_ping(s, img_num):
metadata = getMetaData(s, img_num)
if not metadata == None:
- print "Connected to Deluge node."
- # Prints out image status
- print "--------------------------------------------------"
- print "Stored image %d" % img_num
- print toStatusStr(2, metadata)
- print "--------------------------------------------------"
- return True
+ if verifyMetaData(metadata) == True:
+ print "Connected to Deluge node."
+ # Prints out image status
+ print "--------------------------------------------------"
+ print "Stored image %d" % img_num
+ print toStatusStr(2, metadata)
+ print "--------------------------------------------------"
+ return True
- print "No proper Deluge image found!"
return False
# Erases an image volume
sreqpkt = SerialReqPacket((MSG_WRITE, img_num, 0, 0, []))
local_crc = 0 # Running CRC
length = len(binary_stream)
+ total_length = length # For progress bar
+ next_tick = 100 # For progress bar
+ start_time = time.time()
+ print "[0% 25% 50% 75% 100%]\r[",
+
sreqpkt.offset = 0
while length > 0:
+ if ((length * 100) / total_length) < next_tick:
+ next_tick = next_tick - 2
+ sys.stdout.write('-')
+ sys.stdout.flush()
+
# Calculates the payload size for the current packet
if length >= SERIAL_DATA_LENGTH:
sreqpkt.len = SERIAL_DATA_LENGTH
# Sends over serial to the mote
if s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload()) == False:
+ print
print "ERROR: Unable to send the last serial packet (file offset: %d)" % sreqpkt.offset
return False
packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
sreplypkt = SerialReplyPacket(packet[1])
if sreplypkt.error != ERROR_SUCCESS:
+ print
print "ERROR: Unable to write to the flash volume (file offset: %d)" % sreqpkt.offset
return False
local_crc = s.crc16(local_crc, sreqpkt.data) # Computes running CRC
length -= sreqpkt.len
sreqpkt.offset += sreqpkt.len
-
+
+ print '\r' + ' ' * 52,
+ elasped_time = time.time() - start_time
+ print "\r%s bytes in %.2f seconds (%.4f bytes/s)" % (total_length, elasped_time, int(total_length) / (elasped_time))
return True
# Injects an image (specified by tos_image_xml) to an image volume
return False
# Gets status information of stored image
- metadata = getMetaData(s, img_num)
- print "Connected to Deluge nodes."
- print "--------------------------------------------------"
- print "Stored image %d" % img_num
version = 0
+ metadata = getMetaData(s, img_num)
if not metadata == None:
- version = toInt(metadata[4:6]) + 1 # Increments the version
- print toStatusStr(2, metadata)
+ print "Connected to Deluge nodes."
+ if verifyMetaData(metadata) == True:
+ print "--------------------------------------------------"
+ print "Stored image %d" % img_num
+ print toStatusStr(2, metadata)
+ version = toInt(metadata[4:6]) + 1 # Increments the version
else:
- print " No proper Deluge image found!"
- print "--------------------------------------------------"
+ return False
# Creates binary image from the TOS image XML
+ print "--------------------------------------------------"
p = subprocess.Popen([PATH_PY_BUILD_IMAGE, "-v", str(version), "-i", str(img_num), tos_image_xml], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print p.stderr.read(),
print "--------------------------------------------------"
# Writes the new binary image
if op_erase(s, img_num):
if op_write(s, img_num, p.stdout.read()):
+ print "--------------------------------------------------"
metadata = getMetaData(s, img_num)
- if not metadata == None:
- print "Replace image with:"
- print toStatusStr(2, metadata)
- print "--------------------------------------------------"
-
- return True
+ if not metadata == None:
+ if verifyMetaData(metadata) == True:
+ print "Replace image with:"
+ print toStatusStr(2, metadata)
+ print "--------------------------------------------------"
+ return True
return False
# Requests the base station to reprogram itself
def op_reprog_bs(s, img_num):
- if getMetaData(s, img_num) == None:
- print "ERROR: No proper Deluge image found!"
- else:
- sreqpkt = SerialReqPacket((MSG_REPROG_BS, img_num, 0, 0, []))
- success = s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload())
- if success == True:
- packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
- sreplypkt = SerialReplyPacket(packet[1])
- if sreplypkt.error == ERROR_SUCCESS:
- return True
- else:
- print "ERROR: Unable to reprogram the base station"
- return False
-
- print "ERROR: Unable to send the command"
+ metadata = getMetaData(s, img_num)
+ if not metadata == None:
+ if verifyMetaData(metadata) == True:
+ sreqpkt = SerialReqPacket((MSG_REPROG_BS, img_num, 0, 0, []))
+ success = s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload())
+ if success == True:
+ packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
+ sreplypkt = SerialReplyPacket(packet[1])
+ if sreplypkt.error == ERROR_SUCCESS:
+ return True
+ else:
+ print "ERROR: Unable to reprogram the base station"
+
+ print "ERROR: Unable to send the command"
+
return False
# Requests the network to reprogram with the specified image number
# Requests the mote to disseminate an image
def op_diss(s, img_num):
- if getMetaData(s, img_num) == None:
- print "ERROR: No proper Deluge image found!"
- else:
- sreqpkt = SerialReqPacket((MSG_DISS, img_num, 0, 0, []))
- success = s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload())
- if success == True:
- packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
- sreplypkt = SerialReplyPacket(packet[1])
- if sreplypkt.error == ERROR_SUCCESS:
- return True
- else:
- print "ERROR: Unable to start the command dissemination"
- return False
+ metadata = getMetaData(s, img_num)
+ if not metadata == None:
+ if verifyMetaData(metadata) == True:
+ sreqpkt = SerialReqPacket((MSG_DISS, img_num, 0, 0, []))
+ success = s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload())
+ if success == True:
+ packet = s.read_packet(SERIAL_AMGROUP, SERIAL_AMID)
+ sreplypkt = SerialReplyPacket(packet[1])
+ if sreplypkt.error == ERROR_SUCCESS:
+ return True
+ else:
+ print "ERROR: Unable to start the command dissemination"
+
+ print "ERROR: Unable to send the command"
- print "ERROR: Unable to send the command"
return False
-
+
# Resets image versioning information
def op_reset(s, img_num):
sreqpkt = SerialReqPacket((MSG_WRITE, img_num, 4, 2, [0, 0]))
if s.write_packet(SERIAL_AMGROUP, SERIAL_AMID, sreqpkt.payload()) == False:
- print "ERROR: Unable to send the last serial packet (file offset: %d)" % sreqpkt.offset
+ print "ERROR: Unable to send the command"
return False
# Waiting for confirmation
return False
return True
-
+
def print_usage():
print "Usage: %s <device_port> <baud_rate> <-p|-i|-r|-d|-e|-s> image_number [options]" % sys.argv[0]
print " <baud_rate>\n Either the platform name or the baud rate value"
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-#ifndef __DELUGE_H__
-#define __DELUGE_H__
-
-#include "DelugeMetadata.h"
-#include "TOSBoot.h"
-
-#ifndef DELUGE_NUM_IMAGES
-#define DELUGE_NUM_IMAGES 3
-#endif
-
-enum {
- DELUGE_VERSION = 2,
- DELUGE_MAX_ADV_PERIOD_LOG2 = 22,
- DELUGE_NUM_NEWDATA_ADVS_REQUIRED = 2,
- DELUGE_NUM_MIN_ADV_PERIODS = 2,
- DELUGE_MAX_NUM_REQ_TRIES = 1,
- DELUGE_REBOOT_DELAY = 4,
- DELUGE_FAILED_SEND_DELAY = 16,
- DELUGE_MIN_DELAY = 16,
- DELUGE_PKTS_PER_PAGE = 48,
- DELUGE_PKT_PAYLOAD_SIZE = 23,
- DELUGE_DATA_OFFSET = 128,
- DELUGE_IDENT_SIZE = 128,
- DELUGE_INVALID_ADDR = (0x7fffffffL),
- DELUGE_MAX_REQ_DELAY = (0x1L << (DELUGE_MIN_ADV_PERIOD_LOG2-1)),
- DELUGE_NACK_TIMEOUT = (DELUGE_MAX_REQ_DELAY >> 0x1),
- DELUGE_BYTES_PER_PAGE = (DELUGE_PKTS_PER_PAGE*DELUGE_PKT_PAYLOAD_SIZE),
- DELUGE_PKT_BITVEC_SIZE = (((DELUGE_PKTS_PER_PAGE-1) / 8) + 1),
- DELUGE_MAX_IMAGE_SIZE = (128L*1024L),
- DELUGE_MAX_PAGES = 128,
- DELUGE_CRC_SIZE = sizeof(uint16_t),
- DELUGE_CRC_BLOCK_SIZE = DELUGE_MAX_PAGES*DELUGE_CRC_SIZE,
- DELUGE_GOLDEN_IMAGE_NUM = 0x0,
- DELUGE_INVALID_VNUM = -1,
- DELUGE_INVALID_IMGNUM = 0xff,
- DELUGE_INVALID_PKTNUM = 0xff,
- DELUGE_INVALID_PGNUM = 0xff,
-};
-
-#include "Storage.h"
-
-struct deluge_image_t {
- imgnum_t imageNum;
- volume_id_t volumeId;
-};
-
-typedef struct DelugeAdvTimer {
- uint32_t timer : 32;
- uint8_t periodLog2 : 8;
- bool overheard : 1;
- uint8_t newAdvs : 7;
-} DelugeAdvTimer;
-
-typedef struct DelugeNodeDesc {
- imgvnum_t vNum;
- uint32_t uid;
- imgnum_t imgNum;
- uint8_t reserved;
- uint16_t crc;
-} DelugeNodeDesc;
-
-enum {
- DELUGE_VOLUME_ID_0 = unique("StorageManager"),
-#if DELUGE_NUM_IMAGES >= 2
- DELUGE_VOLUME_ID_1 = unique("StorageManager"),
-#if DELUGE_NUM_IMAGES >= 3
- DELUGE_VOLUME_ID_2 = unique("StorageManager"),
-#if DELUGE_NUM_IMAGES >= 4
- DELUGE_VOLUME_ID_3 = unique("StorageManager"),
-#if DELUGE_NUM_IMAGES >= 5
- DELUGE_VOLUME_ID_4 = unique("StorageManager"),
-#if DELUGE_NUM_IMAGES >= 6
- DELUGE_VOLUME_ID_5 = unique("StorageManager"),
-#if DELUGE_NUM_IMAGES >= 7
- DELUGE_VOLUME_ID_6 = unique("StorageManager"),
-#if DELUGE_NUM_IMAGES >= 8
- DELUGE_VOLUME_ID_7 = unique("StorageManager"),
-#endif
-#endif
-#endif
-#endif
-#endif
-#endif
-#endif
-};
-
-static const struct deluge_image_t DELUGE_IMAGES[DELUGE_NUM_IMAGES] = {
- { DELUGE_VOLUME_ID_0, 0xDF },
-#if DELUGE_NUM_IMAGES >= 2
- { DELUGE_VOLUME_ID_1, 0xD0 },
-#if DELUGE_NUM_IMAGES >= 3
- { DELUGE_VOLUME_ID_2, 0xD1 },
-#if DELUGE_NUM_IMAGES >= 4
- { DELUGE_VOLUME_ID_3, 0xD2 },
-#if DELUGE_NUM_IMAGES >= 5
- { DELUGE_VOLUME_ID_4, 0xD3 },
-#if DELUGE_NUM_IMAGES >= 6
- { DELUGE_VOLUME_ID_5, 0xD4 },
-#if DELUGE_NUM_IMAGES >= 7
- { DELUGE_VOLUME_ID_6, 0xD5 },
-#if DELUGE_NUM_IMAGES >= 8
- { DELUGE_VOLUME_ID_7, 0xD6 },
-#endif
-#endif
-#endif
-#endif
-#endif
-#endif
-#endif
-};
-
-#endif
+++ /dev/null
-
-interface Exec {
- command void exec();
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-interface ExtFlash {
- command void startRead(uint32_t addr);
- command uint8_t readByte();
- command void stopRead();
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-interface Hardware {
- command void init();
- command void reboot();
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-interface Leds {
- command void set(uint8_t ledsOn);
- command void flash(uint8_t a);
- command void glow(uint8_t a, uint8_t b);
-}
+++ /dev/null
-# $Id$
-
-# tab:2
-#
-#
-# "Copyright (c) 2000-2005 The Regents of the University of California.
-# All rights reserved.
-#
-# Permission to use, copy, modify, and distribute this software and its
-# documentation for any purpose, without fee, and without written agreement is
-# hereby granted, provided that the above copyright notice, the following
-# two paragraphs and the author appear in all copies of this software.
-#
-# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
-# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
-# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
-# CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
-# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-# AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
-# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
-# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
-#
-#
-
-#
-# @author Jonathan Hui <jwhui@cs.berkeley.edu>
-#
-
-COMPONENT=TOSBoot
-TINYOS_NP=
-
-PFLAGS += -DNESC_BUILD_BINARY
-
-# ifeq ($(MAKECMDGOALS),mica2)
-# CFLAGS += -DTOSBOOT_START=0x1f000 -DTOSBOOT_END=0x20000
-# CFLAGS += -Wl,--section-start=.text=0x1f000
-# CFLAGS += -Iat45db -Iavr -Imica2 -Ilib
-# endif
-
-# ifeq ($(MAKECMDGOALS),mica2dot)
-# CFLAGS += -DTOSBOOT_START=0x1f000 -DTOSBOOT_END=0x20000
-# CFLAGS += -Wl,--section-start=.text=0x1f000
-# CFLAGS += -Iat45db -Iavr -Imica2dot -Ilib
-# endif
-
-ifeq ($(MAKECMDGOALS),micaz)
- CFLAGS += -DTOSBOOT_START=0x1f000 -DTOSBOOT_END=0x20000
- CFLAGS += -Wl,--section-start=.text=0x1f000
- CFLAGS += -Iat45db -Iavr -Imicaz -Ilib
- CFLAGS += -I../net/Deluge
-endif
-
-# ifeq ($(MAKECMDGOALS),telosa)
-# CFLAGS += -DTOSBOOT_START=0x1100 -DTOSBOOT_END=0x1a00
-# CFLAGS += -Iat45db -Imsp430 -Itelos -Ilib
-# POST_BUILD_EXTRA_DEPS += strip_iv
-# endif
-
-ifeq ($(MAKECMDGOALS),telosb)
- CFLAGS += -DTOSBOOT_START=0x4000 -DTOSBOOT_END=0x4a00
- CFLAGS += -Imsp430 -Istm25p -Itelosb -Ilib
- CFLAGS += -I../net/Deluge
- POST_BUILD_EXTRA_DEPS += strip_iv
-endif
-
-strip_iv: FORCE
- @echo " removing interrupt vector from binary"
- msp430-objcopy -j .text -j .data -O ihex $(BUILDDIR)/main.exe $(BUILDDIR)/main.ihex
-
-include $(MAKERULES)
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-interface ProgFlash {
- command error_t write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len);
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-#ifndef __TOSBOOT_H__
-#define __TOSBOOT_H__
-
-#include "TOSBoot_platform.h"
-
-typedef struct tosboot_args_t {
- uint32_t imageAddr;
- uint8_t gestureCount;
- bool noReprogram;
-} tosboot_args_t;
-
-#endif
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-includes Deluge;
-includes TOSBoot;
-
-configuration TOSBoot {
-}
-implementation {
-
- components
- TOSBootM,
- ExecC,
- ExtFlashC,
- HardwareC,
- InternalFlashC as IntFlash,
- LedsC,
- PluginC,
- ProgFlashM as ProgFlash,
- VoltageC;
-
- TOSBootM.SubInit -> ExtFlashC;
- TOSBootM.SubControl -> ExtFlashC.StdControl;
- TOSBootM.SubControl -> PluginC;
-
- TOSBootM.Exec -> ExecC;
- TOSBootM.ExtFlash -> ExtFlashC;
- TOSBootM.Hardware -> HardwareC;
- TOSBootM.IntFlash -> IntFlash;
- TOSBootM.Leds -> LedsC;
- TOSBootM.ProgFlash -> ProgFlash;
- TOSBootM.Voltage -> VoltageC;
-
-}
+++ /dev/null
-/*
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- * Copyright (c) 2007 Johns Hopkins University.
- * All rights reserved.
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
- * @author Razvan Musaloiu-E. <razvanm@cs.jhu.edu>
- */
-
-includes crc;
-includes hardware;
-
-module TOSBootM {
- uses {
- interface Exec;
- interface ExtFlash;
- interface Hardware;
- interface InternalFlash as IntFlash;
- interface Leds;
- interface ProgFlash;
- interface StdControl as SubControl;
- interface Init as SubInit;
- interface Voltage;
- }
-}
-implementation {
-
- enum {
- LEDS_LOWBATT = 1,
- LEDS_GESTURE = 7,
- };
-
- enum {
- R_SUCCESS,
- R_INVALID_IMAGE_ERROR,
- R_PROGRAMMING_ERROR,
- };
-
- void startupLeds() {
-
- uint8_t output = 0x7;
- uint8_t i;
-
- for (i = 3; i; i--, output >>= 1 )
- call Leds.glow(output, output >> 1);
-
- }
-
- in_flash_addr_t extFlashReadAddr() {
- in_flash_addr_t result = 0;
- uint8_t i;
- for ( i = 0; i < 4; i++ )
- result |= ((in_flash_addr_t)call ExtFlash.readByte() & 0xff) << (i*8);
- return result;
- }
-
- bool verifyImage(ex_flash_addr_t startAddr) {
-
- uint16_t crcTarget = 0, crcTmp = 0;
- uint16_t addr, len;
- pgnum_t numPgs;
- uint8_t i;
-
- // read size of image
- call ExtFlash.startRead(startAddr + offsetof(DelugeImgDesc,numPgs));
- numPgs = call ExtFlash.readByte();
- call ExtFlash.stopRead();
-
- if (numPgs == 0 || numPgs == 0xff)
- return FALSE;
-
- startAddr += DELUGE_METADATA_SIZE;
-
- addr = DELUGE_CRC_BLOCK_SIZE;
- len = DELUGE_BYTES_PER_PAGE-DELUGE_CRC_BLOCK_SIZE;
-
- for ( i = 0; i < numPgs && crcTarget == crcTmp; i++ ) {
-
- // read crc
- call ExtFlash.startRead(startAddr + i*sizeof(uint16_t));
- crcTarget = (uint16_t)(call ExtFlash.readByte() & 0xff);
- crcTarget |= (uint16_t)(call ExtFlash.readByte() & 0xff) << 8;
- call ExtFlash.stopRead();
-
- // compute crc
- call ExtFlash.startRead(startAddr + addr);
- for ( crcTmp = 0; len; len-- )
- crcTmp = crcByte(crcTmp, call ExtFlash.readByte());
- call ExtFlash.stopRead();
-
- addr = (uint16_t)(i+1)*DELUGE_BYTES_PER_PAGE;
- len = DELUGE_BYTES_PER_PAGE;
- }
-
- return (i == numPgs) && (crcTarget == crcTmp);
- }
-
- error_t programImage(ex_flash_addr_t startAddr) {
-
- uint8_t buf[TOSBOOT_INT_PAGE_SIZE];
- uint16_t pageAddr, newPageAddr;
- in_flash_addr_t intAddr;
- in_flash_addr_t secLength;
- ex_flash_addr_t curAddr;
-
- if (!verifyImage(startAddr))
- return R_INVALID_IMAGE_ERROR;
-
- curAddr = startAddr + DELUGE_METADATA_SIZE + DELUGE_CRC_BLOCK_SIZE + DELUGE_IDENT_SIZE;
-
- call ExtFlash.startRead(curAddr);
-
- intAddr = extFlashReadAddr();
- secLength = extFlashReadAddr();
- curAddr = curAddr + 8;
-
-#if defined(PLATFORM_TELOSB)
- if (intAddr != TOSBOOT_END) {
-#elif defined(PLATFORM_MICAZ)
- if (intAddr != 0) {
-#else
- #error "Target platform is not currently supported by Deluge T2"
-#endif
- call ExtFlash.stopRead();
- return R_INVALID_IMAGE_ERROR;
- }
-
- call ExtFlash.stopRead(); // MIKE_LIANG
-
- while ( secLength ) {
-
- pageAddr = newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE;
-
- call ExtFlash.startRead(curAddr);
- // fill in ram buffer for internal program flash sector
- do {
-
- // check if secLength is all ones
- if ( secLength == 0xffffffff ) {
- call ExtFlash.stopRead(); // MIKE_LIANG
- return FAIL;
- }
-
- buf[(uint16_t)intAddr % TOSBOOT_INT_PAGE_SIZE] = call ExtFlash.readByte();
- intAddr++; curAddr++;
-
- if ( --secLength == 0 ) {
- intAddr = extFlashReadAddr();
- secLength = extFlashReadAddr();
- curAddr = curAddr + 8;
- }
-
- newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE;
-
- } while ( pageAddr == newPageAddr && secLength );
- call ExtFlash.stopRead();
-
- call Leds.set(pageAddr);
-
-
- // write out page
- if (call ProgFlash.write(pageAddr*TOSBOOT_INT_PAGE_SIZE, buf,
- TOSBOOT_INT_PAGE_SIZE) == FAIL) {
- return R_PROGRAMMING_ERROR;
- }
- }
-
- return R_SUCCESS;
-
- }
-
- void runApp() {
- call SubControl.stop();
- call Exec.exec();
- }
-
- void startupSequence() {
-
- tosboot_args_t args;
-
- // check voltage and make sure flash can be programmed
- // if not, just run the app, can't check for gestures
- // if we can't write to the internal flash anyway
- if ( !call Voltage.okToProgram() ) {
- // give user some time and count down LEDs
- call Leds.flash(LEDS_LOWBATT);
- startupLeds();
- runApp();
- }
-
- // get current value of counter
- call IntFlash.read((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
-
- // increment gesture counter, see if it exceeds threshold
- if ( ++args.gestureCount >= TOSBOOT_GESTURE_MAX_COUNT - 1 ) {
- // gesture has been detected, display receipt of gesture on LEDs
- call Leds.flash(LEDS_GESTURE);
-
- // load golden image from flash
- // if the golden image is invalid, forget about reprogramming
- // if an error happened during reprogramming, reboot and try again
- // not much else we can do :-/
- if (programImage(TOSBOOT_GOLDEN_IMG_ADDR) == R_PROGRAMMING_ERROR) {
- call Hardware.reboot();
- }
- }
- else {
- // update gesture counter
- call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
- if ( !args.noReprogram ) {
- // if an error happened during reprogramming, reboot and try again
- // after two tries, try programming the golden image
- if (programImage(args.imageAddr) == R_PROGRAMMING_ERROR) {
- call Hardware.reboot();
- }
- }
- }
-
- // give user some time and count down LEDs
- startupLeds();
-
- // reset counter and reprogramming flag
- args.gestureCount = 0xff;
- args.noReprogram = TRUE;
- call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
-
- runApp();
-
- }
-
- int main() __attribute__ ((C, spontaneous)) {
-
- __nesc_disable_interrupt();
-
- TOSH_SET_PIN_DIRECTIONS();
- call Hardware.init();
-
- call SubInit.init();
- call SubControl.start();
-
- startupSequence();
-
- return 0;
-
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-interface Voltage {
- command bool okToProgram();
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module ExtFlashC {
- provides {
- interface Init;
- interface StdControl;
- interface ExtFlash;
- }
-}
-
-implementation {
-
- uint32_t addr;
-
- command error_t Init.init() {
- TOSH_MAKE_FLASH_CS_OUTPUT();
- TOSH_SET_FLASH_CS_PIN();
- TOSH_MAKE_FLASH_CLK_OUTPUT();
- TOSH_CLR_FLASH_CLK_PIN();
- TOSH_MAKE_FLASH_OUT_OUTPUT();
- TOSH_SET_FLASH_OUT_PIN();
- TOSH_MAKE_FLASH_IN_INPUT();
- TOSH_CLR_FLASH_IN_PIN();
- return SUCCESS;
- }
-
- command error_t StdControl.start() { return SUCCESS; }
- command error_t StdControl.stop() { return SUCCESS; }
-
- uint8_t SPIByte(uint8_t out) {
-
- uint8_t in = 0;
- uint8_t i;
-
- for ( i = 0; i < 8; i++, out <<= 1 ) {
-
- // write bit
- if (out & 0x80)
- TOSH_SET_FLASH_OUT_PIN();
- else
- TOSH_CLR_FLASH_OUT_PIN();
-
- // clock
- TOSH_SET_FLASH_CLK_PIN();
-
- // read bit
- in <<= 1;
- if (TOSH_READ_FLASH_IN_PIN())
- in |= 1;
-
- // clock
- TOSH_CLR_FLASH_CLK_PIN();
-
- }
-
- return in;
-
- }
-
- command void ExtFlash.startRead(uint32_t newAddr) {
-
- uint8_t cmdBuf[4];
- uint8_t i;
-
- addr = newAddr;
-
- cmdBuf[0] = 0x68;
- cmdBuf[1] = (addr >> 15) & 0xff;
- cmdBuf[2] = (addr >> 7) & 0xfe;
- cmdBuf[3] = addr & 0xff;
-
- TOSH_CLR_FLASH_CLK_PIN();
- TOSH_CLR_FLASH_CS_PIN();
-
- for(i = 0; i < 4; i++)
- SPIByte(cmdBuf[i]);
- for(i = 0; i < 4; i++)
- SPIByte(0x0);
-
- TOSH_SET_FLASH_CLK_PIN();
- TOSH_CLR_FLASH_CLK_PIN();
-
- }
-
- command uint8_t ExtFlash.readByte() {
- if (!(addr & 0xff)) {
- call ExtFlash.stopRead();
- call ExtFlash.startRead(addr);
- }
- addr++;
- return SPIByte(0);
- }
-
- command void ExtFlash.stopRead() {
- TOSH_SET_FLASH_CS_PIN();
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module HardwareC {
- provides {
- interface Hardware;
- }
-}
-
-implementation {
-
- command void Hardware.init() {}
-
- command void Hardware.reboot() {
- wdt_enable(1);
- while(1);
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-includes InternalFlash;
-
-module InternalFlashC {
- provides interface InternalFlash;
-}
-
-implementation {
-
- command error_t InternalFlash.write(void* addr, void* buf, uint16_t size) {
-
- uint8_t *addrPtr = (uint8_t*)addr;
- uint8_t *bufPtr = (uint8_t*)buf;
-
- for ( ; size; size-- )
- eeprom_write_byte(addrPtr++, *bufPtr++);
-
- while(!eeprom_is_ready());
-
- return SUCCESS;
-
- }
-
- command error_t InternalFlash.read(void* addr, void* buf, uint16_t size) {
-
- uint8_t *addrPtr = (uint8_t*)addr;
- uint8_t *bufPtr = (uint8_t*)buf;
-
- for ( ; size; size-- )
- *bufPtr++ = eeprom_read_byte(addrPtr++);
-
- return SUCCESS;
-
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module ProgFlashM {
- provides {
- interface ProgFlash;
- }
-}
-
-implementation {
-
-#include <boot.h>
-
- command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) {
-
- uint16_t* wordBuf = (uint16_t*)buf;
- uint32_t i;
-
- if ( addr + len > TOSBOOT_START )
- return FAIL;
-
- boot_page_erase( addr );
- while( boot_rww_busy() )
- boot_rww_enable();
-
- for ( i = 0; i < len; i += 2 )
- boot_page_fill( addr + i, *wordBuf++ );
-
- boot_page_write( addr );
-
- while ( boot_rww_busy() )
- boot_rww_enable();
-
- return SUCCESS;
-
- }
-
-}
+++ /dev/null
-/* Copyright (c) 2002, 2003, 2004 Eric B. Weddington\r
- All rights reserved.\r
-\r
- Redistribution and use in source and binary forms, with or without\r
- modification, are permitted provided that the following conditions are met:\r
-\r
- * Redistributions of source code must retain the above copyright\r
- notice, this list of conditions and the following disclaimer.\r
- * Redistributions in binary form must reproduce the above copyright\r
- notice, this list of conditions and the following disclaimer in\r
- the documentation and/or other materials provided with the\r
- distribution.\r
- * Neither the name of the copyright holders nor the names of\r
- contributors may be used to endorse or promote products derived\r
- from this software without specific prior written permission.\r
-\r
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
- POSSIBILITY OF SUCH DAMAGE. */\r
-\r
-#ifndef _AVR_BOOT_H_\r
-#define _AVR_BOOT_H_ 1\r
-\r
-/** \defgroup avr_boot Bootloader Support Utilities\r
- \code\r
- #include <avr/io.h>\r
- #include <avr/boot.h>\r
- \endcode\r
-\r
- The macros in this module provide a C language interface to the\r
- bootloader support functionality of certain AVR processors. These\r
- macros are designed to work with all sizes of flash memory.\r
-\r
- \note Not all AVR processors provide bootloader support. See your\r
- processor datasheet to see if it provides bootloader support.\r
-\r
- \todo From email with Marek: On smaller devices (all except ATmega64/128),\r
- __SPM_REG is in the I/O space, accessible with the shorter "in" and "out"\r
- instructions - since the boot loader has a limited size, this could be an\r
- important optimization.\r
-\r
- \par API Usage Example\r
- The following code shows typical usage of the boot API.\r
-\r
- \code\r
- #include <avr/interrupt.h>\r
- #include <avr/pgmspace.h>\r
- \r
- #define ADDRESS 0x1C000UL\r
- \r
- void boot_test(void)\r
- {\r
- unsigned char buffer[8];\r
- \r
- cli();\r
- \r
- // Erase page.\r
- boot_page_erase((unsigned long)ADDRESS);\r
- while(boot_rww_busy())\r
- {\r
- boot_rww_enable();\r
- }\r
- \r
- // Write data to buffer a word at a time. Note incrementing address\r
- // by 2. SPM_PAGESIZE is defined in the microprocessor IO header file.\r
- for(unsigned long i = ADDRESS; i < ADDRESS + SPM_PAGESIZE; i += 2)\r
- {\r
- boot_page_fill(i, (i-ADDRESS) + ((i-ADDRESS+1) << 8));\r
- }\r
- \r
- // Write page.\r
- boot_page_write((unsigned long)ADDRESS);\r
- while(boot_rww_busy())\r
- {\r
- boot_rww_enable();\r
- }\r
- \r
- sei();\r
- \r
- // Read back the values and display.\r
- // (The show() function is undefined and is used here as an example\r
- // only.)\r
- for(unsigned long i = ADDRESS; i < ADDRESS + 256; i++)\r
- {\r
- show(utoa(pgm_read_byte(i), buffer, 16));\r
- }\r
- \r
- return;\r
- }\endcode */\r
-\r
-#include <avr/eeprom.h>\r
-#include <avr/io.h>\r
-#include <inttypes.h>\r
-#include <limits.h>\r
-\r
-/* Check for SPM Control Register in processor. */\r
-#if defined (SPMCSR)\r
-# define __SPM_REG SPMCSR\r
-#elif defined (SPMCR)\r
-# define __SPM_REG SPMCR\r
-#else\r
-# error AVR processor does not provide bootloader support!\r
-#endif\r
-\r
-/** \ingroup avr_boot\r
- \def BOOTLOADER_SECTION\r
-\r
- Used to declare a function or variable to be placed into a\r
- new section called .bootloader. This section and its contents\r
- can then be relocated to any address (such as the bootloader\r
- NRWW area) at link-time. */\r
-\r
-#define BOOTLOADER_SECTION __attribute__ ((section (".bootloader")))\r
-\r
-/* Create common bit definitions. */\r
-#ifdef ASB\r
-#define __COMMON_ASB ASB\r
-#else\r
-#define __COMMON_ASB RWWSB\r
-#endif\r
-\r
-#ifdef ASRE\r
-#define __COMMON_ASRE ASRE\r
-#else\r
-#define __COMMON_ASRE RWWSRE\r
-#endif\r
-\r
-/* Define the bit positions of the Boot Lock Bits. */\r
-\r
-#define BLB12 5\r
-#define BLB11 4\r
-#define BLB02 3\r
-#define BLB01 2\r
-\r
-/** \ingroup avr_boot\r
- \def boot_spm_interrupt_enable()\r
- Enable the SPM interrupt. */\r
-\r
-#define boot_spm_interrupt_enable() (__SPM_REG |= (uint8_t)_BV(SPMIE))\r
-\r
-/** \ingroup avr_boot\r
- \def boot_spm_interrupt_disable()\r
- Disable the SPM interrupt. */\r
-\r
-#define boot_spm_interrupt_disable() (__SPM_REG &= (uint8_t)~_BV(SPMIE))\r
-\r
-/** \ingroup avr_boot\r
- \def boot_is_spm_interrupt()\r
- Check if the SPM interrupt is enabled. */\r
-\r
-#define boot_is_spm_interrupt() (__SPM_REG & (uint8_t)_BV(SPMIE))\r
-\r
-/** \ingroup avr_boot\r
- \def boot_rww_busy()\r
- Check if the RWW section is busy. */\r
-\r
-#define boot_rww_busy() (__SPM_REG & (uint8_t)_BV(__COMMON_ASB))\r
-\r
-/** \ingroup avr_boot\r
- \def boot_spm_busy()\r
- Check if the SPM instruction is busy. */\r
-\r
-#define boot_spm_busy() (__SPM_REG & (uint8_t)_BV(SPMEN))\r
-\r
-/** \ingroup avr_boot\r
- \def boot_spm_busy_wait()\r
- Wait while the SPM instruction is busy. */\r
-\r
-#define boot_spm_busy_wait() do{}while(boot_spm_busy())\r
-\r
-#define __BOOT_PAGE_ERASE (_BV(SPMEN) | _BV(PGERS))\r
-#define __BOOT_PAGE_WRITE (_BV(SPMEN) | _BV(PGWRT))\r
-#define __BOOT_PAGE_FILL _BV(SPMEN)\r
-#define __BOOT_RWW_ENABLE (_BV(SPMEN) | _BV(__COMMON_ASRE))\r
-#define __BOOT_LOCK_BITS_SET (_BV(SPMEN) | _BV(BLBSET))\r
-\r
-#define __BOOT_LOCK_BITS_MASK (_BV(BLB01) | _BV(BLB02) \\r
- | _BV(BLB11) | _BV(BLB12))\r
-\r
-#define eeprom_busy_wait() do {} while (!eeprom_is_ready())\r
-\r
-#define __boot_page_fill_normal(address, data) \\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "movw r0, %3\n\t" \\r
- "movw r30, %2\n\t" \\r
- "sts %0, %1\n\t" \\r
- "spm\n\t" \\r
- "clr r1\n\t" \\r
- : "=m" (__SPM_REG) \\r
- : "r" ((uint8_t)__BOOT_PAGE_FILL), \\r
- "r" ((uint16_t)address), \\r
- "r" ((uint16_t)data) \\r
- : "r0", "r30", "r31" \\r
- ); \\r
-})\r
-\r
-#define __boot_page_fill_alternate(address, data)\\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "movw r0, %3\n\t" \\r
- "movw r30, %2\n\t" \\r
- "sts %0, %1\n\t" \\r
- "spm\n\t" \\r
- ".word 0xffff\n\t" \\r
- "nop\n\t" \\r
- "clr r1\n\t" \\r
- : "=m" (__SPM_REG) \\r
- : "r" ((uint8_t)__BOOT_PAGE_FILL), \\r
- "r" ((uint16_t)address), \\r
- "r" ((uint16_t)data) \\r
- : "r0", "r30", "r31" \\r
- ); \\r
-})\r
-\r
-#define __boot_page_fill_extended(address, data) \\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "movw r0, %4\n\t" \\r
- "movw r30, %A3\n\t" \\r
- "sts %1, %C3\n\t" \\r
- "sts %0, %2\n\t" \\r
- "spm\n\t" \\r
- "clr r1\n\t" \\r
- : "=m" (__SPM_REG), \\r
- "=m" (RAMPZ) \\r
- : "r" ((uint8_t)__BOOT_PAGE_FILL), \\r
- "r" ((uint32_t)address), \\r
- "r" ((uint16_t)data) \\r
- : "r0", "r30", "r31" \\r
- ); \\r
-})\r
-\r
-#define __boot_page_erase_normal(address) \\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "movw r30, %2\n\t" \\r
- "sts %0, %1\n\t" \\r
- "spm\n\t" \\r
- : "=m" (__SPM_REG) \\r
- : "r" ((uint8_t)__BOOT_PAGE_ERASE), \\r
- "r" ((uint16_t)address) \\r
- : "r30", "r31" \\r
- ); \\r
-})\r
-\r
-#define __boot_page_erase_alternate(address) \\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "movw r30, %2\n\t" \\r
- "sts %0, %1\n\t" \\r
- "spm\n\t" \\r
- ".word 0xffff\n\t" \\r
- "nop\n\t" \\r
- : "=m" (__SPM_REG) \\r
- : "r" ((uint8_t)__BOOT_PAGE_ERASE), \\r
- "r" ((uint16_t)address) \\r
- : "r30", "r31" \\r
- ); \\r
-})\r
-\r
-#define __boot_page_erase_extended(address) \\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "movw r30, %A3\n\t" \\r
- "sts %1, %C3\n\t" \\r
- "sts %0, %2\n\t" \\r
- "spm\n\t" \\r
- : "=m" (__SPM_REG), \\r
- "=m" (RAMPZ) \\r
- : "r" ((uint8_t)__BOOT_PAGE_ERASE), \\r
- "r" ((uint32_t)address) \\r
- : "r30", "r31" \\r
- ); \\r
-})\r
-\r
-#define __boot_page_write_normal(address) \\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "movw r30, %2\n\t" \\r
- "sts %0, %1\n\t" \\r
- "spm\n\t" \\r
- : "=m" (__SPM_REG) \\r
- : "r" ((uint8_t)__BOOT_PAGE_WRITE), \\r
- "r" ((uint16_t)address) \\r
- : "r30", "r31" \\r
- ); \\r
-})\r
-\r
-#define __boot_page_write_alternate(address) \\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "movw r30, %2\n\t" \\r
- "sts %0, %1\n\t" \\r
- "spm\n\t" \\r
- ".word 0xffff\n\t" \\r
- "nop\n\t" \\r
- : "=m" (__SPM_REG) \\r
- : "r" ((uint8_t)__BOOT_PAGE_WRITE), \\r
- "r" ((uint16_t)address) \\r
- : "r30", "r31" \\r
- ); \\r
-})\r
-\r
-#define __boot_page_write_extended(address) \\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "movw r30, %A3\n\t" \\r
- "sts %1, %C3\n\t" \\r
- "sts %0, %2\n\t" \\r
- "spm\n\t" \\r
- : "=m" (__SPM_REG), \\r
- "=m" (RAMPZ) \\r
- : "r" ((uint8_t)__BOOT_PAGE_WRITE), \\r
- "r" ((uint32_t)address) \\r
- : "r30", "r31" \\r
- ); \\r
-})\r
-\r
-#define __boot_rww_enable() \\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "sts %0, %1\n\t" \\r
- "spm\n\t" \\r
- : "=m" (__SPM_REG) \\r
- : "r" ((uint8_t)__BOOT_RWW_ENABLE) \\r
- ); \\r
-})\r
-\r
-#define __boot_rww_enable_alternate() \\r
-({ \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "sts %0, %1\n\t" \\r
- "spm\n\t" \\r
- ".word 0xffff\n\t" \\r
- "nop\n\t" \\r
- : "=m" (__SPM_REG) \\r
- : "r" ((uint8_t)__BOOT_RWW_ENABLE) \\r
- ); \\r
-})\r
-\r
-#define __boot_lock_bits_set(lock_bits) \\r
-({ \\r
- uint8_t value = (uint8_t)(lock_bits | __BOOT_LOCK_BITS_MASK); \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "ldi r30, 1\n\t" \\r
- "ldi r31, 0\n\t" \\r
- "mov r0, %2\n\t" \\r
- "sts %0, %1\n\t" \\r
- "spm\n\t" \\r
- : "=m" (__SPM_REG) \\r
- : "r" ((uint8_t)__BOOT_LOCK_BITS_SET), \\r
- "r" (value) \\r
- : "r0", "r30", "r31" \\r
- ); \\r
-})\r
-\r
-#define __boot_lock_bits_set_alternate(lock_bits) \\r
-({ \\r
- uint8_t value = (uint8_t)(lock_bits | __BOOT_LOCK_BITS_MASK); \\r
- boot_spm_busy_wait(); \\r
- eeprom_busy_wait(); \\r
- __asm__ __volatile__ \\r
- ( \\r
- "ldi r30, 1\n\t" \\r
- "ldi r31, 0\n\t" \\r
- "mov r0, %2\n\t" \\r
- "sts %0, %1\n\t" \\r
- "spm\n\t" \\r
- ".word 0xffff\n\t" \\r
- "nop\n\t" \\r
- : "=m" (__SPM_REG) \\r
- : "r" ((uint8_t)__BOOT_LOCK_BITS_SET), \\r
- "r" (value) \\r
- : "r0", "r30", "r31" \\r
- ); \\r
-})\r
-\r
-/** \ingroup avr_boot\r
- \def boot_page_fill(address, data)\r
-\r
- Fill the bootloader temporary page buffer for flash \r
- address with data word. \r
-\r
- \note The address is a byte address. The data is a word. The AVR \r
- writes data to the buffer a word at a time, but addresses the buffer\r
- per byte! So, increment your address by 2 between calls, and send 2\r
- data bytes in a word format! The LSB of the data is written to the lower \r
- address; the MSB of the data is written to the higher address.*/\r
-\r
-/** \ingroup avr_boot\r
- \def boot_page_erase(address)\r
-\r
- Erase the flash page that contains address.\r
-\r
- \note address is a byte address in flash, not a word address. */\r
-\r
-/** \ingroup avr_boot\r
- \def boot_page_write(address)\r
-\r
- Write the bootloader temporary page buffer \r
- to flash page that contains address.\r
- \r
- \note address is a byte address in flash, not a word address. */\r
-\r
-/** \ingroup avr_boot\r
- \def boot_rww_enable()\r
-\r
- Enable the Read-While-Write memory section. */\r
-\r
-/** \ingroup avr_boot\r
- \def boot_lock_bits_set(lock_bits)\r
-\r
- Set the bootloader lock bits. */\r
-\r
-/* Normal versions of the macros use 16-bit addresses.\r
- Extended versions of the macros use 32-bit addresses.\r
- Alternate versions of the macros use 16-bit addresses and require special\r
- instruction sequences after LPM.\r
-\r
- FLASHEND is defined in the ioXXXX.h file.\r
- USHRT_MAX is defined in <limits.h>. */ \r
-\r
-#if defined(__AVR_ATmega161__) || defined(__AVR_ATmega163__) \\r
- || defined(__AVR_ATmega323__)\r
-\r
-/* Alternate: ATmega161/163/323 and 16 bit address */\r
-#define boot_page_fill(address, data) __boot_page_fill_alternate(address, data)\r
-#define boot_page_erase(address) __boot_page_erase_alternate(address)\r
-#define boot_page_write(address) __boot_page_write_alternate(address)\r
-#define boot_rww_enable() __boot_rww_enable_alternate()\r
-#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set_alternate(lock_bits)\r
-\r
-#elif (FLASHEND > USHRT_MAX) && !defined(__USING_MINT8)\r
-\r
-/* Extended: >16 bit address */\r
-#define boot_page_fill(address, data) __boot_page_fill_extended(address, data)\r
-#define boot_page_erase(address) __boot_page_erase_extended(address)\r
-#define boot_page_write(address) __boot_page_write_extended(address)\r
-#define boot_rww_enable() __boot_rww_enable()\r
-#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set(lock_bits)\r
-\r
-#else\r
-\r
-/* Normal: 16 bit address */\r
-#define boot_page_fill(address, data) __boot_page_fill_normal(address, data)\r
-#define boot_page_erase(address) __boot_page_erase_normal(address)\r
-#define boot_page_write(address) __boot_page_write_normal(address)\r
-#define boot_rww_enable() __boot_rww_enable()\r
-#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set(lock_bits)\r
-\r
-#endif\r
-\r
-#endif /* _AVR_BOOT_H_ */\r
+++ /dev/null
-// $Id$
-
-/* tab:4
- * "Copyright (c) 2000-2003 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- * Copyright (c) 2002-2003 Intel Corporation
- * All rights reserved.
- *
- * This file is distributed under the terms in the attached INTEL-LICENSE
- * file. If you do not find these files, copies can be found by writing to
- * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
- * 94704. Attention: Intel License Inquiry.
- */
-
-/**
- * Default CRC function. Note that avrmote has a much more efficient one.
- *
- * This CRC-16 function produces a 16-bit running CRC that adheres to the
- * ITU-T CRC standard.
- *
- * The ITU-T polynomial is: G_16(x) = x^16 + x^12 + x^5 + 1
- *
- */
-
-uint16_t crcByte(uint16_t crc, uint8_t b)
-{
- uint8_t i;
-
- crc = crc ^ b << 8;
- i = 8;
- do
- if (crc & 0x8000)
- crc = crc << 1 ^ 0x1021;
- else
- crc = crc << 1;
- while (--i);
-
- return crc;
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- */
-
-/*
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module ExecC {
- provides {
- interface Exec;
- }
-}
-
-implementation {
-
- command void Exec.exec() {
-
- //goto *(void*)(TOSBOOT_END);
-
- typedef void __attribute__((noreturn)) (*tosboot_exec)();
- ((tosboot_exec)TOSBOOT_END)();
-
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module LedsC {
- provides interface Leds;
-}
-
-implementation {
-
- enum {
- RED_BIT = 1,
- GREEN_BIT = 2,
- YELLOW_BIT = 4
- };
-
- command void Leds.set(uint8_t ledsOn) {
- if (ledsOn & GREEN_BIT)
- TOSH_CLR_GREEN_LED_PIN();
- else
- TOSH_SET_GREEN_LED_PIN();
- if (ledsOn & YELLOW_BIT )
- TOSH_CLR_YELLOW_LED_PIN();
- else
- TOSH_SET_YELLOW_LED_PIN();
- if (ledsOn & RED_BIT)
- TOSH_CLR_RED_LED_PIN();
- else
- TOSH_SET_RED_LED_PIN();
- }
-
- command void Leds.flash(uint8_t a) {
- uint8_t i, j;
- for ( i = 3; i; i-- ) {
- call Leds.set(a);
- for ( j = 4; j; j-- )
- wait(0xffff);
- call Leds.set(0);
- for ( j = 4; j; j-- )
- wait(0xffff);
- }
- }
-
- command void Leds.glow(uint8_t a, uint8_t b) {
- int i;
- for (i = 1536; i > 0; i -= 4) {
- call Leds.set(a);
- wait(i);
- call Leds.set(b);
- wait(1536-i);
- }
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- */
-
-/*
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module ExecC {
- provides {
- interface Exec;
- }
-}
-
-implementation {
-
- command void Exec.exec() {
- __asm__ __volatile__ ("jmp 0x0000\n\t" ::);
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:4
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * InternalFlash.h - Internal flash implementation for the avr
- * platform.
- *
- * Valid address range is 0x0 - 0xFFF.
- *
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-#ifndef __INTERNAL_FLASH_H__
-#define __INTERNAL_FLASH_H__
-
-#include <avr/eeprom.h>
-
-#endif
+++ /dev/null
-
-module PluginC {
- provides {
- interface StdControl;
- }
-}
-
-implementation {
-
- command error_t StdControl.start() { return SUCCESS; }
- command error_t StdControl.stop() { return SUCCESS; }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-#ifndef __TOSBOOT_PLATFORM_H__
-#define __TOSBOOT_PLATFORM_H__
-
-enum {
- // address of TOSBoot args in internal flash
- TOSBOOT_ARGS_ADDR = 0xff0,
- // number of resets to force golden image
- TOSBOOT_GESTURE_MAX_COUNT = 3,
- // address of the golden image in external flash
- TOSBOOT_GOLDEN_IMG_ADDR = 0x0L,
- // size of each internal program flash page
- TOSBOOT_INT_PAGE_SIZE = SPM_PAGESIZE,
-};
-
-enum {
- DELUGE_MIN_ADV_PERIOD_LOG2 = 9,
- DELUGE_QSIZE = 2,
-};
-
-#endif
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module VoltageC {
- provides {
- interface Voltage;
- }
-}
-
-implementation {
-
- command bool Voltage.okToProgram() {
-
- // 250 KHz ADC clock (4MHz/16)
- outp( 0x04, ADCSR );
- // clear interrupt flag by writing a 1
- sbi( ADCSR, ADIF );
- // setup input channel
- outp( VOLTAGE_PORT, ADMUX );
- // adc enable
- sbi( ADCSR, ADEN );
- // adc start conversion
- sbi( ADCSR, ADSC );
- // wait for conversion to complete
- while ( !bit_is_set( ADCSR, ADIF ) );
-
- return ( __inw(ADCL) < VTHRESH );
-
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:4
- * "Copyright (c) 2000-2003 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- * Copyright (c) 2002-2003 Intel Corporation
- * All rights reserved.
- *
- * This file is distributed under the terms in the attached INTEL-LICENSE
- * file. If you do not find these files, copies can be found by writing to
- * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
- * 94704. Attention: Intel License Inquiry.
- */
-/*
- *
- * Authors: Jason Hill, Philip Levis, Nelson Lee
- *
- *
- */
-
-/**
- * @author Jason Hill
- * @author Philip Levis
- * @author Nelson Lee
- */
-
-
-#ifndef TOSH_AVRHARDWARE_H
-#define TOSH_AVRHARDWARE_H
-
-// check for a new-look avr-libc
-#if defined(DTOSTR_ALWAYS_SIGN) && !defined(TOSH_NEW_AVRLIBC)
-#define TOSH_NEW_AVRLIBC
-#endif
-
-#ifdef TOSH_NEW_AVRLIBC
-#include <avr/io.h>
-#if __AVR_LIBC_VERSION__ >= 10400UL
-#include <avr/interrupt.h>
-#else
-#include <avr/interrupt.h>
-#include <avr/signal.h>
-#endif
-#include <avr/wdt.h>
-#include <avr/pgmspace.h>
-#include <avr/eeprom.h>
-
-#ifndef sbi
-/* avr-libc 1.2.3 doesn't include these anymore. */
-#define sbi(port, bit) ((port) |= _BV(bit))
-#define cbi(port, bit) ((port) &= ~_BV(bit))
-#define inp(port) (port)
-#define inb(port) (port)
-#define outp(value, port) ((port) = (value))
-#define outb(port, value) ((port) = (value))
-#define inw(port) (*(volatile uint16_t *)&(port))
-#define outw(port, value) ((*(volatile uint16_t *)&(port)) = (value))
-#define PRG_RDB(addr) pgm_read_byte(addr)
-#endif
-
-#else
-#include <io.h>
-#include <sig-avr.h>
-#include <interrupt.h>
-#include <wdt.h>
-#include <pgmspace.h>
-#endif /* TOSH_NEW_AVRLIBC */
-
-// check for version 3.3 of GNU gcc or later
-#if ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))
-#define __outw(val, port) outw(port, val);
-#endif
-
-#ifndef __inw
-#ifndef __SFR_OFFSET
-#define __SFR_OFFSET 0
-#endif /* !__SFR_OFFSET */
-#define __inw(_port) inw(_port)
-
-#define __inw_atomic(__sfrport) ({ \
- uint16_t __t; \
- bool bStatus; \
- bStatus = bit_is_set(SREG,7); \
- cli(); \
- __t = inw(__sfrport); \
- if (bStatus) sei(); \
- __t; \
- })
-
-#endif /* __inw */
-
-#define TOSH_ASSIGN_PIN(name, port, bit) \
-static inline void TOSH_SET_##name##_PIN() {sbi(PORT##port , bit);} \
-static inline void TOSH_CLR_##name##_PIN() {cbi(PORT##port , bit);} \
-static inline int TOSH_READ_##name##_PIN() \
- {return (inp(PIN##port) & (1 << bit)) != 0;} \
-static inline void TOSH_MAKE_##name##_OUTPUT() {sbi(DDR##port , bit);} \
-static inline void TOSH_MAKE_##name##_INPUT() {cbi(DDR##port , bit);}
-
-#define TOSH_ASSIGN_OUTPUT_ONLY_PIN(name, port, bit) \
-static inline void TOSH_SET_##name##_PIN() {sbi(PORT##port , bit);} \
-static inline void TOSH_CLR_##name##_PIN() {cbi(PORT##port , bit);} \
-static inline void TOSH_MAKE_##name##_OUTPUT() {;}
-
-#define TOSH_ALIAS_OUTPUT_ONLY_PIN(alias, connector)\
-static inline void TOSH_SET_##alias##_PIN() {TOSH_SET_##connector##_PIN();} \
-static inline void TOSH_CLR_##alias##_PIN() {TOSH_CLR_##connector##_PIN();} \
-static inline void TOSH_MAKE_##alias##_OUTPUT() {} \
-
-#define TOSH_ALIAS_PIN(alias, connector) \
-static inline void TOSH_SET_##alias##_PIN() {TOSH_SET_##connector##_PIN();} \
-static inline void TOSH_CLR_##alias##_PIN() {TOSH_CLR_##connector##_PIN();} \
-static inline char TOSH_READ_##alias##_PIN() {return TOSH_READ_##connector##_PIN();} \
-static inline void TOSH_MAKE_##alias##_OUTPUT() {TOSH_MAKE_##connector##_OUTPUT();} \
-static inline void TOSH_MAKE_##alias##_INPUT() {TOSH_MAKE_##connector##_INPUT();}
-
-// We need slightly different defs than SIGNAL, INTERRUPT
-#define TOSH_SIGNAL(signame) \
-void signame() __attribute__ ((signal, spontaneous, C))
-
-#define TOSH_INTERRUPT(signame) \
-void signame() __attribute__ ((interrupt, spontaneous, C))
-
-/* Watchdog Prescaler
- */
-enum {
- TOSH_period16 = 0x00, // 47ms
- TOSH_period32 = 0x01, // 94ms
- TOSH_period64 = 0x02, // 0.19s
- TOSH_period128 = 0x03, // 0.38s
- TOSH_period256 = 0x04, // 0.75s
- TOSH_period512 = 0x05, // 1.5s
- TOSH_period1024 = 0x06, // 3.0s
- TOSH_period2048 = 0x07 // 6.0s
-};
-
-void TOSH_wait()
-{
- asm volatile("nop");
- asm volatile("nop");
-}
-
-// atomic statement runtime support
-
-/* typedef uint8_t __nesc_atomic_t; */
-
-/* __nesc_atomic_t __nesc_atomic_start(void); */
-/* void __nesc_atomic_end(__nesc_atomic_t oldSreg); */
-
-/* #ifndef NESC_BUILD_BINARY */
-
-/* inline __nesc_atomic_t __nesc_atomic_start(void) __attribute__((spontaneous)) */
-/* { */
-/* __nesc_atomic_t result = inp(SREG); */
-/* cli(); */
-/* return result; */
-/* } */
-
-/* inline void __nesc_atomic_end(__nesc_atomic_t oldSreg) __attribute__((spontaneous)) */
-/* { */
-/* outp(oldSreg, SREG); */
-/* } */
-
-/* #endif */
-
-/* inline void __nesc_atomic_sleep() */
-/* { */
-/* /\* Atomically enable interrupts and sleep *\/ */
-/* sei(); // Make sure interrupts are on, so we can wake up! */
-/* asm volatile ("sleep"); */
-/* TOSH_wait(); */
-/* } */
-
-
-/* inline void __nesc_enable_interrupt() { */
-/* sei(); */
-/* } */
-
-/* inline void __nesc_disable_interrupt() { */
-/* cli(); */
-/* } */
-
-#endif //TOSH_AVRHARDWARE_H
+++ /dev/null
-// $Id$
-
-/* tab:4
- * "Copyright (c) 2000-2003 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- * Copyright (c) 2002-2003 Intel Corporation
- * All rights reserved.
- *
- * This file is distributed under the terms in the attached INTEL-LICENSE
- * file. If you do not find these files, copies can be found by writing to
- * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
- * 94704. Attention: Intel License Inquiry.
- */
-/* tab:4
- * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
- * downloading, copying, installing or using the software you agree to
- * this license. If you do not agree to this license, do not download,
- * install, copy or use the software.
- *
- * Intel Open Source License
- *
- * Copyright (c) 2002 Intel Corporation
- * All rights reserved.
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * Neither the name of the Intel Corporation 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 COPYRIGHT HOLDERS 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 INTEL OR ITS
- * 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$
- *
- */
-
-#ifndef __HARDWARE_H__
-#define __HARDWARE_H__
-
-#include <atm128hardware.h>
-#include <avrhardware.h>
-
-typedef uint32_t in_flash_addr_t;
-typedef uint32_t ex_flash_addr_t;
-
-void wait( uint16_t t ) {
- for ( ; t; t-- );
-}
-
-// LED assignments
-TOSH_ASSIGN_PIN(RED_LED, A, 2);
-TOSH_ASSIGN_PIN(GREEN_LED, A, 1);
-TOSH_ASSIGN_PIN(YELLOW_LED, A, 0);
-
-TOSH_ASSIGN_PIN(SERIAL_ID, A, 4);
-
-// Flash assignments
-TOSH_ASSIGN_PIN(FLASH_CS, A, 3);
-TOSH_ASSIGN_PIN(FLASH_CLK, D, 5);
-TOSH_ASSIGN_PIN(FLASH_OUT, D, 3);
-TOSH_ASSIGN_PIN(FLASH_IN, D, 2);
-
-// power control assignments
-TOSH_ASSIGN_PIN(PW0, C, 0);
-TOSH_ASSIGN_PIN(PW1, C, 1);
-TOSH_ASSIGN_PIN(PW2, C, 2);
-TOSH_ASSIGN_PIN(PW3, C, 3);
-TOSH_ASSIGN_PIN(PW4, C, 4);
-TOSH_ASSIGN_PIN(PW5, C, 5);
-TOSH_ASSIGN_PIN(PW6, C, 6);
-TOSH_ASSIGN_PIN(PW7, C, 7);
-
-void TOSH_SET_PIN_DIRECTIONS(void)
-{
- TOSH_MAKE_RED_LED_OUTPUT();
- TOSH_MAKE_YELLOW_LED_OUTPUT();
- TOSH_MAKE_GREEN_LED_OUTPUT();
-
- TOSH_MAKE_PW7_OUTPUT();
- TOSH_MAKE_PW6_OUTPUT();
- TOSH_MAKE_PW5_OUTPUT();
- TOSH_MAKE_PW4_OUTPUT();
- TOSH_MAKE_PW3_OUTPUT();
- TOSH_MAKE_PW2_OUTPUT();
- TOSH_MAKE_PW1_OUTPUT();
- TOSH_MAKE_PW0_OUTPUT();
-
- TOSH_MAKE_SERIAL_ID_INPUT();
- TOSH_CLR_SERIAL_ID_PIN(); // Prevent sourcing current
-
- TOSH_MAKE_FLASH_CS_OUTPUT();
- TOSH_MAKE_FLASH_OUT_OUTPUT();
- TOSH_MAKE_FLASH_CLK_OUTPUT();
- TOSH_SET_FLASH_CS_PIN();
-}
-
-enum {
- VOLTAGE_PORT = 30,
- VTHRESH = 0x1cf, // 2.7V
-};
-
-#endif
-
-
-
-
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module HPLUSART0M {
- provides interface HPLUSARTControl;
-}
-implementation {
-
- command void HPLUSARTControl.disableSPI() {
- // USART0 SPI module disable
- //ME1 &= ~USPIE0;
-
- // set to PUC values
- ME1 = 0;
- U0CTL = 1;
- U0TCTL = 1;
- U0RCTL = 0;
- }
-
- command void HPLUSARTControl.setModeSPI() {
-
- //U0CTL = SWRST;
-
- // 8-bit char, SPI-mode, USART as master
- U0CTL = SWRST | CHAR | SYNC | MM;
-
- // 3-pin + half-cycle delayed UCLK
- U0TCTL |= STC + CKPH + SSEL_SMCLK;
-
- // as fast as possible
- U0BR0 = 0x02;
- U0BR1 = 0;
-
- // enable SPI
- ME1 |= USPIE0;
-
- U0CTL &= ~SWRST;
-
- // clear interrupts
- IFG1 = 0;
-
- }
-
- command void HPLUSARTControl.disableI2C() {
- /*
- U0CTL = 1;
- U0TCTL = 1;
- I2CTCTL = 0;
- */
- U0CTL &= ~I2CEN;
- U0CTL &= ~I2C;
- I2CTCTL = 0;
- call HPLUSARTControl.disableSPI();
- }
-
- command void HPLUSARTControl.setModeI2C() {
-
- // Recommended init procedure
- U0CTL = I2C + SYNC + MST;
-
- // use 1MHz SMCLK as the I2C reference
- I2CTCTL |= I2CSSEL_2 | I2CTRX;
-
- // Enable I2C
- U0CTL |= I2CEN;
-
- return;
- }
-
- command error_t HPLUSARTControl.isTxEmpty(){
- if (U0TCTL & TXEPT) {
- return SUCCESS;
- }
- return FAIL;
- }
-
- command error_t HPLUSARTControl.isTxIntrPending(){
- if (IFG1 & UTXIFG0){
- IFG1 &= ~UTXIFG0;
- return SUCCESS;
- }
- return FAIL;
- }
-
- command error_t HPLUSARTControl.isRxIntrPending(){
- if (IFG1 & URXIFG0){
- IFG1 &= ~URXIFG0;
- return SUCCESS;
- }
- return FAIL;
- }
-
- command void HPLUSARTControl.tx(uint8_t data){
- U0TXBUF = data;
- }
-
- command uint8_t HPLUSARTControl.rx(){
- return U0RXBUF;
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-includes msp430usart;
-
-interface HPLUSARTControl {
-
- command void disableSPI();
- command void setModeSPI();
- command void disableI2C();
- command void setModeI2C();
- command error_t isTxEmpty();
- command error_t isTxIntrPending();
- command error_t isRxIntrPending();
- command void tx(uint8_t data);
- command uint8_t rx();
-
-}
-
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module HardwareC {
- provides {
- interface Hardware;
- }
-}
-
-implementation {
-
- command void Hardware.init() {
- BCSCTL1 = RSEL0 | RSEL1 | RSEL2 | XT2OFF;
- DCOCTL = DCO0 | DCO1 | DCO2;
- }
-
- command void Hardware.reboot() {
- WDTCTL = 0;
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:4
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * InternalFlashC.nc - Internal flash implementation for telos msp
- * platform. On the msp, the flash must first be erased before a value
- * can be written. However, the msp can only erase the flash at a
- * segment granularity (128 bytes for the information section). This
- * module allows transparent read/write of individual bytes to the
- * information section by dynamically switching between the two
- * provided segments in the information section.
- *
- * Valid address range is 0x1000 - 0x107E (0x107F is used to store the
- * version number of the information segment).
- *
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-includes InternalFlash;
-
-module InternalFlashC {
- provides interface InternalFlash;
-}
-
-implementation {
-
- enum {
- IFLASH_OFFSET = 0x1000,
- IFLASH_SIZE = 128,
- IFLASH_SEG0_VNUM_ADDR = 0x107f,
- IFLASH_SEG1_VNUM_ADDR = 0x10ff,
- IFLASH_INVALID_VNUM = -1,
- };
-
- uint8_t chooseSegment() {
- int8_t vnum0 = *(int8_t*)IFLASH_SEG0_VNUM_ADDR;
- int8_t vnum1 = *(int8_t*)IFLASH_SEG1_VNUM_ADDR;
- if (vnum0 == IFLASH_INVALID_VNUM)
- return 1;
- else if (vnum1 == IFLASH_INVALID_VNUM)
- return 0;
- return ( (int8_t)(vnum0 - vnum1) < 0 );
- }
-
- command error_t InternalFlash.write(void* addr, void* buf, uint16_t size) {
-
- volatile int8_t *newPtr;
- int8_t *oldPtr;
- int8_t *bufPtr = (int8_t*)buf;
- int8_t version;
- uint16_t i;
-
- addr += IFLASH_OFFSET;
- newPtr = oldPtr = (int8_t*)IFLASH_OFFSET;
- if (chooseSegment()) {
- oldPtr += IFLASH_SIZE;
- }
- else {
- addr += IFLASH_SIZE;
- newPtr += IFLASH_SIZE;
- }
-
- FCTL2 = FWKEY + FSSEL1 + FN2;
- FCTL3 = FWKEY;
- FCTL1 = FWKEY + ERASE;
- *newPtr = 0;
- FCTL1 = FWKEY + WRT;
-
- for ( i = 0; i < IFLASH_SIZE-1; i++, newPtr++, oldPtr++ ) {
- if ((uint16_t)newPtr < (uint16_t)addr || (uint16_t)addr+size <= (uint16_t)newPtr)
- *newPtr = *oldPtr;
- else
- *newPtr = *bufPtr++;
- }
- version = *oldPtr + 1;
- if (version == IFLASH_INVALID_VNUM)
- version++;
- *newPtr = version;
-
- FCTL1 = FWKEY;
- FCTL3 = FWKEY + LOCK;
-
- return SUCCESS;
-
- }
-
- command error_t InternalFlash.read(void* addr, void* buf, uint16_t size) {
-
- addr += IFLASH_OFFSET;
- if (chooseSegment())
- addr += IFLASH_SIZE;
-
- memcpy(buf, addr, size);
-
- return SUCCESS;
-
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module ProgFlashM {
- provides {
- interface ProgFlash;
- }
-}
-
-implementation {
-
- enum {
- RESET_ADDR = 0xfffe,
- };
-
- command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, uint16_t len) {
-
- volatile uint16_t *flashAddr = (uint16_t*)(uint16_t)addr;
- uint16_t *wordBuf = (uint16_t*)buf;
- uint16_t i = 0;
-
- // len is 16 bits so it can't be larger than 0xffff
- // make sure we can't wrap around
- if (addr < (0xffff - (len >> 1))) {
- FCTL2 = FWKEY + FSSEL1 + FN2;
- FCTL3 = FWKEY;
- FCTL1 = FWKEY + ERASE;
- *flashAddr = 0;
- FCTL1 = FWKEY + WRT;
- for (i = 0; i < (len >> 1); i++, flashAddr++) {
- if ((uint16_t)flashAddr != RESET_ADDR)
- *flashAddr = wordBuf[i];
- else
- *flashAddr = TOSBOOT_START;
- }
- FCTL1 = FWKEY;
- FCTL3 = FWKEY + LOCK;
- return SUCCESS;
- }
- return FAIL;
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module VoltageC {
- provides {
- interface Voltage;
- }
-}
-
-implementation {
-
- enum {
- VTHRESH = 0xE66, // 2.7V
- };
-
- command bool Voltage.okToProgram() {
-
- int i;
-
- // Turn on and set up ADC12 with REF_1_5V
- ADC12CTL0 = ADC12ON | SHT0_2 | REFON;
- // Use sampling timer
- ADC12CTL1 = SHP;
- // Set up to sample voltage
- ADC12MCTL0 = EOS | SREF_1 | INCH_11;
- // Delay for reference start-up
- for ( i=0; i<0x3600; i++ );
-
- // Enable conversions
- ADC12CTL0 |= ENC;
- // Start conversion
- ADC12CTL0 |= ADC12SC;
- // Wait for completion
- while ((ADC12IFG & BIT0) == 0);
-
- // Turn off ADC12
- ADC12CTL0 &= ~ENC;
- ADC12CTL0 = 0;
-
- // Check if voltage is greater than 2.7V
- return ( ADC12MEM0 > VTHRESH );
-
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-configuration ExtFlashC {
- provides {
- interface Init;
- interface StdControl;
- interface ExtFlash;
- }
-}
-
-implementation {
-
- components
- ExtFlashM,
- HPLUSART0M;
-
- Init = ExtFlashM;
- StdControl = ExtFlashM;
- ExtFlash = ExtFlashM;
-
- ExtFlashM.USARTControl -> HPLUSART0M;
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module ExtFlashM {
- provides {
- interface StdControl;
- interface Init;
- interface ExtFlash;
- }
- uses {
- interface HPLUSARTControl as USARTControl;
- }
-}
-
-implementation {
-
- command error_t Init.init() {
- TOSH_MAKE_FLASH_HOLD_OUTPUT();
- TOSH_MAKE_FLASH_CS_OUTPUT();
- TOSH_SET_FLASH_HOLD_PIN();
- call USARTControl.setModeSPI();
- return SUCCESS;
- }
-
- command error_t StdControl.start() {
- return SUCCESS;
- }
-
- command error_t StdControl.stop() {
-
- TOSH_CLR_FLASH_CS_PIN();
-
- call USARTControl.tx(0xb9);
- while(call USARTControl.isTxEmpty() != SUCCESS);
-
- TOSH_SET_FLASH_CS_PIN();
-
- call USARTControl.disableSPI();
-
- return SUCCESS;
-
- }
-
- void powerOnFlash() {
-
- uint8_t i;
-
- TOSH_CLR_FLASH_CS_PIN();
-
- // command byte + 3 dummy bytes + signature
- for ( i = 0; i < 5; i++ ) {
- call USARTControl.tx(0xab);
- while(call USARTControl.isTxIntrPending() != SUCCESS);
- }
-
- TOSH_SET_FLASH_CS_PIN();
-
- }
-
- command void ExtFlash.startRead(uint32_t addr) {
-
- uint8_t i;
-
- powerOnFlash();
-
- TOSH_CLR_FLASH_CS_PIN();
-
- // add command byte to address
- addr |= (uint32_t)0x3 << 24;
-
- // address
- for ( i = 4; i > 0; i-- ) {
- call USARTControl.tx((addr >> (i-1)*8) & 0xff);
- while(call USARTControl.isTxIntrPending() != SUCCESS);
- }
-
- }
-
- command uint8_t ExtFlash.readByte() {
- call USARTControl.rx();
- call USARTControl.tx(0);
- while(call USARTControl.isRxIntrPending() != SUCCESS);
- return call USARTControl.rx();
- }
-
- command void ExtFlash.stopRead() {
- TOSH_SET_FLASH_CS_PIN();
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:4
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * InternalFlash.h - Internal flash implementation for telos msp
- * platform. On the msp, the flash must first be erased before a value
- * can be written. However, the msp can only erase the flash at a
- * segment granularity (128 bytes for the information section). This
- * module allows transparent read/write of individual bytes to the
- * information section by dynamically switching between the two
- * provided segments in the information section.
- *
- * Valid address range is 0x1000 - 0x107E (0x107F is used to store the
- * version number of the information segment).
- *
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-#ifndef __INTERNAL_FLASH_H__
-#define __INTERNAL_FLASH_H__
-
-#endif
+++ /dev/null
-// $Id$
-
-/* tab:4
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * InternalFlash.nc - A generic interface to read and store values in
- * the internal flash of a microcontroller.
- *
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-interface InternalFlash {
- command error_t write(void* addr, void* buf, uint16_t size);
- command error_t read(void* addr, void* buf, uint16_t size);
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-configuration PluginC {
- provides {
- interface StdControl;
- }
-}
-
-implementation {
-
- components ExtFlashC, LedsC, PowerOffM;
-
- StdControl = PowerOffM;
-
- PowerOffM.Leds -> LedsC;
- PowerOffM.SubControl -> ExtFlashC;
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2004 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-module PowerOffM {
- provides {
- interface Init;
- interface StdControl;
- }
- uses {
- interface Leds;
- interface StdControl as SubControl;
- }
-}
-
-implementation {
-
- void haltsystem() {
-
- uint16_t _lpmreg;
-
- TOSH_SET_PIN_DIRECTIONS();
-
- call SubControl.stop();
-
- call Leds.glow(0x7, 0x0);
-
- _lpmreg = LPM4_bits;
- _lpmreg |= SR_GIE;
-
- __asm__ __volatile__( "bis %0, r2" : : "m" ((uint16_t)_lpmreg) );
-
- }
-
- command error_t Init.init() {
- return SUCCESS;
- }
-
- command error_t StdControl.start() {
-
- int i;
-
- // wait a short period for things to stabilize
- for ( i = 0; i < 4; i++ )
- wait(0xffff);
-
- // if user button is pressed, power down
- if (!TOSH_READ_USERINT_PIN())
- haltsystem();
-
- return SUCCESS;
-
- }
-
- command error_t StdControl.stop() {
- return SUCCESS;
- }
-
-}
+++ /dev/null
-// $Id$
-
-/* tab:2
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-#ifndef __TOSBOOT_PLATFORM_H__
-#define __TOSBOOT_PLATFORM_H__
-
-enum {
- // address of TOSBoot args in internal flash
- TOSBOOT_ARGS_ADDR = 0x70,
- // number of resets to force golden image
- TOSBOOT_GESTURE_MAX_COUNT = 3,
- // address of the golden image in external flash
- TOSBOOT_GOLDEN_IMG_ADDR = 0xf0000L,
- // size of each internal program flash page
- TOSBOOT_INT_PAGE_SIZE = 512L,
-};
-
-enum {
- DELUGE_MIN_ADV_PERIOD_LOG2 = 9,
- DELUGE_QSIZE = 1,
-};
-
-#endif
+++ /dev/null
-// $Id$
-
-/* tab:2
- *
- *
- * "Copyright (c) 2000-2005 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose, without fee, and without written agreement is
- * hereby granted, provided that the above copyright notice, the following
- * two paragraphs and the author appear in all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
- *
- */
-
-/**
- * @author Jonathan Hui <jwhui@cs.berkeley.edu>
- */
-
-#ifndef __HARDWARE_H__
-#define __HARDWARE_H__
-
-#include "msp430hardware.h"
-
-// internal flash is 16 bits in width
-typedef uint16_t in_flash_addr_t;
-// external flash is 32 bits in width
-typedef uint32_t ex_flash_addr_t;
-
-void wait(uint16_t t) {
- for ( ; t > 0; t-- );
-}
-
-// LEDs
-TOSH_ASSIGN_PIN(RED_LED, 5, 4);
-TOSH_ASSIGN_PIN(GREEN_LED, 5, 5);
-TOSH_ASSIGN_PIN(YELLOW_LED, 5, 6);
-
-// UART pins
-TOSH_ASSIGN_PIN(SOMI0, 3, 2);
-TOSH_ASSIGN_PIN(SIMO0, 3, 1);
-TOSH_ASSIGN_PIN(UCLK0, 3, 3);
-TOSH_ASSIGN_PIN(UTXD0, 3, 4);
-TOSH_ASSIGN_PIN(URXD0, 3, 5);
-
-// User Interupt Pin
-TOSH_ASSIGN_PIN(USERINT, 2, 7);
-
-// FLASH
-TOSH_ASSIGN_PIN(FLASH_PWR, 4, 3);
-TOSH_ASSIGN_PIN(FLASH_CS, 4, 4);
-TOSH_ASSIGN_PIN(FLASH_HOLD, 4, 7);
-
-void TOSH_SET_PIN_DIRECTIONS(void)
-{
- P3SEL = 0x0E; // set SPI and I2C to mod func
-
- P1DIR = 0xe0;
- P1OUT = 0x00;
-
- P2DIR = 0x7b;
- P2OUT = 0x10;
-
- P3DIR = 0xf1;
- P3OUT = 0x00;
-
- P4DIR = 0xfd;
- P4OUT = 0xdd;
-
- P5DIR = 0xff;
- P5OUT = 0xff;
-
- P6DIR = 0xff;
- P6OUT = 0x00;
-}
-
-#endif
DelugeDissemination delugeDis;
call ObjectTransfer.stop();
- call Leds.led0Toggle();
delugeDis.uid = imgDesc->uid;
delugeDis.vNum = imgDesc->vNum;
{
DelugeDissemination delugeDis;
- call Leds.led2Toggle();
-
delugeDis.uid = 0;
delugeDis.vNum = 0;
delugeDis.imgNum = new_img_num;
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+#ifndef __DELUGE_H__
+#define __DELUGE_H__
+
+#include "DelugeMetadata.h"
+#include "TOSBoot.h"
+
+#ifndef DELUGE_NUM_IMAGES
+#define DELUGE_NUM_IMAGES 3
+#endif
+
+enum {
+ DELUGE_VERSION = 2,
+ DELUGE_MAX_ADV_PERIOD_LOG2 = 22,
+ DELUGE_NUM_NEWDATA_ADVS_REQUIRED = 2,
+ DELUGE_NUM_MIN_ADV_PERIODS = 2,
+ DELUGE_MAX_NUM_REQ_TRIES = 1,
+ DELUGE_REBOOT_DELAY = 4,
+ DELUGE_FAILED_SEND_DELAY = 16,
+ DELUGE_MIN_DELAY = 16,
+ DELUGE_PKTS_PER_PAGE = 48,
+ DELUGE_PKT_PAYLOAD_SIZE = 23,
+ DELUGE_DATA_OFFSET = 128,
+ DELUGE_IDENT_SIZE = 128,
+ DELUGE_INVALID_ADDR = (0x7fffffffL),
+ DELUGE_MAX_REQ_DELAY = (0x1L << (DELUGE_MIN_ADV_PERIOD_LOG2-1)),
+ DELUGE_NACK_TIMEOUT = (DELUGE_MAX_REQ_DELAY >> 0x1),
+ DELUGE_BYTES_PER_PAGE = (DELUGE_PKTS_PER_PAGE*DELUGE_PKT_PAYLOAD_SIZE),
+ DELUGE_PKT_BITVEC_SIZE = (((DELUGE_PKTS_PER_PAGE-1) / 8) + 1),
+ DELUGE_MAX_IMAGE_SIZE = (128L*1024L),
+ DELUGE_MAX_PAGES = 128,
+ DELUGE_CRC_SIZE = sizeof(uint16_t),
+ DELUGE_CRC_BLOCK_SIZE = DELUGE_MAX_PAGES*DELUGE_CRC_SIZE,
+ DELUGE_GOLDEN_IMAGE_NUM = 0x0,
+ DELUGE_INVALID_VNUM = -1,
+ DELUGE_INVALID_IMGNUM = 0xff,
+ DELUGE_INVALID_PKTNUM = 0xff,
+ DELUGE_INVALID_PGNUM = 0xff,
+};
+
+#include "Storage.h"
+
+struct deluge_image_t {
+ imgnum_t imageNum;
+ volume_id_t volumeId;
+};
+
+typedef struct DelugeAdvTimer {
+ uint32_t timer : 32;
+ uint8_t periodLog2 : 8;
+ bool overheard : 1;
+ uint8_t newAdvs : 7;
+} DelugeAdvTimer;
+
+typedef struct DelugeNodeDesc {
+ imgvnum_t vNum;
+ uint32_t uid;
+ imgnum_t imgNum;
+ uint8_t reserved;
+ uint16_t crc;
+} DelugeNodeDesc;
+
+enum {
+ DELUGE_VOLUME_ID_0 = unique("StorageManager"),
+#if DELUGE_NUM_IMAGES >= 2
+ DELUGE_VOLUME_ID_1 = unique("StorageManager"),
+#if DELUGE_NUM_IMAGES >= 3
+ DELUGE_VOLUME_ID_2 = unique("StorageManager"),
+#if DELUGE_NUM_IMAGES >= 4
+ DELUGE_VOLUME_ID_3 = unique("StorageManager"),
+#if DELUGE_NUM_IMAGES >= 5
+ DELUGE_VOLUME_ID_4 = unique("StorageManager"),
+#if DELUGE_NUM_IMAGES >= 6
+ DELUGE_VOLUME_ID_5 = unique("StorageManager"),
+#if DELUGE_NUM_IMAGES >= 7
+ DELUGE_VOLUME_ID_6 = unique("StorageManager"),
+#if DELUGE_NUM_IMAGES >= 8
+ DELUGE_VOLUME_ID_7 = unique("StorageManager"),
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+};
+
+static const struct deluge_image_t DELUGE_IMAGES[DELUGE_NUM_IMAGES] = {
+ { DELUGE_VOLUME_ID_0, 0xDF },
+#if DELUGE_NUM_IMAGES >= 2
+ { DELUGE_VOLUME_ID_1, 0xD0 },
+#if DELUGE_NUM_IMAGES >= 3
+ { DELUGE_VOLUME_ID_2, 0xD1 },
+#if DELUGE_NUM_IMAGES >= 4
+ { DELUGE_VOLUME_ID_3, 0xD2 },
+#if DELUGE_NUM_IMAGES >= 5
+ { DELUGE_VOLUME_ID_4, 0xD3 },
+#if DELUGE_NUM_IMAGES >= 6
+ { DELUGE_VOLUME_ID_5, 0xD4 },
+#if DELUGE_NUM_IMAGES >= 7
+ { DELUGE_VOLUME_ID_6, 0xD5 },
+#if DELUGE_NUM_IMAGES >= 8
+ { DELUGE_VOLUME_ID_7, 0xD6 },
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+#endif
+};
+
+#endif
--- /dev/null
+
+interface Exec {
+ command void exec();
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+interface ExtFlash {
+ command void startRead(uint32_t addr);
+ command uint8_t readByte();
+ command void stopRead();
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+interface Hardware {
+ command void init();
+ command void reboot();
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+interface Leds {
+ command void set(uint8_t ledsOn);
+ command void flash(uint8_t a);
+ command void glow(uint8_t a, uint8_t b);
+}
--- /dev/null
+# $Id$
+
+# tab:2
+#
+#
+# "Copyright (c) 2000-2005 The Regents of the University of California.
+# All rights reserved.
+#
+# Permission to use, copy, modify, and distribute this software and its
+# documentation for any purpose, without fee, and without written agreement is
+# hereby granted, provided that the above copyright notice, the following
+# two paragraphs and the author appear in all copies of this software.
+#
+# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+# OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+# CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+# ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+# PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+#
+#
+
+#
+# @author Jonathan Hui <jwhui@cs.berkeley.edu>
+#
+
+COMPONENT=TOSBoot
+TINYOS_NP=
+
+PFLAGS += -DNESC_BUILD_BINARY
+
+# ifeq ($(MAKECMDGOALS),mica2)
+# CFLAGS += -DTOSBOOT_START=0x1f000 -DTOSBOOT_END=0x20000
+# CFLAGS += -Wl,--section-start=.text=0x1f000
+# CFLAGS += -Iat45db -Iavr -Imica2 -Ilib
+# endif
+
+# ifeq ($(MAKECMDGOALS),mica2dot)
+# CFLAGS += -DTOSBOOT_START=0x1f000 -DTOSBOOT_END=0x20000
+# CFLAGS += -Wl,--section-start=.text=0x1f000
+# CFLAGS += -Iat45db -Iavr -Imica2dot -Ilib
+# endif
+
+ifeq ($(MAKECMDGOALS),micaz)
+ CFLAGS += -DTOSBOOT_START=0x1f000 -DTOSBOOT_END=0x20000
+ CFLAGS += -Wl,--section-start=.text=0x1f000
+ CFLAGS += -Iat45db -Iavr -Imicaz -Ilib
+ CFLAGS += -I../net/Deluge
+endif
+
+# ifeq ($(MAKECMDGOALS),telosa)
+# CFLAGS += -DTOSBOOT_START=0x1100 -DTOSBOOT_END=0x1a00
+# CFLAGS += -Iat45db -Imsp430 -Itelos -Ilib
+# POST_BUILD_EXTRA_DEPS += strip_iv
+# endif
+
+ifeq ($(MAKECMDGOALS),telosb)
+ CFLAGS += -DTOSBOOT_START=0x4000 -DTOSBOOT_END=0x4a00
+ CFLAGS += -Imsp430 -Istm25p -Itelosb -Ilib
+ CFLAGS += -I../net/Deluge
+ POST_BUILD_EXTRA_DEPS += strip_iv
+endif
+
+strip_iv: FORCE
+ @echo " removing interrupt vector from binary"
+ msp430-objcopy -j .text -j .data -O ihex $(BUILDDIR)/main.exe $(BUILDDIR)/main.ihex
+
+include $(MAKERULES)
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+interface ProgFlash {
+ command error_t write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len);
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+#ifndef __TOSBOOT_H__
+#define __TOSBOOT_H__
+
+#include "TOSBoot_platform.h"
+
+typedef struct tosboot_args_t {
+ uint32_t imageAddr;
+ uint8_t gestureCount;
+ bool noReprogram;
+} tosboot_args_t;
+
+#endif
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+includes Deluge;
+includes TOSBoot;
+
+configuration TOSBoot {
+}
+implementation {
+
+ components
+ TOSBootM,
+ ExecC,
+ ExtFlashC,
+ HardwareC,
+ InternalFlashC as IntFlash,
+ LedsC,
+ PluginC,
+ ProgFlashM as ProgFlash,
+ VoltageC;
+
+ TOSBootM.SubInit -> ExtFlashC;
+ TOSBootM.SubControl -> ExtFlashC.StdControl;
+ TOSBootM.SubControl -> PluginC;
+
+ TOSBootM.Exec -> ExecC;
+ TOSBootM.ExtFlash -> ExtFlashC;
+ TOSBootM.Hardware -> HardwareC;
+ TOSBootM.IntFlash -> IntFlash;
+ TOSBootM.Leds -> LedsC;
+ TOSBootM.ProgFlash -> ProgFlash;
+ TOSBootM.Voltage -> VoltageC;
+
+}
--- /dev/null
+/*
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ * Copyright (c) 2007 Johns Hopkins University.
+ * All rights reserved.
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ * @author Razvan Musaloiu-E. <razvanm@cs.jhu.edu>
+ */
+
+includes crc;
+includes hardware;
+
+module TOSBootM {
+ uses {
+ interface Exec;
+ interface ExtFlash;
+ interface Hardware;
+ interface InternalFlash as IntFlash;
+ interface Leds;
+ interface ProgFlash;
+ interface StdControl as SubControl;
+ interface Init as SubInit;
+ interface Voltage;
+ }
+}
+implementation {
+
+ enum {
+ LEDS_LOWBATT = 1,
+ LEDS_GESTURE = 7,
+ };
+
+ enum {
+ R_SUCCESS,
+ R_INVALID_IMAGE_ERROR,
+ R_PROGRAMMING_ERROR,
+ };
+
+ void startupLeds() {
+
+ uint8_t output = 0x7;
+ uint8_t i;
+
+ for (i = 3; i; i--, output >>= 1 )
+ call Leds.glow(output, output >> 1);
+
+ }
+
+ in_flash_addr_t extFlashReadAddr() {
+ in_flash_addr_t result = 0;
+ uint8_t i;
+ for ( i = 0; i < 4; i++ )
+ result |= ((in_flash_addr_t)call ExtFlash.readByte() & 0xff) << (i*8);
+ return result;
+ }
+
+ bool verifyImage(ex_flash_addr_t startAddr) {
+
+ uint16_t crcTarget = 0, crcTmp = 0;
+ uint16_t addr, len;
+ pgnum_t numPgs;
+ uint8_t i;
+
+ // read size of image
+ call ExtFlash.startRead(startAddr + offsetof(DelugeImgDesc,numPgs));
+ numPgs = call ExtFlash.readByte();
+ call ExtFlash.stopRead();
+
+ if (numPgs == 0 || numPgs == 0xff)
+ return FALSE;
+
+ startAddr += DELUGE_METADATA_SIZE;
+
+ addr = DELUGE_CRC_BLOCK_SIZE;
+ len = DELUGE_BYTES_PER_PAGE-DELUGE_CRC_BLOCK_SIZE;
+
+ for ( i = 0; i < numPgs && crcTarget == crcTmp; i++ ) {
+
+ // read crc
+ call ExtFlash.startRead(startAddr + i*sizeof(uint16_t));
+ crcTarget = (uint16_t)(call ExtFlash.readByte() & 0xff);
+ crcTarget |= (uint16_t)(call ExtFlash.readByte() & 0xff) << 8;
+ call ExtFlash.stopRead();
+
+ // compute crc
+ call ExtFlash.startRead(startAddr + addr);
+ for ( crcTmp = 0; len; len-- )
+ crcTmp = crcByte(crcTmp, call ExtFlash.readByte());
+ call ExtFlash.stopRead();
+
+ addr = (uint16_t)(i+1)*DELUGE_BYTES_PER_PAGE;
+ len = DELUGE_BYTES_PER_PAGE;
+ }
+
+ return (i == numPgs) && (crcTarget == crcTmp);
+ }
+
+ error_t programImage(ex_flash_addr_t startAddr) {
+
+ uint8_t buf[TOSBOOT_INT_PAGE_SIZE];
+ uint16_t pageAddr, newPageAddr;
+ in_flash_addr_t intAddr;
+ in_flash_addr_t secLength;
+ ex_flash_addr_t curAddr;
+
+ if (!verifyImage(startAddr))
+ return R_INVALID_IMAGE_ERROR;
+
+ curAddr = startAddr + DELUGE_METADATA_SIZE + DELUGE_CRC_BLOCK_SIZE + DELUGE_IDENT_SIZE;
+
+ call ExtFlash.startRead(curAddr);
+
+ intAddr = extFlashReadAddr();
+ secLength = extFlashReadAddr();
+ curAddr = curAddr + 8;
+
+#if defined(PLATFORM_TELOSB)
+ if (intAddr != TOSBOOT_END) {
+#elif defined(PLATFORM_MICAZ)
+ if (intAddr != 0) {
+#else
+ #error "Target platform is not currently supported by Deluge T2"
+#endif
+ call ExtFlash.stopRead();
+ return R_INVALID_IMAGE_ERROR;
+ }
+
+ call ExtFlash.stopRead(); // MIKE_LIANG
+
+ while ( secLength ) {
+
+ pageAddr = newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE;
+
+ call ExtFlash.startRead(curAddr);
+ // fill in ram buffer for internal program flash sector
+ do {
+
+ // check if secLength is all ones
+ if ( secLength == 0xffffffff ) {
+ call ExtFlash.stopRead(); // MIKE_LIANG
+ return FAIL;
+ }
+
+ buf[(uint16_t)intAddr % TOSBOOT_INT_PAGE_SIZE] = call ExtFlash.readByte();
+ intAddr++; curAddr++;
+
+ if ( --secLength == 0 ) {
+ intAddr = extFlashReadAddr();
+ secLength = extFlashReadAddr();
+ curAddr = curAddr + 8;
+ }
+
+ newPageAddr = intAddr / TOSBOOT_INT_PAGE_SIZE;
+
+ } while ( pageAddr == newPageAddr && secLength );
+ call ExtFlash.stopRead();
+
+ call Leds.set(pageAddr);
+
+
+ // write out page
+ if (call ProgFlash.write(pageAddr*TOSBOOT_INT_PAGE_SIZE, buf,
+ TOSBOOT_INT_PAGE_SIZE) == FAIL) {
+ return R_PROGRAMMING_ERROR;
+ }
+ }
+
+ return R_SUCCESS;
+
+ }
+
+ void runApp() {
+ call SubControl.stop();
+ call Exec.exec();
+ }
+
+ void startupSequence() {
+
+ tosboot_args_t args;
+
+ // check voltage and make sure flash can be programmed
+ // if not, just run the app, can't check for gestures
+ // if we can't write to the internal flash anyway
+ if ( !call Voltage.okToProgram() ) {
+ // give user some time and count down LEDs
+ call Leds.flash(LEDS_LOWBATT);
+ startupLeds();
+ runApp();
+ }
+
+ // get current value of counter
+ call IntFlash.read((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
+
+ // increment gesture counter, see if it exceeds threshold
+ if ( ++args.gestureCount >= TOSBOOT_GESTURE_MAX_COUNT - 1 ) {
+ // gesture has been detected, display receipt of gesture on LEDs
+ call Leds.flash(LEDS_GESTURE);
+
+ // load golden image from flash
+ // if the golden image is invalid, forget about reprogramming
+ // if an error happened during reprogramming, reboot and try again
+ // not much else we can do :-/
+ if (programImage(TOSBOOT_GOLDEN_IMG_ADDR) == R_PROGRAMMING_ERROR) {
+ call Hardware.reboot();
+ }
+ }
+ else {
+ // update gesture counter
+ call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
+ if ( !args.noReprogram ) {
+ // if an error happened during reprogramming, reboot and try again
+ // after two tries, try programming the golden image
+ if (programImage(args.imageAddr) == R_PROGRAMMING_ERROR) {
+ call Hardware.reboot();
+ }
+ }
+ }
+
+ // give user some time and count down LEDs
+ startupLeds();
+
+ // reset counter and reprogramming flag
+ args.gestureCount = 0xff;
+ args.noReprogram = TRUE;
+ call IntFlash.write((uint8_t*)TOSBOOT_ARGS_ADDR, &args, sizeof(args));
+
+ runApp();
+
+ }
+
+ int main() __attribute__ ((C, spontaneous)) {
+
+ __nesc_disable_interrupt();
+
+ TOSH_SET_PIN_DIRECTIONS();
+ call Hardware.init();
+
+ call SubInit.init();
+ call SubControl.start();
+
+ startupSequence();
+
+ return 0;
+
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+interface Voltage {
+ command bool okToProgram();
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module ExtFlashC {
+ provides {
+ interface Init;
+ interface StdControl;
+ interface ExtFlash;
+ }
+}
+
+implementation {
+
+ uint32_t addr;
+
+ command error_t Init.init() {
+ TOSH_MAKE_FLASH_CS_OUTPUT();
+ TOSH_SET_FLASH_CS_PIN();
+ TOSH_MAKE_FLASH_CLK_OUTPUT();
+ TOSH_CLR_FLASH_CLK_PIN();
+ TOSH_MAKE_FLASH_OUT_OUTPUT();
+ TOSH_SET_FLASH_OUT_PIN();
+ TOSH_MAKE_FLASH_IN_INPUT();
+ TOSH_CLR_FLASH_IN_PIN();
+ return SUCCESS;
+ }
+
+ command error_t StdControl.start() { return SUCCESS; }
+ command error_t StdControl.stop() { return SUCCESS; }
+
+ uint8_t SPIByte(uint8_t out) {
+
+ uint8_t in = 0;
+ uint8_t i;
+
+ for ( i = 0; i < 8; i++, out <<= 1 ) {
+
+ // write bit
+ if (out & 0x80)
+ TOSH_SET_FLASH_OUT_PIN();
+ else
+ TOSH_CLR_FLASH_OUT_PIN();
+
+ // clock
+ TOSH_SET_FLASH_CLK_PIN();
+
+ // read bit
+ in <<= 1;
+ if (TOSH_READ_FLASH_IN_PIN())
+ in |= 1;
+
+ // clock
+ TOSH_CLR_FLASH_CLK_PIN();
+
+ }
+
+ return in;
+
+ }
+
+ command void ExtFlash.startRead(uint32_t newAddr) {
+
+ uint8_t cmdBuf[4];
+ uint8_t i;
+
+ addr = newAddr;
+
+ cmdBuf[0] = 0x68;
+ cmdBuf[1] = (addr >> 15) & 0xff;
+ cmdBuf[2] = (addr >> 7) & 0xfe;
+ cmdBuf[3] = addr & 0xff;
+
+ TOSH_CLR_FLASH_CLK_PIN();
+ TOSH_CLR_FLASH_CS_PIN();
+
+ for(i = 0; i < 4; i++)
+ SPIByte(cmdBuf[i]);
+ for(i = 0; i < 4; i++)
+ SPIByte(0x0);
+
+ TOSH_SET_FLASH_CLK_PIN();
+ TOSH_CLR_FLASH_CLK_PIN();
+
+ }
+
+ command uint8_t ExtFlash.readByte() {
+ if (!(addr & 0xff)) {
+ call ExtFlash.stopRead();
+ call ExtFlash.startRead(addr);
+ }
+ addr++;
+ return SPIByte(0);
+ }
+
+ command void ExtFlash.stopRead() {
+ TOSH_SET_FLASH_CS_PIN();
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module HardwareC {
+ provides {
+ interface Hardware;
+ }
+}
+
+implementation {
+
+ command void Hardware.init() {}
+
+ command void Hardware.reboot() {
+ wdt_enable(1);
+ while(1);
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+includes InternalFlash;
+
+module InternalFlashC {
+ provides interface InternalFlash;
+}
+
+implementation {
+
+ command error_t InternalFlash.write(void* addr, void* buf, uint16_t size) {
+
+ uint8_t *addrPtr = (uint8_t*)addr;
+ uint8_t *bufPtr = (uint8_t*)buf;
+
+ for ( ; size; size-- )
+ eeprom_write_byte(addrPtr++, *bufPtr++);
+
+ while(!eeprom_is_ready());
+
+ return SUCCESS;
+
+ }
+
+ command error_t InternalFlash.read(void* addr, void* buf, uint16_t size) {
+
+ uint8_t *addrPtr = (uint8_t*)addr;
+ uint8_t *bufPtr = (uint8_t*)buf;
+
+ for ( ; size; size-- )
+ *bufPtr++ = eeprom_read_byte(addrPtr++);
+
+ return SUCCESS;
+
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module ProgFlashM {
+ provides {
+ interface ProgFlash;
+ }
+}
+
+implementation {
+
+#include <boot.h>
+
+ command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) {
+
+ uint16_t* wordBuf = (uint16_t*)buf;
+ uint32_t i;
+
+ if ( addr + len > TOSBOOT_START )
+ return FAIL;
+
+ boot_page_erase( addr );
+ while( boot_rww_busy() )
+ boot_rww_enable();
+
+ for ( i = 0; i < len; i += 2 )
+ boot_page_fill( addr + i, *wordBuf++ );
+
+ boot_page_write( addr );
+
+ while ( boot_rww_busy() )
+ boot_rww_enable();
+
+ return SUCCESS;
+
+ }
+
+}
--- /dev/null
+/* Copyright (c) 2002, 2003, 2004 Eric B. Weddington\r
+ All rights reserved.\r
+\r
+ Redistribution and use in source and binary forms, with or without\r
+ modification, are permitted provided that the following conditions are met:\r
+\r
+ * Redistributions of source code must retain the above copyright\r
+ notice, this list of conditions and the following disclaimer.\r
+ * Redistributions in binary form must reproduce the above copyright\r
+ notice, this list of conditions and the following disclaimer in\r
+ the documentation and/or other materials provided with the\r
+ distribution.\r
+ * Neither the name of the copyright holders nor the names of\r
+ contributors may be used to endorse or promote products derived\r
+ from this software without specific prior written permission.\r
+\r
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE\r
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ POSSIBILITY OF SUCH DAMAGE. */\r
+\r
+#ifndef _AVR_BOOT_H_\r
+#define _AVR_BOOT_H_ 1\r
+\r
+/** \defgroup avr_boot Bootloader Support Utilities\r
+ \code\r
+ #include <avr/io.h>\r
+ #include <avr/boot.h>\r
+ \endcode\r
+\r
+ The macros in this module provide a C language interface to the\r
+ bootloader support functionality of certain AVR processors. These\r
+ macros are designed to work with all sizes of flash memory.\r
+\r
+ \note Not all AVR processors provide bootloader support. See your\r
+ processor datasheet to see if it provides bootloader support.\r
+\r
+ \todo From email with Marek: On smaller devices (all except ATmega64/128),\r
+ __SPM_REG is in the I/O space, accessible with the shorter "in" and "out"\r
+ instructions - since the boot loader has a limited size, this could be an\r
+ important optimization.\r
+\r
+ \par API Usage Example\r
+ The following code shows typical usage of the boot API.\r
+\r
+ \code\r
+ #include <avr/interrupt.h>\r
+ #include <avr/pgmspace.h>\r
+ \r
+ #define ADDRESS 0x1C000UL\r
+ \r
+ void boot_test(void)\r
+ {\r
+ unsigned char buffer[8];\r
+ \r
+ cli();\r
+ \r
+ // Erase page.\r
+ boot_page_erase((unsigned long)ADDRESS);\r
+ while(boot_rww_busy())\r
+ {\r
+ boot_rww_enable();\r
+ }\r
+ \r
+ // Write data to buffer a word at a time. Note incrementing address\r
+ // by 2. SPM_PAGESIZE is defined in the microprocessor IO header file.\r
+ for(unsigned long i = ADDRESS; i < ADDRESS + SPM_PAGESIZE; i += 2)\r
+ {\r
+ boot_page_fill(i, (i-ADDRESS) + ((i-ADDRESS+1) << 8));\r
+ }\r
+ \r
+ // Write page.\r
+ boot_page_write((unsigned long)ADDRESS);\r
+ while(boot_rww_busy())\r
+ {\r
+ boot_rww_enable();\r
+ }\r
+ \r
+ sei();\r
+ \r
+ // Read back the values and display.\r
+ // (The show() function is undefined and is used here as an example\r
+ // only.)\r
+ for(unsigned long i = ADDRESS; i < ADDRESS + 256; i++)\r
+ {\r
+ show(utoa(pgm_read_byte(i), buffer, 16));\r
+ }\r
+ \r
+ return;\r
+ }\endcode */\r
+\r
+#include <avr/eeprom.h>\r
+#include <avr/io.h>\r
+#include <inttypes.h>\r
+#include <limits.h>\r
+\r
+/* Check for SPM Control Register in processor. */\r
+#if defined (SPMCSR)\r
+# define __SPM_REG SPMCSR\r
+#elif defined (SPMCR)\r
+# define __SPM_REG SPMCR\r
+#else\r
+# error AVR processor does not provide bootloader support!\r
+#endif\r
+\r
+/** \ingroup avr_boot\r
+ \def BOOTLOADER_SECTION\r
+\r
+ Used to declare a function or variable to be placed into a\r
+ new section called .bootloader. This section and its contents\r
+ can then be relocated to any address (such as the bootloader\r
+ NRWW area) at link-time. */\r
+\r
+#define BOOTLOADER_SECTION __attribute__ ((section (".bootloader")))\r
+\r
+/* Create common bit definitions. */\r
+#ifdef ASB\r
+#define __COMMON_ASB ASB\r
+#else\r
+#define __COMMON_ASB RWWSB\r
+#endif\r
+\r
+#ifdef ASRE\r
+#define __COMMON_ASRE ASRE\r
+#else\r
+#define __COMMON_ASRE RWWSRE\r
+#endif\r
+\r
+/* Define the bit positions of the Boot Lock Bits. */\r
+\r
+#define BLB12 5\r
+#define BLB11 4\r
+#define BLB02 3\r
+#define BLB01 2\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_spm_interrupt_enable()\r
+ Enable the SPM interrupt. */\r
+\r
+#define boot_spm_interrupt_enable() (__SPM_REG |= (uint8_t)_BV(SPMIE))\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_spm_interrupt_disable()\r
+ Disable the SPM interrupt. */\r
+\r
+#define boot_spm_interrupt_disable() (__SPM_REG &= (uint8_t)~_BV(SPMIE))\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_is_spm_interrupt()\r
+ Check if the SPM interrupt is enabled. */\r
+\r
+#define boot_is_spm_interrupt() (__SPM_REG & (uint8_t)_BV(SPMIE))\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_rww_busy()\r
+ Check if the RWW section is busy. */\r
+\r
+#define boot_rww_busy() (__SPM_REG & (uint8_t)_BV(__COMMON_ASB))\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_spm_busy()\r
+ Check if the SPM instruction is busy. */\r
+\r
+#define boot_spm_busy() (__SPM_REG & (uint8_t)_BV(SPMEN))\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_spm_busy_wait()\r
+ Wait while the SPM instruction is busy. */\r
+\r
+#define boot_spm_busy_wait() do{}while(boot_spm_busy())\r
+\r
+#define __BOOT_PAGE_ERASE (_BV(SPMEN) | _BV(PGERS))\r
+#define __BOOT_PAGE_WRITE (_BV(SPMEN) | _BV(PGWRT))\r
+#define __BOOT_PAGE_FILL _BV(SPMEN)\r
+#define __BOOT_RWW_ENABLE (_BV(SPMEN) | _BV(__COMMON_ASRE))\r
+#define __BOOT_LOCK_BITS_SET (_BV(SPMEN) | _BV(BLBSET))\r
+\r
+#define __BOOT_LOCK_BITS_MASK (_BV(BLB01) | _BV(BLB02) \\r
+ | _BV(BLB11) | _BV(BLB12))\r
+\r
+#define eeprom_busy_wait() do {} while (!eeprom_is_ready())\r
+\r
+#define __boot_page_fill_normal(address, data) \\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "movw r0, %3\n\t" \\r
+ "movw r30, %2\n\t" \\r
+ "sts %0, %1\n\t" \\r
+ "spm\n\t" \\r
+ "clr r1\n\t" \\r
+ : "=m" (__SPM_REG) \\r
+ : "r" ((uint8_t)__BOOT_PAGE_FILL), \\r
+ "r" ((uint16_t)address), \\r
+ "r" ((uint16_t)data) \\r
+ : "r0", "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+#define __boot_page_fill_alternate(address, data)\\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "movw r0, %3\n\t" \\r
+ "movw r30, %2\n\t" \\r
+ "sts %0, %1\n\t" \\r
+ "spm\n\t" \\r
+ ".word 0xffff\n\t" \\r
+ "nop\n\t" \\r
+ "clr r1\n\t" \\r
+ : "=m" (__SPM_REG) \\r
+ : "r" ((uint8_t)__BOOT_PAGE_FILL), \\r
+ "r" ((uint16_t)address), \\r
+ "r" ((uint16_t)data) \\r
+ : "r0", "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+#define __boot_page_fill_extended(address, data) \\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "movw r0, %4\n\t" \\r
+ "movw r30, %A3\n\t" \\r
+ "sts %1, %C3\n\t" \\r
+ "sts %0, %2\n\t" \\r
+ "spm\n\t" \\r
+ "clr r1\n\t" \\r
+ : "=m" (__SPM_REG), \\r
+ "=m" (RAMPZ) \\r
+ : "r" ((uint8_t)__BOOT_PAGE_FILL), \\r
+ "r" ((uint32_t)address), \\r
+ "r" ((uint16_t)data) \\r
+ : "r0", "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+#define __boot_page_erase_normal(address) \\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "movw r30, %2\n\t" \\r
+ "sts %0, %1\n\t" \\r
+ "spm\n\t" \\r
+ : "=m" (__SPM_REG) \\r
+ : "r" ((uint8_t)__BOOT_PAGE_ERASE), \\r
+ "r" ((uint16_t)address) \\r
+ : "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+#define __boot_page_erase_alternate(address) \\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "movw r30, %2\n\t" \\r
+ "sts %0, %1\n\t" \\r
+ "spm\n\t" \\r
+ ".word 0xffff\n\t" \\r
+ "nop\n\t" \\r
+ : "=m" (__SPM_REG) \\r
+ : "r" ((uint8_t)__BOOT_PAGE_ERASE), \\r
+ "r" ((uint16_t)address) \\r
+ : "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+#define __boot_page_erase_extended(address) \\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "movw r30, %A3\n\t" \\r
+ "sts %1, %C3\n\t" \\r
+ "sts %0, %2\n\t" \\r
+ "spm\n\t" \\r
+ : "=m" (__SPM_REG), \\r
+ "=m" (RAMPZ) \\r
+ : "r" ((uint8_t)__BOOT_PAGE_ERASE), \\r
+ "r" ((uint32_t)address) \\r
+ : "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+#define __boot_page_write_normal(address) \\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "movw r30, %2\n\t" \\r
+ "sts %0, %1\n\t" \\r
+ "spm\n\t" \\r
+ : "=m" (__SPM_REG) \\r
+ : "r" ((uint8_t)__BOOT_PAGE_WRITE), \\r
+ "r" ((uint16_t)address) \\r
+ : "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+#define __boot_page_write_alternate(address) \\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "movw r30, %2\n\t" \\r
+ "sts %0, %1\n\t" \\r
+ "spm\n\t" \\r
+ ".word 0xffff\n\t" \\r
+ "nop\n\t" \\r
+ : "=m" (__SPM_REG) \\r
+ : "r" ((uint8_t)__BOOT_PAGE_WRITE), \\r
+ "r" ((uint16_t)address) \\r
+ : "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+#define __boot_page_write_extended(address) \\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "movw r30, %A3\n\t" \\r
+ "sts %1, %C3\n\t" \\r
+ "sts %0, %2\n\t" \\r
+ "spm\n\t" \\r
+ : "=m" (__SPM_REG), \\r
+ "=m" (RAMPZ) \\r
+ : "r" ((uint8_t)__BOOT_PAGE_WRITE), \\r
+ "r" ((uint32_t)address) \\r
+ : "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+#define __boot_rww_enable() \\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "sts %0, %1\n\t" \\r
+ "spm\n\t" \\r
+ : "=m" (__SPM_REG) \\r
+ : "r" ((uint8_t)__BOOT_RWW_ENABLE) \\r
+ ); \\r
+})\r
+\r
+#define __boot_rww_enable_alternate() \\r
+({ \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "sts %0, %1\n\t" \\r
+ "spm\n\t" \\r
+ ".word 0xffff\n\t" \\r
+ "nop\n\t" \\r
+ : "=m" (__SPM_REG) \\r
+ : "r" ((uint8_t)__BOOT_RWW_ENABLE) \\r
+ ); \\r
+})\r
+\r
+#define __boot_lock_bits_set(lock_bits) \\r
+({ \\r
+ uint8_t value = (uint8_t)(lock_bits | __BOOT_LOCK_BITS_MASK); \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "ldi r30, 1\n\t" \\r
+ "ldi r31, 0\n\t" \\r
+ "mov r0, %2\n\t" \\r
+ "sts %0, %1\n\t" \\r
+ "spm\n\t" \\r
+ : "=m" (__SPM_REG) \\r
+ : "r" ((uint8_t)__BOOT_LOCK_BITS_SET), \\r
+ "r" (value) \\r
+ : "r0", "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+#define __boot_lock_bits_set_alternate(lock_bits) \\r
+({ \\r
+ uint8_t value = (uint8_t)(lock_bits | __BOOT_LOCK_BITS_MASK); \\r
+ boot_spm_busy_wait(); \\r
+ eeprom_busy_wait(); \\r
+ __asm__ __volatile__ \\r
+ ( \\r
+ "ldi r30, 1\n\t" \\r
+ "ldi r31, 0\n\t" \\r
+ "mov r0, %2\n\t" \\r
+ "sts %0, %1\n\t" \\r
+ "spm\n\t" \\r
+ ".word 0xffff\n\t" \\r
+ "nop\n\t" \\r
+ : "=m" (__SPM_REG) \\r
+ : "r" ((uint8_t)__BOOT_LOCK_BITS_SET), \\r
+ "r" (value) \\r
+ : "r0", "r30", "r31" \\r
+ ); \\r
+})\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_page_fill(address, data)\r
+\r
+ Fill the bootloader temporary page buffer for flash \r
+ address with data word. \r
+\r
+ \note The address is a byte address. The data is a word. The AVR \r
+ writes data to the buffer a word at a time, but addresses the buffer\r
+ per byte! So, increment your address by 2 between calls, and send 2\r
+ data bytes in a word format! The LSB of the data is written to the lower \r
+ address; the MSB of the data is written to the higher address.*/\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_page_erase(address)\r
+\r
+ Erase the flash page that contains address.\r
+\r
+ \note address is a byte address in flash, not a word address. */\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_page_write(address)\r
+\r
+ Write the bootloader temporary page buffer \r
+ to flash page that contains address.\r
+ \r
+ \note address is a byte address in flash, not a word address. */\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_rww_enable()\r
+\r
+ Enable the Read-While-Write memory section. */\r
+\r
+/** \ingroup avr_boot\r
+ \def boot_lock_bits_set(lock_bits)\r
+\r
+ Set the bootloader lock bits. */\r
+\r
+/* Normal versions of the macros use 16-bit addresses.\r
+ Extended versions of the macros use 32-bit addresses.\r
+ Alternate versions of the macros use 16-bit addresses and require special\r
+ instruction sequences after LPM.\r
+\r
+ FLASHEND is defined in the ioXXXX.h file.\r
+ USHRT_MAX is defined in <limits.h>. */ \r
+\r
+#if defined(__AVR_ATmega161__) || defined(__AVR_ATmega163__) \\r
+ || defined(__AVR_ATmega323__)\r
+\r
+/* Alternate: ATmega161/163/323 and 16 bit address */\r
+#define boot_page_fill(address, data) __boot_page_fill_alternate(address, data)\r
+#define boot_page_erase(address) __boot_page_erase_alternate(address)\r
+#define boot_page_write(address) __boot_page_write_alternate(address)\r
+#define boot_rww_enable() __boot_rww_enable_alternate()\r
+#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set_alternate(lock_bits)\r
+\r
+#elif (FLASHEND > USHRT_MAX) && !defined(__USING_MINT8)\r
+\r
+/* Extended: >16 bit address */\r
+#define boot_page_fill(address, data) __boot_page_fill_extended(address, data)\r
+#define boot_page_erase(address) __boot_page_erase_extended(address)\r
+#define boot_page_write(address) __boot_page_write_extended(address)\r
+#define boot_rww_enable() __boot_rww_enable()\r
+#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set(lock_bits)\r
+\r
+#else\r
+\r
+/* Normal: 16 bit address */\r
+#define boot_page_fill(address, data) __boot_page_fill_normal(address, data)\r
+#define boot_page_erase(address) __boot_page_erase_normal(address)\r
+#define boot_page_write(address) __boot_page_write_normal(address)\r
+#define boot_rww_enable() __boot_rww_enable()\r
+#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set(lock_bits)\r
+\r
+#endif\r
+\r
+#endif /* _AVR_BOOT_H_ */\r
--- /dev/null
+// $Id$
+
+/* tab:4
+ * "Copyright (c) 2000-2003 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ * Copyright (c) 2002-2003 Intel Corporation
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached INTEL-LICENSE
+ * file. If you do not find these files, copies can be found by writing to
+ * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
+ * 94704. Attention: Intel License Inquiry.
+ */
+
+/**
+ * Default CRC function. Note that avrmote has a much more efficient one.
+ *
+ * This CRC-16 function produces a 16-bit running CRC that adheres to the
+ * ITU-T CRC standard.
+ *
+ * The ITU-T polynomial is: G_16(x) = x^16 + x^12 + x^5 + 1
+ *
+ */
+
+uint16_t crcByte(uint16_t crc, uint8_t b)
+{
+ uint8_t i;
+
+ crc = crc ^ b << 8;
+ i = 8;
+ do
+ if (crc & 0x8000)
+ crc = crc << 1 ^ 0x1021;
+ else
+ crc = crc << 1;
+ while (--i);
+
+ return crc;
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/*
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module ExecC {
+ provides {
+ interface Exec;
+ }
+}
+
+implementation {
+
+ command void Exec.exec() {
+
+ //goto *(void*)(TOSBOOT_END);
+
+ typedef void __attribute__((noreturn)) (*tosboot_exec)();
+ ((tosboot_exec)TOSBOOT_END)();
+
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module LedsC {
+ provides interface Leds;
+}
+
+implementation {
+
+ enum {
+ RED_BIT = 1,
+ GREEN_BIT = 2,
+ YELLOW_BIT = 4
+ };
+
+ command void Leds.set(uint8_t ledsOn) {
+ if (ledsOn & GREEN_BIT)
+ TOSH_CLR_GREEN_LED_PIN();
+ else
+ TOSH_SET_GREEN_LED_PIN();
+ if (ledsOn & YELLOW_BIT )
+ TOSH_CLR_YELLOW_LED_PIN();
+ else
+ TOSH_SET_YELLOW_LED_PIN();
+ if (ledsOn & RED_BIT)
+ TOSH_CLR_RED_LED_PIN();
+ else
+ TOSH_SET_RED_LED_PIN();
+ }
+
+ command void Leds.flash(uint8_t a) {
+ uint8_t i, j;
+ for ( i = 3; i; i-- ) {
+ call Leds.set(a);
+ for ( j = 4; j; j-- )
+ wait(0xffff);
+ call Leds.set(0);
+ for ( j = 4; j; j-- )
+ wait(0xffff);
+ }
+ }
+
+ command void Leds.glow(uint8_t a, uint8_t b) {
+ int i;
+ for (i = 1536; i > 0; i -= 4) {
+ call Leds.set(a);
+ wait(i);
+ call Leds.set(b);
+ wait(1536-i);
+ }
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/*
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module ExecC {
+ provides {
+ interface Exec;
+ }
+}
+
+implementation {
+
+ command void Exec.exec() {
+ __asm__ __volatile__ ("jmp 0x0000\n\t" ::);
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:4
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * InternalFlash.h - Internal flash implementation for the avr
+ * platform.
+ *
+ * Valid address range is 0x0 - 0xFFF.
+ *
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+#ifndef __INTERNAL_FLASH_H__
+#define __INTERNAL_FLASH_H__
+
+#include <avr/eeprom.h>
+
+#endif
--- /dev/null
+
+module PluginC {
+ provides {
+ interface StdControl;
+ }
+}
+
+implementation {
+
+ command error_t StdControl.start() { return SUCCESS; }
+ command error_t StdControl.stop() { return SUCCESS; }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+#ifndef __TOSBOOT_PLATFORM_H__
+#define __TOSBOOT_PLATFORM_H__
+
+enum {
+ // address of TOSBoot args in internal flash
+ TOSBOOT_ARGS_ADDR = 0xff0,
+ // number of resets to force golden image
+ TOSBOOT_GESTURE_MAX_COUNT = 3,
+ // address of the golden image in external flash
+ TOSBOOT_GOLDEN_IMG_ADDR = 0x0L,
+ // size of each internal program flash page
+ TOSBOOT_INT_PAGE_SIZE = SPM_PAGESIZE,
+};
+
+enum {
+ DELUGE_MIN_ADV_PERIOD_LOG2 = 9,
+ DELUGE_QSIZE = 2,
+};
+
+#endif
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module VoltageC {
+ provides {
+ interface Voltage;
+ }
+}
+
+implementation {
+
+ command bool Voltage.okToProgram() {
+
+ // 250 KHz ADC clock (4MHz/16)
+ outp( 0x04, ADCSR );
+ // clear interrupt flag by writing a 1
+ sbi( ADCSR, ADIF );
+ // setup input channel
+ outp( VOLTAGE_PORT, ADMUX );
+ // adc enable
+ sbi( ADCSR, ADEN );
+ // adc start conversion
+ sbi( ADCSR, ADSC );
+ // wait for conversion to complete
+ while ( !bit_is_set( ADCSR, ADIF ) );
+
+ return ( __inw(ADCL) < VTHRESH );
+
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:4
+ * "Copyright (c) 2000-2003 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ * Copyright (c) 2002-2003 Intel Corporation
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached INTEL-LICENSE
+ * file. If you do not find these files, copies can be found by writing to
+ * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
+ * 94704. Attention: Intel License Inquiry.
+ */
+/*
+ *
+ * Authors: Jason Hill, Philip Levis, Nelson Lee
+ *
+ *
+ */
+
+/**
+ * @author Jason Hill
+ * @author Philip Levis
+ * @author Nelson Lee
+ */
+
+
+#ifndef TOSH_AVRHARDWARE_H
+#define TOSH_AVRHARDWARE_H
+
+// check for a new-look avr-libc
+#if defined(DTOSTR_ALWAYS_SIGN) && !defined(TOSH_NEW_AVRLIBC)
+#define TOSH_NEW_AVRLIBC
+#endif
+
+#ifdef TOSH_NEW_AVRLIBC
+#include <avr/io.h>
+#if __AVR_LIBC_VERSION__ >= 10400UL
+#include <avr/interrupt.h>
+#else
+#include <avr/interrupt.h>
+#include <avr/signal.h>
+#endif
+#include <avr/wdt.h>
+#include <avr/pgmspace.h>
+#include <avr/eeprom.h>
+
+#ifndef sbi
+/* avr-libc 1.2.3 doesn't include these anymore. */
+#define sbi(port, bit) ((port) |= _BV(bit))
+#define cbi(port, bit) ((port) &= ~_BV(bit))
+#define inp(port) (port)
+#define inb(port) (port)
+#define outp(value, port) ((port) = (value))
+#define outb(port, value) ((port) = (value))
+#define inw(port) (*(volatile uint16_t *)&(port))
+#define outw(port, value) ((*(volatile uint16_t *)&(port)) = (value))
+#define PRG_RDB(addr) pgm_read_byte(addr)
+#endif
+
+#else
+#include <io.h>
+#include <sig-avr.h>
+#include <interrupt.h>
+#include <wdt.h>
+#include <pgmspace.h>
+#endif /* TOSH_NEW_AVRLIBC */
+
+// check for version 3.3 of GNU gcc or later
+#if ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))
+#define __outw(val, port) outw(port, val);
+#endif
+
+#ifndef __inw
+#ifndef __SFR_OFFSET
+#define __SFR_OFFSET 0
+#endif /* !__SFR_OFFSET */
+#define __inw(_port) inw(_port)
+
+#define __inw_atomic(__sfrport) ({ \
+ uint16_t __t; \
+ bool bStatus; \
+ bStatus = bit_is_set(SREG,7); \
+ cli(); \
+ __t = inw(__sfrport); \
+ if (bStatus) sei(); \
+ __t; \
+ })
+
+#endif /* __inw */
+
+#define TOSH_ASSIGN_PIN(name, port, bit) \
+static inline void TOSH_SET_##name##_PIN() {sbi(PORT##port , bit);} \
+static inline void TOSH_CLR_##name##_PIN() {cbi(PORT##port , bit);} \
+static inline int TOSH_READ_##name##_PIN() \
+ {return (inp(PIN##port) & (1 << bit)) != 0;} \
+static inline void TOSH_MAKE_##name##_OUTPUT() {sbi(DDR##port , bit);} \
+static inline void TOSH_MAKE_##name##_INPUT() {cbi(DDR##port , bit);}
+
+#define TOSH_ASSIGN_OUTPUT_ONLY_PIN(name, port, bit) \
+static inline void TOSH_SET_##name##_PIN() {sbi(PORT##port , bit);} \
+static inline void TOSH_CLR_##name##_PIN() {cbi(PORT##port , bit);} \
+static inline void TOSH_MAKE_##name##_OUTPUT() {;}
+
+#define TOSH_ALIAS_OUTPUT_ONLY_PIN(alias, connector)\
+static inline void TOSH_SET_##alias##_PIN() {TOSH_SET_##connector##_PIN();} \
+static inline void TOSH_CLR_##alias##_PIN() {TOSH_CLR_##connector##_PIN();} \
+static inline void TOSH_MAKE_##alias##_OUTPUT() {} \
+
+#define TOSH_ALIAS_PIN(alias, connector) \
+static inline void TOSH_SET_##alias##_PIN() {TOSH_SET_##connector##_PIN();} \
+static inline void TOSH_CLR_##alias##_PIN() {TOSH_CLR_##connector##_PIN();} \
+static inline char TOSH_READ_##alias##_PIN() {return TOSH_READ_##connector##_PIN();} \
+static inline void TOSH_MAKE_##alias##_OUTPUT() {TOSH_MAKE_##connector##_OUTPUT();} \
+static inline void TOSH_MAKE_##alias##_INPUT() {TOSH_MAKE_##connector##_INPUT();}
+
+// We need slightly different defs than SIGNAL, INTERRUPT
+#define TOSH_SIGNAL(signame) \
+void signame() __attribute__ ((signal, spontaneous, C))
+
+#define TOSH_INTERRUPT(signame) \
+void signame() __attribute__ ((interrupt, spontaneous, C))
+
+/* Watchdog Prescaler
+ */
+enum {
+ TOSH_period16 = 0x00, // 47ms
+ TOSH_period32 = 0x01, // 94ms
+ TOSH_period64 = 0x02, // 0.19s
+ TOSH_period128 = 0x03, // 0.38s
+ TOSH_period256 = 0x04, // 0.75s
+ TOSH_period512 = 0x05, // 1.5s
+ TOSH_period1024 = 0x06, // 3.0s
+ TOSH_period2048 = 0x07 // 6.0s
+};
+
+void TOSH_wait()
+{
+ asm volatile("nop");
+ asm volatile("nop");
+}
+
+// atomic statement runtime support
+
+/* typedef uint8_t __nesc_atomic_t; */
+
+/* __nesc_atomic_t __nesc_atomic_start(void); */
+/* void __nesc_atomic_end(__nesc_atomic_t oldSreg); */
+
+/* #ifndef NESC_BUILD_BINARY */
+
+/* inline __nesc_atomic_t __nesc_atomic_start(void) __attribute__((spontaneous)) */
+/* { */
+/* __nesc_atomic_t result = inp(SREG); */
+/* cli(); */
+/* return result; */
+/* } */
+
+/* inline void __nesc_atomic_end(__nesc_atomic_t oldSreg) __attribute__((spontaneous)) */
+/* { */
+/* outp(oldSreg, SREG); */
+/* } */
+
+/* #endif */
+
+/* inline void __nesc_atomic_sleep() */
+/* { */
+/* /\* Atomically enable interrupts and sleep *\/ */
+/* sei(); // Make sure interrupts are on, so we can wake up! */
+/* asm volatile ("sleep"); */
+/* TOSH_wait(); */
+/* } */
+
+
+/* inline void __nesc_enable_interrupt() { */
+/* sei(); */
+/* } */
+
+/* inline void __nesc_disable_interrupt() { */
+/* cli(); */
+/* } */
+
+#endif //TOSH_AVRHARDWARE_H
--- /dev/null
+// $Id$
+
+/* tab:4
+ * "Copyright (c) 2000-2003 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ * Copyright (c) 2002-2003 Intel Corporation
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached INTEL-LICENSE
+ * file. If you do not find these files, copies can be found by writing to
+ * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
+ * 94704. Attention: Intel License Inquiry.
+ */
+/* tab:4
+ * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
+ * downloading, copying, installing or using the software you agree to
+ * this license. If you do not agree to this license, do not download,
+ * install, copy or use the software.
+ *
+ * Intel Open Source License
+ *
+ * Copyright (c) 2002 Intel Corporation
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the Intel Corporation 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 COPYRIGHT HOLDERS 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 INTEL OR ITS
+ * 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$
+ *
+ */
+
+#ifndef __HARDWARE_H__
+#define __HARDWARE_H__
+
+#include <atm128hardware.h>
+#include <avrhardware.h>
+
+typedef uint32_t in_flash_addr_t;
+typedef uint32_t ex_flash_addr_t;
+
+void wait( uint16_t t ) {
+ for ( ; t; t-- );
+}
+
+// LED assignments
+TOSH_ASSIGN_PIN(RED_LED, A, 2);
+TOSH_ASSIGN_PIN(GREEN_LED, A, 1);
+TOSH_ASSIGN_PIN(YELLOW_LED, A, 0);
+
+TOSH_ASSIGN_PIN(SERIAL_ID, A, 4);
+
+// Flash assignments
+TOSH_ASSIGN_PIN(FLASH_CS, A, 3);
+TOSH_ASSIGN_PIN(FLASH_CLK, D, 5);
+TOSH_ASSIGN_PIN(FLASH_OUT, D, 3);
+TOSH_ASSIGN_PIN(FLASH_IN, D, 2);
+
+// power control assignments
+TOSH_ASSIGN_PIN(PW0, C, 0);
+TOSH_ASSIGN_PIN(PW1, C, 1);
+TOSH_ASSIGN_PIN(PW2, C, 2);
+TOSH_ASSIGN_PIN(PW3, C, 3);
+TOSH_ASSIGN_PIN(PW4, C, 4);
+TOSH_ASSIGN_PIN(PW5, C, 5);
+TOSH_ASSIGN_PIN(PW6, C, 6);
+TOSH_ASSIGN_PIN(PW7, C, 7);
+
+void TOSH_SET_PIN_DIRECTIONS(void)
+{
+ TOSH_MAKE_RED_LED_OUTPUT();
+ TOSH_MAKE_YELLOW_LED_OUTPUT();
+ TOSH_MAKE_GREEN_LED_OUTPUT();
+
+ TOSH_MAKE_PW7_OUTPUT();
+ TOSH_MAKE_PW6_OUTPUT();
+ TOSH_MAKE_PW5_OUTPUT();
+ TOSH_MAKE_PW4_OUTPUT();
+ TOSH_MAKE_PW3_OUTPUT();
+ TOSH_MAKE_PW2_OUTPUT();
+ TOSH_MAKE_PW1_OUTPUT();
+ TOSH_MAKE_PW0_OUTPUT();
+
+ TOSH_MAKE_SERIAL_ID_INPUT();
+ TOSH_CLR_SERIAL_ID_PIN(); // Prevent sourcing current
+
+ TOSH_MAKE_FLASH_CS_OUTPUT();
+ TOSH_MAKE_FLASH_OUT_OUTPUT();
+ TOSH_MAKE_FLASH_CLK_OUTPUT();
+ TOSH_SET_FLASH_CS_PIN();
+}
+
+enum {
+ VOLTAGE_PORT = 30,
+ VTHRESH = 0x1cf, // 2.7V
+};
+
+#endif
+
+
+
+
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module HPLUSART0M {
+ provides interface HPLUSARTControl;
+}
+implementation {
+
+ command void HPLUSARTControl.disableSPI() {
+ // USART0 SPI module disable
+ //ME1 &= ~USPIE0;
+
+ // set to PUC values
+ ME1 = 0;
+ U0CTL = 1;
+ U0TCTL = 1;
+ U0RCTL = 0;
+ }
+
+ command void HPLUSARTControl.setModeSPI() {
+
+ //U0CTL = SWRST;
+
+ // 8-bit char, SPI-mode, USART as master
+ U0CTL = SWRST | CHAR | SYNC | MM;
+
+ // 3-pin + half-cycle delayed UCLK
+ U0TCTL |= STC + CKPH + SSEL_SMCLK;
+
+ // as fast as possible
+ U0BR0 = 0x02;
+ U0BR1 = 0;
+
+ // enable SPI
+ ME1 |= USPIE0;
+
+ U0CTL &= ~SWRST;
+
+ // clear interrupts
+ IFG1 = 0;
+
+ }
+
+ command void HPLUSARTControl.disableI2C() {
+ /*
+ U0CTL = 1;
+ U0TCTL = 1;
+ I2CTCTL = 0;
+ */
+ U0CTL &= ~I2CEN;
+ U0CTL &= ~I2C;
+ I2CTCTL = 0;
+ call HPLUSARTControl.disableSPI();
+ }
+
+ command void HPLUSARTControl.setModeI2C() {
+
+ // Recommended init procedure
+ U0CTL = I2C + SYNC + MST;
+
+ // use 1MHz SMCLK as the I2C reference
+ I2CTCTL |= I2CSSEL_2 | I2CTRX;
+
+ // Enable I2C
+ U0CTL |= I2CEN;
+
+ return;
+ }
+
+ command error_t HPLUSARTControl.isTxEmpty(){
+ if (U0TCTL & TXEPT) {
+ return SUCCESS;
+ }
+ return FAIL;
+ }
+
+ command error_t HPLUSARTControl.isTxIntrPending(){
+ if (IFG1 & UTXIFG0){
+ IFG1 &= ~UTXIFG0;
+ return SUCCESS;
+ }
+ return FAIL;
+ }
+
+ command error_t HPLUSARTControl.isRxIntrPending(){
+ if (IFG1 & URXIFG0){
+ IFG1 &= ~URXIFG0;
+ return SUCCESS;
+ }
+ return FAIL;
+ }
+
+ command void HPLUSARTControl.tx(uint8_t data){
+ U0TXBUF = data;
+ }
+
+ command uint8_t HPLUSARTControl.rx(){
+ return U0RXBUF;
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+includes msp430usart;
+
+interface HPLUSARTControl {
+
+ command void disableSPI();
+ command void setModeSPI();
+ command void disableI2C();
+ command void setModeI2C();
+ command error_t isTxEmpty();
+ command error_t isTxIntrPending();
+ command error_t isRxIntrPending();
+ command void tx(uint8_t data);
+ command uint8_t rx();
+
+}
+
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module HardwareC {
+ provides {
+ interface Hardware;
+ }
+}
+
+implementation {
+
+ command void Hardware.init() {
+ BCSCTL1 = RSEL0 | RSEL1 | RSEL2 | XT2OFF;
+ DCOCTL = DCO0 | DCO1 | DCO2;
+ }
+
+ command void Hardware.reboot() {
+ WDTCTL = 0;
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:4
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * InternalFlashC.nc - Internal flash implementation for telos msp
+ * platform. On the msp, the flash must first be erased before a value
+ * can be written. However, the msp can only erase the flash at a
+ * segment granularity (128 bytes for the information section). This
+ * module allows transparent read/write of individual bytes to the
+ * information section by dynamically switching between the two
+ * provided segments in the information section.
+ *
+ * Valid address range is 0x1000 - 0x107E (0x107F is used to store the
+ * version number of the information segment).
+ *
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+includes InternalFlash;
+
+module InternalFlashC {
+ provides interface InternalFlash;
+}
+
+implementation {
+
+ enum {
+ IFLASH_OFFSET = 0x1000,
+ IFLASH_SIZE = 128,
+ IFLASH_SEG0_VNUM_ADDR = 0x107f,
+ IFLASH_SEG1_VNUM_ADDR = 0x10ff,
+ IFLASH_INVALID_VNUM = -1,
+ };
+
+ uint8_t chooseSegment() {
+ int8_t vnum0 = *(int8_t*)IFLASH_SEG0_VNUM_ADDR;
+ int8_t vnum1 = *(int8_t*)IFLASH_SEG1_VNUM_ADDR;
+ if (vnum0 == IFLASH_INVALID_VNUM)
+ return 1;
+ else if (vnum1 == IFLASH_INVALID_VNUM)
+ return 0;
+ return ( (int8_t)(vnum0 - vnum1) < 0 );
+ }
+
+ command error_t InternalFlash.write(void* addr, void* buf, uint16_t size) {
+
+ volatile int8_t *newPtr;
+ int8_t *oldPtr;
+ int8_t *bufPtr = (int8_t*)buf;
+ int8_t version;
+ uint16_t i;
+
+ addr += IFLASH_OFFSET;
+ newPtr = oldPtr = (int8_t*)IFLASH_OFFSET;
+ if (chooseSegment()) {
+ oldPtr += IFLASH_SIZE;
+ }
+ else {
+ addr += IFLASH_SIZE;
+ newPtr += IFLASH_SIZE;
+ }
+
+ FCTL2 = FWKEY + FSSEL1 + FN2;
+ FCTL3 = FWKEY;
+ FCTL1 = FWKEY + ERASE;
+ *newPtr = 0;
+ FCTL1 = FWKEY + WRT;
+
+ for ( i = 0; i < IFLASH_SIZE-1; i++, newPtr++, oldPtr++ ) {
+ if ((uint16_t)newPtr < (uint16_t)addr || (uint16_t)addr+size <= (uint16_t)newPtr)
+ *newPtr = *oldPtr;
+ else
+ *newPtr = *bufPtr++;
+ }
+ version = *oldPtr + 1;
+ if (version == IFLASH_INVALID_VNUM)
+ version++;
+ *newPtr = version;
+
+ FCTL1 = FWKEY;
+ FCTL3 = FWKEY + LOCK;
+
+ return SUCCESS;
+
+ }
+
+ command error_t InternalFlash.read(void* addr, void* buf, uint16_t size) {
+
+ addr += IFLASH_OFFSET;
+ if (chooseSegment())
+ addr += IFLASH_SIZE;
+
+ memcpy(buf, addr, size);
+
+ return SUCCESS;
+
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module ProgFlashM {
+ provides {
+ interface ProgFlash;
+ }
+}
+
+implementation {
+
+ enum {
+ RESET_ADDR = 0xfffe,
+ };
+
+ command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, uint16_t len) {
+
+ volatile uint16_t *flashAddr = (uint16_t*)(uint16_t)addr;
+ uint16_t *wordBuf = (uint16_t*)buf;
+ uint16_t i = 0;
+
+ // len is 16 bits so it can't be larger than 0xffff
+ // make sure we can't wrap around
+ if (addr < (0xffff - (len >> 1))) {
+ FCTL2 = FWKEY + FSSEL1 + FN2;
+ FCTL3 = FWKEY;
+ FCTL1 = FWKEY + ERASE;
+ *flashAddr = 0;
+ FCTL1 = FWKEY + WRT;
+ for (i = 0; i < (len >> 1); i++, flashAddr++) {
+ if ((uint16_t)flashAddr != RESET_ADDR)
+ *flashAddr = wordBuf[i];
+ else
+ *flashAddr = TOSBOOT_START;
+ }
+ FCTL1 = FWKEY;
+ FCTL3 = FWKEY + LOCK;
+ return SUCCESS;
+ }
+ return FAIL;
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module VoltageC {
+ provides {
+ interface Voltage;
+ }
+}
+
+implementation {
+
+ enum {
+ VTHRESH = 0xE66, // 2.7V
+ };
+
+ command bool Voltage.okToProgram() {
+
+ int i;
+
+ // Turn on and set up ADC12 with REF_1_5V
+ ADC12CTL0 = ADC12ON | SHT0_2 | REFON;
+ // Use sampling timer
+ ADC12CTL1 = SHP;
+ // Set up to sample voltage
+ ADC12MCTL0 = EOS | SREF_1 | INCH_11;
+ // Delay for reference start-up
+ for ( i=0; i<0x3600; i++ );
+
+ // Enable conversions
+ ADC12CTL0 |= ENC;
+ // Start conversion
+ ADC12CTL0 |= ADC12SC;
+ // Wait for completion
+ while ((ADC12IFG & BIT0) == 0);
+
+ // Turn off ADC12
+ ADC12CTL0 &= ~ENC;
+ ADC12CTL0 = 0;
+
+ // Check if voltage is greater than 2.7V
+ return ( ADC12MEM0 > VTHRESH );
+
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+configuration ExtFlashC {
+ provides {
+ interface Init;
+ interface StdControl;
+ interface ExtFlash;
+ }
+}
+
+implementation {
+
+ components
+ ExtFlashM,
+ HPLUSART0M;
+
+ Init = ExtFlashM;
+ StdControl = ExtFlashM;
+ ExtFlash = ExtFlashM;
+
+ ExtFlashM.USARTControl -> HPLUSART0M;
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module ExtFlashM {
+ provides {
+ interface StdControl;
+ interface Init;
+ interface ExtFlash;
+ }
+ uses {
+ interface HPLUSARTControl as USARTControl;
+ }
+}
+
+implementation {
+
+ command error_t Init.init() {
+ TOSH_MAKE_FLASH_HOLD_OUTPUT();
+ TOSH_MAKE_FLASH_CS_OUTPUT();
+ TOSH_SET_FLASH_HOLD_PIN();
+ call USARTControl.setModeSPI();
+ return SUCCESS;
+ }
+
+ command error_t StdControl.start() {
+ return SUCCESS;
+ }
+
+ command error_t StdControl.stop() {
+
+ TOSH_CLR_FLASH_CS_PIN();
+
+ call USARTControl.tx(0xb9);
+ while(call USARTControl.isTxEmpty() != SUCCESS);
+
+ TOSH_SET_FLASH_CS_PIN();
+
+ call USARTControl.disableSPI();
+
+ return SUCCESS;
+
+ }
+
+ void powerOnFlash() {
+
+ uint8_t i;
+
+ TOSH_CLR_FLASH_CS_PIN();
+
+ // command byte + 3 dummy bytes + signature
+ for ( i = 0; i < 5; i++ ) {
+ call USARTControl.tx(0xab);
+ while(call USARTControl.isTxIntrPending() != SUCCESS);
+ }
+
+ TOSH_SET_FLASH_CS_PIN();
+
+ }
+
+ command void ExtFlash.startRead(uint32_t addr) {
+
+ uint8_t i;
+
+ powerOnFlash();
+
+ TOSH_CLR_FLASH_CS_PIN();
+
+ // add command byte to address
+ addr |= (uint32_t)0x3 << 24;
+
+ // address
+ for ( i = 4; i > 0; i-- ) {
+ call USARTControl.tx((addr >> (i-1)*8) & 0xff);
+ while(call USARTControl.isTxIntrPending() != SUCCESS);
+ }
+
+ }
+
+ command uint8_t ExtFlash.readByte() {
+ call USARTControl.rx();
+ call USARTControl.tx(0);
+ while(call USARTControl.isRxIntrPending() != SUCCESS);
+ return call USARTControl.rx();
+ }
+
+ command void ExtFlash.stopRead() {
+ TOSH_SET_FLASH_CS_PIN();
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:4
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * InternalFlash.h - Internal flash implementation for telos msp
+ * platform. On the msp, the flash must first be erased before a value
+ * can be written. However, the msp can only erase the flash at a
+ * segment granularity (128 bytes for the information section). This
+ * module allows transparent read/write of individual bytes to the
+ * information section by dynamically switching between the two
+ * provided segments in the information section.
+ *
+ * Valid address range is 0x1000 - 0x107E (0x107F is used to store the
+ * version number of the information segment).
+ *
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+#ifndef __INTERNAL_FLASH_H__
+#define __INTERNAL_FLASH_H__
+
+#endif
--- /dev/null
+// $Id$
+
+/* tab:4
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * InternalFlash.nc - A generic interface to read and store values in
+ * the internal flash of a microcontroller.
+ *
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+interface InternalFlash {
+ command error_t write(void* addr, void* buf, uint16_t size);
+ command error_t read(void* addr, void* buf, uint16_t size);
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+configuration PluginC {
+ provides {
+ interface StdControl;
+ }
+}
+
+implementation {
+
+ components ExtFlashC, LedsC, PowerOffM;
+
+ StdControl = PowerOffM;
+
+ PowerOffM.Leds -> LedsC;
+ PowerOffM.SubControl -> ExtFlashC;
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2004 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+module PowerOffM {
+ provides {
+ interface Init;
+ interface StdControl;
+ }
+ uses {
+ interface Leds;
+ interface StdControl as SubControl;
+ }
+}
+
+implementation {
+
+ void haltsystem() {
+
+ uint16_t _lpmreg;
+
+ TOSH_SET_PIN_DIRECTIONS();
+
+ call SubControl.stop();
+
+ call Leds.glow(0x7, 0x0);
+
+ _lpmreg = LPM4_bits;
+ _lpmreg |= SR_GIE;
+
+ __asm__ __volatile__( "bis %0, r2" : : "m" ((uint16_t)_lpmreg) );
+
+ }
+
+ command error_t Init.init() {
+ return SUCCESS;
+ }
+
+ command error_t StdControl.start() {
+
+ int i;
+
+ // wait a short period for things to stabilize
+ for ( i = 0; i < 4; i++ )
+ wait(0xffff);
+
+ // if user button is pressed, power down
+ if (!TOSH_READ_USERINT_PIN())
+ haltsystem();
+
+ return SUCCESS;
+
+ }
+
+ command error_t StdControl.stop() {
+ return SUCCESS;
+ }
+
+}
--- /dev/null
+// $Id$
+
+/* tab:2
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+#ifndef __TOSBOOT_PLATFORM_H__
+#define __TOSBOOT_PLATFORM_H__
+
+enum {
+ // address of TOSBoot args in internal flash
+ TOSBOOT_ARGS_ADDR = 0x70,
+ // number of resets to force golden image
+ TOSBOOT_GESTURE_MAX_COUNT = 3,
+ // address of the golden image in external flash
+ TOSBOOT_GOLDEN_IMG_ADDR = 0xf0000L,
+ // size of each internal program flash page
+ TOSBOOT_INT_PAGE_SIZE = 512L,
+};
+
+enum {
+ DELUGE_MIN_ADV_PERIOD_LOG2 = 9,
+ DELUGE_QSIZE = 1,
+};
+
+#endif
--- /dev/null
+// $Id$
+
+/* tab:2
+ *
+ *
+ * "Copyright (c) 2000-2005 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
+ * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ */
+
+/**
+ * @author Jonathan Hui <jwhui@cs.berkeley.edu>
+ */
+
+#ifndef __HARDWARE_H__
+#define __HARDWARE_H__
+
+#include "msp430hardware.h"
+
+// internal flash is 16 bits in width
+typedef uint16_t in_flash_addr_t;
+// external flash is 32 bits in width
+typedef uint32_t ex_flash_addr_t;
+
+void wait(uint16_t t) {
+ for ( ; t > 0; t-- );
+}
+
+// LEDs
+TOSH_ASSIGN_PIN(RED_LED, 5, 4);
+TOSH_ASSIGN_PIN(GREEN_LED, 5, 5);
+TOSH_ASSIGN_PIN(YELLOW_LED, 5, 6);
+
+// UART pins
+TOSH_ASSIGN_PIN(SOMI0, 3, 2);
+TOSH_ASSIGN_PIN(SIMO0, 3, 1);
+TOSH_ASSIGN_PIN(UCLK0, 3, 3);
+TOSH_ASSIGN_PIN(UTXD0, 3, 4);
+TOSH_ASSIGN_PIN(URXD0, 3, 5);
+
+// User Interupt Pin
+TOSH_ASSIGN_PIN(USERINT, 2, 7);
+
+// FLASH
+TOSH_ASSIGN_PIN(FLASH_PWR, 4, 3);
+TOSH_ASSIGN_PIN(FLASH_CS, 4, 4);
+TOSH_ASSIGN_PIN(FLASH_HOLD, 4, 7);
+
+void TOSH_SET_PIN_DIRECTIONS(void)
+{
+ P3SEL = 0x0E; // set SPI and I2C to mod func
+
+ P1DIR = 0xe0;
+ P1OUT = 0x00;
+
+ P2DIR = 0x7b;
+ P2OUT = 0x10;
+
+ P3DIR = 0xf1;
+ P3OUT = 0x00;
+
+ P4DIR = 0xfd;
+ P4OUT = 0xdd;
+
+ P5DIR = 0xff;
+ P5OUT = 0xff;
+
+ P6DIR = 0xff;
+ P6OUT = 0x00;
+}
+
+#endif