]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Initial checkin of tosthreads stuff...
authorklueska <klueska>
Thu, 12 Jun 2008 14:02:11 +0000 (14:02 +0000)
committerklueska <klueska>
Thu, 12 Jun 2008 14:02:11 +0000 (14:02 +0000)
224 files changed:
tos/lib/tosthreads/chips/atm128/HplAtm128AdcC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128AdcP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128I2CBusC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128I2CBusP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128InterruptC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128InterruptSigP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128SpiC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128SpiP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128Timer0AsyncC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128Timer0AsyncP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128Timer1C.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128Timer1P.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128Timer2C.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128Timer3C.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128Timer3P.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128UartC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/HplAtm128UartP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/chip_thread.h [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/sim/HplAtm128CompareC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/sim/HplAtm128Counter0C.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/sim/HplAtm128Counter2C.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/sim/HplAtm128Timer0AsyncC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/sim/HplAtm128Timer0AsyncP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm128/sim/HplAtm128Timer2C.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer1P.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer2AsyncC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer2AsyncP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer3P.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm1281/HplAtm128AdcP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm1281/HplAtm128Timer1C.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm1281/HplAtm128Timer3C.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/atm1281/HplAtm128UartP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplAdc12P.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplMsp430DmaC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplMsp430DmaP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplMsp430InterruptC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplMsp430InterruptNMIC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplMsp430InterruptNMIP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplMsp430InterruptP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplMsp430Usart0C.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplMsp430Usart0P.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplMsp430Usart1C.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/HplMsp430Usart1P.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/Msp430Adc12P.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/Msp430TimerC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/Msp430TimerCommonP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcImplP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcP.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcReadClientC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcReadStreamClientC.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/msp430/chip_thread.h [new file with mode: 0644]
tos/lib/tosthreads/chips/pxa27x/HplPXA27xInterruptImplM.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/pxa27x/HplPXA27xInterruptM.nc [new file with mode: 0644]
tos/lib/tosthreads/chips/pxa27x/chip_thread.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/CAMRadioC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CAMRadioP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CAMSerialC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CAMSerialP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CBlockStorageC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CBlockStorageP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CLedsC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CLedsP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CLinkedListC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CLinkedListP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CLogStorageC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CLogStorageP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CQueueC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CThreadC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CThreadP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CThreadSynchronizationC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/CThreadSynchronizationP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/TinyOSEntryPointC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/TinyOSEntryPointP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/TosThreadApiC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/VolumeMapC.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/VolumeMapP.nc [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_amradio.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_amserial.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_barrier.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_blockstorage.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_condvar.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_leds.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_linked_list.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_logstorage.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_mutex.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_queue.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_refcounter.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_semaphore.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_tenet.h [new file with mode: 0644]
tos/lib/tosthreads/csystem/tosthread_threadsync.h [new file with mode: 0644]
tos/lib/tosthreads/interfaces/Barrier.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/BitArrayUtils.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/BlockingAMSend.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/BlockingBlock.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/BlockingBlockWrite.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/BlockingLog.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/BlockingRead.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/BlockingReadStream.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/BlockingReceive.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/BlockingResource.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/BlockingStdControl.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/ConditionVariable.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/DynamicThread.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/LinkedList.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/Malloc.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/Mutex.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/PlatformInterrupt.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/PoolThread.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/ReferenceCounter.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/Semaphore.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/SystemCall.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/SystemCallQueue.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/TaskScheduler.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/Thread.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/ThreadCleanup.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/ThreadFunction.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/ThreadInfo.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/ThreadNotification.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/ThreadQueue.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/ThreadScheduler.nc [new file with mode: 0644]
tos/lib/tosthreads/interfaces/ThreadSleep.nc [new file with mode: 0644]
tos/lib/tosthreads/lib/printf/PrintfC.nc [new file with mode: 0644]
tos/lib/tosthreads/lib/printf/PrintfP.nc [new file with mode: 0644]
tos/lib/tosthreads/lib/printf/avr_stdio.h [new file with mode: 0644]
tos/lib/tosthreads/lib/printf/printf.h [new file with mode: 0644]
tos/lib/tosthreads/platforms/mica2/chips/cc1000/HplCC1000InitP.nc [new file with mode: 0644]
tos/lib/tosthreads/platforms/mica2/chips/cc1000/HplCC1000SpiP.nc [new file with mode: 0644]
tos/lib/tosthreads/platforms/telosa/TelosSerialP.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingHamamatsuS10871TsrC.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingHamamatsuS1087ParC.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingSensirionSht11C.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingSensirionSht11ReaderImplP.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingSensirionSht11ReaderP.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS10871TsrC.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS10871TsrP.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS1087ParC.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS1087ParP.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/CSensirionSht11C.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/CSensirionSht11P.nc [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/tmote_onboard_sensors.h [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/tosthread_hamamatsuS1087.h [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/tosthread_hamamatsuS10871.h [new file with mode: 0644]
tos/lib/tosthreads/sensorboards/tmote_onboard/tosthread_sensirionSht11.h [new file with mode: 0644]
tos/lib/tosthreads/system/BarrierC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BarrierP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BitArrayUtilsC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingAMReceiverC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingAMReceiverImplP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingAMReceiverP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingAMSenderC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingAMSenderImplP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingAMSenderP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingAMSnooperC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingAMSnooperP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingActiveMessageC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingBlockStorageC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingBlockStorageImplP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingBlockStorageP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingBootC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingBootP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingLogStorageC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingLogStorageImplP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingLogStorageP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingResourceC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingResourceP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingSerialAMReceiverC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingSerialAMReceiverP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingSerialAMSenderC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingSerialAMSenderP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingSerialActiveMessageC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingStdControlC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingStdControlImplP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/BlockingStdControlP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ConditionVariableC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ConditionVariableP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/DynamicThreadC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/DynamicThreadP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/LinkedListC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/MainC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/MutexC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/MutexP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/PlatformInterruptC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/PoolThreadC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/PoolThreadP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/RealMainImplP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/RealMainP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ReferenceCounterC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ReferenceCounterP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/SchedulerBasicP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/SemaphoreC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/SemaphoreP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/StaticThreadP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/SystemCallC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/SystemCallP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/SystemCallQueueC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/SystemCallQueueP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/TOSThreadsInterruptP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ThreadC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ThreadInfoMapP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ThreadInfoP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ThreadP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ThreadQueueC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ThreadQueueP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ThreadSleepC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ThreadSleepP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ThreadSynchronizationC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/ThreadTimersC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/TinyOSMainP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/TinyTaskSchedulerC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/TinyThreadSchedulerC.nc [new file with mode: 0644]
tos/lib/tosthreads/system/TinyThreadSchedulerP.nc [new file with mode: 0644]
tos/lib/tosthreads/system/TosMallocC.nc [new file with mode: 0644]
tos/lib/tosthreads/types/barrier.h [new file with mode: 0644]
tos/lib/tosthreads/types/condvar.h [new file with mode: 0644]
tos/lib/tosthreads/types/linked_list.h [new file with mode: 0644]
tos/lib/tosthreads/types/mutex.h [new file with mode: 0644]
tos/lib/tosthreads/types/poolthread.h [new file with mode: 0644]
tos/lib/tosthreads/types/queue.h [new file with mode: 0644]
tos/lib/tosthreads/types/refcounter.h [new file with mode: 0644]
tos/lib/tosthreads/types/semaphore.h [new file with mode: 0644]
tos/lib/tosthreads/types/syscall_queue.h [new file with mode: 0644]
tos/lib/tosthreads/types/thread.h [new file with mode: 0644]
tos/lib/tosthreads/types/thread_queue.h [new file with mode: 0644]

diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128AdcC.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128AdcC.nc
new file mode 100644 (file)
index 0000000..191e28b
--- /dev/null
@@ -0,0 +1,46 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+#include "Atm128Adc.h"
+
+/**
+ * HPL for the Atmega128 A/D conversion susbsystem.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author Hu Siquan <husq@xbow.com>
+ * @author David Gay
+ */
+
+configuration HplAtm128AdcC {
+  provides interface HplAtm128Adc;
+}
+implementation {
+  components HplAtm128AdcP, McuSleepC;
+
+  HplAtm128Adc = HplAtm128AdcP;
+  HplAtm128AdcP.McuPowerState -> McuSleepC;
+  
+  components PlatformInterruptC;
+  HplAtm128AdcP.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128AdcP.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128AdcP.nc
new file mode 100644 (file)
index 0000000..35ee4cd
--- /dev/null
@@ -0,0 +1,134 @@
+/// $Id$
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+#include "Atm128Adc.h"
+
+/**
+ * HPL for the Atmega128 A/D conversion susbsystem.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author Hu Siquan <husq@xbow.com>
+ * @author David Gay
+ */
+
+module HplAtm128AdcP {
+  provides interface HplAtm128Adc;
+  uses interface McuPowerState;
+  uses interface PlatformInterrupt;
+}
+implementation {
+  //=== Direct read of HW registers. =================================
+  async command Atm128Admux_t HplAtm128Adc.getAdmux() { 
+    return *(Atm128Admux_t*)&ADMUX; 
+  }
+  async command Atm128Adcsra_t HplAtm128Adc.getAdcsra() { 
+    return *(Atm128Adcsra_t*)&ADCSRA; 
+  }
+  async command uint16_t HplAtm128Adc.getValue() { 
+    return ADC; 
+  }
+
+  DEFINE_UNION_CAST(Admux2int, Atm128Admux_t, uint8_t);
+  DEFINE_UNION_CAST(Adcsra2int, Atm128Adcsra_t, uint8_t);
+
+  //=== Direct write of HW registers. ================================
+  async command void HplAtm128Adc.setAdmux( Atm128Admux_t x ) { 
+    ADMUX = Admux2int(x); 
+  }
+  async command void HplAtm128Adc.setAdcsra( Atm128Adcsra_t x ) { 
+    ADCSRA = Adcsra2int(x); 
+  }
+
+  async command void HplAtm128Adc.setPrescaler(uint8_t scale){
+    Atm128Adcsra_t  current_val = call HplAtm128Adc.getAdcsra(); 
+    current_val.adif = FALSE;
+    current_val.adps = scale;
+    call HplAtm128Adc.setAdcsra(current_val);
+  }
+
+  // Individual bit manipulation. These all clear any pending A/D interrupt.
+  async command void HplAtm128Adc.enableAdc() {
+    SET_BIT(ADCSRA, ADEN); 
+    call McuPowerState.update();
+  }
+  async command void HplAtm128Adc.disableAdc() {
+    CLR_BIT(ADCSRA, ADEN); 
+    call McuPowerState.update();
+  }
+  async command void HplAtm128Adc.enableInterruption() { SET_BIT(ADCSRA, ADIE); }
+  async command void HplAtm128Adc.disableInterruption() { CLR_BIT(ADCSRA, ADIE); }
+  async command void HplAtm128Adc.setContinuous() { SET_BIT(ADCSRA, ADFR); }
+  async command void HplAtm128Adc.setSingle() { CLR_BIT(ADCSRA, ADFR); }
+  async command void HplAtm128Adc.resetInterrupt() { SET_BIT(ADCSRA, ADIF); }
+  async command void HplAtm128Adc.startConversion() { SET_BIT(ADCSRA, ADSC); }
+
+
+  /* A/D status checks */
+  async command bool HplAtm128Adc.isEnabled()     {       
+    return (call HplAtm128Adc.getAdcsra()).aden; 
+  }
+
+  async command bool HplAtm128Adc.isStarted()     {
+    return (call HplAtm128Adc.getAdcsra()).adsc; 
+  }
+  
+  async command bool HplAtm128Adc.isComplete()    {
+    return (call HplAtm128Adc.getAdcsra()).adif; 
+  }
+
+  /* A/D interrupt handlers. Signals dataReady event with interrupts enabled */
+  AVR_ATOMIC_HANDLER(SIG_ADC) {
+    uint16_t data = call HplAtm128Adc.getValue();
+    
+    __nesc_enable_interrupt();
+    signal HplAtm128Adc.dataReady(data);
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void HplAtm128Adc.dataReady(uint16_t done) { }
+
+  async command bool HplAtm128Adc.cancel() { 
+    /* This is tricky */
+    atomic
+      {
+       Atm128Adcsra_t oldSr = call HplAtm128Adc.getAdcsra(), newSr;
+
+       /* To cancel a conversion, first turn off ADEN, then turn off
+          ADSC. We also cancel any pending interrupt.
+          Finally we reenable the ADC.
+       */
+       newSr = oldSr;
+       newSr.aden = FALSE;
+       newSr.adif = TRUE; /* This clears a pending interrupt... */
+       newSr.adie = FALSE; /* We don't want to start sampling again at the
+                              next sleep */
+       call HplAtm128Adc.setAdcsra(newSr);
+       newSr.adsc = FALSE;
+       call HplAtm128Adc.setAdcsra(newSr);
+       newSr.aden = TRUE;
+       call HplAtm128Adc.setAdcsra(newSr);
+
+       return oldSr.adif || oldSr.adsc;
+      }
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128I2CBusC.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128I2CBusC.nc
new file mode 100644 (file)
index 0000000..fad9190
--- /dev/null
@@ -0,0 +1,52 @@
+/// $Id$
+
+/*
+ *  Copyright (c) 2004-2006 Crossbow Technology, Inc.
+ *  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 (updated) modification history and the author appear in
+ *  all copies of this source code.
+ *
+ *  Permission is also granted to distribute this software under the
+ *  standard BSD license as contained in the TinyOS distribution.
+ *
+ *  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 HOLDERS OR CONTRIBUTORS 
+ *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+ *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA, 
+ *  OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
+ *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
+ *  THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * This driver implements direct I2C register access and a blocking master
+ * controller for the ATmega128 via a Hardware Platform Layer (HPL) to its  
+ * two-wire-interface (TWI) hardware subsystem.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author Philip Levis
+ *
+ * @version    $Id$
+ */
+
+configuration HplAtm128I2CBusC {
+  provides interface HplAtm128I2CBus as I2C;
+}
+implementation {
+
+  components HplAtm128GeneralIOC as IO, HplAtm128I2CBusP as Bus;
+  
+  I2C         = Bus.I2C;
+  Bus.I2CClk  -> IO.PortD0;
+  Bus.I2CData -> IO.PortD1;
+  
+  components PlatformInterruptC;
+  Bus.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128I2CBusP.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128I2CBusP.nc
new file mode 100644 (file)
index 0000000..bc40546
--- /dev/null
@@ -0,0 +1,187 @@
+/// $Id$
+
+/*
+ *  Copyright (c) 2004-2005 Crossbow Technology, Inc.
+ *  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 (updated) modification history and the author appear in
+ *  all copies of this source code.
+ *
+ *  Permission is also granted to distribute this software under the
+ *  standard BSD license as contained in the TinyOS distribution.
+ *
+ *  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 HOLDERS OR CONTRIBUTORS 
+ *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+ *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA, 
+ *  OR PROFITS) 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.
+ */
+
+#define F_CPU       7372800
+
+#include "Atm128I2C.h"
+
+/**
+ * This driver implements direct I2C register access and a blocking master
+ * controller for the ATmega128 via a Hardware Platform Layer (HPL) to its  
+ * two-wire-interface (TWI) hardware subsystem.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author Philip Levis
+ *
+ * @version $Id$
+ */
+module HplAtm128I2CBusP {
+  provides interface HplAtm128I2CBus as I2C;
+
+  uses {
+    interface GeneralIO as I2CClk;
+    interface GeneralIO as I2CData;
+    interface PlatformInterrupt;
+  }
+}
+implementation {
+  uint8_t current;
+  
+  async command void I2C.init(bool hasExternalPulldown) {
+    // Set the internal pullup resisters
+    if (hasExternalPulldown) {
+      //call I2CClk.makeOutput();
+      //call I2CData.makeOutput();
+      call I2CClk.set();
+      call I2CData.set();
+    }
+    call I2CClk.makeInput();
+    call I2CData.makeInput();
+    TWSR = 0;                             // set prescaler == 0
+    TWBR = (F_CPU / 50000UL - 16) / 2;   // set I2C baud rate
+    //TWBR = 50;
+    TWAR = 0;
+    TWCR = 0;
+  }
+
+  async command void I2C.off() {
+    call I2CClk.clr();
+    call I2CData.clr();
+  }
+  
+  async command uint8_t I2C.status() {
+    return TWSR & 0xf8;
+  }
+
+  async command void I2C.sendCommand() {
+    atomic TWCR = current;
+  }
+
+  async command void I2C.readCurrent() {
+    atomic current = TWCR;
+  }
+  
+  /** Send START symbol and begin I2C bus transaction. */
+  async command void I2C.setStart(bool on) {
+    if (on) {
+      atomic SET_BIT(current, TWSTA);
+    }
+    else {
+      atomic CLR_BIT(current, TWSTA);
+    }
+  }
+  async command bool I2C.hasStart() {
+    return READ_BIT(current, TWSTA);
+  }
+
+  async command void I2C.setStop(bool on) {
+    if (on) {
+      atomic SET_BIT(current, TWSTO);
+    }
+    else {
+      atomic CLR_BIT(current, TWSTO);
+    }
+  }
+  async command bool I2C.hasStop() {
+    return READ_BIT(current, TWSTO);
+  }
+  
+  /** Write a byte to an I2C slave device. */
+  async command void I2C.write(uint8_t data) {
+    TWDR = data;
+  }
+
+  async command uint8_t I2C.read() {
+    return TWDR;
+  }
+
+  async command void I2C.enableAck(bool enable) {
+    if (enable) {
+      atomic SET_BIT(current, TWEA);
+    }
+    else {
+      atomic CLR_BIT(current, TWEA);
+    }
+  }
+  
+  async command bool I2C.hasAcks() {
+    return READ_BIT(current, TWEA);
+  }
+  
+  async command void I2C.enableInterrupt(bool enable) {
+    if (enable) {
+      atomic SET_BIT(current, TWIE);
+    }
+    else {
+      atomic CLR_BIT(current, TWIE);
+    }
+  }
+
+  async command bool I2C.isInterruptEnabled() {
+    return READ_BIT(current, TWIE);
+  }
+  
+  async command bool I2C.isRealInterruptPending() {
+    return READ_BIT(TWCR, TWINT);
+  }
+
+  async command bool I2C.isInterruptPending() {
+    return READ_BIT(current, TWINT);
+  }
+
+  async command void I2C.setInterruptPending(bool on) {
+    if (on) {
+      atomic SET_BIT(current, TWINT);
+    }
+    else {
+      atomic CLR_BIT(current, TWINT);
+    }
+  }
+  
+  async command void I2C.enable(bool enable) {
+    if (enable) {
+      atomic SET_BIT(current, TWEN);
+    }
+    else {
+      atomic CLR_BIT(current, TWEN);
+    }
+  }
+
+  async command bool I2C.isEnabled() {
+    return READ_BIT(current, TWEN);
+  }
+
+  async command bool I2C.hasWriteCollided() {
+    return READ_BIT(current, TWWC);
+  }
+
+  default async event void I2C.commandComplete() { }
+  AVR_ATOMIC_HANDLER(SIG_2WIRE_SERIAL) {
+    signal I2C.commandComplete();
+    call PlatformInterrupt.postAmble();
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128InterruptC.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128InterruptC.nc
new file mode 100644 (file)
index 0000000..e64ff40
--- /dev/null
@@ -0,0 +1,83 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+#include <atm128hardware.h>
+
+/**
+ * Component providing access to all external interrupt pins on ATmega128.
+ * @author Martin Turon <mturon@xbow.com>
+ */
+
+configuration HplAtm128InterruptC
+{
+  // provides all the ports as raw ports
+  provides {
+    interface HplAtm128Interrupt as Int0;
+    interface HplAtm128Interrupt as Int1;
+    interface HplAtm128Interrupt as Int2;
+    interface HplAtm128Interrupt as Int3;
+    interface HplAtm128Interrupt as Int4;
+    interface HplAtm128Interrupt as Int5;
+    interface HplAtm128Interrupt as Int6;
+    interface HplAtm128Interrupt as Int7;
+  }
+}
+implementation
+{
+#define IRQ_PORT_D_PIN(bit) (uint8_t)&EICRA, ISC##bit##0, ISC##bit##1, bit
+#define IRQ_PORT_E_PIN(bit) (uint8_t)&EICRB, ISC##bit##0, ISC##bit##1, bit
+
+  components 
+    HplAtm128InterruptSigP as IrqVector,
+    new HplAtm128InterruptPinP(IRQ_PORT_D_PIN(0)) as IntPin0,
+    new HplAtm128InterruptPinP(IRQ_PORT_D_PIN(1)) as IntPin1,
+    new HplAtm128InterruptPinP(IRQ_PORT_D_PIN(2)) as IntPin2,
+    new HplAtm128InterruptPinP(IRQ_PORT_D_PIN(3)) as IntPin3,
+    new HplAtm128InterruptPinP(IRQ_PORT_E_PIN(4)) as IntPin4,
+    new HplAtm128InterruptPinP(IRQ_PORT_E_PIN(5)) as IntPin5,
+    new HplAtm128InterruptPinP(IRQ_PORT_E_PIN(6)) as IntPin6,
+    new HplAtm128InterruptPinP(IRQ_PORT_E_PIN(7)) as IntPin7;
+  
+  Int0 = IntPin0;
+  Int1 = IntPin1;
+  Int2 = IntPin2;
+  Int3 = IntPin3;
+  Int4 = IntPin4;
+  Int5 = IntPin5;
+  Int6 = IntPin6;
+  Int7 = IntPin7;
+
+  IntPin0.IrqSignal -> IrqVector.IntSig0;
+  IntPin1.IrqSignal -> IrqVector.IntSig1;
+  IntPin2.IrqSignal -> IrqVector.IntSig2;
+  IntPin3.IrqSignal -> IrqVector.IntSig3;
+  IntPin4.IrqSignal -> IrqVector.IntSig4;
+  IntPin5.IrqSignal -> IrqVector.IntSig5;
+  IntPin6.IrqSignal -> IrqVector.IntSig6;
+  IntPin7.IrqSignal -> IrqVector.IntSig7;
+
+  components PlatformInterruptC;
+  IrqVector.PlatformInterrupt -> PlatformInterruptC;
+}
+
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128InterruptSigP.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128InterruptSigP.nc
new file mode 100644 (file)
index 0000000..06dac94
--- /dev/null
@@ -0,0 +1,93 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/**
+ * Interrupt interface access for interrupt capable GPIO pins.
+ * Exposes just the interrupt vector routine for 
+ * easy linking to generic components.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ */
+module HplAtm128InterruptSigP
+{
+  provides interface HplAtm128InterruptSig as IntSig0;
+  provides interface HplAtm128InterruptSig as IntSig1;
+  provides interface HplAtm128InterruptSig as IntSig2;
+  provides interface HplAtm128InterruptSig as IntSig3;
+  provides interface HplAtm128InterruptSig as IntSig4;
+  provides interface HplAtm128InterruptSig as IntSig5;
+  provides interface HplAtm128InterruptSig as IntSig6;
+  provides interface HplAtm128InterruptSig as IntSig7;
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+  default async event void IntSig0.fired() { }
+  AVR_ATOMIC_HANDLER( SIG_INTERRUPT0 ) {
+    signal IntSig0.fired();
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void IntSig1.fired() { }
+  AVR_ATOMIC_HANDLER( SIG_INTERRUPT1 ) {
+    signal IntSig1.fired();
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void IntSig2.fired() { }
+  AVR_ATOMIC_HANDLER( SIG_INTERRUPT2 ) {
+    signal IntSig2.fired();
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void IntSig3.fired() { }
+  AVR_ATOMIC_HANDLER( SIG_INTERRUPT3 ) {
+    signal IntSig3.fired();
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void IntSig4.fired() { }
+  AVR_ATOMIC_HANDLER( SIG_INTERRUPT4 ) {
+    signal IntSig4.fired();
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void IntSig5.fired() { }
+  AVR_ATOMIC_HANDLER( SIG_INTERRUPT5 ) {
+    signal IntSig5.fired();
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void IntSig6.fired() { }
+  AVR_ATOMIC_HANDLER( SIG_INTERRUPT6 ) {
+    signal IntSig6.fired();
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void IntSig7.fired() { }
+  AVR_ATOMIC_HANDLER( SIG_INTERRUPT7 ) {
+    signal IntSig7.fired();
+    call PlatformInterrupt.postAmble();
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128SpiC.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128SpiC.nc
new file mode 100644 (file)
index 0000000..10e60f1
--- /dev/null
@@ -0,0 +1,76 @@
+/// $Id$
+
+/*
+ * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * 
+ * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY
+ * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
+ * ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/**
+ * Configuration encapsulating the basic SPI HPL for the atm128.
+ *
+ * <pre>
+ * $Id$
+ * </pre>
+ *
+ * @author Philip Levis
+ * @author Martin Turon <mturon@xbow.com>
+ */
+
+
+configuration HplAtm128SpiC {
+    provides interface Atm128Spi as SpiBus;
+}
+implementation
+{
+  components HplAtm128GeneralIOC as IO, HplAtm128SpiP as HplSpi;
+  components McuSleepC;
+  
+  SpiBus = HplSpi;
+
+  HplSpi.Mcu -> McuSleepC;
+  HplSpi.SS   -> IO.PortB0;  // Slave set line
+  HplSpi.SCK  -> IO.PortB1;  // SPI clock line
+  HplSpi.MOSI -> IO.PortB2;  // Master out, slave in
+  HplSpi.MISO -> IO.PortB3;  // Master in, slave out
+  
+  components PlatformInterruptC;
+  HplSpi.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128SpiP.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128SpiP.nc
new file mode 100644 (file)
index 0000000..65073cf
--- /dev/null
@@ -0,0 +1,223 @@
+/// $Id$
+
+/*
+ * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * 
+ * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY
+ * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
+ * ENHANCEMENTS, OR MODIFICATIONS."
+ *
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/**
+ * Implementation of the SPI bus abstraction for the atm128
+ * microcontroller.
+ *
+ * @author Philip Levis
+ * @author Martin Turon
+ */
+
+#include "Atm128Spi.h"
+
+module HplAtm128SpiP {
+  provides interface Atm128Spi as SPI;
+  provides interface AsyncStdControl;
+  
+  uses {
+    interface GeneralIO as SS;   // Slave set line
+    interface GeneralIO as SCK;  // SPI clock line
+    interface GeneralIO as MOSI; // Master out, slave in
+    interface GeneralIO as MISO; // Master in, slave out
+    interface McuPowerState as Mcu;
+    interface PlatformInterrupt;
+  }
+}
+implementation {
+
+  async command error_t AsyncStdControl.start() {
+    call SPI.enableSpi(TRUE);
+  }
+
+  async command error_t AsyncStdControl.stop() {
+    call SPI.enableInterrupt(FALSE);
+    call SPI.enableSpi(FALSE);
+  }
+  
+  async command void SPI.initMaster() {
+    call MOSI.makeOutput();
+    call MISO.makeInput();
+    call SCK.makeOutput();
+    call SPI.setMasterBit(TRUE);
+  }
+
+  async command void SPI.initSlave() {
+    call MISO.makeOutput();
+    call MOSI.makeInput();
+    call SCK.makeInput();
+    call SS.makeInput();
+    call SPI.setMasterBit(FALSE);
+  }
+  
+  async command void SPI.sleep() {
+//    call SS.set();   // why was this needed?
+  }
+  
+  async command uint8_t SPI.read()        { return SPDR; }
+  async command void SPI.write(uint8_t d) { SPDR = d; }
+    
+  default async event void SPI.dataReady(uint8_t d) {}
+  AVR_ATOMIC_HANDLER(SIG_SPI) {
+    signal SPI.dataReady(call SPI.read());
+    call PlatformInterrupt.postAmble();
+  }
+
+  //=== SPI Bus utility routines. ====================================
+  async command bool SPI.isInterruptPending() {
+    return READ_BIT(SPSR, SPIF);
+  }
+
+  async command bool SPI.isInterruptEnabled () {                
+    return READ_BIT(SPCR, SPIE);
+  }
+
+  async command void SPI.enableInterrupt(bool enabled) {
+    if (enabled) {
+      SET_BIT(SPCR, SPIE);
+      call Mcu.update();
+    }
+    else {
+      CLR_BIT(SPCR, SPIE);
+      call Mcu.update();
+    }
+  }
+
+  async command bool SPI.isSpiEnabled() {
+    return READ_BIT(SPCR, SPE);
+  }
+  
+  async command void SPI.enableSpi(bool enabled) {
+    if (enabled) {
+      SET_BIT(SPCR, SPE);
+      call Mcu.update();
+    }
+    else {
+      CLR_BIT(SPCR, SPE);
+      call Mcu.update();
+    }
+  }
+
+  /* DORD bit */
+  async command void SPI.setDataOrder(bool lsbFirst) {
+    if (lsbFirst) {
+      SET_BIT(SPCR, DORD);
+    }
+    else {
+      CLR_BIT(SPCR, DORD);
+    }
+  }
+  
+  async command bool SPI.isOrderLsbFirst() {
+    return READ_BIT(SPCR, DORD);
+  }
+  
+  /* MSTR bit */
+  async command void SPI.setMasterBit(bool isMaster) {
+    if (isMaster) {
+      SET_BIT(SPCR, MSTR);
+    }
+    else {
+      CLR_BIT(SPCR, MSTR);
+    }
+  }
+  async command bool SPI.isMasterBitSet() {
+    return READ_BIT(SPCR, MSTR);
+  }
+  
+  /* CPOL bit */
+  async command void SPI.setClockPolarity(bool highWhenIdle) {
+    if (highWhenIdle) {
+      SET_BIT(SPCR, CPOL);
+    }
+    else {
+      CLR_BIT(SPCR, CPOL);
+    }
+  }
+  
+  async command bool SPI.getClockPolarity() {
+    return READ_BIT(SPCR, CPOL);
+  }
+  
+  /* CPHA bit */
+  async command void SPI.setClockPhase(bool sampleOnTrailing) {
+    if (sampleOnTrailing) {
+      SET_BIT(SPCR, CPHA);
+    }
+    else {
+      CLR_BIT(SPCR, CPHA);
+    }
+  }
+  async command bool SPI.getClockPhase() {
+    return READ_BIT(SPCR, CPHA);
+  }
+
+  
+  async command uint8_t SPI.getClock () {                
+    return READ_FLAG(SPCR, ((1 << SPR1) | (1 <<SPR0)));
+  }
+  
+  async command void SPI.setClock (uint8_t v) {
+    v &= (SPR1) | (SPR0);
+    SPCR = (SPCR & ~(SPR1 | SPR0)) | v;
+  }
+
+  async command bool SPI.hasWriteCollided() {
+    return READ_BIT(SPSR, WCOL);
+  }
+
+  async command bool SPI.isMasterDoubleSpeed() {
+    return READ_BIT(SPSR, SPI2X);
+  }
+
+  async command void SPI.setMasterDoubleSpeed(bool on) {
+   if (on) {
+      SET_BIT(SPSR, SPI2X);
+    }
+    else {
+      CLR_BIT(SPSR, SPI2X);
+    }
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128Timer0AsyncC.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128Timer0AsyncC.nc
new file mode 100644 (file)
index 0000000..4ff8bc5
--- /dev/null
@@ -0,0 +1,67 @@
+/// $Id$
+/*
+ * Copyright (c) 2006 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * Simple wrapper around the actual timer implementation that automatically
+ * wires it to McuSleepC for low-power calculations..
+ *
+ * @author Philip Levis
+ * @author David Gay
+ */
+
+#include <Atm128Timer.h>
+
+configuration HplAtm128Timer0AsyncC
+{
+  provides {
+    // 8-bit Timers
+    interface HplAtm128Timer<uint8_t>   as Timer;
+    interface HplAtm128TimerCtrl8       as TimerCtrl;
+    interface HplAtm128Compare<uint8_t> as Compare;
+    interface HplAtm128TimerAsync       as TimerAsync;
+  }
+}
+implementation
+{
+  components HplAtm128Timer0AsyncP;
+  components McuSleepC;
+
+  McuSleepC.McuPowerOverride -> HplAtm128Timer0AsyncP;
+
+  Timer = HplAtm128Timer0AsyncP;
+  TimerCtrl = HplAtm128Timer0AsyncP;
+  Compare = HplAtm128Timer0AsyncP;
+  TimerAsync = HplAtm128Timer0AsyncP;
+  
+  components PlatformInterruptC;
+  HplAtm128Timer0AsyncP.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128Timer0AsyncP.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128Timer0AsyncP.nc
new file mode 100644 (file)
index 0000000..e3b4855
--- /dev/null
@@ -0,0 +1,216 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/**
+ * HPL interface to Atmega128 timer 0 in ASYNC mode. This is a specialised
+ * HPL component that assumes that timer 0 is used in ASYNC mode and
+ * includes some workarounds for some of the weirdnesses (delayed overflow
+ * interrupt) of that mode.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <dgay@intel-research.net>
+ */
+
+#include <Atm128Timer.h>
+
+module HplAtm128Timer0AsyncP {
+  provides {
+    // 8-bit Timers
+    interface HplAtm128Timer<uint8_t>   as Timer;
+    interface HplAtm128TimerCtrl8       as TimerCtrl;
+    interface HplAtm128Compare<uint8_t> as Compare;
+    interface McuPowerOverride;
+    interface HplAtm128TimerAsync       as TimerAsync;
+  }
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+  //=== Read the current timer value. ===================================
+  async command uint8_t  Timer.get() { return TCNT0; }
+
+  //=== Set/clear the current timer value. ==============================
+  async command void Timer.set(uint8_t t)  {
+    TCNT0 = t;
+  }
+
+  //=== Read the current timer scale. ===================================
+  async command uint8_t Timer.getScale() { return TCCR0 & 0x7; }
+
+  //=== Turn off the timers. ============================================
+  async command void Timer.off() { call Timer.setScale(AVR_CLOCK_OFF); }
+
+  //=== Write a new timer scale. ========================================
+  async command void Timer.setScale(uint8_t s)  { 
+    Atm128TimerControl_t x = call TimerCtrl.getControl();
+    x.bits.cs = s;
+    call TimerCtrl.setControl(x);  
+  }
+
+  //=== Read the control registers. =====================================
+  async command Atm128TimerControl_t TimerCtrl.getControl() { 
+    return *(Atm128TimerControl_t*)&TCCR0; 
+  }
+
+  //=== Write the control registers. ====================================
+  async command void TimerCtrl.setControl( Atm128TimerControl_t x ) { 
+    TCCR0 = x.flat; 
+  }
+
+  //=== Read the interrupt mask. =====================================
+  async command Atm128_TIMSK_t TimerCtrl.getInterruptMask() { 
+    return *(Atm128_TIMSK_t*)&TIMSK; 
+  }
+
+  //=== Write the interrupt mask. ====================================
+  DEFINE_UNION_CAST(TimerMask8_2int, Atm128_TIMSK_t, uint8_t);
+  DEFINE_UNION_CAST(TimerMask16_2int, Atm128_ETIMSK_t, uint8_t);
+
+  async command void TimerCtrl.setInterruptMask( Atm128_TIMSK_t x ) { 
+    TIMSK = TimerMask8_2int(x); 
+  }
+
+  //=== Read the interrupt flags. =====================================
+  async command Atm128_TIFR_t TimerCtrl.getInterruptFlag() { 
+    return *(Atm128_TIFR_t*)&TIFR; 
+  }
+
+  //=== Write the interrupt flags. ====================================
+  DEFINE_UNION_CAST(TimerFlags8_2int, Atm128_TIFR_t, uint8_t);
+  DEFINE_UNION_CAST(TimerFlags16_2int, Atm128_ETIFR_t, uint8_t);
+
+  async command void TimerCtrl.setInterruptFlag( Atm128_TIFR_t x ) { 
+    TIFR = TimerFlags8_2int(x); 
+  }
+
+  //=== Timer 8-bit implementation. ====================================
+  async command void Timer.reset() { TIFR = 1 << TOV0; }
+  async command void Timer.start() { SET_BIT(TIMSK, TOIE0); }
+  async command void Timer.stop()  { CLR_BIT(TIMSK, TOIE0); }
+
+  bool overflowed() {
+    return (call TimerCtrl.getInterruptFlag()).bits.tov0; 
+  }
+
+  async command bool Timer.test()  { 
+    return overflowed();
+  }
+  async command bool Timer.isOn()  { 
+    return (call TimerCtrl.getInterruptMask()).bits.toie0; 
+  }
+  async command void Compare.reset() { TIFR = 1 << OCF0; }
+  async command void Compare.start() { SET_BIT(TIMSK,OCIE0); }
+  async command void Compare.stop()  { CLR_BIT(TIMSK,OCIE0); }
+  async command bool Compare.test()  { 
+    return (call TimerCtrl.getInterruptFlag()).bits.ocf0; 
+  }
+  async command bool Compare.isOn()  { 
+    return (call TimerCtrl.getInterruptMask()).bits.ocie0; 
+  }
+
+  //=== Read the compare registers. =====================================
+  async command uint8_t Compare.get()   { return OCR0; }
+
+  //=== Write the compare registers. ====================================
+  async command void Compare.set(uint8_t t)   { 
+    OCR0 = t; 
+  }
+
+  //=== Timer interrupts signals ========================================
+  inline void stabiliseTimer0() {
+    TCCR0 = TCCR0;
+    while (ASSR & 1 << TCR0UB)
+      ;
+  }
+
+  /**
+   * On the atm128, there is a small latency when waking up from
+   * POWER_SAVE mode. So if a timer is going to go off very soon, it's
+   * better to drop down until EXT_STANDBY, which has a 6 cycle wakeup
+   * latency. This function calculates whether staying in EXT_STANDBY
+   * is needed. If the timer is not running it returns POWER_DOWN.
+   * Please refer to TEP 112 and the atm128 datasheet for details.
+   */
+  
+  async command mcu_power_t McuPowerOverride.lowestState() {
+    uint8_t diff;
+    // We need to make sure that the sleep wakeup latency will not
+    // cause us to miss a timer. POWER_SAVE 
+    if (TIMSK & (1 << OCIE0 | 1 << TOIE0)) {
+      // need to wait for timer 0 updates propagate before sleeping
+      // (we don't need to worry about reentering sleep mode too early,
+      // as the wake ups from timer0 wait at least one TOSC1 cycle
+      // anyway - see the stabiliseTimer0 function)
+      while (ASSR & (1 << TCN0UB | 1 << OCR0UB | 1 << TCR0UB))
+       ;
+      diff = OCR0 - TCNT0;
+      if (diff < EXT_STANDBY_T0_THRESHOLD ||
+         TCNT0 > 256 - EXT_STANDBY_T0_THRESHOLD) 
+       return ATM128_POWER_EXT_STANDBY;
+      return ATM128_POWER_SAVE;
+    }
+    else {
+      return ATM128_POWER_DOWN;
+    }
+  }
+  
+  default async event void Compare.fired() { }
+  AVR_ATOMIC_HANDLER(SIG_OUTPUT_COMPARE0) {
+    stabiliseTimer0();
+    signal Compare.fired();
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void Timer.overflow() { }
+  AVR_ATOMIC_HANDLER(SIG_OVERFLOW0) {
+    stabiliseTimer0();
+    signal Timer.overflow();
+    call PlatformInterrupt.postAmble();
+  }
+
+  // Asynchronous status register support
+  async command Atm128Assr_t TimerAsync.getAssr() {
+    return *(Atm128Assr_t *)&ASSR;
+  }
+
+  async command void TimerAsync.setAssr(Atm128Assr_t x) {
+    ASSR = x.flat;
+  }
+
+  async command void TimerAsync.setTimer0Asynchronous() {
+    ASSR |= 1 << AS0;
+  }
+
+  async command int TimerAsync.controlBusy() {
+    return (ASSR & (1 << TCR0UB)) != 0;
+  }
+
+  async command int TimerAsync.compareBusy() {
+    return (ASSR & (1 << OCR0UB)) != 0;
+  }
+
+  async command int TimerAsync.countBusy() {
+    return (ASSR & (1 << TCN0UB)) != 0;
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128Timer1C.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128Timer1C.nc
new file mode 100644 (file)
index 0000000..ba57d24
--- /dev/null
@@ -0,0 +1,58 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/**
+ * HPL interface to Atmega128 timer 1.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <dgay@intel-research.net>
+ */
+
+configuration HplAtm128Timer1C
+{
+  provides {
+    // 16-bit Timers
+    interface HplAtm128Timer<uint16_t>   as Timer;
+    interface HplAtm128TimerCtrl16       as TimerCtrl;
+    interface HplAtm128Capture<uint16_t> as Capture;
+    interface HplAtm128Compare<uint16_t> as Compare[uint8_t id];
+  }
+}
+implementation
+{
+  components HplAtm128Timer0AsyncC, HplAtm128Timer1P;
+
+  Timer = HplAtm128Timer1P;
+  TimerCtrl = HplAtm128Timer1P;
+  Capture = HplAtm128Timer1P;
+
+  Compare[0] = HplAtm128Timer1P.CompareA; 
+  Compare[1] = HplAtm128Timer1P.CompareB;
+  Compare[2] = HplAtm128Timer1P.CompareC;
+
+  HplAtm128Timer1P.Timer0Ctrl -> HplAtm128Timer0AsyncC;
+  
+  components PlatformInterruptC;
+  HplAtm128Timer1P.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128Timer1P.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128Timer1P.nc
new file mode 100644 (file)
index 0000000..1861615
--- /dev/null
@@ -0,0 +1,220 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/**
+ * Internal component of the HPL interface to Atmega128 timer 1.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ */
+
+#include <Atm128Timer.h>
+
+module HplAtm128Timer1P
+{
+  provides {
+    // 16-bit Timers
+    interface HplAtm128Timer<uint16_t>   as Timer;
+    interface HplAtm128TimerCtrl16       as TimerCtrl;
+    interface HplAtm128Capture<uint16_t> as Capture;
+    interface HplAtm128Compare<uint16_t> as CompareA;
+    interface HplAtm128Compare<uint16_t> as CompareB;
+    interface HplAtm128Compare<uint16_t> as CompareC;
+  }
+  uses interface HplAtm128TimerCtrl8     as Timer0Ctrl;
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+  //=== Read the current timer value. ===================================
+  async command uint16_t Timer.get() { return TCNT1; }
+
+  //=== Set/clear the current timer value. ==============================
+  async command void Timer.set(uint16_t t) { TCNT1 = t; }
+
+  //=== Read the current timer scale. ===================================
+  async command uint8_t Timer.getScale() { return TCCR1B & 0x7; }
+
+  //=== Turn off the timers. ============================================
+  async command void Timer.off() { call Timer.setScale(AVR_CLOCK_OFF); }
+
+  //=== Write a new timer scale. ========================================
+  async command void Timer.setScale(uint8_t s)  { 
+    Atm128TimerCtrlCapture_t x = call TimerCtrl.getCtrlCapture();
+    x.bits.cs = s;
+    call TimerCtrl.setCtrlCapture(x);  
+  }
+
+  //=== Read the control registers. =====================================
+  async command Atm128TimerCtrlCompare_t TimerCtrl.getCtrlCompare() { 
+    return *(Atm128TimerCtrlCompare_t*)&TCCR1A; 
+  }
+  async command Atm128TimerCtrlCapture_t TimerCtrl.getCtrlCapture() { 
+    return *(Atm128TimerCtrlCapture_t*)&TCCR1B; 
+  }
+  async command Atm128TimerCtrlClock_t TimerCtrl.getCtrlClock() { 
+    return *(Atm128TimerCtrlClock_t*)&TCCR1C; 
+  }
+
+
+  //=== Control registers utilities. ==================================
+  DEFINE_UNION_CAST(TimerCtrlCompare2int, Atm128TimerCtrlCompare_t, uint16_t);
+  DEFINE_UNION_CAST(TimerCtrlCapture2int, Atm128TimerCtrlCapture_t, uint16_t);
+  DEFINE_UNION_CAST(TimerCtrlClock2int, Atm128TimerCtrlClock_t, uint16_t);
+
+  //=== Write the control registers. ====================================
+  async command void TimerCtrl.setCtrlCompare( Atm128_TCCR1A_t x ) { 
+    TCCR1A = TimerCtrlCompare2int(x); 
+  }
+  async command void TimerCtrl.setCtrlCapture( Atm128_TCCR1B_t x ) { 
+    TCCR1B = TimerCtrlCapture2int(x); 
+  }
+  async command void TimerCtrl.setCtrlClock( Atm128_TCCR1C_t x ) { 
+    TCCR1C = TimerCtrlClock2int(x); 
+  }
+
+  //=== Read the interrupt mask. =====================================
+  async command Atm128_ETIMSK_t TimerCtrl.getInterruptMask() { 
+    return *(Atm128_ETIMSK_t*)&ETIMSK; 
+  }
+
+  //=== Write the interrupt mask. ====================================
+  DEFINE_UNION_CAST(TimerMask8_2int, Atm128_TIMSK_t, uint8_t);
+  DEFINE_UNION_CAST(TimerMask16_2int, Atm128_ETIMSK_t, uint8_t);
+
+  async command void TimerCtrl.setInterruptMask( Atm128_ETIMSK_t x ) { 
+    ETIMSK = TimerMask16_2int(x); 
+  }
+
+  //=== Read the interrupt flags. =====================================
+  async command Atm128_ETIFR_t TimerCtrl.getInterruptFlag() { 
+    return *(Atm128_ETIFR_t*)&ETIFR; 
+  }
+
+  //=== Write the interrupt flags. ====================================
+  DEFINE_UNION_CAST(TimerFlags8_2int, Atm128_TIFR_t, uint8_t);
+  DEFINE_UNION_CAST(TimerFlags16_2int, Atm128_ETIFR_t, uint8_t);
+
+  async command void TimerCtrl.setInterruptFlag( Atm128_ETIFR_t x ) { 
+    ETIFR = TimerFlags16_2int(x); 
+  }
+
+  //=== Capture 16-bit implementation. ===================================
+  async command void Capture.setEdge(bool up) { WRITE_BIT(TCCR1B,ICES1, up); }
+
+  //=== Timer 16-bit implementation. ===================================
+  async command void Timer.reset()    { TIFR = 1 << TOV1; }
+  async command void Capture.reset()  { TIFR = 1 << ICF1; }
+  async command void CompareA.reset() { TIFR = 1 << OCF1A; }
+  async command void CompareB.reset() { TIFR = 1 << OCF1B; }
+  async command void CompareC.reset() { ETIFR = 1 << OCF1C; }
+
+  async command void Timer.start()    { SET_BIT(TIMSK,TOIE1); }
+  async command void Capture.start()  { SET_BIT(TIMSK,TICIE1); }
+  async command void CompareA.start() { SET_BIT(TIMSK,OCIE1A); }
+  async command void CompareB.start() { SET_BIT(TIMSK,OCIE1B); }
+  async command void CompareC.start() { SET_BIT(ETIMSK,OCIE1C); }
+
+  async command void Timer.stop()    { CLR_BIT(TIMSK,TOIE1); }
+  async command void Capture.stop()  { CLR_BIT(TIMSK,TICIE1); }
+  async command void CompareA.stop() { CLR_BIT(TIMSK,OCIE1A); }
+  async command void CompareB.stop() { CLR_BIT(TIMSK,OCIE1B); }
+  async command void CompareC.stop() { CLR_BIT(ETIMSK,OCIE1C); }
+
+  // Note: Many Timer interrupt flags are on Timer0 register
+  async command bool Timer.test() { 
+    return (call Timer0Ctrl.getInterruptFlag()).bits.tov1; 
+  }
+  async command bool Capture.test()  { 
+    return (call Timer0Ctrl.getInterruptFlag()).bits.icf1; 
+  }
+  async command bool CompareA.test() { 
+    return (call Timer0Ctrl.getInterruptFlag()).bits.ocf1a; 
+  }
+  async command bool CompareB.test() { 
+    return (call Timer0Ctrl.getInterruptFlag()).bits.ocf1b; 
+  }
+  async command bool CompareC.test() { 
+    return (call TimerCtrl.getInterruptFlag()).bits.ocf1c; 
+  }
+
+  // Note: Many Timer interrupt mask bits are on Timer0 register
+  async command bool Timer.isOn() {
+    return (call Timer0Ctrl.getInterruptMask()).bits.toie1;
+  }
+  async command bool Capture.isOn()  {
+    return (call Timer0Ctrl.getInterruptMask()).bits.ticie1;
+  }
+  async command bool CompareA.isOn() {
+    return (call Timer0Ctrl.getInterruptMask()).bits.ocie1a;
+  }
+  async command bool CompareB.isOn() {
+    return (call Timer0Ctrl.getInterruptMask()).bits.ocie1b;
+  }
+  async command bool CompareC.isOn() {
+    return (call TimerCtrl.getInterruptMask()).bits.ocie1c;
+  }
+
+  //=== Read the compare registers. =====================================
+  async command uint16_t CompareA.get() { return OCR1A; }
+  async command uint16_t CompareB.get() { return OCR1B; }
+  async command uint16_t CompareC.get() { return OCR1C; }
+
+  //=== Write the compare registers. ====================================
+  async command void CompareA.set(uint16_t t) { OCR1A = t; }
+  async command void CompareB.set(uint16_t t) { OCR1B = t; }
+  async command void CompareC.set(uint16_t t) { OCR1C = t; }
+
+  //=== Read the capture registers. =====================================
+  async command uint16_t Capture.get() { return ICR1; }
+
+  //=== Write the capture registers. ====================================
+  async command void Capture.set(uint16_t t)  { ICR1 = t; }
+
+  //=== Timer interrupts signals ========================================
+  default async event void CompareA.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE1A) {
+    signal CompareA.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void CompareB.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE1B) {
+    signal CompareB.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void CompareC.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE1C) {
+    signal CompareC.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void Capture.captured(uint16_t time) { }
+  AVR_NONATOMIC_HANDLER(SIG_INPUT_CAPTURE1) {
+    signal Capture.captured(call Timer.get());
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void Timer.overflow() { }
+  AVR_NONATOMIC_HANDLER(SIG_OVERFLOW1) {
+    signal Timer.overflow();
+    call PlatformInterrupt.postAmble();
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128Timer2C.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128Timer2C.nc
new file mode 100644 (file)
index 0000000..c68793f
--- /dev/null
@@ -0,0 +1,139 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/**
+ * HPL interface to Atmega128 timer 2.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ */
+
+#include <Atm128Timer.h>
+
+module HplAtm128Timer2C
+{
+  provides {
+    interface HplAtm128Timer<uint8_t>   as Timer;
+    interface HplAtm128TimerCtrl8       as TimerCtrl;
+    interface HplAtm128Compare<uint8_t> as Compare;
+  }
+  uses interface ThreadScheduler;
+}
+implementation
+{
+  //=== Read the current timer value. ===================================
+  async command uint8_t  Timer.get() { return TCNT2; }
+
+  //=== Set/clear the current timer value. ==============================
+  async command void Timer.set(uint8_t t)  { TCNT2 = t; }
+
+  //=== Read the current timer scale. ===================================
+  async command uint8_t Timer.getScale() { return TCCR2 & 0x7; }
+
+  //=== Turn off the timers. ============================================
+  async command void Timer.off() { call Timer.setScale(AVR_CLOCK_OFF); }
+
+  //=== Write a new timer scale. ========================================
+  async command void Timer.setScale(uint8_t s)  { 
+    Atm128TimerControl_t x = call TimerCtrl.getControl();
+    x.bits.cs = s;
+    call TimerCtrl.setControl(x);  
+  }
+
+  //=== Read the control registers. =====================================
+  async command Atm128TimerControl_t TimerCtrl.getControl() { 
+    return *(Atm128TimerControl_t*)&TCCR2; 
+  }
+
+  //=== Control registers utilities. ==================================
+  DEFINE_UNION_CAST(TimerCtrlCompareint, Atm128TimerCtrlCompare_t, uint16_t);
+  DEFINE_UNION_CAST(TimerCtrlCapture2int, Atm128TimerCtrlCapture_t, uint16_t);
+  DEFINE_UNION_CAST(TimerCtrlClock2int, Atm128TimerCtrlClock_t, uint16_t);
+
+  //=== Write the control registers. ====================================
+  async command void TimerCtrl.setControl( Atm128TimerControl_t x ) { 
+    TCCR2 = x.flat; 
+  }
+
+  //=== Read the interrupt mask. =====================================
+  async command Atm128_TIMSK_t TimerCtrl.getInterruptMask() { 
+    return *(Atm128_TIMSK_t*)&TIMSK; 
+  }
+
+  //=== Write the interrupt mask. ====================================
+  DEFINE_UNION_CAST(TimerMask8_2int, Atm128_TIMSK_t, uint8_t);
+
+  async command void TimerCtrl.setInterruptMask( Atm128_TIMSK_t x ) { 
+    TIMSK = TimerMask8_2int(x); 
+  }
+
+  //=== Read the interrupt flags. =====================================
+  async command Atm128_TIFR_t TimerCtrl.getInterruptFlag() { 
+    return *(Atm128_TIFR_t*)&TIFR; 
+  }
+
+  //=== Write the interrupt flags. ====================================
+  DEFINE_UNION_CAST(TimerFlags8_2int, Atm128_TIFR_t, uint8_t);
+
+  async command void TimerCtrl.setInterruptFlag( Atm128_TIFR_t x ) { 
+    TIFR = TimerFlags8_2int(x); 
+  }
+
+  //=== Timer 8-bit implementation. ====================================
+  async command void Timer.reset() { TIFR = 1 << TOV2; }
+  async command void Timer.start() { SET_BIT(TIMSK,TOIE2); }
+  async command void Timer.stop()  { CLR_BIT(TIMSK,TOIE2); }
+  async command bool Timer.test()  { 
+    return (call TimerCtrl.getInterruptFlag()).bits.tov2; 
+  }
+  async command bool Timer.isOn()  { 
+    return (call TimerCtrl.getInterruptMask()).bits.toie2; 
+  }
+  async command void Compare.reset() { TIFR = 1 << OCF2; }
+  async command void Compare.start() { SET_BIT(TIMSK,OCIE2); }
+  async command void Compare.stop()  { CLR_BIT(TIMSK,OCIE2); }
+  async command bool Compare.test()  { 
+    return (call TimerCtrl.getInterruptFlag()).bits.ocf2; 
+  }
+  async command bool Compare.isOn()  { 
+    return (call TimerCtrl.getInterruptMask()).bits.ocie2; 
+  }
+
+  //=== Read the compare registers. =====================================
+  async command uint8_t Compare.get()   { return OCR2; }
+
+  //=== Write the compare registers. ====================================
+  async command void Compare.set(uint8_t t)   { OCR2 = t; }
+
+  //=== Timer interrupts signals ========================================
+  default async event void Compare.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE2) {
+    signal Compare.fired();
+    call ThreadScheduler.interruptPostAmble();
+  }
+  default async event void Timer.overflow() { }
+  AVR_NONATOMIC_HANDLER(SIG_OVERFLOW2) {
+    signal Timer.overflow();
+    call ThreadScheduler.interruptPostAmble();
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128Timer3C.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128Timer3C.nc
new file mode 100644 (file)
index 0000000..7db7102
--- /dev/null
@@ -0,0 +1,56 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/**
+ * HPL interface to Atmega128 timer 2.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <david.e.gay@intel.com>
+ */
+
+configuration HplAtm128Timer3C
+{
+  provides {
+    // 16-bit Timers
+    interface HplAtm128Timer<uint16_t>   as Timer;
+    interface HplAtm128TimerCtrl16       as TimerCtrl;
+    interface HplAtm128Capture<uint16_t> as Capture;
+    interface HplAtm128Compare<uint16_t> as Compare[uint8_t id];
+  }
+}
+implementation
+{
+  components HplAtm128Timer3P;
+
+  Timer = HplAtm128Timer3P;
+  TimerCtrl = HplAtm128Timer3P;
+  Capture = HplAtm128Timer3P;
+
+  Compare[0] = HplAtm128Timer3P.CompareA; 
+  Compare[1] = HplAtm128Timer3P.CompareB;
+  Compare[2] = HplAtm128Timer3P.CompareC;
+  
+  components PlatformInterruptC;
+  HplAtm128Timer3P.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128Timer3P.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128Timer3P.nc
new file mode 100644 (file)
index 0000000..e907a9b
--- /dev/null
@@ -0,0 +1,214 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/**
+ * Internal componentr of the HPL interface to Atmega128 timer 3.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ */
+
+#include <Atm128Timer.h>
+
+module HplAtm128Timer3P
+{
+  provides {
+    interface HplAtm128Timer<uint16_t>   as Timer;
+    interface HplAtm128TimerCtrl16       as TimerCtrl;
+    interface HplAtm128Capture<uint16_t> as Capture;
+    interface HplAtm128Compare<uint16_t> as CompareA;
+    interface HplAtm128Compare<uint16_t> as CompareB;
+    interface HplAtm128Compare<uint16_t> as CompareC;
+  }
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+  //=== Read the current timer value. ===================================
+  async command uint16_t Timer.get() { return TCNT3; }
+
+  //=== Set/clear the current timer value. ==============================
+  async command void Timer.set(uint16_t t) { TCNT3 = t; }
+
+  //=== Read the current timer scale. ===================================
+  async command uint8_t Timer.getScale() { return TCCR3B & 0x7; }
+
+  //=== Turn off the timers. ============================================
+  async command void Timer.off() { call Timer.setScale(AVR_CLOCK_OFF); }
+
+  //=== Write a new timer scale. ========================================
+  async command void Timer.setScale(uint8_t s)  { 
+    Atm128TimerCtrlCapture_t x = call TimerCtrl.getCtrlCapture();
+    x.bits.cs = s;
+    call TimerCtrl.setCtrlCapture(x);  
+  }
+
+  //=== Read the control registers. =====================================
+  async command Atm128TimerCtrlCompare_t TimerCtrl.getCtrlCompare() { 
+    return *(Atm128TimerCtrlCompare_t*)&TCCR3A; 
+  }
+  async command Atm128TimerCtrlCapture_t TimerCtrl.getCtrlCapture() { 
+    return *(Atm128TimerCtrlCapture_t*)&TCCR3B; 
+  }
+  async command Atm128TimerCtrlClock_t TimerCtrl.getCtrlClock() { 
+    return *(Atm128TimerCtrlClock_t*)&TCCR3C; 
+  }
+
+
+  //=== Control registers utilities. ==================================
+  DEFINE_UNION_CAST(TimerCtrlCompare2int, Atm128TimerCtrlCompare_t, uint16_t);
+  DEFINE_UNION_CAST(TimerCtrlCapture2int, Atm128TimerCtrlCapture_t, uint16_t);
+  DEFINE_UNION_CAST(TimerCtrlClock2int, Atm128TimerCtrlClock_t, uint16_t);
+
+  //=== Write the control registers. ====================================
+  async command void TimerCtrl.setCtrlCompare( Atm128_TCCR3A_t x ) { 
+    TCCR3A = TimerCtrlCompare2int(x); 
+  }
+  async command void TimerCtrl.setCtrlCapture( Atm128_TCCR3B_t x ) { 
+    TCCR3B = TimerCtrlCapture2int(x); 
+  }
+  async command void TimerCtrl.setCtrlClock( Atm128_TCCR3C_t x ) { 
+    TCCR3C = TimerCtrlClock2int(x); 
+  }
+
+  //=== Read the interrupt mask. =====================================
+  async command Atm128_ETIMSK_t TimerCtrl.getInterruptMask() { 
+    return *(Atm128_ETIMSK_t*)&ETIMSK; 
+  }
+
+  //=== Write the interrupt mask. ====================================
+  DEFINE_UNION_CAST(TimerMask16_2int, Atm128_ETIMSK_t, uint8_t);
+
+  async command void TimerCtrl.setInterruptMask( Atm128_ETIMSK_t x ) { 
+    ETIMSK = TimerMask16_2int(x); 
+  }
+
+  //=== Read the interrupt flags. =====================================
+  async command Atm128_ETIFR_t TimerCtrl.getInterruptFlag() { 
+    return *(Atm128_ETIFR_t*)&ETIFR; 
+  }
+
+  //=== Write the interrupt flags. ====================================
+  DEFINE_UNION_CAST(TimerFlags16_2int, Atm128_ETIFR_t, uint8_t);
+
+  async command void TimerCtrl.setInterruptFlag( Atm128_ETIFR_t x ) { 
+    ETIFR = TimerFlags16_2int(x); 
+  }
+
+  //=== Capture 16-bit implementation. ===================================
+  async command void Capture.setEdge(bool up) { WRITE_BIT(TCCR3B,ICES3, up); }
+
+  //=== Timer 16-bit implementation. ===================================
+  async command void Timer.reset()    { ETIFR = 1 << TOV3; }
+  async command void Capture.reset()  { ETIFR = 1 << ICF3; }
+  async command void CompareA.reset() { ETIFR = 1 << OCF3A; }
+  async command void CompareB.reset() { ETIFR = 1 << OCF3B; }
+  async command void CompareC.reset() { ETIFR = 1 << OCF3C; }
+
+  async command void Timer.start()    { SET_BIT(ETIMSK,TOIE3); }
+  async command void Capture.start()  { SET_BIT(ETIMSK,TICIE3); }
+  async command void CompareA.start() { SET_BIT(ETIMSK,OCIE3A); }
+  async command void CompareB.start() { SET_BIT(ETIMSK,OCIE3B); }
+  async command void CompareC.start() { SET_BIT(ETIMSK,OCIE3C); }
+
+  async command void Timer.stop()    { CLR_BIT(ETIMSK,TOIE3); }
+  async command void Capture.stop()  { CLR_BIT(ETIMSK,TICIE3); }
+  async command void CompareA.stop() { CLR_BIT(ETIMSK,OCIE3A); }
+  async command void CompareB.stop() { CLR_BIT(ETIMSK,OCIE3B); }
+  async command void CompareC.stop() { CLR_BIT(ETIMSK,OCIE3C); }
+
+  async command bool Timer.test() { 
+    return (call TimerCtrl.getInterruptFlag()).bits.tov3; 
+  }
+  async command bool Capture.test()  { 
+    return (call TimerCtrl.getInterruptFlag()).bits.icf3; 
+  }
+  async command bool CompareA.test() { 
+    return (call TimerCtrl.getInterruptFlag()).bits.ocf3a; 
+  }
+  async command bool CompareB.test() { 
+    return (call TimerCtrl.getInterruptFlag()).bits.ocf3b; 
+  }
+  async command bool CompareC.test() { 
+    return (call TimerCtrl.getInterruptFlag()).bits.ocf3c; 
+  }
+
+  async command bool Timer.isOn() {
+    return (call TimerCtrl.getInterruptMask()).bits.toie3;
+  }
+  async command bool Capture.isOn()  {
+    return (call TimerCtrl.getInterruptMask()).bits.ticie3;
+  }
+  async command bool CompareA.isOn() {
+    return (call TimerCtrl.getInterruptMask()).bits.ocie3a;
+  }
+  async command bool CompareB.isOn() {
+    return (call TimerCtrl.getInterruptMask()).bits.ocie3b;
+  }
+  async command bool CompareC.isOn() {
+    return (call TimerCtrl.getInterruptMask()).bits.ocie3c;
+  }
+
+  //=== Read the compare registers. =====================================
+  async command uint16_t CompareA.get() { return OCR3A; }
+  async command uint16_t CompareB.get() { return OCR3B; }
+  async command uint16_t CompareC.get() { return OCR3C; }
+
+  //=== Write the compare registers. ====================================
+  async command void CompareA.set(uint16_t t) { OCR3A = t; }
+  async command void CompareB.set(uint16_t t) { OCR3B = t; }
+  async command void CompareC.set(uint16_t t) { OCR3C = t; }
+
+  //=== Read the capture registers. =====================================
+  async command uint16_t Capture.get() { return ICR3; }
+
+  //=== Write the capture registers. ====================================
+  async command void Capture.set(uint16_t t)  { ICR3 = t; }
+
+  //=== Timer interrupts signals ========================================
+  default async event void CompareA.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE3A) {
+    signal CompareA.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void CompareB.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE3B) {
+    signal CompareB.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void CompareC.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE3C) {
+    signal CompareC.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void Capture.captured(uint16_t time) { }
+  AVR_NONATOMIC_HANDLER(SIG_INPUT_CAPTURE3) {
+    signal Capture.captured(call Timer.get());
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void Timer.overflow() { }
+  AVR_NONATOMIC_HANDLER(SIG_OVERFLOW3) {
+    signal Timer.overflow();
+    call PlatformInterrupt.postAmble();
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128UartC.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128UartC.nc
new file mode 100644 (file)
index 0000000..b69d417
--- /dev/null
@@ -0,0 +1,68 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/// 
+
+#include <Atm128Uart.h>
+
+/**
+ * HPL for the Atmega 128 serial ports.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay
+ */
+configuration HplAtm128UartC
+{
+  provides {
+    interface StdControl as Uart0TxControl;
+    interface StdControl as Uart0RxControl;
+    interface HplAtm128Uart as HplUart0;
+    
+    interface StdControl as Uart1TxControl;
+    interface StdControl as Uart1RxControl;
+    interface HplAtm128Uart as HplUart1;
+  }
+}
+implementation
+{
+  components HplAtm128UartP, PlatformC, McuSleepC;
+  
+  Uart0TxControl = HplAtm128UartP.Uart0TxControl;
+  Uart0RxControl = HplAtm128UartP.Uart0RxControl;
+  HplUart0 = HplAtm128UartP.HplUart0;
+  
+  Uart1TxControl = HplAtm128UartP.Uart1TxControl;
+  Uart1RxControl = HplAtm128UartP.Uart1RxControl;
+  HplUart1 = HplAtm128UartP.HplUart1;
+  
+  HplAtm128UartP.Atm128Calibrate -> PlatformC;
+  HplAtm128UartP.McuPowerState -> McuSleepC;
+  
+  components MainC;
+  MainC.SoftwareInit -> HplAtm128UartP.Uart0Init;
+  MainC.SoftwareInit -> HplAtm128UartP.Uart1Init;
+  
+  components PlatformInterruptC;
+  HplAtm128UartP.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/atm128/HplAtm128UartP.nc b/tos/lib/tosthreads/chips/atm128/HplAtm128UartP.nc
new file mode 100644 (file)
index 0000000..f9ef70b
--- /dev/null
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2006 Arch Rock 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 Arch Rock 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
+ * ARCH ROCK 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
+ */
+
+/**
+ * @author Alec Woo <awoo@archrock.com>
+ * @author Jonathan Hui <jhui@archrock.com>
+ * @version $Revision$ $Date$
+ */
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/** 
+ * Private component of the Atmega128 serial port HPL.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay
+ */
+
+#include <Atm128Uart.h>
+
+module HplAtm128UartP {
+  
+  provides interface Init as Uart0Init;
+  provides interface StdControl as Uart0TxControl;
+  provides interface StdControl as Uart0RxControl;
+  provides interface HplAtm128Uart as HplUart0;
+    
+  provides interface Init as Uart1Init;
+  provides interface StdControl as Uart1TxControl;
+  provides interface StdControl as Uart1RxControl;
+  provides interface HplAtm128Uart as HplUart1;
+  
+  uses interface Atm128Calibrate;
+  uses interface McuPowerState;
+  uses interface PlatformInterrupt;
+}
+implementation {
+  
+  //=== Uart Init Commands. ====================================
+  command error_t Uart0Init.init() {
+    Atm128UartMode_t    mode;
+    Atm128UartStatus_t  stts;
+    Atm128UartControl_t ctrl;
+    uint16_t ubrr0;
+
+    ctrl.bits = (struct Atm128_UCSRB_t) {rxcie:0, txcie:0, rxen:0, txen:0};
+    stts.bits = (struct Atm128_UCSRA_t) {u2x:1};
+    mode.bits = (struct Atm128_UCSRC_t) {ucsz:ATM128_UART_DATA_SIZE_8_BITS};
+
+    ubrr0 = call Atm128Calibrate.baudrateRegister(PLATFORM_BAUDRATE);
+    UBRR0L = ubrr0;
+    UBRR0H = ubrr0 >> 8;
+    UCSR0A = stts.flat;
+    UCSR0C = mode.flat;
+    UCSR0B = ctrl.flat;
+
+    return SUCCESS;
+  }
+
+  command error_t Uart0TxControl.start() {
+    SET_BIT(UCSR0B, TXEN);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart0TxControl.stop() {
+    CLR_BIT(UCSR0B, TXEN);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart0RxControl.start() {
+    SET_BIT(UCSR0B, RXEN);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart0RxControl.stop() {
+    CLR_BIT(UCSR0B, RXEN);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart0.enableTxIntr() {
+    SET_BIT(UCSR0A, TXC);
+    SET_BIT(UCSR0B, TXCIE);
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart0.disableTxIntr(){
+    CLR_BIT(UCSR0B, TXCIE);
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart0.enableRxIntr(){
+    SET_BIT(UCSR0B, RXCIE);
+    return SUCCESS;
+  }
+
+  async command error_t HplUart0.disableRxIntr(){
+    CLR_BIT(UCSR0B, RXCIE);
+    return SUCCESS;
+  }
+  
+  async command bool HplUart0.isTxEmpty(){
+    return READ_BIT(UCSR0A, TXC);
+  }
+
+  async command bool HplUart0.isRxEmpty(){
+    return !READ_BIT(UCSR0A, RXC);
+  }
+  
+  async command uint8_t HplUart0.rx(){
+    return UDR0;
+  }
+
+  async command void HplUart0.tx(uint8_t data) {
+    atomic{
+      UDR0 = data; 
+      SET_BIT(UCSR0A, TXC);
+    }
+  }
+  
+  AVR_ATOMIC_HANDLER(SIG_UART0_RECV) {
+    if (READ_BIT(UCSR0A, RXC)) {
+      signal HplUart0.rxDone(UDR0);
+    }
+    call PlatformInterrupt.postAmble();
+  }
+  
+  AVR_NONATOMIC_HANDLER(SIG_UART0_TRANS) {
+    signal HplUart0.txDone();
+    call PlatformInterrupt.postAmble();
+  }
+  
+  command error_t Uart1Init.init() {
+    Atm128UartMode_t    mode;
+    Atm128UartStatus_t  stts;
+    Atm128UartControl_t ctrl;
+    uint16_t ubrr1;
+    
+    ctrl.bits = (struct Atm128_UCSRB_t) {rxcie:0, txcie:0, rxen:0, txen:0};
+    stts.bits = (struct Atm128_UCSRA_t) {u2x:1};
+    mode.bits = (struct Atm128_UCSRC_t) {ucsz:ATM128_UART_DATA_SIZE_8_BITS};
+
+    ubrr1 = call Atm128Calibrate.baudrateRegister(PLATFORM_BAUDRATE);
+    UBRR1L = ubrr1;
+    UBRR1H = ubrr1 >> 8;
+    UCSR1A = stts.flat;
+    UCSR1C = mode.flat;
+    UCSR1B = ctrl.flat;
+
+    return SUCCESS;
+  }
+
+  command error_t Uart1TxControl.start() {
+    SET_BIT(UCSR1B, TXEN);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart1TxControl.stop() {
+    CLR_BIT(UCSR1B, TXEN);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart1RxControl.start() {
+    SET_BIT(UCSR1B, RXEN);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart1RxControl.stop() {
+    CLR_BIT(UCSR1B, RXEN);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart1.enableTxIntr() {
+    SET_BIT(UCSR1A, TXC);
+    SET_BIT(UCSR1B, TXCIE);
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart1.disableTxIntr(){
+    CLR_BIT(UCSR1B, TXCIE);
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart1.enableRxIntr(){
+    SET_BIT(UCSR1B, RXCIE);
+    return SUCCESS;
+  }
+
+  async command error_t HplUart1.disableRxIntr(){
+    CLR_BIT(UCSR1B, RXCIE);
+    return SUCCESS;
+  }
+  
+  async command bool HplUart1.isTxEmpty() {
+    return READ_BIT(UCSR1A, TXC);
+  }
+
+  async command bool HplUart1.isRxEmpty() {
+    return !READ_BIT(UCSR1A, RXC);
+  }
+  
+  async command uint8_t HplUart1.rx(){
+    return UDR1;
+  }
+
+  async command void HplUart1.tx(uint8_t data) {
+    atomic{
+      UDR1 = data; 
+      SET_BIT(UCSR1A, TXC);
+    }
+  }
+  
+  AVR_ATOMIC_HANDLER(SIG_UART1_RECV) {
+    if (READ_BIT(UCSR1A, RXC))
+      signal HplUart1.rxDone(UDR1);
+    call PlatformInterrupt.postAmble();
+  }
+  
+  AVR_NONATOMIC_HANDLER(SIG_UART1_TRANS) {
+    signal HplUart1.txDone();
+    call PlatformInterrupt.postAmble();
+  }
+  
+  default async event void HplUart0.txDone() {} 
+  default async event void HplUart0.rxDone(uint8_t data) {}
+  default async event void HplUart1.txDone() {}
+  default async event void HplUart1.rxDone(uint8_t data) {}
+  
+}
diff --git a/tos/lib/tosthreads/chips/atm128/chip_thread.h b/tos/lib/tosthreads/chips/atm128/chip_thread.h
new file mode 100644 (file)
index 0000000..ed56172
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * This file is derived from similar files in the TinyThread implementation
+ * by William P. McCartney from Cleveland State University (2006)
+ *
+ * This file contains MSP430 platform-specific routines for implementing
+ * threads in TinyOS
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+//Define on platform specific basis for inclusion in
+// the thread control block
+typedef struct thread_regs {
+  uint8_t status;
+  uint8_t r0;
+  uint8_t r1;
+  uint8_t r2;
+  uint8_t r3;
+  uint8_t r4;
+  uint8_t r5;
+  uint8_t r6;
+  uint8_t r7;
+  uint8_t r8;
+  uint8_t r9;
+  uint8_t r10;
+  uint8_t r11;
+  uint8_t r12;
+  uint8_t r13;
+  uint8_t r14;
+  uint8_t r15;
+  uint8_t r16;
+  uint8_t r17;
+  uint8_t r18;
+  uint8_t r19;
+  uint8_t r20;
+  uint8_t r21;
+  uint8_t r22;
+  uint8_t r23;
+  uint8_t r24;
+  uint8_t r25;
+  uint8_t r26;
+  uint8_t r27;
+  uint8_t r28;
+  uint8_t r29;
+  uint8_t r30;
+  uint8_t r31;
+} thread_regs_t;
+
+typedef uint16_t* stack_ptr_t;
+  
+#define STACK_TOP(stack, size)    \
+  (&(((uint8_t*)stack)[size - sizeof(stack_ptr_t)]))
+  
+//Save stack pointer
+#define SAVE_STACK_PTR(t)                                      \
+  __asm__("in %A0, __SP_L__\n\t"                                       \
+          "in %B0, __SP_H__\n\t"                                       \
+          :"=r"((t)->stack_ptr) : );
+
+//Save status register
+#define SAVE_STATUS(t)                                         \
+  __asm__("in %0,__SREG__ \n\t" : "=r" ((t)->regs.status) : );
+  
+//Save General Purpose Registers
+#define SAVE_GPR(t)                                                \
+  __asm__("mov %0,r0 \n\t" : "=r" ((t)->regs.r0) : );   \
+  __asm__("mov %0,r1 \n\t" : "=r" ((t)->regs.r1) : );   \
+  __asm__("mov %0,r2 \n\t" : "=r" ((t)->regs.r2) : );   \
+  __asm__("mov %0,r3 \n\t" : "=r" ((t)->regs.r3) : );   \
+  __asm__("mov %0,r4 \n\t" : "=r" ((t)->regs.r4) : );   \
+  __asm__("mov %0,r5 \n\t" : "=r" ((t)->regs.r5) : );   \
+  __asm__("mov %0,r6 \n\t" : "=r" ((t)->regs.r6) : );   \
+  __asm__("mov %0,r7 \n\t" : "=r" ((t)->regs.r7) : );   \
+  __asm__("mov %0,r8 \n\t" : "=r" ((t)->regs.r8) : );   \
+  __asm__("mov %0,r9 \n\t" : "=r" ((t)->regs.r9) : );   \
+  __asm__("mov %0,r10 \n\t" : "=r" ((t)->regs.r10) : );   \
+  __asm__("mov %0,r11 \n\t" : "=r" ((t)->regs.r11) : );   \
+  __asm__("mov %0,r12 \n\t" : "=r" ((t)->regs.r12) : );   \
+  __asm__("mov %0,r13 \n\t" : "=r" ((t)->regs.r13) : );   \
+  __asm__("mov %0,r14 \n\t" : "=r" ((t)->regs.r14) : );   \
+  __asm__("mov %0,r15 \n\t" : "=r" ((t)->regs.r15) : );   \
+  __asm__("mov %0,r16 \n\t" : "=r" ((t)->regs.r16) : );   \
+  __asm__("mov %0,r17 \n\t" : "=r" ((t)->regs.r17) : );   \
+  __asm__("mov %0,r18 \n\t" : "=r" ((t)->regs.r18) : );   \
+  __asm__("mov %0,r19 \n\t" : "=r" ((t)->regs.r19) : );   \
+  __asm__("mov %0,r20 \n\t" : "=r" ((t)->regs.r20) : );   \
+  __asm__("mov %0,r21 \n\t" : "=r" ((t)->regs.r21) : );   \
+  __asm__("mov %0,r22 \n\t" : "=r" ((t)->regs.r22) : );   \
+  __asm__("mov %0,r23 \n\t" : "=r" ((t)->regs.r23) : );   \
+  __asm__("mov %0,r24 \n\t" : "=r" ((t)->regs.r24) : );   \
+  __asm__("mov %0,r25 \n\t" : "=r" ((t)->regs.r25) : );   \
+  __asm__("mov %0,r26 \n\t" : "=r" ((t)->regs.r26) : );   \
+  __asm__("mov %0,r27 \n\t" : "=r" ((t)->regs.r27) : );   \
+  __asm__("mov %0,r28 \n\t" : "=r" ((t)->regs.r28) : );   \
+  __asm__("mov %0,r29 \n\t" : "=r" ((t)->regs.r29) : );   \
+  __asm__("mov %0,r30 \n\t" : "=r" ((t)->regs.r30) : );   \
+  __asm__("mov %0,r31 \n\t" : "=r" ((t)->regs.r31) : );
+  
+//Restore stack pointer
+#define RESTORE_STACK_PTR(t)                                            \
+  __asm__("out __SP_H__,%B0 \n\t"                    \
+          "out __SP_L__,%A0 \n\t"                    \
+          ::"r" ((t)->stack_ptr))
+
+//Restore status register
+#define RESTORE_STATUS(t)                                      \
+  __asm__("out __SREG__,%0 \n\t" :: "r" ((t)->regs.status) ); 
+
+//Restore the general purpose registers
+#define RESTORE_GPR(t)                                              \
+  __asm__("mov r0,%0 \n\t" :: "r" ((t)->regs.r0) );  \
+  __asm__("mov r1,%0 \n\t" :: "r" ((t)->regs.r1) );  \
+  __asm__("mov r2,%0 \n\t" :: "r" ((t)->regs.r2) );  \
+  __asm__("mov r3,%0 \n\t" :: "r" ((t)->regs.r3) );  \
+  __asm__("mov r4,%0 \n\t" :: "r" ((t)->regs.r4) );  \
+  __asm__("mov r5,%0 \n\t" :: "r" ((t)->regs.r5) );  \
+  __asm__("mov r6,%0 \n\t" :: "r" ((t)->regs.r6) );  \
+  __asm__("mov r7,%0 \n\t" :: "r" ((t)->regs.r7) );  \
+  __asm__("mov r8,%0 \n\t" :: "r" ((t)->regs.r8) );  \
+  __asm__("mov r9,%0 \n\t" :: "r" ((t)->regs.r9) );  \
+  __asm__("mov r10,%0 \n\t" :: "r" ((t)->regs.r10) );  \
+  __asm__("mov r11,%0 \n\t" :: "r" ((t)->regs.r11) );  \
+  __asm__("mov r12,%0 \n\t" :: "r" ((t)->regs.r12) );  \
+  __asm__("mov r13,%0 \n\t" :: "r" ((t)->regs.r13) );  \
+  __asm__("mov r14,%0 \n\t" :: "r" ((t)->regs.r14) );  \
+  __asm__("mov r15,%0 \n\t" :: "r" ((t)->regs.r15) );  \
+  __asm__("mov r16,%0 \n\t" :: "r" ((t)->regs.r16) );  \
+  __asm__("mov r17,%0 \n\t" :: "r" ((t)->regs.r17) );  \
+  __asm__("mov r18,%0 \n\t" :: "r" ((t)->regs.r18) );  \
+  __asm__("mov r19,%0 \n\t" :: "r" ((t)->regs.r19) );  \
+  __asm__("mov r20,%0 \n\t" :: "r" ((t)->regs.r20) );  \
+  __asm__("mov r21,%0 \n\t" :: "r" ((t)->regs.r21) );  \
+  __asm__("mov r22,%0 \n\t" :: "r" ((t)->regs.r22) );  \
+  __asm__("mov r23,%0 \n\t" :: "r" ((t)->regs.r23) );  \
+  __asm__("mov r24,%0 \n\t" :: "r" ((t)->regs.r24) );  \
+  __asm__("mov r25,%0 \n\t" :: "r" ((t)->regs.r25) );  \
+  __asm__("mov r26,%0 \n\t" :: "r" ((t)->regs.r26) );  \
+  __asm__("mov r27,%0 \n\t" :: "r" ((t)->regs.r27) );  \
+  __asm__("mov r28,%0 \n\t" :: "r" ((t)->regs.r28) );  \
+  __asm__("mov r29,%0 \n\t" :: "r" ((t)->regs.r29) );  \
+  __asm__("mov r30,%0 \n\t" :: "r" ((t)->regs.r30) );  \
+  __asm__("mov r31,%0 \n\t" :: "r" ((t)->regs.r31) );
+  
+#define SAVE_TCB(t) \
+  SAVE_GPR(t);         \
+  SAVE_STATUS(t);      \
+  SAVE_STACK_PTR(t) 
+  
+#define RESTORE_TCB(t)  \
+  RESTORE_STACK_PTR(t); \
+  RESTORE_STATUS(t);    \
+  RESTORE_GPR(t)
+  
+#define SWITCH_CONTEXTS(from, to) \
+  SAVE_TCB(from);                                \
+  RESTORE_TCB(to)
+
+#define SWAP_STACK_PTR(OLD, NEW) \
+  __asm__("in %A0, __SP_L__\n\t in %B0, __SP_H__":"=r"(OLD):);\
+  __asm__("out __SP_H__,%B0\n\t out __SP_L__,%A0"::"r"(NEW))
+#define PREPARE_THREAD(t, thread_ptr)                         \
+  {  uint16_t temp;                                                                   \
+     SWAP_STACK_PTR(temp, (t)->stack_ptr);                 \
+     __asm__("push %A0\n push %B0"::"r"(&(thread_ptr)));   \
+     SWAP_STACK_PTR((t)->stack_ptr, temp);                 \
+     SAVE_STATUS(t)                                                                   \
+  }
+  
+/*
+  *((uint8_t*)((t)->stack_ptr)) = (uint8_t)((uint16_t)(&(thread_ptr)) >> 8);   \
+  *((uint8_t*)((t)->stack_ptr)-1) = (uint8_t)((&(thread_ptr)));        \
+*/
diff --git a/tos/lib/tosthreads/chips/atm128/sim/HplAtm128CompareC.nc b/tos/lib/tosthreads/chips/atm128/sim/HplAtm128CompareC.nc
new file mode 100644 (file)
index 0000000..23fa822
--- /dev/null
@@ -0,0 +1,280 @@
+/// $Id$
+/*
+ * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * 
+ * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY
+ * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
+ * ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ * Basic compare abstraction that builds on top of a counter.
+ *
+ * @author Philip Levis
+ * @date   Nov 22 2005
+ */
+
+// $Id$
+
+#include <Atm128Timer.h>
+
+generic module HplAtm128CompareC(typedef width_t @integer(),
+                                uint8_t valueRegister,
+                                uint8_t interruptRegister,
+                                uint8_t interruptBit,
+                                uint8_t flagRegister,
+                                uint8_t flagBit) 
+{
+  provides {
+    // 8-bit Timers
+    interface HplAtm128Compare<width_t> as Compare;
+  }
+  uses {
+    interface HplAtm128Timer<width_t>   as Timer;
+    interface HplAtm128TimerCtrl8       as TimerCtrl;
+    interface HplAtm128TimerNotify as Notify;
+    interface ThreadScheduler;
+  }
+}
+implementation {
+  /* lastZero keeps track of the phase of the clock. It denotes the sim
+   * time at which the underlying clock started, which is needed to
+   * calculate when compares will occur. */
+  sim_time_t lastZero = 0;
+
+  /** This variable is needed to keep track of when the underlying
+   *  timer starts, in order to reset lastZero. When oldScale is
+   *  AVR_CLOCK_OFF and the scale is set to something else, the
+   *  clock starts ticking. */
+  uint8_t oldScale = AVR_CLOCK_OFF;
+  
+  void adjust_zero(width_t currentCounter);
+
+  void cancel_compare();
+  sim_event_t* allocate_compare();
+  void configure_compare(sim_event_t* e);
+  void schedule_new_compare();
+
+  sim_time_t clock_to_sim(sim_time_t t);
+  sim_time_t sim_to_clock(sim_time_t t);
+  uint16_t shiftFromScale();
+
+
+  sim_time_t last_zero() {
+    if (lastZero == 0) {
+      lastZero = sim_mote_start_time(sim_node());
+    }
+    return lastZero;
+  }
+
+
+  async event void Notify.changed() {
+    uint8_t newScale = call Timer.getScale();
+    if (newScale != AVR_CLOCK_OFF &&
+       oldScale == AVR_CLOCK_OFF) {
+      lastZero = sim_time();
+    }
+    oldScale = newScale;
+    
+    schedule_new_compare();
+  }
+  
+  async command void Compare.reset() { REG_ACCESS(flagRegister) &= ~(1 << flagBit); }
+  async command void Compare.start() { SET_BIT(interruptRegister,interruptBit); }
+  async command void Compare.stop()  { CLR_BIT(interruptRegister,interruptBit); }
+  async command bool Compare.test()  { 
+    return (call TimerCtrl.getInterruptFlag()).bits.ocf0; 
+  }
+  async command bool Compare.isOn()  { 
+    return (call TimerCtrl.getInterruptMask()).bits.ocie0; 
+  }
+
+  //=== Read the compare registers. =====================================
+  async command width_t Compare.get()   { return (width_t)REG_ACCESS(valueRegister); }
+
+  //=== Write the compare registers. ====================================
+  async command void Compare.set(width_t t)   { 
+    atomic {
+       /* Re the comment above: it's a bad idea to wake up at time 0, as
+          we'll just spin when setting the next deadline. Try and reduce
+          the likelihood by delaying the interrupt...
+       */
+      if (t == 0 || t >= 0xfe)
+       t = 1;
+      
+      if (t != REG_ACCESS(valueRegister)) {
+       REG_ACCESS(valueRegister) = t;
+       schedule_new_compare();
+      }
+    }
+  }
+
+  //=== Timer interrupts signals ========================================
+  default async event void Compare.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE0) {
+    signal Compare.fired();
+    call ThreadScheduler.interruptPostAmble();
+  }
+
+
+  /**
+   * If the clock was stopped and has restarted, then
+   * we need to move the time when the clock was last
+   * zero to a time that reflects the current settings.
+   * For example, if the clock was stopped when the counter
+   * was 52 and then later restarted, then <tt>lastZero</tt>
+   * needs to be moved forward in time so that the 52
+   * reflects the current time.
+   */ 
+  void adjust_zero(width_t currentCounter) {
+    sim_time_t now = sim_time();
+    sim_time_t adjust = currentCounter;
+    adjust = adjust << shiftFromScale();
+    adjust = clock_to_sim(adjust);
+    lastZero = now - adjust;
+  }
+  
+  sim_time_t clock_to_sim(sim_time_t t) {
+    t *= sim_ticks_per_sec();
+    t /= call Notify.clockTicksPerSec();
+    return t;
+  }
+
+  sim_time_t sim_to_clock(sim_time_t t) {
+    t *= call Notify.clockTicksPerSec();
+    t /= sim_ticks_per_sec();
+    return t;
+  }
+  
+  uint16_t shiftFromScale() {
+    uint8_t scale = call Timer.getScale();
+    switch (scale) {
+    case 0:
+      return 0;
+    case 1:
+      return 0;
+    case 2:
+      return 3;
+    case 3:
+      return 5;
+    case 4:
+      return 6;
+    case 5:
+      return 7;
+    case 6:
+      return 8;
+    case 7:
+      return 10;
+    default:
+      return 255;
+    }
+    
+  }
+
+  sim_event_t* compare;
+
+  void timer0_compare_handle(sim_event_t* evt) {
+    dbg("HplAtm128CompareC", "%s Beginning compare at 0x%p\n", __FUNCTION__, evt);
+    if (evt->cancelled) {
+      return;
+    }
+    else {
+      dbg("HplAtm128CompareC", "%s Handling compare at 0x%p @ %s\n",__FUNCTION__,  evt, sim_time_string());
+           
+      if (READ_BIT(interruptRegister, interruptBit)) {
+       CLR_BIT(flagRegister, flagBit);
+       dbg("HplAtm128CompareC", "%s Compare interrupt @ %s\n", __FUNCTION__, sim_time_string());
+       SIG_OUTPUT_COMPARE0();
+      }
+      else {
+       SET_BIT(flagRegister, flagBit);
+      }
+      // If we haven't been cancelled
+      if (!evt->cancelled) {
+       configure_compare(evt);
+       sim_queue_insert(evt);
+      }
+    }
+  }
+
+  sim_event_t* allocate_compare() {
+    sim_event_t* newEvent = sim_queue_allocate_event();
+    dbg("HplAtm128CompareC", "Allocated compare at 0x%p\n", newEvent);
+    newEvent->handle = timer0_compare_handle;
+    newEvent->cleanup = sim_queue_cleanup_none;
+    return newEvent;
+  }
+  
+  void configure_compare(sim_event_t* evt) {
+    sim_time_t compareTime = 0;
+    sim_time_t phaseOffset = 0;
+    uint8_t timerVal = call Timer.get();
+    uint8_t compareVal = call Compare.get();
+
+    // Calculate how many counter increments until timer
+    // hits compare, considering wraparound, and special
+    // case of complete wraparound.
+    compareTime = ((compareVal - timerVal) & 0xff);
+    if (compareTime == 0) {
+      compareTime = 256;
+    }
+
+    // Now convert the compare time from counter increments
+    // to simulation ticks, considering the fact that the
+    // increment actually has a phase offset.
+    compareTime = compareTime << shiftFromScale();
+    compareTime = clock_to_sim(compareTime);
+    compareTime += sim_time();
+
+    // How long into a timer tick was the clock actually reset?
+    // This covers the case when the compare is set midway between
+    // a tick, so it will go off a little early
+    phaseOffset = sim_time();
+    phaseOffset -= last_zero();
+    phaseOffset %= clock_to_sim(1 << shiftFromScale());
+    compareTime -= phaseOffset;
+      
+    dbg("HplAtm128CompareC", "Configuring new compare of %i for %i at time %llu  (@ %llu)\n", (int)compareVal, sim_node(), compareTime, sim_time());
+    
+    evt->time = compareTime;    
+  }
+  
+  void schedule_new_compare() {
+    if (compare != NULL) {
+      cancel_compare();
+    }
+    if (call Timer.getScale() != AVR_CLOCK_OFF) {
+      sim_event_t* newEvent = allocate_compare();
+      configure_compare(newEvent);
+
+      compare = newEvent;
+      sim_queue_insert(newEvent);
+    }
+  }
+
+  void cancel_compare() {
+    dbg("HplAtm128CompareC", "Cancelling compare at 0x%p\n", compare);
+    if (compare != NULL) {
+      compare->cancelled = 1;
+      compare->cleanup = sim_queue_cleanup_total;
+    }
+  }
+
+  async event void Timer.overflow() {}
+  
+}
diff --git a/tos/lib/tosthreads/chips/atm128/sim/HplAtm128Counter0C.nc b/tos/lib/tosthreads/chips/atm128/sim/HplAtm128Counter0C.nc
new file mode 100644 (file)
index 0000000..9042e4a
--- /dev/null
@@ -0,0 +1,380 @@
+/*
+ * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * 
+ * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY
+ * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
+ * ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ * The TOSSIM implementation of the Atm128 Timer0 counter. It handles
+ * overflow, scaling, and phase considerations.
+ *
+ * @date November 22 2005
+ *
+ * @author Philip Levis <pal@cs.stanford.edu>
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <dgay@intel-research.net>
+ */
+
+// $Id$/// $Id: HplAtm128Timer2C.nc,
+
+#include <Atm128Timer.h>
+#include <hardware.h>
+
+module HplAtm128Counter0C {
+  provides {
+    interface Init @atleastonce();
+    // 8-bit Timers
+    interface HplAtm128Timer<uint8_t>   as Timer0;
+    interface HplAtm128TimerNotify      as Notify;
+    interface HplAtm128TimerCtrl8       as Timer0Ctrl;
+  }
+  uses interface ThreadScheduler;
+}
+implementation
+{
+  bool inOverflow = 0;
+  uint8_t savedCounter = 0;
+  sim_time_t lastZero = 0;
+
+  void adjust_zero(uint8_t currentCounter);
+
+  void cancel_overflow();
+  sim_event_t* allocate_overflow();
+  void configure_overflow(sim_event_t* e);
+  void schedule_new_overflow();
+
+  sim_time_t clock_to_sim(sim_time_t t);
+  sim_time_t sim_to_clock(sim_time_t t);
+  uint16_t shiftFromScale();
+
+  command error_t Init.init() {
+    /* Do nothing. On a standard mote this configures Timer0 to
+     * operating in asynchronous mode off an external crystal. Here in
+     * TOSSIM it's assumed that's the case. */
+    return SUCCESS;
+  }
+    
+  async command sim_time_t Notify.clockTicksPerSec() {
+    return ATM128_TIMER0_TICKSPPS;
+  }
+  
+  sim_time_t last_zero() {
+    if (lastZero == 0) {
+      lastZero = sim_mote_start_time(sim_node());
+    }
+    return lastZero;
+  }
+  
+  //=== Read the current timer value. ===================================
+  async command uint8_t  Timer0.get() {
+    uint8_t rval;
+    sim_time_t elapsed = sim_time() - last_zero();
+    elapsed = sim_to_clock(elapsed);
+    elapsed = elapsed >> shiftFromScale();
+    rval = (uint8_t)(elapsed & 0xff);
+    dbg("HplAtm128Counter0C", "HplAtm128Counter0C: Getting timer: %hhu\n", rval);
+    return rval;
+  }
+
+  //=== Set/clear the current timer value. ==============================
+  /**
+   * Set/clear the current timer value.
+   *
+   * This code is pretty tricky.  */
+  async command void Timer0.set(uint8_t newVal)  {
+    uint8_t curVal = call Timer0.get();
+    if (newVal == curVal) {
+      return;
+    }
+    else {
+      sim_time_t adjustment = curVal - newVal;
+      adjustment = adjustment << shiftFromScale();
+      adjustment = clock_to_sim(adjustment);
+
+      if (newVal < curVal) {
+       lastZero += adjustment;
+      }
+      else { // newVal > curVal
+       lastZero -= adjustment;
+      }
+
+      schedule_new_overflow();
+      signal Notify.changed();
+    }
+  }
+
+  //=== Read the current timer scale. ===================================
+  async command uint8_t Timer0.getScale() {
+    return TCCR0 & 0x7;
+  }
+
+  //=== Turn off the timers. ============================================
+  async command void Timer0.off() {
+    call Timer0.setScale(AVR_CLOCK_OFF);
+    savedCounter = call Timer0.get();
+    cancel_overflow();
+    signal Notify.changed();
+  }
+
+  //=== Write a new timer scale. ========================================
+  async command void Timer0.setScale(uint8_t s)  {
+    Atm128TimerControl_t ctrl;
+    uint8_t currentScale = call Timer0.getScale();
+    uint8_t currentCounter;
+    dbg("HplAtm128Counter0C", "Timer0 scale set to %i\n", (int)s);
+    if (currentScale == 0) {
+      currentCounter = savedCounter;
+    }
+    else {
+      currentCounter = call Timer0.get();
+    }
+    
+    ctrl = call Timer0Ctrl.getControl();
+    ctrl.flat &= ~(0x7);
+    ctrl.flat |= (s & 0x7);
+    call Timer0Ctrl.setControl(ctrl);  
+
+    if (currentScale != s) {
+      adjust_zero(currentCounter);
+      schedule_new_overflow();
+    }
+    signal Notify.changed();
+  }
+
+  //=== Read the control registers. =====================================
+  async command Atm128TimerControl_t Timer0Ctrl.getControl() { 
+    return *(Atm128TimerControl_t*)&TCCR0; 
+  }
+
+  //=== Write the control registers. ====================================
+  async command void Timer0Ctrl.setControl( Atm128TimerControl_t x ) { 
+    TCCR0 = x.flat; 
+  }
+
+  //=== Read the interrupt mask. =====================================
+  async command Atm128_TIMSK_t Timer0Ctrl.getInterruptMask() { 
+    return *(Atm128_TIMSK_t*)&TIMSK; 
+  }
+
+  //=== Write the interrupt mask. ====================================
+  DEFINE_UNION_CAST(TimerMask8_2int, Atm128_TIMSK_t, uint8_t);
+  DEFINE_UNION_CAST(TimerMask16_2int, Atm128_ETIMSK_t, uint8_t);
+
+  async command void Timer0Ctrl.setInterruptMask( Atm128_TIMSK_t x ) { 
+    TIMSK = TimerMask8_2int(x); 
+  }
+
+  //=== Read the interrupt flags. =====================================
+  async command Atm128_TIFR_t Timer0Ctrl.getInterruptFlag() { 
+    return *(Atm128_TIFR_t*)&TIFR; 
+  }
+
+  //=== Write the interrupt flags. ====================================
+  DEFINE_UNION_CAST(TimerFlags8_2int, Atm128_TIFR_t, uint8_t);
+  DEFINE_UNION_CAST(TimerFlags16_2int, Atm128_ETIFR_t, uint8_t);
+
+  async command void Timer0Ctrl.setInterruptFlag( Atm128_TIFR_t x ) { 
+    TIFR = TimerFlags8_2int(x); 
+  }
+
+  //=== Timer 8-bit implementation. ====================================
+  async command void Timer0.reset() {
+    // Clear TOV0. On real hardware, this is a write.
+    TIFR &= ~(1 << TOV0);
+  }
+  async command void Timer0.start() {
+    SET_BIT(ATM128_TIMSK, TOIE0);
+    dbg("HplAtm128Counter0C", "Enabling TOIE0 at %llu\n", sim_time());
+    schedule_new_overflow();
+  }
+  async command void Timer0.stop()  {
+    dbg("HplAtm128Counter0C", "Timer stopped @ %llu\n", sim_time());
+    CLR_BIT(ATM128_TIMSK, TOIE0);
+    cancel_overflow();
+  }
+
+  bool overflowed() {
+    return READ_BIT(ATM128_TIFR, TOV0); 
+  }
+
+  inline void stabiliseOverflow() {
+    /* From the atmel manual:
+
+    During asynchronous operation, the synchronization of the interrupt
+    flags for the asynchronous timer takes three processor cycles plus one
+    timer cycle.  The timer is therefore advanced by at least one before
+    the processor can read the timer value causing the setting of the
+    interrupt flag. The output compare pin is changed on the timer clock
+    and is not synchronized to the processor clock.
+
+    So: if the timer is = 0, wait till it's = 1, except if
+    - we're currently in the overflow interrupt handler
+    - or, the overflow flag is already set
+    */
+
+    //if (!inOverflow)
+    //  while (!TCNT0 && !overflowed())
+    //;
+  }
+
+  async command bool Timer0.test()  { 
+    stabiliseOverflow();
+    return overflowed();
+  }
+  async command bool Timer0.isOn()  { 
+    return (call Timer0Ctrl.getInterruptMask()).bits.toie0; 
+  }
+
+  default async event void Timer0.overflow() { }
+  AVR_ATOMIC_HANDLER(SIG_OVERFLOW0) {
+    inOverflow = TRUE;
+    signal Timer0.overflow();
+    inOverflow = FALSE;
+    call ThreadScheduler.interruptPostAmble();
+  }
+
+  /**
+   * If the clock was stopped and has restarted, then
+   * we need to move the time when the clock was last
+   * zero to a time that reflects the current settings.
+   * For example, if the clock was stopped when the counter
+   * was 52 and then later restarted, then <tt>lastZero</tt>
+   * needs to be moved forward in time so that the 52
+   * reflects the current time.
+   */ 
+  void adjust_zero(uint8_t currentCounter) {
+    sim_time_t now = sim_time();
+    sim_time_t adjust = currentCounter;
+    adjust = adjust << shiftFromScale();
+    adjust = clock_to_sim(adjust);
+    lastZero = now - adjust;
+  }
+  
+  sim_time_t clock_to_sim(sim_time_t t) {
+    t *= sim_ticks_per_sec();
+    t /= call Notify.clockTicksPerSec();
+    return t;
+  }
+
+  sim_time_t sim_to_clock(sim_time_t t) {
+    t *= call Notify.clockTicksPerSec();
+    t /= sim_ticks_per_sec();
+    return t;
+  }
+  
+  uint16_t shiftFromScale() {
+    uint8_t scale = call Timer0.getScale();
+    switch (scale) {
+    case 0:
+      return 0;
+    case 1:
+      return 0;
+    case 2:
+      return 3;
+    case 3:
+      return 5;
+    case 4:
+      return 6;
+    case 5:
+      return 7;
+    case 6:
+      return 8;
+    case 7:
+      return 10;
+    default:
+      return 255;
+    }
+    
+  }
+
+  sim_event_t* overflow;
+
+  void timer0_overflow_handle(sim_event_t* evt) {
+    if (evt->cancelled) {
+      return;
+    }
+    else {
+      if (READ_BIT(ATM128_TIMSK, TOIE0)) {
+       CLR_BIT(ATM128_TIFR, TOV0);
+       dbg("HplAtm128Counter0C", "Overflow interrupt at %s\n", sim_time_string());
+       SIG_OVERFLOW0();
+      }
+      else {
+       dbg("HplAtm128Counter0C", "Setting overflow bit at %s\n", sim_time_string());
+       SET_BIT(ATM128_TIFR, TOV0);
+      }
+      configure_overflow(evt);
+      sim_queue_insert(evt);
+    }
+  }
+  
+  sim_event_t* allocate_overflow() {
+    sim_event_t* newEvent = sim_queue_allocate_event();
+
+    newEvent->handle = timer0_overflow_handle;
+    newEvent->cleanup = sim_queue_cleanup_none;
+    return newEvent;
+  }
+  
+  void configure_overflow(sim_event_t* evt) {
+    sim_time_t overflowTime = 0;
+    uint8_t timerVal = call Timer0.get();
+    uint8_t overflowVal = 0;
+
+    // Calculate how many counter increments until timer
+    // hits compare, considering wraparound, and special
+    // case of complete wraparound.
+    overflowTime = ((overflowVal - timerVal) & 0xff);
+    if (overflowTime == 0) {
+      overflowTime = 256;
+    }
+
+    // Now convert the compare time from counter increments
+    // to simulation ticks, considering the fact that the
+    // increment actually has a phase offset.
+    overflowTime = overflowTime << shiftFromScale();
+    overflowTime = clock_to_sim(overflowTime);
+    overflowTime += sim_time();
+    overflowTime -= (sim_time() - last_zero()) % (1 << shiftFromScale());
+
+    dbg("HplAtm128Counter0C", "Scheduling new overflow for %i at time %llu\n", sim_node(), overflowTime);
+    
+    evt->time = overflowTime;
+  }
+  
+  void schedule_new_overflow() {
+    sim_event_t* newEvent = allocate_overflow();
+    configure_overflow(newEvent);
+
+    if (overflow != NULL) {
+      cancel_overflow();
+    }
+    overflow = newEvent;
+    sim_queue_insert(newEvent);
+  }
+  
+  void cancel_overflow() {
+    if (overflow != NULL) {
+      overflow->cancelled = 1;
+      dbg("HplAtm128Counter0C", "Cancelling overflow %p.\n", overflow);
+      overflow->cleanup = sim_queue_cleanup_total;
+    }
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/sim/HplAtm128Counter2C.nc b/tos/lib/tosthreads/chips/atm128/sim/HplAtm128Counter2C.nc
new file mode 100644 (file)
index 0000000..5fb701b
--- /dev/null
@@ -0,0 +1,378 @@
+/*
+ * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * 
+ * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY
+ * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
+ * ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ * The TOSSIM implementation of the Atm128 Timer2 counter. It handles
+ * overflow, scaling, and phase considerations.
+ *
+ * @date November 22 2005
+ *
+ * @author Philip Levis <pal@cs.stanford.edu>
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <dgay@intel-research.net>
+ */
+
+// $Id$/// $Id: HplAtm128Timer2C.nc,
+
+#include <Atm128Timer.h>
+#include <hardware.h>
+
+enum {
+  ATM128_TIMER2_TICKSPPS = (1 << 13)
+};
+
+module HplAtm128Counter2C {
+  provides {
+    // 8-bit Timers
+    interface HplAtm128Timer<uint8_t>   as Timer2;
+    interface HplAtm128TimerNotify      as Notify;
+    interface HplAtm128TimerCtrl8       as Timer2Ctrl;
+  }
+  uses interface ThreadScheduler;
+}
+implementation
+{
+  bool inOverflow = 0;
+  uint8_t savedCounter = 0;
+  sim_time_t lastZero = 0;
+
+  void adjust_zero(uint8_t currentCounter);
+
+  void cancel_overflow();
+  sim_event_t* allocate_overflow();
+  void configure_overflow(sim_event_t* e);
+  void schedule_new_overflow();
+
+  sim_time_t clock_to_sim(sim_time_t t);
+  sim_time_t sim_to_clock(sim_time_t t);
+  uint16_t shiftFromScale();
+
+
+  async command sim_time_t Notify.clockTicksPerSec() {
+    return ATM128_TIMER2_TICKSPPS;
+  }
+  
+  sim_time_t last_zero() {
+    if (lastZero == 0) {
+      lastZero = sim_mote_start_time(sim_node());
+    }
+    return lastZero;
+  }
+  
+  //=== Read the current timer value. ===================================
+  async command uint8_t  Timer2.get() {
+    uint8_t rval;
+    sim_time_t elapsed = sim_time() - last_zero();
+    elapsed = sim_to_clock(elapsed);
+    elapsed = elapsed >> shiftFromScale();
+    rval = (uint8_t)(elapsed & 0xff);
+    dbg("HplAtm128Counter2C", "HplAtm128Counter2C: Getting timer: %hhu\n", rval);
+    return rval;
+  }
+
+  //=== Set/clear the current timer value. ==============================
+  /**
+   * Set/clear the current timer value.
+   *
+   * This code is pretty tricky.  */
+  async command void Timer2.set(uint8_t newVal)  {
+    uint8_t curVal = call Timer2.get();
+    if (newVal == curVal) {
+      return;
+    }
+    else {
+      sim_time_t adjustment = curVal - newVal;
+      adjustment = adjustment << shiftFromScale();
+      adjustment = clock_to_sim(adjustment);
+
+      if (newVal < curVal) {
+       lastZero += adjustment;
+      }
+      else { // newVal > curVal
+       lastZero -= adjustment;
+      }
+
+      schedule_new_overflow();
+      signal Notify.changed();
+    }
+  }
+
+  //=== Read the current timer scale. ===================================
+  async command uint8_t Timer2.getScale() {
+    return TCCR2 & 0x7;
+  }
+
+  //=== Turn off the timers. ============================================
+  async command void Timer2.off() {
+    call Timer2.setScale(AVR_CLOCK_OFF);
+    savedCounter = call Timer2.get();
+    cancel_overflow();
+    signal Notify.changed();
+  }
+
+  //=== Write a new timer scale. ========================================
+  async command void Timer2.setScale(uint8_t s)  {
+    Atm128TimerControl_t ctrl;
+    uint8_t currentScale = call Timer2.getScale();
+    uint8_t currentCounter;
+    dbg("HplAtm128Counter2C", "Timer2 scale set to %i\n", (int)s);
+    if (currentScale == 0) {
+      currentCounter = savedCounter;
+    }
+    else {
+      currentCounter = call Timer2.get();
+    }
+    
+    ctrl = call Timer2Ctrl.getControl();
+    ctrl.bits.cs = s;
+    call Timer2Ctrl.setControl(ctrl);  
+
+    if (currentScale != s) {
+      adjust_zero(currentCounter);
+      schedule_new_overflow();
+    }
+    signal Notify.changed();
+  }
+
+  //=== Read the control registers. =====================================
+  async command Atm128TimerControl_t Timer2Ctrl.getControl() { 
+    return *(Atm128TimerControl_t*)&TCCR2; 
+  }
+
+  //=== Write the control registers. ====================================
+  async command void Timer2Ctrl.setControl( Atm128TimerControl_t x ) { 
+    TCCR2 = x.flat; 
+  }
+
+  //=== Read the interrupt mask. =====================================
+  async command Atm128_TIMSK_t Timer2Ctrl.getInterruptMask() { 
+    return *(Atm128_TIMSK_t*)&TIMSK; 
+  }
+
+  //=== Write the interrupt mask. ====================================
+  DEFINE_UNION_CAST(TimerMask8_2int, Atm128_TIMSK_t, uint8_t);
+  DEFINE_UNION_CAST(TimerMask16_2int, Atm128_ETIMSK_t, uint8_t);
+
+  async command void Timer2Ctrl.setInterruptMask( Atm128_TIMSK_t x ) { 
+    TIMSK = TimerMask8_2int(x); 
+  }
+
+  //=== Read the interrupt flags. =====================================
+  async command Atm128_TIFR_t Timer2Ctrl.getInterruptFlag() { 
+    return *(Atm128_TIFR_t*)&TIFR; 
+  }
+
+  //=== Write the interrupt flags. ====================================
+  DEFINE_UNION_CAST(TimerFlags8_2int, Atm128_TIFR_t, uint8_t);
+  DEFINE_UNION_CAST(TimerFlags16_2int, Atm128_ETIFR_t, uint8_t);
+
+  async command void Timer2Ctrl.setInterruptFlag( Atm128_TIFR_t x ) { 
+    TIFR = TimerFlags8_2int(x); 
+  }
+
+  //=== Timer 8-bit implementation. ====================================
+  async command void Timer2.reset() {
+    // Clear TOV0. On real hardware, this is a write.
+    TIFR &= ~(1 << TOV2);
+  }
+  async command void Timer2.start() {
+    SET_BIT(ATM128_TIMSK, TOIE2);
+    dbg("HplAtm128Counter2C", "Enabling TOIE0 at %llu\n", sim_time());
+    schedule_new_overflow();
+  }
+  async command void Timer2.stop()  {
+    dbg("HplAtm128Counter2C", "Timer stopped @ %llu\n", sim_time());
+    CLR_BIT(ATM128_TIMSK, TOIE2);
+    cancel_overflow();
+  }
+
+  bool overflowed() {
+    return READ_BIT(ATM128_TIFR, TOV2); 
+  }
+
+  inline void stabiliseOverflow() {
+    /* From the atmel manual:
+
+    During asynchronous operation, the synchronization of the interrupt
+    flags for the asynchronous timer takes three processor cycles plus one
+    timer cycle.  The timer is therefore advanced by at least one before
+    the processor can read the timer value causing the setting of the
+    interrupt flag. The output compare pin is changed on the timer clock
+    and is not synchronized to the processor clock.
+
+    So: if the timer is = 0, wait till it's = 1, except if
+    - we're currently in the overflow interrupt handler
+    - or, the overflow flag is already set
+    */
+
+    //if (!inOverflow)
+    //  while (!TCNT0 && !overflowed())
+    //;
+  }
+
+  async command bool Timer2.test()  { 
+    stabiliseOverflow();
+    return overflowed();
+  }
+  async command bool Timer2.isOn()  { 
+    return (call Timer2Ctrl.getInterruptMask()).bits.toie2; 
+  }
+
+  default async event void Timer2.overflow() { }
+  AVR_ATOMIC_HANDLER(SIG_OVERFLOW2) {
+    inOverflow = TRUE;
+    signal Timer2.overflow();
+    inOverflow = FALSE;
+    call ThreadScheduler.interruptPostAmble();
+  }
+
+  /**
+   * If the clock was stopped and has restarted, then
+   * we need to move the time when the clock was last
+   * zero to a time that reflects the current settings.
+   * For example, if the clock was stopped when the counter
+   * was 52 and then later restarted, then <tt>lastZero</tt>
+   * needs to be moved forward in time so that the 52
+   * reflects the current time.
+   */ 
+  void adjust_zero(uint8_t currentCounter) {
+    sim_time_t now = sim_time();
+    sim_time_t adjust = currentCounter;
+    adjust = adjust << shiftFromScale();
+    adjust = clock_to_sim(adjust);
+    lastZero = now - adjust;
+  }
+  
+  sim_time_t clock_to_sim(sim_time_t t) {
+    t *= sim_ticks_per_sec();
+    t /= call Notify.clockTicksPerSec();
+    return t;
+  }
+
+  sim_time_t sim_to_clock(sim_time_t t) {
+    t *= call Notify.clockTicksPerSec();
+    t /= sim_ticks_per_sec();
+    return t;
+  }
+  
+  uint16_t shiftFromScale() {
+    uint8_t scale = call Timer2.getScale();
+    switch (scale) {
+    case 0:
+      return 0;
+    case 1:
+      return 0;
+    case 2:
+      return 3;
+    case 3:
+      return 5;
+    case 4:
+      return 6;
+    case 5:
+      return 7;
+    case 6:
+      return 8;
+    case 7:
+      return 10;
+    default:
+      return 255;
+    }
+    
+  }
+
+  sim_event_t* overflow;
+
+  void timer2_overflow_handle(sim_event_t* evt) {
+    if (evt->cancelled) {
+      return;
+    }
+    else {
+      char time[128];
+      sim_print_now(time, 128);
+      if (READ_BIT(ATM128_TIMSK, TOIE2)) {
+       CLR_BIT(ATM128_TIFR, TOV2);
+       dbg("HplAtm128Counter2C", "Overflow interrupt at %s\n", time);
+       SIG_OVERFLOW2();
+      }
+      else {
+       dbg("HplAtm128Counter2C", "Setting overflow bit at %s\n", time);
+       SET_BIT(ATM128_TIFR, TOV2);
+      }
+      configure_overflow(evt);
+      sim_queue_insert(evt);
+    }
+  }
+  
+  sim_event_t* allocate_overflow() {
+    sim_event_t* newEvent = sim_queue_allocate_event();
+
+    newEvent->handle = timer2_overflow_handle;
+    newEvent->cleanup = sim_queue_cleanup_none;
+    return newEvent;
+  }
+  
+  void configure_overflow(sim_event_t* evt) {
+    sim_time_t overflowTime = 0;
+    uint8_t timerVal = call Timer2.get();
+    uint8_t overflowVal = 0;
+
+    // Calculate how many counter increments until timer
+    // hits compare, considering wraparound, and special
+    // case of complete wraparound.
+    overflowTime = ((overflowVal - timerVal) & 0xff);
+    if (overflowTime == 0) {
+      overflowTime = 256;
+    }
+
+    // Now convert the compare time from counter increments
+    // to simulation ticks, considering the fact that the
+    // increment actually has a phase offset.
+    overflowTime = overflowTime << shiftFromScale();
+    overflowTime = clock_to_sim(overflowTime);
+    overflowTime += sim_time();
+    overflowTime -= (sim_time() - last_zero()) % (1 << shiftFromScale());
+
+    dbg("HplAtm128Counter2C", "Scheduling new overflow for %i at time %llu\n", sim_node(), overflowTime);
+    
+    evt->time = overflowTime;
+  }
+  
+  void schedule_new_overflow() {
+    sim_event_t* newEvent = allocate_overflow();
+    configure_overflow(newEvent);
+
+    if (overflow != NULL) {
+      cancel_overflow();
+    }
+    overflow = newEvent;
+    sim_queue_insert(newEvent);
+  }
+  
+  void cancel_overflow() {
+    if (overflow != NULL) {
+      overflow->cancelled = 1;
+      dbg("HplAtm128Counter2C", "Cancelling overflow %p.\n", overflow);
+      overflow->cleanup = sim_queue_cleanup_total;
+    }
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/sim/HplAtm128Timer0AsyncC.nc b/tos/lib/tosthreads/chips/atm128/sim/HplAtm128Timer0AsyncC.nc
new file mode 100644 (file)
index 0000000..53296f5
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * 
+ * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY
+ * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
+ * ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ * The TOSSIM implementation of the Atm128 Timer0. It is built from a
+ * timer-specific counter component and a generic compare
+ * component. The counter component has an additional simulation-only
+ * interface to let the compare component know when its state has
+ * changed (e.g., TCNTX was set).
+ *
+ * @date November 22 2005
+ *
+ * @author Philip Levis <pal@cs.stanford.edu>
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <dgay@intel-research.net>
+ */
+
+// $Id$/// $Id: HplAtm128Timer2C.nc,
+
+#include <Atm128Timer.h>
+
+configuration HplAtm128Timer0AsyncC
+{
+  provides {
+    // 8-bit Timers
+    interface HplAtm128Timer<uint8_t>   as Timer;
+    interface HplAtm128TimerCtrl8       as TimerCtrl;
+    interface HplAtm128Compare<uint8_t> as Compare;
+    interface HplAtm128TimerAsync       as TimerAsync;
+  }
+}
+implementation {
+  components HplAtm128Timer0AsyncP;
+  Timer = HplAtm128Timer0AsyncP;
+  TimerCtrl = HplAtm128Timer0AsyncP;
+  Compare = HplAtm128Timer0AsyncP;
+  TimerAsync = HplAtm128Timer0AsyncP;
+  
+  components TinyThreadSchedulerC;
+  HplAtm128Timer0AsyncP.ThreadScheduler -> TinyThreadSchedulerC;
+}
diff --git a/tos/lib/tosthreads/chips/atm128/sim/HplAtm128Timer0AsyncP.nc b/tos/lib/tosthreads/chips/atm128/sim/HplAtm128Timer0AsyncP.nc
new file mode 100644 (file)
index 0000000..192e179
--- /dev/null
@@ -0,0 +1,579 @@
+/*
+ * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * 
+ * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY
+ * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
+ * ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ * The TOSSIM implementation of the Atm128 Timer0 counter. It handles
+ * overflow, scaling, and phase considerations.
+ *
+ * @date November 22 2005
+ *
+ * @author Philip Levis <pal@cs.stanford.edu>
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <dgay@intel-research.net>
+ */
+
+// $Id$/// $Id: HplAtm128Timer2C.nc,
+
+#include <Atm128Timer.h>
+#include <hardware.h>
+
+module HplAtm128Timer0AsyncP {
+  provides {
+    interface HplAtm128Timer<uint8_t>   as Timer0;
+    interface HplAtm128TimerCtrl8       as Timer0Ctrl;
+    interface HplAtm128Compare<uint8_t> as Compare;
+    interface HplAtm128TimerAsync       as TimerAsync;
+  }
+  uses interface ThreadScheduler;
+}
+implementation {
+  bool inOverflow = 0;
+  uint8_t savedCounter = 0;
+
+  void adjust_zero(uint8_t currentCounter);
+
+  void cancel_overflow();
+  sim_event_t* allocate_overflow();
+  void configure_overflow(sim_event_t* e);
+  void schedule_new_overflow();
+
+  sim_time_t clock_to_sim(sim_time_t t);
+  sim_time_t sim_to_clock(sim_time_t t);
+  uint16_t shiftFromScale();
+
+  /* lastZero keeps track of the phase of the clock. It denotes the sim
+   * time at which the underlying clock started, which is needed to
+   * calculate when compares will occur. */
+  sim_time_t lastZero = 0;
+
+  /** This variable is needed to keep track of when the underlying
+   *  timer starts, in order to reset lastZero. When oldScale is
+   *  AVR_CLOCK_OFF and the scale is set to something else, the
+   *  clock starts ticking. */
+  uint8_t oldScale = AVR_CLOCK_OFF;
+  
+  void adjust_zero(uint8_t currentCounter);
+  
+  void cancel_compare();
+  sim_event_t* allocate_compare();
+  void configure_compare(sim_event_t* e);
+  void schedule_new_compare();
+
+  sim_time_t clock_to_sim(sim_time_t t);
+  sim_time_t sim_to_clock(sim_time_t t);
+  uint16_t shiftFromScale();
+
+  default async event void Compare.fired() { }
+  AVR_ATOMIC_HANDLER(SIG_OUTPUT_COMPARE0) {
+    //stabiliseTimer0();
+    signal Compare.fired();
+    call ThreadScheduler.interruptPostAmble();
+  }
+  default async event void Timer0.overflow() { }
+  AVR_ATOMIC_HANDLER(SIG_OVERFLOW0) {
+    inOverflow = TRUE;
+    signal Timer0.overflow();
+    inOverflow = FALSE;
+    call ThreadScheduler.interruptPostAmble();
+  }
+
+
+  
+  sim_time_t last_zero() {
+    if (lastZero == 0) {
+      lastZero = sim_mote_start_time(sim_node());
+    }
+    return lastZero;
+  }
+
+
+  void notify_changed() {
+    uint8_t newScale = call Timer0.getScale();
+    if (newScale != AVR_CLOCK_OFF &&
+       oldScale == AVR_CLOCK_OFF) {
+      lastZero = sim_time();
+    }
+    oldScale = newScale;
+    
+    schedule_new_compare();
+  }
+
+  sim_time_t notify_clockTicksPerSec() {
+    return ATM128_TIMER0_TICKSPPS;
+  }
+  
+  /**
+   * If the clock was stopped and has restarted, then
+   * we need to move the time when the clock was last
+   * zero to a time that reflects the current settings.
+   * For example, if the clock was stopped when the counter
+   * was 52 and then later restarted, then <tt>lastZero</tt>
+   * needs to be moved forward in time so that the 52
+   * reflects the current time.
+   */ 
+  void adjust_zero(uint8_t currentCounter) {
+    sim_time_t now = sim_time();
+    sim_time_t adjust = currentCounter;
+    adjust = adjust << shiftFromScale();
+    adjust = clock_to_sim(adjust);
+    lastZero = now - adjust;
+  }
+  
+  sim_time_t clock_to_sim(sim_time_t t) {
+    t *= sim_ticks_per_sec();
+    t /= notify_clockTicksPerSec();
+    return t;
+  }
+
+  sim_time_t sim_to_clock(sim_time_t t) {
+    t *= notify_clockTicksPerSec();
+    t /= sim_ticks_per_sec();
+    return t;
+  }
+  
+  uint16_t shiftFromScale() {
+    uint8_t scale = call Timer0.getScale();
+    switch (scale) {
+    case 0:
+      return 0;
+    case 1:
+      return 0;
+    case 2:
+      return 3;
+    case 3:
+      return 5;
+    case 4:
+      return 6;
+    case 5:
+      return 7;
+    case 6:
+      return 8;
+    case 7:
+      return 10;
+    default:
+      return 255;
+    }
+    
+  }
+
+  sim_event_t* compare;
+
+  void timer0_compare_handle(sim_event_t* evt) {
+    dbg("HplAtm128Timer0AsyncP", "Beginning compare 0x%p at %s\n", evt, sim_time_string());
+    if (evt->cancelled) {
+      return;
+    }
+    else {
+      char timeStr[128];
+      sim_print_now(timeStr, 128);
+      dbg("HplAtm128Timer0AsyncP", "Handling compare at 0x%p @ %s\n", evt, sim_time_string());
+      
+      if (READ_BIT(ATM128_TCCR0, WGM01) && !READ_BIT(ATM128_TCCR0, WGM00)) {
+       dbg("HplAtm128Timer0AsyncP", "%s: CTC is set, clear timer.\n", __FUNCTION__);
+       call Timer0.set(0);
+      }
+      else {
+       dbg("HplAtm128Timer0AsyncP", "%s: TCCR is 0x%hhx, %i, %i\n", __FUNCTION__, TCCR0, (int)READ_BIT(ATM128_TCCR0, WGM01), (int)READ_BIT(ATM128_TCCR0, WGM00));
+      }
+      
+      if (READ_BIT(ATM128_TIMSK, OCIE0)) {
+       dbg("HplAtm128Timer0AsyncP", "TIFR is %hhx\n", TIFR);
+       CLR_BIT(ATM128_TIFR, OCF0);
+       dbg("HplAtm128Timer0AsyncP", "TIFR is %hhx\n", TIFR);
+       dbg("HplAtm128Timer0AsyncP", "Compare interrupt @ %s\n", timeStr);
+       SIG_OUTPUT_COMPARE0();
+      }
+      else {
+       SET_BIT(ATM128_TIFR, OCF0);
+      }
+      // If we haven't been cancelled
+      if (!evt->cancelled) {
+       configure_compare(evt);
+       sim_queue_insert(evt);
+      }
+    }
+  }
+
+  sim_event_t* allocate_compare() {
+    sim_event_t* newEvent = sim_queue_allocate_event();
+    dbg("HplAtm128Timer0AsyncP", "Allocated compare at 0x%p\n", newEvent);
+    newEvent->handle = timer0_compare_handle;
+    newEvent->cleanup = sim_queue_cleanup_none;
+    return newEvent;
+  }
+  
+  void configure_compare(sim_event_t* evt) {
+    sim_time_t compareTime = 0;
+    sim_time_t phaseOffset = 0;
+    uint8_t timerVal = call Timer0.get();
+    uint8_t compareVal = call Compare.get();
+
+    // Calculate how many counter increments until timer
+    // hits compare, considering wraparound, and special
+    // case of complete wraparound.
+    compareTime = ((compareVal - timerVal) & 0xff);
+    if (compareTime == 0) {
+      compareTime = 256;
+    }
+
+    // Now convert the compare time from counter increments
+    // to simulation ticks, considering the fact that the
+    // increment actually has a phase offset.
+    // The +1 is from the timer behavior: if you set OCR0 to be X,
+    // it will actually fire when TCNT is X+1
+    compareTime = (compareTime + 1) << shiftFromScale();
+    compareTime = clock_to_sim(compareTime);
+    compareTime += sim_time();
+
+    // How long into a timer tick was the clock actually reset?
+    // This covers the case when the compare is set midway between
+    // a tick, so it will go off a little early
+    phaseOffset = sim_time();
+    phaseOffset -= last_zero();
+    phaseOffset %= clock_to_sim(1 << shiftFromScale());
+    compareTime -= phaseOffset;
+      
+    dbg("HplAtm128Timer0AsyncP", "Configuring new compare of %i for %i at time %llu  (@ %llu)\n", (int)compareVal, sim_node(), compareTime, sim_time());
+    
+    evt->time = compareTime;    
+  }
+  
+  void schedule_new_compare() {
+    if (compare != NULL) {
+      cancel_compare();
+    }
+    if (call Timer0.getScale() != AVR_CLOCK_OFF) {
+      sim_event_t* newEvent = allocate_compare();
+      configure_compare(newEvent);
+
+      compare = newEvent;
+      sim_queue_insert(newEvent);
+    }
+  }
+
+  
+  //=== Read the current timer value. ===================================
+  async command uint8_t  Timer0.get() {
+    uint8_t rval;
+    sim_time_t elapsed = sim_time() - last_zero();
+    elapsed = sim_to_clock(elapsed);
+    elapsed = elapsed >> shiftFromScale();
+    rval = (uint8_t)(elapsed & 0xff);
+    dbg("HplAtm128Timer0AsyncP", "HplAtm128Timer0AsyncP: Getting timer: %hhu\n", rval);
+    return rval;
+  }
+
+  //=== Set/clear the current timer value. ==============================
+  /**
+   * Set/clear the current timer value.
+   *
+   * This code is pretty tricky.  */
+  async command void Timer0.set(uint8_t newVal)  {
+    uint8_t curVal = call Timer0.get();
+    dbg("HplAtm128Timer0AsyncP", "HplAtm128Timer0AsyncP: Setting timer: %hhu\n", newVal);
+    if (newVal == curVal) {
+      return;
+    }
+    else {
+      sim_time_t adjustment = curVal - newVal;
+      adjustment = adjustment << shiftFromScale();
+      adjustment = clock_to_sim(adjustment);
+
+      if (newVal < curVal) {
+       lastZero += adjustment;
+      }
+      else { // newVal > curVal
+       lastZero -= adjustment;
+      }
+
+      schedule_new_overflow();
+      notify_changed();
+    }
+  }
+
+  //=== Read the current timer scale. ===================================
+  async command uint8_t Timer0.getScale() {
+    return TCCR0 & 0x7;
+  }
+
+  //=== Turn off the timers. ============================================
+  async command void Timer0.off() {
+    call Timer0.setScale(AVR_CLOCK_OFF);
+    savedCounter = call Timer0.get();
+    cancel_overflow();
+    notify_changed();
+  }
+
+  //=== Write a new timer scale. ========================================
+  async command void Timer0.setScale(uint8_t s)  {
+    Atm128TimerControl_t ctrl;
+    uint8_t currentScale = call Timer0.getScale();
+    uint8_t currentCounter;
+    dbg("HplAtm128Timer0AsyncP", "Timer0 scale set to %i\n", (int)s);
+    if (currentScale == 0) {
+      currentCounter = savedCounter;
+    }
+    else {
+      currentCounter = call Timer0.get();
+    }
+    
+    ctrl = call Timer0Ctrl.getControl();
+    ctrl.flat &= ~(0x7);
+    ctrl.flat |= (s & 0x7);
+    call Timer0Ctrl.setControl(ctrl);  
+
+    if (currentScale != s) {
+      adjust_zero(currentCounter);
+      schedule_new_overflow();
+    }
+    notify_changed();
+  }
+
+  //=== Read the control registers. =====================================
+  async command Atm128TimerControl_t Timer0Ctrl.getControl() { 
+    return *(Atm128TimerControl_t*)&TCCR0; 
+  }
+
+  //=== Write the control registers. ====================================
+  async command void Timer0Ctrl.setControl( Atm128TimerControl_t x ) {
+    dbg("HplAtm128Timer0AsyncP", "Setting control to be 0x%hhx\n", x.flat);
+    TCCR0 = x.flat; 
+  }
+
+  //=== Read the interrupt mask. =====================================
+  async command Atm128_TIMSK_t Timer0Ctrl.getInterruptMask() { 
+    return *(Atm128_TIMSK_t*)&TIMSK; 
+  }
+
+  //=== Write the interrupt mask. ====================================
+  DEFINE_UNION_CAST(TimerMask8_2int, Atm128_TIMSK_t, uint8_t);
+  DEFINE_UNION_CAST(TimerMask16_2int, Atm128_ETIMSK_t, uint8_t);
+
+  async command void Timer0Ctrl.setInterruptMask( Atm128_TIMSK_t x ) { 
+    TIMSK = TimerMask8_2int(x); 
+  }
+
+  //=== Read the interrupt flags. =====================================
+  async command Atm128_TIFR_t Timer0Ctrl.getInterruptFlag() {
+    Atm128_TIFR_t at;
+    at.flat = TIFR;
+    return at;
+  }
+
+  //=== Write the interrupt flags. ====================================
+  DEFINE_UNION_CAST(TimerFlags8_2int, Atm128_TIFR_t, uint8_t);
+  DEFINE_UNION_CAST(TimerFlags16_2int, Atm128_ETIFR_t, uint8_t);
+
+  async command void Timer0Ctrl.setInterruptFlag( Atm128_TIFR_t x ) { 
+    TIFR = TimerFlags8_2int(x); 
+  }
+
+  //=== Timer 8-bit implementation. ====================================
+  async command void Timer0.reset() {
+    // Clear TOV0. On real hardware, this is a write.
+    TIFR &= ~(1 << TOV0);
+  }
+  async command void Timer0.start() {
+    SET_BIT(ATM128_TIMSK, TOIE0);
+    dbg("HplAtm128Timer0AsyncP", "Enabling TOIE0 at %llu\n", sim_time());
+    schedule_new_overflow();
+  }
+  async command void Timer0.stop()  {
+    dbg("HplAtm128Timer0AsyncP", "Timer stopped @ %llu\n", sim_time());
+    CLR_BIT(ATM128_TIMSK, TOIE0);
+    cancel_overflow();
+  }
+
+  bool overflowed() {
+    return READ_BIT(ATM128_TIFR, TOV0); 
+  }
+
+  inline void stabiliseOverflow() {
+    /* From the atmel manual:
+
+    During asynchronous operation, the synchronization of the interrupt
+    flags for the asynchronous timer takes three processor cycles plus one
+    timer cycle.  The timer is therefore advanced by at least one before
+    the processor can read the timer value causing the setting of the
+    interrupt flag. The output compare pin is changed on the timer clock
+    and is not synchronized to the processor clock.
+
+    So: if the timer is = 0, wait till it's = 1, except if
+    - we're currently in the overflow interrupt handler
+    - or, the overflow flag is already set
+    */
+
+    //if (!inOverflow)
+    //  while (!TCNT0 && !overflowed())
+    //;
+  }
+  
+  async command bool Timer0.test()  { 
+    stabiliseOverflow();
+    return overflowed();
+  }
+
+  async command bool Timer0.isOn()  { 
+    return (call Timer0Ctrl.getInterruptMask()).bits.toie0; 
+  }
+
+  async command void Compare.reset() { TIFR = 1 << OCF0; }
+  async command void Compare.start() { SET_BIT(ATM128_TIMSK,OCIE0); }
+  async command void Compare.stop()  { CLR_BIT(ATM128_TIMSK,OCIE0); }
+  async command bool Compare.test()  { 
+    return (call Timer0Ctrl.getInterruptFlag()).bits.ocf0; 
+  }
+  async command bool Compare.isOn()  { 
+    return (call Timer0Ctrl.getInterruptMask()).bits.ocie0; 
+  }
+
+  //=== Read the compare registers. =====================================
+  async command uint8_t Compare.get()   {
+    dbg("HplAtm128Timer0AsyncP", "HplAtm128Timer0AsyncP: Getting compare: %hhu\n", OCR0);
+    return OCR0;
+  }
+  
+  //=== Write the compare registers. ====================================
+  async command void Compare.set(uint8_t t)   {
+    dbg("HplAtm128Timer0AsyncP", "HplAtm128Timer0AsyncP: Setting compare: %hhu\n", t);
+    atomic {
+       /* Re the comment above: it's a bad idea to wake up at time 0, as
+          we'll just spin when setting the next deadline. Try and reduce
+          the likelihood by delaying the interrupt...
+       */
+      if (t == 0 || t >= 0xfe)
+       t = 1;
+      
+      if (t != OCR0) {
+       OCR0 = t;
+       schedule_new_compare();
+      }
+    }
+  }
+
+  sim_event_t* overflow;  
+  void timer0_overflow_handle(sim_event_t* evt) {
+    if (evt->cancelled) {
+      return;
+    }
+    else {
+      if (READ_BIT(ATM128_TIMSK, TOIE0)) {
+       CLR_BIT(ATM128_TIFR, TOV0);
+       dbg("HplAtm128Timer0AsyncP", "Overflow interrupt at %s\n", sim_time_string());
+       SIG_OVERFLOW0();
+      }
+      else {
+       dbg("HplAtm128Timer0AsyncP", "Setting overflow bit at %s\n", sim_time_string());
+       SET_BIT(ATM128_TIFR, TOV0);
+      }
+      configure_overflow(evt);
+      sim_queue_insert(evt);
+    }
+  }
+  
+  sim_event_t* allocate_overflow() {
+    sim_event_t* newEvent = sim_queue_allocate_event();
+
+    newEvent->handle = timer0_overflow_handle;
+    newEvent->cleanup = sim_queue_cleanup_none;
+    return newEvent;
+  }
+  
+  void configure_overflow(sim_event_t* evt) {
+    sim_time_t overflowTime = 0;
+    uint8_t timerVal = call Timer0.get();
+    uint8_t overflowVal = 0;
+
+    // Calculate how many counter increments until timer
+    // hits compare, considering wraparound, and special
+    // case of complete wraparound.
+    overflowTime = ((overflowVal - timerVal) & 0xff);
+    if (overflowTime == 0) {
+      overflowTime = 256;
+    }
+
+    // Now convert the compare time from counter increments
+    // to simulation ticks, considering the fact that the
+    // increment actually has a phase offset.
+    overflowTime = overflowTime << shiftFromScale();
+    overflowTime = clock_to_sim(overflowTime);
+    overflowTime += sim_time();
+    overflowTime -= (sim_time() - last_zero()) % (1 << shiftFromScale());
+
+    dbg("HplAtm128Timer0AsyncP", "Scheduling new overflow for %i at time %llu\n", sim_node(), overflowTime);
+    
+    evt->time = overflowTime;
+  }
+  
+  void schedule_new_overflow() {
+    sim_event_t* newEvent = allocate_overflow();
+    configure_overflow(newEvent);
+
+    if (overflow != NULL) {
+      cancel_overflow();
+    }
+    overflow = newEvent;
+    sim_queue_insert(newEvent);
+  }
+  
+  void cancel_overflow() {
+    if (overflow != NULL) {
+      overflow->cancelled = 1;
+      dbg("HplAtm128Timer0AsyncP", "Cancelling overflow %p.\n", overflow);
+      overflow->cleanup = sim_queue_cleanup_total;
+    }
+  }
+
+  async command Atm128Assr_t TimerAsync.getAssr() {
+    return *(Atm128Assr_t *)&ASSR;
+  }
+
+  async command void TimerAsync.setAssr(Atm128Assr_t x) {
+    ASSR = x.flat;
+  }
+
+  async command void TimerAsync.setTimer0Asynchronous() {
+    ASSR |= 1 << AS0;
+  }
+
+  async command int TimerAsync.controlBusy() {
+    return (ASSR & (1 << TCR0UB)) != 0;
+  }
+
+  async command int TimerAsync.compareBusy() {
+    return (ASSR & (1 << OCR0UB)) != 0;
+  }
+
+  async command int TimerAsync.countBusy() {
+    return (ASSR & (1 << TCN0UB)) != 0;
+  }
+
+  void cancel_compare() {
+    dbg("HplAtm128CompareC", "Cancelling compare at 0x%p\n", compare);
+    if (compare != NULL) {
+      compare->cancelled = 1;
+      compare->cleanup = sim_queue_cleanup_total;
+    }
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm128/sim/HplAtm128Timer2C.nc b/tos/lib/tosthreads/chips/atm128/sim/HplAtm128Timer2C.nc
new file mode 100644 (file)
index 0000000..0877b9e
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * "Copyright (c) 2005 Stanford University. 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 STANFORD UNIVERSITY 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 STANFORD UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * 
+ * STANFORD UNIVERSITY 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 STANFORD UNIVERSITY
+ * HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
+ * ENHANCEMENTS, OR MODIFICATIONS."
+ */
+
+/**
+ * The TOSSIM implementation of the Atm128 Timer2. It is built from a
+ * timer-specific counter component and a generic compare
+ * component. The counter component has an additional simulation-only
+ * interface to let the compare component know when its state has
+ * changed (e.g., TCNTX was set).
+ *
+ * @date November 22 2005
+ *
+ * @author Philip Levis <pal@cs.stanford.edu>
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <dgay@intel-research.net>
+ */
+
+// $Id$/// $Id: HplAtm128Timer2C.nc,
+
+
+#include <Atm128Timer.h>
+
+configuration HplAtm128Timer2C
+{
+  provides {
+    // 8-bit Timers
+    interface HplAtm128Timer<uint8_t>   as Timer2;
+    interface HplAtm128TimerCtrl8       as Timer2Ctrl;
+    interface HplAtm128Compare<uint8_t> as Compare2;
+  }
+  uses interface ThreadScheduler;
+}
+implementation {
+  components HplAtm128Counter0C, new HplAtm128CompareC(uint8_t,
+                                                ATM128_OCR2,
+                                                ATM128_TIMSK,
+                                                OCIE2,
+                                                ATM128_TIFR,
+                                                OCF2);
+
+  Timer2 = HplAtm128Counter2C;
+  Timer2Ctrl = HplAtm128Counter2C;
+  Compare2 = HplAtm128CompareC;
+
+  HplAtm128CompareC.Timer -> HplAtm128Counter2C;
+  HplAtm128CompareC.TimerCtrl -> HplAtm128Counter2C;
+  HplAtm128CompareC.Notify -> HplAtm128Counter2C;
+  
+  components TinyThreadSchedulerC;
+  HplAtm128Counter0C.ThreadScheduler -> TinyThreadSchedulerC;
+  HplAtm128CompareC.ThreadScheduler -> TinyThreadSchedulerC;
+}
diff --git a/tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer1P.nc b/tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer1P.nc
new file mode 100644 (file)
index 0000000..a327d47
--- /dev/null
@@ -0,0 +1,231 @@
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ */
+
+/**
+ * Internal component of the HPL interface to Atmega1281 timer 1.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author Janos Sallai <janos.sallai@vanderbilt.edu>
+ */
+
+#include <Atm128Timer.h>
+
+module HplAtm1281Timer1P
+{
+  provides {
+    // 16-bit Timers
+    interface HplAtm128Timer<uint16_t>   as Timer;
+    interface HplAtm128TimerCtrl16       as TimerCtrl;
+    interface HplAtm128Capture<uint16_t> as Capture;
+    interface HplAtm128Compare<uint16_t> as CompareA;
+    interface HplAtm128Compare<uint16_t> as CompareB;
+    interface HplAtm128Compare<uint16_t> as CompareC;
+  }
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+  //=== Read the current timer value. ===================================
+  async command uint16_t Timer.get() { return TCNT1; }
+
+  //=== Set/clear the current timer value. ==============================
+  async command void Timer.set(uint16_t t) { TCNT1 = t; }
+
+  //=== Read the current timer scale. ===================================
+  async command uint8_t Timer.getScale() { return TCCR1B & 0x7; }
+
+  //=== Turn off the timers. ============================================
+  async command void Timer.off() { call Timer.setScale(AVR_CLOCK_OFF); }
+
+  //=== Write a new timer scale. ========================================
+  async command void Timer.setScale(uint8_t s)  { 
+    Atm128_TCCRB_t x = (Atm128_TCCRB_t) call TimerCtrl.getControlB();
+    x.bits.cs = s;
+    call TimerCtrl.setControlB(x.flat);  
+  }
+
+  //=== Read the control registers. =====================================
+  async command uint8_t TimerCtrl.getControlA() { 
+    return TCCR1A; 
+  }
+
+  async command uint8_t TimerCtrl.getControlB() { 
+    return TCCR1B; 
+  }
+
+  async command uint8_t TimerCtrl.getControlC() { 
+    return TCCR1C; 
+  }
+
+  //=== Write the control registers. ====================================
+  async command void TimerCtrl.setControlA( uint8_t x ) { 
+    TCCR1A = x; 
+  }
+
+  async command void TimerCtrl.setControlB( uint8_t x ) { 
+    TCCR1B = x; 
+  }
+
+  async command void TimerCtrl.setControlC( uint8_t x ) { 
+    TCCR1C = x; 
+  }
+
+  //=== Read the interrupt mask. =====================================
+  async command uint8_t TimerCtrl.getInterruptMask() { 
+    return TIMSK1; 
+  }
+
+  //=== Write the interrupt mask. ====================================
+  async command void TimerCtrl.setInterruptMask( uint8_t x ) { 
+    TIMSK1 = x; 
+  }
+
+  //=== Read the interrupt flags. =====================================
+  async command uint8_t TimerCtrl.getInterruptFlag() { 
+    return TIFR1; 
+  }
+
+  //=== Write the interrupt flags. ====================================
+  async command void TimerCtrl.setInterruptFlag( uint8_t x ) { 
+    TIFR1 = x; 
+  }
+
+  //=== Capture 16-bit implementation. ===================================
+  async command void Capture.setEdge(bool up) { WRITE_BIT(TCCR1B,ICES1, up); }
+
+  //=== Timer 16-bit implementation. ===================================
+  async command void Timer.reset()    { TIFR1 = 1 << TOV1; }
+  async command void Capture.reset()  { TIFR1 = 1 << ICF1; }
+  async command void CompareA.reset() { TIFR1 = 1 << OCF1A; }
+  async command void CompareB.reset() { TIFR1 = 1 << OCF1B; }
+  async command void CompareC.reset() { TIFR1 = 1 << OCF1C; }
+
+  async command void Timer.start()    { SET_BIT(TIMSK1,TOIE1); }
+  async command void Capture.start()  { SET_BIT(TIMSK1,ICIE1); }
+  async command void CompareA.start() { SET_BIT(TIMSK1,OCIE1A); }
+  async command void CompareB.start() { SET_BIT(TIMSK1,OCIE1B); }
+  async command void CompareC.start() { SET_BIT(TIMSK1,OCIE1C); }
+
+  async command void Timer.stop()    { CLR_BIT(TIMSK1,TOIE1); }
+  async command void Capture.stop()  { CLR_BIT(TIMSK1,ICIE1); }
+  async command void CompareA.stop() { CLR_BIT(TIMSK1,OCIE1A); }
+  async command void CompareB.stop() { CLR_BIT(TIMSK1,OCIE1B); }
+  async command void CompareC.stop() { CLR_BIT(TIMSK1,OCIE1C); }
+
+  async command bool Timer.test() { 
+    return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.tov; 
+  }
+  async command bool Capture.test()  { 
+    return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.icf; 
+  }
+  async command bool CompareA.test() { 
+    return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.ocfa; 
+  }
+  async command bool CompareB.test() { 
+    return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.ocfb; 
+  }
+  async command bool CompareC.test() { 
+    return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.ocfc; 
+  }
+
+  async command bool Timer.isOn() {
+    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.toie;
+  }
+  async command bool Capture.isOn()  {
+    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.icie;
+  }
+  async command bool CompareA.isOn() {
+    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.ociea;
+  }
+  async command bool CompareB.isOn() {
+    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.ocieb;
+  }
+  async command bool CompareC.isOn() {
+    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.ociec;
+  }
+
+  //=== Read the compare registers. =====================================
+  async command uint16_t CompareA.get() { return OCR1A; }
+  async command uint16_t CompareB.get() { return OCR1B; }
+  async command uint16_t CompareC.get() { return OCR1C; }
+
+  //=== Write the compare registers. ====================================
+  async command void CompareA.set(uint16_t t) { OCR1A = t; }
+  async command void CompareB.set(uint16_t t) { OCR1B = t; }
+  async command void CompareC.set(uint16_t t) { OCR1C = t; }
+
+  //=== Read the capture registers. =====================================
+  async command uint16_t Capture.get() { return ICR1; }
+
+  //=== Write the capture registers. ====================================
+  async command void Capture.set(uint16_t t)  { ICR1 = t; }
+
+  //=== Timer interrupts signals ========================================
+  default async event void CompareA.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE1A) {
+    signal CompareA.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void CompareB.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE1B) {
+    signal CompareB.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void CompareC.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE1C) {
+    signal CompareC.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void Capture.captured(uint16_t time) { }
+  AVR_NONATOMIC_HANDLER(SIG_INPUT_CAPTURE1) {
+    signal Capture.captured(call Timer.get());
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void Timer.overflow() { }
+  AVR_NONATOMIC_HANDLER(SIG_OVERFLOW1) {
+    signal Timer.overflow();
+    call PlatformInterrupt.postAmble();
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer2AsyncC.nc b/tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer2AsyncC.nc
new file mode 100644 (file)
index 0000000..0455261
--- /dev/null
@@ -0,0 +1,90 @@
+/// $Id$
+/*
+ * Copyright (c) 2006 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ */
+
+/**
+ * Simple wrapper around the actual timer implementation that automatically
+ * wires it to McuSleepC for low-power calculations..
+ *
+ * @author Philip Levis
+ * @author David Gay
+ * @author Janos Sallai <janos.sallai@vanderbilt.edu>
+ */
+
+#include <Atm128Timer.h>
+
+configuration HplAtm1281Timer2AsyncC
+{
+  provides {
+    // 8-bit Timers
+    interface HplAtm128Timer<uint8_t>   as Timer;
+    interface HplAtm128TimerCtrl8       as TimerCtrl;
+    interface HplAtm128Compare<uint8_t> as Compare;
+    interface HplAtm128TimerAsync       as TimerAsync;
+  }
+}
+implementation
+{
+  components HplAtm1281Timer2AsyncP;
+  components McuSleepC;
+
+  McuSleepC.McuPowerOverride -> HplAtm1281Timer2AsyncP;
+
+  Timer = HplAtm1281Timer2AsyncP;
+  TimerCtrl = HplAtm1281Timer2AsyncP;
+  Compare = HplAtm1281Timer2AsyncP;
+  TimerAsync = HplAtm1281Timer2AsyncP;
+  
+  components PlatformInterruptC;
+  HplAtm1281Timer2AsyncP.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer2AsyncP.nc b/tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer2AsyncP.nc
new file mode 100644 (file)
index 0000000..bab5723
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ */
+
+/**
+ * HPL interface to Atmega1281 timer 2 in ASYNC mode. This is a specialised
+ * HPL component that assumes that timer 2 is used in ASYNC mode and
+ * includes some workarounds for some of the weirdnesses (delayed overflow
+ * interrupt) of that mode.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <dgay@intel-research.net>
+ * @author Janos Sallai <janos.sallai@vanderbilt.edu>
+ */
+
+#include <Atm128Timer.h>
+
+module HplAtm1281Timer2AsyncP
+{
+  provides {
+    // 8-bit Timers
+    interface HplAtm128Timer<uint8_t>   as Timer;
+    interface HplAtm128TimerCtrl8       as TimerCtrl;
+    interface HplAtm128Compare<uint8_t> as Compare;
+    interface McuPowerOverride;
+    interface HplAtm128TimerAsync       as TimerAsync;
+  }
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+//  bool inOverflow;
+
+//  command error_t Init.init() {
+//    SET_BIT(ASSR, AS2);  // set Timer/Counter2 to asynchronous mode
+//    return SUCCESS;
+//  }
+
+  //=== Read the current timer value. ===================================
+  async command uint8_t  Timer.get() { return TCNT2; }
+
+  //=== Set/clear the current timer value. ==============================
+  async command void Timer.set(uint8_t t)  {
+    while (ASSR & 1 << TCN2UB)
+      ;
+    TCNT2 = t;
+  }
+
+  //=== Read the current timer scale. ===================================
+  async command uint8_t Timer.getScale() { return TCCR2B & 0x7; }
+
+  //=== Turn off the timers. ============================================
+  async command void Timer.off() { call Timer.setScale(AVR_CLOCK_OFF); }
+
+  //=== Write a new timer scale. ========================================
+  async command void Timer.setScale(uint8_t s)  { 
+    Atm128_TCCR2B_t x = (Atm128_TCCR2B_t) call TimerCtrl.getControlB();
+    x.bits.cs = s;
+    call TimerCtrl.setControlB(x.flat);  
+  }
+
+  //=== Read the control registers. =====================================
+  async command uint8_t TimerCtrl.getControlA() { 
+    return TCCR2A; 
+  }
+
+  async command uint8_t TimerCtrl.getControlB() { 
+    return TCCR2B; 
+  }
+
+  //=== Write the control registers. ====================================
+  async command void TimerCtrl.setControlA( uint8_t x ) { 
+    while (ASSR & 1 << TCR2AUB)
+      ;
+    TCCR2A = ((Atm128_TCCR2A_t)x).flat; 
+  }
+
+  async command void TimerCtrl.setControlB( uint8_t x ) { 
+    while (ASSR & 1 << TCR2BUB)
+      ;
+    TCCR2B = ((Atm128_TCCR2B_t)x).flat; 
+  }
+
+  //=== Read the interrupt mask. =====================================
+  async command uint8_t TimerCtrl.getInterruptMask() { 
+    return TIMSK2; 
+  }
+
+  //=== Write the interrupt mask. ====================================
+  async command void TimerCtrl.setInterruptMask( uint8_t x ) { 
+    TIMSK2 = x; 
+  }
+
+  //=== Read the interrupt flags. =====================================
+  async command uint8_t TimerCtrl.getInterruptFlag() { 
+    return TIFR2; 
+  }
+
+  //=== Write the interrupt flags. ====================================
+  async command void TimerCtrl.setInterruptFlag( uint8_t x ) { 
+    TIFR2 = x; 
+  }
+
+  //=== Timer 8-bit implementation. ====================================
+  async command void Timer.reset() { TIFR2 = 1 << TOV2; }
+  async command void Timer.start() { SET_BIT(TIMSK2, TOIE2); }
+  async command void Timer.stop()  { CLR_BIT(TIMSK2, TOIE2); }
+
+  bool overflowed() {
+    return ((Atm128_TIFR2_t)call TimerCtrl.getInterruptFlag()).bits.tov; 
+  }
+
+  async command bool Timer.test()  { 
+    return overflowed();
+  }
+  
+  async command bool Timer.isOn()  { 
+    return ((Atm128_TIMSK2_t)call TimerCtrl.getInterruptMask()).bits.toie; 
+  }
+  
+  async command void Compare.reset() { TIFR2 = 1 << OCF2A; }
+  async command void Compare.start() { SET_BIT(TIMSK2,OCIE2A); }
+  async command void Compare.stop()  { CLR_BIT(TIMSK2,OCIE2A); }
+  async command bool Compare.test()  { 
+    return ((Atm128_TIFR2_t)call TimerCtrl.getInterruptFlag()).bits.ocfa; 
+  }
+  async command bool Compare.isOn()  { 
+    return ((Atm128_TIMSK2_t)call TimerCtrl.getInterruptMask()).bits.ociea; 
+  }
+
+  //=== Read the compare registers. =====================================
+  async command uint8_t Compare.get(){ return OCR2A; }
+
+  //=== Write the compare registers. ====================================
+  async command void Compare.set(uint8_t t)   { 
+    atomic
+      {
+       while (ASSR & 1 << OCR2AUB)
+         ;
+       OCR2A = t; 
+      }
+  }
+
+  //=== Timer interrupts signals ========================================
+  inline void stabiliseTimer2() {
+    TCCR2A = TCCR2A;
+    while (ASSR & 1 << TCR2AUB)
+      ;
+  }
+
+  /**
+   * On the atm128, there is a small latency when waking up from
+   * POWER_SAVE mode. So if a timer is going to go off very soon, it's
+   * better to drop down until EXT_STANDBY, which has a 6 cycle wakeup
+   * latency. This function calculates whether staying in EXT_STANDBY
+   * is needed. If the timer is not running it returns POWER_DOWN.
+   * Please refer to TEP 112 and the atm128 datasheet for details.
+   */
+  
+  async command mcu_power_t McuPowerOverride.lowestState() {
+    uint8_t diff;
+    // We need to make sure that the sleep wakeup latency will not
+    // cause us to miss a timer. POWER_SAVE 
+    if (TIMSK2 & (1 << OCIE2A | 1 << TOIE2)) {
+      // need to wait for timer 2 updates propagate before sleeping
+      // (we don't need to worry about reentering sleep mode too early,
+      // as the wake ups from timer2 wait at least one TOSC1 cycle
+      // anyway - see the stabiliseTimer2 function)
+      while (ASSR & (1 << TCN2UB | 1 << OCR2AUB | 1 << TCR2AUB))
+       ;
+      diff = OCR2A - TCNT2;
+      if (diff < EXT_STANDBY_T0_THRESHOLD ||
+         TCNT2 > 256 - EXT_STANDBY_T0_THRESHOLD) 
+       return ATM128_POWER_EXT_STANDBY;
+      return ATM128_POWER_SAVE;
+    }
+    else {
+      return ATM128_POWER_DOWN;
+    }
+  }
+
+  default async event void Compare.fired() { }
+  AVR_ATOMIC_HANDLER(SIG_OUTPUT_COMPARE2A) {
+    stabiliseTimer2();
+//    __nesc_enable_interrupt();
+   
+    signal Compare.fired();
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void Timer.overflow() { }
+  AVR_ATOMIC_HANDLER(SIG_OVERFLOW2) {
+    stabiliseTimer2();
+//    inOverflow = TRUE;
+    signal Timer.overflow();
+//    inOverflow = FALSE;
+    call PlatformInterrupt.postAmble();  
+  }
+
+  // Asynchronous status register support
+  async command Atm128_ASSR_t TimerAsync.getAssr() {
+    return *(Atm128_ASSR_t *)&ASSR;
+  }
+
+  async command void TimerAsync.setAssr(Atm128_ASSR_t x) {
+    ASSR = x.flat;
+  }
+
+  async command void TimerAsync.setTimer2Asynchronous() {
+    ASSR |= 1 << AS2;
+  }
+
+  async command int TimerAsync.controlABusy() {
+    return (ASSR & (1 << TCR2AUB)) != 0;
+  }
+
+  async command int TimerAsync.controlBBusy() {
+    return (ASSR & (1 << TCR2BUB)) != 0;
+  }
+
+  async command int TimerAsync.compareABusy() {
+    return (ASSR & (1 << OCR2AUB)) != 0;
+  }
+
+  async command int TimerAsync.compareBBusy() {
+    return (ASSR & (1 << OCR2BUB)) != 0;
+  }
+
+  async command int TimerAsync.countBusy() {
+    return (ASSR & (1 << TCN2UB)) != 0;
+  }
+
+}
diff --git a/tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer3P.nc b/tos/lib/tosthreads/chips/atm1281/HplAtm1281Timer3P.nc
new file mode 100644 (file)
index 0000000..519c966
--- /dev/null
@@ -0,0 +1,231 @@
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ */
+
+/**
+ * Internal component of the HPL interface to Atmega1281 timer 3.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author Janos Sallai <janos.sallai@vanderbilt.edu>
+ */
+
+#include <Atm128Timer.h>
+
+module HplAtm1281Timer3P
+{
+  provides {
+    // 16-bit Timers
+    interface HplAtm128Timer<uint16_t>   as Timer;
+    interface HplAtm128TimerCtrl16       as TimerCtrl;
+    interface HplAtm128Capture<uint16_t> as Capture;
+    interface HplAtm128Compare<uint16_t> as CompareA;
+    interface HplAtm128Compare<uint16_t> as CompareB;
+    interface HplAtm128Compare<uint16_t> as CompareC;
+  }
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+  //=== Read the current timer value. ===================================
+  async command uint16_t Timer.get() { return TCNT3; }
+
+  //=== Set/clear the current timer value. ==============================
+  async command void Timer.set(uint16_t t) { TCNT3 = t; }
+
+  //=== Read the current timer scale. ===================================
+  async command uint8_t Timer.getScale() { return TCCR3B & 0x7; }
+
+  //=== Turn off the timers. ============================================
+  async command void Timer.off() { call Timer.setScale(AVR_CLOCK_OFF); }
+
+  //=== Write a new timer scale. ========================================
+  async command void Timer.setScale(uint8_t s)  { 
+    Atm128_TCCRB_t x = (Atm128_TCCRB_t) call TimerCtrl.getControlB();
+    x.bits.cs = s;
+    call TimerCtrl.setControlB(x.flat);  
+  }
+
+  //=== Read the control registers. =====================================
+  async command uint8_t TimerCtrl.getControlA() { 
+    return TCCR3A; 
+  }
+
+  async command uint8_t TimerCtrl.getControlB() { 
+    return TCCR3B; 
+  }
+
+  async command uint8_t TimerCtrl.getControlC() { 
+    return TCCR3C; 
+  }
+
+  //=== Write the control registers. ====================================
+  async command void TimerCtrl.setControlA( uint8_t x ) { 
+    TCCR3A = x; 
+  }
+
+  async command void TimerCtrl.setControlB( uint8_t x ) { 
+    TCCR3B = x; 
+  }
+
+  async command void TimerCtrl.setControlC( uint8_t x ) { 
+    TCCR3C = x; 
+  }
+
+  //=== Read the interrupt mask. =====================================
+  async command uint8_t TimerCtrl.getInterruptMask() { 
+    return TIMSK3; 
+  }
+
+  //=== Write the interrupt mask. ====================================
+  async command void TimerCtrl.setInterruptMask( uint8_t x ) { 
+    TIMSK3 = x; 
+  }
+
+  //=== Read the interrupt flags. =====================================
+  async command uint8_t TimerCtrl.getInterruptFlag() { 
+    return TIFR3; 
+  }
+
+  //=== Write the interrupt flags. ====================================
+  async command void TimerCtrl.setInterruptFlag( uint8_t x ) { 
+    TIFR3 = x; 
+  }
+
+  //=== Capture 16-bit implementation. ===================================
+  async command void Capture.setEdge(bool up) { WRITE_BIT(TCCR3B, ICES3, up); }
+
+  //=== Timer 16-bit implementation. ===================================
+  async command void Timer.reset()    { TIFR3 = 1 << TOV3; }
+  async command void Capture.reset()  { TIFR3 = 1 << ICF3; }
+  async command void CompareA.reset() { TIFR3 = 1 << OCF3A; }
+  async command void CompareB.reset() { TIFR3 = 1 << OCF3B; }
+  async command void CompareC.reset() { TIFR3 = 1 << OCF3C; }
+
+  async command void Timer.start()    { SET_BIT(TIMSK3,TOIE3); }
+  async command void Capture.start()  { SET_BIT(TIMSK3,ICIE3); }
+  async command void CompareA.start() { SET_BIT(TIMSK3,OCIE3A); }
+  async command void CompareB.start() { SET_BIT(TIMSK3,OCIE3B); }
+  async command void CompareC.start() { SET_BIT(TIMSK3,OCIE3C); }
+
+  async command void Timer.stop()    { CLR_BIT(TIMSK3,TOIE3); }
+  async command void Capture.stop()  { CLR_BIT(TIMSK3,ICIE3); }
+  async command void CompareA.stop() { CLR_BIT(TIMSK3,OCIE3A); }
+  async command void CompareB.stop() { CLR_BIT(TIMSK3,OCIE3B); }
+  async command void CompareC.stop() { CLR_BIT(TIMSK3,OCIE3C); }
+
+  async command bool Timer.test() { 
+    return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.tov; 
+  }
+  async command bool Capture.test()  { 
+    return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.icf; 
+  }
+  async command bool CompareA.test() { 
+    return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.ocfa; 
+  }
+  async command bool CompareB.test() { 
+    return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.ocfb; 
+  }
+  async command bool CompareC.test() { 
+    return ((Atm128_TIFR_t)call TimerCtrl.getInterruptFlag()).bits.ocfc; 
+  }
+
+  async command bool Timer.isOn() {
+    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.toie;
+  }
+  async command bool Capture.isOn()  {
+    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.icie;
+  }
+  async command bool CompareA.isOn() {
+    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.ociea;
+  }
+  async command bool CompareB.isOn() {
+    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.ocieb;
+  }
+  async command bool CompareC.isOn() {
+    return ((Atm128_TIMSK_t)call TimerCtrl.getInterruptMask()).bits.ociec;
+  }
+
+  //=== Read the compare registers. =====================================
+  async command uint16_t CompareA.get() { return OCR3A; }
+  async command uint16_t CompareB.get() { return OCR3B; }
+  async command uint16_t CompareC.get() { return OCR3C; }
+
+  //=== Write the compare registers. ====================================
+  async command void CompareA.set(uint16_t t) { OCR3A = t; }
+  async command void CompareB.set(uint16_t t) { OCR3B = t; }
+  async command void CompareC.set(uint16_t t) { OCR3C = t; }
+
+  //=== Read the capture registers. =====================================
+  async command uint16_t Capture.get() { return ICR3; }
+
+  //=== Write the capture registers. ====================================
+  async command void Capture.set(uint16_t t)  { ICR3 = t; }
+
+  //=== Timer interrupts signals ========================================
+  default async event void CompareA.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE3A) {
+    signal CompareA.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void CompareB.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE3B) {
+    signal CompareB.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void CompareC.fired() { }
+  AVR_NONATOMIC_HANDLER(SIG_OUTPUT_COMPARE3C) {
+    signal CompareC.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void Capture.captured(uint16_t time) { }
+  AVR_NONATOMIC_HANDLER(SIG_INPUT_CAPTURE3) {
+    signal Capture.captured(call Timer.get());
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void Timer.overflow() { }
+  AVR_NONATOMIC_HANDLER(SIG_OVERFLOW3) {
+    signal Timer.overflow();
+    call PlatformInterrupt.postAmble();
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm1281/HplAtm128AdcP.nc b/tos/lib/tosthreads/chips/atm1281/HplAtm128AdcP.nc
new file mode 100644 (file)
index 0000000..7c966aa
--- /dev/null
@@ -0,0 +1,162 @@
+/// $Id$
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS. 
+ */
+
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ */
+
+
+#include "Atm128Adc.h"
+
+/**
+ * HPL for the Atmega1281 A/D conversion susbsystem.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author Hu Siquan <husq@xbow.com>
+ * @author David Gay
+ * @author Janos Sallai <janos.sallai@vanderbilt.edu>
+ */
+
+module HplAtm128AdcP {
+  provides interface HplAtm128Adc;
+  uses interface McuPowerState;
+  uses interface PlatformInterrupt;
+}
+implementation {
+  //=== Direct read of HW registers. =================================
+  async command Atm128Admux_t HplAtm128Adc.getAdmux() { 
+    return *(Atm128Admux_t*)&ADMUX; 
+  }
+  async command Atm128Adcsra_t HplAtm128Adc.getAdcsra() { 
+    return *(Atm128Adcsra_t*)&ADCSRA; 
+  }
+  async command uint16_t HplAtm128Adc.getValue() { 
+    return ADC; 
+  }
+
+  DEFINE_UNION_CAST(Admux2int, Atm128Admux_t, uint8_t);
+  DEFINE_UNION_CAST(Adcsra2int, Atm128Adcsra_t, uint8_t);
+
+  //=== Direct write of HW registers. ================================
+  async command void HplAtm128Adc.setAdmux( Atm128Admux_t x ) { 
+    ADMUX = Admux2int(x); 
+  }
+  async command void HplAtm128Adc.setAdcsra( Atm128Adcsra_t x ) { 
+    ADCSRA = Adcsra2int(x); 
+  }
+
+  async command void HplAtm128Adc.setPrescaler(uint8_t scale){
+    Atm128Adcsra_t  current_val = call HplAtm128Adc.getAdcsra(); 
+    current_val.adif = FALSE;
+    current_val.adps = scale;
+    call HplAtm128Adc.setAdcsra(current_val);
+  }
+
+  // Individual bit manipulation. These all clear any pending A/D interrupt.
+  // It's not clear these are that useful...
+  async command void HplAtm128Adc.enableAdc() {
+    SET_BIT(ADCSRA, ADEN); 
+    call McuPowerState.update();
+  }
+  async command void HplAtm128Adc.disableAdc() {
+    CLR_BIT(ADCSRA, ADEN); 
+    call McuPowerState.update();
+  }
+  async command void HplAtm128Adc.enableInterruption() { SET_BIT(ADCSRA, ADIE); }
+  async command void HplAtm128Adc.disableInterruption() { CLR_BIT(ADCSRA, ADIE); }
+  async command void HplAtm128Adc.setContinuous() { 
+    ((Atm128Adcsrb_t*)&ADCSRB)->adts = 0; 
+    SET_BIT(ADCSRA, ADATE);
+  }
+  async command void HplAtm128Adc.setSingle() { CLR_BIT(ADCSRA, ADATE); }
+  async command void HplAtm128Adc.resetInterrupt() { SET_BIT(ADCSRA, ADIF); }
+  async command void HplAtm128Adc.startConversion() { SET_BIT(ADCSRA, ADSC); }
+
+
+  /* A/D status checks */
+  async command bool HplAtm128Adc.isEnabled()     {       
+    return (call HplAtm128Adc.getAdcsra()).aden; 
+  }
+
+  async command bool HplAtm128Adc.isStarted()     {
+    return (call HplAtm128Adc.getAdcsra()).adsc; 
+  }
+  
+  async command bool HplAtm128Adc.isComplete()    {
+    return (call HplAtm128Adc.getAdcsra()).adif; 
+  }
+
+  /* A/D interrupt handlers. Signals dataReady event with interrupts enabled */
+  AVR_ATOMIC_HANDLER(SIG_ADC) {
+    uint16_t data = call HplAtm128Adc.getValue();
+    
+    __nesc_enable_interrupt();
+    signal HplAtm128Adc.dataReady(data);
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void HplAtm128Adc.dataReady(uint16_t done) { }
+
+  async command bool HplAtm128Adc.cancel() { 
+    /* This is tricky */
+    atomic
+      {
+       Atm128Adcsra_t oldSr = call HplAtm128Adc.getAdcsra(), newSr;
+
+       /* To cancel a conversion, first turn off ADEN, then turn off
+          ADSC. We also cancel any pending interrupt.
+          Finally we reenable the ADC.
+       */
+       newSr = oldSr;
+       newSr.aden = FALSE;
+       newSr.adif = TRUE; /* This clears a pending interrupt... */
+       newSr.adie = FALSE; /* We don't want to start sampling again at the
+                              next sleep */
+       call HplAtm128Adc.setAdcsra(newSr);
+       newSr.adsc = FALSE;
+       call HplAtm128Adc.setAdcsra(newSr);
+       newSr.aden = TRUE;
+       call HplAtm128Adc.setAdcsra(newSr);
+
+       return oldSr.adif || oldSr.adsc;
+      }
+  }
+}
diff --git a/tos/lib/tosthreads/chips/atm1281/HplAtm128Timer1C.nc b/tos/lib/tosthreads/chips/atm1281/HplAtm128Timer1C.nc
new file mode 100644 (file)
index 0000000..0d51e4f
--- /dev/null
@@ -0,0 +1,79 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ */
+
+/**
+ * HPL interface to Atmega1281 timer 1.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <dgay@intel-research.net>
+ * @author Janos Sallai <janos.sallai@vanderbilt.edu>
+ */
+
+configuration HplAtm128Timer1C
+{
+  provides {
+    // 16-bit Timers
+    interface HplAtm128Timer<uint16_t>   as Timer;
+    interface HplAtm128TimerCtrl16       as TimerCtrl;
+    interface HplAtm128Capture<uint16_t> as Capture;
+    interface HplAtm128Compare<uint16_t> as Compare[uint8_t id];
+  }
+}
+implementation
+{
+  components HplAtm1281Timer1P;
+
+  Timer = HplAtm1281Timer1P;
+  TimerCtrl = HplAtm1281Timer1P;
+  Capture = HplAtm1281Timer1P;
+
+  Compare[0] = HplAtm1281Timer1P.CompareA; 
+  Compare[1] = HplAtm1281Timer1P.CompareB;
+  Compare[2] = HplAtm1281Timer1P.CompareC;
+  
+  components PlatformInterruptC;
+  HplAtm1281Timer1P.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/atm1281/HplAtm128Timer3C.nc b/tos/lib/tosthreads/chips/atm1281/HplAtm128Timer3C.nc
new file mode 100644 (file)
index 0000000..260bf57
--- /dev/null
@@ -0,0 +1,79 @@
+/// $Id$
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ */
+
+/**
+ * HPL interface to Atmega1281 timer 3.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay <dgay@intel-research.net>
+ * @author Janos Sallai <janos.sallai@vanderbilt.edu>
+ */
+
+configuration HplAtm128Timer3C
+{
+  provides {
+    // 16-bit Timers
+    interface HplAtm128Timer<uint16_t>   as Timer;
+    interface HplAtm128TimerCtrl16       as TimerCtrl;
+    interface HplAtm128Capture<uint16_t> as Capture;
+    interface HplAtm128Compare<uint16_t> as Compare[uint8_t id];
+  }
+}
+implementation
+{
+  components HplAtm1281Timer3P;
+
+  Timer = HplAtm1281Timer3P;
+  TimerCtrl = HplAtm1281Timer3P;
+  Capture = HplAtm1281Timer3P;
+
+  Compare[0] = HplAtm1281Timer3P.CompareA; 
+  Compare[1] = HplAtm1281Timer3P.CompareB;
+  Compare[2] = HplAtm1281Timer3P.CompareC;
+  
+  components PlatformInterruptC;
+  HplAtm1281Timer3P.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/atm1281/HplAtm128UartP.nc b/tos/lib/tosthreads/chips/atm1281/HplAtm128UartP.nc
new file mode 100644 (file)
index 0000000..81067ca
--- /dev/null
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2006 Arch Rock 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 Arch Rock 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
+ * ARCH ROCK 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
+ */
+
+/**
+ * @author Alec Woo <awoo@archrock.com>
+ * @author Jonathan Hui <jhui@archrock.com>
+ * @version $Revision$ $Date$
+ */
+
+/*
+ * Copyright (c) 2004-2005 Crossbow Technology, Inc.  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 CROSSBOW TECHNOLOGY OR ANY OF ITS LICENSORS 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 CROSSBOW OR ITS LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
+ * DAMAGE. 
+ *
+ * CROSSBOW TECHNOLOGY AND ITS LICENSORS SPECIFICALLY DISCLAIM ALL 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 NEITHER CROSSBOW NOR ANY LICENSOR HAS ANY 
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR 
+ * MODIFICATIONS.
+ */
+
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * 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 VANDERBILT UNIVERSITY 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 VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY 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 VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ */
+
+/** 
+ * Private component of the Atmega1281 serial port HPL.
+ *
+ * @author Martin Turon <mturon@xbow.com>
+ * @author David Gay
+ * @author Janos Sallai <janos.sallai@vanderbilt.edu>
+ */
+
+#include <Atm128Uart.h>
+
+module HplAtm128UartP {
+  
+  provides interface Init as Uart0Init;
+  provides interface StdControl as Uart0TxControl;
+  provides interface StdControl as Uart0RxControl;
+  provides interface HplAtm128Uart as HplUart0;
+    
+  provides interface Init as Uart1Init;
+  provides interface StdControl as Uart1TxControl;
+  provides interface StdControl as Uart1RxControl;
+  provides interface HplAtm128Uart as HplUart1;
+  
+  uses interface Atm128Calibrate;
+  uses interface McuPowerState;
+  
+  uses interface PlatformInterrupt;
+}
+implementation {
+  
+  //=== Uart Init Commands. ====================================
+  command error_t Uart0Init.init() {
+    Atm128UartMode_t    mode;
+    Atm128UartStatus_t  stts;
+    Atm128UartControl_t ctrl;
+    uint16_t ubrr0;
+
+    ctrl.bits = (struct Atm128_UCSRB_t) {rxcie:0, txcie:0, rxen:0, txen:0};
+    stts.bits = (struct Atm128_UCSRA_t) {u2x:1};
+    mode.bits = (struct Atm128_UCSRC_t) {ucsz:ATM128_UART_DATA_SIZE_8_BITS};
+
+    ubrr0 = call Atm128Calibrate.baudrateRegister(PLATFORM_BAUDRATE);
+    UBRR0L = ubrr0;
+    UBRR0H = ubrr0 >> 8;
+    UCSR0A = stts.flat;
+    UCSR0C = mode.flat;
+    UCSR0B = ctrl.flat;
+
+    return SUCCESS;
+  }
+
+  command error_t Uart0TxControl.start() {
+    SET_BIT(UCSR0B, TXEN0);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart0TxControl.stop() {
+    CLR_BIT(UCSR0B, TXEN0);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart0RxControl.start() {
+    SET_BIT(UCSR0B, RXEN0);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart0RxControl.stop() {
+    CLR_BIT(UCSR0B, RXEN0);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart0.enableTxIntr() {
+    SET_BIT(UCSR0A, TXC0);
+    SET_BIT(UCSR0B, TXCIE0);
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart0.disableTxIntr(){
+    CLR_BIT(UCSR0B, TXCIE0);
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart0.enableRxIntr(){
+    SET_BIT(UCSR0B, RXCIE0);
+    return SUCCESS;
+  }
+
+  async command error_t HplUart0.disableRxIntr(){
+    CLR_BIT(UCSR0B, RXCIE0);
+    return SUCCESS;
+  }
+  
+  async command bool HplUart0.isTxEmpty(){
+    return READ_BIT(UCSR0A, TXC0);
+  }
+
+  async command bool HplUart0.isRxEmpty(){
+    return !READ_BIT(UCSR0A, RXC0);
+  }
+  
+  async command uint8_t HplUart0.rx(){
+    return UDR0;
+  }
+
+  async command void HplUart0.tx(uint8_t data) {
+    atomic{
+      UDR0 = data; 
+      SET_BIT(UCSR0A, TXC0);
+    }
+  }
+  
+  AVR_ATOMIC_HANDLER(SIG_USART0_RECV) {
+    if (READ_BIT(UCSR0A, RXC0)) {
+      signal HplUart0.rxDone(UDR0);
+    }
+    call PlatformInterrupt.postAmble();
+  }
+  
+  AVR_NONATOMIC_HANDLER(SIG_USART0_TRANS) {
+    signal HplUart0.txDone();
+    call PlatformInterrupt.postAmble();
+  }
+  
+  command error_t Uart1Init.init() {
+    Atm128UartMode_t    mode;
+    Atm128UartStatus_t  stts;
+    Atm128UartControl_t ctrl;
+    uint16_t ubrr1;
+    
+    ctrl.bits = (struct Atm128_UCSRB_t) {rxcie:0, txcie:0, rxen:0, txen:0};
+    stts.bits = (struct Atm128_UCSRA_t) {u2x:1};
+    mode.bits = (struct Atm128_UCSRC_t) {ucsz:ATM128_UART_DATA_SIZE_8_BITS};
+
+    ubrr1 = call Atm128Calibrate.baudrateRegister(PLATFORM_BAUDRATE);
+    UBRR1L = ubrr1;
+    UBRR1H = ubrr1 >> 8;
+    UCSR1A = stts.flat;
+    UCSR1C = mode.flat;
+    UCSR1B = ctrl.flat;
+
+    return SUCCESS;
+  }
+
+  command error_t Uart1TxControl.start() {
+    SET_BIT(UCSR1B, TXEN1);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart1TxControl.stop() {
+    CLR_BIT(UCSR1B, TXEN1);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart1RxControl.start() {
+    SET_BIT(UCSR1B, RXEN1);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+
+  command error_t Uart1RxControl.stop() {
+    CLR_BIT(UCSR1B, RXEN1);
+    call McuPowerState.update();
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart1.enableTxIntr() {
+    SET_BIT(UCSR1A, TXC1);
+    SET_BIT(UCSR1B, TXCIE1);
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart1.disableTxIntr(){
+    CLR_BIT(UCSR1B, TXCIE1);
+    return SUCCESS;
+  }
+  
+  async command error_t HplUart1.enableRxIntr(){
+    SET_BIT(UCSR1B, RXCIE1);
+    return SUCCESS;
+  }
+
+  async command error_t HplUart1.disableRxIntr(){
+    CLR_BIT(UCSR1B, RXCIE1);
+    return SUCCESS;
+  }
+  
+  async command bool HplUart1.isTxEmpty() {
+    return READ_BIT(UCSR1A, TXC1);
+  }
+
+  async command bool HplUart1.isRxEmpty() {
+    return !READ_BIT(UCSR1A, RXC1);
+  }
+  
+  async command uint8_t HplUart1.rx(){
+    return UDR1;
+  }
+
+  async command void HplUart1.tx(uint8_t data) {
+    atomic{
+      UDR1 = data; 
+      SET_BIT(UCSR1A, TXC1);
+    }
+  }
+  
+  AVR_ATOMIC_HANDLER(SIG_USART1_RECV) {
+    if (READ_BIT(UCSR1A, RXC1))
+      signal HplUart1.rxDone(UDR1);
+    call PlatformInterrupt.postAmble();
+  }
+  
+  AVR_NONATOMIC_HANDLER(SIG_USART1_TRANS) {
+    signal HplUart1.txDone();
+    call PlatformInterrupt.postAmble();
+  }
+  
+  default async event void HplUart0.txDone() {} 
+  default async event void HplUart0.rxDone(uint8_t data) {}
+  default async event void HplUart1.txDone() {}
+  default async event void HplUart1.rxDone(uint8_t data) {}
+  
+}
diff --git a/tos/lib/tosthreads/chips/msp430/HplAdc12P.nc b/tos/lib/tosthreads/chips/msp430/HplAdc12P.nc
new file mode 100644 (file)
index 0000000..3200f4b
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2004, Technische Universitaet Berlin
+ * 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 Universitaet 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.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+/**
+ * The HplAdc12 interface exports low-level access to the ADC12 registers
+ * of the MSP430 MCU.
+ *
+ * @author Jan Hauer
+ * @see  Please refer to TEP 101 for more information about this component and its
+ *          intended use.
+ */
+
+module HplAdc12P {
+  provides interface HplAdc12;
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+  MSP430REG_NORACE(ADC12CTL0);
+  MSP430REG_NORACE(ADC12CTL1);
+  MSP430REG_NORACE(ADC12IFG);
+  MSP430REG_NORACE(ADC12IE);
+  MSP430REG_NORACE(ADC12IV);
+
+  // SFRs are accessed directly or cast to a pointer, both works fine
+  // (we don't access all SFRs directly, because that would result in
+  // much higher memory footprint)
+  
+  async command void HplAdc12.setCtl0(adc12ctl0_t control0){
+    ADC12CTL0 = *((uint16_t*) &control0); 
+  }
+  
+  async command void HplAdc12.setCtl1(adc12ctl1_t control1){
+    ADC12CTL1 = *((uint16_t*) &control1); 
+  }
+  
+  async command adc12ctl0_t HplAdc12.getCtl0(){ 
+    return *((adc12ctl0_t*) &ADC12CTL0); 
+  }
+  
+  async command adc12ctl1_t HplAdc12.getCtl1(){
+    return *((adc12ctl1_t*) &ADC12CTL1); 
+  }
+  
+  async command void HplAdc12.setMCtl(uint8_t i, adc12memctl_t memControl){
+    uint8_t *memCtlPtr = (uint8_t*) ADC12MCTL;
+    memCtlPtr += i;
+    *memCtlPtr = *(uint8_t*)&memControl; 
+  }
+   
+  async command adc12memctl_t HplAdc12.getMCtl(uint8_t i){
+    adc12memctl_t x = {inch: 0, sref: 0, eos: 0 };    
+    uint8_t *memCtlPtr = (uint8_t*) ADC12MCTL;
+    memCtlPtr += i;
+    x = *(adc12memctl_t*) memCtlPtr;
+    return x;
+  }  
+  
+  async command uint16_t HplAdc12.getMem(uint8_t i){
+    return *((uint16_t*) ADC12MEM + i);
+  }
+
+  async command void HplAdc12.setIEFlags(uint16_t mask){ ADC12IE = mask; } 
+  async command uint16_t HplAdc12.getIEFlags(){ return (uint16_t) ADC12IE; } 
+  
+  async command void HplAdc12.resetIFGs(){ 
+    ADC12IV = 0; 
+    ADC12IFG = 0;
+  } 
+  
+  async command void HplAdc12.startConversion(){ 
+    ADC12CTL0 |= ADC12ON; 
+    ADC12CTL0 |= (ADC12SC + ENC); 
+  }
+  
+  async command void HplAdc12.stopConversion(){
+    // stop conversion mode immediately, conversion data is unreliable
+    ADC12CTL1 &= ~(CONSEQ0 | CONSEQ1);
+    ADC12CTL0 &= ~(ADC12SC + ENC); 
+    ADC12CTL0 &= ~(ADC12ON); 
+  }
+  
+  async command void HplAdc12.enableConversion(){ 
+    ADC12CTL0 |= ENC; 
+  }
+    
+  async command bool HplAdc12.isBusy(){ return ADC12CTL1 & ADC12BUSY; }
+
+  TOSH_SIGNAL(ADC_VECTOR) {
+    signal HplAdc12.conversionDone(ADC12IV);
+    call PlatformInterrupt.postAmble();
+  }
+}
+
diff --git a/tos/lib/tosthreads/chips/msp430/HplMsp430DmaC.nc b/tos/lib/tosthreads/chips/msp430/HplMsp430DmaC.nc
new file mode 100644 (file)
index 0000000..d399eaf
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2005-2006 Arch Rock 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 Arch Rock 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
+ * ARCHED ROCK 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
+ */
+
+/*
+ * "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 Ben Greenstein <ben@cs.ucla.edu>
+ * @author Jonathan Hui <jhui@archrock.com>
+ * @version $Revision$ $Date$
+ */
+
+configuration HplMsp430DmaC {
+
+  provides interface HplMsp430DmaControl as Control;
+  provides interface HplMsp430DmaChannel as Channel0;
+  provides interface HplMsp430DmaChannel as Channel1;
+  provides interface HplMsp430DmaChannel as Channel2;
+
+}
+
+implementation {
+
+  components HplMsp430DmaP;
+  components new HplMsp430DmaXP( DMA0CTL_, DMA0SA_, DMA0DA_,
+                                DMA0SZ_, DMA0TSEL_MASK, 
+                                DMA0TSEL_SHIFT ) as Dma0;
+  components new HplMsp430DmaXP( DMA1CTL_, DMA1SA_, DMA1DA_,
+                                DMA1SZ_, DMA1TSEL_MASK, 
+                                DMA1TSEL_SHIFT ) as Dma1;
+  components new HplMsp430DmaXP( DMA2CTL_, DMA2SA_, DMA2DA_,
+                                DMA2SZ_, DMA2TSEL_MASK, 
+                                DMA2TSEL_SHIFT ) as Dma2;
+
+  Control = HplMsp430DmaP;
+  Channel0 = Dma0;
+  Channel1 = Dma1;
+  Channel2 = Dma2;
+  Dma0.Interrupt -> HplMsp430DmaP;
+  Dma1.Interrupt -> HplMsp430DmaP;
+  Dma2.Interrupt -> HplMsp430DmaP;
+
+  components PlatformInterruptC;
+  HplMsp430DmaP.PlatformInterrupt -> PlatformInterruptC;
+}
+
diff --git a/tos/lib/tosthreads/chips/msp430/HplMsp430DmaP.nc b/tos/lib/tosthreads/chips/msp430/HplMsp430DmaP.nc
new file mode 100644 (file)
index 0000000..61e21da
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2005-2006 Arch Rock 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 Arch Rock 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
+ * ARCHED ROCK 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
+ */
+
+/*
+ * "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 Ben Greenstein <ben@cs.ucla.edu>
+ * @author Jonathan Hui <jhui@archrock.com>
+ * @author Joe Polastre <info@moteiv.com>
+ * @version $Revision$ $Date$
+ */
+
+module HplMsp430DmaP {
+
+  provides interface HplMsp430DmaControl as DmaControl;
+  provides interface HplMsp430DmaInterrupt as Interrupt;
+  uses interface PlatformInterrupt;
+}
+
+implementation {
+
+  MSP430REG_NORACE( DMACTL0 );
+  MSP430REG_NORACE( DMACTL1 );
+
+  TOSH_SIGNAL( DACDMA_VECTOR ) {
+    signal Interrupt.fired();
+    call PlatformInterrupt.postAmble();
+  }
+
+  async command void DmaControl.setOnFetch(){
+    DMACTL1 |= DMAONFETCH;
+  }
+
+  async command void DmaControl.clearOnFetch(){
+    DMACTL1 &= ~DMAONFETCH;
+  }
+
+  async command void DmaControl.setRoundRobin(){
+    DMACTL1 |= ROUNDROBIN;
+  }
+  async command void DmaControl.clearRoundRobin(){
+    DMACTL1 &= ~ROUNDROBIN;
+  }
+
+  async command void DmaControl.setENNMI(){
+    DMACTL1 |= ENNMI;
+  }
+
+  async command void DmaControl.clearENNMI(){
+    DMACTL1 &= ~ENNMI;
+  }
+
+  async command void DmaControl.setState(dma_state_t s){
+    DMACTL1 = *(int*)&s;
+  }
+
+  async command dma_state_t DmaControl.getState(){
+    dma_state_t s;
+    s = *(dma_state_t*)&DMACTL1;
+    return s;
+  }
+
+  async command void DmaControl.reset(){
+    DMACTL0 = 0;
+    DMACTL1 = 0;
+  }
+
+}
+
diff --git a/tos/lib/tosthreads/chips/msp430/HplMsp430InterruptC.nc b/tos/lib/tosthreads/chips/msp430/HplMsp430InterruptC.nc
new file mode 100644 (file)
index 0000000..7f1eab9
--- /dev/null
@@ -0,0 +1,77 @@
+
+/* "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."
+ */
+
+/**
+ * HPL for the TI MSP430 family of microprocessors. This provides an
+ * abstraction for GPIO interrupts.
+ *
+ * @author Joe Polastre
+ */
+configuration HplMsp430InterruptC
+{
+#ifdef __msp430_have_port1
+  provides interface HplMsp430Interrupt as Port10;
+  provides interface HplMsp430Interrupt as Port11;
+  provides interface HplMsp430Interrupt as Port12;
+  provides interface HplMsp430Interrupt as Port13;
+  provides interface HplMsp430Interrupt as Port14;
+  provides interface HplMsp430Interrupt as Port15;
+  provides interface HplMsp430Interrupt as Port16;
+  provides interface HplMsp430Interrupt as Port17;
+#endif
+#ifdef __msp430_have_port2
+  provides interface HplMsp430Interrupt as Port20;
+  provides interface HplMsp430Interrupt as Port21;
+  provides interface HplMsp430Interrupt as Port22;
+  provides interface HplMsp430Interrupt as Port23;
+  provides interface HplMsp430Interrupt as Port24;
+  provides interface HplMsp430Interrupt as Port25;
+  provides interface HplMsp430Interrupt as Port26;
+  provides interface HplMsp430Interrupt as Port27;
+#endif
+}
+implementation
+{
+  components HplMsp430InterruptP as HplInterruptP;
+#ifdef __msp430_have_port1
+  Port10 = HplInterruptP.Port10;
+  Port11 = HplInterruptP.Port11;
+  Port12 = HplInterruptP.Port12;
+  Port13 = HplInterruptP.Port13;
+  Port14 = HplInterruptP.Port14;
+  Port15 = HplInterruptP.Port15;
+  Port16 = HplInterruptP.Port16;
+  Port17 = HplInterruptP.Port17;
+#endif
+#ifdef __msp430_have_port2
+  Port20 = HplInterruptP.Port20;
+  Port21 = HplInterruptP.Port21;
+  Port22 = HplInterruptP.Port22;
+  Port23 = HplInterruptP.Port23;
+  Port24 = HplInterruptP.Port24;
+  Port25 = HplInterruptP.Port25;
+  Port26 = HplInterruptP.Port26;
+  Port27 = HplInterruptP.Port27;
+#endif
+
+  components PlatformInterruptC;
+  HplInterruptP.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/msp430/HplMsp430InterruptNMIC.nc b/tos/lib/tosthreads/chips/msp430/HplMsp430InterruptNMIC.nc
new file mode 100644 (file)
index 0000000..b7ef025
--- /dev/null
@@ -0,0 +1,44 @@
+
+/* "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."
+ */
+
+/**
+ * HPL for the TI MSP430 family of microprocessors. This provides an
+ * abstraction for non-maskable interrupts.
+ *
+ * @author Joe Polastre
+ */
+configuration HplMsp430InterruptNMIC
+{
+  provides interface HplMsp430Interrupt as NMI;
+  provides interface HplMsp430Interrupt as OF;
+  provides interface HplMsp430Interrupt as ACCV;
+}
+implementation
+{
+  components HplMsp430InterruptNMIP as HplInterruptP;
+
+  NMI = HplInterruptP.NMI;
+  OF = HplInterruptP.OF;
+  ACCV = HplInterruptP.ACCV;
+  
+  components PlatformInterruptC;
+  HplInterruptP.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/msp430/HplMsp430InterruptNMIP.nc b/tos/lib/tosthreads/chips/msp430/HplMsp430InterruptNMIP.nc
new file mode 100644 (file)
index 0000000..b3071df
--- /dev/null
@@ -0,0 +1,95 @@
+
+/* "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 Joe Polastre
+ */
+module HplMsp430InterruptNMIP
+{
+  provides interface HplMsp430Interrupt as NMI;
+  provides interface HplMsp430Interrupt as OF;
+  provides interface HplMsp430Interrupt as ACCV;
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+  TOSH_SIGNAL(NMI_VECTOR)
+  {
+    volatile int n = IFG1;
+    if (n & NMIIFG) { signal NMI.fired(); }
+    else if (n & OFIFG)  { signal OF.fired(); }
+    else if (FCTL3 & ACCVIFG) { signal ACCV.fired(); }
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void NMI.fired() { call NMI.clear(); }
+  default async event void OF.fired() { call OF.clear(); }
+  default async event void ACCV.fired() { call ACCV.clear(); }
+
+  async command void NMI.enable() {
+    volatile uint16_t _watchdog;
+    atomic {
+      _watchdog = WDTCTL;
+      _watchdog = WDTPW | (_watchdog & 0x0FF);
+      _watchdog |= WDTNMI;
+      WDTCTL = _watchdog;
+      IE1 |= NMIIE;
+    }
+  }
+  async command void OF.enable() { atomic IE1 |= OFIE; }
+  async command void ACCV.enable() { atomic IE1 |= ACCVIE; }
+
+  async command void NMI.disable() {
+    volatile uint16_t _watchdog;
+    atomic {
+      _watchdog = WDTCTL;
+      _watchdog = WDTPW | (_watchdog & 0x0FF);
+      _watchdog &= ~WDTNMI;
+      WDTCTL = _watchdog;
+      IE1 &= ~NMIIE;
+    }
+  }
+  async command void OF.disable() { atomic IE1 &= ~OFIE; }
+  async command void ACCV.disable() { atomic IE1 &= ~ACCVIE; }
+
+  async command void NMI.clear() { atomic IFG1 &= ~NMIIFG; }
+  async command void OF.clear() { atomic IFG1 &= ~OFIFG; }
+  async command void ACCV.clear() { atomic FCTL3 &= ~ACCVIFG; }
+
+  async command bool NMI.getValue() { bool b; atomic b=(IFG1 & NMIIFG) & 0x01; return b; }
+  async command bool OF.getValue() { bool b; atomic b=(IFG1 & OFIFG) & 0x01; return b; }
+  async command bool ACCV.getValue() { bool b; atomic b=(FCTL3 & ACCVIFG) & 0x01; return b; }
+
+  async command void NMI.edge(bool l2h) { 
+    volatile uint16_t _watchdog;
+    atomic {
+      _watchdog = WDTCTL;
+      _watchdog = WDTPW | (_watchdog & 0x0FF);
+      if (l2h)  _watchdog &= ~(WDTNMIES); 
+      else      _watchdog |=  (WDTNMIES);
+      WDTCTL = _watchdog;
+    }
+  }
+  // edge does not apply to oscillator faults
+  async command void OF.edge(bool l2h) { }
+  // edge does not apply to flash access violations
+  async command void ACCV.edge(bool l2h) { }
+}
diff --git a/tos/lib/tosthreads/chips/msp430/HplMsp430InterruptP.nc b/tos/lib/tosthreads/chips/msp430/HplMsp430InterruptP.nc
new file mode 100644 (file)
index 0000000..69d97e2
--- /dev/null
@@ -0,0 +1,264 @@
+
+/* "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 Joe Polastre
+ */
+module HplMsp430InterruptP
+{
+#ifdef __msp430_have_port1
+  provides interface HplMsp430Interrupt as Port10;
+  provides interface HplMsp430Interrupt as Port11;
+  provides interface HplMsp430Interrupt as Port12;
+  provides interface HplMsp430Interrupt as Port13;
+  provides interface HplMsp430Interrupt as Port14;
+  provides interface HplMsp430Interrupt as Port15;
+  provides interface HplMsp430Interrupt as Port16;
+  provides interface HplMsp430Interrupt as Port17;
+#endif
+#ifdef __msp430_have_port2
+  provides interface HplMsp430Interrupt as Port20;
+  provides interface HplMsp430Interrupt as Port21;
+  provides interface HplMsp430Interrupt as Port22;
+  provides interface HplMsp430Interrupt as Port23;
+  provides interface HplMsp430Interrupt as Port24;
+  provides interface HplMsp430Interrupt as Port25;
+  provides interface HplMsp430Interrupt as Port26;
+  provides interface HplMsp430Interrupt as Port27;
+#endif
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+
+#ifdef __msp430_have_port1
+  TOSH_SIGNAL(PORT1_VECTOR)
+  {
+    volatile int n = P1IFG & P1IE;
+
+    if (n & (1 << 0)) { signal Port10.fired(); }
+    else if (n & (1 << 1)) { signal Port11.fired(); }
+    else if (n & (1 << 2)) { signal Port12.fired(); }
+    else if (n & (1 << 3)) { signal Port13.fired(); }
+    else if (n & (1 << 4)) { signal Port14.fired(); }
+    else if (n & (1 << 5)) { signal Port15.fired(); }
+    else if (n & (1 << 6)) { signal Port16.fired(); }
+    else if (n & (1 << 7)) { signal Port17.fired(); }
+    call PlatformInterrupt.postAmble();
+  }
+
+  default async event void Port10.fired() { call Port10.clear(); }
+  default async event void Port11.fired() { call Port11.clear(); }
+  default async event void Port12.fired() { call Port12.clear(); }
+  default async event void Port13.fired() { call Port13.clear(); }
+  default async event void Port14.fired() { call Port14.clear(); }
+  default async event void Port15.fired() { call Port15.clear(); }
+  default async event void Port16.fired() { call Port16.clear(); }
+  default async event void Port17.fired() { call Port17.clear(); }
+  async command void Port10.enable() { P1IE |= (1 << 0); }
+  async command void Port11.enable() { P1IE |= (1 << 1); }
+  async command void Port12.enable() { P1IE |= (1 << 2); }
+  async command void Port13.enable() { P1IE |= (1 << 3); }
+  async command void Port14.enable() { P1IE |= (1 << 4); }
+  async command void Port15.enable() { P1IE |= (1 << 5); }
+  async command void Port16.enable() { P1IE |= (1 << 6); }
+  async command void Port17.enable() { P1IE |= (1 << 7); }
+  async command void Port10.disable() { P1IE &= ~(1 << 0); }
+  async command void Port11.disable() { P1IE &= ~(1 << 1); }
+  async command void Port12.disable() { P1IE &= ~(1 << 2); }
+  async command void Port13.disable() { P1IE &= ~(1 << 3); }
+  async command void Port14.disable() { P1IE &= ~(1 << 4); }
+  async command void Port15.disable() { P1IE &= ~(1 << 5); }
+  async command void Port16.disable() { P1IE &= ~(1 << 6); }
+  async command void Port17.disable() { P1IE &= ~(1 << 7); }
+  async command void Port10.clear() { P1IFG &= ~(1 << 0); }
+  async command void Port11.clear() { P1IFG &= ~(1 << 1); }
+  async command void Port12.clear() { P1IFG &= ~(1 << 2); }
+  async command void Port13.clear() { P1IFG &= ~(1 << 3); }
+  async command void Port14.clear() { P1IFG &= ~(1 << 4); }
+  async command void Port15.clear() { P1IFG &= ~(1 << 5); }
+  async command void Port16.clear() { P1IFG &= ~(1 << 6); }
+  async command void Port17.clear() { P1IFG &= ~(1 << 7); }
+  async command bool Port10.getValue() { bool b; atomic b=(P1IN >> 0) & 1; return b; }
+  async command bool Port11.getValue() { bool b; atomic b=(P1IN >> 1) & 1; return b; }
+  async command bool Port12.getValue() { bool b; atomic b=(P1IN >> 2) & 1; return b; }
+  async command bool Port13.getValue() { bool b; atomic b=(P1IN >> 3) & 1; return b; }
+  async command bool Port14.getValue() { bool b; atomic b=(P1IN >> 4) & 1; return b; }
+  async command bool Port15.getValue() { bool b; atomic b=(P1IN >> 5) & 1; return b; }
+  async command bool Port16.getValue() { bool b; atomic b=(P1IN >> 6) & 1; return b; }
+  async command bool Port17.getValue() { bool b; atomic b=(P1IN >> 7) & 1; return b; }
+  async command void Port10.edge(bool l2h) { 
+    atomic {
+      if (l2h)  P1IES &= ~(1 << 0); 
+      else      P1IES |=  (1 << 0);
+    }
+  }
+  async command void Port11.edge(bool l2h) { 
+    atomic {
+      if (l2h)  P1IES &= ~(1 << 1); 
+      else      P1IES |=  (1 << 1);
+    }
+  }
+  async command void Port12.edge(bool l2h) { 
+    atomic {
+      if (l2h)  P1IES &= ~(1 << 2); 
+      else      P1IES |=  (1 << 2);
+    }
+  }
+  async command void Port13.edge(bool l2h) { 
+    atomic {
+      if (l2h)  P1IES &= ~(1 << 3); 
+      else      P1IES |=  (1 << 3);
+    }
+  }
+  async command void Port14.edge(bool l2h) { 
+    atomic {
+      if (l2h)  P1IES &= ~(1 << 4); 
+      else      P1IES |=  (1 << 4);
+    }
+  }
+  async command void Port15.edge(bool l2h) { 
+    atomic {
+      if (l2h)  P1IES &= ~(1 << 5); 
+      else      P1IES |=  (1 << 5);
+    }
+  }
+  async command void Port16.edge(bool l2h) { 
+    atomic {
+      if (l2h)  P1IES &= ~(1 << 6); 
+      else      P1IES |=  (1 << 6);
+    }
+  }
+  async command void Port17.edge(bool l2h) { 
+    atomic {
+      if (l2h)  P1IES &= ~(1 << 7); 
+      else      P1IES |=  (1 << 7);
+    }
+  }
+#endif
+
+#ifdef __msp430_have_port2
+  TOSH_SIGNAL(PORT2_VECTOR)
+  {
+    volatile int n = P2IFG & P2IE;
+
+    if (n & (1 << 0)) { signal Port20.fired(); }
+    else if (n & (1 << 1)) { signal Port21.fired(); }
+    else if (n & (1 << 2)) { signal Port22.fired(); }
+    else if (n & (1 << 3)) { signal Port23.fired(); }
+    else if (n & (1 << 4)) { signal Port24.fired(); }
+    else if (n & (1 << 5)) { signal Port25.fired(); }
+    else if (n & (1 << 6)) { signal Port26.fired(); }
+    else if (n & (1 << 7)) { signal Port27.fired(); }
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void Port20.fired() { call Port20.clear(); }
+  default async event void Port21.fired() { call Port21.clear(); }
+  default async event void Port22.fired() { call Port22.clear(); }
+  default async event void Port23.fired() { call Port23.clear(); }
+  default async event void Port24.fired() { call Port24.clear(); }
+  default async event void Port25.fired() { call Port25.clear(); }
+  default async event void Port26.fired() { call Port26.clear(); }
+  default async event void Port27.fired() { call Port27.clear(); }
+  async command void Port20.enable() { P2IE |= (1 << 0); }
+  async command void Port21.enable() { P2IE |= (1 << 1); }
+  async command void Port22.enable() { P2IE |= (1 << 2); }
+  async command void Port23.enable() { P2IE |= (1 << 3); }
+  async command void Port24.enable() { P2IE |= (1 << 4); }
+  async command void Port25.enable() { P2IE |= (1 << 5); }
+  async command void Port26.enable() { P2IE |= (1 << 6); }
+  async command void Port27.enable() { P2IE |= (1 << 7); }
+  async command void Port20.disable() { P2IE &= ~(1 << 0); }
+  async command void Port21.disable() { P2IE &= ~(1 << 1); }
+  async command void Port22.disable() { P2IE &= ~(1 << 2); }
+  async command void Port23.disable() { P2IE &= ~(1 << 3); }
+  async command void Port24.disable() { P2IE &= ~(1 << 4); }
+  async command void Port25.disable() { P2IE &= ~(1 << 5); }
+  async command void Port26.disable() { P2IE &= ~(1 << 6); }
+  async command void Port27.disable() { P2IE &= ~(1 << 7); }
+  async command void Port20.clear() { P2IFG &= ~(1 << 0); }
+  async command void Port21.clear() { P2IFG &= ~(1 << 1); }
+  async command void Port22.clear() { P2IFG &= ~(1 << 2); }
+  async command void Port23.clear() { P2IFG &= ~(1 << 3); }
+  async command void Port24.clear() { P2IFG &= ~(1 << 4); }
+  async command void Port25.clear() { P2IFG &= ~(1 << 5); }
+  async command void Port26.clear() { P2IFG &= ~(1 << 6); }
+  async command void Port27.clear() { P2IFG &= ~(1 << 7); }
+  async command bool Port20.getValue() { bool b; atomic b=(P2IN >> 0) & 1; return b; }
+  async command bool Port21.getValue() { bool b; atomic b=(P2IN >> 1) & 1; return b; }
+  async command bool Port22.getValue() { bool b; atomic b=(P2IN >> 2) & 1; return b; }
+  async command bool Port23.getValue() { bool b; atomic b=(P2IN >> 3) & 1; return b; }
+  async command bool Port24.getValue() { bool b; atomic b=(P2IN >> 4) & 1; return b; }
+  async command bool Port25.getValue() { bool b; atomic b=(P2IN >> 5) & 1; return b; }
+  async command bool Port26.getValue() { bool b; atomic b=(P2IN >> 6) & 1; return b; }
+  async command bool Port27.getValue() { bool b; atomic b=(P2IN >> 7) & 1; return b; }
+  async command void Port20.edge(bool l2h) {
+    atomic {
+      if (l2h)  P2IES &= ~(1 << 0);
+      else      P2IES |=  (1 << 0);
+    }
+  }
+  async command void Port21.edge(bool l2h) {
+    atomic {
+      if (l2h)  P2IES &= ~(1 << 1);
+      else      P2IES |=  (1 << 1);
+    }
+  }  
+  async command void Port22.edge(bool l2h) {
+    atomic {
+      if (l2h)  P2IES &= ~(1 << 2);
+      else      P2IES |=  (1 << 2);
+    }
+  }  
+  async command void Port23.edge(bool l2h) {
+    atomic {
+      if (l2h)  P2IES &= ~(1 << 3);
+      else      P2IES |=  (1 << 3);
+    }
+  }  
+  async command void Port24.edge(bool l2h) {
+    atomic {
+      if (l2h)  P2IES &= ~(1 << 4);
+      else      P2IES |=  (1 << 4);
+    }
+  }
+  async command void Port25.edge(bool l2h) {
+    atomic {
+      if (l2h)  P2IES &= ~(1 << 5);
+      else      P2IES |=  (1 << 5);
+    }
+  }
+  async command void Port26.edge(bool l2h) {
+    atomic {
+      if (l2h)  P2IES &= ~(1 << 6);
+      else      P2IES |=  (1 << 6);
+    }
+  }
+  async command void Port27.edge(bool l2h) {
+    atomic {
+      if (l2h)  P2IES &= ~(1 << 7);
+      else      P2IES |=  (1 << 7);
+    }
+  }
+#endif
+
+
+}
diff --git a/tos/lib/tosthreads/chips/msp430/HplMsp430Usart0C.nc b/tos/lib/tosthreads/chips/msp430/HplMsp430Usart0C.nc
new file mode 100644 (file)
index 0000000..ea9c605
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2005-2006 Arch Rock 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 Arch Rock 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
+ * ARCHED ROCK 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
+ */
+
+/*
+ * "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."
+ */
+
+/**
+ * An HPL abstraction of USART0 on the MSP430.
+ *
+ * @author Jonathan Hui <jhui@archrock.com>
+ * @author Joe Polastre
+ * @version $Revision$ $Date$
+ */
+
+#include "msp430usart.h"
+
+configuration HplMsp430Usart0C {
+  
+  provides interface HplMsp430Usart;
+  provides interface HplMsp430UsartInterrupts;
+  provides interface HplMsp430I2CInterrupts;
+  
+}
+
+implementation {
+  
+  components HplMsp430Usart0P as HplUsartP;
+  HplMsp430Usart = HplUsartP;
+  HplMsp430UsartInterrupts = HplUsartP;
+  HplMsp430I2CInterrupts = HplUsartP;
+  
+  components HplMsp430GeneralIOC as GIO;
+  HplUsartP.SIMO -> GIO.SIMO0;
+  HplUsartP.SOMI -> GIO.SOMI0;
+  HplUsartP.UCLK -> GIO.UCLK0;
+  HplUsartP.URXD -> GIO.URXD0;
+  HplUsartP.UTXD -> GIO.UTXD0;
+
+  components PlatformInterruptC;
+  HplUsartP.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/msp430/HplMsp430Usart0P.nc b/tos/lib/tosthreads/chips/msp430/HplMsp430Usart0P.nc
new file mode 100644 (file)
index 0000000..7eb9885
--- /dev/null
@@ -0,0 +1,399 @@
+/**
+ * Copyright (c) 2005-2006 Arched Rock 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 Arched Rock 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
+ * ARCHED ROCK 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
+ */
+
+/**
+ * Copyright (c) 2004-2005, Technische Universitaet Berlin
+ * 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 Universitaet 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.
+ */
+
+#include "msp430usart.h"
+/**
+ * Implementation of USART0 lowlevel functionality - stateless.
+ * Setting a mode will by default disable USART-Interrupts.
+ *
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * @author: Jonathan Hui <jhui@archedrock.com>
+ * @author: Vlado Handziski <handzisk@tkn.tu-berlin.de>
+ * @author: Joe Polastre
+ * @author: Philipp Huppertz <huppertz@tkn.tu-berlin.de>
+ * @version $Revision$ $Date$
+ */
+
+module HplMsp430Usart0P {
+  provides interface HplMsp430Usart as Usart;
+  provides interface HplMsp430UsartInterrupts as Interrupts;
+  provides interface HplMsp430I2CInterrupts as I2CInterrupts;
+  
+  uses interface HplMsp430I2C as HplI2C;
+  uses interface HplMsp430GeneralIO as SIMO;
+  uses interface HplMsp430GeneralIO as SOMI;
+  uses interface HplMsp430GeneralIO as UCLK;
+  uses interface HplMsp430GeneralIO as URXD;
+  uses interface HplMsp430GeneralIO as UTXD;
+  uses interface PlatformInterrupt;
+}
+
+implementation
+{
+  MSP430REG_NORACE(IE1);
+  MSP430REG_NORACE(ME1);
+  MSP430REG_NORACE(IFG1);
+  MSP430REG_NORACE(U0TCTL);
+  MSP430REG_NORACE(U0RCTL);
+  MSP430REG_NORACE(U0TXBUF);
+  
+  TOSH_SIGNAL(UART0RX_VECTOR) {
+    uint8_t temp = U0RXBUF;
+    signal Interrupts.rxDone(temp);
+    call PlatformInterrupt.postAmble();
+  }
+  
+  TOSH_SIGNAL(UART0TX_VECTOR) {
+    if ( call HplI2C.isI2C() )
+      signal I2CInterrupts.fired();
+    else
+      signal Interrupts.txDone();
+    call PlatformInterrupt.postAmble();
+  }
+  
+  async command void Usart.setUctl(msp430_uctl_t control) {
+    U0CTL=uctl2int(control);
+  }
+
+  async command msp430_uctl_t Usart.getUctl() {
+    return int2uctl(U0CTL);
+  }
+
+  async command void Usart.setUtctl(msp430_utctl_t control) {
+    U0TCTL=utctl2int(control);
+  }
+
+  async command msp430_utctl_t Usart.getUtctl() {
+    return int2utctl(U0TCTL);
+  }
+
+  async command void Usart.setUrctl(msp430_urctl_t control) {
+    U0RCTL=urctl2int(control);
+  }
+
+  async command msp430_urctl_t Usart.getUrctl() {
+    return int2urctl(U0RCTL);
+  }
+
+  async command void Usart.setUbr(uint16_t control) {
+    atomic {
+      U0BR0 = control & 0x00FF;
+      U0BR1 = (control >> 8) & 0x00FF;
+    }
+  }
+
+  async command uint16_t Usart.getUbr() {
+    return (U0BR1 << 8) + U0BR0;
+  }
+
+  async command void Usart.setUmctl(uint8_t control) {
+    U0MCTL=control;
+  }
+
+  async command uint8_t Usart.getUmctl() {
+    return U0MCTL;
+  }
+
+  async command void Usart.resetUsart(bool reset) {
+    if (reset) {
+      U0CTL = SWRST;
+    }
+    else {
+      CLR_FLAG(U0CTL, SWRST);
+    }
+  }
+
+  async command bool Usart.isSpi() {
+    atomic {
+      return (U0CTL & SYNC) && (ME1 & USPIE0);
+    }
+  }
+
+  async command bool Usart.isUart() {
+    atomic {
+      return !(U0CTL & SYNC) && ((ME1 & UTXE0) && (ME1 & URXE0));
+    }
+  }
+
+  async command bool Usart.isUartTx() {
+    atomic {
+      return !(U0CTL & SYNC) && (ME1 & UTXE0);
+    }
+  }
+
+  async command bool Usart.isUartRx() {
+    atomic {
+      return !(U0CTL & SYNC) && (ME1 & URXE0);
+    }
+  }
+
+  async command msp430_usartmode_t Usart.getMode() {
+    if (call Usart.isUart())
+      return USART_UART;
+    else if (call Usart.isUartRx())
+      return USART_UART_RX;
+    else if (call Usart.isUartTx())
+      return USART_UART_TX;
+    else if (call Usart.isSpi())
+      return USART_SPI;
+    else if (call HplI2C.isI2C())
+      return USART_I2C;
+    else
+      return USART_NONE;
+  }
+
+  async command void Usart.enableUart() {
+    atomic{
+      call UTXD.selectModuleFunc();
+      call URXD.selectModuleFunc();
+    }
+    ME1 |= (UTXE0 | URXE0);   // USART0 UART module enable
+  }
+
+  async command void Usart.disableUart() {
+    atomic {
+      ME1 &= ~(UTXE0 | URXE0);   // USART0 UART module enable
+      call UTXD.selectIOFunc();
+      call URXD.selectIOFunc();
+    }
+
+  }
+
+  async command void Usart.enableUartTx() {
+    call UTXD.selectModuleFunc();
+    ME1 |= UTXE0;   // USART0 UART Tx module enable
+  }
+
+  async command void Usart.disableUartTx() {
+    ME1 &= ~UTXE0;   // USART0 UART Tx module enable
+    call UTXD.selectIOFunc();
+
+  }
+
+  async command void Usart.enableUartRx() {
+    call URXD.selectModuleFunc();
+    ME1 |= URXE0;   // USART0 UART Rx module enable
+  }
+
+  async command void Usart.disableUartRx() {
+    ME1 &= ~URXE0;  // USART0 UART Rx module disable
+    call URXD.selectIOFunc();
+
+  }
+
+  async command void Usart.enableSpi() {
+    atomic {
+      call SIMO.selectModuleFunc();
+      call SOMI.selectModuleFunc();
+      call UCLK.selectModuleFunc();
+    }
+    ME1 |= USPIE0;   // USART0 SPI module enable
+  }
+
+  async command void Usart.disableSpi() {
+    atomic {
+      ME1 &= ~USPIE0;   // USART0 SPI module disable
+      call SIMO.selectIOFunc();
+      call SOMI.selectIOFunc();
+      call UCLK.selectIOFunc();
+    }
+  }
+  
+  void configSpi(msp430_spi_union_config_t* config) {
+    // U0CTL = (config->spiRegisters.uctl & ~I2C) | SYNC | SWRST;
+    U0CTL = (config->spiRegisters.uctl) | SYNC | SWRST;  
+    U0TCTL = config->spiRegisters.utctl;
+
+    call Usart.setUbr(config->spiRegisters.ubr);
+    call Usart.setUmctl(0x00);
+  }
+
+  async command void Usart.setModeSpi(msp430_spi_union_config_t* config) {
+    
+    atomic {
+       call Usart.resetUsart(TRUE);
+       call HplI2C.clearModeI2C();
+       call Usart.disableUart();
+      configSpi(config);
+      call Usart.enableSpi();
+      call Usart.resetUsart(FALSE);
+      call Usart.clrIntr();
+      call Usart.disableIntr();
+    }    
+    return;
+  }
+
+  void configUart(msp430_uart_union_config_t* config) {
+
+    U0CTL = (config->uartRegisters.uctl & ~SYNC) | SWRST;
+    U0TCTL = config->uartRegisters.utctl;
+    U0RCTL = config->uartRegisters.urctl;        
+    
+    call Usart.setUbr(config->uartRegisters.ubr);
+    call Usart.setUmctl(config->uartRegisters.umctl);
+  }
+
+  async command void Usart.setModeUart(msp430_uart_union_config_t* config) {
+
+    atomic { 
+      call Usart.resetUsart(TRUE);
+       call HplI2C.clearModeI2C();
+       call Usart.disableSpi();
+      configUart(config);
+      if ((config->uartConfig.utxe == 1) && (config->uartConfig.urxe == 1)) {
+       call Usart.enableUart();
+      } else if ((config->uartConfig.utxe == 0) && (config->uartConfig.urxe == 1)) {
+        call Usart.disableUartTx();
+        call Usart.enableUartRx();
+      } else if ((config->uartConfig.utxe == 1) && (config->uartConfig.urxe == 0)){
+        call Usart.disableUartRx();
+        call Usart.enableUartTx();
+      } else {
+        call Usart.disableUart();
+      }
+      call Usart.resetUsart(FALSE);
+      call Usart.clrIntr();
+      call Usart.disableIntr();
+    }
+    
+    return;
+  }
+
+  async command bool Usart.isTxIntrPending(){
+    if (IFG1 & UTXIFG0){
+      return TRUE;
+    }
+    return FALSE;
+  }
+
+  async command bool Usart.isTxEmpty(){
+    if (U0TCTL & TXEPT) {
+      return TRUE;
+    }
+    return FALSE;
+  }
+
+  async command bool Usart.isRxIntrPending(){
+    if (IFG1 & URXIFG0){
+      return TRUE;
+    }
+    return FALSE;
+  }
+
+  async command void Usart.clrTxIntr(){
+    IFG1 &= ~UTXIFG0;
+  }
+
+  async command void Usart.clrRxIntr() {
+    IFG1 &= ~URXIFG0;
+  }
+
+  async command void Usart.clrIntr() {
+    IFG1 &= ~(UTXIFG0 | URXIFG0);
+  }
+
+  async command void Usart.disableRxIntr() {
+    IE1 &= ~URXIE0;
+  }
+
+  async command void Usart.disableTxIntr() {
+    IE1 &= ~UTXIE0;
+  }
+
+  async command void Usart.disableIntr() {
+      IE1 &= ~(UTXIE0 | URXIE0);
+  }
+
+  async command void Usart.enableRxIntr() {
+    atomic {
+      IFG1 &= ~URXIFG0;
+      IE1 |= URXIE0;
+    }
+  }
+
+  async command void Usart.enableTxIntr() {
+    atomic {
+      IFG1 &= ~UTXIFG0;
+      IE1 |= UTXIE0;
+    }
+  }
+
+  async command void Usart.enableIntr() {
+    atomic {
+      IFG1 &= ~(UTXIFG0 | URXIFG0);
+      IE1 |= (UTXIE0 | URXIE0);
+    }
+  }
+
+  async command void Usart.tx(uint8_t data) {
+    atomic U0TXBUF = data;
+  }
+
+  async command uint8_t Usart.rx() {
+    uint8_t value;
+    atomic value = U0RXBUF;
+    return value;
+  }
+
+  default async event void I2CInterrupts.fired() {}
+  default async command bool HplI2C.isI2C() { return FALSE; }
+  default async command void HplI2C.clearModeI2C() {};
+  
+}
diff --git a/tos/lib/tosthreads/chips/msp430/HplMsp430Usart1C.nc b/tos/lib/tosthreads/chips/msp430/HplMsp430Usart1C.nc
new file mode 100644 (file)
index 0000000..9ce44ff
--- /dev/null
@@ -0,0 +1,91 @@
+/**
+ * Copyright (c) 2005-2006 Arched Rock 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 Arched Rock 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
+ * ARCHED ROCK 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
+ */
+
+/**
+ * "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."
+ */
+
+/**
+ * An HPL abstraction of USART1 on the MSP430.
+ *
+ * @author Jonathan Hui <jhui@archedrock.com>
+ * @author Joe Polastre
+ * @version $Revision$ $Date$
+ */
+
+#include "msp430usart.h"
+
+configuration HplMsp430Usart1C {
+
+  provides interface AsyncStdControl;
+  provides interface HplMsp430Usart;
+  provides interface HplMsp430UsartInterrupts;
+
+}
+
+implementation {
+
+  components HplMsp430Usart1P as HplUsartP;
+  components HplMsp430GeneralIOC as GIO;
+
+  AsyncStdControl = HplUsartP;
+  HplMsp430Usart = HplUsartP;
+  HplMsp430UsartInterrupts = HplUsartP;
+
+  HplUsartP.SIMO -> GIO.SIMO1;
+  HplUsartP.SOMI -> GIO.SOMI1;
+  HplUsartP.UCLK -> GIO.UCLK1;
+  HplUsartP.URXD -> GIO.URXD1;
+  HplUsartP.UTXD -> GIO.UTXD1;
+
+  components PlatformInterruptC;
+  HplUsartP.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/chips/msp430/HplMsp430Usart1P.nc b/tos/lib/tosthreads/chips/msp430/HplMsp430Usart1P.nc
new file mode 100644 (file)
index 0000000..73a0b28
--- /dev/null
@@ -0,0 +1,397 @@
+/**
+ * Copyright (c) 2005-2006 Arched Rock 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 Arched Rock 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
+ * ARCHED ROCK 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
+ */
+
+/**
+ * Copyright (c) 2004-2005, Technische Universitaet Berlin
+ * 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 Universitaet 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.
+ */
+
+#include "msp430usart.h"
+/**
+ * Implementation of USART1 lowlevel functionality - stateless.
+ * Setting a mode will by default disable USART-Interrupts.
+ *
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * @author: Jonathan Hui <jhui@archedrock.com>
+ * @author: Vlado Handziski <handzisk@tkn.tu-berlin.de>
+ * @author: Joe Polastre
+ * @version $Revision$ $Date$
+ */
+
+module HplMsp430Usart1P {
+  provides interface AsyncStdControl;
+  provides interface HplMsp430Usart as Usart;
+  provides interface HplMsp430UsartInterrupts as Interrupts;
+
+  uses interface HplMsp430GeneralIO as SIMO;
+  uses interface HplMsp430GeneralIO as SOMI;
+  uses interface HplMsp430GeneralIO as UCLK;
+  uses interface HplMsp430GeneralIO as URXD;
+  uses interface HplMsp430GeneralIO as UTXD;
+  uses interface PlatformInterrupt;
+}
+
+implementation
+{
+  MSP430REG_NORACE(IE2);
+  MSP430REG_NORACE(ME2);
+  MSP430REG_NORACE(IFG2);
+  MSP430REG_NORACE(U1TCTL);
+  MSP430REG_NORACE(U1RCTL);
+  MSP430REG_NORACE(U1TXBUF);
+
+
+
+  TOSH_SIGNAL(UART1RX_VECTOR) {
+    uint8_t temp = U1RXBUF;
+    signal Interrupts.rxDone(temp);
+    call PlatformInterrupt.postAmble();
+  }
+
+  TOSH_SIGNAL(UART1TX_VECTOR) {
+    signal Interrupts.txDone();
+    call PlatformInterrupt.postAmble();
+  }
+
+  async command error_t AsyncStdControl.start() {
+    return SUCCESS;
+  }
+
+  async command error_t AsyncStdControl.stop() {
+    call Usart.disableSpi();
+    call Usart.disableUart();
+    return SUCCESS;
+  }
+
+
+  async command void Usart.setUctl(msp430_uctl_t control) {
+    U1CTL=uctl2int(control);
+  }
+
+  async command msp430_uctl_t Usart.getUctl() {
+    return int2uctl(U0CTL);
+  }
+
+  async command void Usart.setUtctl(msp430_utctl_t control) {
+    U1TCTL=utctl2int(control);
+  }
+
+  async command msp430_utctl_t Usart.getUtctl() {
+    return int2utctl(U1TCTL);
+  }
+
+  async command void Usart.setUrctl(msp430_urctl_t control) {
+    U1RCTL=urctl2int(control);
+  }
+
+  async command msp430_urctl_t Usart.getUrctl() {
+    return int2urctl(U1RCTL);
+  }
+
+  async command void Usart.setUbr(uint16_t control) {
+    atomic {
+      U1BR0 = control & 0x00FF;
+      U1BR1 = (control >> 8) & 0x00FF;
+    }
+  }
+
+  async command uint16_t Usart.getUbr() {
+    return (U1BR1 << 8) + U1BR0;
+  }
+
+  async command void Usart.setUmctl(uint8_t control) {
+    U1MCTL=control;
+  }
+
+  async command uint8_t Usart.getUmctl() {
+    return U1MCTL;
+  }
+
+  async command void Usart.resetUsart(bool reset) {
+    if (reset)
+      U1CTL = SWRST;
+    else
+      CLR_FLAG(U1CTL, SWRST);
+  }
+
+  async command bool Usart.isSpi() {
+    atomic {
+      return (U1CTL & SYNC) && (ME2 & USPIE1);
+    }
+  }
+
+  async command bool Usart.isUart() {
+    atomic {
+      return !(U1CTL & SYNC) && ((ME2 & UTXE1) && (ME2 & URXE1));
+    }
+  }
+
+  async command bool Usart.isUartTx() {
+    atomic {
+      return !(U1CTL & SYNC) && (ME2 & UTXE1);
+    }
+  }
+
+  async command bool Usart.isUartRx() {
+    atomic {
+      return !(U1CTL & SYNC) && (ME2 & URXE1);
+    }
+  }
+
+  async command msp430_usartmode_t Usart.getMode() {
+    if (call Usart.isUart())
+      return USART_UART;
+    else if (call Usart.isUartRx())
+      return USART_UART_RX;
+    else if (call Usart.isUartTx())
+      return USART_UART_TX;
+    else if (call Usart.isSpi())
+      return USART_SPI;
+    else
+      return USART_NONE;
+  }
+
+  async command void Usart.enableUart() {
+    atomic{
+      call UTXD.selectModuleFunc();
+      call URXD.selectModuleFunc();
+    }
+    ME2 |= (UTXE1 | URXE1);   // USART1 UART module enable
+  }
+
+  async command void Usart.disableUart() {
+    atomic {
+      ME2 &= ~(UTXE1 | URXE1);   // USART1 UART module enable
+      call UTXD.selectIOFunc();
+      call URXD.selectIOFunc();
+    }
+
+  }
+
+  async command void Usart.enableUartTx() {
+    call UTXD.selectModuleFunc();
+    ME2 |= UTXE1;   // USART1 UART Tx module enable
+  }
+
+  async command void Usart.disableUartTx() {
+    ME2 &= ~UTXE1;   // USART1 UART Tx module enable
+    call UTXD.selectIOFunc();
+
+  }
+
+  async command void Usart.enableUartRx() {
+    call URXD.selectModuleFunc();
+    ME2 |= URXE1;   // USART1 UART Rx module enable
+  }
+
+  async command void Usart.disableUartRx() {
+    ME2 &= ~URXE1;  // USART1 UART Rx module disable
+    call URXD.selectIOFunc();
+
+  }
+
+  async command void Usart.enableSpi() {
+    atomic {
+      call SIMO.selectModuleFunc();
+      call SOMI.selectModuleFunc();
+      call UCLK.selectModuleFunc();
+    }
+    ME2 |= USPIE1;   // USART1 SPI module enable
+  }
+
+  async command void Usart.disableSpi() {
+    atomic {
+      ME2 &= ~USPIE1;   // USART1 SPI module disable
+      call SIMO.selectIOFunc();
+      call SOMI.selectIOFunc();
+      call UCLK.selectIOFunc();
+    }
+  }
+
+  void configSpi(msp430_spi_union_config_t* config) {
+    U1CTL = (config->spiRegisters.uctl) | SYNC | SWRST;  
+    U1TCTL = config->spiRegisters.utctl;
+
+    call Usart.setUbr(config->spiRegisters.ubr);
+    call Usart.setUmctl(0x00);
+  }
+
+
+  async command void Usart.setModeSpi(msp430_spi_union_config_t* config) {    
+    atomic {
+      call Usart.resetUsart(TRUE);
+      call Usart.disableUart();
+      configSpi(config);
+      call Usart.enableSpi();
+      call Usart.resetUsart(FALSE);
+      call Usart.clrIntr();
+      call Usart.disableIntr();
+    }    
+    return;
+  }
+
+
+  void configUart(msp430_uart_union_config_t* config) {
+
+    U1CTL = (config->uartRegisters.uctl & ~SYNC) | SWRST;
+    U1TCTL = config->uartRegisters.utctl;
+    U1RCTL = config->uartRegisters.urctl;        
+    
+    call Usart.setUbr(config->uartRegisters.ubr);
+    call Usart.setUmctl(config->uartRegisters.umctl);
+  }
+
+  async command void Usart.setModeUart(msp430_uart_union_config_t* config) {
+
+    atomic { 
+      call Usart.resetUsart(TRUE);
+      call Usart.disableSpi();
+      configUart(config);
+      if ((config->uartConfig.utxe == 1) && (config->uartConfig.urxe == 1)) {
+       call Usart.enableUart();
+      } else if ((config->uartConfig.utxe == 0) && (config->uartConfig.urxe == 1)) {
+        call Usart.disableUartTx();
+        call Usart.enableUartRx();
+      } else if ((config->uartConfig.utxe == 1) && (config->uartConfig.urxe == 0)){
+        call Usart.disableUartRx();
+        call Usart.enableUartTx();
+      } else {
+        call Usart.disableUart();
+      }
+      call Usart.resetUsart(FALSE);
+      call Usart.clrIntr();
+      call Usart.disableIntr();
+    }
+    
+    return;
+  }
+
+  async command bool Usart.isTxIntrPending(){
+    if (IFG2 & UTXIFG1){
+      return TRUE;
+    }
+    return FALSE;
+  }
+
+  async command bool Usart.isTxEmpty(){
+    if (U1TCTL & TXEPT) {
+      return TRUE;
+    }
+    return FALSE;
+  }
+
+  async command bool Usart.isRxIntrPending(){
+    if (IFG2 & URXIFG1){
+      return TRUE;
+    }
+    return FALSE;
+  }
+
+  async command void Usart.clrTxIntr(){
+    IFG2 &= ~UTXIFG1;
+  }
+
+  async command void Usart.clrRxIntr() {
+    IFG2 &= ~URXIFG1;
+  }
+
+  async command void Usart.clrIntr() {
+    IFG2 &= ~(UTXIFG1 | URXIFG1);
+  }
+
+  async command void Usart.disableRxIntr() {
+    IE2 &= ~URXIE1;
+  }
+
+  async command void Usart.disableTxIntr() {
+    IE2 &= ~UTXIE1;
+  }
+
+  async command void Usart.disableIntr() {
+      IE2 &= ~(UTXIE1 | URXIE1);
+  }
+
+  async command void Usart.enableRxIntr() {
+    atomic {
+      IFG2 &= ~URXIFG1;
+      IE2 |= URXIE1;
+    }
+  }
+
+  async command void Usart.enableTxIntr() {
+    atomic {
+      IFG2 &= ~UTXIFG1;
+      IE2 |= UTXIE1;
+    }
+  }
+
+  async command void Usart.enableIntr() {
+    atomic {
+      IFG2 &= ~(UTXIFG1 | URXIFG1);
+      IE2 |= (UTXIE1 | URXIE1);
+    }
+  }
+
+  async command void Usart.tx(uint8_t data) {
+    atomic U1TXBUF = data;
+  }
+
+  async command uint8_t Usart.rx() {
+    uint8_t value;
+    atomic value = U1RXBUF;
+    return value;
+  }
+
+}
diff --git a/tos/lib/tosthreads/chips/msp430/Msp430Adc12P.nc b/tos/lib/tosthreads/chips/msp430/Msp430Adc12P.nc
new file mode 100644 (file)
index 0000000..3f3e1ea
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2006, Technische Universitaet Berlin
+ * 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 Universitaet 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.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include <Msp430Adc12.h> 
+configuration Msp430Adc12P 
+{ 
+  provides {
+    interface Resource[uint8_t id]; 
+    interface Msp430Adc12SingleChannel as SingleChannel[uint8_t id]; 
+    interface Msp430Adc12MultiChannel as MultiChannel[uint8_t id]; 
+    interface Msp430Adc12Overflow as Overflow[uint8_t id]; 
+    interface AsyncStdControl as DMAExtension[uint8_t id];
+  }
+} implementation { 
+  components Msp430Adc12ImplP, HplAdc12P, MainC, 
+             new SimpleRoundRobinArbiterC(MSP430ADC12_RESOURCE) as Arbiter;
+
+  Resource = Arbiter;
+  SingleChannel = Msp430Adc12ImplP.SingleChannel;
+  MultiChannel= Msp430Adc12ImplP.MultiChannel;
+  Overflow = Msp430Adc12ImplP.Overflow;
+  DMAExtension = Msp430Adc12ImplP.DMAExtension;
+  
+  Msp430Adc12ImplP.Init <- MainC;
+  Msp430Adc12ImplP.ADCArbiterInfo -> Arbiter;
+  Msp430Adc12ImplP.HplAdc12 -> HplAdc12P;
+
+#ifdef ADC12_P6PIN_AUTO_CONFIGURE
+  components HplMsp430GeneralIOC;
+  Msp430Adc12ImplP.Port60 -> HplMsp430GeneralIOC.Port60;
+  Msp430Adc12ImplP.Port61 -> HplMsp430GeneralIOC.Port61;
+  Msp430Adc12ImplP.Port62 -> HplMsp430GeneralIOC.Port62;
+  Msp430Adc12ImplP.Port63 -> HplMsp430GeneralIOC.Port63;
+  Msp430Adc12ImplP.Port64 -> HplMsp430GeneralIOC.Port64;
+  Msp430Adc12ImplP.Port65 -> HplMsp430GeneralIOC.Port65;
+  Msp430Adc12ImplP.Port66 -> HplMsp430GeneralIOC.Port66;
+  Msp430Adc12ImplP.Port67 -> HplMsp430GeneralIOC.Port67;
+#endif
+
+#ifdef ADC12_TIMERA_ENABLED
+  components Msp430TimerC;
+  Msp430Adc12ImplP.TimerA -> Msp430TimerC.TimerA;
+  Msp430Adc12ImplP.ControlA0 -> Msp430TimerC.ControlA0;
+  Msp430Adc12ImplP.ControlA1 -> Msp430TimerC.ControlA1;
+  Msp430Adc12ImplP.CompareA0 -> Msp430TimerC.CompareA0;
+  Msp430Adc12ImplP.CompareA1 -> Msp430TimerC.CompareA1;
+#endif
+
+  components PlatformInterruptC;
+  HplAdc12P.PlatformInterrupt -> PlatformInterruptC;
+}
+
diff --git a/tos/lib/tosthreads/chips/msp430/Msp430TimerC.nc b/tos/lib/tosthreads/chips/msp430/Msp430TimerC.nc
new file mode 100644 (file)
index 0000000..3ac7648
--- /dev/null
@@ -0,0 +1,166 @@
+
+/* "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."
+ */
+/**
+ * @author Cory Sharp <cssharp@eecs.berkeley.edu>
+ */
+
+configuration Msp430TimerC
+{
+  provides interface Msp430Timer as TimerA;
+  provides interface Msp430TimerControl as ControlA0;
+  provides interface Msp430TimerControl as ControlA1;
+  provides interface Msp430TimerControl as ControlA2;
+  provides interface Msp430Compare as CompareA0;
+  provides interface Msp430Compare as CompareA1;
+  provides interface Msp430Compare as CompareA2;
+  provides interface Msp430Capture as CaptureA0;
+  provides interface Msp430Capture as CaptureA1;
+  provides interface Msp430Capture as CaptureA2;
+
+  provides interface Msp430Timer as TimerB;
+  provides interface Msp430TimerControl as ControlB0;
+  provides interface Msp430TimerControl as ControlB1;
+  provides interface Msp430TimerControl as ControlB2;
+  provides interface Msp430TimerControl as ControlB3;
+  provides interface Msp430TimerControl as ControlB4;
+  provides interface Msp430TimerControl as ControlB5;
+  provides interface Msp430TimerControl as ControlB6;
+  provides interface Msp430Compare as CompareB0;
+  provides interface Msp430Compare as CompareB1;
+  provides interface Msp430Compare as CompareB2;
+  provides interface Msp430Compare as CompareB3;
+  provides interface Msp430Compare as CompareB4;
+  provides interface Msp430Compare as CompareB5;
+  provides interface Msp430Compare as CompareB6;
+  provides interface Msp430Capture as CaptureB0;
+  provides interface Msp430Capture as CaptureB1;
+  provides interface Msp430Capture as CaptureB2;
+  provides interface Msp430Capture as CaptureB3;
+  provides interface Msp430Capture as CaptureB4;
+  provides interface Msp430Capture as CaptureB5;
+  provides interface Msp430Capture as CaptureB6;
+}
+implementation
+{
+  components new Msp430TimerP( TAIV_, TAR_, TACTL_, TAIFG, TACLR, TAIE,
+               TASSEL0, TASSEL1, FALSE ) as Msp430TimerA
+           , new Msp430TimerP( TBIV_, TBR_, TBCTL_, TBIFG, TBCLR, TBIE,
+               TBSSEL0, TBSSEL1, TRUE ) as Msp430TimerB
+           , new Msp430TimerCapComP( TACCTL0_, TACCR0_ ) as Msp430TimerA0
+           , new Msp430TimerCapComP( TACCTL1_, TACCR1_ ) as Msp430TimerA1
+           , new Msp430TimerCapComP( TACCTL2_, TACCR2_ ) as Msp430TimerA2
+           , new Msp430TimerCapComP( TBCCTL0_, TBCCR0_ ) as Msp430TimerB0
+           , new Msp430TimerCapComP( TBCCTL1_, TBCCR1_ ) as Msp430TimerB1
+           , new Msp430TimerCapComP( TBCCTL2_, TBCCR2_ ) as Msp430TimerB2
+           , new Msp430TimerCapComP( TBCCTL3_, TBCCR3_ ) as Msp430TimerB3
+           , new Msp430TimerCapComP( TBCCTL4_, TBCCR4_ ) as Msp430TimerB4
+           , new Msp430TimerCapComP( TBCCTL5_, TBCCR5_ ) as Msp430TimerB5
+           , new Msp430TimerCapComP( TBCCTL6_, TBCCR6_ ) as Msp430TimerB6
+           , Msp430TimerCommonP as Common
+           ;
+
+  // Timer A
+  TimerA = Msp430TimerA.Timer;
+  Msp430TimerA.Overflow -> Msp430TimerA.Event[5];
+  Msp430TimerA.VectorTimerX0 -> Common.VectorTimerA0;
+  Msp430TimerA.VectorTimerX1 -> Common.VectorTimerA1;
+
+  // Timer A0
+  ControlA0 = Msp430TimerA0.Control;
+  CompareA0 = Msp430TimerA0.Compare;
+  CaptureA0 = Msp430TimerA0.Capture;
+  Msp430TimerA0.Timer -> Msp430TimerA.Timer;
+  Msp430TimerA0.Event -> Msp430TimerA.Event[0];
+
+  // Timer A1
+  ControlA1 = Msp430TimerA1.Control;
+  CompareA1 = Msp430TimerA1.Compare;
+  CaptureA1 = Msp430TimerA1.Capture;
+  Msp430TimerA1.Timer -> Msp430TimerA.Timer;
+  Msp430TimerA1.Event -> Msp430TimerA.Event[1];
+
+  // Timer A2
+  ControlA2 = Msp430TimerA2.Control;
+  CompareA2 = Msp430TimerA2.Compare;
+  CaptureA2 = Msp430TimerA2.Capture;
+  Msp430TimerA2.Timer -> Msp430TimerA.Timer;
+  Msp430TimerA2.Event -> Msp430TimerA.Event[2];
+
+  // Timer B
+  TimerB = Msp430TimerB.Timer;
+  Msp430TimerB.Overflow -> Msp430TimerB.Event[7];
+  Msp430TimerB.VectorTimerX0 -> Common.VectorTimerB0;
+  Msp430TimerB.VectorTimerX1 -> Common.VectorTimerB1;
+
+  // Timer B0
+  ControlB0 = Msp430TimerB0.Control;
+  CompareB0 = Msp430TimerB0.Compare;
+  CaptureB0 = Msp430TimerB0.Capture;
+  Msp430TimerB0.Timer -> Msp430TimerB.Timer;
+  Msp430TimerB0.Event -> Msp430TimerB.Event[0];
+
+  // Timer B1
+  ControlB1 = Msp430TimerB1.Control;
+  CompareB1 = Msp430TimerB1.Compare;
+  CaptureB1 = Msp430TimerB1.Capture;
+  Msp430TimerB1.Timer -> Msp430TimerB.Timer;
+  Msp430TimerB1.Event -> Msp430TimerB.Event[1];
+
+  // Timer B2
+  ControlB2 = Msp430TimerB2.Control;
+  CompareB2 = Msp430TimerB2.Compare;
+  CaptureB2 = Msp430TimerB2.Capture;
+  Msp430TimerB2.Timer -> Msp430TimerB.Timer;
+  Msp430TimerB2.Event -> Msp430TimerB.Event[2];
+
+  // Timer B3
+  ControlB3 = Msp430TimerB3.Control;
+  CompareB3 = Msp430TimerB3.Compare;
+  CaptureB3 = Msp430TimerB3.Capture;
+  Msp430TimerB3.Timer -> Msp430TimerB.Timer;
+  Msp430TimerB3.Event -> Msp430TimerB.Event[3];
+
+  // Timer B4
+  ControlB4 = Msp430TimerB4.Control;
+  CompareB4 = Msp430TimerB4.Compare;
+  CaptureB4 = Msp430TimerB4.Capture;
+  Msp430TimerB4.Timer -> Msp430TimerB.Timer;
+  Msp430TimerB4.Event -> Msp430TimerB.Event[4];
+
+  // Timer B5
+  ControlB5 = Msp430TimerB5.Control;
+  CompareB5 = Msp430TimerB5.Compare;
+  CaptureB5 = Msp430TimerB5.Capture;
+  Msp430TimerB5.Timer -> Msp430TimerB.Timer;
+  Msp430TimerB5.Event -> Msp430TimerB.Event[5];
+
+  // Timer B6
+  ControlB6 = Msp430TimerB6.Control;
+  CompareB6 = Msp430TimerB6.Compare;
+  CaptureB6 = Msp430TimerB6.Capture;
+  Msp430TimerB6.Timer -> Msp430TimerB.Timer;
+  Msp430TimerB6.Event -> Msp430TimerB.Event[6];
+  
+  components PlatformInterruptC;
+  Common.PlatformInterrupt -> PlatformInterruptC;
+}
+
diff --git a/tos/lib/tosthreads/chips/msp430/Msp430TimerCommonP.nc b/tos/lib/tosthreads/chips/msp430/Msp430TimerCommonP.nc
new file mode 100644 (file)
index 0000000..241861d
--- /dev/null
@@ -0,0 +1,29 @@
+
+module Msp430TimerCommonP
+{
+  provides interface Msp430TimerEvent as VectorTimerA0;
+  provides interface Msp430TimerEvent as VectorTimerA1;
+  provides interface Msp430TimerEvent as VectorTimerB0;
+  provides interface Msp430TimerEvent as VectorTimerB1;
+  uses interface PlatformInterrupt;
+}
+implementation
+{
+  TOSH_SIGNAL(TIMERA0_VECTOR) { 
+    signal VectorTimerA0.fired(); 
+    call PlatformInterrupt.postAmble();
+  }
+  TOSH_SIGNAL(TIMERA1_VECTOR) { 
+    signal VectorTimerA1.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  TOSH_SIGNAL(TIMERB0_VECTOR) { 
+    signal VectorTimerB0.fired();
+    call PlatformInterrupt.postAmble();
+  }
+  TOSH_SIGNAL(TIMERB1_VECTOR) { 
+    signal VectorTimerB1.fired();
+    call PlatformInterrupt.postAmble();
+  }
+}
+
diff --git a/tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcImplP.nc b/tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcImplP.nc
new file mode 100644 (file)
index 0000000..17040e5
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module BlockingAdcImplP {
+  provides {
+    interface Init;
+    interface BlockingRead<uint16_t> as BlockingRead[uint8_t client];
+    interface BlockingReadStream<uint16_t> as BlockingReadStream[uint8_t streamClient];
+  }
+  uses {
+    interface Read<uint16_t> as Read[uint8_t client];
+    interface ReadStream<uint16_t> as ReadStream[uint8_t streamClient];
+    
+    interface SystemCall;
+    interface SystemCallQueue;
+  }
+}
+implementation {
+
+  typedef struct read_params {
+    uint16_t* val;
+    error_t   error;
+  } read_params_t;
+
+  typedef struct readstream_params {
+    uint32_t* usPeriod;
+    uint16_t* buf;
+    uint16_t* count;
+    error_t   error;
+  } readstream_params_t;
+
+  syscall_queue_t read_queue;
+  syscall_queue_t readstream_queue;
+  
+  command error_t Init.init() {
+    call SystemCallQueue.init(&read_queue);
+    call SystemCallQueue.init(&readstream_queue);
+    return SUCCESS;
+  }
+  
+  /**************************** Read ********************************/
+  void readTask(syscall_t* s) {
+    read_params_t* p = s->params;
+    p->error = call Read.read[s->id]();
+    if(p->error != SUCCESS) {
+      call SystemCall.finish(s);
+    } 
+  }  
+  
+  command error_t BlockingRead.read[uint8_t id](uint16_t* val) {
+    syscall_t s;
+    read_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&read_queue, id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&read_queue, &s);
+    }
+    
+    p.val = val;
+    call SystemCall.start(&readTask, &s, id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&read_queue, &s);
+      return p.error;
+    }
+  }
+  
+  event void Read.readDone[uint8_t id]( error_t result, uint16_t val ) {
+    syscall_t* s = call SystemCallQueue.find(&read_queue, id);
+    read_params_t* p = s->params;
+    *(p->val) = val;
+    p->error = result;
+    call SystemCall.finish(s);  
+  }
+  
+  /**************************** ReadStream ********************************/
+  void readStreamTask(syscall_t* s) {
+    readstream_params_t* p = s->params;
+    p->error = call ReadStream.postBuffer[s->id](p->buf, *(p->count));
+    if(p->error == SUCCESS)
+      p->error = call ReadStream.read[s->id](*(p->usPeriod));
+    if(p->error != SUCCESS)
+      call SystemCall.finish(s);
+  }
+  
+  command error_t BlockingReadStream.read[uint8_t id](uint32_t* usPeriod, uint16_t* buf, uint16_t count) {
+    syscall_t s;
+    readstream_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&readstream_queue, id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&readstream_queue, &s);
+    }
+    
+    p.usPeriod = usPeriod;
+    p.buf = buf;
+    p.count = &count;
+    call SystemCall.start(&readTask, &s, id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&readstream_queue, &s);
+      return p.error;
+    }
+  }
+  
+  event void ReadStream.bufferDone[uint8_t id](error_t result, 
+                        uint16_t* buf, uint16_t count) {
+    //Should never get here!!!!!!
+  }
+                        
+  event void ReadStream.readDone[uint8_t id](error_t result, uint32_t usPeriod) {
+    syscall_t* s = call SystemCallQueue.find(&read_queue, id);
+    readstream_params_t* p = s->params;
+    *(p->usPeriod) = usPeriod;
+    p->error = result;
+    call SystemCall.finish(s);  
+  }
+}
diff --git a/tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcP.nc b/tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcP.nc
new file mode 100644 (file)
index 0000000..e88a996
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "thread.h"
+
+configuration BlockingAdcP {
+  provides {
+    interface BlockingRead<uint16_t> as BlockingRead[uint8_t client];
+    interface BlockingReadStream<uint16_t> as BlockingReadStream[uint8_t streamClient];
+  }
+  uses {
+    //For BlockingRead
+    interface AdcConfigure<const msp430adc12_channel_config_t*> as Config[uint8_t client];
+    interface Msp430Adc12SingleChannel as SingleChannel[uint8_t client];
+    interface Resource as ResourceRead[uint8_t client];
+    
+    //For BlockingReadStream
+    interface AdcConfigure<const msp430adc12_channel_config_t*> as ConfigReadStream[uint8_t streamClient];
+    interface Msp430Adc12SingleChannel as SingleChannelReadStream[uint8_t streamClient];
+    interface Resource as ResourceReadStream[uint8_t streamClient];
+  }
+}
+implementation {
+  components MainC;
+  components AdcP;
+  components WireAdcStreamP;
+  components BlockingAdcImplP;
+  
+  MainC.SoftwareInit -> BlockingAdcImplP;
+  
+  //For BlockingRead
+  BlockingRead = BlockingAdcImplP;
+  Config = AdcP.Config;
+  SingleChannel = AdcP.SingleChannel;
+  ResourceRead = AdcP.ResourceRead;
+  BlockingAdcImplP.Read -> AdcP.Read;
+  
+  //For BlockingReadStream
+  BlockingReadStream = BlockingAdcImplP;
+  ConfigReadStream = WireAdcStreamP;
+  SingleChannelReadStream = WireAdcStreamP;
+  ResourceReadStream = WireAdcStreamP;
+  BlockingAdcImplP.ReadStream -> WireAdcStreamP;
+  
+  components SystemCallC;
+  components SystemCallQueueC;
+  BlockingAdcImplP.SystemCallQueue -> SystemCallQueueC;
+  BlockingAdcImplP.SystemCall -> SystemCallC;
+}
+
+
diff --git a/tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcReadClientC.nc b/tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcReadClientC.nc
new file mode 100644 (file)
index 0000000..0a62fa4
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include <Msp430Adc12.h>
+generic configuration BlockingAdcReadClientC() {
+  provides interface BlockingRead<uint16_t>;
+  uses interface AdcConfigure<const msp430adc12_channel_config_t*>;
+} implementation {
+  components BlockingAdcP,
+#ifdef REF_VOLT_AUTO_CONFIGURE     
+             // if the client configuration requires a stable 
+             // reference voltage, the reference voltage generator 
+             // is automatically enabled
+             new Msp430Adc12ClientAutoRVGC() as Msp430AdcClient;
+#else
+             new Msp430Adc12ClientC() as Msp430AdcClient;
+#endif
+
+  enum {
+    CLIENT = unique(ADCC_SERVICE),
+  };
+
+  BlockingRead = BlockingAdcP.BlockingRead[CLIENT];
+  AdcConfigure = BlockingAdcP.Config[CLIENT];
+  BlockingAdcP.SingleChannel[CLIENT] -> Msp430AdcClient.Msp430Adc12SingleChannel;
+  BlockingAdcP.ResourceRead[CLIENT] -> Msp430AdcClient.Resource;
+#ifdef REF_VOLT_AUTO_CONFIGURE
+  AdcConfigure = Msp430AdcClient.AdcConfigure;
+#endif 
+}
+  
diff --git a/tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcReadStreamClientC.nc b/tos/lib/tosthreads/chips/msp430/adc12/BlockingAdcReadStreamClientC.nc
new file mode 100644 (file)
index 0000000..1db007b
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include <Msp430Adc12.h>
+generic configuration BlockingAdcReadStreamClientC() {
+  provides interface BlockingReadStream<uint16_t>;
+  uses interface AdcConfigure<const msp430adc12_channel_config_t*>;
+} implementation {
+  components BlockingAdcP,
+#ifdef REF_VOLT_AUTO_CONFIGURE     
+             // if the client configuration requires a stable 
+             // reference voltage, the reference voltage generator 
+             // is automatically enabled
+             new Msp430Adc12ClientAutoRVGC() as Msp430AdcPlient;
+#else
+             new Msp430Adc12ClientC() as Msp430AdcPlient;
+#endif
+
+  enum {
+    RSCLIENT = unique(ADCC_READ_STREAM_SERVICE),
+  };
+
+  BlockingReadStream = BlockingAdcP.BlockingReadStream[RSCLIENT];
+  AdcConfigure = BlockingAdcP.ConfigReadStream[RSCLIENT];
+  BlockingAdcP.SingleChannelReadStream[RSCLIENT] -> Msp430AdcPlient.Msp430Adc12SingleChannel;
+  BlockingAdcP.ResourceReadStream[RSCLIENT] -> Msp430AdcPlient.Resource;
+#ifdef REF_VOLT_AUTO_CONFIGURE
+  AdcConfigure = Msp430AdcPlient.AdcConfigure;
+#endif
+}
+  
diff --git a/tos/lib/tosthreads/chips/msp430/chip_thread.h b/tos/lib/tosthreads/chips/msp430/chip_thread.h
new file mode 100644 (file)
index 0000000..38d69a4
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * This file is derived from similar files in the TinyThread implementation
+ * by William P. McCartney from Cleveland State University (2006)
+ *
+ * This file contains MSP430 platform-specific routines for implementing
+ * threads in TinyOS
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+//Define on platform specific basis for inclusion in
+// the thread control block
+typedef struct thread_regs {
+  uint16_t status;
+  uint16_t r4;
+  uint16_t r5;
+  uint16_t r6;
+  uint16_t r7;
+  uint16_t r8;
+  uint16_t r9;
+  uint16_t r10;
+  uint16_t r11;
+  uint16_t r12;
+  uint16_t r13;
+  uint16_t r14;
+  uint16_t r15;
+} thread_regs_t;
+
+typedef uint16_t* stack_ptr_t;
+  
+#define STACK_TOP(stack, size)    \
+  (&(((uint8_t*)stack)[size - sizeof(stack_ptr_t)]))
+  
+//Save stack pointer
+#define SAVE_STACK_PTR(t)                                      \
+  __asm__("mov.w r1,%0" : "=m" ((t)->stack_ptr))
+
+//Save status register
+#define SAVE_STATUS(t)                                         \
+  __asm__("mov.w r2,%0" : "=r" ((t)->regs.status))
+
+//Save General Purpose Registers
+#define SAVE_GPR(t)                                            \
+  __asm__("mov.w r4,%0" : "=m" ((t)->regs.r4));        \
+  __asm__("mov.w r5,%0" : "=m" ((t)->regs.r5));        \
+  __asm__("mov.w r6,%0" : "=m" ((t)->regs.r6));        \
+  __asm__("mov.w r7,%0" : "=m" ((t)->regs.r7));        \
+  __asm__("mov.w r8,%0" : "=m" ((t)->regs.r8));        \
+  __asm__("mov.w r9,%0" : "=m" ((t)->regs.r9));        \
+  __asm__("mov.w r10,%0" : "=m" ((t)->regs.r10));      \
+  __asm__("mov.w r11,%0" : "=m" ((t)->regs.r11));      \
+  __asm__("mov.w r12,%0" : "=m" ((t)->regs.r12));      \
+  __asm__("mov.w r13,%0" : "=m" ((t)->regs.r13));      \
+  __asm__("mov.w r14,%0" : "=m" ((t)->regs.r14));      \
+  __asm__("mov.w r15,%0" : "=m" ((t)->regs.r15))
+  
+//Restore stack pointer
+#define RESTORE_STACK_PTR(t)                                           \
+  __asm__("mov.w %0,r1" : : "m" ((t)->stack_ptr))
+
+//Restore status register
+#define RESTORE_STATUS(t)                                      \
+  __asm__("mov.w %0,r2" : : "r" ((t)->regs.status))
+
+//Restore the general purpose registers
+#define RESTORE_GPR(t)                                         \
+  __asm__("mov.w %0,r4" : : "m" ((t)->regs.r4));       \
+  __asm__("mov.w %0,r5" : : "m" ((t)->regs.r5));       \
+  __asm__("mov.w %0,r6" : : "m" ((t)->regs.r6));       \
+  __asm__("mov.w %0,r7" : : "m" ((t)->regs.r7));       \
+  __asm__("mov.w %0,r8" : : "m" ((t)->regs.r8));       \
+  __asm__("mov.w %0,r9" : : "m" ((t)->regs.r9));       \
+  __asm__("mov.w %0,r10" : : "m" ((t)->regs.r10));     \
+  __asm__("mov.w %0,r11" : : "m" ((t)->regs.r11));     \
+  __asm__("mov.w %0,r12" : : "m" ((t)->regs.r12));     \
+  __asm__("mov.w %0,r13" : : "m" ((t)->regs.r13));     \
+  __asm__("mov.w %0,r14" : : "m" ((t)->regs.r14));     \
+  __asm__("mov.w %0,r15" : : "m" ((t)->regs.r15))
+  
+#define SAVE_TCB(t) \
+  SAVE_GPR(t);         \
+  SAVE_STATUS(t);      \
+  SAVE_STACK_PTR(t) 
+  
+#define RESTORE_TCB(t)  \
+  RESTORE_STACK_PTR(t); \
+  RESTORE_STATUS(t);    \
+  RESTORE_GPR(t)
+  
+#define SWITCH_CONTEXTS(from, to) \
+  SAVE_TCB(from);                                \
+  RESTORE_TCB(to)
+
+#define SWAP_STACK_PTR(OLD, NEW)                       \
+  __asm__("mov.w r1,%0" : "=m" (OLD));         \
+  __asm__("mov.w %0,r1" : : "m" (NEW))
+  
+#define PREPARE_THREAD(t, thread_ptr)          \
+  *((t)->stack_ptr) = (uint16_t)(&(thread_ptr));       \
+  SAVE_STATUS(t)
diff --git a/tos/lib/tosthreads/chips/pxa27x/HplPXA27xInterruptImplM.nc b/tos/lib/tosthreads/chips/pxa27x/HplPXA27xInterruptImplM.nc
new file mode 100644 (file)
index 0000000..1fa74c8
--- /dev/null
@@ -0,0 +1,237 @@
+// $Id$ \r
+\r
+/*                                                                     tab:4\r
+ *  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.  By\r
+ *  downloading, copying, installing or using the software you agree to\r
+ *  this license.  If you do not agree to this license, do not download,\r
+ *  install, copy or use the software.\r
+ *\r
+ *  Intel Open Source License \r
+ *\r
+ *  Copyright (c) 2002 Intel Corporation \r
+ *  All rights reserved. \r
+ *  Redistribution and use in source and binary forms, with or without\r
+ *  modification, are permitted provided that the following conditions are\r
+ *  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 the\r
+ *  documentation and/or other materials provided with the distribution.\r
+ *      Neither the name of the Intel Corporation nor the names of its\r
+ *  contributors may be used to endorse or promote products derived from\r
+ *  this software without specific prior written permission.\r
+ *  \r
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+ *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\r
+ *  PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE INTEL OR ITS\r
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
+ *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
+ *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * \r
+ * \r
+ */\r
+/*\r
+ *\r
+ * Authors:            Phil Buonadonna\r
+ *\r
+ * Edits:      Josh Herbach\r
+ * Revised: 09/02/2005\r
+ * \r
+ * Edits:   Kevin Klues\r
+ * Revised: 05/27/2008\r
+ */\r
+\r
+module HplPXA27xInterruptM\r
+{\r
+  provides {\r
+    interface HplPXA27xInterrupt as PXA27xIrq[uint8_t id];\r
+    interface HplPXA27xInterruptCntl;\r
+  }\r
+  uses interface PlatformInterrupt;\r
+}\r
+\r
+implementation \r
+{\r
+\r
+  uint32_t getICHP() {\r
+    uint32_t val;\r
+\r
+    asm volatile ("mrc p6,0,%0,c5,c0,0\n\t":"=r" (val));\r
+    return val;\r
+  }\r
+\r
+  /* Core PXA27X interrupt dispatch vectors */\r
+  /* DO NOT change the name of these functions */\r
+  void hplarmv_irq() __attribute__ ((interrupt ("IRQ"))) @C() @atomic_hwevent() {\r
+\r
+    uint32_t IRQPending;\r
+\r
+    IRQPending = getICHP();  // Determine which interrupt to service\r
+    IRQPending >>= 16;  // Right justify to the IRQ portion\r
+\r
+    while (IRQPending & (1 << 15)) {\r
+      uint8_t PeripheralID = (IRQPending & 0x3f); // Get rid of the Valid bit\r
+      signal PXA27xIrq.fired[PeripheralID]();     // Handler is responsible for clearing interrupt\r
+      call PlatformInterrupt.postAmble();\r
+      IRQPending = getICHP();  // Determine which interrupt to service\r
+      IRQPending >>= 16;  // Right justify to the IRQ portion\r
+    }\r
+\r
+    return;\r
+  }\r
+\r
+  void hplarmv_fiq() __attribute__ ((interrupt ("FIQ"))) @C() @atomic_hwevent() {\r
+      call PlatformInterrupt.postAmble();\r
+  } \r
+\r
+  static uint8_t usedPriorities = 0;\r
+\r
+  /* Helper functions */\r
+  /* NOTE: Read-back of all register writes is necessary to ensure the data latches */\r
+\r
+  error_t allocate(uint8_t id, bool level, uint8_t priority)\r
+  {\r
+    uint32_t tmp;\r
+    error_t error = FAIL;\r
+\r
+    atomic{\r
+      uint8_t i;\r
+      if(usedPriorities == 0){//assumed that the table will have some entries\r
+       uint8_t PriorityTable[40], DuplicateTable[40];\r
+       for(i = 0; i < 40; i++){\r
+         DuplicateTable[i] = PriorityTable[i] = 0xFF;\r
+       }\r
+       \r
+       for(i = 0; i < 40; i++)\r
+         if(TOSH_IRP_TABLE[i] != 0xff){\r
+           if(PriorityTable[TOSH_IRP_TABLE[i]] != 0xFF)/*duplicate priorities\r
+                                                         in the table, mark \r
+                                                         for later fixing*/\r
+             DuplicateTable[i] = PriorityTable[TOSH_IRP_TABLE[i]];\r
+           else\r
+             PriorityTable[TOSH_IRP_TABLE[i]] = i;\r
+         }\r
+       \r
+       //compress table\r
+       for(i = 0; i < 40; i++){\r
+         if(PriorityTable[i] != 0xff){\r
+           PriorityTable[usedPriorities] = PriorityTable[i];\r
+           if(i != usedPriorities)\r
+             PriorityTable[i] = 0xFF;\r
+           usedPriorities++;\r
+         }\r
+       }\r
+\r
+       for(i = 0; i < 40; i++)\r
+         if(DuplicateTable[i] != 0xFF){\r
+           uint8_t j, ExtraTable[40];\r
+           for(j = 0; DuplicateTable[i] != PriorityTable[j]; j++);\r
+           memcpy(ExtraTable + j + 1, PriorityTable + j, usedPriorities - j);\r
+           memcpy(PriorityTable + j + 1, ExtraTable + j + 1, \r
+                  usedPriorities - j);\r
+           PriorityTable[j] = i;\r
+           usedPriorities++;\r
+         }\r
+\r
+       for(i = 0; i < usedPriorities; i++){\r
+         IPR(i) = (IPR_VALID | PriorityTable[i]);\r
+         tmp = IPR(i);\r
+       }\r
+      }\r
+\r
+      if (id < 34){\r
+       if(priority == 0xff){\r
+         priority = usedPriorities;\r
+         usedPriorities++;\r
+         IPR(priority) = (IPR_VALID | (id));\r
+         tmp = IPR(priority);\r
+       }\r
+       if (level) {\r
+         _ICLR(id) |= _PPID_Bit(id);\r
+         tmp = _ICLR(id);\r
+       } \r
+       \r
+       error = SUCCESS;\r
+      }\r
+    }\r
+    return error;\r
+  }\r
+  \r
+  void enable(uint8_t id)\r
+  {\r
+    uint32_t tmp;\r
+    atomic {\r
+      if (id < 34) {\r
+       _ICMR(id) |= _PPID_Bit(id);\r
+       tmp = _ICMR(id);\r
+      }\r
+    }\r
+    return;\r
+  }\r
+\r
+  void disable(uint8_t id)\r
+  {\r
+    uint32_t tmp;\r
+    atomic {\r
+      if (id < 34) {\r
+       _ICMR(id) &= ~(_PPID_Bit(id));\r
+       tmp = _ICMR(id);\r
+      }\r
+    }\r
+    return;\r
+  }\r
+\r
+  /* Interface implementation */\r
+\r
+  async command error_t PXA27xIrq.allocate[uint8_t id]()\r
+  {\r
+    return allocate(id, FALSE, TOSH_IRP_TABLE[id]);\r
+  }\r
+\r
+  async command void PXA27xIrq.enable[uint8_t id]()\r
+  {\r
+    enable(id);\r
+    return;\r
+  }\r
+\r
+  async command void PXA27xIrq.disable[uint8_t id]()\r
+  {\r
+    disable(id);\r
+    return;\r
+  }\r
+\r
+  async command void HplPXA27xInterruptCntl.setICCR_DIM(bool flag) {\r
+\r
+    if (flag) {\r
+      ICCR |= ICCR_DIM;\r
+    }\r
+    else {\r
+      ICCR = 0;\r
+    }\r
+    return;\r
+\r
+  }\r
+\r
+  async command bool HplPXA27xInterruptCntl.getICCR_DIM() {\r
+    bool result = FALSE;\r
+\r
+    if (ICCR & ICCR_DIM) {\r
+      result = TRUE;\r
+    }\r
+\r
+    return result;\r
+  }\r
+\r
+  default async event void PXA27xIrq.fired[uint8_t id]() \r
+  {\r
+    return;\r
+  }\r
+\r
+}\r
diff --git a/tos/lib/tosthreads/chips/pxa27x/HplPXA27xInterruptM.nc b/tos/lib/tosthreads/chips/pxa27x/HplPXA27xInterruptM.nc
new file mode 100644 (file)
index 0000000..49dc6e9
--- /dev/null
@@ -0,0 +1,66 @@
+// $Id$ \r
+\r
+/*                                                                     tab:4\r
+ *  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.  By\r
+ *  downloading, copying, installing or using the software you agree to\r
+ *  this license.  If you do not agree to this license, do not download,\r
+ *  install, copy or use the software.\r
+ *\r
+ *  Intel Open Source License \r
+ *\r
+ *  Copyright (c) 2002 Intel Corporation \r
+ *  All rights reserved. \r
+ *  Redistribution and use in source and binary forms, with or without\r
+ *  modification, are permitted provided that the following conditions are\r
+ *  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 the\r
+ *  documentation and/or other materials provided with the distribution.\r
+ *      Neither the name of the Intel Corporation nor the names of its\r
+ *  contributors may be used to endorse or promote products derived from\r
+ *  this software without specific prior written permission.\r
+ *  \r
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+ *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\r
+ *  PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE INTEL OR ITS\r
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\r
+ *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
+ *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
+ *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ * \r
+ * \r
+ */\r
+/*\r
+ *\r
+ * Authors:            Phil Buonadonna\r
+ *\r
+ * Edits:      Josh Herbach\r
+ * Revised: 09/02/2005\r
+ *\r
+ * Edits:   Kevin Klues\r
+ * Revised: 05/27/2008\r
+ */\r
+\r
+configuration HplPXA27xInterruptM\r
+{\r
+  provides {\r
+    interface HplPXA27xInterrupt as PXA27xIrq[uint8_t id];\r
+    interface HplPXA27xInterruptCntl;\r
+  }\r
+}\r
+implementation {\r
+  components HplPXA27xInterruptImplM;\r
+  \r
+  PXA27xIrq = HplPXA27xInterruptImplM;\r
+  HplPXA27xInterruptCntl = HplPXA27xInterruptImplM;\r
+\r
+  components PlatformInterruptC;\r
+  HplInterruptP.PlatformInterrupt -> PlatformInterruptC;\r
+}
\ No newline at end of file
diff --git a/tos/lib/tosthreads/chips/pxa27x/chip_thread.h b/tos/lib/tosthreads/chips/pxa27x/chip_thread.h
new file mode 100644 (file)
index 0000000..d97b9ef
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * This file is derived from similar files in the TinyThread implementation
+ * by William P. McCartney from Cleveland State University (2006)
+ *
+ * This file contains MSP430 platform-specific routines for implementing
+ * threads in TinyOS
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+//Define on platform specific basis for inclusion in
+// the thread control block
+typedef struct thread_regs {
+} thread_regs_t;
+
+typedef uint16_t* stack_ptr_t;
+
+#define STACK_TOP(stack, size)    \
+  (&(((uint8_t*)stack)[size - sizeof(stack_ptr_t)]))
+
+//Save stack pointer
+#define SAVE_STACK_PTR(t)
+
+//Save status register
+#define SAVE_STATUS(t)
+
+//Save General Purpose Registers
+#define SAVE_GPR(t)
+
+//Restore stack pointer
+#define RESTORE_STACK_PTR(t)
+
+//Restore status register
+#define RESTORE_STATUS(t)
+
+//Restore the general purpose registers
+#define RESTORE_GPR(t)
+
+#define SAVE_TCB(t)
+
+#define RESTORE_TCB(t)
+
+#define SWITCH_CONTEXTS(from, to)
+
+#define SWAP_STACK_PTR(OLD, NEW)
+
+#define PREPARE_THREAD(t, thread_ptr)
diff --git a/tos/lib/tosthreads/csystem/CAMRadioC.nc b/tos/lib/tosthreads/csystem/CAMRadioC.nc
new file mode 100644 (file)
index 0000000..a066c05
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+#include "tosthread_amradio.h"
+
+configuration CAMRadioC {}
+
+implementation {
+  components CAMRadioP as CAMP;
+  components BlockingActiveMessageC as AM;
+  
+  CAMP.BlockingStdControl -> AM;
+  CAMP.BlockingReceive -> AM.BlockingReceive;
+  CAMP.BlockingSnoop -> AM.BlockingSnoop;
+  CAMP.BlockingReceiveAny -> AM.BlockingReceiveAny;
+  CAMP.BlockingSnoopAny -> AM.BlockingSnoopAny;
+  CAMP.Send -> AM;
+  CAMP.Packet -> AM;
+  CAMP.AMPacket -> AM;
+  CAMP.PacketAcknowledgements -> AM;
+}
diff --git a/tos/lib/tosthreads/csystem/CAMRadioP.nc b/tos/lib/tosthreads/csystem/CAMRadioP.nc
new file mode 100644 (file)
index 0000000..2dc7d63
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+module CAMRadioP {
+  uses {
+    interface BlockingStdControl;
+    interface BlockingReceive[am_id_t amId];
+    interface BlockingReceive as BlockingReceiveAny;
+    interface BlockingReceive as BlockingSnoop[am_id_t amId];
+    interface BlockingReceive as BlockingSnoopAny;
+    interface BlockingAMSend as Send[am_id_t id];
+    interface Packet;
+    interface AMPacket;
+    interface PacketAcknowledgements;
+  }
+}
+implementation {
+  error_t amRadioStart() @C() @spontaneous() { 
+    return call BlockingStdControl.start();
+  }
+  error_t amRadioStop() @C() @spontaneous() { 
+    return call BlockingStdControl.stop();
+  }
+  error_t amRadioReceive(message_t* m, uint32_t timeout, am_id_t amId) @C() @spontaneous() {
+    if(amId == AM_RECEIVE_FROM_ANY)
+      return call BlockingReceiveAny.receive(m, timeout);
+    else 
+      return call BlockingReceive.receive[amId](m, timeout);
+  }
+  error_t amRadioSnoop(message_t* m, uint32_t timeout, am_id_t amId) @C() @spontaneous() {
+    if(amId == AM_RECEIVE_FROM_ANY)
+      return call BlockingSnoopAny.receive(m, timeout);
+    else 
+      return call BlockingSnoop.receive[amId](m, timeout);
+  }
+  error_t amRadioSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId) @C() @spontaneous() {
+    return call Send.send[amId](addr, msg, len);
+  }
+  am_addr_t amRadioGetLocalAddress() @C() @spontaneous() {
+    return call AMPacket.address();
+  }
+  am_group_t amRadioGetLocalGroup() @C() @spontaneous() {
+    return call AMPacket.localGroup();
+  }
+  am_addr_t amRadioGetDestination(message_t* amsg) @C() @spontaneous() {
+    return call AMPacket.destination(amsg);
+  }
+  am_addr_t amRadioGetSource(message_t* amsg) @C() @spontaneous() {
+    return call AMPacket.source(amsg);
+  }
+  void amRadioSetDestination(message_t* amsg, am_addr_t addr) @C() @spontaneous() {
+    call AMPacket.setDestination(amsg, addr);
+  }
+  void amRadioSetSource(message_t* amsg, am_addr_t addr) @C() @spontaneous() {
+    return call AMPacket.setSource(amsg, addr);
+  }
+  bool amRadioIsForMe(message_t* amsg) @C() @spontaneous() {
+    return call AMPacket.isForMe(amsg);
+  }
+  am_id_t amRadioGetType(message_t* amsg) @C() @spontaneous() {
+    return call AMPacket.type(amsg);
+  }
+  void amRadioSetType(message_t* amsg, am_id_t t) @C() @spontaneous() {
+    call AMPacket.setType(amsg, t);
+  }
+  am_group_t amRadioGetGroup(message_t* amsg) @C() @spontaneous() {
+    return call AMPacket.group(amsg);
+  }
+  void amRadioSetGroup(message_t* amsg, am_group_t grp) @C() @spontaneous() {
+    return call AMPacket.setGroup(amsg, grp);
+  }
+  void radioClear(message_t* msg) @C() @spontaneous() {
+    call Packet.clear(msg);
+  }
+  uint8_t radioGetPayloadLength(message_t* msg) @C() @spontaneous() {
+    return call Packet.payloadLength(msg);
+  }
+  void  radioSetPayloadLength(message_t* msg, uint8_t len) @C() @spontaneous() {
+    call Packet.setPayloadLength(msg, len);
+  }
+  uint8_t radioMaxPayloadLength() @C() @spontaneous() {
+    return call Packet.maxPayloadLength();
+  }
+  void* radioGetPayload(message_t* msg, uint8_t len) @C() @spontaneous() {
+    return call Packet.getPayload(msg, len);
+  }
+  error_t radioRequestAck( message_t* msg ) @C() @spontaneous() {
+    return call PacketAcknowledgements.requestAck(msg);
+  }
+  error_t radioNoAck( message_t* msg ) @C() @spontaneous() {
+    return call PacketAcknowledgements.noAck(msg);
+  }
+  bool radioWasAcked(message_t* msg) @C() @spontaneous() {
+    return call PacketAcknowledgements.wasAcked(msg);
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/CAMSerialC.nc b/tos/lib/tosthreads/csystem/CAMSerialC.nc
new file mode 100644 (file)
index 0000000..ac776aa
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+#include "tosthread_amserial.h"
+
+configuration CAMSerialC {}
+
+implementation {
+  components CAMSerialP as CAMP;
+  components BlockingSerialActiveMessageC as AM;
+  
+  CAMP.BlockingStdControl -> AM;
+  CAMP.BlockingReceive -> AM.BlockingReceive;
+  CAMP.BlockingReceiveAny -> AM.BlockingReceiveAny;
+  CAMP.Send -> AM;
+  CAMP.Packet -> AM;
+  CAMP.AMPacket -> AM;
+  CAMP.PacketAcknowledgements -> AM;
+}
diff --git a/tos/lib/tosthreads/csystem/CAMSerialP.nc b/tos/lib/tosthreads/csystem/CAMSerialP.nc
new file mode 100644 (file)
index 0000000..fea5963
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+module CAMSerialP {
+  uses {
+    interface BlockingStdControl;
+    interface BlockingReceive[am_id_t amId];
+    interface BlockingReceive as BlockingReceiveAny;
+    interface BlockingAMSend as Send[am_id_t id];
+    interface Packet;
+    interface AMPacket;
+    interface PacketAcknowledgements;
+  }
+}
+implementation {
+  error_t amSerialStart() @C() @spontaneous() { 
+    return call BlockingStdControl.start();
+  }
+  error_t amSerialStop() @C() @spontaneous() { 
+    return call BlockingStdControl.stop();
+  }
+  error_t amSerialReceive(message_t* m, uint32_t timeout, am_id_t amId) @C() @spontaneous() {
+    if(amId == AM_RECEIVE_FROM_ANY)
+      return call BlockingReceiveAny.receive(m, timeout);
+    else 
+      return call BlockingReceive.receive[amId](m, timeout);
+  }
+  error_t amSerialSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId) @C() @spontaneous() {
+    return call Send.send[amId](addr, msg, len);
+  }
+  am_addr_t amSerialLocalAddress() @C() @spontaneous() {
+    return call AMPacket.address();
+  }
+  am_group_t amSerialGetLocalGroup() @C() @spontaneous() {
+    return call AMPacket.localGroup();
+  }
+  am_addr_t amSerialGetDestination(message_t* amsg) @C() @spontaneous() {
+    return call AMPacket.destination(amsg);
+  }
+  am_addr_t amSerialGetSource(message_t* amsg) @C() @spontaneous() {
+    return call AMPacket.source(amsg);
+  }
+  void amSerialSetDestination(message_t* amsg, am_addr_t addr) @C() @spontaneous() {
+    call AMPacket.setDestination(amsg, addr);
+  }
+  void amSerialSetSource(message_t* amsg, am_addr_t addr) @C() @spontaneous() {
+    return call AMPacket.setSource(amsg, addr);
+  }
+  bool amSerialIsForMe(message_t* amsg) @C() @spontaneous() {
+    return call AMPacket.isForMe(amsg);
+  }
+  am_id_t amSerialGetType(message_t* amsg) @C() @spontaneous() {
+    return call AMPacket.type(amsg);
+  }
+  void amSerialSetType(message_t* amsg, am_id_t t) @C() @spontaneous() {
+    call AMPacket.setType(amsg, t);
+  }
+  am_group_t amSerialGetGroup(message_t* amsg) @C() @spontaneous() {
+    return call AMPacket.group(amsg);
+  }
+  void amSerialSetGroup(message_t* amsg, am_group_t grp) @C() @spontaneous() {
+    return call AMPacket.setGroup(amsg, grp);
+  }
+  void serialClear(message_t* msg) @C() @spontaneous() {
+    call Packet.clear(msg);
+  }
+  uint8_t serialGetPayloadLength(message_t* msg) @C() @spontaneous() {
+    return call Packet.payloadLength(msg);
+  }
+  void  serialSetPayloadLength(message_t* msg, uint8_t len) @C() @spontaneous() {
+    call Packet.setPayloadLength(msg, len);
+  }
+  uint8_t serialMaxPayloadLength() @C() @spontaneous() {
+    return call Packet.maxPayloadLength();
+  }
+  void* serialGetPayload(message_t* msg, uint8_t len) @C() @spontaneous() {
+    return call Packet.getPayload(msg, len);
+  }
+  error_t serialRequestAck( message_t* msg ) @C() @spontaneous() {
+    return call PacketAcknowledgements.requestAck(msg);
+  }
+  error_t serialNoAck( message_t* msg ) @C() @spontaneous() {
+    return call PacketAcknowledgements.noAck(msg);
+  }
+  bool serialWasAcked(message_t* msg) @C() @spontaneous() {
+    return call PacketAcknowledgements.wasAcked(msg);
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/CBlockStorageC.nc b/tos/lib/tosthreads/csystem/CBlockStorageC.nc
new file mode 100644 (file)
index 0000000..15ad930
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+configuration CBlockStorageC {}
+
+implementation {
+  components CBlockStorageP,
+             BlockingBlockStorageP,
+             VolumeMapC;
+             
+  CBlockStorageP.BlockingBlock -> BlockingBlockStorageP;
+  
+  BlockingBlockStorageP.BlockRead -> VolumeMapC;
+  BlockingBlockStorageP.BlockWrite -> VolumeMapC;
+}
diff --git a/tos/lib/tosthreads/csystem/CBlockStorageP.nc b/tos/lib/tosthreads/csystem/CBlockStorageP.nc
new file mode 100644 (file)
index 0000000..82817dc
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+module CBlockStorageP {
+  uses {
+    interface BlockingBlock[uint8_t volume_id];
+  }
+}
+
+implementation {
+  error_t volumeBlockRead(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() @spontaneous()
+  {
+    return call BlockingBlock.read[volumeId](addr, buf, len);
+  }
+  
+  error_t volumeBlockWrite(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len)  @C() @spontaneous()
+  {
+    return call BlockingBlock.write[volumeId](addr, buf, len);
+  }
+  
+  error_t volumeBlockCrc(uint8_t volumeId, storage_addr_t addr, storage_len_t* len, uint16_t crc, uint16_t *finalCrc) @C() @spontaneous()
+  {
+    return call BlockingBlock.computeCrc[volumeId](addr, len, crc, finalCrc);
+  }
+  
+  error_t volumeBlockErase(uint8_t volumeId) @C() @spontaneous()
+  {
+    return call BlockingBlock.erase[volumeId]();
+  }
+  
+  error_t volumeBlockSync(uint8_t volumeId) @C() @spontaneous()
+  {
+    return call BlockingBlock.sync[volumeId]();
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/CLedsC.nc b/tos/lib/tosthreads/csystem/CLedsC.nc
new file mode 100644 (file)
index 0000000..3ec7bac
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+configuration CLedsC {}
+implementation {
+  components LedsC;
+  components CLedsP;
+  
+  CLedsP.Leds -> LedsC;
+}
+
diff --git a/tos/lib/tosthreads/csystem/CLedsP.nc b/tos/lib/tosthreads/csystem/CLedsP.nc
new file mode 100644 (file)
index 0000000..cf1944e
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+module CLedsP {
+  uses {
+    interface Leds;
+  }
+}
+implementation {
+  void led0On() @C() @spontaneous(){
+    call Leds.led0On();
+  }
+  void led0Off() @C() @spontaneous(){
+    call Leds.led0Off();
+  }
+  void led0Toggle() @C() @spontaneous(){
+    call Leds.led0Toggle();
+  }
+
+  void led1On() @C() @spontaneous(){
+    call Leds.led1On();
+  }
+  void led1Off() @C() @spontaneous(){
+    call Leds.led1Off();
+  }
+  void led1Toggle() @C() @spontaneous(){
+    call Leds.led1Toggle();
+  }
+  
+  void led2On() @C() @spontaneous(){
+    call Leds.led2On();
+  }
+  void led2Off() @C() @spontaneous(){
+    call Leds.led2Off();
+  }
+  void led2Toggle() @C() @spontaneous(){
+    call Leds.led2Toggle();
+  }
+
+  uint8_t getLeds() @C() @spontaneous(){
+    return call Leds.get();
+  }
+  void setLeds(uint8_t val) @C() @spontaneous(){
+    call Leds.set(val);
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/CLinkedListC.nc b/tos/lib/tosthreads/csystem/CLinkedListC.nc
new file mode 100644 (file)
index 0000000..994e89b
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+#include "tosthread_linked_list.h"
+
+configuration CLinkedListC {}
+implementation {
+  components LinkedListC;
+  components CLinkedListP;
+  
+  CLinkedListP.LinkedList -> LinkedListC;
+}
+
diff --git a/tos/lib/tosthreads/csystem/CLinkedListP.nc b/tos/lib/tosthreads/csystem/CLinkedListP.nc
new file mode 100644 (file)
index 0000000..33d1cf7
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module CLinkedListP { 
+  uses interface LinkedList;
+}
+implementation { 
+  void linked_list_init(linked_list_t* l) @C() @spontaneous() {  
+    call LinkedList.init(l);
+  }
+  void linked_list_clear(linked_list_t* l) @C() @spontaneous() { 
+    call LinkedList.clear(l);
+  }
+  uint8_t linked_list_size(linked_list_t* l) @C() @spontaneous() { 
+    return call LinkedList.size(l);
+  }
+  error_t linked_list_addFirst(linked_list_t* l, list_element_t* e) @C() @spontaneous() { 
+    return call LinkedList.addFirst(l, e);
+  }
+  list_element_t* linked_list_getFirst(linked_list_t* l) @C() @spontaneous() { 
+    return call LinkedList.getFirst(l);
+  }
+  list_element_t* linked_list_removeFirst(linked_list_t* l) @C() @spontaneous() { 
+    return call LinkedList.removeFirst(l);
+  }
+  error_t linked_list_addLast(linked_list_t* l, list_element_t* e) @C() @spontaneous() { 
+    return call LinkedList.addLast(l, e);
+  }
+  list_element_t* linked_list_getLast(linked_list_t* l) @C() @spontaneous() { 
+    return call LinkedList.getLast(l);
+  }
+  list_element_t* linked_list_removeLast(linked_list_t* l) @C() @spontaneous() { 
+    return call LinkedList.removeLast(l);
+  }
+  error_t linked_list_addAt(linked_list_t* l, list_element_t* e, uint8_t i) @C() @spontaneous() { 
+    return call LinkedList.addAt(l, e, i);
+  }
+  list_element_t* linked_list_getAt(linked_list_t* l, uint8_t i) @C() @spontaneous() { 
+    return call LinkedList.getAt(l, i);
+  }
+  list_element_t* linked_list_removeAt(linked_list_t* l, uint8_t i) @C() @spontaneous() { 
+    return call LinkedList.removeAt(l, i);
+  }  
+  error_t linked_list_addAfter(linked_list_t* l, list_element_t* first, list_element_t* second) @C() @spontaneous() { 
+    return call LinkedList.addAfter(l, first, second);
+  }
+  error_t linked_list_addBefore(linked_list_t* l, list_element_t* first, list_element_t* e) @C() @spontaneous() { 
+    return call LinkedList.addBefore(l, first, e);
+  }
+  list_element_t* linked_list_getAfter(linked_list_t* l, list_element_t* e) @C() @spontaneous() { 
+    return call LinkedList.getAfter(l, e);
+  }  
+  list_element_t* linked_list_getBefore(linked_list_t* l, list_element_t* e) @C() @spontaneous() { 
+    return call LinkedList.getBefore(l, e);
+  }
+  list_element_t* linked_list_remove(linked_list_t* l, list_element_t* e) @C() @spontaneous() { 
+    return call LinkedList.remove(l, e);
+  }  
+  list_element_t* linked_list_removeBefore(linked_list_t* l, list_element_t* e) @C() @spontaneous() { 
+    return call LinkedList.removeBefore(l, e);
+  }  
+  list_element_t* linked_list_removeAfter(linked_list_t* l, list_element_t* e) @C() @spontaneous() { 
+    return call LinkedList.removeAfter(l, e);
+  }  
+  uint8_t linked_list_indexOf(linked_list_t* l, list_element_t* e) @C() @spontaneous() { 
+    return call LinkedList.indexOf(l, e);
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/CLogStorageC.nc b/tos/lib/tosthreads/csystem/CLogStorageC.nc
new file mode 100644 (file)
index 0000000..ea23a54
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+configuration CLogStorageC {}
+
+implementation {
+  components CLogStorageP,
+             BlockingLogStorageP,
+             VolumeMapC;
+             
+  CLogStorageP.BlockingLog -> BlockingLogStorageP;
+  
+  BlockingLogStorageP.LogRead -> VolumeMapC;
+  BlockingLogStorageP.LogWrite -> VolumeMapC;
+}
diff --git a/tos/lib/tosthreads/csystem/CLogStorageP.nc b/tos/lib/tosthreads/csystem/CLogStorageP.nc
new file mode 100644 (file)
index 0000000..04f0db5
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module CLogStorageP {
+  uses {
+    interface BlockingLog[uint8_t volume_id];
+  }
+}
+implementation {
+  error_t volumeLogRead(uint8_t volumeId, void *buf, storage_len_t *len) @C() @spontaneous() {
+    return call BlockingLog.read[volumeId](buf, len);
+  }
+  storage_cookie_t volumeLogCurrentReadOffset(uint8_t volumeId) @C() @spontaneous() {
+    return call BlockingLog.currentReadOffset[volumeId]();
+  }
+  error_t volumeLogSeek(uint8_t volumeId, storage_cookie_t offset) @C() @spontaneous() {
+    return call BlockingLog.seek[volumeId](offset);
+  }
+  storage_len_t volumeLogGetSize(uint8_t volumeId) @C() @spontaneous() {
+    return call BlockingLog.getSize[volumeId]();
+  }  
+  error_t volumeLogAppend(uint8_t volumeId, void* buf, storage_len_t *len, bool *recordsLost) @C() @spontaneous() {
+    return call BlockingLog.append[volumeId](buf, len, recordsLost);
+  }
+  storage_cookie_t volumeLogCurrentWriteOffset(uint8_t volumeId) @C() @spontaneous() {
+    return call BlockingLog.currentWriteOffset[volumeId]();
+  }
+  error_t volumeLogErase(uint8_t volumeId) @C() @spontaneous() {
+    return call BlockingLog.erase[volumeId]();
+  }
+  error_t volumeLogSync(uint8_t volumeId) @C() @spontaneous() {
+    return call BlockingLog.sync[volumeId]();
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/CQueueC.nc b/tos/lib/tosthreads/csystem/CQueueC.nc
new file mode 100644 (file)
index 0000000..267c1c6
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "tosthread_linked_list.h"
+#include "tosthread_queue.h"
+
+module CQueueC {}
+implementation { 
+  void queue_init(queue_t* q) @C() @spontaneous() {  
+    linked_list_init( &(q->l) );
+  }
+  void queue_clear(queue_t* q) @C() @spontaneous() { 
+    linked_list_clear( &(q->l) );
+  }
+  error_t queue_enqueue(queue_t* q, queue_element_t* e) @C() @spontaneous() { 
+    return linked_list_addLast(&(q->l), (list_element_t*)e);
+  }
+  queue_element_t* queue_dequeue(queue_t* q) @C() @spontaneous() { 
+    return (queue_element_t*)linked_list_removeFirst( &(q->l) );
+  }
+  queue_element_t* queue_remove(queue_t* q, queue_element_t* e) @C() @spontaneous() { 
+    return (queue_element_t*)linked_list_remove(&(q->l), (list_element_t*)e);
+  }
+  uint8_t queue_size(queue_t* q) @C() @spontaneous() { 
+    return linked_list_size( &(q->l) );
+  }
+  bool queue_is_empty(queue_t* q) @C() @spontaneous() { 
+    return (linked_list_size( &(q->l) ) == 0);
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/CThreadC.nc b/tos/lib/tosthreads/csystem/CThreadC.nc
new file mode 100644 (file)
index 0000000..7858fcc
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+configuration CThreadC {}
+implementation {
+  components DynamicThreadC;
+  components CThreadP;
+    
+  CThreadP.DynamicThread -> DynamicThreadC;
+}
+
diff --git a/tos/lib/tosthreads/csystem/CThreadP.nc b/tos/lib/tosthreads/csystem/CThreadP.nc
new file mode 100644 (file)
index 0000000..52f1601
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+#include "thread.h"
+
+module CThreadP {
+  uses {
+    interface DynamicThread;
+  }
+}
+implementation {
+
+  error_t tosthread_create(tosthread_t* t, void (*start_routine)(void*), void* arg, uint16_t stack_size) @C() @spontaneous() {
+    return call DynamicThread.create(t, start_routine, arg, stack_size);
+  }
+  error_t tosthread_destroy(tosthread_t* t) @C() @spontaneous() {
+    return call DynamicThread.destroy(t);
+  }
+  error_t tosthread_pause(tosthread_t* t) @C() @spontaneous() {
+    return call DynamicThread.pause(t);
+  }
+  error_t tosthread_resume(tosthread_t* t) @C() @spontaneous() {
+    return call DynamicThread.resume(t);
+  }
+  error_t tosthread_sleep(uint32_t milli) @C() @spontaneous() {
+    return call DynamicThread.sleep(milli);
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/CThreadSynchronizationC.nc b/tos/lib/tosthreads/csystem/CThreadSynchronizationC.nc
new file mode 100644 (file)
index 0000000..78e6e09
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "tosthread_threadsync.h"
+
+configuration CThreadSynchronizationC {}
+implementation {
+  components ThreadSynchronizationC;
+  components CThreadSynchronizationP;
+  
+  CThreadSynchronizationP.Mutex -> ThreadSynchronizationC;
+  CThreadSynchronizationP.Semaphore -> ThreadSynchronizationC;
+  CThreadSynchronizationP.Barrier -> ThreadSynchronizationC;
+  CThreadSynchronizationP.ConditionVariable -> ThreadSynchronizationC;
+  CThreadSynchronizationP.ReferenceCounter -> ThreadSynchronizationC;
+}
diff --git a/tos/lib/tosthreads/csystem/CThreadSynchronizationP.nc b/tos/lib/tosthreads/csystem/CThreadSynchronizationP.nc
new file mode 100644 (file)
index 0000000..952c48d
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module CThreadSynchronizationP {
+  uses {
+    interface Mutex;
+    interface Semaphore;
+    interface Barrier;
+    interface ConditionVariable;
+    interface ReferenceCounter;
+  }
+}
+implementation {
+  /******************** Mutex ***************************/
+  void mutex_init(mutex_t* m) @C() @spontaneous() {
+    call Mutex.init(m);
+  }
+  error_t mutex_lock(mutex_t* m) @C() @spontaneous() {
+    return call Mutex.lock(m);
+  }
+  error_t mutex_unlock(mutex_t* m) @C() @spontaneous() {
+    return call Mutex.unlock(m);
+  }
+  
+  /******************** Semaphore ***************************/
+  void semaphore_reset(semaphore_t* s, uint8_t v) @C() @spontaneous() {
+    call Semaphore.reset(s, v);
+  }
+  error_t semaphore_acquire(semaphore_t* s) @C() @spontaneous() {
+    return call Semaphore.acquire(s);
+  }
+  error_t semaphore_release(semaphore_t* s) @C() @spontaneous() {
+    return call Semaphore.release(s);
+  }
+  
+  /******************** Barrier ***************************/
+  void barrier_reset(barrier_t* b, uint8_t count) @C() @spontaneous() {
+    call Barrier.reset(b, count);
+  }
+  void barrier_block(barrier_t* b) @C() @spontaneous() {
+    call Barrier.block(b);
+  }
+  bool barrier_isBlocking(barrier_t* b) @C() @spontaneous() {
+    return call Barrier.isBlocking(b);
+  }
+  void condvar_init(condvar_t* c) @C() @spontaneous() {
+    call ConditionVariable.init(c);
+  }
+  
+  /******************** Condition Variable ***************************/
+  void condvar_wait(condvar_t* c, mutex_t* m) @C() @spontaneous() {
+    call ConditionVariable.wait(c, m);
+  }
+  void condvar_signalNext(condvar_t* c) @C() @spontaneous() {
+    call ConditionVariable.signalNext(c);
+  }
+  void condvar_signalAll(condvar_t* c) @C() @spontaneous() {
+    call ConditionVariable.signalAll(c);
+  }
+  bool condvar_isBlocking(condvar_t* c) @C() @spontaneous() {
+    return call ConditionVariable.isBlocking(c);
+  }
+  
+  /******************** Reference Counter ***************************/
+  void refcounter_init(refcounter_t* r) @C() @spontaneous() {
+    call ReferenceCounter.init(r);
+  }
+  void refcounter_increment(refcounter_t* r) @C() @spontaneous() {
+    call ReferenceCounter.increment(r);
+  }
+  void refcounter_decrement(refcounter_t* r) @C() @spontaneous() {
+    call ReferenceCounter.decrement(r);
+  }
+  void refcounter_waitOnValue(refcounter_t* r, uint8_t count) @C() @spontaneous() {
+    call ReferenceCounter.waitOnValue(r, count);
+  }
+  uint8_t refcounter_count(refcounter_t* r) @C() @spontaneous() {
+    return call ReferenceCounter.count(r);
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/TinyOSEntryPointC.nc b/tos/lib/tosthreads/csystem/TinyOSEntryPointC.nc
new file mode 100644 (file)
index 0000000..d55f5a6
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "tosthread.h"
+
+configuration TinyOSEntryPointC {
+}
+implementation {
+  components MainC;
+
+  components TinyOSEntryPointP;
+  MainC.Boot <- TinyOSEntryPointP;
+  
+#ifdef TOSTHREAD_TENET
+  components TosThreadTenetApiC;
+#else
+  components TosThreadApiC;
+#endif
+}
diff --git a/tos/lib/tosthreads/csystem/TinyOSEntryPointP.nc b/tos/lib/tosthreads/csystem/TinyOSEntryPointP.nc
new file mode 100644 (file)
index 0000000..0ec46ca
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+/**
+ *  The Makefile for your top level application must contain a line of the form:
+ *  TOSTHREAD_MAIN=Blink.c
+ *  in order to compile correctly.  
+ *  
+ *  This simply issues an error at compile time if TOSTHREAD_MAIN has not been defined
+ *  appropriately.
+ */
+#ifndef MAIN_APP
+#error "You must define the TOSTHREAD_MAIN constant in your Makefile to correctly point to your top level c file in order to compile..... Spelling Error?"
+#else 
+#include MAIN_APP
+#endif
+
+module TinyOSEntryPointP {
+  uses {
+    interface Boot;
+  }
+}
+implementation {
+  tosthread_t thread;
+
+  event void Boot.booted() {
+    tosthread_create(&thread, tosthread_main, NULL, TOSTHREAD_MAIN_STACK_SIZE);
+  }
+}
diff --git a/tos/lib/tosthreads/csystem/TosThreadApiC.nc b/tos/lib/tosthreads/csystem/TosThreadApiC.nc
new file mode 100644 (file)
index 0000000..394c636
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "tosthread.h"
+
+configuration TosThreadApiC {
+}
+implementation {
+  //Here are all the components that implement the Tosthread API calls
+  components CThreadC;
+  #if defined(PRINTF_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components PrintfC;
+  #endif
+  #if defined(TOSTHREAD_QUEUE_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CQueueC;
+  #endif
+  #if defined(TOSTHREAD_LINKED_LIST_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CLinkedListC;
+  #endif
+  #if defined(TOSTHREAD_THREADSYNC_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CThreadSynchronizationC;
+  #endif
+  #if defined(TOSTHREAD_LEDS_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CLedsC;
+  #endif
+  #if defined(TOSTHREAD_AMRADIO_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CAMRadioC;
+  #endif
+  #if defined(TOSTHREAD_AMSERIAL_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CAMSerialC;
+  #endif
+  #if defined(TOSTHREAD_BLOCKSTORAGE_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CBlockStorageC;
+  #endif 
+  #if defined(TOSTHREAD_LOGSTORAGE_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CLogStorageC;
+  #endif 
+  
+  //Telosb sensorbard specific.  Later need to find conditional way of adding this in
+  #if defined(TOSTHREAD_HAMAMATSUS1087_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CHamamatsuS1087ParC;
+  #endif
+  #if defined(TOSTHREAD_HAMAMATSUS10871_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CHamamatsuS10871TsrC;
+  #endif
+  #if defined(TOSTHREAD_SENSIRIONSHT11_H) || defined(TOSTHREAD_DYNAMIC_LOADER)
+    components CSensirionSht11C;
+  #endif
+}
diff --git a/tos/lib/tosthreads/csystem/VolumeMapC.nc b/tos/lib/tosthreads/csystem/VolumeMapC.nc
new file mode 100644 (file)
index 0000000..2821a08
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+configuration VolumeMapC { 
+  provides { 
+    interface BlockRead[uint8_t volume_id]; 
+    interface BlockWrite[uint8_t volume_id];
+    interface LogRead[uint8_t volume_id];
+    interface LogWrite[uint8_t volume_id];
+  }
+} 
+
+implementation { 
+  components VolumeMapP;
+  
+  BlockRead = VolumeMapP; 
+  BlockWrite = VolumeMapP;
+  LogRead = VolumeMapP;
+  LogWrite = VolumeMapP;
+} 
diff --git a/tos/lib/tosthreads/csystem/VolumeMapP.nc b/tos/lib/tosthreads/csystem/VolumeMapP.nc
new file mode 100644 (file)
index 0000000..5c810dd
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+module VolumeMapP {
+  provides { 
+    interface BlockRead[uint8_t volume_id]; 
+    interface BlockWrite[uint8_t volume_id];
+    interface LogRead[uint8_t volume_id];
+    interface LogWrite[uint8_t volume_id];
+  }
+  
+  uses { 
+    interface BlockRead as SubBlockRead[uint8_t volume_id]; 
+    interface BlockWrite as SubBlockWrite[uint8_t volume_id]; 
+    interface LogRead as SubLogRead[uint8_t volume_id];
+    interface LogWrite as SubLogWrite[uint8_t volume_id];
+  }
+}
+
+implementation {
+  command error_t BlockRead.read[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) {
+    return call SubBlockRead.read[volume_id](addr, buf, len);
+  }
+
+  event void SubBlockRead.readDone[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {
+    signal BlockRead.readDone[volume_id](addr, buf, len, error);
+  }
+
+  command error_t BlockRead.computeCrc[uint8_t volume_id](storage_addr_t addr, storage_len_t len, uint16_t crc) {
+    return call SubBlockRead.computeCrc[volume_id](addr, len, crc);
+  }
+
+  event void SubBlockRead.computeCrcDone[uint8_t volume_id](storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error) {
+    signal BlockRead.computeCrcDone[volume_id](addr, len, crc, error);
+  }
+
+  command storage_len_t BlockRead.getSize[uint8_t volume_id]() {
+    return call SubBlockRead.getSize[volume_id]();
+  }
+  
+  command error_t BlockWrite.write[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) {
+    return call SubBlockWrite.write[volume_id](addr, buf, len);
+  }
+
+  event void SubBlockWrite.writeDone[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {
+    signal BlockWrite.writeDone[volume_id](addr, buf, len, error);
+  }
+
+  command error_t BlockWrite.erase[uint8_t volume_id]() {
+    return call SubBlockWrite.erase[volume_id]();
+  }
+
+  event void SubBlockWrite.eraseDone[uint8_t volume_id](error_t error) {
+    signal BlockWrite.eraseDone[volume_id](error);
+  }
+
+  command error_t BlockWrite.sync[uint8_t volume_id]() {
+    return call SubBlockWrite.sync[volume_id]();
+  }
+
+  event void SubBlockWrite.syncDone[uint8_t volume_id](error_t error) {
+    signal BlockWrite.syncDone[volume_id](error);
+  }
+  
+  default command error_t SubBlockRead.read[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) {
+    return FAIL;
+  }
+
+  default command error_t SubBlockRead.computeCrc[uint8_t volume_id](storage_addr_t addr, storage_len_t len, uint16_t crc) {
+    return FAIL;
+  }
+
+  default command storage_len_t SubBlockRead.getSize[uint8_t volume_id]() {
+    return FAIL;
+  }
+  
+  default command error_t SubBlockWrite.write[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) {
+    return FAIL;
+  }
+
+  default command error_t SubBlockWrite.erase[uint8_t volume_id]() {
+    return FAIL;
+  }
+
+  default command error_t SubBlockWrite.sync[uint8_t volume_id]() {
+    return FAIL;
+  }
+  
+  default event void BlockRead.readDone[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {}
+  default event void BlockRead.computeCrcDone[uint8_t volume_id](storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error) {}
+  default event void BlockWrite.writeDone[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {}
+  default event void BlockWrite.eraseDone[uint8_t volume_id](error_t error) {}
+  default event void BlockWrite.syncDone[uint8_t volume_id](error_t error) {}
+  
+  command error_t LogRead.read[uint8_t volume_id](void* buf, storage_len_t len) {
+    return call SubLogRead.read[volume_id](buf, len);
+  }
+
+  event void SubLogRead.readDone[uint8_t volume_id](void* buf, storage_len_t len, error_t error) {
+    signal LogRead.readDone[volume_id](buf, len, error);
+  }
+
+  command storage_cookie_t LogRead.currentOffset[uint8_t volume_id]() {
+    return call SubLogRead.currentOffset[volume_id]();
+  }
+
+  command error_t LogRead.seek[uint8_t volume_id](storage_cookie_t offset) {
+    return call SubLogRead.seek[volume_id](offset);
+  }
+
+  event void SubLogRead.seekDone[uint8_t volume_id](error_t error) {
+    signal LogRead.seekDone[volume_id](error);
+  }
+
+  command storage_len_t LogRead.getSize[uint8_t volume_id]() {
+    return call SubLogRead.getSize[volume_id]();
+  }
+  
+  command error_t LogWrite.append[uint8_t volume_id](void* buf, storage_len_t len) {
+    return call SubLogWrite.append[volume_id](buf, len);
+  }
+
+  event void SubLogWrite.appendDone[uint8_t volume_id](void* buf, storage_len_t len, bool recordsLost, error_t error) {
+    signal LogWrite.appendDone[volume_id](buf, len, recordsLost, error);
+  }
+
+  command storage_cookie_t LogWrite.currentOffset[uint8_t volume_id]() {
+    return call SubLogWrite.currentOffset[volume_id]();
+  }
+
+  command error_t LogWrite.erase[uint8_t volume_id]() {
+    return call SubLogWrite.erase[volume_id]();
+  }
+
+  event void SubLogWrite.eraseDone[uint8_t volume_id](error_t error) {
+    signal LogWrite.eraseDone[volume_id](error);
+  }
+
+  command error_t LogWrite.sync[uint8_t volume_id]() {
+    return call SubLogWrite.sync[volume_id]();
+  }
+
+  event void SubLogWrite.syncDone[uint8_t volume_id](error_t error) {
+    signal LogWrite.syncDone[volume_id](error);
+  }
+  
+  default command error_t SubLogRead.read[uint8_t volume_id](void* buf, storage_len_t len) {
+    return FAIL;
+  }
+
+  default command storage_cookie_t SubLogRead.currentOffset[uint8_t volume_id]() {
+    return 0;
+  }
+
+  default command error_t SubLogRead.seek[uint8_t volume_id](storage_cookie_t offset) {
+    return FAIL;
+  }
+
+  default command storage_len_t SubLogRead.getSize[uint8_t volume_id]() {
+    return 0;
+  }
+  
+  default command error_t SubLogWrite.append[uint8_t volume_id](void* buf, storage_len_t len) {
+    return FAIL;
+  }
+
+  default command storage_cookie_t SubLogWrite.currentOffset[uint8_t volume_id]() {
+    return 0;
+  }
+
+  default command error_t SubLogWrite.erase[uint8_t volume_id]() {
+    return FAIL;
+  }
+
+  default command error_t SubLogWrite.sync[uint8_t volume_id]() {
+    return FAIL;
+  }
+  
+  default event void LogRead.readDone[uint8_t volume_id](void* buf, storage_len_t len, error_t error) {}
+  default event void LogRead.seekDone[uint8_t volume_id](error_t error) {}
+  default event void LogWrite.appendDone[uint8_t volume_id](void* buf, storage_len_t len, bool recordsLost, error_t error) {}
+  default event void LogWrite.eraseDone[uint8_t volume_id](error_t error) {}
+  default event void LogWrite.syncDone[uint8_t volume_id](error_t error) {}
+}
diff --git a/tos/lib/tosthreads/csystem/tosthread.h b/tos/lib/tosthreads/csystem/tosthread.h
new file mode 100644 (file)
index 0000000..b032ad5
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * This is the file to include in your top level application when using 
+ * the tosthread library.  It defines all the tosthread_* commands and 
+ * #includes all of the needed header files for the basic tosthread 
+ * library calls
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef TOSTHREAD_H_INCLUDED
+#define TOSTHREAD_H_INCLUDED
+
+#include "thread.h"
+
+/**
+ *  tosthread_main()
+ *
+ *  This in the main entry point thread from which all tosthread applications begin.  
+ *  @param     NULL
+ */
+extern void tosthread_main(void* arg);
+
+/**
+ *  tosthread_create()
+ * 
+ *  This function creates a new tosthread.  
+ *  
+ *  @param     t                               A pointer to a thread identifier
+ *  @param     start_routine   The function called when the created thread starts running
+ *  @param     arg                             The parameter passed to the start_routine for the created thread
+ *  @param     stack_size              The maximum stack size for this thread
+ *  @return                                    An error code indicating whether the thread could be created or not
+ *                                                             SUCCESS         -       The thread has been created
+ *                                                             FAIL            -       The thread could not be created
+ *                                                             EALREADY        -       The thread identifier is already associated with a
+ *                                                                                             currently active thread
+ */
+extern error_t tosthread_create(tosthread_t* t, void (*start_routine)(void*), void* arg, uint16_t stack_size);
+
+/**
+ *  tosthread_destroy()
+ *
+ *  This function destroys a tosthread.  
+ *  
+ *  @param t                           A pointer to a thread identifier
+ *  @return                                    An error code indicating whether the thread could be destroyed or not
+ *                                                             SUCCESS         -       The thread has been destroyed
+ *                                                             FAIL            -       The thread could not be destroyed
+ *                                                             EBUSY           -       The thread holds mutexes so cannot be destroyed
+ *                                                                                             at the moment
+ */
+extern error_t tosthread_destroy(tosthread_t* t);
+
+/**
+ *  tosthread_pause() 
+ *
+ *  This function pauses a tosthread.  
+ *  
+ *  @param t                           A pointer to a thread identifier
+ *  @return                                    An error code indicating whether the thread could be paused or not
+ *                                                             SUCCESS         -       The thread has been paused
+ *                                                             FAIL            -       The thread could not be paused
+ *                                                             EBUSY           -       The thread holds mutexes so cannot be paused
+ *                                                                                             at the moment
+ */
+extern error_t tosthread_pause(tosthread_t* t);
+
+/**
+ *  tosthread_resume()
+ *
+ *  This function resumes a previously paused tosthread.  
+ *  
+ *  @param t                           A pointer to a thread identifier
+ *  @return                                    An error code indicating whether the thread could be resumed or not
+ *                                                             SUCCESS         -       The thread has been resumed
+ *                                                             FAIL            -       The thread could not be resumed
+ */
+extern error_t tosthread_resume(tosthread_t* t);
+
+/**
+ *  tosthread_sleep()
+ *
+ *  This function puts the currently running thread to sleep.  
+ *  
+ *  @param milli                       The number of milliseconds to sleep for
+ *  @return                                    An error code indicating whether the thread could be put to sleep or not
+ *                                                             SUCCESS         -       The thread has been put to sleep
+ *                                                             FAIL            -       The thread could not be put to sleep
+ */
+extern error_t tosthread_sleep(uint32_t milli);
+
+#endif //TOSTHREAD_H_INCLUDED
diff --git a/tos/lib/tosthreads/csystem/tosthread_amradio.h b/tos/lib/tosthreads/csystem/tosthread_amradio.h
new file mode 100644 (file)
index 0000000..19bb9c9
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef TOSTHREAD_AMRADIO_H
+#define TOSTHREAD_AMRADIO_H
+
+#include "message.h"
+#include "AM.h"
+#include "TinyError.h"
+
+#ifndef AM_RECEIVE_FROM_ANY
+#define AM_RECEIVE_FROM_ANY   0XFF
+#endif
+
+extern error_t amRadioStart();
+extern error_t amRadioStop();
+
+extern error_t amRadioReceive(message_t* m, uint32_t timeout, am_id_t amId);
+extern error_t amRadioSnoop(message_t* m, uint32_t timeout, am_id_t amId);
+extern error_t amRadioSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId);
+
+extern am_addr_t  amRadioGetLocalAddress(); 
+extern am_group_t amRadioGetLocalGroup();
+extern am_addr_t  amRadioGetDestination(message_t* amsg);
+extern am_addr_t  amRadioGetSource(message_t* amsg);
+extern void       amRadioSetDestination(message_t* amsg, am_addr_t addr);
+extern void       amRadioSetSource(message_t* amsg, am_addr_t addr);
+extern bool       amRadioIsForMe(message_t* amsg);
+extern am_id_t    amRadioGetType(message_t* amsg);
+extern void       amRadioSetType(message_t* amsg, am_id_t t);
+extern am_group_t amRadioGetGroup(message_t* amsg);
+extern void       amRadioSetGroup(message_t* amsg, am_group_t grp);
+extern void    radioClear(message_t* msg);
+extern uint8_t radioGetPayloadLength(message_t* msg);
+extern void    radioSetPayloadLength(message_t* msg, uint8_t len);
+extern uint8_t radioMaxPayloadLength();
+extern void*   radioGetPayload(message_t* msg, uint8_t len);
+
+extern error_t radioRequestAck( message_t* msg );
+extern error_t radioNoAck( message_t* msg );
+extern bool    radioWasAcked(message_t* msg);
+
+#endif //TOSTHREAD_AMRADIO_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_amserial.h b/tos/lib/tosthreads/csystem/tosthread_amserial.h
new file mode 100644 (file)
index 0000000..a63035a
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+#ifndef TOSTHREAD_AMSERIAL_H
+#define TOSTHREAD_AMSERIAL_H
+
+#include "message.h"
+#include "TinyError.h"
+
+#ifndef AM_RECEIVE_FROM_ANY
+#define AM_RECEIVE_FROM_ANY   0XFF
+#endif
+
+extern error_t amSerialStart();
+extern error_t amSerialStop();
+
+extern error_t amSerialReceive(message_t* m, uint32_t timeout, am_id_t amId);
+extern error_t amSerialSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId);
+
+extern am_addr_t  amSerialLocalAddress(); 
+extern am_group_t amSerialGetLocalGroup();
+extern am_addr_t  amSerialGetDestination(message_t* amsg);
+extern am_addr_t  amSerialGetSource(message_t* amsg);
+extern void       amSerialSetDestination(message_t* amsg, am_addr_t addr);
+extern void       amSerialSetSource(message_t* amsg, am_addr_t addr);
+extern bool       amSerialIsForMe(message_t* amsg);
+extern am_id_t    amSerialGetType(message_t* amsg);
+extern void       amSerialSetType(message_t* amsg, am_id_t t);
+extern am_group_t amSerialGetGroup(message_t* amsg);
+extern void       amSerialSetGroup(message_t* amsg, am_group_t grp);
+
+extern void    serialClear(message_t* msg);
+extern uint8_t serialGetPayloadLength(message_t* msg);
+extern void    serialSetPayloadLength(message_t* msg, uint8_t len);
+extern uint8_t serialMaxPayloadLength();
+extern void*   serialGetPayload(message_t* msg, uint8_t len);
+
+extern error_t serialRequestAck( message_t* msg );
+extern error_t serialNoAck( message_t* msg );
+extern bool    serialWasAcked(message_t* msg);
+#endif //TOSTHREAD_AMSERIAL_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_barrier.h b/tos/lib/tosthreads/csystem/tosthread_barrier.h
new file mode 100644 (file)
index 0000000..391bb6d
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef TOSTHREAD_BARRIER_H
+#define TOSTHREAD_BARRIER_H
+
+#include "barrier.h"
+
+extern void barrier_reset(barrier_t* b, uint8_t count);
+extern void barrier_block(barrier_t* b);
+extern bool barrier_isBlocking(barrier_t* b);
+
+#endif //TOSTHREAD_BARRIER_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_blockstorage.h b/tos/lib/tosthreads/csystem/tosthread_blockstorage.h
new file mode 100644 (file)
index 0000000..c246534
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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: Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+#ifndef TOSTHREAD_BLOCKSTORAGE_H
+#define TOSTHREAD_BLOCKSTORAGE_H
+
+#include "Storage.h"
+
+extern error_t volumeBlockRead(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len);
+extern error_t volumeBlockWrite(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len);
+extern error_t volumeBlockCrc(uint8_t volumeId, storage_addr_t addr, storage_len_t* len, uint16_t crc, uint16_t *finalCrc);
+extern error_t volumeBlockErase(uint8_t volumeId);
+extern error_t volumeBlockSync(uint8_t volumeId);
+
+#endif //TOSTHREAD_BLOCKSTORAGE_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_condvar.h b/tos/lib/tosthreads/csystem/tosthread_condvar.h
new file mode 100644 (file)
index 0000000..a05dc90
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef TOSTHREAD_CONDVAR_H
+#define TOSTHREAD_CONDVAR_H
+
+#include "condvar.h"
+
+extern void condvar_init(condvar_t* c);
+extern void condvar_wait(condvar_t* c, mutex_t* m);
+extern void condvar_signalNext(condvar_t* c);
+extern void condvar_signalAll(condvar_t* c);
+extern bool condvar_isBlocking(condvar_t* c);
+
+#endif //TOSTHREAD_CONDVAR_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_leds.h b/tos/lib/tosthreads/csystem/tosthread_leds.h
new file mode 100644 (file)
index 0000000..fa3f8a3
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+#ifndef TOSTHREAD_LEDS_H
+#define TOSTHREAD_LEDS_H
+
+extern void led0On();
+extern void led0Off();
+extern void led0Toggle();
+
+extern void led1On();
+extern void led1Off();
+extern void led1Toggle();
+
+extern void led2On();
+extern void led2Off();
+extern void led2Toggle();
+
+extern uint8_t getLeds();
+extern void setLeds(uint8_t val);
+
+#endif //TOSTHREAD_LEDS_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_linked_list.h b/tos/lib/tosthreads/csystem/tosthread_linked_list.h
new file mode 100644 (file)
index 0000000..b22c101
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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
+ *extern  notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *extern  notice, this list of conditions and the following disclaimer in the
+ *extern  documentation and/or other materials provided with the
+ *extern  distribution.
+ * - Neither the name of the Stanford University nor the names of
+ *extern  its contributors may be used to endorse or promote products derived
+ *extern  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.extern IN NO EVENT SHALL STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+#ifndef TOSTHREAD_LINKED_LIST_H
+#define TOSTHREAD_LINKED_LIST_H
+
+#include "linked_list.h"
+
+extern void linked_list_init(linked_list_t* l); 
+extern void linked_list_clear(linked_list_t* l); 
+extern uint8_t linked_list_size(linked_list_t* l); 
+extern error_t linked_list_addFirst(linked_list_t* l, list_element_t* e);
+extern list_element_t* linked_list_getFirst(linked_list_t* l); 
+extern list_element_t* linked_list_removeFirst(linked_list_t* l);
+extern error_t linked_list_addLast(linked_list_t* l, list_element_t* e); 
+extern list_element_t* linked_list_getLast(linked_list_t* l); 
+extern list_element_t* linked_list_removeLast(linked_list_t* l); 
+extern error_t linked_list_addAt(linked_list_t* l, list_element_t* e, uint8_t i); 
+extern list_element_t* linked_list_getAt(linked_list_t* l, uint8_t i); 
+extern list_element_t* linked_list_removeAt(linked_list_t* l, uint8_t i);
+extern error_t linked_list_addAfter(linked_list_t* l, list_element_t* first, list_element_t* second); 
+extern error_t linked_list_addBefore(linked_list_t* l, list_element_t* first, list_element_t* e); 
+extern list_element_t* linked_list_getAfter(linked_list_t* l, list_element_t* e); 
+extern list_element_t* linked_list_getBefore(linked_list_t* l, list_element_t* e); 
+extern list_element_t* linked_list_remove(linked_list_t* l, list_element_t* e); 
+extern list_element_t* linked_list_removeBefore(linked_list_t* l, list_element_t* e); 
+extern list_element_t* linked_list_removeAfter(linked_list_t* l, list_element_t* e);  
+extern uint8_t linked_list_indexOf(linked_list_t* l, list_element_t* e); 
+
+#endif //TOSTHREAD_LINKED_LIST_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_logstorage.h b/tos/lib/tosthreads/csystem/tosthread_logstorage.h
new file mode 100644 (file)
index 0000000..edb82df
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#ifndef TOSTHREAD_LOGSTORAGE_H
+#define TOSTHREAD_LOGSTORAGE_H
+
+#include "Storage.h"
+
+extern error_t volumeLogRead(uint8_t volumeId, void *buf, storage_len_t *len);
+extern storage_cookie_t volumeLogCurrentReadOffset(uint8_t volumeId);
+extern error_t volumeLogSeek(uint8_t volumeId, storage_cookie_t offset);
+extern storage_len_t volumeLogGetSize(uint8_t volumeId);
+  
+extern error_t volumeLogAppend(uint8_t volumeId, void* buf, storage_len_t *len, bool *recordsLost);
+extern storage_cookie_t volumeLogCurrentWriteOffset(uint8_t volumeId);
+extern error_t volumeLogErase(uint8_t volumeId);
+extern error_t volumeLogSync(uint8_t volumeId);
+
+#endif //TOSTHREAD_LOGSTORAGE_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_mutex.h b/tos/lib/tosthreads/csystem/tosthread_mutex.h
new file mode 100644 (file)
index 0000000..d54f988
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef TOSTHREAD_MUTEX_H
+#define TOSTHREAD_MUTEX_H
+
+#include "mutex.h"
+#include "TinyError.h"
+
+extern void mutex_init(mutex_t* m);
+extern error_t mutex_lock(mutex_t* m);
+extern error_t mutex_unlock(mutex_t* m);
+
+#endif //TOSTHREAD_MUTEX_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_queue.h b/tos/lib/tosthreads/csystem/tosthread_queue.h
new file mode 100644 (file)
index 0000000..20d114b
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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
+ *extern  notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *extern  notice, this list of conditions and the following disclaimer in the
+ *extern  documentation and/or other materials provided with the
+ *extern  distribution.
+ * - Neither the name of the Stanford University nor the names of
+ *extern  its contributors may be used to endorse or promote products derived
+ *extern  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.extern IN NO EVENT SHALL STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+#ifndef TOSTHREAD_QUEUE_H
+#define TOSTHREAD_QUEUE_H
+
+#include "queue.h"
+
+extern void queue_init(queue_t* q); 
+extern void queue_clear(queue_t* q); 
+extern error_t queue_enqueue(queue_t* q, queue_element_t* e);
+extern queue_element_t* queue_dequeue(queue_t* q);
+extern queue_element_t* queue_remove(queue_t* q, queue_element_t* e);
+extern uint8_t queue_size(queue_t* q); 
+extern bool queue_is_empty(queue_t* q); 
+
+#endif //TOSTHREAD_QUEUE_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_refcounter.h b/tos/lib/tosthreads/csystem/tosthread_refcounter.h
new file mode 100644 (file)
index 0000000..34f4b15
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef TOSTHREAD_REFCOUNTER_H
+#define TOSTHREAD_REFCOUNTER_H
+
+#include "refcounter.h"
+
+extern void refcounter_init(refcounter_t* r);
+extern void refcounter_increment(refcounter_t* r);
+extern void refcounter_decrement(refcounter_t* r);
+extern void refcounter_waitOnValue(refcounter_t* r, uint8_t count);
+extern uint8_t refcounter_count(refcounter_t* r);
+
+#endif //TOSTHREAD_REFCOUNTER_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_semaphore.h b/tos/lib/tosthreads/csystem/tosthread_semaphore.h
new file mode 100644 (file)
index 0000000..a0df5cc
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef TOSTHREAD_SEMAPHORE_H
+#define TOSTHREAD_SEMAPHORE_H
+
+#include "semaphore.h"
+#include "TinyError.h"
+
+extern void semaphore_reset(semaphore_t* s, uint8_t v);
+extern error_t semaphore_acquire(semaphore_t* s);
+extern error_t semaphore_release(semaphore_t* s);
+
+#endif //TOSTHREAD_MUTEX_H
diff --git a/tos/lib/tosthreads/csystem/tosthread_tenet.h b/tos/lib/tosthreads/csystem/tosthread_tenet.h
new file mode 100644 (file)
index 0000000..a2d5fd9
--- /dev/null
@@ -0,0 +1,39 @@
+
+/**
+ * @author Jeongyeup Paek (jpaek@enl.usc.edu)
+ **/
+#ifndef TOSTHREAD_TENET_H
+#define TOSTHREAD_TENET_H
+
+extern error_t tenet_send(uint8_t len, uint8_t *data);
+extern error_t tenet_sendto(uint16_t tid, uint16_t dst, uint8_t len, uint8_t *data);
+
+extern uint16_t tenet_get_tid();
+extern uint16_t tenet_get_src();
+extern uint8_t tenet_get_numtasks();
+
+extern void reboot();
+
+extern uint16_t get_nodeid();
+extern uint16_t get_nexthop();
+extern uint32_t get_globaltime();
+extern uint32_t get_localtime();
+extern uint16_t get_rfpower();
+extern uint16_t get_istimesync();
+extern uint32_t get_globaltimems();
+extern uint32_t get_localtimems();
+extern uint16_t get_clockfreq();
+extern uint16_t get_platform();
+extern uint16_t get_hopcount();
+extern uint16_t get_rfchannel();
+
+extern uint16_t read_voltage();
+extern uint16_t read_internal_temperature();
+extern uint16_t read_tsr_sensor();
+extern uint16_t read_par_sensor();
+extern uint16_t read_temperature();
+extern uint16_t read_humidity();
+
+#endif //TOSTHREAD_TENET_H
+
diff --git a/tos/lib/tosthreads/csystem/tosthread_threadsync.h b/tos/lib/tosthreads/csystem/tosthread_threadsync.h
new file mode 100644 (file)
index 0000000..8e410cb
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef TOSTHREAD_THREADSYNC_H
+#define TOSTHREAD_THREADSYNC_H
+
+#include "tosthread_mutex.h"
+#include "tosthread_semaphore.h"
+#include "tosthread_barrier.h"
+#include "tosthread_condvar.h"
+#include "tosthread_refcounter.h"
+
+#endif //TOSTHREAD_THREADSYNC_H
diff --git a/tos/lib/tosthreads/interfaces/Barrier.nc b/tos/lib/tosthreads/interfaces/Barrier.nc
new file mode 100644 (file)
index 0000000..83a99b4
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * Interface for using Barrier synchronization with tosthreads.
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "barrier.h"
+
+interface Barrier {
+  /**
+   * Reset a barrier for use.
+   * @param b     The barrier you would like to reset.
+   * @param count The number of threads that must call
+   *              block before the flood gates open and
+   *              the barrier is unblocked.
+   */
+  command void reset(barrier_t* b, uint8_t count);
+  /**
+   * Block on a barrier until all threads have called 
+   * block() as indicated in the count parameter to reset()
+   * @param b The barrier you would like to block on.
+   */
+  command void block(barrier_t* b);
+  /**
+   * Query whether a barrier is currently blocked or not
+   * @param b The barrier you would like to query.
+   * @return  TRUE or FALSE
+   */
+  command bool isBlocking(barrier_t* b);
+}  
diff --git a/tos/lib/tosthreads/interfaces/BitArrayUtils.nc b/tos/lib/tosthreads/interfaces/BitArrayUtils.nc
new file mode 100644 (file)
index 0000000..3f19baa
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+interface BitArrayUtils {
+  async command void clrArray(uint8_t* array, uint8_t numBytes);
+  async command bool getBit(uint8_t* array, uint8_t idx);
+  async command void setBit(uint8_t* array, uint8_t idx);
+  async command void clrBit(uint8_t* array, uint8_t idx);
+}
diff --git a/tos/lib/tosthreads/interfaces/BlockingAMSend.nc b/tos/lib/tosthreads/interfaces/BlockingAMSend.nc
new file mode 100644 (file)
index 0000000..8e249dc
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include <TinyError.h>
+#include <message.h>
+#include <AM.h>
+
+interface BlockingAMSend {
+  command error_t send(am_addr_t addr, message_t* msg, uint8_t len);
+  command uint8_t maxPayloadLength();
+  command void* getPayload(message_t* msg, uint8_t len);
+}
diff --git a/tos/lib/tosthreads/interfaces/BlockingBlock.nc b/tos/lib/tosthreads/interfaces/BlockingBlock.nc
new file mode 100644 (file)
index 0000000..4ff4750
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+ #include "Storage.h"
+interface BlockingBlock {
+  command error_t read(storage_addr_t addr, void *buf, storage_len_t* len);
+  command error_t computeCrc(storage_addr_t addr, storage_len_t* len, uint16_t crc, uint16_t *finalCrc);
+  command storage_len_t getSize();
+  
+  command error_t write(storage_addr_t addr, void *buf, storage_len_t* len);
+  command error_t erase();
+  command error_t sync();
+}
diff --git a/tos/lib/tosthreads/interfaces/BlockingBlockWrite.nc b/tos/lib/tosthreads/interfaces/BlockingBlockWrite.nc
new file mode 100644 (file)
index 0000000..83f79c4
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+interface BlockingBlockWrite { 
+  command error_t write(storage_addr_t addr, void* buf, storage_len_t len);
+  command error_t erase();
+  command error_t sync();
+}
diff --git a/tos/lib/tosthreads/interfaces/BlockingLog.nc b/tos/lib/tosthreads/interfaces/BlockingLog.nc
new file mode 100644 (file)
index 0000000..23c6359
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+ #include "Storage.h"
+interface BlockingLog {
+  command error_t read(void *buf, storage_len_t *len);
+  command storage_cookie_t currentReadOffset();
+  command error_t seek(storage_cookie_t offset);
+  command storage_len_t getSize();
+  
+  command error_t append(void* buf, storage_len_t *len, bool *recordsLost);
+  command storage_cookie_t currentWriteOffset();
+  command error_t erase();
+  command error_t sync();
+}
diff --git a/tos/lib/tosthreads/interfaces/BlockingRead.nc b/tos/lib/tosthreads/interfaces/BlockingRead.nc
new file mode 100644 (file)
index 0000000..adad884
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+interface BlockingRead<val_t> {
+  /**
+   * Read a value
+   * 
+   * @param val pointer for where to store the value that has been read
+   * @return SUCCESS if a readDone() event will eventually come back.
+   */
+  command error_t read(val_t* val);
+}
diff --git a/tos/lib/tosthreads/interfaces/BlockingReadStream.nc b/tos/lib/tosthreads/interfaces/BlockingReadStream.nc
new file mode 100644 (file)
index 0000000..b325df9
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+interface BlockingReadStream<val_t> {
+  /**
+   * Directs the device to fill a buffer by sampling with the
+   * specified period. 
+   * 
+   * @param usPeriod the between-sample period in microseconds
+   * @param buf a pointer to the buffer
+   * @param count the number of values the buffer should hold
+   * @param usActualPeriod Actual sampling period used - may be 
+   *   different from period requested. Undefined if 
+   *   result != SUCCESS.
+   * 
+   * @return SUCCESS if the reading was carried out successfully
+   */
+  command error_t read(uint32_t* usPeriod, val_t* buf, uint16_t count);
+}    
diff --git a/tos/lib/tosthreads/interfaces/BlockingReceive.nc b/tos/lib/tosthreads/interfaces/BlockingReceive.nc
new file mode 100644 (file)
index 0000000..4ececa5
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include <TinyError.h>
+#include <message.h>
+
+interface BlockingReceive {
+  command error_t receive(message_t* m, uint32_t timeout); 
+  command void* getPayload(message_t* msg, uint8_t len);
+}
diff --git a/tos/lib/tosthreads/interfaces/BlockingResource.nc b/tos/lib/tosthreads/interfaces/BlockingResource.nc
new file mode 100644 (file)
index 0000000..7f82664
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+  
+interface BlockingResource {
+  command error_t request();
+  command error_t release();
+  command error_t timedRelease(uint32_t milli);
+  command bool isOwner();
+}
diff --git a/tos/lib/tosthreads/interfaces/BlockingStdControl.nc b/tos/lib/tosthreads/interfaces/BlockingStdControl.nc
new file mode 100644 (file)
index 0000000..54edb84
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include <TinyError.h>
+#include <message.h>
+#include <AM.h>
+
+interface BlockingStdControl {
+  command error_t start();
+  command error_t stop();
+}
diff --git a/tos/lib/tosthreads/interfaces/ConditionVariable.nc b/tos/lib/tosthreads/interfaces/ConditionVariable.nc
new file mode 100644 (file)
index 0000000..4c3454b
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * Interface for using Conddition Variables for synchronization 
+ * with tosthreads.
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "condvar.h"
+
+interface ConditionVariable {
+  /**
+   * Reset a condition variable for use.
+   * @param c The condition variable you would like to reset.
+   */
+  command void init(condvar_t* c);
+  /**
+   * Wait on a condition variable until one of the signal
+   * calls unbocks me.  In the process, unlock the mutex 
+   * passed in to me.
+   * @param c The condition variable you would like to wait on.
+   * @param m The mutex you would like to unlock
+   */
+  command void wait(condvar_t* c, mutex_t* m);
+  /**
+   * Signal the next thread waiting on this condition variable 
+   * to continue execution.  To unblock all threads waiting on 
+   * this condition vairable use signalAll().
+   * @param c The condition variable associated with the thread 
+   *          you would like to signal.
+   */
+  command void signalNext(condvar_t* c);
+  /**
+   * Signal all threads waiting on this condition variable 
+   * to continue execution.  To unblock just the next thread
+   * waiting on this condition vairable use signalNext().
+   * @param c The condition variable associated with the thread 
+   *          you would like to signal.
+   */
+  command void signalAll(condvar_t* c);
+  /**
+   * Query whether a condition variable is currently blocking 
+   * any threads from executing.
+   * @param c The cndition variable you would like to query.
+   * @return  TRUE or FALSE
+   */
+  command bool isBlocking(condvar_t* c);
+}  
diff --git a/tos/lib/tosthreads/interfaces/DynamicThread.nc b/tos/lib/tosthreads/interfaces/DynamicThread.nc
new file mode 100644 (file)
index 0000000..aea023c
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+interface DynamicThread {
+  /**
+   *  create()
+   * 
+   *  This function creates a new tosthread.  
+   *  
+   *  @param   t                               A pointer to a unique handler associated with the thread being created
+   *  @param   start_routine   The function called when the created thread starts running
+   *  @param   arg                             The parameter passed to the start_routine for the created thread
+   *  @param   stack_size              The maximum stack size for this thread
+   *  @return                                  An error code indicating whether the thread could be created or not
+   *                                                           SUCCESS         -       The thread has been created
+   *                                                           FAIL            -       The thread could not be created
+   *                                                           EALREADY        -       The thread identifier is already associated with a
+   *                                                                                           currently active thread
+   */
+  command error_t create(tosthread_t* t, void (*start_routine)(void*), void* arg, uint16_t stack_size);
+
+  /**
+   *  destroy()
+   *
+   *  This function destroys a tosthread.  
+   *  
+   *  @param t                                 A pointer to a thread identifier
+   *  @return                          An error code indicating whether the thread could be destroyed or not
+   *                                                   SUCCESS         -       The thread has been destroyed
+   *                                                   FAIL            -       The thread could not be destroyed
+   *                                                   EBUSY           -       The thread holds mutexes so cannot be destroyed
+   *                                                                                   at the moment
+   */
+  command error_t destroy(tosthread_t* t);
+
+  /**
+   *  tosthread_pause() 
+   *
+   *  This function pauses a tosthread.  
+   *  
+   *  @param t                                 A pointer to a thread identifier
+   *  @return                          An error code indicating whether the thread could be paused or not
+   *                                                   SUCCESS         -       The thread has been paused
+   *                                                   FAIL            -       The thread could not be paused
+   *                                                   EBUSY           -       The thread holds mutexes so cannot be paused
+   *                                                                                   at the moment
+   */
+  command error_t pause(tosthread_t* t);
+
+  /**
+   *  resume()
+   *
+   *  This function resumes a previously paused tosthread.  
+   *  
+   *  @param t                                 A pointer to a thread identifier
+   *  @return                          An error code indicating whether the thread could be resumed or not
+   *                                                   SUCCESS         -       The thread has been resumed
+   *                                                   FAIL            -       The thread could not be resumed
+   */
+  command error_t resume(tosthread_t* t);
+
+  /**
+   *  sleep()
+   *
+   *  This function puts the currently running thread to sleep.  
+   *  
+   *  @param milli                     The number of milliseconds to sleep for
+   *  @return                          An error code indicating whether the thread could be put to sleep or not
+   *                                                   SUCCESS         -       The thread has been put to sleep
+   *                                                   FAIL            -       The thread could not be put to sleep
+   */
+  command error_t sleep(uint32_t milli);
+}  
diff --git a/tos/lib/tosthreads/interfaces/LinkedList.nc b/tos/lib/tosthreads/interfaces/LinkedList.nc
new file mode 100644 (file)
index 0000000..845989b
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "linked_list.h"
+
+interface LinkedList {
+  async command void init(linked_list_t* l);
+  async command void clear(linked_list_t* l);
+  async command uint8_t size(linked_list_t* l);
+  async command error_t addAt(linked_list_t* l, list_element_t* e, uint8_t i);
+  async command error_t addFirst(linked_list_t* l, list_element_t* e);
+  async command error_t addLast(linked_list_t* l, list_element_t* e);
+  async command error_t addAfter(linked_list_t* l, list_element_t* first, list_element_t* second);
+  async command error_t addBefore(linked_list_t* l, list_element_t* first, list_element_t* second);
+  async command list_element_t* getAt(linked_list_t* l, uint8_t i);
+  async command list_element_t* getFirst(linked_list_t* l);
+  async command list_element_t* getLast(linked_list_t* l);
+  async command list_element_t* getAfter(linked_list_t* l, list_element_t* e);
+  async command list_element_t* getBefore(linked_list_t* l, list_element_t* e);
+  async command uint8_t indexOf(linked_list_t* l, list_element_t* e);
+  async command list_element_t* remove(linked_list_t* l, list_element_t* e);
+  async command list_element_t* removeAt(linked_list_t* l, uint8_t i);
+  async command list_element_t* removeFirst(linked_list_t* l);
+  async command list_element_t* removeLast(linked_list_t* l);
+  async command list_element_t* removeBefore(linked_list_t* l, list_element_t* e);
+  async command list_element_t* removeAfter(linked_list_t* l, list_element_t* e);
+}
diff --git a/tos/lib/tosthreads/interfaces/Malloc.nc b/tos/lib/tosthreads/interfaces/Malloc.nc
new file mode 100644 (file)
index 0000000..2997a24
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+interface Malloc {
+  async command void* malloc(size_t size);
+  async command void free (void *p);
+}
diff --git a/tos/lib/tosthreads/interfaces/Mutex.nc b/tos/lib/tosthreads/interfaces/Mutex.nc
new file mode 100644 (file)
index 0000000..3d66ad5
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "mutex.h"
+
+interface Mutex {
+  command void init(mutex_t* m);
+  command error_t lock(mutex_t* m);
+  command error_t unlock(mutex_t* m);
+}  
diff --git a/tos/lib/tosthreads/interfaces/PlatformInterrupt.nc b/tos/lib/tosthreads/interfaces/PlatformInterrupt.nc
new file mode 100644 (file)
index 0000000..ebd66cf
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+interface PlatformInterrupt {
+  async command void postAmble();
+}  
diff --git a/tos/lib/tosthreads/interfaces/PoolThread.nc b/tos/lib/tosthreads/interfaces/PoolThread.nc
new file mode 100644 (file)
index 0000000..565352f
--- /dev/null
@@ -0,0 +1,18 @@
+/**
+ * @author Jeongyeup Paek (jpaek@enl.usc.edu)
+ **/
+
+interface PoolThread {
+
+  command error_t allocate(uint8_t* t, void (*start_routine)(void*), void* arg);
+
+  command error_t release(uint8_t t);
+
+  command error_t pause(uint8_t t);
+
+  command error_t resume(uint8_t t);
+
+  command error_t sleep(uint32_t milli);
+}
+
diff --git a/tos/lib/tosthreads/interfaces/ReferenceCounter.nc b/tos/lib/tosthreads/interfaces/ReferenceCounter.nc
new file mode 100644 (file)
index 0000000..d5b3ee4
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "refcounter.h"
+
+interface ReferenceCounter {
+  async command void init(refcounter_t* r);
+  async command void increment(refcounter_t* r);
+  async command void decrement(refcounter_t* r);
+  async command void waitOnValue(refcounter_t* r, uint8_t count);
+  async command uint8_t count(refcounter_t* r);
+}  
diff --git a/tos/lib/tosthreads/interfaces/Semaphore.nc b/tos/lib/tosthreads/interfaces/Semaphore.nc
new file mode 100644 (file)
index 0000000..a0aaefa
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+#include "semaphore.h"
+
+/*
+ * Counting semaphore
+ */
+interface Semaphore {
+  command void reset(semaphore_t* s, uint8_t v);
+  command error_t acquire(semaphore_t* s);
+  command error_t release(semaphore_t* s);
+}
diff --git a/tos/lib/tosthreads/interfaces/SystemCall.nc b/tos/lib/tosthreads/interfaces/SystemCall.nc
new file mode 100644 (file)
index 0000000..4191b70
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "TinyError.h"
+
+interface SystemCall {
+  command error_t start(void* syscall_ptr, syscall_t* s, syscall_id_t id, void* params);
+  command error_t finish(syscall_t* s);
+}
+
diff --git a/tos/lib/tosthreads/interfaces/SystemCallQueue.nc b/tos/lib/tosthreads/interfaces/SystemCallQueue.nc
new file mode 100644 (file)
index 0000000..72c7850
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "thread.h"
+#include "syscall_queue.h"
+
+interface SystemCallQueue {
+  async command void init(syscall_queue_t* q);
+  async command void enqueue(syscall_queue_t* q, syscall_t* t);
+  async command syscall_t* dequeue(syscall_queue_t* q);
+  async command syscall_t* remove(syscall_queue_t* q, syscall_t* t);
+  
+  async command syscall_t* find(syscall_queue_t* q, syscall_id_t id);
+  
+  async command bool isEmpty(syscall_queue_t* q);
+}
diff --git a/tos/lib/tosthreads/interfaces/TaskScheduler.nc b/tos/lib/tosthreads/interfaces/TaskScheduler.nc
new file mode 100644 (file)
index 0000000..ce4954c
--- /dev/null
@@ -0,0 +1,71 @@
+// $Id$
+/*                                                                     tab:4
+ * "Copyright (c) 2004-5 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) 2004-5 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.
+ */
+
+/** 
+  * The interface to a TinyOS task scheduler.
+  *
+  * @author Philip Levis
+  * @author Kevin Klues <klueska@cs.stanford.edu>
+  * @date   January 19 2005
+  * @see TEP 106: Tasks and Schedulers
+  * @see TEP 107: Boot Sequence
+  */ 
+
+
+interface TaskScheduler {
+
+  /** 
+   * Initialize the scheduler.
+   */
+  command void init();
+
+  /** 
+    * Run the next task if one is waiting, otherwise return immediately. 
+    *
+    * @return        whether a task was run -- TRUE indicates a task
+    *                ran, FALSE indicates there was no task to run.
+    */
+  command bool runNextTask();
+  
+  /** 
+    * Check to see if there are any pending tasks in the task queue. 
+    *
+    * @return        whether there are any tasks waiting to run
+    */
+  async command bool hasTasks();
+
+  /**
+   * Enter an infinite task-running loop. Put the MCU into a low power
+   * state when the processor is idle (task queue empty, waiting for
+   * interrupts). This call never returns.
+   */
+  command void taskLoop();
+}
+
diff --git a/tos/lib/tosthreads/interfaces/Thread.nc b/tos/lib/tosthreads/interfaces/Thread.nc
new file mode 100644 (file)
index 0000000..15b93f6
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+interface Thread {
+  command error_t start(void* arg);
+  command error_t stop();
+  command error_t pause();
+  command error_t resume();
+  command error_t sleep(uint32_t milli);
+  event void run(void* arg);
+}  
diff --git a/tos/lib/tosthreads/interfaces/ThreadCleanup.nc b/tos/lib/tosthreads/interfaces/ThreadCleanup.nc
new file mode 100644 (file)
index 0000000..1810737
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+interface ThreadCleanup {
+  async event void cleanup();
+}  
diff --git a/tos/lib/tosthreads/interfaces/ThreadFunction.nc b/tos/lib/tosthreads/interfaces/ThreadFunction.nc
new file mode 100644 (file)
index 0000000..d8a0e87
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+interface ThreadFunction {
+  event void signalThreadRun(void* arg);
+}  
diff --git a/tos/lib/tosthreads/interfaces/ThreadInfo.nc b/tos/lib/tosthreads/interfaces/ThreadInfo.nc
new file mode 100644 (file)
index 0000000..d98379f
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "thread.h"
+
+interface ThreadInfo {
+  async command thread_t* get();
+}  
diff --git a/tos/lib/tosthreads/interfaces/ThreadNotification.nc b/tos/lib/tosthreads/interfaces/ThreadNotification.nc
new file mode 100644 (file)
index 0000000..4297335
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+interface ThreadNotification {
+  async event void justCreated();
+  async event void aboutToDestroy();
+}  
diff --git a/tos/lib/tosthreads/interfaces/ThreadQueue.nc b/tos/lib/tosthreads/interfaces/ThreadQueue.nc
new file mode 100644 (file)
index 0000000..c7b2090
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "thread_queue.h"
+
+interface ThreadQueue {
+  async command void init(thread_queue_t* q);
+  async command void enqueue(thread_queue_t* q, thread_t* t);
+  async command thread_t* dequeue(thread_queue_t* q);
+  async command thread_t* remove(thread_queue_t* q, thread_t* t);
+  async command bool isEmpty(thread_queue_t* q);
+}
diff --git a/tos/lib/tosthreads/interfaces/ThreadScheduler.nc b/tos/lib/tosthreads/interfaces/ThreadScheduler.nc
new file mode 100644 (file)
index 0000000..0894608
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "thread.h"
+
+interface ThreadScheduler {
+  async command uint8_t currentThreadId();
+  async command thread_t* currentThreadInfo();
+  async command thread_t* threadInfo(thread_id_t id);
+  
+  command error_t initThread(thread_id_t id);
+  command error_t startThread(thread_id_t id);
+  command error_t stopThread(thread_id_t id);
+  
+  async command error_t suspendCurrentThread();
+  async command error_t interruptCurrentThread();
+
+  async command error_t wakeupThread(thread_id_t id);
+}
diff --git a/tos/lib/tosthreads/interfaces/ThreadSleep.nc b/tos/lib/tosthreads/interfaces/ThreadSleep.nc
new file mode 100644 (file)
index 0000000..b13d991
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+interface ThreadSleep {
+  command error_t sleep(uint32_t milli);
+}  
diff --git a/tos/lib/tosthreads/lib/printf/PrintfC.nc b/tos/lib/tosthreads/lib/printf/PrintfC.nc
new file mode 100644 (file)
index 0000000..85642a2
--- /dev/null
@@ -0,0 +1,65 @@
+ /*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "printf.h"
+
+configuration PrintfC {}
+implementation {
+  components MainC;
+  components PrintfP;
+  PrintfP.Boot -> MainC;
+
+  components new ThreadC(200);
+  PrintfP.PrintfThread -> ThreadC;
+  
+  components BlockingSerialActiveMessageC;
+  PrintfP.SerialControl -> BlockingSerialActiveMessageC;
+  PrintfP.Packet -> BlockingSerialActiveMessageC;
+  
+  components new PrintfQueueC(uint8_t, PRINTF_BUFFER_SIZE) as QueueC;
+  PrintfP.Queue -> QueueC;
+  
+  components BarrierC;
+  PrintfP.Barrier -> BarrierC;
+  
+  components MutexC;
+  PrintfP.Mutex -> MutexC;
+
+  components new BlockingSerialAMSenderC(AM_PRINTF_MSG);
+  PrintfP.BlockingAMSend -> BlockingSerialAMSenderC;
+
+  components LedsC;
+  PrintfP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/lib/printf/PrintfP.nc b/tos/lib/tosthreads/lib/printf/PrintfP.nc
new file mode 100644 (file)
index 0000000..a0c0a64
--- /dev/null
@@ -0,0 +1,136 @@
+ /*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "printf.h"
+
+#ifdef _H_atmega128hardware_H
+static int uart_putchar(char c, FILE *stream);
+static FILE atm128_stdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
+#endif
+
+module PrintfP {
+  uses {
+    interface Boot;
+    interface Thread as PrintfThread;
+    interface BlockingStdControl as SerialControl;
+    interface PrintfQueue<uint8_t> as Queue;
+    interface Barrier;
+    interface Mutex;
+
+    interface BlockingAMSend;
+    interface Packet;
+    interface Leds;
+  }
+}
+implementation {
+  message_t printfMsg;
+  printf_msg_t* printf_payload;
+  mutex_t printf_mutex;
+  barrier_t flushstart_barrier;
+  barrier_t flushdone_barrier;
+  
+  void flush_buffer();
+  
+  event void Boot.booted() {
+    #ifdef _H_atmega128hardware_H
+      stdout = &atm128_stdout;
+    #endif
+    
+    printf_payload = (printf_msg_t*)call Packet.getPayload(&printfMsg, sizeof(printf_msg_t));
+    call Mutex.init(&printf_mutex);
+    call Barrier.reset(&flushstart_barrier, 2);
+    call Barrier.reset(&flushdone_barrier, 2);
+    call PrintfThread.start(NULL);
+  }
+  
+  event void PrintfThread.run(void* arg) {
+    call SerialControl.start();
+    for(;;) {
+      call Barrier.block(&flushstart_barrier);
+        flush_buffer();
+      call Barrier.block(&flushdone_barrier);
+    }
+  }
+  
+  void flush_buffer() {
+    int i;
+    uint16_t q_size;
+    uint16_t length_to_send;
+    
+    call Mutex.lock(&printf_mutex);
+      q_size = call Queue.size();
+    call Mutex.unlock(&printf_mutex);
+    
+    while(q_size > 0) {
+      memset(printf_payload->buffer, 0, sizeof(printf_msg_t));    
+      length_to_send = (q_size < sizeof(printf_msg_t)) ? q_size : sizeof(printf_msg_t);
+     
+      call Mutex.lock(&printf_mutex); 
+        for(i=0; i<length_to_send; i++)
+          printf_payload->buffer[i] = call Queue.dequeue();
+        q_size = call Queue.size();
+      call Mutex.unlock(&printf_mutex);
+      call BlockingAMSend.send(AM_BROADCAST_ADDR, &printfMsg, sizeof(printf_msg_t));
+    }
+  }
+  
+  int printfflush() @C() @spontaneous() {
+    call Barrier.block(&flushstart_barrier);
+    call Barrier.reset(&flushstart_barrier, 2);  
+    call Barrier.block(&flushdone_barrier);
+    call Barrier.reset(&flushdone_barrier, 2);  
+    return SUCCESS;
+  }
+  
+  #ifdef _H_msp430hardware_h
+  int putchar(int c) __attribute__((noinline)) @C() @spontaneous() {
+  #endif
+  #ifdef _H_atmega128hardware_H
+  int uart_putchar(char c, FILE *stream) __attribute__((noinline)) @C() @spontaneous() {
+  #endif
+    uint16_t q_size;
+    error_t q_error;
+    
+    call Mutex.lock(&printf_mutex);
+      q_error = call Queue.enqueue(c);
+      q_size = call Queue.size();
+    call Mutex.unlock(&printf_mutex);
+    
+    if((q_size == PRINTF_BUFFER_SIZE/2))
+      printfflush();
+    if(q_error == SUCCESS) return 0;
+    else return -1;
+  }
+}
diff --git a/tos/lib/tosthreads/lib/printf/avr_stdio.h b/tos/lib/tosthreads/lib/printf/avr_stdio.h
new file mode 100644 (file)
index 0000000..8d1808d
--- /dev/null
@@ -0,0 +1,1094 @@
+/* Copyright (c) 2002, 2005, Joerg Wunsch
+   All rights reserved.
+
+   Portions of documentation Copyright (c) 1990, 1991, 1993
+   The Regents of the University of California.
+
+   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 copyright holders nor the names of
+     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.
+
+  $Id$
+*/
+
+#ifndef _STDIO_H_
+#define        _STDIO_H_ 1
+
+#ifndef __ASSEMBLER__
+
+#include <inttypes.h>
+#include <stdarg.h>
+
+#define __need_NULL
+#define __need_size_t
+#include <stddef.h>
+
+/** \defgroup avr_stdio <stdio.h>: Standard IO facilities
+    \code #include <stdio.h> \endcode
+
+    <h3>Introduction to the Standard IO facilities</h3>
+
+    This file declares the standard IO facilities that are implemented
+    in \c avr-libc.  Due to the nature of the underlying hardware,
+    only a limited subset of standard IO is implemented.  There is no
+    actual file implementation available, so only device IO can be
+    performed.  Since there's no operating system, the application
+    needs to provide enough details about their devices in order to
+    make them usable by the standard IO facilities.
+
+    Due to space constraints, some functionality has not been
+    implemented at all (like some of the \c printf conversions that
+    have been left out).  Nevertheless, potential users of this
+    implementation should be warned: the \c printf and \c scanf families of functions, although
+    usually associated with presumably simple things like the
+    famous "Hello, world!" program, are actually fairly complex
+    which causes their inclusion to eat up a fair amount of code space.
+    Also, they are not fast due to the nature of interpreting the
+    format string at run-time.  Whenever possible, resorting to the
+    (sometimes non-standard) predetermined conversion facilities that are
+    offered by avr-libc will usually cost much less in terms of speed
+    and code size.
+
+    <h3>Tunable options for code size vs. feature set</h3>
+
+    In order to allow programmers a code size vs. functionality tradeoff,
+    the function vfprintf() which is the heart of the printf family can be
+    selected in different flavours using linker options.  See the
+    documentation of vfprintf() for a detailed description.  The same
+    applies to vfscanf() and the \c scanf family of functions.
+
+    <h3>Outline of the chosen API</h3>
+
+    The standard streams \c stdin, \c stdout, and \c stderr are
+    provided, but contrary to the C standard, since avr-libc has no
+    knowledge about applicable devices, these streams are not already
+    pre-initialized at application startup.  Also, since there is no
+    notion of "file" whatsoever to avr-libc, there is no function
+    \c fopen() that could be used to associate a stream to some device.
+    (See \ref stdio_note1 "note 1".)  Instead, the function \c fdevopen()
+    is provided to associate a stream to a device, where the device
+    needs to provide a function to send a character, to receive a
+    character, or both.  There is no differentiation between "text" and
+    "binary" streams inside avr-libc.  Character \c \\n is sent
+    literally down to the device's \c put() function.  If the device
+    requires a carriage return (\c \\r) character to be sent before
+    the linefeed, its \c put() routine must implement this (see
+    \ref stdio_note2 "note 2").
+
+    As an alternative method to fdevopen(), the macro
+    fdev_setup_stream() might be used to setup a user-supplied FILE
+    structure.
+
+    It should be noted that the automatic conversion of a newline
+    character into a carriage return - newline sequence breaks binary
+    transfers.  If binary transfers are desired, no automatic
+    conversion should be performed, but instead any string that aims
+    to issue a CR-LF sequence must use <tt>"\r\n"</tt> explicitly.
+
+    For convenience, the first call to \c fdevopen() that opens a
+    stream for reading will cause the resulting stream to be aliased
+    to \c stdin.  Likewise, the first call to \c fdevopen() that opens
+    a stream for writing will cause the resulting stream to be aliased
+    to both, \c stdout, and \c stderr.  Thus, if the open was done
+    with both, read and write intent, all three standard streams will
+    be identical.  Note that these aliases are indistinguishable from
+    each other, thus calling \c fclose() on such a stream will also
+    effectively close all of its aliases (\ref stdio_note3 "note 3").
+
+    It is possible to tie additional user data to a stream, using
+    fdev_set_udata().  The backend put and get functions can then
+    extract this user data using fdev_get_udata(), and act
+    appropriately.  For example, a single put function could be used
+    to talk to two different UARTs that way, or the put and get
+    functions could keep internal state between calls there.
+
+    <h3>Format strings in flash ROM</h3>
+
+    All the \c printf and \c scanf family functions come in two flavours: the
+    standard name, where the format string is expected to be in
+    SRAM, as well as a version with the suffix "_P" where the format
+    string is expected to reside in the flash ROM.  The macro
+    \c PSTR (explained in \ref avr_pgmspace) becomes very handy
+    for declaring these format strings.
+
+    \anchor stdio_without_malloc
+    <h3>Running stdio without malloc()</h3>
+
+    By default, fdevopen() as well as the floating-point versions of
+    the printf and scanf family require malloc().  As this is often
+    not desired in the limited environment of a microcontroller, an
+    alternative option is provided to run completely without malloc().
+
+    The macro fdev_setup_stream() is provided to prepare a
+    user-supplied FILE buffer for operation with stdio.  If
+    floating-point operation is desired, a user-supplied buffer can as
+    well be passed for the internal buffering for the floating-point
+    numbers (and processing of \%[ scanf data).
+
+    <h4>Example</h4>
+
+    \code
+    #include <stdio.h>
+
+    static int uart_putchar(char c, FILE *stream);
+
+    static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
+                                             _FDEV_SETUP_WRITE);
+
+    static int
+    uart_putchar(char c, FILE *stream)
+    {
+
+      if (c == '\n')
+        uart_putchar('\r', stream);
+      loop_until_bit_is_set(UCSRA, UDRE);
+      UDR = c;
+      return 0;
+    }
+
+    int
+    main(void)
+    {
+      init_uart();
+      stdout = &mystdout;
+      printf("Hello, world!\n");
+
+      return 0;
+    }
+    \endcode
+
+    This example uses the initializer form FDEV_SETUP_STREAM() rather
+    than the function-like fdev_setup_stream(), so all data
+    initialization happens during C start-up.
+
+    If streams initialized that way are no longer needed, they can be
+    destroyed by first calling the macro fdev_close(), and then
+    destroying the object itself.  No call to fclose() should be
+    issued for these streams.  While calling fclose() itself is
+    harmless, it will cause an undefined reference to free() and thus
+    cause the linker to link the malloc module into the application.
+
+    <h3>Notes</h3>
+
+    \anchor stdio_note1 \par Note 1:
+    It might have been possible to implement a device abstraction that
+    is compatible with \c fopen() but since this would have required
+    to parse a string, and to take all the information needed either
+    out of this string, or out of an additional table that would need to be
+    provided by the application, this approach was not taken.
+
+    \anchor stdio_note2 \par Note 2:
+    This basically follows the Unix approach: if a device such as a
+    terminal needs special handling, it is in the domain of the
+    terminal device driver to provide this functionality.  Thus, a
+    simple function suitable as \c put() for \c fdevopen() that talks
+    to a UART interface might look like this:
+
+    \code
+    int
+    uart_putchar(char c, FILE *stream)
+    {
+
+      if (c == '\n')
+        uart_putchar('\r');
+      loop_until_bit_is_set(UCSRA, UDRE);
+      UDR = c;
+      return 0;
+    }
+    \endcode
+
+    \anchor stdio_note3 \par Note 3:
+    This implementation has been chosen because the cost of maintaining
+    an alias is considerably smaller than the cost of maintaining full
+    copies of each stream.  Yet, providing an implementation that offers
+    the complete set of standard streams was deemed to be useful.  Not
+    only that writing \c printf() instead of <tt>fprintf(mystream, ...)</tt>
+    saves typing work, but since avr-gcc needs to resort to pass all
+    arguments of variadic functions on the stack (as opposed to passing
+    them in registers for functions that take a fixed number of
+    parameters), the ability to pass one parameter less by implying
+    \c stdin will also save some execution time.
+*/
+
+#if !defined(__DOXYGEN__)
+
+/*
+ * This is an internal structure of the library that is subject to be
+ * changed without warnings at any time.  Please do *never* reference
+ * elements of it beyond by using the official interfaces provided.
+ */
+struct __file {
+       char    *buf;           /* buffer pointer */
+       unsigned char unget;    /* ungetc() buffer */
+       uint8_t flags;          /* flags, see below */
+#define __SRD  0x0001          /* OK to read */
+#define __SWR  0x0002          /* OK to write */
+#define __SSTR 0x0004          /* this is an sprintf/snprintf string */
+#define __SPGM 0x0008          /* fmt string is in progmem */
+#define __SERR 0x0010          /* found error */
+#define __SEOF 0x0020          /* found EOF */
+#define __SUNGET 0x040         /* ungetc() happened */
+#define __SMALLOC 0x80         /* handle is malloc()ed */
+#if 0
+/* possible future extensions, will require uint16_t flags */
+#define __SRW  0x0100          /* open for reading & writing */
+#define __SLBF 0x0200          /* line buffered */
+#define __SNBF 0x0400          /* unbuffered */
+#define __SMBF 0x0800          /* buf is from malloc */
+#endif
+       int     size;           /* size of buffer */
+       int     len;            /* characters read or written so far */
+       int     (*put)(char, struct __file *);  /* function to write one char to device */
+       int     (*get)(struct __file *);        /* function to read one char from device */
+       void    *udata;         /* User defined and accessible data. */
+};
+
+#endif /* not __DOXYGEN__ */
+
+/*@{*/
+/**
+   \c FILE is the opaque structure that is passed around between the
+   various standard IO functions.
+*/
+#define FILE   struct __file
+
+/**
+   Stream that will be used as an input stream by the simplified
+   functions that don't take a \c stream argument.
+
+   The first stream opened with read intent using \c fdevopen()
+   will be assigned to \c stdin.
+*/
+#define stdin (__iob[0])
+
+/**
+   Stream that will be used as an output stream by the simplified
+   functions that don't take a \c stream argument.
+
+   The first stream opened with write intent using \c fdevopen()
+   will be assigned to both, \c stdin, and \c stderr.
+*/
+#define stdout (__iob[1])
+
+/**
+   Stream destined for error output.  Unless specifically assigned,
+   identical to \c stdout.
+
+   If \c stderr should point to another stream, the result of
+   another \c fdevopen() must be explicitly assigned to it without
+   closing the previous \c stderr (since this would also close
+   \c stdout).
+*/
+#define stderr (__iob[2])
+
+/**
+   \c EOF declares the value that is returned by various standard IO
+   functions in case of an error.  Since the AVR platform (currently)
+   doesn't contain an abstraction for actual files, its origin as
+   "end of file" is somewhat meaningless here.
+*/
+#define EOF    (-1)
+
+/** This macro inserts a pointer to user defined data into a FILE
+    stream object.
+
+    The user data can be useful for tracking state in the put and get
+    functions supplied to the fdevopen() function. */
+#define fdev_set_udata(stream, u) do { (stream)->udata = u; } while(0)
+
+/** This macro retrieves a pointer to user defined data from a FILE
+    stream object. */
+#define fdev_get_udata(stream) ((stream)->udata)
+
+#if defined(__DOXYGEN__)
+/**
+   \brief Setup a user-supplied buffer as an stdio stream
+
+   This macro takes a user-supplied buffer \c stream, and sets it up
+   as a stream that is valid for stdio operations, similar to one that
+   has been obtained dynamically from fdevopen(). The buffer to setup
+   must be of type FILE.
+
+   The arguments \c put and \c get are identical to those that need to
+   be passed to fdevopen().
+
+   The \c rwflag argument can take one of the values _FDEV_SETUP_READ,
+   _FDEV_SETUP_WRITE, or _FDEV_SETUP_RW, for read, write, or read/write
+   intent, respectively.
+
+   \note No assignments to the standard streams will be performed by
+   fdev_setup_stream().  If standard streams are to be used, these
+   need to be assigned by the user.  See also under
+   \ref stdio_without_malloc "Running stdio without malloc()".
+ */
+#define fdev_setup_stream(stream, put, get, rwflag)
+#else  /* !DOXYGEN */
+#define fdev_setup_stream(stream, p, g, f) \
+       do { \
+               (stream)->put = p; \
+               (stream)->get = g; \
+               (stream)->flags = f; \
+               (stream)->udata = 0; \
+       } while(0)
+#endif /* DOXYGEN */
+
+#define _FDEV_SETUP_READ  __SRD        /**< fdev_setup_stream() with read intent */
+#define _FDEV_SETUP_WRITE __SWR        /**< fdev_setup_stream() with write intent */
+#define _FDEV_SETUP_RW    (__SRD|__SWR)        /**< fdev_setup_stream() with read/write intent */
+
+/**
+ * Return code for an error condition during device read.
+ *
+ * To be used in the get function of fdevopen().
+ */
+#define _FDEV_ERR (-1)
+
+/**
+ * Return code for an end-of-file condition during device read.
+ *
+ * To be used in the get function of fdevopen().
+ */
+#define _FDEV_EOF (-2)
+
+#if defined(__DOXYGEN__)
+/**
+   \brief Initializer for a user-supplied stdio stream
+
+   This macro acts similar to fdev_setup_stream(), but it is to be
+   used as the initializer of a variable of type FILE.
+
+   The remaining arguments are to be used as explained in
+   fdev_setup_stream().
+ */
+#define FDEV_SETUP_STREAM(put, get, rwflag)
+#else  /* !DOXYGEN */
+#define FDEV_SETUP_STREAM(p, g, f) \
+       { \
+               .put = p, \
+               .get = g, \
+               .flags = f, \
+               .udata = 0, \
+       }
+#endif /* DOXYGEN */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(__DOXYGEN__)
+/*
+ * Doxygen documentation can be found in fdevopen.c.
+ */
+
+extern struct __file *__iob[];
+
+#if defined(__STDIO_FDEVOPEN_COMPAT_12)
+/*
+ * Declare prototype for the discontinued version of fdevopen() that
+ * has been in use up to avr-libc 1.2.x.  The new implementation has
+ * some backwards compatibility with the old version.
+ */
+extern FILE *fdevopen(int (*__put)(char), int (*__get)(void),
+                      int __opts __attribute__((unused)));
+#else  /* !defined(__STDIO_FDEVOPEN_COMPAT_12) */
+/* New prototype for avr-libc 1.4 and above. */
+extern FILE *fdevopen(int (*__put)(char, FILE*), int (*__get)(FILE*));
+#endif /* defined(__STDIO_FDEVOPEN_COMPAT_12) */
+
+#endif /* not __DOXYGEN__ */
+
+/**
+   This function closes \c stream, and disallows and further
+   IO to and from it.
+
+   When using fdevopen() to setup the stream, a call to fclose() is
+   needed in order to free the internal resources allocated.
+
+   If the stream has been set up using fdev_setup_stream() or
+   FDEV_SETUP_STREAM(), use fdev_close() instead.
+
+   It currently always returns 0 (for success).
+*/
+extern int     fclose(FILE *__stream);
+
+/**
+   This macro frees up any library resources that might be associated
+   with \c stream.  It should be called if \c stream is no longer
+   needed, right before the application is going to destroy the
+   \c stream object itself.
+
+   (Currently, this macro evaluates to nothing, but this might change
+   in future versions of the library.)
+*/
+#if defined(__DOXYGEN__)
+# define fdev_close()
+#else
+# define fdev_close() ((void)0)
+#endif
+
+/**
+   \c vfprintf is the central facility of the \c printf family of
+   functions.  It outputs values to \c stream under control of a
+   format string passed in \c fmt.  The actual values to print are
+   passed as a variable argument list \c ap.
+
+   \c vfprintf returns the number of characters written to \c stream,
+   or \c EOF in case of an error.  Currently, this will only happen
+   if \c stream has not been opened with write intent.
+
+   The format string is composed of zero or more directives: ordinary
+   characters (not \c %), which are copied unchanged to the output
+   stream; and conversion specifications, each of which results in
+   fetching zero or more subsequent arguments.  Each conversion
+   specification is introduced by the \c % character.  The arguments must
+   properly correspond (after type promotion) with the conversion
+   specifier.  After the \c %, the following appear in sequence:
+
+   - Zero or more of the following flags:
+      <ul>
+      <li> \c # The value should be converted to an "alternate form".  For
+            c, d, i, s, and u conversions, this option has no effect.
+            For o conversions, the precision of the number is
+            increased to force the first character of the output
+            string to a zero (except if a zero value is printed with
+            an explicit precision of zero).  For x and X conversions,
+            a non-zero result has the string `0x' (or `0X' for X
+            conversions) prepended to it.</li>
+      <li> \c 0 (zero) Zero padding.  For all conversions, the converted
+            value is padded on the left with zeros rather than blanks.
+            If a precision is given with a numeric conversion (d, i,
+            o, u, i, x, and X), the 0 flag is ignored.</li>
+      <li> \c - A negative field width flag; the converted value is to be
+            left adjusted on the field boundary.  The converted value
+            is padded on the right with blanks, rather than on the
+            left with blanks or zeros.  A - overrides a 0 if both are
+            given.</li>
+      <li> ' ' (space) A blank should be left before a positive number
+            produced by a signed conversion (d, or i).</li>
+      <li> \c + A sign must always be placed before a number produced by a
+            signed conversion.  A + overrides a space if both are
+            used.</li>
+      </ul>
+      
+   -   An optional decimal digit string specifying a minimum field width.
+       If the converted value has fewer characters than the field width, it
+       will be padded with spaces on the left (or right, if the left-adjust­
+       ment flag has been given) to fill out the field width.
+   -   An optional precision, in the form of a period . followed by an
+       optional digit string.  If the digit string is omitted, the
+       precision is taken as zero.  This gives the minimum number of
+       digits to appear for d, i, o, u, x, and X conversions, or the
+       maximum number of characters to be printed from a string for \c s
+       conversions.
+   -   An optional \c l length modifier, that specifies that the
+       argument for the d, i, o, u, x, or X conversion is a \c "long int"
+       rather than \c int.
+   -   A character that specifies the type of conversion to be applied.
+
+   The conversion specifiers and their meanings are:
+
+   - \c diouxX The int (or appropriate variant) argument is converted
+           to signed decimal (d and i), unsigned octal (o), unsigned
+           decimal (u), or unsigned hexadecimal (x and X) notation.
+           The letters "abcdef" are used for x conversions; the
+           letters "ABCDEF" are used for X conversions.  The
+           precision, if any, gives the minimum number of digits that
+           must appear; if the converted value requires fewer digits,
+           it is padded on the left with zeros.
+   - \c p  The <tt>void *</tt> argument is taken as an unsigned integer,
+           and converted similarly as a <tt>%\#x</tt> command would do.
+   - \c c  The \c int argument is converted to an \c "unsigned char", and the
+           resulting character is written.
+   - \c s  The \c "char *" argument is expected to be a pointer to an array
+           of character type (pointer to a string).  Characters from
+           the array are written up to (but not including) a
+           terminating NUL character; if a precision is specified, no
+           more than the number specified are written.  If a precision
+           is given, no null character need be present; if the
+           precision is not specified, or is greater than the size of
+           the array, the array must contain a terminating NUL
+           character.
+   - \c %  A \c % is written.  No argument is converted.  The complete
+           conversion specification is "%%".
+   - \c eE The double argument is rounded and converted in the format
+           \c "[-]d.ddde±dd" where there is one digit before the
+           decimal-point character and the number of digits after it
+           is equal to the precision; if the precision is missing, it
+           is taken as 6; if the precision is zero, no decimal-point
+           character appears.  An \e E conversion uses the letter \c 'E'
+           (rather than \c 'e') to introduce the exponent.  The exponent
+           always contains two digits; if the value is zero,
+           the exponent is 00.
+   - \c fF The double argument is rounded and converted to decimal notation
+           in the format \c "[-]ddd.ddd", where the number of digits after the
+           decimal-point character is equal to the precision specification.
+           If the precision is missing, it is taken as 6; if the precision
+           is explicitly zero, no decimal-point character appears.  If a
+           decimal point appears, at least one digit appears before it.
+   - \c gG The double argument is converted in style \c f or \c e (or
+           \c F or \c E for \c G conversions).  The precision
+           specifies the number of significant digits.  If the
+           precision is missing, 6 digits are given; if the precision
+           is zero, it is treated as 1.  Style \c e is used if the
+           exponent from its conversion is less than -4 or greater
+           than or equal to the precision.  Trailing zeros are removed
+           from the fractional part of the result; a decimal point
+           appears only if it is followed by at least one digit.
+   - \c S  Similar to the \c s format, except the pointer is expected to
+           point to a program-memory (ROM) string instead of a RAM string.
+
+   In no case does a non-existent or small field width cause truncation of a
+   numeric field; if the result of a conversion is wider than the field
+   width, the field is expanded to contain the conversion result.
+
+   Since the full implementation of all the mentioned features becomes
+   fairly large, three different flavours of vfprintf() can be
+   selected using linker options.  The default vfprintf() implements
+   all the mentioned functionality except floating point conversions.
+   A minimized version of vfprintf() is available that only implements
+   the very basic integer and string conversion facilities, but none
+   of the additional options that can be specified using conversion
+   flags (these flags are parsed correctly from the format
+   specification, but then simply ignored).  This version can be
+   requested using the following \ref gcc_minusW "compiler options":
+
+   \code
+   -Wl,-u,vfprintf -lprintf_min
+   \endcode
+
+   If the full functionality including the floating point conversions
+   is required, the following options should be used:
+
+   \code
+   -Wl,-u,vfprintf -lprintf_flt -lm
+   \endcode
+
+   \par Limitations:
+   - The specified width and precision can be at most 127.
+   - For floating-point conversions, trailing digits will be lost if
+     a number close to DBL_MAX is converted with a precision > 0.
+
+ */
+
+extern int     vfprintf(FILE *__stream, const char *__fmt, va_list __ap);
+
+/**
+   Variant of \c vfprintf() that uses a \c fmt string that resides
+   in program memory.
+*/
+extern int     vfprintf_P(FILE *__stream, const char *__fmt, va_list __ap);
+
+/**
+   The function \c fputc sends the character \c c (though given as type
+   \c int) to \c stream.  It returns the character, or \c EOF in case
+   an error occurred.
+*/
+extern int     fputc(int __c, FILE *__stream);
+
+#if !defined(__DOXYGEN__)
+
+/* putc() function implementation, required by standard */
+extern int     putc(int __c, FILE *__stream);
+
+/* putchar() function implementation, required by standard */
+extern int     putchar(int __c);
+
+#endif /* not __DOXYGEN__ */
+
+/**
+   The macro \c putc used to be a "fast" macro implementation with a
+   functionality identical to fputc().  For space constraints, in
+   \c avr-libc, it is just an alias for \c fputc.
+*/
+#define putc(__c, __stream) fputc(__c, __stream)
+
+/**
+   The macro \c putchar sends character \c c to \c stdout.
+*/
+#define putchar(__c) fputc(__c, stdout)
+
+/**
+   The function \c printf performs formatted output to stream
+   \c stderr.  See \c vfprintf() for details.
+*/
+extern int     printf(const char *__fmt, ...);
+
+/**
+   Variant of \c printf() that uses a \c fmt string that resides
+   in program memory.
+*/
+extern int     printf_P(const char *__fmt, ...);
+
+/**
+   The function \c vprintf performs formatted output to stream
+   \c stdout, taking a variable argument list as in vfprintf().
+
+   See vfprintf() for details.
+*/
+extern int     vprintf(const char *__fmt, va_list __ap);
+
+/**
+   Variant of \c printf() that sends the formatted characters
+   to string \c s.
+*/
+extern int     sprintf(char *__s, const char *__fmt, ...);
+
+/**
+   Variant of \c sprintf() that uses a \c fmt string that resides
+   in program memory.
+*/
+extern int     sprintf_P(char *__s, const char *__fmt, ...);
+
+/**
+   Like \c sprintf(), but instead of assuming \c s to be of infinite
+   size, no more than \c n characters (including the trailing NUL
+   character) will be converted to \c s.
+
+   Returns the number of characters that would have been written to
+   \c s if there were enough space.
+*/
+extern int     snprintf(char *__s, size_t __n, const char *__fmt, ...);
+
+/**
+   Variant of \c snprintf() that uses a \c fmt string that resides
+   in program memory.
+*/
+extern int     snprintf_P(char *__s, size_t __n, const char *__fmt, ...);
+
+/**
+   Like \c sprintf() but takes a variable argument list for the
+   arguments.
+*/
+extern int     vsprintf(char *__s, const char *__fmt, va_list ap);
+
+/**
+   Variant of \c vsprintf() that uses a \c fmt string that resides
+   in program memory.
+*/
+extern int     vsprintf_P(char *__s, const char *__fmt, va_list ap);
+
+/**
+   Like \c vsprintf(), but instead of assuming \c s to be of infinite
+   size, no more than \c n characters (including the trailing NUL
+   character) will be converted to \c s.
+
+   Returns the number of characters that would have been written to
+   \c s if there were enough space.
+*/
+extern int     vsnprintf(char *__s, size_t __n, const char *__fmt, va_list ap);
+
+/**
+   Variant of \c vsnprintf() that uses a \c fmt string that resides
+   in program memory.
+*/
+extern int     vsnprintf_P(char *__s, size_t __n, const char *__fmt, va_list ap);
+/**
+   The function \c fprintf performs formatted output to \c stream.
+   See \c vfprintf() for details.
+*/
+extern int     fprintf(FILE *__stream, const char *__fmt, ...);
+
+/**
+   Variant of \c fprintf() that uses a \c fmt string that resides
+   in program memory.
+*/
+extern int     fprintf_P(FILE *__stream, const char *__fmt, ...);
+
+/**
+   Write the string pointed to by \c str to stream \c stream.
+
+   Returns 0 on success and EOF on error.
+*/
+extern int     fputs(const char *__str, FILE *__stream);
+
+/**
+   Variant of fputs() where \c str resides in program memory.
+*/
+extern int     fputs_P(const char *__str, FILE *__stream);
+
+/**
+   Write the string pointed to by \c str, and a trailing newline
+   character, to \c stdout.
+*/
+extern int     puts(const char *__str);
+
+/**
+   Variant of puts() where \c str resides in program memory.
+*/
+extern int     puts_P(const char *__str);
+
+/**
+   Write \c nmemb objects, \c size bytes each, to \c stream.
+   The first byte of the first object is referenced by \c ptr.
+
+   Returns the number of objects successfully written, i. e.
+   \c nmemb unless an output error occured.
+ */
+extern size_t  fwrite(const void *__ptr, size_t __size, size_t __nmemb,
+                      FILE *__stream);
+
+/**
+   The function \c fgetc reads a character from \c stream.  It returns
+   the character, or \c EOF in case end-of-file was encountered or an
+   error occurred.  The routines feof() or ferror() must be used to
+   distinguish between both situations.
+*/
+extern int     fgetc(FILE *__stream);
+
+#if !defined(__DOXYGEN__)
+
+/* getc() function implementation, required by standard */
+extern int     getc(FILE *__stream);
+
+/* getchar() function implementation, required by standard */
+extern int     getchar(void);
+
+#endif /* not __DOXYGEN__ */
+
+/**
+   The macro \c getc used to be a "fast" macro implementation with a
+   functionality identical to fgetc().  For space constraints, in
+   \c avr-libc, it is just an alias for \c fgetc.
+*/
+#define getc(__stream) fgetc(__stream)
+
+/**
+   The macro \c getchar reads a character from \c stdin.  Return
+   values and error handling is identical to fgetc().
+*/
+#define getchar() fgetc(stdin)
+
+/**
+   The ungetc() function pushes the character \c c (converted to an
+   unsigned char) back onto the input stream pointed to by \c stream.
+   The pushed-back character will be returned by a subsequent read on
+   the stream.
+
+   Currently, only a single character can be pushed back onto the
+   stream.
+   
+   The ungetc() function returns the character pushed back after the
+   conversion, or \c EOF if the operation fails.  If the value of the
+   argument \c c character equals \c EOF, the operation will fail and
+   the stream will remain unchanged.
+*/
+extern int     ungetc(int __c, FILE *__stream);
+
+/**
+   Read at most <tt>size - 1</tt> bytes from \c stream, until a
+   newline character was encountered, and store the characters in the
+   buffer pointed to by \c str.  Unless an error was encountered while
+   reading, the string will then be terminated with a \c NUL
+   character.
+
+   If an error was encountered, the function returns NULL and sets the
+   error flag of \c stream, which can be tested using ferror().
+   Otherwise, a pointer to the string will be returned.  */
+extern char    *fgets(char *__str, int __size, FILE *__stream);
+
+/**
+   Similar to fgets() except that it will operate on stream \c stdin,
+   and the trailing newline (if any) will not be stored in the string.
+   It is the caller's responsibility to provide enough storage to hold
+   the characters read.  */
+extern char    *gets(char *__str);
+
+/**
+   Read \c nmemb objects, \c size bytes each, from \c stream,
+   to the buffer pointed to by \c ptr.
+
+   Returns the number of objects successfully read, i. e.
+   \c nmemb unless an input error occured or end-of-file was
+   encountered.  feof() and ferror() must be used to distinguish
+   between these two conditions.
+ */
+extern size_t  fread(void *__ptr, size_t __size, size_t __nmemb,
+                     FILE *__stream);
+
+/**
+   Clear the error and end-of-file flags of \c stream.
+ */
+extern void    clearerr(FILE *__stream);
+
+#if !defined(__DOXYGEN__)
+/* fast inlined version of clearerr() */
+#define clearerror(s) do { (s)->flags &= ~(__SERR | __SEOF); } while(0)
+#endif /* !defined(__DOXYGEN__) */
+
+/**
+   Test the end-of-file flag of \c stream.  This flag can only be cleared
+   by a call to clearerr().
+ */
+extern int     feof(FILE *__stream);
+
+#if !defined(__DOXYGEN__)
+/* fast inlined version of feof() */
+#define feof(s) ((s)->flags & __SEOF)
+#endif /* !defined(__DOXYGEN__) */
+
+/**
+   Test the error flag of \c stream.  This flag can only be cleared
+   by a call to clearerr().
+ */
+extern int     ferror(FILE *__stream);
+
+#if !defined(__DOXYGEN__)
+/* fast inlined version of ferror() */
+#define ferror(s) ((s)->flags & __SERR)
+#endif /* !defined(__DOXYGEN__) */
+
+/**
+   Formatted input.  This function is the heart of the \c scanf
+   family of functions.
+
+   Characters are read from \c stream and processed in a way
+   described by \c fmt.  Conversion results will be assigned to the
+   parameters passed via \c ap.
+
+   The format string \c fmt is scanned for conversion specifications.
+   Anything that doesn't comprise a conversion specification is taken
+   as text that is matched literally against the input.  White space
+   in the format string will match any white space in the data
+   (including none), all other characters match only itself.
+   Processing is aborted as soon as the data and format string no
+   longer match, or there is an error or end-of-file condition on
+   \c stream.
+
+   Most conversions skip leading white space before starting the
+   actual conversion.
+
+   Conversions are introduced with the character \b %.  Possible
+   options can follow the \b %:
+
+   - a \c * indicating that the conversion should be performed but
+     the conversion result is to be discarded; no parameters will
+     be processed from \c ap,
+   - the character \c h indicating that the argument is a pointer
+     to <tt>short int</tt> (rather than <tt>int</tt>),
+   - the character \c l indicating that the argument is a pointer
+     to <tt>long int</tt> (rather than <tt>int</tt>, for integer
+     type conversions), or a pointer to \c double (for floating
+     point conversions).
+
+   In addition, a maximal field width may be specified as a nonzero
+   positive decimal integer, which will restrict the conversion to at
+   most this many characters from the input stream.  This field width
+   is limited to at most 127 characters which is also the default
+   value (except for the <tt>%c</tt> conversion that defaults to 1).
+
+   The following conversion flags are supported:
+
+   - \c % Matches a literal \c % character.  This is not a conversion.
+   - \c d Matches an optionally signed decimal integer; the next
+     pointer must be a pointer to \c int.
+   - \c i Matches an optionally signed integer; the next pointer must
+     be a pointer to \c int.  The integer is read in base 16 if it
+     begins with \b 0x or \b 0X, in base 8 if it begins with \b 0, and
+     in base 10 otherwise.  Only characters that correspond to the
+     base are used.
+   - \c o Matches an octal integer; the next pointer must be a pointer to
+     <tt>unsigned int</tt>.
+   - \c u Matches an optionally signed decimal integer; the next
+     pointer must be a pointer to <tt>unsigned int</tt>.
+   - \c x Matches an optionally signed hexadecimal integer; the next
+     pointer must be a pointer to <tt>unsigned int</tt>.
+   - \c f Matches an optionally signed floating-point number; the next
+     pointer must be a pointer to \c float.
+   - <tt>e, g, E, G</tt> Equivalent to \c f.
+   - \c s
+     Matches a sequence of non-white-space characters; the next pointer
+     must be a pointer to \c char, and the array must be large enough to
+     accept all the sequence and the terminating \c NUL character.  The
+     input string stops at white space or at the maximum field width,
+     whichever occurs first.
+   - \c c
+     Matches a sequence of width count characters (default 1); the next
+     pointer must be a pointer to \c char, and there must be enough room
+     for all the characters (no terminating \c NUL is added).  The usual
+     skip of leading white space is suppressed.  To skip white space
+     first, use an explicit space in the format.
+   - \c [
+     Matches a nonempty sequence of characters from the specified set
+     of accepted characters; the next pointer must be a pointer to \c
+     char, and there must be enough room for all the characters in the
+     string, plus a terminating \c NUL character.  The usual skip of
+     leading white space is suppressed.  The string is to be made up
+     of characters in (or not in) a particular set; the set is defined
+     by the characters between the open bracket \c [ character and a
+     close bracket \c ] character.  The set excludes those characters
+     if the first character after the open bracket is a circumflex
+     \c ^.  To include a close bracket in the set, make it the first
+     character after the open bracket or the circumflex; any other
+     position will end the set.  The hyphen character \c - is also
+     special; when placed between two other characters, it adds all
+     intervening characters to the set.  To include a hyphen, make it
+     the last character before the final close bracket.  For instance,
+     <tt>[^]0-9-]</tt> means the set of <em>everything except close
+     bracket, zero through nine, and hyphen</em>.  The string ends
+     with the appearance of a character not in the (or, with a
+     circumflex, in) set or when the field width runs out.
+   - \c p
+     Matches a pointer value (as printed by <tt>%p</tt> in printf()); the
+     next pointer must be a pointer to \c void.
+   - \c n
+     Nothing is expected; instead, the number of characters consumed
+     thus far from the input is stored through the next pointer, which
+     must be a pointer to \c int.  This is not a conversion, although it
+     can be suppressed with the \c * flag.
+
+     These functions return the number of input items assigned, which
+     can be fewer than provided for, or even zero, in the event of a
+     matching failure.  Zero indicates that, while there was input
+     available, no conversions were assigned; typically this is due
+     to an invalid input character, such as an alphabetic character
+     for a <tt>%d</tt> conversion.  The value \c EOF is returned if an input
+     failure occurs before any conversion such as an end-of-file
+     occurs.  If an error or end-of-file occurs after conversion has
+     begun, the number of conversions which were successfully
+     completed is returned.
+
+     By default, all the conversions described above are available
+     except the floating-point conversions, and the <tt>\%[</tt> conversion.
+     These conversions will be available in the extended version
+     provided by the library \c libscanf_flt.a.  Note that either of
+     these conversions requires the availability of a buffer that
+     needs to be obtained at run-time using malloc().  If this buffer
+     cannot be obtained, the operation is aborted, returning the
+     value \c EOF.  To link a program against the extended version,
+     use the following compiler flags in the link stage:
+
+     \code
+     -Wl,-u,vfscanf -lscanf_flt -lm
+     \endcode
+
+     A third version is available for environments that are tight
+     on space.  This version is provided in the library
+     \c libscanf_min.a, and can be requested using the following
+     options in the link stage:
+
+     \code
+     -Wl,-u,vfscanf -lscanf_min -lm
+     \endcode
+
+     In addition to the restrictions of the standard version, this
+     version implements no field width specification, no conversion
+     assignment suppression flag (\c *), no <tt>%n</tt> specification, and
+     no general format character matching at all.  All characters in
+     \c fmt that do not comprise a conversion specification will
+     simply be ignored, including white space (that is normally used
+     to consume \e any amount of white space in the input stream).
+     However, the usual skip of initial white space in the formats
+     that support it is implemented.
+*/
+extern int     vfscanf(FILE *__stream, const char *__fmt, va_list __ap);
+
+/**
+   Variant of vfscanf() using a \c fmt string in program memory.
+ */
+extern int     vfscanf_P(FILE *__stream, const char *__fmt, va_list __ap);
+
+/**
+   The function \c fscanf performs formatted input, reading the
+   input data from \c stream.
+
+   See vfscanf() for details.
+ */
+extern int     fscanf(FILE *__stream, const char *__fmt, ...);
+
+/**
+   Variant of fscanf() using a \c fmt string in program memory.
+ */
+extern int     fscanf_P(FILE *__stream, const char *__fmt, ...);
+
+/**
+   The function \c scanf performs formatted input from stream \c stdin.
+
+   See vfscanf() for details.
+ */
+extern int     scanf(const char *__fmt, ...);
+
+/**
+   Variant of scanf() where \c fmt resides in program memory.
+ */
+extern int     scanf_P(const char *__fmt, ...);
+
+/**
+   The function \c vscanf performs formatted input from stream
+   \c stdin, taking a variable argument list as in vfscanf().
+
+   See vfscanf() for details.
+*/
+extern int     vscanf(const char *__fmt, va_list __ap);
+
+/**
+   The function \c sscanf performs formatted input, reading the
+   input data from the buffer pointed to by \c buf.
+
+   See vfscanf() for details.
+ */
+extern int     sscanf(const char *__buf, const char *__fmt, ...);
+
+/**
+   Variant of sscanf() using a \c fmt string in program memory.
+ */
+extern int     sscanf_P(const char *__buf, const char *__fmt, ...);
+
+#if defined(__DOXYGEN__)
+/**
+   Flush \c stream.
+
+   This is a null operation provided for source-code compatibility
+   only, as the standard IO implementation currently does not perform
+   any buffering.
+ */
+extern int     fflush(FILE *stream);
+#else
+static __inline__ int fflush(FILE *stream __attribute__((unused)))
+{
+       return 0;
+}
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/*@}*/
+
+/*
+ * The following constants are currently not used by avr-libc's
+ * stdio subsystem.  They are defined here since the gcc build
+ * environment expects them to be here.
+ */
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#define SEEK_END 2
+
+#endif /* __ASSEMBLER */
+
+#endif /* _STDLIB_H_ */
diff --git a/tos/lib/tosthreads/lib/printf/printf.h b/tos/lib/tosthreads/lib/printf/printf.h
new file mode 100644 (file)
index 0000000..a21a83d
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * "Copyright (c) 2006 Washington University in St. Louis.
+ * 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 WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON
+ * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * WASHINGTON UNIVERSITY IN ST. LOUIS 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 WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+ * MODIFICATIONS."
+ */
+
+/**
+ *
+ * @author Kevin Klues (klueska@cs.wustl.edu)
+ * @version $Revision$
+ * @date $Date$
+ */
+
+#ifndef PRINTF_H
+#define PRINTF_H
+
+#ifndef PRINTF_BUFFER_SIZE
+#define PRINTF_BUFFER_SIZE 255 
+#endif
+
+#if PRINTF_BUFFER_SIZE > 255
+  #define PrintfQueueC BigQueueC
+  #define PrintfQueue  BigQueue
+#else
+  #define PrintfQueueC QueueC
+  #define PrintfQueue  Queue
+#endif
+
+#ifdef _H_msp430hardware_h
+  #include <stdio.h>
+#endif
+#ifdef _H_atmega128hardware_H
+  #include "avr_stdio.h"
+#endif
+#include "message.h"
+
+typedef nx_struct printf_msg {
+  nx_uint8_t buffer[TOSH_DATA_LENGTH];
+} printf_msg_t;
+
+enum {
+  AM_PRINTF_MSG = 100,
+};
+
+int printfflush();
+
+#endif //PRINTF_H
+
diff --git a/tos/lib/tosthreads/platforms/mica2/chips/cc1000/HplCC1000InitP.nc b/tos/lib/tosthreads/platforms/mica2/chips/cc1000/HplCC1000InitP.nc
new file mode 100644 (file)
index 0000000..7362325
--- /dev/null
@@ -0,0 +1,57 @@
+// $Id$
+/*                                                                     tab:4
+ * "Copyright (c) 2004-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) 2004-2005 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.
+ */
+/**
+ * Hardware initialisation for the CC1000 radio. This component is always
+ * included even if the radio is not used.
+ *
+ * @author David Gay
+ */
+configuration HplCC1000InitP {
+  provides interface Init as PlatformInit;
+}
+implementation {
+  components HplCC1000P, HplCC1000SpiP, HplAtm128GeneralIOC as IO;
+
+  PlatformInit = HplCC1000P;
+  PlatformInit = HplCC1000SpiP;
+
+  HplCC1000P.CHP_OUT -> IO.PortA6;
+  HplCC1000P.PALE -> IO.PortD4;
+  HplCC1000P.PCLK -> IO.PortD6;
+  HplCC1000P.PDATA -> IO.PortD7;
+
+  HplCC1000SpiP.SpiSck -> IO.PortB1;
+  HplCC1000SpiP.SpiMiso -> IO.PortB3;
+  HplCC1000SpiP.SpiMosi -> IO.PortB2;
+  HplCC1000SpiP.OC1C -> IO.PortB7;
+  
+  components PlatformInterruptC;
+  HplCC1000SpiP.PlatformInterrupt -> PlatformInterruptC;
+}
diff --git a/tos/lib/tosthreads/platforms/mica2/chips/cc1000/HplCC1000SpiP.nc b/tos/lib/tosthreads/platforms/mica2/chips/cc1000/HplCC1000SpiP.nc
new file mode 100644 (file)
index 0000000..116b289
--- /dev/null
@@ -0,0 +1,116 @@
+// $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.
+ */
+/**
+ * Low-level functions to access the CC1000 bus. Built using the mica2
+ * hardware SPI.
+ *
+ * @author Jaein Jeong
+ * @author Philip buonadonna
+ */
+
+
+module HplCC1000SpiP {
+  provides interface Init as PlatformInit;
+  provides interface HplCC1000Spi;
+  //uses interface PowerManagement;
+  uses {
+    interface GeneralIO as SpiSck;
+    interface GeneralIO as SpiMiso;
+    interface GeneralIO as SpiMosi;
+    interface GeneralIO as OC1C;
+    interface PlatformInterrupt;
+  }
+}
+implementation
+{
+  uint8_t outgoingByte;
+
+  command error_t PlatformInit.init() {
+    call SpiSck.makeInput();
+    call OC1C.makeInput();
+    call HplCC1000Spi.rxMode();
+    return SUCCESS;
+  }
+
+  AVR_ATOMIC_HANDLER(SIG_SPI) {
+    register uint8_t temp = SPDR;
+    SPDR = outgoingByte;
+    signal HplCC1000Spi.dataReady(temp);
+    call PlatformInterrupt.postAmble();
+  }
+  default async event void HplCC1000Spi.dataReady(uint8_t data) { }
+  
+
+  async command void HplCC1000Spi.writeByte(uint8_t data) {
+    atomic outgoingByte = data;
+  }
+
+  async command bool HplCC1000Spi.isBufBusy() {
+    return bit_is_clear(SPSR, SPIF);
+  }
+
+  async command uint8_t HplCC1000Spi.readByte() {
+    return SPDR;
+  }
+
+  async command void HplCC1000Spi.enableIntr() {
+    //sbi(SPCR,SPIE);
+    SPCR = 0xc0;
+    CLR_BIT(DDRB, 0);
+    //call PowerManagement.adjustPower();
+  }
+
+  async command void HplCC1000Spi.disableIntr() {
+    CLR_BIT(SPCR, SPIE);
+    SET_BIT(DDRB, 0);
+    CLR_BIT(PORTB, 0);
+    //call PowerManagement.adjustPower();
+  }
+
+  async command void HplCC1000Spi.initSlave() {
+    atomic {
+      CLR_BIT(SPCR, CPOL);             // Set proper polarity...
+      CLR_BIT(SPCR, CPHA);             // ...and phase
+      SET_BIT(SPCR, SPIE);     // enable spi port
+      SET_BIT(SPCR, SPE);
+    } 
+  }
+       
+  async command void HplCC1000Spi.txMode() {
+    call SpiMiso.makeOutput();
+    call SpiMosi.makeOutput();
+  }
+
+  async command void HplCC1000Spi.rxMode() {
+    call SpiMiso.makeInput();
+    call SpiMosi.makeInput();
+  }
+}
diff --git a/tos/lib/tosthreads/platforms/telosa/TelosSerialP.nc b/tos/lib/tosthreads/platforms/telosa/TelosSerialP.nc
new file mode 100644 (file)
index 0000000..fcfc91d
--- /dev/null
@@ -0,0 +1,23 @@
+module TelosSerialP {
+  provides interface StdControl;
+  provides interface Msp430UartConfigure;
+  uses interface Resource;
+}
+implementation {
+  
+  msp430_uart_union_config_t msp430_uart_telos_config = { {ubr: UBR_1MHZ_57600, umctl: UMCTL_1MHZ_57600, ssel: 0x02, pena: 0, pev: 0, spb: 0, clen: 1, listen: 0, mm: 0, ckpl: 0, urxse: 0, urxeie: 1, urxwie: 0, utxe : 1, urxe : 1} };
+
+  command error_t StdControl.start(){
+    return call Resource.immediateRequest();
+  }
+  command error_t StdControl.stop(){
+    call Resource.release();
+    return SUCCESS;
+  }
+  event void Resource.granted(){}
+
+  async command msp430_uart_union_config_t* Msp430UartConfigure.getConfig() {
+    return &msp430_uart_telos_config;
+  }
+  
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingHamamatsuS10871TsrC.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingHamamatsuS10871TsrC.nc
new file mode 100644 (file)
index 0000000..123fdeb
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+generic configuration BlockingHamamatsuS10871TsrC() {
+  provides interface DeviceMetadata;
+  provides interface BlockingRead<uint16_t> as Read;
+  provides interface BlockingReadStream<uint16_t> as ReadStream;
+}
+implementation {
+  components new BlockingAdcReadClientC() as AdcReadClientC;
+  Read = AdcReadClientC;
+
+  components new BlockingAdcReadStreamClientC() as AdcReadStreamClientC;
+  ReadStream = AdcReadStreamClientC;
+
+  components HamamatsuS10871TsrP;
+  DeviceMetadata = HamamatsuS10871TsrP;
+  AdcReadClientC.AdcConfigure -> HamamatsuS10871TsrP;
+  AdcReadStreamClientC.AdcConfigure -> HamamatsuS10871TsrP;
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingHamamatsuS1087ParC.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingHamamatsuS1087ParC.nc
new file mode 100644 (file)
index 0000000..40b647c
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+generic configuration BlockingHamamatsuS1087ParC() {
+  provides interface DeviceMetadata;
+  provides interface BlockingRead<uint16_t> as Read;
+  provides interface BlockingReadStream<uint16_t> as ReadStream;
+}
+implementation {
+  components new BlockingAdcReadClientC() as AdcReadClientC;
+  Read = AdcReadClientC;
+
+  components new BlockingAdcReadStreamClientC() as AdcReadStreamClientC;
+  ReadStream = AdcReadStreamClientC;
+
+  components HamamatsuS1087ParP;
+  DeviceMetadata = HamamatsuS1087ParP;
+  AdcReadClientC.AdcConfigure -> HamamatsuS1087ParP;
+  AdcReadStreamClientC.AdcConfigure -> HamamatsuS1087ParP;
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingSensirionSht11C.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingSensirionSht11C.nc
new file mode 100644 (file)
index 0000000..fc49810
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+generic configuration BlockingSensirionSht11C() {
+  provides interface BlockingRead<uint16_t> as Temperature;
+  provides interface DeviceMetadata as TemperatureMetadata;
+  provides interface BlockingRead<uint16_t> as Humidity;
+  provides interface DeviceMetadata as HumidityMetadata;
+}
+implementation {
+  components new BlockingSensirionSht11ReaderP() as SensirionSht11ReaderP;
+
+  Temperature = SensirionSht11ReaderP.Temperature;
+  TemperatureMetadata = SensirionSht11ReaderP.TemperatureMetadata;
+  Humidity = SensirionSht11ReaderP.Humidity;
+  HumidityMetadata = SensirionSht11ReaderP.HumidityMetadata;
+
+  components HalSensirionSht11C;
+
+  enum { TEMP_KEY = unique("Sht11.Resource") };
+  enum { HUM_KEY = unique("Sht11.Resource") };
+
+  SensirionSht11ReaderP.TempResource -> HalSensirionSht11C.Resource[ TEMP_KEY ];
+  SensirionSht11ReaderP.Sht11Temp -> HalSensirionSht11C.SensirionSht11[ TEMP_KEY ];
+  SensirionSht11ReaderP.HumResource -> HalSensirionSht11C.Resource[ HUM_KEY ];
+  SensirionSht11ReaderP.Sht11Hum -> HalSensirionSht11C.SensirionSht11[ HUM_KEY ];
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingSensirionSht11ReaderImplP.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingSensirionSht11ReaderImplP.nc
new file mode 100644 (file)
index 0000000..05be001
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include <SensirionSht11.h>
+
+generic module BlockingSensirionSht11ReaderImplP() {
+  provides {
+    interface BlockingRead<uint16_t> as BlockingTemperature;
+    interface BlockingRead<uint16_t> as BlockingHumidity;
+  }
+  uses {
+    interface Read<uint16_t> as Temperature;
+    interface Read<uint16_t> as Humidity;
+    
+    interface SystemCall;
+  }
+}
+implementation {
+  typedef struct params {
+    uint16_t* val;
+    error_t   error;
+  } params_t;
+
+  syscall_t* temp_call = NULL;
+  syscall_t* hum_call = NULL;
+  
+  void tempTask(syscall_t* s) {
+    params_t* p = s->params;
+    p->error = call Temperature.read();
+    if(p->error != SUCCESS) {
+      call SystemCall.finish(s);
+    }  
+  }
+  
+  void humTask(syscall_t* s) {
+    params_t* p = s->params;
+    p->error = call Humidity.read();
+    if(p->error != SUCCESS) {
+      call SystemCall.finish(s);
+    }  
+  }
+  
+  error_t blockingRead(syscall_t** s_call, uint16_t* val, void* task_ptr) {
+    syscall_t s;
+    params_t p;
+    atomic {
+      if(*s_call != NULL)
+        return EBUSY;
+      *s_call = &s;
+    }
+    
+    p.val = val;
+    call SystemCall.start(task_ptr, &s, INVALID_ID, &p);
+    
+    atomic {
+      *s_call = NULL;
+      return p.error;
+    }    
+  }
+
+  command error_t BlockingTemperature.read(uint16_t* val) {
+    return blockingRead(&temp_call, val, tempTask);
+  }
+  
+  command error_t BlockingHumidity.read(uint16_t* val) {
+    return blockingRead(&hum_call, val, humTask);
+  }
+
+  event void Temperature.readDone( error_t result, uint16_t val ) {
+    params_t* p = temp_call->params;
+    p->error = result;
+    *(p->val) = val;
+    call SystemCall.finish(temp_call);
+  }  
+  
+  event void Humidity.readDone( error_t result, uint16_t val ) {
+    params_t* p = hum_call->params;
+    p->error = result;
+    *(p->val) = val;
+    call SystemCall.finish(hum_call);
+  }
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingSensirionSht11ReaderP.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/BlockingSensirionSht11ReaderP.nc
new file mode 100644 (file)
index 0000000..5ff2782
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "thread.h"
+
+generic configuration BlockingSensirionSht11ReaderP() {
+  provides interface DeviceMetadata as TemperatureMetadata;
+  provides interface BlockingRead<uint16_t> as Temperature;
+  provides interface DeviceMetadata as HumidityMetadata;
+  provides interface BlockingRead<uint16_t> as Humidity;
+  
+  uses interface Resource as TempResource;
+  uses interface Resource as HumResource;
+  uses interface SensirionSht11 as Sht11Temp;
+  uses interface SensirionSht11 as Sht11Hum;
+}
+implementation {
+  components new SensirionSht11ReaderP();
+  components new BlockingSensirionSht11ReaderImplP();
+  
+  TemperatureMetadata = SensirionSht11ReaderP.TemperatureMetadata;
+  Temperature = BlockingSensirionSht11ReaderImplP.BlockingTemperature;
+  HumidityMetadata = SensirionSht11ReaderP.HumidityMetadata;
+  Humidity = BlockingSensirionSht11ReaderImplP.BlockingHumidity;
+  
+  TempResource = SensirionSht11ReaderP.TempResource;
+  HumResource = SensirionSht11ReaderP.HumResource;
+  Sht11Temp = SensirionSht11ReaderP.Sht11Temp;
+  Sht11Hum = SensirionSht11ReaderP.Sht11Hum;
+  
+  BlockingSensirionSht11ReaderImplP.Temperature -> SensirionSht11ReaderP.Temperature;
+  BlockingSensirionSht11ReaderImplP.Humidity -> SensirionSht11ReaderP.Humidity;
+  
+  components SystemCallC;
+  BlockingSensirionSht11ReaderImplP.SystemCall -> SystemCallC;
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS10871TsrC.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS10871TsrC.nc
new file mode 100644 (file)
index 0000000..e90f0e5
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+configuration CHamamatsuS10871TsrC {}
+implementation {
+  components CHamamatsuS10871TsrP;
+  components new BlockingHamamatsuS10871TsrC();
+             
+  CHamamatsuS10871TsrP.DeviceMetadata -> BlockingHamamatsuS10871TsrC.DeviceMetadata;
+  CHamamatsuS10871TsrP.Read -> BlockingHamamatsuS10871TsrC.Read;
+  CHamamatsuS10871TsrP.ReadStream -> BlockingHamamatsuS10871TsrC.ReadStream;
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS10871TsrP.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS10871TsrP.nc
new file mode 100644 (file)
index 0000000..8346ee8
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module CHamamatsuS10871TsrP {
+  uses {
+    interface DeviceMetadata;
+    interface BlockingRead<uint16_t> as Read;
+    interface BlockingReadStream<uint16_t> as ReadStream;
+  }
+}
+implementation {
+  error_t hamamatsuS10871_tsr_read(uint16_t* val) @C() @spontaneous() {
+    return call Read.read(val);
+  }
+  error_t hamamatsuS10871_tsr_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() @spontaneous() {
+    return call ReadStream.read(usPeriod, buf, count);                                           
+  }                                            
+  uint8_t hamamatsuS10871_tsr_getNumBits() @C() @spontaneous() {
+    return call DeviceMetadata.getSignificantBits();
+  }
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS1087ParC.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS1087ParC.nc
new file mode 100644 (file)
index 0000000..8466647
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+configuration CHamamatsuS1087ParC {}
+implementation {
+  components CHamamatsuS1087ParP;
+  components new BlockingHamamatsuS1087ParC();
+             
+  CHamamatsuS1087ParP.DeviceMetadata -> BlockingHamamatsuS1087ParC.DeviceMetadata;
+  CHamamatsuS1087ParP.Read -> BlockingHamamatsuS1087ParC.Read;
+  CHamamatsuS1087ParP.ReadStream -> BlockingHamamatsuS1087ParC.ReadStream;
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS1087ParP.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS1087ParP.nc
new file mode 100644 (file)
index 0000000..683b606
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module CHamamatsuS1087ParP {
+  uses {
+    interface DeviceMetadata;
+    interface BlockingRead<uint16_t> as Read;
+    interface BlockingReadStream<uint16_t> as ReadStream;
+   }
+}
+implementation {
+
+  error_t hamamatsuS1087_par_read(uint16_t* val) @C() @spontaneous() {
+    return call Read.read(val);
+  }
+  error_t hamamatsuS1087_par_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() @spontaneous() {
+    return call ReadStream.read(usPeriod, buf, count);                                           
+  }                                           
+  uint8_t hamamatsuS1087_par_getNumBits() @C() @spontaneous() {
+    return call DeviceMetadata.getSignificantBits();
+  }
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/CSensirionSht11C.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/CSensirionSht11C.nc
new file mode 100644 (file)
index 0000000..b30196e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+configuration CSensirionSht11C {}
+implementation {
+  components CSensirionSht11P;
+  components new BlockingSensirionSht11C();
+             
+  CSensirionSht11P.Temperature -> BlockingSensirionSht11C.Temperature;
+  CSensirionSht11P.TemperatureMetadata -> BlockingSensirionSht11C.TemperatureMetadata;
+  CSensirionSht11P.Humidity -> BlockingSensirionSht11C.Humidity;
+  CSensirionSht11P.HumidityMetadata -> BlockingSensirionSht11C.HumidityMetadata;
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/CSensirionSht11P.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/CSensirionSht11P.nc
new file mode 100644 (file)
index 0000000..38ba3e8
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module CSensirionSht11P {
+  uses {
+    interface BlockingRead<uint16_t> as Temperature;
+    interface DeviceMetadata as TemperatureMetadata;
+    interface BlockingRead<uint16_t> as Humidity;
+    interface DeviceMetadata as HumidityMetadata;  
+  }
+}
+implementation {
+  error_t sensirionSht11_humidity_read(uint16_t* val) @C() @spontaneous() {
+    return call Humidity.read(val);
+  }
+  uint8_t sensirionSht11_humidity_getNumBits() @C() @spontaneous() {
+    return call HumidityMetadata.getSignificantBits();
+  }
+  error_t sensirionSht11_temperature_read(uint16_t* val) @C() @spontaneous() {
+    return call Temperature.read(val);
+  }
+  uint8_t sensirionSht11_temperature_getNumBits() @C() @spontaneous() {
+    return call TemperatureMetadata.getSignificantBits();
+  }
+}
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/tmote_onboard_sensors.h b/tos/lib/tosthreads/sensorboards/tmote_onboard/tmote_onboard_sensors.h
new file mode 100644 (file)
index 0000000..bf37969
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+  
+#ifndef TMOTE_ONBOARD_SENSORS_H
+#define TMOTE_ONBOARD_SENSORS_H
+
+#include "tosthread_sensirionSht11.h"
+#include "tosthread_hamamatsuS1087.h"
+#include "tosthread_hamamatsuS10871.h"
+
+#endif //TMOTE_ONBOARD_SENSORS_H
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/tosthread_hamamatsuS1087.h b/tos/lib/tosthreads/sensorboards/tmote_onboard/tosthread_hamamatsuS1087.h
new file mode 100644 (file)
index 0000000..c033b0b
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef TOSTHREAD_HAMAMATSUS1087_H
+#define TOSTHREAD_HAMAMATSUS1087_H
+
+#include "TinyError.h"
+#define tmote_par hamamatsuS1087_par
+
+extern error_t hamamatsuS1087_par_read(uint16_t* val);
+extern error_t hamamatsuS1087_par_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count);
+extern uint8_t hamamatsuS1087_par_getNumBits();
+
+#endif //TOSTHREAD_HAMAMATSUS1087_H
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/tosthread_hamamatsuS10871.h b/tos/lib/tosthreads/sensorboards/tmote_onboard/tosthread_hamamatsuS10871.h
new file mode 100644 (file)
index 0000000..2ef4f4e
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef TOSTHREAD_HAMAMATSUS10871_H
+#define TOSTHREAD_HAMAMATSUS10871_H
+
+#include "TinyError.h"
+#define tmote_tsr hamamatsuS10871_tsr
+
+extern error_t hamamatsuS10871_tsr_read(uint16_t* val);
+extern error_t hamamatsuS10871_tsr_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count);
+extern uint8_t hamamatsuS10871_tsr_getNumBits();
+
+#endif //TOSTHREAD_HAMAMATSUS1087_H
diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/tosthread_sensirionSht11.h b/tos/lib/tosthreads/sensorboards/tmote_onboard/tosthread_sensirionSht11.h
new file mode 100644 (file)
index 0000000..64ed65c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+  
+#ifndef TOSTHREAD_SENSIRIONSHT11_H
+#define TOSTHREAD_SENSIRIONSHT11_H
+
+#include "TinyError.h"
+#define tmote_humidity sensirionSht11_humidity
+#define tmote_temperature sensirionSht11_temperature
+
+extern error_t sensirionSht11_humidity_read(uint16_t* val);
+extern uint8_t sensirionSht11_humidity_getNumBits();
+
+extern error_t sensirionSht11_temperature_read(uint16_t* val);
+extern uint8_t sensirionSht11_temperature_getNumBits();
+
+#endif //TOSTHREAD_SENSIRIONSHT11_H
diff --git a/tos/lib/tosthreads/system/BarrierC.nc b/tos/lib/tosthreads/system/BarrierC.nc
new file mode 100644 (file)
index 0000000..4627b51
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * This is the barrier implementation.  Every barrier has a pointer to 
+ * a linked list of threads.  When a thread calls block() on a barrier 
+ * it is pushed onto the thread queue associated with that barrier and
+ * it is blocked.  Once some thread calls unblock() on a particular 
+ * barrier, all threads on that barrier's thread queue are popped off 
+ * and woken up. 
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "thread.h"
+#include "barrier.h"
+
+configuration BarrierC {
+  provides {
+    interface Barrier;
+  }
+}
+implementation {
+  components TinyThreadSchedulerC;
+  components ThreadQueueC;
+  components BarrierP;
+  
+  Barrier = BarrierP;
+  BarrierP.ThreadScheduler -> TinyThreadSchedulerC;
+  BarrierP.ThreadQueue -> ThreadQueueC;
+  
+  components LedsC;
+  BarrierP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/BarrierP.nc b/tos/lib/tosthreads/system/BarrierP.nc
new file mode 100644 (file)
index 0000000..ee1b259
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * This is the barrier implementation.  Every barrier has a pointer to 
+ * a linked list of threads.  When a thread calls block() on a barrier 
+ * it is pushed onto the thread queue associated with that barrier and
+ * it is blocked.  Once some thread calls unblock() on a particular 
+ * barrier, all threads on that barrier's thread queue are popped off 
+ * and woken up. 
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module BarrierP {
+  provides {
+    interface Barrier;
+  }
+  uses {
+    interface ThreadScheduler;
+    interface ThreadQueue;
+    interface Leds;
+  }
+}
+
+implementation {
+  command void Barrier.reset(barrier_t* b, uint8_t count) {
+    atomic {
+      b->count = count;
+      //Initialize the thread queue associated with this barrier.
+      call ThreadQueue.init(&(b->thread_queue));  
+    }
+  }
+  command void Barrier.block(barrier_t* b) {
+    atomic {
+      if(b->count > 1) {
+        //Push the thread that just called block() onto the thread queue associated with this barrier
+        call ThreadQueue.enqueue(&(b->thread_queue), call ThreadScheduler.currentThreadInfo());
+        b->count--;
+        call ThreadScheduler.suspendCurrentThread();
+      }
+      else {
+        thread_t* t;
+        while((t = call ThreadQueue.dequeue(&(b->thread_queue))) != NULL)
+          call ThreadScheduler.wakeupThread(t->id);
+      }
+    }
+  }
+  command bool Barrier.isBlocking(barrier_t* b) {
+    atomic return !(call ThreadQueue.isEmpty(&(b->thread_queue)));
+  }
+}
diff --git a/tos/lib/tosthreads/system/BitArrayUtilsC.nc b/tos/lib/tosthreads/system/BitArrayUtilsC.nc
new file mode 100644 (file)
index 0000000..6f2abc8
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module BitArrayUtilsC {
+  provides interface BitArrayUtils;
+}
+
+implementation {
+  uint16_t getByteIndex(uint8_t bitIndex) {
+    return bitIndex / 8;
+  }
+  uint8_t getMask(uint8_t bitIndex) {
+    return 1 << (bitIndex % 8);
+  }
+  async command void BitArrayUtils.clrArray(uint8_t* array, uint8_t size) {
+    memset(array, 0, size);
+  }
+  async command bool BitArrayUtils.getBit(uint8_t* array, uint8_t bitIndex) {
+    return (array[getByteIndex(bitIndex)] & getMask(bitIndex)) ? TRUE : FALSE;
+  }
+  async command void BitArrayUtils.setBit(uint8_t* array, uint8_t bitIndex) {
+    array[getByteIndex(bitIndex)] |= getMask(bitIndex);
+  }
+  async command void BitArrayUtils.clrBit(uint8_t* array, uint8_t bitIndex) {
+    array[getByteIndex(bitIndex)] &= ~getMask(bitIndex);
+  }
+}
diff --git a/tos/lib/tosthreads/system/BlockingAMReceiverC.nc b/tos/lib/tosthreads/system/BlockingAMReceiverC.nc
new file mode 100644 (file)
index 0000000..efac52c
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include "AM.h"
+
+generic configuration BlockingAMReceiverC(am_id_t amId) {
+  provides {
+    interface BlockingReceive;
+    interface Packet;
+    interface AMPacket;
+  }
+}
+implementation {
+  components BlockingActiveMessageC as AM;
+  BlockingReceive = AM.BlockingReceive[amId];
+  
+  Packet = AM;
+  AMPacket = AM;
+}
diff --git a/tos/lib/tosthreads/system/BlockingAMReceiverImplP.nc b/tos/lib/tosthreads/system/BlockingAMReceiverImplP.nc
new file mode 100644 (file)
index 0000000..c2c7fa4
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+generic module BlockingAMReceiverImplP() {
+  provides {
+    interface Init;
+    interface BlockingReceive[uint8_t id];
+    interface BlockingReceive as BlockingReceiveAny;
+  }
+  uses {
+    interface Packet;
+    interface Timer<TMilli>[uint8_t id];
+    interface Receive[uint8_t id];
+    interface SystemCall;
+    interface SystemCallQueue;
+    interface ThreadScheduler;
+    interface Leds;
+  }
+}
+implementation {
+  
+  typedef struct params {
+    message_t* msg;
+    uint32_t*  timeout;
+    error_t    error;
+  } params_t;
+
+  //For parameterized BlockingReceive interface
+  syscall_queue_t am_queue;
+  
+  //For single BlockingReceiveAny interface 
+  bool blockForAny = FALSE;
+  
+  void timerTask(syscall_t* s) {
+    params_t* p = s->params;
+    call Timer.startOneShot[s->thread->id](*(p->timeout));  
+  }
+  
+  command error_t Init.init() {
+    call SystemCallQueue.init(&am_queue);
+    blockForAny = FALSE;
+    return SUCCESS;
+  }
+  
+  void blockingReceive(syscall_t* s, am_id_t am_id, params_t* p, message_t* m, uint32_t* timeout) { 
+    p->msg = m;
+    p->timeout = timeout;
+    atomic {
+      p->error = EBUSY;
+      if(*timeout != 0)
+        call SystemCall.start(&timerTask, s, am_id, p);
+      else
+        call SystemCall.start(SYSCALL_WAIT_ON_EVENT, s, am_id, p);
+    }
+  }
+  
+  command error_t BlockingReceiveAny.receive(message_t* m, uint32_t timeout) {
+    syscall_t s;
+    params_t p;
+    atomic {
+      if((blockForAny == TRUE) || (call SystemCallQueue.isEmpty(&am_queue) == FALSE))
+        return EBUSY;
+      call SystemCallQueue.enqueue(&am_queue, &s);
+      blockForAny = TRUE;
+    }
+    
+    blockingReceive(&s, INVALID_ID, &p, m, &timeout);
+    
+    atomic {
+      blockForAny = FALSE;
+      call SystemCallQueue.remove(&am_queue, &s);
+      return p.error;
+    }
+  }
+  
+  command error_t BlockingReceive.receive[uint8_t am_id](message_t* m, uint32_t timeout) {
+    syscall_t s;
+    params_t p;
+    atomic {
+      if((blockForAny == TRUE) || (call SystemCallQueue.find(&am_queue, am_id) != NULL))
+        return EBUSY;
+      call SystemCallQueue.enqueue(&am_queue, &s);
+    }
+        
+       blockingReceive(&s, am_id, &p, m, &timeout);
+       
+    atomic {
+      call SystemCallQueue.remove(&am_queue, &s);
+      return p.error;
+    }  
+  }
+
+  command void* BlockingReceive.getPayload[uint8_t am_id](message_t* msg, uint8_t len) {
+    return call Packet.getPayload(msg,len);
+  }
+  
+  command void* BlockingReceiveAny.getPayload(message_t* msg, uint8_t len) {
+    return call Packet.getPayload(msg,len);
+  }
+  
+  event message_t* Receive.receive[uint8_t am_id](message_t* m, void* payload, uint8_t len) {
+    syscall_t* s;
+    params_t* p;
+    
+    if(blockForAny == TRUE)
+      s = call SystemCallQueue.find(&am_queue, INVALID_ID);
+    else
+      s = call SystemCallQueue.find(&am_queue, am_id);
+    if(s == NULL) return m;
+        
+    p = s->params;
+    if( (p->error == EBUSY) ) {
+      call Timer.stop[s->thread->id]();
+      *(p->msg) = *m;
+      p->error = SUCCESS;
+      call SystemCall.finish(s);
+    }
+    return m;
+  }
+  
+  event void Timer.fired[uint8_t id]() {
+    thread_t* t = call ThreadScheduler.threadInfo(id);
+    params_t* p = t->syscall->params;
+    if( (p->error == EBUSY) ) {
+      p->error = FAIL;
+      call SystemCall.finish(t->syscall);
+    }
+  }
+}
diff --git a/tos/lib/tosthreads/system/BlockingAMReceiverP.nc b/tos/lib/tosthreads/system/BlockingAMReceiverP.nc
new file mode 100644 (file)
index 0000000..71d73f7
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include "AM.h"
+#include "thread.h"
+
+configuration BlockingAMReceiverP {
+  provides {
+    interface BlockingReceive[uint8_t id];
+    interface BlockingReceive as BlockingReceiveAny;
+  }
+  uses {
+    interface Receive[uint8_t id];
+  }
+}
+implementation {
+  components MainC;
+  components ActiveMessageC as AM;
+  components new BlockingAMReceiverImplP();
+  
+  MainC.SoftwareInit -> BlockingAMReceiverImplP;
+
+  BlockingReceive = BlockingAMReceiverImplP;
+  BlockingReceiveAny = BlockingAMReceiverImplP;
+  Receive = BlockingAMReceiverImplP;
+  BlockingAMReceiverImplP.Packet -> AM;
+  
+  components SystemCallC;
+  components SystemCallQueueC;
+  components TinyThreadSchedulerC;
+  BlockingAMReceiverImplP.SystemCallQueue -> SystemCallQueueC;
+  BlockingAMReceiverImplP.SystemCall -> SystemCallC;
+  BlockingAMReceiverImplP.ThreadScheduler -> TinyThreadSchedulerC;
+
+  components ThreadTimersC;
+  BlockingAMReceiverImplP.Timer -> ThreadTimersC;
+  
+  components LedsC;
+  BlockingAMReceiverImplP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingAMSenderC.nc b/tos/lib/tosthreads/system/BlockingAMSenderC.nc
new file mode 100644 (file)
index 0000000..4d70b1e
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include "AM.h"
+
+generic configuration BlockingAMSenderC(am_id_t AMId) {
+  provides {
+    interface BlockingAMSend;
+    interface Packet;
+    interface AMPacket;
+    interface PacketAcknowledgements as Acks;
+  }
+}
+
+implementation {
+  components BlockingActiveMessageC as AM;
+  BlockingAMSend = AM.BlockingAMSend[AMId];
+  
+  Packet = AM;
+  AMPacket = AM;
+  Acks = AM;
+}
diff --git a/tos/lib/tosthreads/system/BlockingAMSenderImplP.nc b/tos/lib/tosthreads/system/BlockingAMSenderImplP.nc
new file mode 100644 (file)
index 0000000..539e074
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+generic module BlockingAMSenderImplP() {
+  provides {
+    interface Init;
+    interface BlockingAMSend[am_id_t id];
+  }
+  uses {
+    interface SystemCall;
+    interface Mutex;
+    interface AMSend[am_id_t id];
+    interface Packet;
+    interface Leds;
+  }
+}
+implementation {
+
+  typedef struct params {
+    am_addr_t  addr;
+    message_t* msg;
+    uint8_t    len;
+    error_t    error;
+  } params_t;
+  
+  syscall_t* send_call;
+  mutex_t my_mutex;
+  
+  void sendTask(syscall_t* s) {
+    params_t* p = s->params;
+    p->error = call AMSend.send[s->id](p->addr, p->msg, p->len);
+    if(p->error != SUCCESS)
+      call SystemCall.finish(s);
+  }
+  
+  command error_t Init.init() {
+    call Mutex.init(&my_mutex);
+    return SUCCESS;
+  }
+  
+  command error_t BlockingAMSend.send[am_id_t am_id](am_addr_t addr, message_t* msg, uint8_t len) {
+    syscall_t s;
+    params_t p;
+    call Mutex.lock(&my_mutex);
+      send_call = &s;
+    
+      p.addr = addr;
+      p.msg = msg;
+      p.len = len;
+    
+      call SystemCall.start(&sendTask, &s, am_id, &p);
+    
+    atomic {
+      call Mutex.unlock(&my_mutex);
+      return p.error;
+    }
+  }
+
+  command uint8_t BlockingAMSend.maxPayloadLength[am_id_t id]() {
+    return call Packet.maxPayloadLength();
+  }
+  command void* BlockingAMSend.getPayload[am_id_t id](message_t* msg, uint8_t len) {
+    return call Packet.getPayload(msg, len);
+  }
+  
+  event void AMSend.sendDone[am_id_t am_id](message_t* m, error_t error) {
+    params_t* p;
+    p = send_call->params;
+    p->error = error;
+    call SystemCall.finish(send_call);
+  }
+  default command error_t AMSend.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len) {
+    return SUCCESS;
+  }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tos/lib/tosthreads/system/BlockingAMSenderP.nc b/tos/lib/tosthreads/system/BlockingAMSenderP.nc
new file mode 100644 (file)
index 0000000..1678f38
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include "AM.h"
+#include "thread.h"
+#include "mutex.h"
+
+configuration BlockingAMSenderP {
+  provides {
+    interface BlockingAMSend[am_id_t amId];
+  }
+  uses {
+    interface AMSend[am_id_t amId];
+  }
+}
+
+implementation {
+  components MainC;
+  components ActiveMessageC as AM;
+  components new BlockingAMSenderImplP();
+  components MutexC;
+  components SystemCallC;
+  components LedsC;
+  
+  MainC.SoftwareInit -> BlockingAMSenderImplP;
+  
+  BlockingAMSend = BlockingAMSenderImplP;
+  AMSend = BlockingAMSenderImplP;
+  BlockingAMSenderImplP.Mutex -> MutexC;
+  BlockingAMSenderImplP.SystemCall -> SystemCallC;
+  BlockingAMSenderImplP.Packet -> AM;
+  BlockingAMSenderImplP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingAMSnooperC.nc b/tos/lib/tosthreads/system/BlockingAMSnooperC.nc
new file mode 100644 (file)
index 0000000..962bcbe
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include "AM.h"
+
+generic configuration BlockingAMSnooperC(am_id_t amId) {
+  provides {
+    interface BlockingReceive as BlockingSnoop;
+    interface Packet;
+    interface AMPacket;
+  }
+}
+implementation {
+  components BlockingActiveMessageC as AM;
+  BlockingReceive = AM.BlockingSnoop[amId];
+  
+  Packet = AM;
+  AMPacket = AM;
+}
diff --git a/tos/lib/tosthreads/system/BlockingAMSnooperP.nc b/tos/lib/tosthreads/system/BlockingAMSnooperP.nc
new file mode 100644 (file)
index 0000000..5f2091e
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include "AM.h"
+#include "thread.h"
+
+configuration BlockingAMSnooperP {
+  provides {
+    interface BlockingReceive as BlockingSnoop[uint8_t id];
+    interface BlockingReceive as BlockingSnoopAny;
+  }
+  uses {
+    interface Receive as Snoop[uint8_t id];
+  }
+}
+implementation {
+  components MainC;
+  components ActiveMessageC as AM;
+  components new BlockingAMReceiverImplP();
+  
+  MainC.SoftwareInit -> BlockingAMReceiverImplP;
+
+  BlockingSnoop = BlockingAMReceiverImplP;
+  BlockingSnoopAny = BlockingAMReceiverImplP;
+  Snoop = BlockingAMReceiverImplP;
+  BlockingAMReceiverImplP.Packet -> AM;
+  
+  components SystemCallC;
+  components SystemCallQueueC;
+  components TinyThreadSchedulerC;
+  BlockingAMReceiverImplP.SystemCallQueue -> SystemCallQueueC;
+  BlockingAMReceiverImplP.SystemCall -> SystemCallC;
+  BlockingAMReceiverImplP.ThreadScheduler -> TinyThreadSchedulerC;
+
+  components ThreadTimersC;
+  BlockingAMReceiverImplP.Timer -> ThreadTimersC;
+  
+  components LedsC;
+  BlockingAMReceiverImplP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingActiveMessageC.nc b/tos/lib/tosthreads/system/BlockingActiveMessageC.nc
new file mode 100644 (file)
index 0000000..f3ab2dc
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+configuration BlockingActiveMessageC {
+  provides {
+    interface BlockingStdControl;
+    interface BlockingReceive[uint8_t id];
+    interface BlockingReceive as BlockingReceiveAny;
+    interface BlockingReceive as BlockingSnoop[uint8_t id];
+    interface BlockingReceive as BlockingSnoopAny;
+    interface BlockingAMSend[uint8_t id];
+
+    interface Packet;
+    interface AMPacket;
+    interface PacketAcknowledgements;
+  }
+}
+implementation {
+  components ActiveMessageC as AM;
+  components new BlockingStdControlC();
+  components BlockingAMReceiverP as AMReceiverP;
+  components BlockingAMSnooperP as AMSnooperP;
+  components BlockingAMSenderP as AMSenderP;
+  BlockingStdControl = BlockingStdControlC;
+  BlockingReceive = AMReceiverP;
+  BlockingReceiveAny = AMReceiverP;
+  BlockingSnoop = AMSnooperP;
+  BlockingSnoopAny = AMSnooperP;
+  BlockingAMSend = AMSenderP;
+  
+  BlockingStdControlC.SplitControl -> AM;
+  AMReceiverP.Receive -> AM.Receive;
+  AMSnooperP.Snoop -> AM.Snoop;
+  AMSenderP.AMSend -> AM.AMSend;
+    
+  Packet       = AM;
+  AMPacket     = AM;
+  PacketAcknowledgements = AM;
+}
diff --git a/tos/lib/tosthreads/system/BlockingBlockStorageC.nc b/tos/lib/tosthreads/system/BlockingBlockStorageC.nc
new file mode 100644 (file)
index 0000000..f40935c
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+#define UQ_BLOCKING_BLOCK_STORAGE_VOLUME "Blocking.Block.Storage.Volume"
+
+generic configuration BlockingBlockStorageC(volume_id_t volume_id) {
+  provides {
+    interface BlockingBlock;
+  }
+}
+
+implementation {
+  enum {
+    VOLUME_ID = unique(UQ_BLOCKING_BLOCK_STORAGE_VOLUME),
+  };
+
+  components new BlockStorageC(volume_id),
+             BlockingBlockStorageP;
+  
+  BlockingBlock = BlockingBlockStorageP.BlockingBlock[VOLUME_ID];
+  BlockingBlockStorageP.BlockRead[VOLUME_ID] -> BlockStorageC;
+  BlockingBlockStorageP.BlockWrite[VOLUME_ID] -> BlockStorageC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingBlockStorageImplP.nc b/tos/lib/tosthreads/system/BlockingBlockStorageImplP.nc
new file mode 100644 (file)
index 0000000..7734b13
--- /dev/null
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Kevin Klues <klueska@cs.stanford.edu>
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+module BlockingBlockStorageImplP {
+  provides {
+    interface Init;
+    interface BlockingBlock[uint8_t volume_id];
+  }
+  uses {
+    interface BlockRead[uint8_t volume_id];
+    interface BlockWrite[uint8_t volume_id];
+    interface SystemCall;
+    interface SystemCallQueue;
+  }
+}
+implementation {
+  
+  typedef struct read_write_params {
+    storage_addr_t addr;
+    void*          buf;
+    storage_len_t* len;
+    error_t        error;
+  } read_write_params_t;
+  
+  typedef struct crc_params {
+    storage_addr_t addr;
+    storage_len_t* len;
+    uint16_t       crc;
+    uint16_t       *finalCrc;    
+    error_t        error;
+  } crc_params_t;
+  
+  typedef struct erase_sync_params {
+    error_t error;
+  } erase_sync_params_t;
+
+  syscall_queue_t vol_queue;
+
+  command error_t Init.init() {
+    call SystemCallQueue.init(&vol_queue);
+    return SUCCESS;
+  }
+
+  command storage_len_t BlockingBlock.getSize[uint8_t volume_id]() {
+    return call BlockRead.getSize[volume_id]();
+  }
+  
+  /**************************** Reading ********************************/
+  void readTask(syscall_t* s) {
+    read_write_params_t* p = s->params;
+    p->error = call BlockRead.read[s->id](p->addr, p->buf, *(p->len));
+    if(p->error != SUCCESS)
+      call SystemCall.finish(s);
+  }
+  
+  command error_t BlockingBlock.read[uint8_t volume_id](storage_addr_t addr, void *buf, storage_len_t* len) {
+    syscall_t s;
+    read_write_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&vol_queue, &s);
+    }
+    
+    p.addr = addr;
+    p.buf = buf;
+    p.len = len;
+    call SystemCall.start(&readTask, &s, volume_id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&vol_queue, &s);
+      return p.error;
+    }
+  }
+
+  event void BlockRead.readDone[uint8_t volume_id](storage_addr_t addr, void *buf, storage_len_t len, error_t error) {
+    syscall_t* s = call SystemCallQueue.find(&vol_queue, volume_id);
+    read_write_params_t* p = s->params;
+    p->error = error;
+    *(p->len) = len;
+    call SystemCall.finish(s);
+  }
+
+  
+  /**************************** Writing ********************************/
+  void writeTask(syscall_t* s) {
+    read_write_params_t* p = s->params;
+    p->error = call BlockWrite.write[s->id](p->addr, p->buf, *(p->len));
+    if(p->error != SUCCESS)
+      call SystemCall.finish(s);
+  }
+  
+  command error_t BlockingBlock.write[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t* len) {
+    syscall_t s;
+    read_write_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&vol_queue, &s);
+    }
+    
+    p.addr = addr;
+    p.buf = buf;
+    p.len = len;
+    call SystemCall.start(&writeTask, &s, volume_id, &p);
+
+    atomic {
+      call SystemCallQueue.remove(&vol_queue, &s);
+      return p.error;
+    }
+  }
+  
+  event void BlockWrite.writeDone[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {
+    syscall_t* s = call SystemCallQueue.find(&vol_queue, volume_id);
+    read_write_params_t* p = s->params;
+    *(p->len) = len;
+    p->error = error;
+    call SystemCall.finish(s);
+  }
+
+  /**************************** Computing CRC ********************************/
+  void crcTask(syscall_t* s) {
+    crc_params_t* p = s->params;
+    p->error = call BlockRead.computeCrc[s->id](p->addr, *(p->len), p->crc);
+    if(p->error != SUCCESS)
+      call SystemCall.finish(s);
+  }
+  
+  command error_t BlockingBlock.computeCrc[uint8_t volume_id](storage_addr_t addr, storage_len_t* len, uint16_t crc, uint16_t *finalCrc) {
+    syscall_t s;
+    crc_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&vol_queue, &s);
+    }
+    
+    p.addr = addr;
+    p.len = len;
+    p.crc = crc;
+    p.finalCrc = finalCrc;
+    call SystemCall.start(&crcTask, &s, volume_id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&vol_queue, &s);
+      return p.error;
+    }
+  }
+  
+  event void BlockRead.computeCrcDone[uint8_t volume_id](storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error) {
+    syscall_t* s = call SystemCallQueue.find(&vol_queue, volume_id);
+    crc_params_t* p = s->params;
+    *(p->finalCrc) = crc;
+    *(p->len) = len;
+    p->error = error;
+    call SystemCall.finish(s);
+  }
+
+  /**************************** Erasing ********************************/
+  void eraseTask(syscall_t* s) {
+    erase_sync_params_t* p = s->params;
+    p->error = call BlockWrite.erase[s->id]();
+    if(p->error != SUCCESS)
+      call SystemCall.finish(s);
+  }
+  
+  command error_t BlockingBlock.erase[uint8_t volume_id]() {
+    syscall_t s;
+    erase_sync_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&vol_queue, &s);
+    }
+    
+    call SystemCall.start(&eraseTask, &s, volume_id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&vol_queue, &s);
+      return p.error;
+    }
+  }
+
+  event void BlockWrite.eraseDone[uint8_t volume_id](error_t error) {
+    syscall_t* s = call SystemCallQueue.find(&vol_queue, volume_id);
+    erase_sync_params_t* p = s->params;
+    p->error = error;
+    call SystemCall.finish(s);
+  }
+
+  /**************************** Syncing ********************************/
+  void syncTask(syscall_t* s) {
+    erase_sync_params_t* p = s->params;
+    p->error = call BlockWrite.sync[s->id]();
+    if(p->error != SUCCESS)
+      call SystemCall.finish(s);
+  }
+  
+  command error_t BlockingBlock.sync[uint8_t volume_id]() {
+    syscall_t s;
+    erase_sync_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&vol_queue, &s);
+    }
+    
+    call SystemCall.start(&syncTask, &s, volume_id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&vol_queue, &s);
+      return p.error;
+    }
+  }
+  
+  event void BlockWrite.syncDone[uint8_t volume_id](error_t error) {
+    syscall_t* s = call SystemCallQueue.find(&vol_queue, volume_id);
+    erase_sync_params_t* p = s->params;
+    p->error = error;
+    call SystemCall.finish(s);
+  }
+  
+  default command error_t BlockRead.read[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
+  default command error_t BlockRead.computeCrc[uint8_t volume_id](storage_addr_t addr, storage_len_t len, uint16_t crc) { return FAIL; }
+  default command storage_len_t BlockRead.getSize[uint8_t volume_id]() { return 0; }
+  default command error_t BlockWrite.write[uint8_t volume_id](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
+  default command error_t BlockWrite.erase[uint8_t volume_id]() { return FAIL; }
+  default command error_t BlockWrite.sync[uint8_t volume_id]() { return FAIL; }
+}
diff --git a/tos/lib/tosthreads/system/BlockingBlockStorageP.nc b/tos/lib/tosthreads/system/BlockingBlockStorageP.nc
new file mode 100644 (file)
index 0000000..4433359
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+configuration BlockingBlockStorageP {
+  provides {
+    interface BlockingBlock[uint8_t id];
+  }
+  uses {
+    interface BlockRead[uint8_t id];
+    interface BlockWrite[uint8_t id];
+  }
+}
+
+implementation {
+  components MainC,
+             BlockingBlockStorageImplP;
+             
+  MainC.SoftwareInit -> BlockingBlockStorageImplP;
+  
+  BlockingBlock = BlockingBlockStorageImplP;
+  BlockRead = BlockingBlockStorageImplP;
+  BlockWrite = BlockingBlockStorageImplP;
+  
+  components SystemCallC;
+  components SystemCallQueueC;
+  BlockingBlockStorageImplP.SystemCall -> SystemCallC;
+  BlockingBlockStorageImplP.SystemCallQueue -> SystemCallQueueC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingBootC.nc b/tos/lib/tosthreads/system/BlockingBootC.nc
new file mode 100644 (file)
index 0000000..056dfdd
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+generic configuration BlockingBootC() {
+  provides {
+    interface Boot as BlockingBoot;
+  }
+  uses {
+    interface Boot;
+  }
+}
+
+implementation {
+
+  components SystemCallC;
+  components new BlockingBootP();
+  BlockingBoot = BlockingBootP;
+  Boot = BlockingBootP;
+  BlockingBootP.SystemCall -> SystemCallC;
+  
+  components LedsC;
+  BlockingBootP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingBootP.nc b/tos/lib/tosthreads/system/BlockingBootP.nc
new file mode 100644 (file)
index 0000000..c4fbbff
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+generic module BlockingBootP() {
+  provides {
+    interface Boot as BlockingBoot;
+  }
+  uses {
+    interface Boot;
+    interface SystemCall;
+    interface Leds;
+  }
+}
+implementation {
+  void bootTask(syscall_t* s) {
+    signal BlockingBoot.booted();
+    call SystemCall.finish(s);
+  }  
+  
+  event void Boot.booted() {
+    syscall_t s;    
+    call SystemCall.start(&bootTask, &s, INVALID_ID, NULL);
+  }
+}
diff --git a/tos/lib/tosthreads/system/BlockingLogStorageC.nc b/tos/lib/tosthreads/system/BlockingLogStorageC.nc
new file mode 100644 (file)
index 0000000..d8b798d
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+#include "Storage.h"
+#define UQ_BLOCKING_LOG_STORAGE_VOLUME "Blocking.Log.Storage.Volume"
+
+generic configuration BlockingLogStorageC(volume_id_t volume_id, bool circular) {
+  provides {
+    interface BlockingLog;
+  }
+}
+
+implementation {
+  enum {
+    VOLUME_ID = unique(UQ_BLOCKING_LOG_STORAGE_VOLUME),
+  };
+
+  components new LogStorageC(volume_id, circular),
+             BlockingLogStorageP;
+  
+  BlockingLog = BlockingLogStorageP.BlockingLog[VOLUME_ID];
+  BlockingLogStorageP.LogRead[VOLUME_ID] -> LogStorageC;
+  BlockingLogStorageP.LogWrite[VOLUME_ID] -> LogStorageC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingLogStorageImplP.nc b/tos/lib/tosthreads/system/BlockingLogStorageImplP.nc
new file mode 100644 (file)
index 0000000..4de3b92
--- /dev/null
@@ -0,0 +1,269 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+module BlockingLogStorageImplP {
+  provides {
+    interface Init;
+    interface BlockingLog[uint8_t volume_id];
+  }
+  
+  uses {
+    interface LogRead[uint8_t volume_id];
+    interface LogWrite[uint8_t volume_id];
+    interface SystemCall;
+    interface SystemCallQueue;
+  }
+}
+
+implementation {
+  typedef struct read_params {
+    void *buf;
+    storage_len_t* len;
+    error_t error;
+  } read_params_t;
+  
+  typedef struct append_params {
+    void *buf;
+    storage_len_t* len;
+    bool* recordsLost;
+    error_t error;
+  } append_params_t;
+  
+  typedef struct seek_params {
+    storage_cookie_t offset;
+    error_t error;
+  } seek_params_t;
+  
+  typedef struct erase_sync_params {
+    error_t error;
+  } erase_sync_params_t;
+
+  syscall_queue_t vol_queue;
+
+  command error_t Init.init()
+  {
+    call SystemCallQueue.init(&vol_queue);
+    return SUCCESS;
+  }
+
+   // ===== READ ===== //
+  void readTask(syscall_t *s)
+  {
+    read_params_t *p = s->params;
+    p->error = call LogRead.read[s->id](p->buf, *(p->len));
+    if(p->error != SUCCESS) {
+      call SystemCall.finish(s);
+    }
+  }
+  
+  command error_t BlockingLog.read[uint8_t volume_id](void *buf, storage_len_t *len)
+  {
+    syscall_t s;
+    read_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&vol_queue, &s);
+    }
+    
+    p.buf = buf;
+    p.len = len;
+    call SystemCall.start(&readTask, &s, volume_id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&vol_queue, &s);
+      return p.error;
+    }
+  }
+
+  event void LogRead.readDone[uint8_t volume_id](void *buf, storage_len_t len, error_t error)
+  {
+    syscall_t *s = call SystemCallQueue.find(&vol_queue, volume_id);
+    read_params_t *p = s->params;
+    if (p->buf == buf) {
+      p->error = error;
+      *(p->len) = len;
+      call SystemCall.finish(s);
+    }
+  }
+  
+  // ===== SEEK ===== //
+  void seekTask(syscall_t *s)
+  {
+    seek_params_t *p = s->params;
+    p->error = call LogRead.seek[s->id](p->offset);
+    if(p->error != SUCCESS) {
+      call SystemCall.finish(s);
+    }
+  }
+  
+  command error_t BlockingLog.seek[uint8_t volume_id](storage_cookie_t offset)
+  {
+    syscall_t s;
+    seek_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&vol_queue, &s);
+    }
+    
+    p.offset = offset;
+    call SystemCall.start(&seekTask, &s, volume_id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&vol_queue, &s);
+      return p.error;
+    }
+  }
+  
+  event void LogRead.seekDone[uint8_t volume_id](error_t error)
+  {
+    syscall_t *s = call SystemCallQueue.find(&vol_queue, volume_id);
+    seek_params_t *p = s->params;
+    p->error = error;
+    call SystemCall.finish(s);
+  }
+  
+  // ===== APPEND ===== //
+  void appendTask(syscall_t *s)
+  {
+    append_params_t *p = s->params;
+    p->error = call LogWrite.append[s->id](p->buf, *(p->len));
+    if(p->error != SUCCESS) {
+      call SystemCall.finish(s);
+    }
+  }
+  
+  command error_t BlockingLog.append[uint8_t volume_id](void* buf, storage_len_t *len, bool *recordsLost)
+  {
+    syscall_t s;
+    append_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&vol_queue, &s);
+    }
+    
+    p.buf = buf;
+    p.len = len;
+    p.recordsLost = recordsLost;
+    call SystemCall.start(&appendTask, &s, volume_id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&vol_queue, &s);
+      return p.error;
+    }
+  }
+
+  event void LogWrite.appendDone[uint8_t volume_id](void* buf, storage_len_t len, bool recordsLost, error_t error)
+  {
+    syscall_t *s = call SystemCallQueue.find(&vol_queue, volume_id);
+    append_params_t *p = s->params;
+    if (p->buf == buf) {
+      p->error = error;
+      *(p->len) = len;
+      *(p->recordsLost) = recordsLost;
+      call SystemCall.finish(s);
+    }
+  }
+  
+  // ===== ERASE ===== //
+  void eraseTask(syscall_t *s)
+  {
+    erase_sync_params_t *p = s->params;
+    p->error = call LogWrite.erase[s->id]();
+    if(p->error != SUCCESS) {
+      call SystemCall.finish(s);
+    }
+  }
+  
+  command error_t BlockingLog.erase[uint8_t volume_id]()
+  {
+    syscall_t s;
+    erase_sync_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&vol_queue, &s);
+    }
+    
+    call SystemCall.start(&eraseTask, &s, volume_id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&vol_queue, &s);
+      return p.error;
+    }
+  }
+  
+  event void LogWrite.eraseDone[uint8_t volume_id](error_t error)
+  {
+    syscall_t *s = call SystemCallQueue.find(&vol_queue, volume_id);
+    erase_sync_params_t *p = s->params;
+    p->error = error;
+    call SystemCall.finish(s);
+  }
+  
+  // ===== SYNC ===== //
+  void syncTask(syscall_t *s)
+  {
+    erase_sync_params_t *p = s->params;
+    p->error = call LogWrite.sync[s->id]();
+    if(p->error != SUCCESS) {
+      call SystemCall.finish(s);
+    }
+  }
+  
+  command error_t BlockingLog.sync[uint8_t volume_id]()
+  {
+    syscall_t s;
+    erase_sync_params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&vol_queue, volume_id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&vol_queue, &s);
+    }
+    
+    call SystemCall.start(&syncTask, &s, volume_id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&vol_queue, &s);
+      return p.error;
+    }
+  }
+  
+  event void LogWrite.syncDone[uint8_t volume_id](error_t error)
+  {
+    syscall_t *s = call SystemCallQueue.find(&vol_queue, volume_id);
+    erase_sync_params_t *p = s->params;
+    p->error = error;
+    call SystemCall.finish(s);
+  }
+  
+  // ===== MISC ===== //
+  command storage_cookie_t BlockingLog.currentWriteOffset[uint8_t volume_id]() { return call LogWrite.currentOffset[volume_id](); }
+  command storage_cookie_t BlockingLog.currentReadOffset[uint8_t volume_id]() { return call LogRead.currentOffset[volume_id](); }
+  command storage_len_t BlockingLog.getSize[uint8_t volume_id]() { return call LogRead.getSize[volume_id](); }
+}
diff --git a/tos/lib/tosthreads/system/BlockingLogStorageP.nc b/tos/lib/tosthreads/system/BlockingLogStorageP.nc
new file mode 100644 (file)
index 0000000..49eeb3e
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+configuration BlockingLogStorageP {
+  provides {
+    interface BlockingLog[uint8_t id];
+  }
+  uses {
+    interface LogRead[uint8_t id];
+    interface LogWrite[uint8_t id];
+  }
+}
+
+implementation {
+  components MainC,
+             BlockingLogStorageImplP;
+             
+  MainC.SoftwareInit -> BlockingLogStorageImplP;
+  
+  BlockingLog = BlockingLogStorageImplP;
+  LogRead = BlockingLogStorageImplP;
+  LogWrite = BlockingLogStorageImplP;
+  
+  components SystemCallC,
+             SystemCallQueueC;
+  BlockingLogStorageImplP.SystemCall -> SystemCallC;
+  BlockingLogStorageImplP.SystemCallQueue -> SystemCallQueueC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingResourceC.nc b/tos/lib/tosthreads/system/BlockingResourceC.nc
new file mode 100644 (file)
index 0000000..fc14b25
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+generic configuration BlockingResourceC() {
+  provides {
+    interface BlockingResource;
+  }
+  uses {
+    interface Resource;
+  }
+}
+
+implementation {
+  components new BlockingResourceP();
+  BlockingResource = BlockingResourceP;
+  Resource = BlockingResourceP;
+  
+  components ThreadTimersC;
+  BlockingResourceP.Timer -> ThreadTimersC;
+  
+  components SystemCallC;
+  components TinyThreadSchedulerC;
+  BlockingResourceP.SystemCall -> SystemCallC;
+  BlockingResourceP.ThreadScheduler -> TinyThreadSchedulerC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingResourceP.nc b/tos/lib/tosthreads/system/BlockingResourceP.nc
new file mode 100644 (file)
index 0000000..b3e69a7
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+generic module BlockingResourceP() {
+  provides {
+    interface BlockingResource;
+  }
+  uses {
+    interface SystemCall;
+    interface ThreadScheduler;
+    interface Resource;
+    interface Timer<TMilli>[uint8_t id];
+  }
+}
+implementation {
+  typedef struct params {
+    uint32_t* milli;
+    error_t   error;
+  } params_t;
+  
+  syscall_t* resource_call = NULL;
+  
+  /**************************** Request ********************************/
+  void requestTask(syscall_t* s) {
+    params_t* p = s->params;
+    p->error = call Resource.request();
+    if(p->error != SUCCESS)
+      call SystemCall.finish(s);
+  }  
+  
+  command error_t BlockingResource.request() {
+    syscall_t s;
+    params_t p;
+    atomic {
+      if(resource_call != NULL)
+        return EBUSY;
+      resource_call = &s;
+    }
+    
+    call SystemCall.start(requestTask, &s, INVALID_ID, &p);
+    
+    atomic {
+      resource_call = NULL;
+      return p.error;
+    }  
+  }
+  
+  event void Resource.granted() {
+    params_t* p = resource_call->params;
+    p->error = SUCCESS;
+    call SystemCall.finish(resource_call);
+  }
+  
+  /**************************** Release ********************************/
+  void releaseTask(syscall_t* s) {
+    params_t* p = s->params;
+    p->error = call Resource.release();
+    call SystemCall.finish(s);
+  }  
+  
+  command error_t BlockingResource.release() {
+    syscall_t s;
+    params_t p;
+    atomic {
+      if(resource_call != NULL)
+        return EBUSY;
+      resource_call = &s;
+    }
+    
+    call SystemCall.start(releaseTask, &s, INVALID_ID, &p);
+    
+    atomic {
+      resource_call = NULL;
+      return p.error;
+    }  
+  }
+  
+  /************************* Timed Release *****************************/
+  void timerTask(syscall_t* s) {
+    params_t* p = s->params;
+    call Timer.startOneShot[s->thread->id](*(p->milli));
+  }    
+  
+  command error_t BlockingResource.timedRelease(uint32_t milli) {
+    syscall_t s;
+    params_t p;
+    atomic {
+      if(resource_call != NULL)
+        return EBUSY;
+      resource_call = &s;
+    }
+    
+    if(milli != 0) {
+      p.milli = &milli;
+      call SystemCall.start(timerTask, &s, INVALID_ID, &p);
+    }
+    else {
+      call SystemCall.start(releaseTask, &s, INVALID_ID, &p); 
+      if(p.error == SUCCESS)
+        call SystemCall.start(requestTask, &s, INVALID_ID, &p); 
+    }
+    
+    atomic {
+      resource_call = NULL;
+      return p.error;
+    }  
+  }
+  
+  event void Timer.fired[uint8_t id]() {
+    thread_t* t = call ThreadScheduler.threadInfo(id);
+    syscall_t* s = t->syscall;
+    params_t* p = t->syscall->params;
+    call SystemCall.start(releaseTask, s, INVALID_ID, p); 
+    if(p->error == SUCCESS)
+      call SystemCall.start(requestTask, s, INVALID_ID, p);   
+    else call SystemCall.finish(s); 
+  }
+  
+  /************************* isOwner pass through *****************************/
+  command error_t BlockingResource.isOwner() {
+    return call Resource.isOwner();
+  }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tos/lib/tosthreads/system/BlockingSerialAMReceiverC.nc b/tos/lib/tosthreads/system/BlockingSerialAMReceiverC.nc
new file mode 100644 (file)
index 0000000..7ec4d38
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include "AM.h"
+
+generic configuration BlockingSerialAMReceiverC(am_id_t amId) {
+  provides {
+    interface BlockingReceive;
+    interface Packet;
+    interface AMPacket;
+  }
+}
+implementation {
+  components BlockingSerialActiveMessageC as AM;
+  BlockingReceive = AM.BlockingReceive[amId];
+  
+  Packet = AM;
+  AMPacket = AM;
+}
diff --git a/tos/lib/tosthreads/system/BlockingSerialAMReceiverP.nc b/tos/lib/tosthreads/system/BlockingSerialAMReceiverP.nc
new file mode 100644 (file)
index 0000000..30dd547
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include "AM.h"
+#include "thread.h"
+
+configuration BlockingSerialAMReceiverP {
+  provides {
+    interface BlockingReceive[uint8_t id];
+    interface BlockingReceive as BlockingReceiveAny;
+  }
+  uses {
+    interface Receive[uint8_t id];
+  }
+}
+implementation {
+  components MainC;
+  components SerialActiveMessageC as AM;
+  components new BlockingAMReceiverImplP();
+  
+  MainC.SoftwareInit -> BlockingAMReceiverImplP;
+
+  BlockingReceive = BlockingAMReceiverImplP;
+  BlockingReceiveAny = BlockingAMReceiverImplP;
+  Receive = BlockingAMReceiverImplP;
+  BlockingAMReceiverImplP.Packet -> AM;
+  
+  components SystemCallC;
+  components SystemCallQueueC;
+  components TinyThreadSchedulerC;
+  BlockingAMReceiverImplP.SystemCallQueue -> SystemCallQueueC;
+  BlockingAMReceiverImplP.SystemCall -> SystemCallC;
+  BlockingAMReceiverImplP.ThreadScheduler -> TinyThreadSchedulerC;
+
+  components ThreadTimersC;
+  BlockingAMReceiverImplP.Timer -> ThreadTimersC;
+  
+  components LedsC;
+  BlockingAMReceiverImplP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingSerialAMSenderC.nc b/tos/lib/tosthreads/system/BlockingSerialAMSenderC.nc
new file mode 100644 (file)
index 0000000..b866dea
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include "AM.h"
+
+generic configuration BlockingSerialAMSenderC(am_id_t AMId) {
+  provides {
+    interface BlockingAMSend;
+    interface Packet;
+    interface AMPacket;
+    interface PacketAcknowledgements as Acks;
+  }
+}
+
+implementation {
+  components BlockingSerialActiveMessageC as AM;
+  BlockingAMSend = AM.BlockingAMSend[AMId];
+  
+  Packet = AM;
+  AMPacket = AM;
+  Acks = AM;
+}
diff --git a/tos/lib/tosthreads/system/BlockingSerialAMSenderP.nc b/tos/lib/tosthreads/system/BlockingSerialAMSenderP.nc
new file mode 100644 (file)
index 0000000..e0e36c8
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#include "AM.h"
+#include "thread.h"
+#include "mutex.h"
+
+configuration BlockingSerialAMSenderP {
+  provides {
+    interface BlockingAMSend[am_id_t amId];
+  }
+  uses {
+    interface AMSend[am_id_t amId];
+  }
+}
+
+implementation {
+  components MainC;
+  components SerialActiveMessageC as AM;
+  components new BlockingAMSenderImplP();
+  components MutexC;
+  components SystemCallC;
+  components LedsC;
+  
+  MainC.SoftwareInit -> BlockingAMSenderImplP;
+  
+  BlockingAMSend = BlockingAMSenderImplP;
+  AMSend = BlockingAMSenderImplP;
+  BlockingAMSenderImplP.Mutex -> MutexC;
+  BlockingAMSenderImplP.SystemCall -> SystemCallC;
+  BlockingAMSenderImplP.Packet -> AM;
+  BlockingAMSenderImplP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/BlockingSerialActiveMessageC.nc b/tos/lib/tosthreads/system/BlockingSerialActiveMessageC.nc
new file mode 100644 (file)
index 0000000..48933fa
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+configuration BlockingSerialActiveMessageC {
+  provides {
+    interface BlockingStdControl;
+    interface BlockingReceive[uint8_t id];
+    interface BlockingReceive as BlockingReceiveAny;
+    interface BlockingAMSend[uint8_t id];
+
+    interface Packet;
+    interface AMPacket;
+    interface PacketAcknowledgements;
+  }
+}
+implementation {
+  components SerialActiveMessageC as AM;
+  components new BlockingStdControlC();
+  components BlockingSerialAMReceiverP as AMReceiverP;
+  components BlockingSerialAMSenderP as AMSenderP;
+  BlockingStdControl = BlockingStdControlC;
+  BlockingReceive = AMReceiverP;
+  BlockingReceiveAny = AMReceiverP;
+  BlockingAMSend = AMSenderP;
+  
+  BlockingStdControlC.SplitControl -> AM;
+  AMReceiverP.Receive -> AM.Receive;
+  AMSenderP.AMSend -> AM.AMSend;
+    
+  Packet       = AM;
+  AMPacket     = AM;
+  PacketAcknowledgements = AM;
+}
diff --git a/tos/lib/tosthreads/system/BlockingStdControlC.nc b/tos/lib/tosthreads/system/BlockingStdControlC.nc
new file mode 100644 (file)
index 0000000..093017c
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+#define UQ_BLOCKING_STD_CONTROL "Blocking.StdControl"
+generic configuration BlockingStdControlC() {
+  provides {
+    interface BlockingStdControl;
+  }
+  uses {
+    interface SplitControl;
+  }
+}
+
+implementation {
+  
+  enum {
+    CLIENT_ID = unique(UQ_BLOCKING_STD_CONTROL),
+  };
+
+  components BlockingStdControlP;
+  BlockingStdControl = BlockingStdControlP.BlockingStdControl[CLIENT_ID];
+  SplitControl = BlockingStdControlP.SplitControl[CLIENT_ID];
+}
diff --git a/tos/lib/tosthreads/system/BlockingStdControlImplP.nc b/tos/lib/tosthreads/system/BlockingStdControlImplP.nc
new file mode 100644 (file)
index 0000000..4866a5c
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+module BlockingStdControlImplP {
+  provides {
+    interface Init;
+    interface BlockingStdControl[uint8_t id];
+  }
+  uses {
+    interface SplitControl[uint8_t id];
+    interface SystemCall;
+    interface SystemCallQueue;
+    interface Leds;
+  }
+}
+
+implementation {
+
+  typedef struct params {
+    error_t error;
+  } params_t;
+
+  syscall_queue_t std_cntrl_queue;
+  command error_t Init.init() {
+    call SystemCallQueue.init(&std_cntrl_queue);
+    return SUCCESS;
+  }
+  
+  /**************************** Start ********************************/
+  void startTask(syscall_t* s) {
+    params_t* p = s->params;
+    p->error = call SplitControl.start[s->id]();
+    if(p->error != SUCCESS)
+      call SystemCall.finish(s);
+  }  
+  
+  command error_t BlockingStdControl.start[uint8_t id]() {
+    syscall_t s;
+    params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&std_cntrl_queue, id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&std_cntrl_queue, &s);
+    }
+    
+    call SystemCall.start(&startTask, &s, id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&std_cntrl_queue, &s);
+      return p.error;
+    }
+  }
+  
+  event void SplitControl.startDone[uint8_t id](error_t error) {
+    syscall_t* s = call SystemCallQueue.find(&std_cntrl_queue, id);
+    params_t* p = s->params;    
+    p->error = error;
+    call SystemCall.finish(s);
+  }
+  
+  /**************************** Stop ********************************/
+  void stopTask(syscall_t* s) {
+    params_t* p = s->params;
+    p->error = call SplitControl.stop[s->id]();
+    if(p->error != SUCCESS)
+      call SystemCall.finish(s);
+  }
+  
+  command error_t BlockingStdControl.stop[uint8_t id]() {
+    syscall_t s;
+    params_t p;
+    atomic {
+      if(call SystemCallQueue.find(&std_cntrl_queue, id) != NULL)
+        return EBUSY;
+      call SystemCallQueue.enqueue(&std_cntrl_queue, &s);
+    }
+    
+    call SystemCall.start(&stopTask, &s, id, &p);
+    
+    atomic {
+      call SystemCallQueue.remove(&std_cntrl_queue, &s);
+      return p.error;
+    }
+  }
+  
+  event void SplitControl.stopDone[uint8_t id](error_t error) {
+    syscall_t* s = call SystemCallQueue.find(&std_cntrl_queue, id);
+    params_t* p = s->params;
+    p->error = error;
+    call SystemCall.finish(s);
+  }
+  default command error_t SplitControl.start[uint8_t id]() { return SUCCESS; }
+  default command error_t SplitControl.stop[uint8_t id]() { return SUCCESS; }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tos/lib/tosthreads/system/BlockingStdControlP.nc b/tos/lib/tosthreads/system/BlockingStdControlP.nc
new file mode 100644 (file)
index 0000000..8b1e86e
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+configuration BlockingStdControlP {
+  provides {
+    interface BlockingStdControl[uint8_t id];
+  }
+  uses {
+    interface SplitControl[uint8_t id];
+  }
+}
+
+implementation {
+  components MainC;
+  components BlockingStdControlImplP;
+  components LedsC;
+  
+  MainC.SoftwareInit -> BlockingStdControlImplP;
+
+  BlockingStdControl = BlockingStdControlImplP;
+  SplitControl = BlockingStdControlImplP;
+  
+  BlockingStdControlImplP.Leds -> LedsC;
+  
+  components SystemCallC;
+  components SystemCallQueueC;
+  BlockingStdControlImplP.SystemCallQueue -> SystemCallQueueC;
+  BlockingStdControlImplP.SystemCall -> SystemCallC;
+
+}
diff --git a/tos/lib/tosthreads/system/ConditionVariableC.nc b/tos/lib/tosthreads/system/ConditionVariableC.nc
new file mode 100644 (file)
index 0000000..17da969
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * This is the barrier implementation.  Every barrier has a pointer to 
+ * a linked list of threads.  When a thread calls block() on a barrier 
+ * it is pushed onto the thread queue associated with that barrier and
+ * it is blocked.  Once some thread calls unblock() on a particular 
+ * barrier, all threads on that barrier's thread queue are popped off 
+ * and woken up. 
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "thread.h"
+#include "condvar.h"
+
+configuration ConditionVariableC {
+  provides {
+    interface ConditionVariable;
+  }
+}
+implementation {
+  components TinyThreadSchedulerC;
+  components ThreadQueueC;
+  components MutexC;
+  components ConditionVariableP;
+  
+  ConditionVariable = ConditionVariableP;
+  ConditionVariableP.ThreadScheduler -> TinyThreadSchedulerC;
+  ConditionVariableP.ThreadQueue -> ThreadQueueC;
+  ConditionVariableP.Mutex -> MutexC;
+  
+  components LedsC;
+  ConditionVariableP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/ConditionVariableP.nc b/tos/lib/tosthreads/system/ConditionVariableP.nc
new file mode 100644 (file)
index 0000000..7220eb5
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * This is the barrier implementation.  Every barrier has a pointer to 
+ * a linked list of threads.  When a thread calls block() on a barrier 
+ * it is pushed onto the thread queue associated with that barrier and
+ * it is blocked.  Once some thread calls unblock() on a particular 
+ * barrier, all threads on that barrier's thread queue are popped off 
+ * and woken up. 
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module ConditionVariableP {
+  provides {
+    interface ConditionVariable;
+  }
+  uses {
+    interface ThreadScheduler;
+    interface ThreadQueue;
+    interface Mutex;
+    interface Leds;
+  }
+}
+
+implementation {
+  command void ConditionVariable.init(condvar_t* c) {
+    //Initialize the thread queue associated with this condition variable.
+    call ThreadQueue.init(&(c->thread_queue));  
+  }
+  command void ConditionVariable.wait(condvar_t* c, mutex_t* m) {
+    atomic {
+      //Push the thread that just called wait() onto the thread queue associated with 
+      //  this condition variable
+      call ThreadQueue.enqueue(&(c->thread_queue), call ThreadScheduler.currentThreadInfo());
+      call Mutex.unlock(m);
+      call ThreadScheduler.suspendCurrentThread();
+      call Mutex.lock(m);
+    }
+  }
+  command void ConditionVariable.signalNext(condvar_t* c) {
+    atomic {
+      thread_t* t;
+      //Pop all threads currently blocking on this barrier from its thread queue
+      if((t = call ThreadQueue.dequeue(&(c->thread_queue))) != NULL) {
+        call ThreadScheduler.wakeupThread(t->id);
+      }
+    }
+  }
+  command void ConditionVariable.signalAll(condvar_t* c) {
+    atomic {
+      thread_t* t;
+      //Pop all threads currently blocking on this barrier from its thread queue
+      while((t = call ThreadQueue.dequeue(&(c->thread_queue))) != NULL) {
+        call ThreadScheduler.wakeupThread(t->id);
+      }
+    }
+  }
+  command bool ConditionVariable.isBlocking(condvar_t* c) {
+    atomic return !(call ThreadQueue.isEmpty(&(c->thread_queue)));
+;
+  }
+}
diff --git a/tos/lib/tosthreads/system/DynamicThreadC.nc b/tos/lib/tosthreads/system/DynamicThreadC.nc
new file mode 100644 (file)
index 0000000..d3982af
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "thread.h"
+
+configuration DynamicThreadC {
+  provides {
+    interface DynamicThread;
+    interface ThreadNotification[uint8_t id];
+  }
+}
+implementation {
+  components ThreadP;
+  DynamicThread = ThreadP;
+  ThreadNotification = ThreadP.DynamicThreadNotification;
+}
diff --git a/tos/lib/tosthreads/system/DynamicThreadP.nc b/tos/lib/tosthreads/system/DynamicThreadP.nc
new file mode 100644 (file)
index 0000000..cb4cd80
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+#include "thread.h"
+
+module DynamicThreadP {
+  provides {
+    interface DynamicThread;
+    interface ThreadInfo[uint8_t];
+    interface ThreadNotification[uint8_t];
+  }
+  uses {
+    interface ThreadCleanup[uint8_t];
+    interface ThreadScheduler;
+    interface ThreadSleep;
+    interface BitArrayUtils;
+    interface Malloc;
+    interface Leds;
+  }
+}
+implementation {
+  thread_t* thread_info[TOSTHREAD_MAX_DYNAMIC_THREADS];
+  uint8_t* stack_heads[TOSTHREAD_MAX_DYNAMIC_THREADS];
+  uint8_t thread_map[((TOSTHREAD_MAX_DYNAMIC_THREADS - 1) / 8 + 1)];
+  thread_id_t last_id_given = -1;
+  
+  enum {
+    THREAD_OVERFLOW = TOSTHREAD_MAX_DYNAMIC_THREADS,
+  };
+  
+  thread_id_t getNextId() {
+    thread_id_t i;
+    for(i=last_id_given+1; i<TOSTHREAD_MAX_DYNAMIC_THREADS; i++) {
+      if(call BitArrayUtils.getBit(thread_map, i) == 0)
+        goto happy;
+    }
+    for(i=0; i<last_id_given; i++) {
+      if(call BitArrayUtils.getBit(thread_map, i) == 0)
+        goto happy; 
+    }
+    return THREAD_OVERFLOW;
+happy: 
+    last_id_given = i;
+    return i;
+  }
+  
+  error_t init(tosthread_t* t, void (*start_routine)(void*), void* arg, uint16_t stack_size) {
+    void* temp;
+    *t = getNextId();
+    if(*t != THREAD_OVERFLOW) {
+      if((temp = call Malloc.malloc(sizeof(thread_t) + stack_size)) != NULL) {
+        thread_info[*t] = temp;
+        stack_heads[*t] = &(((uint8_t*)temp)[sizeof(thread_t)]);
+      }
+      else return FAIL;
+      call BitArrayUtils.setBit(thread_map, *t);
+      thread_info[*t]->next_thread = NULL; 
+      thread_info[*t]->id = *t + TOSTHREAD_NUM_STATIC_THREADS;
+      thread_info[*t]->init_block = NULL;
+      thread_info[*t]->stack_ptr = (stack_ptr_t)(STACK_TOP(stack_heads[*t], stack_size));
+      thread_info[*t]->state = TOSTHREAD_STATE_INACTIVE;
+      thread_info[*t]->mutex_count = 0;
+      thread_info[*t]->start_ptr = start_routine;
+      thread_info[*t]->start_arg_ptr = arg;
+      thread_info[*t]->syscall = NULL;
+      memset(&(thread_info[*t]->regs), 0, sizeof(thread_regs_t));
+      *t += TOSTHREAD_NUM_STATIC_THREADS;
+      return call ThreadScheduler.initThread(*t);
+    }
+    return FAIL;
+  }
+
+  command error_t DynamicThread.create(tosthread_t* t, void (*start_routine)(void*), void* arg, uint16_t stack_size) {
+   atomic {
+     if(init(t, start_routine, arg, stack_size) == SUCCESS ) {
+        error_t e = call ThreadScheduler.startThread(*t);
+        if(e == SUCCESS)
+         signal ThreadNotification.justCreated[*t]();
+        return e;
+      }
+    }
+    return FAIL;
+  }
+  command error_t DynamicThread.destroy(tosthread_t* t) {
+    atomic {
+      if(call ThreadScheduler.stopThread(*t) == SUCCESS) {
+         signal ThreadCleanup.cleanup[*t]();
+         return SUCCESS;
+      }
+    }
+    return FAIL;
+  }
+  command error_t DynamicThread.pause(tosthread_t* t) {
+    if(call BitArrayUtils.getBit(thread_map, *t-TOSTHREAD_NUM_STATIC_THREADS) == TRUE) {
+      return call ThreadScheduler.stopThread(*t);
+    }
+    return FAIL;
+  }
+  command error_t DynamicThread.resume(tosthread_t* t) {
+    if(call BitArrayUtils.getBit(thread_map, *t-TOSTHREAD_NUM_STATIC_THREADS) == TRUE) {
+      return call ThreadScheduler.startThread(*t);
+    }
+    return FAIL;  
+  }
+  command error_t DynamicThread.sleep(uint32_t milli) {
+    return call ThreadSleep.sleep(milli);
+  }
+  
+  async command thread_t* ThreadInfo.get[uint8_t id]() {
+    atomic return thread_info[id - TOSTHREAD_NUM_STATIC_THREADS];
+  }
+  
+  async event void ThreadCleanup.cleanup[uint8_t id]() {
+    signal ThreadNotification.aboutToDestroy[id]();
+    atomic {
+      uint8_t adjusted_id = id-TOSTHREAD_NUM_STATIC_THREADS;
+      call Malloc.free(thread_info[adjusted_id]);
+      call BitArrayUtils.clrBit(thread_map, adjusted_id);
+    }
+  }
+  default async event void ThreadNotification.justCreated[uint8_t id]() {}
+  default async event void ThreadNotification.aboutToDestroy[uint8_t id]() {}
+}
diff --git a/tos/lib/tosthreads/system/LinkedListC.nc b/tos/lib/tosthreads/system/LinkedListC.nc
new file mode 100644 (file)
index 0000000..dd6e3c3
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "linked_list.h"
+
+module LinkedListC {
+  provides interface LinkedList;
+}
+implementation {
+  list_element_t* get_elementAt(linked_list_t* l, uint8_t i) {
+    if(i >= (l->size)) return NULL;
+    else if((l->head) == NULL) return NULL;
+    else {
+      list_element_t* temp = (l->head); 
+      while(i-- > 0) {
+        temp = temp->next;
+      }
+      return temp;
+    }
+  }
+  
+  list_element_t* get_element(linked_list_t* l, list_element_t* e) {
+    list_element_t* temp = (l->head);
+    while(temp != NULL) {
+      if(temp == e) return temp;
+      temp = temp->next;
+    }
+    return NULL;
+  }
+  
+  list_element_t* get_element_before(linked_list_t* l, list_element_t* e) {
+    list_element_t* temp = (l->head);
+    if(temp == NULL) return NULL;
+    while(temp->next != NULL) {
+      if(temp->next == e) return temp;;
+      temp = temp->next;
+    }
+    return NULL;
+  }
+  
+  list_element_t* get_element_2before(linked_list_t* l, list_element_t* e) {
+    list_element_t* temp = (l->head);
+    if(temp == NULL) return NULL;
+    if(temp->next == NULL) return NULL;
+    while(temp->next->next != NULL) {
+      if(temp->next->next == e) return temp;
+      temp = temp->next->next;
+    }
+    return NULL;
+  }
+  
+  error_t insert_element(linked_list_t* l, list_element_t** previous_next, list_element_t* e) {
+    if(e == NULL) return FAIL;
+    e->next = *previous_next;
+    *previous_next = e;
+    (l->size)++;
+    return SUCCESS;
+  }
+  
+  list_element_t* remove_element(linked_list_t* l, list_element_t** previous_next) {
+    list_element_t* e = (*previous_next);
+    *previous_next = (*previous_next)->next;
+    e->next = NULL;
+    (l->size)--;
+    return e;
+  }
+
+  async command void LinkedList.init(linked_list_t* l) {
+    l->head = NULL; 
+    l->size = 0;
+  }
+  async command void LinkedList.clear(linked_list_t* l) {
+    list_element_t* temp = (l->head);
+    while(temp != NULL)
+      remove_element(l, &temp);
+    l->head = NULL;
+    l->size = 0;
+  }
+  async command uint8_t LinkedList.size(linked_list_t* l) {
+    return (l->size);
+  }
+  async command error_t LinkedList.addFirst(linked_list_t* l, list_element_t* e) {
+    return insert_element(l, &(l->head), e);
+  }
+  async command list_element_t* LinkedList.getFirst(linked_list_t* l) {
+    if((l->head) == NULL) return NULL;
+    return (l->head);
+  }
+  async command list_element_t* LinkedList.removeFirst(linked_list_t* l) {
+    if((l->head) == NULL) return NULL;
+    else return remove_element(l, &(l->head));
+  }
+  async command error_t LinkedList.addLast(linked_list_t* l, list_element_t* e) {
+    return call LinkedList.addAt(l, e, (l->size));
+  }
+  async command list_element_t* LinkedList.getLast(linked_list_t* l) {
+    return get_elementAt(l, (l->size)-1);
+  }
+  async command list_element_t* LinkedList.removeLast(linked_list_t* l) {
+    return call LinkedList.removeAt(l, (l->size)-1);
+  }
+  async command error_t LinkedList.addAt(linked_list_t* l, list_element_t* e, uint8_t i) {
+    if(i > (l->size)) return FAIL;
+    else if(i == 0)
+      return insert_element(l, &(l->head), e);
+    else {
+      list_element_t* temp = get_elementAt(l, i-1);
+      return insert_element(l, &(temp->next), e);
+    }
+  }
+  async command list_element_t* LinkedList.getAt(linked_list_t* l, uint8_t i) {
+    list_element_t* temp = get_elementAt(l, i);
+    if(temp == NULL) return NULL;
+    return temp;
+  }
+  async command list_element_t* LinkedList.removeAt(linked_list_t* l, uint8_t i) {
+    if(i == 0)
+      return call LinkedList.removeFirst(l);
+    else {
+      list_element_t* temp = get_elementAt(l, i-1);
+      if(temp == NULL) return NULL;
+      else return remove_element(l, &(temp->next));
+    }
+  }
+  async command error_t LinkedList.addAfter(linked_list_t* l, list_element_t* first, list_element_t* second) {
+    list_element_t* temp = get_element(l, first);
+    if(temp == NULL) return FAIL;
+    else return insert_element(l, &(temp->next), second);
+  }
+  async command error_t LinkedList.addBefore(linked_list_t* l, list_element_t* first, list_element_t* e) {
+    list_element_t* temp;
+    if((l->head) == NULL) return FAIL;
+    if((l->head) == first) return insert_element(l, &(l->head), e);
+  
+    temp = get_element_before(l, first);
+    if(temp == NULL) return FAIL;
+    else return insert_element(l, &(temp->next), e);
+  }
+  async command list_element_t* LinkedList.getAfter(linked_list_t* l, list_element_t* e) {
+    list_element_t* temp = get_element(l, e);
+    if(temp == NULL) return NULL;
+    if(temp->next == NULL) return NULL;
+    return temp->next;
+  }
+  async command list_element_t* LinkedList.getBefore(linked_list_t* l, list_element_t* e) {
+    list_element_t* temp = get_element_before(l, e);
+    if(temp == NULL) return NULL;
+    return temp;
+  }
+  async command list_element_t* LinkedList.remove(linked_list_t* l, list_element_t* e) {
+    list_element_t* temp;
+    if((l->head) == NULL) return NULL;
+    if((l->head) == e) return remove_element(l, &(l->head));
+    
+    temp = get_element_before(l, e);
+    if(temp == NULL) return NULL;
+    else return remove_element(l, &(temp->next));
+  }
+  async command list_element_t* LinkedList.removeBefore(linked_list_t* l, list_element_t* e) {
+    list_element_t* temp;
+    if((l->head) == NULL) return NULL;
+    if((l->head)->next == NULL) return NULL;
+    if((l->head)->next == e) return remove_element(l, &(l->head));
+    
+    temp = get_element_2before(l, e);
+    if(temp == NULL) return NULL;
+    else return remove_element(l, &(temp->next));
+  }
+  async command list_element_t* LinkedList.removeAfter(linked_list_t* l, list_element_t* e) {
+    list_element_t* temp = get_element(l, e);
+    if(temp == NULL) return NULL;
+    else return remove_element(l, &(temp->next));
+  }
+  async command uint8_t LinkedList.indexOf(linked_list_t* l, list_element_t* e) {
+    int i = -1;
+    list_element_t* temp = (l->head);
+    while(temp != NULL) {
+      i++;
+      if(temp == e) break;
+      temp = temp->next;
+    }
+    return i;
+  }
+}
diff --git a/tos/lib/tosthreads/system/MainC.nc b/tos/lib/tosthreads/system/MainC.nc
new file mode 100644 (file)
index 0000000..69fc2ba
--- /dev/null
@@ -0,0 +1,75 @@
+/*                                     
+ * "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.
+ *
+ * Date last modified:  $Id$
+ */
+
+/**
+ * MainC is the system interface the TinyOS boot sequence. It wires the
+ * boot sequence implementation to the scheduler and hardware resources.
+ *
+ * @author Philip Levis
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "hardware.h"
+
+configuration MainC {
+  provides interface Boot;
+  uses {
+    interface Init as SoftwareInit;
+  }
+}
+implementation {
+  components PlatformC;
+  components TinyOSMainP;
+  components RealMainP;
+  
+  components TinyTaskSchedulerC;
+  components TinyThreadSchedulerC;
+  components ThreadP;
+    
+  // Export the SoftwareInit and Boot for applications
+  SoftwareInit = TinyOSMainP.SoftwareInit;
+  Boot = TinyOSMainP;
+  
+  //Wire up the platform specific code
+  TinyOSMainP.PlatformInit -> PlatformC;
+  TinyOSMainP.TaskScheduler -> TinyTaskSchedulerC;
+  
+  //Wire up the interdependent task and thread schedulers
+  TinyTaskSchedulerC.ThreadScheduler -> TinyThreadSchedulerC;
+  
+  //Wire up the TinyOS code to its thread
+  ThreadP.StaticThreadInfo[TOSTHREAD_TOS_THREAD_ID] -> TinyOSMainP;
+  TinyOSMainP.TinyOSBoot -> TinyThreadSchedulerC;
+  
+  //Wire up the thread scheduler to start running
+  TinyThreadSchedulerC.ThreadSchedulerBoot -> RealMainP;  
+}
+
diff --git a/tos/lib/tosthreads/system/MutexC.nc b/tos/lib/tosthreads/system/MutexC.nc
new file mode 100644 (file)
index 0000000..93a1314
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "thread.h"
+#include "mutex.h"
+
+configuration MutexC {
+  provides {
+    interface Mutex;
+  }
+}
+implementation {
+  components ThreadQueueC;
+  components TinyThreadSchedulerC;
+  components MutexP;
+  
+  Mutex = MutexP;
+  MutexP.ThreadQueue -> ThreadQueueC;
+  MutexP.ThreadScheduler -> TinyThreadSchedulerC;
+}
diff --git a/tos/lib/tosthreads/system/MutexP.nc b/tos/lib/tosthreads/system/MutexP.nc
new file mode 100644 (file)
index 0000000..f09701b
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module MutexP {
+  provides {
+    interface Mutex;
+  }
+  uses {
+    interface ThreadQueue;
+    interface ThreadScheduler;
+  }
+}
+
+implementation {
+  command void Mutex.init(mutex_t* m) {
+    m->lock = FALSE;
+    call ThreadQueue.init(&(m->thread_queue));  
+  }
+  
+  command error_t Mutex.lock(mutex_t* m) {
+    atomic {
+      thread_t* t = call ThreadScheduler.currentThreadInfo();
+      if(m->lock == FALSE) {
+        m->lock = TRUE;
+        t->mutex_count++;
+      }
+      else {
+        call ThreadQueue.enqueue(&(m->thread_queue), t);
+        call ThreadScheduler.suspendCurrentThread();
+      }
+      return SUCCESS;
+    }
+  }
+  
+  command error_t Mutex.unlock(mutex_t* m) {
+    atomic {
+      if(m->lock == TRUE) {
+        thread_t* t = call ThreadScheduler.currentThreadInfo();
+        t->mutex_count--;
+        if((t = call ThreadQueue.dequeue(&(m->thread_queue))) != NULL)
+          call ThreadScheduler.wakeupThread(t->id);
+        else m->lock = FALSE;
+      }
+      return SUCCESS;
+    }    
+  }
+}
diff --git a/tos/lib/tosthreads/system/PlatformInterruptC.nc b/tos/lib/tosthreads/system/PlatformInterruptC.nc
new file mode 100644 (file)
index 0000000..9131d55
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+
+configuration PlatformInterruptC {
+  provides {
+    interface PlatformInterrupt;
+  }
+}
+implementation {
+  components TinyThreadSchedulerC;
+  components TinyTaskSchedulerC;
+  components TOSThreadsInterruptP;
+
+  PlatformInterrupt = TOSThreadsInterruptP;
+  TOSThreadsInterruptP.ThreadScheduler -> TinyThreadSchedulerC;
+  TOSThreadsInterruptP.TaskScheduler -> TinyTaskSchedulerC;
+}
diff --git a/tos/lib/tosthreads/system/PoolThreadC.nc b/tos/lib/tosthreads/system/PoolThreadC.nc
new file mode 100644 (file)
index 0000000..88f5512
--- /dev/null
@@ -0,0 +1,79 @@
+/**
+ * @author Jeongyeup Paek (jpaek@enl.usc.edu)
+ */
+
+#include "thread.h"
+#include "poolthread.h"
+
+configuration PoolThreadC {
+  provides {
+    interface PoolThread;
+    interface ThreadNotification[uint8_t id];
+  }
+}
+implementation {
+  components MainC, PoolThreadP, ThreadP;
+  PoolThread         = PoolThreadP;
+  ThreadNotification = ThreadP.StaticThreadNotification;
+
+  components BitArrayUtilsC;
+  PoolThreadP.BitArrayUtils -> BitArrayUtilsC;
+  components ThreadSleepC;
+  PoolThreadP.ThreadSleep -> ThreadSleepC;
+  components TinyThreadSchedulerC;
+  PoolThreadP.ThreadScheduler -> TinyThreadSchedulerC;
+
+#if (NUM_POOL_THREADS > 0)
+  components new ThreadC(POOL_THREAD_STACK_SIZE) as TinyThread0;
+  PoolThreadP.TinyThread0 -> TinyThread0;
+  PoolThreadP.ThreadInfo0 -> TinyThread0;
+#endif
+#if (NUM_POOL_THREADS > 1)
+  components new ThreadC(POOL_THREAD_STACK_SIZE) as TinyThread1;
+  PoolThreadP.TinyThread1 -> TinyThread1;
+  PoolThreadP.ThreadInfo1 -> TinyThread1;
+#endif
+#if (NUM_POOL_THREADS > 2)
+  components new ThreadC(POOL_THREAD_STACK_SIZE) as TinyThread2;
+  PoolThreadP.TinyThread2 -> TinyThread2;
+  PoolThreadP.ThreadInfo2 -> TinyThread2;
+#endif
+#if (NUM_POOL_THREADS > 3)
+  components new ThreadC(POOL_THREAD_STACK_SIZE) as TinyThread3;
+  PoolThreadP.TinyThread3 -> TinyThread3;
+  PoolThreadP.ThreadInfo3 -> TinyThread3;
+#endif
+#if (NUM_POOL_THREADS > 4)
+  components new ThreadC(POOL_THREAD_STACK_SIZE) as TinyThread4;
+  PoolThreadP.TinyThread4 -> TinyThread4;
+  PoolThreadP.ThreadInfo4 -> TinyThread4;
+#endif
+#if (NUM_POOL_THREADS > 5)
+  components new ThreadC(POOL_THREAD_STACK_SIZE) as TinyThread5;
+  PoolThreadP.TinyThread5 -> TinyThread5;
+  PoolThreadP.ThreadInfo5 -> TinyThread5;
+#endif
+#if (NUM_POOL_THREADS > 6)
+  components new ThreadC(POOL_THREAD_STACK_SIZE) as TinyThread6;
+  PoolThreadP.TinyThread6 -> TinyThread6;
+  PoolThreadP.ThreadInfo6 -> TinyThread6;
+#endif
+#if (NUM_POOL_THREADS > 7)
+  components new ThreadC(POOL_THREAD_STACK_SIZE) as TinyThread7;
+  PoolThreadP.TinyThread7 -> TinyThread7;
+  PoolThreadP.ThreadInfo7 -> TinyThread7;
+#endif
+#if (NUM_POOL_THREADS > 8)
+  components new ThreadC(POOL_THREAD_STACK_SIZE) as TinyThread8;
+  PoolThreadP.TinyThread8 -> TinyThread8;
+  PoolThreadP.ThreadInfo8 -> TinyThread8;
+#endif
+#if (NUM_POOL_THREADS > 9)
+  components new ThreadC(POOL_THREAD_STACK_SIZE) as TinyThread9;
+  PoolThreadP.TinyThread9 -> TinyThread9;
+  PoolThreadP.ThreadInfo9 -> TinyThread9;
+#endif
+}
+
+
diff --git a/tos/lib/tosthreads/system/PoolThreadP.nc b/tos/lib/tosthreads/system/PoolThreadP.nc
new file mode 100644 (file)
index 0000000..e4018f6
--- /dev/null
@@ -0,0 +1,352 @@
+/**
+ * @author Jeongyeup Paek (jpaek@enl.usc.edu)
+ */
+#include "thread.h"
+#include "poolthread.h"
+
+module PoolThreadP {
+  provides {
+    interface PoolThread;
+  }
+  uses {
+#if (NUM_POOL_THREADS > 0)
+    interface Thread as TinyThread0;
+    interface ThreadInfo as ThreadInfo0;
+#endif
+#if (NUM_POOL_THREADS > 1)
+    interface Thread as TinyThread1;
+    interface ThreadInfo as ThreadInfo1;
+#endif
+#if (NUM_POOL_THREADS > 2)
+    interface Thread as TinyThread2;
+    interface ThreadInfo as ThreadInfo2;
+#endif
+#if (NUM_POOL_THREADS > 3)
+    interface Thread as TinyThread3;
+    interface ThreadInfo as ThreadInfo3;
+#endif
+#if (NUM_POOL_THREADS > 4)
+    interface Thread as TinyThread4;
+    interface ThreadInfo as ThreadInfo4;
+#endif
+#if (NUM_POOL_THREADS > 5)
+    interface Thread as TinyThread5;
+    interface ThreadInfo as ThreadInfo5;
+#endif
+#if (NUM_POOL_THREADS > 6)
+    interface Thread as TinyThread6;
+    interface ThreadInfo as ThreadInfo6;
+#endif
+#if (NUM_POOL_THREADS > 7)
+    interface Thread as TinyThread7;
+    interface ThreadInfo as ThreadInfo7;
+#endif
+#if (NUM_POOL_THREADS > 8)
+    interface Thread as TinyThread8;
+    interface ThreadInfo as ThreadInfo8;
+#endif
+#if (NUM_POOL_THREADS > 9)
+    interface Thread as TinyThread9;
+    interface ThreadInfo as ThreadInfo9;
+#endif
+    interface ThreadSleep;
+    interface BitArrayUtils;
+    interface ThreadScheduler;
+  }
+}
+implementation {
+
+    typedef struct pool_item {
+        thread_t* info;
+    } pool_item_t;
+
+    pool_item_t m_list[NUM_POOL_THREADS];
+    uint8_t thread_map[((NUM_POOL_THREADS - 1) / 8 + 1)];
+
+    enum {
+        THREAD_OVERFLOW = NUM_POOL_THREADS,
+    };
+
+    error_t start_thread(uint8_t id, void* arg) {
+        if (id >= NUM_POOL_THREADS)
+            return FAIL;
+    #if (NUM_POOL_THREADS > 0)
+        if (id == 0) return call TinyThread0.start(arg);
+    #endif
+    #if (NUM_POOL_THREADS > 1)
+        if (id == 1) return call TinyThread1.start(arg);
+    #endif
+    #if (NUM_POOL_THREADS > 2)
+        if (id == 2) return call TinyThread2.start(arg);
+    #endif
+    #if (NUM_POOL_THREADS > 3)
+        if (id == 3) return call TinyThread3.start(arg);
+    #endif
+    #if (NUM_POOL_THREADS > 4)
+        if (id == 4) return call TinyThread4.start(arg);
+    #endif
+    #if (NUM_POOL_THREADS > 5)
+        if (id == 5) return call TinyThread5.start(arg);
+    #endif
+    #if (NUM_POOL_THREADS > 6)
+        if (id == 6) return call TinyThread6.start(arg);
+    #endif
+    #if (NUM_POOL_THREADS > 7)
+        if (id == 7) return call TinyThread7.start(arg);
+    #endif
+    #if (NUM_POOL_THREADS > 8)
+        if (id == 8) return call TinyThread8.start(arg);
+    #endif
+    #if (NUM_POOL_THREADS > 9)
+        if (id == 9) return call TinyThread9.start(arg);
+    #endif
+        return FAIL;
+    }
+
+    error_t stop_thread(uint8_t id) {
+        if (id >= NUM_POOL_THREADS)
+            return FAIL;
+    #if (NUM_POOL_THREADS > 0)
+        if (id == 0) return call TinyThread0.stop();
+    #endif
+    #if (NUM_POOL_THREADS > 1)
+        if (id == 1) return call TinyThread1.stop();
+    #endif
+    #if (NUM_POOL_THREADS > 2)
+        if (id == 2) return call TinyThread2.stop();
+    #endif
+    #if (NUM_POOL_THREADS > 3)
+        if (id == 3) return call TinyThread3.stop();
+    #endif
+    #if (NUM_POOL_THREADS > 4)
+        if (id == 4) return call TinyThread4.stop();
+    #endif
+    #if (NUM_POOL_THREADS > 5)
+        if (id == 5) return call TinyThread5.stop();
+    #endif
+    #if (NUM_POOL_THREADS > 6)
+        if (id == 6) return call TinyThread6.stop();
+    #endif
+    #if (NUM_POOL_THREADS > 7)
+        if (id == 7) return call TinyThread7.stop();
+    #endif
+    #if (NUM_POOL_THREADS > 8)
+        if (id == 8) return call TinyThread8.stop();
+    #endif
+    #if (NUM_POOL_THREADS > 9)
+        if (id == 9) return call TinyThread9.stop();
+    #endif
+        return FAIL;
+    }
+
+    error_t pause_thread(uint8_t id) {
+        if (id >= NUM_POOL_THREADS)
+            return FAIL;
+    #if (NUM_POOL_THREADS > 0)
+        if (id == 0) return call TinyThread0.pause();
+    #endif
+    #if (NUM_POOL_THREADS > 1)
+        if (id == 1) return call TinyThread1.pause();
+    #endif
+    #if (NUM_POOL_THREADS > 2)
+        if (id == 2) return call TinyThread2.pause();
+    #endif
+    #if (NUM_POOL_THREADS > 3)
+        if (id == 3) return call TinyThread3.pause();
+    #endif
+    #if (NUM_POOL_THREADS > 4)
+        if (id == 4) return call TinyThread4.pause();
+    #endif
+    #if (NUM_POOL_THREADS > 5)
+        if (id == 5) return call TinyThread5.pause();
+    #endif
+    #if (NUM_POOL_THREADS > 6)
+        if (id == 6) return call TinyThread6.pause();
+    #endif
+    #if (NUM_POOL_THREADS > 7)
+        if (id == 7) return call TinyThread7.pause();
+    #endif
+    #if (NUM_POOL_THREADS > 8)
+        if (id == 8) return call TinyThread8.pause();
+    #endif
+    #if (NUM_POOL_THREADS > 9)
+        if (id == 9) return call TinyThread9.pause();
+    #endif
+        return FAIL;
+    }
+
+    error_t resume_thread(uint8_t id) {
+        if (id >= NUM_POOL_THREADS)
+            return FAIL;
+    #if (NUM_POOL_THREADS > 0)
+        if (id == 0) return call TinyThread0.resume();
+    #endif
+    #if (NUM_POOL_THREADS > 1)
+        if (id == 1) return call TinyThread1.resume();
+    #endif
+    #if (NUM_POOL_THREADS > 2)
+        if (id == 2) return call TinyThread2.resume();
+    #endif
+    #if (NUM_POOL_THREADS > 3)
+        if (id == 3) return call TinyThread3.resume();
+    #endif
+    #if (NUM_POOL_THREADS > 4)
+        if (id == 4) return call TinyThread4.resume();
+    #endif
+    #if (NUM_POOL_THREADS > 5)
+        if (id == 5) return call TinyThread5.resume();
+    #endif
+    #if (NUM_POOL_THREADS > 6)
+        if (id == 6) return call TinyThread6.resume();
+    #endif
+    #if (NUM_POOL_THREADS > 7)
+        if (id == 7) return call TinyThread7.resume();
+    #endif
+    #if (NUM_POOL_THREADS > 8)
+        if (id == 8) return call TinyThread8.resume();
+    #endif
+    #if (NUM_POOL_THREADS > 9)
+        if (id == 9) return call TinyThread9.resume();
+    #endif
+        return FAIL;
+    }
+
+    thread_t *thread_info(uint8_t id) {
+        if (id >= NUM_POOL_THREADS)
+            return NULL;
+    #if (NUM_POOL_THREADS > 0)
+        if (id == 0) return call ThreadInfo0.get();
+    #endif
+    #if (NUM_POOL_THREADS > 1)
+        if (id == 1) return call ThreadInfo1.get();
+    #endif
+    #if (NUM_POOL_THREADS > 2)
+        if (id == 2) return call ThreadInfo2.get();
+    #endif
+    #if (NUM_POOL_THREADS > 3)
+        if (id == 3) return call ThreadInfo3.get();
+    #endif
+    #if (NUM_POOL_THREADS > 4)
+        if (id == 4) return call ThreadInfo4.get();
+    #endif
+    #if (NUM_POOL_THREADS > 5)
+        if (id == 5) return call ThreadInfo5.get();
+    #endif
+    #if (NUM_POOL_THREADS > 6)
+        if (id == 6) return call ThreadInfo6.get();
+    #endif
+    #if (NUM_POOL_THREADS > 7)
+        if (id == 7) return call ThreadInfo7.get();
+    #endif
+    #if (NUM_POOL_THREADS > 8)
+        if (id == 8) return call ThreadInfo8.get();
+    #endif
+    #if (NUM_POOL_THREADS > 9)
+        if (id == 9) return call ThreadInfo9.get();
+    #endif
+        return NULL;
+    }
+
+    uint8_t getNextPoolId() {
+        uint8_t i;
+        for (i = 0; i < NUM_POOL_THREADS; i++) {
+            if(call BitArrayUtils.getBit(thread_map, i) == 0)
+                break;
+        }
+        if (i >= NUM_POOL_THREADS)
+            return THREAD_OVERFLOW;
+        return i;
+    }
+
+    command error_t PoolThread.allocate(uint8_t* id, void (*start_routine)(void*), void* arg) {
+        thread_t *t;
+        atomic {
+            *id = getNextPoolId();
+            if (*id != THREAD_OVERFLOW) {
+                call BitArrayUtils.setBit(thread_map, *id);
+                t = thread_info(*id);
+                m_list[*id].info = t;
+                m_list[*id].info->start_ptr = start_routine;
+                if (start_thread(*id, arg) == SUCCESS) {
+                    return SUCCESS;
+                } else {
+                    call BitArrayUtils.clrBit(thread_map, *id);
+                    m_list[*id].info = NULL;
+                }
+            }
+        }
+        return FAIL;
+    }
+
+    command error_t PoolThread.release(uint8_t id) {
+        atomic {
+            call BitArrayUtils.clrBit(thread_map, id);
+            m_list[id].info = NULL;
+            if (stop_thread(id) == SUCCESS)
+                return SUCCESS;
+        }
+        return FAIL;
+    }
+
+    command error_t PoolThread.pause(uint8_t id) {
+        if (call BitArrayUtils.getBit(thread_map, id) == 1) {
+            return pause_thread(id);
+        }
+        return FAIL;
+    }
+
+    command error_t PoolThread.resume(uint8_t id) {
+        if (call BitArrayUtils.getBit(thread_map, id) == 1) {
+            return resume_thread(id);
+        }
+        return FAIL;  
+    }
+
+    uint8_t findPoolIdFromThreadId(uint8_t id) {
+        int i;
+        for (i = 0; i < NUM_POOL_THREADS; i++) {
+            if (call BitArrayUtils.getBit(thread_map, i) == 1)
+                if (m_list[i].info->id == id)
+                    return i;
+        }
+        return THREAD_OVERFLOW;
+    }
+
+    command error_t PoolThread.sleep(uint32_t milli) {
+        call ThreadSleep.sleep(milli);
+    }
+
+#if (NUM_POOL_THREADS > 0)
+    event void TinyThread0.run(void *arg) {}
+#endif
+#if (NUM_POOL_THREADS > 1)
+    event void TinyThread1.run(void *arg) {}
+#endif
+#if (NUM_POOL_THREADS > 2)
+    event void TinyThread2.run(void *arg) {}
+#endif
+#if (NUM_POOL_THREADS > 3)
+    event void TinyThread3.run(void *arg) {}
+#endif
+#if (NUM_POOL_THREADS > 4)
+    event void TinyThread4.run(void *arg) {}
+#endif
+#if (NUM_POOL_THREADS > 5)
+    event void TinyThread5.run(void *arg) {}
+#endif
+#if (NUM_POOL_THREADS > 6)
+    event void TinyThread6.run(void *arg) {}
+#endif
+#if (NUM_POOL_THREADS > 7)
+    event void TinyThread7.run(void *arg) {}
+#endif
+#if (NUM_POOL_THREADS > 8)
+    event void TinyThread8.run(void *arg) {}
+#endif
+#if (NUM_POOL_THREADS > 9)
+    event void TinyThread9.run(void *arg) {}
+#endif
+}
+
diff --git a/tos/lib/tosthreads/system/RealMainImplP.nc b/tos/lib/tosthreads/system/RealMainImplP.nc
new file mode 100644 (file)
index 0000000..8678992
--- /dev/null
@@ -0,0 +1,61 @@
+// $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:            Philip Levis
+ * Date last modified:  $Id$
+ *
+ */
+
+/**
+ * RealMain implements the TinyOS boot sequence, as documented in TEP 107.
+ *
+ * @author Philip Levis
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module RealMainImplP {
+  provides interface Boot as ThreadSchedulerBoot;
+}
+implementation {
+  int main() @C() @spontaneous() {
+    atomic {
+      // Start running the TinyOS thread scheduler
+      signal ThreadSchedulerBoot.booted();
+    }
+
+    /* We should never reach this point, but some versions of
+     * gcc don't realize that and issue a warning if we return
+     * void from a non-void function. So include this. */
+    return -1;
+  }
+}
+
diff --git a/tos/lib/tosthreads/system/RealMainP.nc b/tos/lib/tosthreads/system/RealMainP.nc
new file mode 100644 (file)
index 0000000..45357be
--- /dev/null
@@ -0,0 +1,58 @@
+// $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:            Philip Levis
+ * Date last modified:  $Id$
+ *
+ */
+
+/**
+ * RealMain implements the TinyOS boot sequence, as documented in TEP 107.
+ *
+ * @author Philip Levis
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+configuration RealMainP {
+  provides interface Boot;
+  uses interface Init as PlatformInit;
+  uses interface Init as SoftwareInit;
+}
+implementation {
+  components TinyOSMainP;
+  components RealMainImplP;
+    
+  Boot = RealMainImplP;
+  SoftwareInit = TinyOSMainP.SoftwareInit;
+  PlatformInit = TinyOSMainP.PlatformInit;
+}
+
diff --git a/tos/lib/tosthreads/system/ReferenceCounterC.nc b/tos/lib/tosthreads/system/ReferenceCounterC.nc
new file mode 100644 (file)
index 0000000..7e1e146
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "thread.h"
+#include "refcounter.h"
+
+configuration ReferenceCounterC {
+  provides {
+    interface ReferenceCounter;
+  }
+}
+implementation {
+  components TinyThreadSchedulerC;
+  components ThreadQueueC;
+  components ReferenceCounterP;
+  
+  ReferenceCounter = ReferenceCounterP;
+  ReferenceCounterP.ThreadScheduler -> TinyThreadSchedulerC;
+  ReferenceCounterP.ThreadQueue -> ThreadQueueC;
+  
+  components LedsC;
+  ReferenceCounterP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/ReferenceCounterP.nc b/tos/lib/tosthreads/system/ReferenceCounterP.nc
new file mode 100644 (file)
index 0000000..1420a20
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module ReferenceCounterP {
+  provides {
+    interface ReferenceCounter;
+  }
+  uses {
+    interface ThreadScheduler;
+    interface ThreadQueue;
+    interface Leds;
+  }
+}
+
+implementation {
+  void signalWaiters(refcounter_t* r) {
+    thread_t* t;
+    while((t = call ThreadQueue.dequeue(&(r->thread_queue))) != NULL)
+      call ThreadScheduler.wakeupThread(t->id); 
+  }
+
+  async command void ReferenceCounter.init(refcounter_t* r) {
+    atomic {
+      r->count = 0;
+      call ThreadQueue.init(&(r->thread_queue));  
+    }
+  }
+  async command void ReferenceCounter.increment(refcounter_t* r) {
+    atomic {
+      if( r->count != 255 ) {
+        r->count++;
+        signalWaiters(r);
+      }
+    }
+  }
+  async command void ReferenceCounter.decrement(refcounter_t* r) {
+    atomic {
+      if( r->count > 0 ) {
+        r->count--;
+        signalWaiters(r);
+      }
+    }
+  }
+  async command void ReferenceCounter.waitOnValue(refcounter_t* r, uint8_t val) {
+    atomic {
+      while(r->count != val) {
+        call ThreadQueue.enqueue(&(r->thread_queue), call ThreadScheduler.currentThreadInfo());
+        call ThreadScheduler.suspendCurrentThread(); 
+      }
+    }
+  }
+  async command uint8_t ReferenceCounter.count(refcounter_t* r) {
+    atomic return r->count;
+  }
+}
diff --git a/tos/lib/tosthreads/system/SchedulerBasicP.nc b/tos/lib/tosthreads/system/SchedulerBasicP.nc
new file mode 100644 (file)
index 0000000..dc642ea
--- /dev/null
@@ -0,0 +1,151 @@
+// $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.
+ */
+
+/**
+ * SchedulerBasicP implements the default TinyOS scheduler sequence, as
+ * documented in TEP 106.
+ *
+ * @author Philip Levis
+ * @author Cory Sharp
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ * @date   January 19 2005
+ */
+
+#include "hardware.h"
+#include "thread.h"
+
+module SchedulerBasicP {
+  provides interface TaskScheduler;
+  provides interface TaskBasic[uint8_t id];
+  uses interface ThreadScheduler;
+  uses interface Leds;
+}
+implementation {
+  enum {
+    NUM_TASKS = uniqueCount("TinyTaskSchedulerC.TaskBasic"),
+    NO_TASK = 255,
+  };
+
+  volatile uint8_t m_head;
+  volatile uint8_t m_tail;
+  volatile uint8_t m_next[NUM_TASKS];
+
+  // Helper functions (internal functions) intentionally do not have atomic
+  // sections.  It is left as the duty of the exported interface functions to
+  // manage atomicity to minimize chances for binary code bloat.
+
+  // move the head forward
+  // if the head is at the end, mark the tail at the end, too
+  // mark the task as not in the queue
+  inline uint8_t popTask() {
+    if( m_head != NO_TASK ) {
+      uint8_t id = m_head;
+      m_head = m_next[m_head];
+      if( m_head == NO_TASK ) {
+           m_tail = NO_TASK;
+      }
+      m_next[id] = NO_TASK;
+      return id;
+    }
+    else {
+      return NO_TASK;
+    }
+  }
+  
+  bool isWaiting( uint8_t id ) {
+    return (m_next[id] != NO_TASK) || (m_tail == id);
+  }
+  
+  async command bool TaskScheduler.hasTasks() {
+    atomic return (m_head != NO_TASK);
+  }
+
+  bool pushTask( uint8_t id ) {
+    if( !isWaiting(id) ) {
+      if( m_head == NO_TASK ) {
+           m_head = id;
+           m_tail = id;
+      }
+      else {
+           m_next[m_tail] = id;
+           m_tail = id;
+      }
+      return TRUE;
+    }
+    else {
+      return FALSE;
+    }
+  }
+  
+  command void TaskScheduler.init() {
+    atomic {
+      memset( (void *)m_next, NO_TASK, sizeof(m_next) );
+      m_head = NO_TASK;
+      m_tail = NO_TASK;
+    }
+  }
+  
+  command bool TaskScheduler.runNextTask() {
+    uint8_t nextTask;
+    atomic {
+      nextTask = popTask();
+      if( nextTask == NO_TASK ) {
+           return FALSE;
+      }
+    }
+    signal TaskBasic.runTask[nextTask]();
+    return TRUE;
+  }
+
+  command void TaskScheduler.taskLoop() {
+    for (;;) {
+      uint8_t nextTask;
+
+      atomic {
+           while((nextTask = popTask()) == NO_TASK) {
+             call ThreadScheduler.suspendCurrentThread();
+           }
+      }
+      signal TaskBasic.runTask[nextTask]();
+    }
+  }
+
+  /**
+   * Return SUCCESS if the post succeeded, EBUSY if it was already posted.
+   */
+  
+  async command error_t TaskBasic.postTask[uint8_t id]() {
+    atomic { return pushTask(id) ? SUCCESS : EBUSY; }
+  }
+
+  default event void TaskBasic.runTask[uint8_t id]() {}
+}
+
diff --git a/tos/lib/tosthreads/system/SemaphoreC.nc b/tos/lib/tosthreads/system/SemaphoreC.nc
new file mode 100644 (file)
index 0000000..1b299da
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+#include "thread.h"
+#include "semaphore.h"
+
+configuration SemaphoreC {
+  provides {
+    interface Semaphore;
+  }
+}
+implementation {
+  components TinyThreadSchedulerC;
+  components MutexC;
+  components ConditionVariableC;
+  components SemaphoreP;
+  
+  Semaphore = SemaphoreP;
+  SemaphoreP.ThreadScheduler -> TinyThreadSchedulerC;
+  SemaphoreP.Mutex -> MutexC;
+  SemaphoreP.ConditionVariable -> ConditionVariableC;
+  
+  components LedsC;
+  SemaphoreP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/SemaphoreP.nc b/tos/lib/tosthreads/system/SemaphoreP.nc
new file mode 100644 (file)
index 0000000..3c1b751
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ * @author Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+module SemaphoreP {
+  provides {
+    interface Semaphore;
+  }
+  uses {
+    interface ThreadScheduler;
+    interface Mutex;
+    interface ConditionVariable;
+    interface Leds;
+  }
+}
+
+implementation {
+  command void Semaphore.reset(semaphore_t* s, uint8_t v) {
+    s->s = 0;
+    s->v = v;
+    call Mutex.init(&(s->lock));  
+    call ConditionVariable.init(&(s->condvar));
+  }
+  command error_t Semaphore.acquire(semaphore_t* s) {
+    atomic {
+    call Mutex.lock(&(s->lock));
+      s->s++;
+      while (s->v == 0) {
+        call ConditionVariable.wait(&(s->condvar), &(s->lock));
+        s->v++;
+      }
+      s->s--;
+      s->v--;  
+    call Mutex.unlock(&(s->lock));
+    }
+    return SUCCESS;
+  }
+  command error_t Semaphore.release(semaphore_t* s) {
+    atomic {
+    call Mutex.lock(&(s->lock));
+      if(s->s > 0)
+        call ConditionVariable.signalNext(&(s->condvar));
+      else s->v++;
+    call Mutex.unlock(&(s->lock));
+    }
+    return SUCCESS;
+  }
+}
diff --git a/tos/lib/tosthreads/system/StaticThreadP.nc b/tos/lib/tosthreads/system/StaticThreadP.nc
new file mode 100644 (file)
index 0000000..ace29d1
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module StaticThreadP {
+  provides {
+    interface Thread[uint8_t id];
+    interface ThreadNotification[uint8_t id];
+  }
+  uses {
+    interface ThreadScheduler;
+    interface ThreadSleep;
+    interface ThreadInfo[uint8_t id];
+    interface ThreadFunction[uint8_t id];
+    interface ThreadCleanup[uint8_t id];
+    interface Leds;
+  }
+}
+implementation {
+
+  error_t init(uint8_t id, void* arg) {
+    thread_t* thread_info = call ThreadInfo.get[id]();
+    thread_info->start_arg_ptr = arg; 
+    thread_info->mutex_count = 0;
+    thread_info->next_thread = NULL;
+    return call ThreadScheduler.initThread(id);
+  }
+  
+  command error_t Thread.start[uint8_t id](void* arg) {
+    atomic {
+      if( init(id, arg) == SUCCESS ) {
+        error_t e = call ThreadScheduler.startThread(id);
+        if(e == SUCCESS) 
+          signal ThreadNotification.justCreated[id]();
+        return e;
+      }
+    }
+    return FAIL;
+  }
+  
+  command error_t Thread.pause[uint8_t id]() {
+    return call ThreadScheduler.stopThread(id);
+  }
+  
+  command error_t Thread.resume[uint8_t id]() {
+    return call ThreadScheduler.startThread(id);
+  }
+  
+  command error_t Thread.stop[uint8_t id]() {
+    if(call ThreadScheduler.stopThread(id) == SUCCESS)
+      return init(id, NULL);
+    return FAIL;
+  }
+  
+  command error_t Thread.sleep[uint8_t id](uint32_t milli) {
+    return call ThreadSleep.sleep(milli);
+  }
+  
+  event void ThreadFunction.signalThreadRun[uint8_t id](void *arg) {
+    signal Thread.run[id](arg);
+  }
+  
+  async event void ThreadCleanup.cleanup[uint8_t id]() {
+    signal ThreadNotification.aboutToDestroy[id]();
+  }
+  
+  default event void Thread.run[uint8_t id](void* arg) {}
+  default async command thread_t* ThreadInfo.get[uint8_t id]() {return NULL;}
+  default async event void ThreadNotification.justCreated[uint8_t id]() {}
+  default async event void ThreadNotification.aboutToDestroy[uint8_t id]() {}
+
+}
diff --git a/tos/lib/tosthreads/system/SystemCallC.nc b/tos/lib/tosthreads/system/SystemCallC.nc
new file mode 100644 (file)
index 0000000..5f6adfd
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "thread.h"
+
+configuration SystemCallC {
+  provides {
+    interface SystemCall;
+  }
+}
+implementation {
+  components SystemCallP;
+  components TinyThreadSchedulerC;
+  
+  SystemCall = SystemCallP;
+  SystemCallP.ThreadScheduler -> TinyThreadSchedulerC;
+}
diff --git a/tos/lib/tosthreads/system/SystemCallP.nc b/tos/lib/tosthreads/system/SystemCallP.nc
new file mode 100644 (file)
index 0000000..fa433ec
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+module SystemCallP {
+  provides {
+    interface SystemCall;
+  }
+  uses {
+    interface ThreadScheduler;
+  }
+}
+implementation {
+
+  syscall_t* current_call = NULL;
+  
+  task void threadTask() {
+    (*(current_call->syscall_ptr))(current_call);
+  }
+  
+  //Had originally planned on using a thread queue here to
+  //  hold and keep track of multiple system call requests 
+  //Observation though is that only one outstanding system 
+  //  call can exist in the system at any given time
+  //Some thread calls this function, and the task gets posted,
+  //  the TOS kernel thread gets woken up, and the task is run
+  //  immediately before any other threads get the chance to
+  //  make any system calls. 
+  //If semantics change in the future, a thread queue could
+  //  be used here with a single TinyOS task servicing all them
+  //  by popping threads off the queue and reposting itself
+  command error_t SystemCall.start(void* syscall_ptr, syscall_t* s, syscall_id_t id, void* p) {
+    atomic {
+
+      current_call = s; 
+      current_call->id = id;
+      current_call->thread = call ThreadScheduler.currentThreadInfo();
+      current_call->thread->syscall = s;
+      current_call->params = p;
+      
+      if(syscall_ptr != SYSCALL_WAIT_ON_EVENT) {
+        current_call->syscall_ptr = syscall_ptr;
+        post threadTask();
+        call ThreadScheduler.wakeupThread(TOSTHREAD_TOS_THREAD_ID);
+      }
+      
+      return call ThreadScheduler.suspendCurrentThread();
+    }
+  }
+  command error_t SystemCall.finish( syscall_t* s ) {
+    return call ThreadScheduler.wakeupThread(s->thread->id);
+  }
+}
diff --git a/tos/lib/tosthreads/system/SystemCallQueueC.nc b/tos/lib/tosthreads/system/SystemCallQueueC.nc
new file mode 100644 (file)
index 0000000..339917f
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "thread.h"
+#include "linked_list.h"
+#include "syscall_queue.h"
+
+configuration SystemCallQueueC {
+  provides {
+    interface SystemCallQueue;
+  }
+}
+implementation {
+  components LinkedListC;
+  components SystemCallQueueP;
+  
+  SystemCallQueue = SystemCallQueueP;
+  SystemCallQueueP.LinkedList -> LinkedListC;
+  
+  components LedsC;
+  SystemCallQueueP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/SystemCallQueueP.nc b/tos/lib/tosthreads/system/SystemCallQueueP.nc
new file mode 100644 (file)
index 0000000..7293944
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module SystemCallQueueP {
+  provides {
+    interface SystemCallQueue;
+  }
+  uses {
+    interface LinkedList;
+    interface Leds;
+  }
+}
+implementation {
+  async command void SystemCallQueue.init(syscall_queue_t* q) {
+    call LinkedList.init(&(q->l));
+  }
+  async command void SystemCallQueue.enqueue(syscall_queue_t* q, syscall_t* s) {
+    s->next_call = NULL;
+    call LinkedList.addLast(&(q->l), (list_element_t*)s);
+  }
+  async command syscall_t* SystemCallQueue.dequeue(syscall_queue_t* q) {
+    return (syscall_t*)call LinkedList.removeFirst(&(q->l));
+  }
+  async command syscall_t* SystemCallQueue.remove(syscall_queue_t* q, syscall_t* s) {
+    return (syscall_t*)call LinkedList.remove(&(q->l), (list_element_t*)s);
+  }
+  async command syscall_t* SystemCallQueue.find(syscall_queue_t* q, uint8_t id) {
+    syscall_t* s;
+    for(s = (syscall_t*)(call LinkedList.getFirst(&(q->l)));
+        s != NULL;
+        s = (syscall_t*)(call LinkedList.getAfter(&(q->l), (list_element_t*)s)) ) {
+      if(s->id == id) return s;
+    }
+    return NULL;
+  }
+  async command bool SystemCallQueue.isEmpty(syscall_queue_t* q) {
+    return (call LinkedList.size(&(q->l)) == 0);
+  }
+}
diff --git a/tos/lib/tosthreads/system/TOSThreadsInterruptP.nc b/tos/lib/tosthreads/system/TOSThreadsInterruptP.nc
new file mode 100644 (file)
index 0000000..535a5bb
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module TOSThreadsInterruptP {
+  provides {
+    interface PlatformInterrupt;
+  }
+  uses {
+    interface TaskScheduler;
+    interface ThreadScheduler;
+  }
+}
+implementation {
+  void interruptThread() __attribute__((noinline)) {
+    if(call ThreadScheduler.wakeupThread(TOSTHREAD_TOS_THREAD_ID) == SUCCESS) 
+      if(call ThreadScheduler.currentThreadId() != TOSTHREAD_TOS_THREAD_ID)
+        call ThreadScheduler.interruptCurrentThread();
+  }
+
+  inline async command void PlatformInterrupt.postAmble() {
+    atomic {
+      if(call TaskScheduler.hasTasks() == TRUE )
+        interruptThread();
+      }
+  }
+}
diff --git a/tos/lib/tosthreads/system/ThreadC.nc b/tos/lib/tosthreads/system/ThreadC.nc
new file mode 100644 (file)
index 0000000..214649c
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "thread.h"
+
+generic configuration ThreadC(uint16_t stack_size) {
+  provides {
+    interface Thread;
+    interface ThreadNotification;
+    interface ThreadInfo;
+  }
+}
+implementation {
+  enum {
+    THREAD_ID = unique(UQ_TOS_THREAD),
+  };
+  
+  components MainC;
+  components new ThreadInfoP(stack_size, THREAD_ID);
+  components ThreadP;
+  components StaticThreadP;
+  
+  MainC.SoftwareInit -> ThreadInfoP;
+  Thread = ThreadP.StaticThread[THREAD_ID];
+  ThreadNotification = ThreadP.StaticThreadNotification[THREAD_ID];
+  ThreadInfo = ThreadInfoP;
+  ThreadP.StaticThreadInfo[THREAD_ID] -> ThreadInfoP;
+  ThreadP.StaticThreadFunction[THREAD_ID] -> ThreadInfoP;
+  StaticThreadP.ThreadCleanup[THREAD_ID] -> ThreadP.StaticThreadCleanup[THREAD_ID];
+  
+  components LedsC;
+  ThreadInfoP.Leds -> LedsC;
+}
diff --git a/tos/lib/tosthreads/system/ThreadInfoMapP.nc b/tos/lib/tosthreads/system/ThreadInfoMapP.nc
new file mode 100644 (file)
index 0000000..eb1cad0
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module ThreadInfoMapP {
+  provides {
+    interface ThreadInfo[uint8_t id];
+    interface ThreadCleanup as StaticThreadCleanup[uint8_t id];
+    interface ThreadCleanup as DynamicThreadCleanup[uint8_t id];
+  }
+  uses {
+    interface ThreadInfo as StaticThreadInfo[uint8_t id];
+    interface ThreadInfo as DynamicThreadInfo[uint8_t id];
+    interface ThreadCleanup[uint8_t id];
+    interface Leds;
+  }
+}
+implementation {
+  async command thread_t* ThreadInfo.get[uint8_t id]() {
+    return call StaticThreadInfo.get[id]();
+  }
+  default async command thread_t* StaticThreadInfo.get[uint8_t id]() {
+    return call DynamicThreadInfo.get[id]();
+  }
+  async event void ThreadCleanup.cleanup[uint8_t id]() {
+    signal StaticThreadCleanup.cleanup[id]();
+  }
+  default async event void StaticThreadCleanup.cleanup[uint8_t id]() {
+    signal DynamicThreadCleanup.cleanup[id]();
+  }
+}
+
+
+
+
diff --git a/tos/lib/tosthreads/system/ThreadInfoP.nc b/tos/lib/tosthreads/system/ThreadInfoP.nc
new file mode 100644 (file)
index 0000000..b971299
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+generic module ThreadInfoP(uint16_t stack_size, uint8_t thread_id) {
+  provides {
+    interface Init;
+    interface ThreadInfo;
+    interface ThreadFunction;
+  }
+  uses {
+    interface Leds;
+  }
+}
+implementation {
+  uint8_t stack[stack_size];
+  thread_t thread_info;
+  
+  void run_thread(void* arg) __attribute__((noinline)) {
+    signal ThreadFunction.signalThreadRun(arg);
+  }
+  
+  command error_t Init.init() {
+    thread_info.next_thread = NULL;
+    thread_info.id = thread_id;
+    thread_info.init_block = NULL;
+    thread_info.stack_ptr = (stack_ptr_t)(STACK_TOP(stack, sizeof(stack)));
+    thread_info.state = TOSTHREAD_STATE_INACTIVE;
+    thread_info.mutex_count = 0;
+    thread_info.start_ptr = run_thread;
+    thread_info.start_arg_ptr = NULL;
+    thread_info.syscall = NULL;
+    return SUCCESS;
+  }
+  
+  async command thread_t* ThreadInfo.get() {
+    return &thread_info;
+  }
+}
diff --git a/tos/lib/tosthreads/system/ThreadP.nc b/tos/lib/tosthreads/system/ThreadP.nc
new file mode 100644 (file)
index 0000000..7069413
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+configuration ThreadP {
+  provides {
+    interface Thread as StaticThread[uint8_t id];
+    interface DynamicThread;
+    interface ThreadNotification as StaticThreadNotification[uint8_t id];
+    interface ThreadNotification as DynamicThreadNotification[uint8_t id];
+    interface ThreadCleanup as StaticThreadCleanup[uint8_t id];
+  }
+  uses {
+    interface ThreadInfo as StaticThreadInfo[uint8_t id];
+    interface ThreadFunction as StaticThreadFunction[uint8_t id];
+  }
+}
+implementation {
+  components StaticThreadP;
+  components DynamicThreadP;
+  components TinyThreadSchedulerC;
+  components ThreadTimersC;
+  components ThreadInfoMapP;
+  components BitArrayUtilsC;
+  components ThreadSleepC;
+  components TosMallocC;
+  
+  StaticThread = StaticThreadP;
+  StaticThreadNotification = StaticThreadP;
+  StaticThreadP.ThreadInfo = StaticThreadInfo;
+  StaticThreadP.ThreadFunction = StaticThreadFunction;
+  StaticThreadP.ThreadSleep -> ThreadSleepC;
+  StaticThreadP.ThreadScheduler -> TinyThreadSchedulerC;
+  
+  DynamicThread = DynamicThreadP;
+  DynamicThreadP.ThreadNotification = DynamicThreadNotification;
+  DynamicThreadP.ThreadSleep -> ThreadSleepC;
+  DynamicThreadP.ThreadScheduler -> TinyThreadSchedulerC;
+  DynamicThreadP.BitArrayUtils -> BitArrayUtilsC;
+  DynamicThreadP.Malloc -> TosMallocC;
+  
+  TinyThreadSchedulerC.ThreadInfo -> ThreadInfoMapP;
+  ThreadInfoMapP.StaticThreadInfo = StaticThreadInfo;
+  ThreadInfoMapP.DynamicThreadInfo -> DynamicThreadP;
+
+  ThreadInfoMapP.ThreadCleanup -> TinyThreadSchedulerC;
+  DynamicThreadP.ThreadCleanup -> ThreadInfoMapP.DynamicThreadCleanup;
+  StaticThreadCleanup = ThreadInfoMapP.StaticThreadCleanup;
+  
+  components LedsC;
+  StaticThreadP.Leds -> LedsC;
+  DynamicThreadP.Leds -> LedsC;
+  ThreadInfoMapP.Leds -> LedsC;
+}
+
diff --git a/tos/lib/tosthreads/system/ThreadQueueC.nc b/tos/lib/tosthreads/system/ThreadQueueC.nc
new file mode 100644 (file)
index 0000000..1b240d4
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "thread.h"
+#include "linked_list.h"
+#include "thread_queue.h"
+
+configuration ThreadQueueC {
+  provides {
+    interface ThreadQueue;
+  }
+}
+implementation {
+  components LinkedListC;
+  components ThreadQueueP;
+  
+  ThreadQueue = ThreadQueueP;
+  ThreadQueueP.LinkedList -> LinkedListC;
+}
diff --git a/tos/lib/tosthreads/system/ThreadQueueP.nc b/tos/lib/tosthreads/system/ThreadQueueP.nc
new file mode 100644 (file)
index 0000000..4e7579d
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module ThreadQueueP {
+  provides {
+    interface ThreadQueue;
+  }
+  uses {
+    interface LinkedList;
+  }
+}
+implementation {
+  async command void ThreadQueue.init(thread_queue_t* q) {
+    call LinkedList.init(&(q->l));
+  }
+  async command void ThreadQueue.enqueue(thread_queue_t* q, thread_t* t) {
+    call LinkedList.addFirst(&(q->l), (list_element_t*)t);
+  }
+  async command thread_t* ThreadQueue.dequeue(thread_queue_t* q) {
+    return (thread_t*)call LinkedList.removeLast(&(q->l));
+  }
+  async command thread_t* ThreadQueue.remove(thread_queue_t* q, thread_t* t) {
+    return (thread_t*)call LinkedList.remove(&(q->l), (list_element_t*)t);
+  }
+  async command bool ThreadQueue.isEmpty(thread_queue_t* q) {
+    return (call LinkedList.size(&(q->l)) == 0);
+  }
+}
diff --git a/tos/lib/tosthreads/system/ThreadSleepC.nc b/tos/lib/tosthreads/system/ThreadSleepC.nc
new file mode 100644 (file)
index 0000000..e58a2ac
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+configuration ThreadSleepC {
+  provides {
+    interface ThreadSleep;
+  }
+}
+implementation {
+  components ThreadTimersC;
+  components ThreadSleepP;
+  components SystemCallC;
+  components TinyThreadSchedulerC;
+  
+  ThreadSleep = ThreadSleepP;
+  ThreadSleepP.TimerMilli -> ThreadTimersC;
+  ThreadSleepP.SystemCall -> SystemCallC;
+  ThreadSleepP.ThreadScheduler -> TinyThreadSchedulerC;
+  
+  components LedsC;
+  ThreadSleepP.Leds -> LedsC;
+}
+
diff --git a/tos/lib/tosthreads/system/ThreadSleepP.nc b/tos/lib/tosthreads/system/ThreadSleepP.nc
new file mode 100644 (file)
index 0000000..65554cf
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+module ThreadSleepP {
+  provides {
+    interface ThreadSleep;
+  }
+  uses {
+    interface SystemCall;
+    interface ThreadScheduler;
+    interface Timer<TMilli> as TimerMilli[uint8_t id];
+    interface Leds;
+  }
+}
+implementation {
+  typedef struct sleep_params {
+    uint32_t* milli;
+  } sleep_params_t;
+  
+  void sleepTask(syscall_t* s) {
+    sleep_params_t* p = s->params;
+    call TimerMilli.startOneShot[s->thread->id]( *(p->milli) );
+  }
+  
+  command error_t ThreadSleep.sleep(uint32_t milli) {
+    syscall_t s;
+    sleep_params_t p;    
+    p.milli = &milli;
+    call SystemCall.start(&sleepTask, &s, INVALID_ID, &p);
+    return SUCCESS;
+  }
+  
+  event void TimerMilli.fired[uint8_t id]() {
+    thread_t* t = call ThreadScheduler.threadInfo(id);
+    call SystemCall.finish(t->syscall);
+  }
+}
diff --git a/tos/lib/tosthreads/system/ThreadSynchronizationC.nc b/tos/lib/tosthreads/system/ThreadSynchronizationC.nc
new file mode 100644 (file)
index 0000000..7c56c8b
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+configuration ThreadSynchronizationC {
+  provides {
+    interface Barrier;
+    interface Mutex;
+    interface Semaphore;
+    interface ConditionVariable;
+    interface ReferenceCounter;
+  }
+}
+implementation {
+  components BarrierC;
+  components MutexC;
+  components SemaphoreC;
+  components ConditionVariableC;
+  components ReferenceCounterC;
+  
+  Barrier = BarrierC;
+  Mutex = MutexC;
+  Semaphore = SemaphoreC;
+  ConditionVariable = ConditionVariableC;
+  ReferenceCounter = ReferenceCounterC;
+}
diff --git a/tos/lib/tosthreads/system/ThreadTimersC.nc b/tos/lib/tosthreads/system/ThreadTimersC.nc
new file mode 100644 (file)
index 0000000..3d29464
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#include "thread.h"
+
+configuration ThreadTimersC {
+  provides {
+    interface Timer<TMilli> as TimerMilli[uint8_t id];
+  }
+}
+implementation {
+  components new TimerMilliC();
+  components new VirtualizeTimerC(TMilli, TOSTHREAD_MAX_NUM_THREADS);
+  
+  VirtualizeTimerC.TimerFrom -> TimerMilliC;
+  TimerMilli = VirtualizeTimerC.Timer;
+}
diff --git a/tos/lib/tosthreads/system/TinyOSMainP.nc b/tos/lib/tosthreads/system/TinyOSMainP.nc
new file mode 100644 (file)
index 0000000..2df6d5d
--- /dev/null
@@ -0,0 +1,105 @@
+// $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:            Philip Levis
+ * Date last modified:  $Id$
+ *
+ */
+
+/**
+ * RealMain implements the TinyOS boot sequence, as documented in TEP 107.
+ *
+ * @author Philip Levis
+ * @author Kevin Klues <klueska@cs.stanford.edu> 
+ */
+
+module TinyOSMainP {
+  provides {
+    interface Boot;
+    interface ThreadInfo;
+  }
+  uses {
+    interface Boot as TinyOSBoot;
+    interface TaskScheduler;
+    interface Init as PlatformInit;
+    interface Init as SoftwareInit;
+    interface Leds;
+  }
+}
+implementation {
+  thread_t thread_info;
+
+  event void TinyOSBoot.booted() {
+    atomic {
+      /*  Initialize all of the very hardware specific stuff, such
+         as CPU settings, counters, etc. After the hardware is ready,
+         initialize the requisite software components and start
+         execution. */
+         platform_bootstrap();
+    
+         // First, initialize the Scheduler so components can post tasks.
+         call TaskScheduler.init(); 
+    
+         /* Initialize the platform. Then spin on the Scheduler, passing
+          * FALSE so it will not put the system to sleep if there are no
+          * more tasks; if no tasks remain, continue on to software
+          * initialization */
+         call PlatformInit.init();
+         while (call TaskScheduler.runNextTask());
+         
+         /* Initialize software components.Then spin on the Scheduler,
+          * passing FALSE so it will not put the system to sleep if there
+          * are no more tasks; if no tasks remain, the system has booted
+          * successfully.*/
+         call SoftwareInit.init(); 
+         while (call TaskScheduler.runNextTask());
+    }
+
+    /* Enable interrupts now that system is ready. */
+    __nesc_enable_interrupt();
+
+    signal Boot.booted();
+
+    /* Spin in the TaskScheduler */
+    call TaskScheduler.taskLoop();
+    
+  }
+
+  async command thread_t* ThreadInfo.get() {
+    return &thread_info;
+  }
+
+  default command error_t PlatformInit.init() { return SUCCESS; }
+  default command error_t SoftwareInit.init() { return SUCCESS; }
+  default event void Boot.booted() { }
+}
+
diff --git a/tos/lib/tosthreads/system/TinyTaskSchedulerC.nc b/tos/lib/tosthreads/system/TinyTaskSchedulerC.nc
new file mode 100644 (file)
index 0000000..03079f1
--- /dev/null
@@ -0,0 +1,51 @@
+// $Id$
+/*
+ * "Copyright (c) 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."
+ */
+
+/**
+ * The TinyOS scheduler. It provides two interfaces: Scheduler,
+ * for TinyOS to initialize and run tasks, and TaskBasic, the simplext
+ * class of TinyOS tasks (reserved always at-most-once posting,
+ * FIFO, parameter-free). For details and information on how to
+ * replace the scheduler, refer to TEP 106.
+ *
+ * @author  Phil Levis
+ * @author  Kevin Klues <klueska@cs.stanford.edu>
+ * @date    August 7 2005
+ * @see     TEP 106: Tasks and Schedulers
+ */
+
+configuration TinyTaskSchedulerC {
+  provides interface TaskScheduler;
+  provides interface TaskBasic[uint8_t id];
+  uses interface ThreadScheduler;
+}
+implementation {
+  components SchedulerBasicP as Sched;
+  components McuSleepC as Sleep;
+  TaskScheduler = Sched;
+  TaskBasic = Sched;
+  Sched.ThreadScheduler = ThreadScheduler;
+  
+  components LedsC;
+  Sched.Leds -> LedsC;
+}
+
diff --git a/tos/lib/tosthreads/system/TinyThreadSchedulerC.nc b/tos/lib/tosthreads/system/TinyThreadSchedulerC.nc
new file mode 100644 (file)
index 0000000..cf5c283
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#include "thread.h"
+
+configuration TinyThreadSchedulerC {
+  provides {
+    interface ThreadScheduler;
+    interface ThreadCleanup[uint8_t id];
+    interface Boot as TinyOSBoot;
+  }
+  uses {
+    interface Boot as ThreadSchedulerBoot;
+    interface ThreadInfo[uint8_t id];
+  }
+}
+implementation {
+  components TinyThreadSchedulerP as Sched;
+  components McuSleepC as Sleep;
+  
+  TinyOSBoot = Sched;
+  ThreadSchedulerBoot = Sched.ThreadSchedulerBoot;
+  ThreadInfo = Sched;
+  ThreadCleanup = Sched;
+  ThreadScheduler = Sched;
+  Sched.McuSleep -> Sleep;
+  
+  components ThreadQueueC;
+  Sched.ThreadQueue -> ThreadQueueC;
+  
+  components new TimerMilliC() as Alarm;
+  Sched.PreemptionAlarm -> Alarm;
+  
+  components LedsC;
+  Sched.Leds -> LedsC;
+}
+
+
diff --git a/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc b/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc
new file mode 100644 (file)
index 0000000..1ae6770
--- /dev/null
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+module TinyThreadSchedulerP {
+  provides {
+    interface ThreadScheduler;
+    interface Boot as TinyOSBoot;
+    interface ThreadCleanup[uint8_t id];
+  }
+  uses {
+    interface Boot as ThreadSchedulerBoot;
+    interface ThreadInfo[uint8_t id];
+    interface ThreadQueue;
+    interface McuSleep;
+    interface Leds;
+    interface Timer<TMilli> as PreemptionAlarm;
+  }
+}
+implementation {
+  //Pointer to currently running thread
+  thread_t* current_thread;
+  //Pointer to the tos thread
+  thread_t* tos_thread;
+  //Pointer to yielding thread
+  thread_t* yielding_thread;
+  //Number of threads started, and currently capable of running if given the chance
+  uint8_t num_started_threads;
+  //Thread queue for keeping track of threads waiting to run
+  thread_queue_t ready_queue;
+  
+  /* switch_threads()
+   * This routine swaps the stack and allows a thread to run.
+   * Needs to be in a separate function like this so that the 
+   * PC counter gets saved on the stack correctly.
+   *
+   * This funciton should have NOTHING other than the call
+   * to the SWITCH_CONTEXTS macro in it.  Otherwise we run
+   * the risk of variables being pushed and popped by the 
+   * compiler, causing obvious problems with the stack switching
+   * thats going on....
+   */
+  void switchThreads() __attribute__((noinline)) {
+    SWITCH_CONTEXTS(yielding_thread, current_thread);
+  }
+  void restoreThread() __attribute__((noinline)) {
+    RESTORE_TCB(current_thread);
+  }
+  
+  /* sleepWhileIdle() 
+   * This routine is responsible for putting the mcu to sleep as 
+   * long as there are no threads waiting to be run.  Once a
+   * thread has been added to the ready queue the mcu will be
+   * woken up and the thread will start running
+   */
+  void sleepWhileIdle() {
+    while(TRUE) {
+      bool mt;
+      atomic mt = (call ThreadQueue.isEmpty(&ready_queue) == TRUE);
+      if(!mt) break;
+      call McuSleep.sleep();
+    }
+  }
+  
+  /* schedule_next_thread()
+   * This routine does the job of deciding which thread should run next.
+   * Should be complete as is.  Add functionality to getNextThreadId() 
+   * if you need to change the actual scheduling policy.
+   */
+  void scheduleNextThread() {
+    if(tos_thread->state == TOSTHREAD_STATE_READY)
+      current_thread = call ThreadQueue.remove(&ready_queue, tos_thread);
+    else
+      current_thread = call ThreadQueue.dequeue(&ready_queue);
+
+    current_thread->state = TOSTHREAD_STATE_ACTIVE;
+  }
+  
+  /* interrupt()
+   * This routine figures out what thread should run next
+   * and then switches to it.
+   */
+  void interrupt(thread_t* thread) {
+    yielding_thread = thread;
+    scheduleNextThread();
+    if(current_thread != yielding_thread) {
+      switchThreads();
+    }
+  }
+  
+  /* suspend()
+   * this routine is responsbile for suspending a thread.  It first 
+   * checks to see if the mcu should be put to sleep based on the fact 
+   * that the thread is being suspended.  If not, it proceeds to switch
+   * contexts to the next thread on the ready queue.
+   */
+  void suspend(thread_t* thread) {
+    //if there are no active threads, put the MCU to sleep
+    //Then wakeup the TinyOS thread whenever the MCU wakes up again
+    sleepWhileIdle();
+    interrupt(thread);
+  }
+  
+  /* stop
+   * This routine stops a thread by putting it into the inactive state
+   * and decrementing any necessary variables used to keep track of
+   * threads by the thread scheduler.
+   */
+   void stop(thread_t* t) {
+     t->state = TOSTHREAD_STATE_INACTIVE;
+     num_started_threads--;
+     if(num_started_threads == 1)
+       call PreemptionAlarm.stop();
+     signal ThreadCleanup.cleanup[t->id]();
+   }
+  
+  /* This executes and cleans up a thread
+   */
+  void threadWrapper() __attribute__((naked, noinline)) {
+    thread_t* t;
+    atomic t = current_thread;
+    
+    __nesc_enable_interrupt();
+    (*(t->start_ptr))(t->start_arg_ptr);
+    
+    atomic {
+      stop(t);
+      sleepWhileIdle();
+      scheduleNextThread();
+      restoreThread();
+    }
+  } 
+  
+  event void ThreadSchedulerBoot.booted() {
+    num_started_threads = 0;
+    tos_thread = call ThreadInfo.get[TOSTHREAD_TOS_THREAD_ID]();
+    tos_thread->id = TOSTHREAD_TOS_THREAD_ID;
+    call ThreadQueue.init(&ready_queue);
+    
+    current_thread = tos_thread;
+    current_thread->state = TOSTHREAD_STATE_ACTIVE;
+    current_thread->init_block = NULL;
+    signal TinyOSBoot.booted();
+  }
+  
+  command error_t ThreadScheduler.initThread(uint8_t id) { 
+    thread_t* t = (call ThreadInfo.get[id]());
+    t->state = TOSTHREAD_STATE_INACTIVE;
+    t->init_block = current_thread->init_block;
+    PREPARE_THREAD(t, threadWrapper);
+    return SUCCESS;
+  }
+  
+  command error_t ThreadScheduler.startThread(uint8_t id) {
+    atomic {
+      thread_t* t = (call ThreadInfo.get[id]());
+      if(t->state == TOSTHREAD_STATE_INACTIVE) {
+        num_started_threads++;
+        if(num_started_threads == 2)
+          call PreemptionAlarm.startOneShot(TOSTHREAD_PREEMPTION_PERIOD);
+        t->state = TOSTHREAD_STATE_READY;
+        call ThreadQueue.enqueue(&ready_queue, t);
+        return SUCCESS;
+      }
+    }
+    return FAIL;  
+  }
+  
+  command error_t ThreadScheduler.stopThread(uint8_t id) { 
+    atomic {
+      thread_t* t = call ThreadInfo.get[id]();
+      if((t->state == TOSTHREAD_STATE_READY) && (t->mutex_count == 0)) {
+        call ThreadQueue.remove(&ready_queue, t);
+        stop(t);
+        return SUCCESS;
+      }
+      return FAIL;
+    }
+  }
+  
+  async command error_t ThreadScheduler.suspendCurrentThread() {
+    atomic {
+      if(current_thread->state == TOSTHREAD_STATE_ACTIVE) {
+        current_thread->state = TOSTHREAD_STATE_SUSPENDED;
+        suspend(current_thread);
+        return SUCCESS;
+      }
+      return FAIL;
+    }
+  }
+  
+  async command error_t ThreadScheduler.interruptCurrentThread() { 
+    atomic {
+      if(current_thread->state == TOSTHREAD_STATE_ACTIVE) {
+        current_thread->state = TOSTHREAD_STATE_READY;
+        call ThreadQueue.enqueue(&ready_queue, current_thread);
+        interrupt(current_thread);
+        return SUCCESS;
+      }
+      return FAIL;
+    }
+  }
+  
+  async command error_t ThreadScheduler.wakeupThread(uint8_t id) {
+    thread_t* t = call ThreadInfo.get[id]();
+    if((t->state) == TOSTHREAD_STATE_SUSPENDED) {
+      t->state = TOSTHREAD_STATE_READY;
+      call ThreadQueue.enqueue(&ready_queue, call ThreadInfo.get[id]());
+      return SUCCESS;
+    }
+    return FAIL;
+  }
+  
+  async command uint8_t ThreadScheduler.currentThreadId() {
+    atomic return current_thread->id;
+  }    
+  
+  async command thread_t* ThreadScheduler.threadInfo(uint8_t id) {
+    atomic return call ThreadInfo.get[id]();
+  }   
+  
+  async command thread_t* ThreadScheduler.currentThreadInfo() {
+    atomic return current_thread;
+  }
+  
+  event void PreemptionAlarm.fired() {
+    call PreemptionAlarm.startOneShot(TOSTHREAD_PREEMPTION_PERIOD);
+    atomic {
+      if((call ThreadQueue.isEmpty(&ready_queue) == FALSE)) {
+        call ThreadScheduler.interruptCurrentThread();
+      }
+    }
+  }
+  
+  default async command thread_t* ThreadInfo.get[uint8_t id]() {
+    return NULL;
+  }
+}
+
diff --git a/tos/lib/tosthreads/system/TosMallocC.nc b/tos/lib/tosthreads/system/TosMallocC.nc
new file mode 100644 (file)
index 0000000..7f811e2
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ * Implementation borrowed from the msp430-libc implementation
+ */
+/*
+ * MALLOC_HEAP_SIZE MUST be defined as a power of 2
+ */
+#ifndef MALLOC_HEAP_SIZE
+#define MALLOC_HEAP_SIZE 1024
+#endif
+module TosMallocC {
+  provides interface Malloc;
+}
+implementation {
+  #define XSIZE(x) ((*x)>>1)
+  #define FREE_P(x) (!((*x)&1))
+  #define MARK_BUSY(x) ((*x)|=1)
+  #define MARK_FREE(x) ((*x)&=0xfffe)
+
+  size_t malloc_heap[MALLOC_HEAP_SIZE];
+
+  void *tos_malloc (size_t size) @C() @spontaneous()
+  {
+    static char once = 0;
+    size_t * heap_bottom = &(malloc_heap[MALLOC_HEAP_SIZE]);
+    size_t * heap_top = malloc_heap;
+    char f = 0;
+
+    atomic if (!once)
+    {
+        once = 1;
+        *heap_top = 0xFFFE;
+    }
+    size = (size+1) >> 1;      /* round to 2 */
+    do
+    {
+        size_t xsize = XSIZE (heap_top);
+        size_t * heap_next = &heap_top[xsize + 1];
+        if ((xsize<<1)+2 == 0)
+        {
+            f = 1;
+        }
+        if (FREE_P (heap_top))
+        {
+            if (f)
+            {
+                xsize = heap_bottom - heap_top - 1;
+            }
+            else if (FREE_P(heap_next))
+            {
+                *heap_top = ( (XSIZE(heap_next)<<1) + 2 == 0
+                              ? 0xfffe
+                              : (xsize + XSIZE(heap_next) + 1)<<1);
+                continue;
+            }
+            if (xsize >= size)
+            {
+                if (f)
+                    heap_top[size + 1] = 0xfffe;
+                else if (xsize != size)
+                    heap_top[size + 1] = (xsize - size - 1) << 1;
+                *heap_top = size << 1;
+                MARK_BUSY (heap_top);
+                return heap_top+1;
+            }
+        }
+        heap_top += xsize + 1;
+    }
+    while (!f);
+    return NULL;
+  }
+
+  void tos_free (void *p) @C() @spontaneous()
+  {
+    size_t *t = (size_t*)p - 1;
+    MARK_FREE (t);
+  }
+  
+  async command void* Malloc.malloc(size_t size) {
+    return tos_malloc(size);
+  }
+  
+  async command void Malloc.free(void* p) {
+    tos_free(p);
+  }
+}
diff --git a/tos/lib/tosthreads/types/barrier.h b/tos/lib/tosthreads/types/barrier.h
new file mode 100644 (file)
index 0000000..449f121
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * Header file declaring struct for barrier synchronization as used
+ * with tosthreads.
+ *
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#ifndef BARRIER_H
+#define BARRIER_H
+
+#include "thread.h"
+#include "thread_queue.h"
+
+typedef struct barrier {
+  uint8_t count;
+  thread_queue_t thread_queue;
+} barrier_t;
+
+#endif //BARRIER_H
diff --git a/tos/lib/tosthreads/types/condvar.h b/tos/lib/tosthreads/types/condvar.h
new file mode 100644 (file)
index 0000000..ad44925
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues (klueska@cs.stanford.edu)
+ */
+
+#ifndef CONDVAR_H
+#define CONDVAR_H
+
+#include "thread.h"
+#include "thread_queue.h"
+#include "mutex.h"
+
+typedef struct condvar {
+  thread_queue_t thread_queue;
+} condvar_t;
+
+#endif //COND_VAR_H
diff --git a/tos/lib/tosthreads/types/linked_list.h b/tos/lib/tosthreads/types/linked_list.h
new file mode 100644 (file)
index 0000000..2a60de3
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef LINKED_LIST_H_INCLUDED
+#define LINKED_LIST_H_INCLUDED
+
+typedef struct list_element {
+  struct list_element* next;
+  uint8_t element_data[0];
+} list_element_t;
+
+typedef struct linked_list {
+  list_element_t* head; 
+  volatile uint8_t size;
+} linked_list_t;
+
+#endif //LINKED_LIST_H_INCLUDED
diff --git a/tos/lib/tosthreads/types/mutex.h b/tos/lib/tosthreads/types/mutex.h
new file mode 100644 (file)
index 0000000..bff0cdf
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#ifndef MUTEX_H
+#define MUTEX_H
+
+#include "thread_queue.h"
+
+typedef struct mutex {
+  bool lock;
+  thread_queue_t thread_queue;
+} mutex_t;
+
+#endif //MUTEX_H
diff --git a/tos/lib/tosthreads/types/poolthread.h b/tos/lib/tosthreads/types/poolthread.h
new file mode 100644 (file)
index 0000000..049fe84
--- /dev/null
@@ -0,0 +1,14 @@
+
+#ifndef _POOL_THREAD_H_
+#define _POOL_THREAD_H_
+
+#ifndef NUM_POOL_THREADS
+#define NUM_POOL_THREADS 5
+#endif
+
+#ifndef POOL_THREAD_STACK_SIZE
+#define POOL_THREAD_STACK_SIZE 200
+#endif
+
+#endif
+
diff --git a/tos/lib/tosthreads/types/queue.h b/tos/lib/tosthreads/types/queue.h
new file mode 100644 (file)
index 0000000..5290165
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef QUEUE_H_INCLUDED
+#define QUEUE_H_INCLUDED
+
+#include "linked_list.h"
+#include "tosthread_linked_list.h"
+
+typedef struct queue {
+  linked_list_t l;
+} queue_t;
+
+typedef linked_list_t queue_element_t;
+
+#endif //QUEUE_H_INCLUDED
diff --git a/tos/lib/tosthreads/types/refcounter.h b/tos/lib/tosthreads/types/refcounter.h
new file mode 100644 (file)
index 0000000..395a1bc
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#ifndef REFCOUNTER_H
+#define REFCOUNTER_H
+
+#include "thread.h"
+#include "thread_queue.h"
+
+typedef struct refcounter {
+  uint8_t count;
+  thread_queue_t thread_queue;
+} refcounter_t;
+
+#endif //REFCOUNTER_H
diff --git a/tos/lib/tosthreads/types/semaphore.h b/tos/lib/tosthreads/types/semaphore.h
new file mode 100644 (file)
index 0000000..018f596
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2008 Johns Hopkins University.
+ * 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 (updated) modification history and the author appear in
+ * all copies of this source code.
+ *
+ * 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 HOLDERS OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
+ * OR PROFITS) 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 Chieh-Jan Mike Liang <cliang4@cs.jhu.edu>
+ */
+
+#ifndef SEMAPHORE_H
+#define SEMAPHORE_H
+
+#include "thread.h"
+#include "mutex.h"
+#include "condvar.h"
+  
+typedef struct semaphore {
+  uint8_t v;
+  uint8_t s;
+  mutex_t lock;
+  condvar_t condvar;
+} semaphore_t;
+
+#endif //SEMAPHORE_H
diff --git a/tos/lib/tosthreads/types/syscall_queue.h b/tos/lib/tosthreads/types/syscall_queue.h
new file mode 100644 (file)
index 0000000..5588bd7
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef SYSCALL_QUEUE_H
+#define SYSCALL_QUEUE_H
+
+#include "linked_list.h"
+
+typedef struct syscall_queue {
+  linked_list_t l;                             //The syscall_queue implementation uses a linked list
+} syscall_queue_t;
+
+#endif //SYSCALL_QUEUE_H
diff --git a/tos/lib/tosthreads/types/thread.h b/tos/lib/tosthreads/types/thread.h
new file mode 100644 (file)
index 0000000..c86d9f7
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+
+#ifndef THREAD_H
+#define THREAD_H
+
+#include "chip_thread.h"
+#include "refcounter.h"
+
+typedef uint8_t thread_id_t;                           //Typedef for thread_id_t
+typedef uint8_t syscall_id_t;                          //Typedef for syscall_id_t
+typedef thread_id_t tosthread_t;                       //Typedef for tosthread_t used to initialize a c-based thread
+
+#ifndef TOSTHREAD_MAIN_STACK_SIZE
+#define TOSTHREAD_MAIN_STACK_SIZE   500  //Default stack size for the main thread that spawns all other threads in the c based api
+#endif
+
+//Since thread initialization is encapsulated 
+//inside a generic component, we can statically 
+//know the number of threads created at compile 
+//time
+#define UQ_TOS_THREAD "Unique.TOS.Thread"
+enum {
+#ifdef MAX_NUM_THREADS
+  TOSTHREAD_MAX_NUM_THREADS = MAX_NUM_THREADS,
+#else
+  TOSTHREAD_MAX_NUM_THREADS = 33,   //Maximum number of threads allowed to run (must be less than sizeof(thread_id_t))
+#endif
+  TOSTHREAD_NUM_STATIC_THREADS = uniqueCount(UQ_TOS_THREAD),  //The number of statically allocated threads
+  TOSTHREAD_MAX_DYNAMIC_THREADS = TOSTHREAD_MAX_NUM_THREADS - TOSTHREAD_NUM_STATIC_THREADS,
+  TOSTHREAD_TOS_THREAD_ID = TOSTHREAD_MAX_NUM_THREADS,        //The ID of the TinyOS thread (One more than max allowable threads)
+  TOSTHREAD_INVALID_THREAD_ID = TOSTHREAD_MAX_NUM_THREADS,    //An invalid thread id
+  TOSTHREAD_PREEMPTION_PERIOD = 5,                            //The preemption period for switching between threads
+};
+
+enum {
+  INVALID_ID = 0xFF,            //ID reserved to indicate an invalid client connected
+  SYSCALL_WAIT_ON_EVENT = 0,    //Indicates there is no actual system call to make, but rather should jsut wait on an event
+};
+
+typedef struct syscall syscall_t;
+typedef struct thread thread_t;
+typedef struct init_block init_block_t;
+
+//This is the data structure associated with an initialization block from which 
+//threads are spawned when dynamically loading them
+struct init_block {
+  void* globals;
+  void (*init_ptr)(void*);
+  void* init_arg;
+  refcounter_t thread_counter;
+};
+
+//This is a system call data structure
+struct syscall {
+  //***** next_call must be at first position in struct for casting purposes *******
+  struct syscall* next_call;        //Pointer to next system call for use in syscall queues when blocking on them
+  syscall_id_t id;                  //client id of this system call for the particular syscall_queue within which it is being held
+  thread_t* thread;                 //Pointer back to the thread with which this system call is associated
+  void (*syscall_ptr)(struct syscall*);   //Pointer to the the function that actually performs the system call
+  void* params;                     //Pointer to a set of parameters passed to the system call once it is running in task context
+};
+
+//This is a thread data structure
+//This structure is 43 bytes long...
+struct thread {
+  //***** next_thread must be at first position in struct for casting purposes *******
+  volatile struct thread* next_thread;  //Pointer to next thread for use in queues when blocked
+  thread_id_t id;                       //id of this thread for use by the thread scheduler
+  init_block_t* init_block;             //Pointer to an initialization block from which this thread was spawned
+  stack_ptr_t stack_ptr;                //Pointer to this threads stack
+  volatile uint8_t state;               //Current state the thread is in
+  volatile uint8_t mutex_count;         //A reference count of the number of mutexes held by this thread
+  void (*start_ptr)(void*);             //Pointer to the start function of this thread
+  void* start_arg_ptr;                  //Pointer to the argument passed as a parameter to the start function of this thread
+  syscall_t* syscall;                   //Pointer to an instance of a system call
+  thread_regs_t regs;                   //Contents of the GPRs stored when doing a context switch
+};
+
+enum {
+  TOSTHREAD_STATE_INACTIVE    = 0,  //This thread is inactive and cannot be run until started
+  TOSTHREAD_STATE_ACTIVE      = 1,  //This thread is currently running and using the cpu
+  TOSTHREAD_STATE_READY       = 2,  //This thread is not currently running, but is not blocked and has work to do 
+  TOSTHREAD_STATE_SUSPENDED   = 3,  //This thread has been suspended by a system call (i.e. blocked)
+};
+
+#endif //THREAD_H
diff --git a/tos/lib/tosthreads/types/thread_queue.h b/tos/lib/tosthreads/types/thread_queue.h
new file mode 100644 (file)
index 0000000..209fd36
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008 Stanford University.
+ * 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 Stanford University 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 STANFORD
+ * UNIVERSITY 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.
+ */
+/**
+ * @author Kevin Klues <klueska@cs.stanford.edu>
+ */
+#ifndef THREAD_QUEUE_H
+#define THREAD_QUEUE_H
+
+#include "linked_list.h"
+
+typedef struct thread_queue {
+  linked_list_t l;                             //The thread_queue implementation uses a linked list
+} thread_queue_t;
+
+#endif //THREAD_QUEUE_H