-#! /usr/bin/env bash
-# Here we setup the environment
-# variables needed by the tinyos
-# make system
+#!/usr/bin/env bash
+#
+# Here we setup the environment variables needed by the tinyos make system.
+# Users source this script from their shell to setup tinyos for their login,
+# and may source again at any time to change which installed TinyOS source
+# tree their code shall be built against.
+TOSCFG=~/.tosrc
TOSBASE=/opt/tinyos
+RCFILES="$HOME/.bashrc $HOME/.shrc $HOME/.kshrc $HOME/.cshrc $ENV"
-# $1 is a directory or tos version number
-# returns a fully rooted and valid TOSROOT
-getdir()
+# $1 is a directory or tos version number returns a fully rooted and valid
+# TOSROOT, or nothing.
+gettosroot()
{
if [ -d "$1" -a -d "$1/tos" ]; then
- echo "$1"
+ echo $(cd $1 && pwd)
elif [ -d "$TOSBASE/$1" -a -d "$TOSBASE/$1/tos" ]; then
echo "$TOSBASE/$1"
fi
}
-# Clear TOS environment
-if [ -n "$TOSROOT" ]; then
- CLASSPATH=$(echo $CLASSPATH | sed -e "s|:$TOSROOT/support/sdk/java||")
-fi
-unset TOSDIR MAKERULES
+# Update CLASSPATH by replacing the element value in $1 with the element value
+# in $2. An empty $2 removes element $1, if present. An empty $1, or $1 not
+# present, adds $2.
+updclasspath()
+{
+ local jpath="support/sdk/java/tinyos.jar"
+ if [ -n "$1" -a -n "$2" ] && \
+ echo "$CLASSPATH" | grep -q "$1/$jpath"; then
+ CLASSPATH=$(echo $CLASSPATH | sed -e "s|:$1/$jpath|:$2/$jpath|")
+ elif [ -n "$2" ]; then
+ CLASSPATH="$CLASSPATH:$2/$jpath"
+ elif [ -n "$1" ]; then
+ CLASSPATH=$(echo $CLASSPATH | sed -e "s|:$1/$jpath||")
+ fi
+ export CLASSPATH
+}
-# Set TOS environment
-TOSROOT=$(getdir "$1")
-if [ -z "$TOSROOT" ]; then
- TOSROOT=$(cat ~/.tosrc 2>/dev/null)
-fi
+# Install a tinyos.sh invocation in user shell rc files.
+installshrc()
+{
+ for rc in $RCFILES; do
+ if [ -f $rc ] && ! grep -q "$TOSBASE/tinyos.sh" $rc; then
+ echo "[ -d $TOSBASE ] && . $TOSBASE/tinyos.sh" >> $rc 2>/dev/null
+ fi
+ done
+}
+
+# Uninstall the tinyos.sh invocation in user shell rc files.
+uninstallshrc()
+{
+ for rc in $RCFILES; do
+ if [ -f $rc ] && grep -q "$TOSBASE/tinyos.sh" $rc; then
+ grep -v "$TOSBASE/tinyos.sh" $rc > $rc.$$
+ mv -f $rc.$$ $rc
+ fi
+ done
+}
+
+# List available TinyOS source versions
+listsources()
+{
+ echo -n "Available sources:"
+ find $TOSBASE -maxdepth 2 -name tos -type d 2>/dev/null | sort | \
+ while read dir; do
+ echo -n " $(basename -- $(dirname -- $dir))"
+ done
+ echo
+}
+
+# MAIN
+
+if [ "$1" = "-t" ]; then
+ # Display TOS environment
+ if [ -z "$TOSROOT" ]; then
+ echo "tinyos: NOT configured"
+ else
+ echo "TOSROOT=$TOSROOT"
+ fi
+elif [ "$1" = "-l" ]; then
+ listsources
+elif [ "$1" = "-h" ]; then
+ cat <<EOF1
+Each TinyOS user must type the following to configure their login:
+
+ . $TOSBASE/tinyos.sh <version>
+
+<version> is the version of an installed source tree or the filesystem path to
+a TinyOS source tree
-if [ -z "$TOSROOT" ]; then
- echo "No TinyOS source directory found. Usage:" >&2
- echo "source /opt/tinyos/tinyos.sh [<version> | <directory>]" >&2
- export TOSROOT TOSDIR MAKERULES
+EOF1
+ listsources
+ cat <<EOF2
+
+Run this command at any time to change the TinyOS source tree for the current
+and all future shell invocations. The tree setting is persistent across
+logins.
+EOF2
+elif [ "$(basename -- $0)" = tinyos.sh ]; then
+ # Operations below here cannot be executed in a sub-shell
+ echo "tinyos: must be sourced"
+elif [ "$1" = "-u" ]; then
+ if [ -f $TOSCFG ]; then
+ uninstallshrc
+ updclasspath "$TOSROOT" ""
+ unset TOSROOT TOSDIR MAKERULES
+ rm -f "$TOSCFG"
+ echo "tinyos: environment uninstalled for $(whoami)"
+ else
+ echo "tinyos: environment not installed for $(whoami)"
+ fi
else
- echo "Setting up for TinyOS source in $TOSROOT"
- echo "$TOSROOT" > ~/.tosrc
- TOSDIR="$TOSROOT/tos"
- CLASSPATH=$CLASSPATH:$TOSROOT/support/sdk/java
- MAKERULES="$TOSROOT/support/make/Makerules"
- export TOSROOT TOSDIR CLASSPATH MAKERULES
+ # Get TOSROOT, either from command line or cached in $TOSCFG
+ if [ -n "$1" ]; then
+ newroot=$(gettosroot "$1")
+ if [ -n "$newroot" ]; then
+ echo "$TOSROOT" > "$TOSCFG"
+ installshrc
+ echo "tinyos: now using $newroot"
+ else
+ echo "tinyos: invalid version; try -h option"
+ fi
+ else
+ newroot=$(cat "$TOSCFG" 2>/dev/null)
+ if [ -z "$newroot" ]; then
+ echo "tinyos: NOT configured; try -h option"
+ fi
+ fi
+
+ # Set TOS environment
+ if [ -n "$newroot" ]; then
+ updclasspath "$TOSROOT" "$newroot"
+ TOSROOT="$newroot"
+ TOSDIR="$TOSROOT/tos"
+ MAKERULES="$TOSROOT/support/make/Makerules"
+ fi
fi
-unset TOSBASE tmp
+export TOSROOT TOSDIR MAKERULES
+unset TOSBASE RCFILES
+
+# vi: sw=4
/*
- * Copyright (c) 2008, Titanium Mirror, Inc.
+ * Copyright (c) 2008-2010, Titanium Mirror, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
configuration PlatformSerialC {
- provides interface Resource;
+ provides interface StdControl;
provides interface UartStream;
provides interface UartByte;
}
implementation {
components new Msp430UartA1C() as UartC;
- Resource = UartC;
UartStream = UartC;
UartByte = UartC;
+ components PlatformSerialP;
+ StdControl = PlatformSerialP;
+ PlatformSerialP.Resource -> UartC;
+
#if 0 /* If you want to change the configuration... */
components SomeConfigurationComponentC as ConfigC;
UartC.AsyncConfigure -> ConfigC;
--- /dev/null
+/*
+ * Copyright (c) 2010, Titanium Mirror, Inc.
+ * 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 Technische Universität Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author R. Steve McKown <rsmckown@gmail.com>
+ */
+
+module PlatformSerialP {
+ provides interface StdControl;
+ uses interface Resource;
+}
+implementation {
+ command error_t StdControl.start()
+ {
+ return call Resource.immediateRequest();
+ }
+
+ command error_t StdControl.stop()
+ {
+ call Resource.release();
+ return SUCCESS;
+ }
+
+ event void Resource.granted() {}
+}