From b67f4e9145bb6be91430fb7beb3fe5bcf56b9ca0 Mon Sep 17 00:00:00 2001 From: r-studio Date: Mon, 7 Sep 2009 14:14:52 +0000 Subject: [PATCH] mulles files --- support/make/m16c62p/crt.S | 196 ++++++++++++ support/make/m16c62p/debug.extra | 4 + support/make/m16c62p/debugopt.extra | 4 + support/make/m16c62p/install.extra | 10 + support/make/m16c62p/m16c.x | 176 +++++++++++ support/make/m16c62p/m16c62p.rules | 126 ++++++++ support/make/m16c62p/reinstall.extra | 6 + support/make/m16c62p/sm16cf.extra | 27 ++ tos/chips/m16c62p/control/M16c62pControl.h | 79 +++++ tos/chips/m16c62p/control/M16c62pControl.nc | 63 ++++ tos/chips/m16c62p/control/M16c62pControlC.nc | 54 ++++ tos/chips/m16c62p/control/M16c62pControlP.nc | 296 ++++++++++++++++++ .../m16c62p/control/M16c62pControlPlatform.nc | 57 ++++ tos/chips/m16c62p/control/StopModeControl.nc | 52 +++ tos/chips/m16c62p/control/StopModeControlC.nc | 59 ++++ .../m16c62p/control/SystemClockControl.nc | 50 +++ .../m16c62p/control/SystemClockControlC.nc | 59 ++++ .../m16c62p/pins/HplM16c62pGeneralIOC.nc | 289 +++++++++++++++++ .../m16c62p/pins/HplM16c62pGeneralIOPinP.nc | 88 ++++++ .../m16c62p/pins/HplM16c62pGeneralIOPortP.nc | 103 ++++++ tos/chips/m16c62p/pins/HplM16c62pInterrupt.nc | 106 +++++++ .../m16c62p/pins/HplM16c62pInterruptC.nc | 104 ++++++ .../m16c62p/pins/HplM16c62pInterruptPinP.nc | 119 +++++++ .../m16c62p/pins/HplM16c62pInterruptSig.nc | 79 +++++ .../m16c62p/pins/HplM16c62pInterruptSigP.nc | 115 +++++++ tos/chips/m16c62p/pins/M16c62pInterruptC.nc | 111 +++++++ tos/chips/m16c62p/timer/HplM16c62pTimer.nc | 143 +++++++++ .../m16c62p/timer/HplM16c62pTimerACtrl.nc | 72 +++++ .../m16c62p/timer/HplM16c62pTimerACtrlP.nc | 131 ++++++++ .../m16c62p/timer/HplM16c62pTimerBCtrl.nc | 61 ++++ .../m16c62p/timer/HplM16c62pTimerBCtrlP.nc | 61 ++++ tos/chips/m16c62p/timer/HplM16c62pTimerC.nc | 168 ++++++++++ .../m16c62p/timer/HplM16c62pTimerInterrupt.nc | 49 +++ .../timer/HplM16c62pTimerInterruptP.nc | 126 ++++++++ tos/chips/m16c62p/timer/HplM16c62pTimerP.nc | 117 +++++++ tos/chips/m16c62p/timer/M16c62pAlarm16C.nc | 117 +++++++ tos/chips/m16c62p/timer/M16c62pAlarm32C.nc | 163 ++++++++++ tos/chips/m16c62p/timer/M16c62pCounter16C.nc | 71 +++++ tos/chips/m16c62p/timer/M16c62pCounter32C.nc | 79 +++++ tos/chips/m16c62p/timer/M16c62pTimer.h | 181 +++++++++++ tos/chips/m16c62p/timer/M16c62pTimerAInitC.nc | 107 +++++++ tos/chips/m16c62p/timer/M16c62pTimerBInitC.nc | 103 ++++++ tos/chips/m16c62p/uart/HplM16c62pUart.nc | 88 ++++++ tos/chips/m16c62p/uart/HplM16c62pUartC.nc | 150 +++++++++ .../m16c62p/uart/HplM16c62pUartInterrupt.nc | 54 ++++ .../m16c62p/uart/HplM16c62pUartInterruptP.nc | 89 ++++++ tos/chips/m16c62p/uart/HplM16c62pUartP.nc | 242 ++++++++++++++ tos/chips/m16c62p/uart/M16c62pUartC.nc | 133 ++++++++ tos/chips/m16c62p/uart/M16c62pUartP.nc | 279 +++++++++++++++++ .../Deluge/extra/m16c62p/HplM16c62pFlash.nc | 71 +++++ .../Deluge/extra/m16c62p/HplM16c62pFlashC.nc | 241 ++++++++++++++ .../Deluge/extra/m16c62p/InternalFlashC.nc | 52 +++ .../Deluge/extra/m16c62p/InternalFlashP.nc | 83 +++++ .../net/Deluge/extra/m16c62p/M16c62pFlash.h | 65 ++++ .../net/Deluge/extra/mulle/NetProg_platform.h | 58 ++++ .../net/Deluge/extra/mulle/ReprogramGuardC.nc | 11 + .../net/Deluge/extra/mulle/ReprogramGuardP.nc | 22 ++ .../net/Deluge/extra/mulle/TOSBoot_platform.h | 15 + tos/lib/tosboot/m16c62p/HardwareC.nc | 72 +++++ tos/lib/tosboot/m16c62p/ProgFlashM.nc | 53 ++++ tos/lib/tosboot/m16c62p/ProgFlashP.nc | 113 +++++++ tos/lib/tosboot/mulle/ExecC.nc | 61 ++++ tos/lib/tosboot/mulle/PluginC.nc | 54 ++++ tos/lib/tosboot/mulle/VoltageC.nc | 58 ++++ tos/lib/tosboot/mulle/hardware.h | 88 ++++++ tos/lib/tosboot/mulle/m16chardware.h | 123 ++++++++ tos/platforms/mulle/.platform | 36 +++ tos/platforms/mulle/ActiveMessageC.nc | 70 +++++ tos/platforms/mulle/DemoSensorC.nc | 63 ++++ tos/platforms/mulle/PlatformC.nc | 70 +++++ tos/platforms/mulle/PlatformLedsC.nc | 59 ++++ tos/platforms/mulle/PlatformP.nc | 83 +++++ tos/platforms/mulle/PlatformSerialC.nc | 61 ++++ tos/platforms/mulle/TimeSyncMessageC.nc | 63 ++++ tos/platforms/mulle/chips/at45db/At45dbSpi.h | 47 +++ .../mulle/chips/at45db/HplAt45dbC.nc | 70 +++++ .../mulle/chips/at45db/HplAt45dbP.nc | 128 ++++++++ .../mulle/chips/at45db/HplAt45db_chip.h | 45 +++ .../mulle/chips/at45db/SoftSpiAt45dbC.nc | 63 ++++ .../mulle/chips/at45db/SoftSpiAt45dbP.nc | 66 ++++ .../chips/m16c62p/M16c62pControlPlatformC.nc | 70 +++++ tos/platforms/mulle/chips/rf230/HplRF230C.nc | 94 ++++++ tos/platforms/mulle/chips/rf230/HplRF230P.nc | 126 ++++++++ .../mulle/chips/rf230/Mulle_RF230Spi.h | 47 +++ .../mulle/chips/rf230/RF230SplitControlP.nc | 79 +++++ tos/platforms/mulle/chips/rf230/RadioConfig.h | 133 ++++++++ .../mulle/chips/rf230/SoftSpiRF230C.nc | 65 ++++ .../mulle/chips/rf230/SoftSpiRF230P.nc | 69 ++++ tos/platforms/mulle/chips/rv8564/RV8564.nc | 89 ++++++ tos/platforms/mulle/chips/rv8564/RV8564C.nc | 62 ++++ tos/platforms/mulle/chips/rv8564/RV8564P.nc | 127 ++++++++ tos/platforms/mulle/chips/rv8564/rv8564.h | 104 ++++++ tos/platforms/mulle/debug/m_printf.h | 276 ++++++++++++++++ tos/platforms/mulle/hardware.h | 51 +++ tos/platforms/mulle/platform.h | 55 ++++ tos/platforms/mulle/platform_message.h | 60 ++++ tos/platforms/mulle/softwarei2c/MulleI2C.h | 45 +++ .../softwarei2c/SoftI2CBatteryMonitorRTCC.nc | 63 ++++ .../softwarei2c/SoftI2CBatteryMonitorRTCP.nc | 68 ++++ tos/platforms/mulle/softwarei2c/SoftI2CBus.nc | 95 ++++++ .../mulle/softwarei2c/SoftI2CBusP.nc | 263 ++++++++++++++++ .../mulle/softwarei2c/SoftI2CMasterImplP.nc | 174 ++++++++++ .../mulle/softwarei2c/SoftI2CMasterP.nc | 103 ++++++ .../mulle/softwarei2c/SoftI2CMasterPacketP.nc | 266 ++++++++++++++++ tos/platforms/mulle/softwarespi/SoftSpiBus.nc | 75 +++++ .../mulle/softwarespi/SoftSpiBusP.nc | 129 ++++++++ .../mulle/softwarespi/SoftSpiMasterImplP.nc | 170 ++++++++++ .../mulle/softwarespi/SoftSpiMasterP.nc | 104 ++++++ .../mulle/softwarespi/SoftSpiMasterPacketP.nc | 189 +++++++++++ tos/platforms/mulle/system/LedsP.nc | 152 +++++++++ tos/platforms/mulle/timers/AlarmMicro16C.nc | 72 +++++ tos/platforms/mulle/timers/AlarmMicro32C.nc | 55 ++++ tos/platforms/mulle/timers/BusyWaitMicroC.nc | 54 ++++ tos/platforms/mulle/timers/CounterMicro16C.nc | 76 +++++ tos/platforms/mulle/timers/CounterMicro32C.nc | 56 ++++ tos/platforms/mulle/timers/HilTimerMilliC.nc | 90 ++++++ tos/platforms/mulle/timers/LocalTimeMicroC.nc | 46 +++ tos/platforms/mulle/timers/TimerConfig.h | 114 +++++++ .../mulle/timers/rf230/AlarmRF23016C.nc | 70 +++++ .../mulle/timers/rf230/CounterRF23016C.nc | 64 ++++ .../timers/stop/RV8564AlarmCounterMilli32C.nc | 104 ++++++ .../timers/stop/RV8564AlarmCounterMilli32P.nc | 55 ++++ .../mulle/timers/wait/AlarmCounterMilli32C.nc | 93 ++++++ 123 files changed, 11732 insertions(+) create mode 100755 support/make/m16c62p/crt.S create mode 100755 support/make/m16c62p/debug.extra create mode 100755 support/make/m16c62p/debugopt.extra create mode 100755 support/make/m16c62p/install.extra create mode 100755 support/make/m16c62p/m16c.x create mode 100755 support/make/m16c62p/m16c62p.rules create mode 100644 support/make/m16c62p/reinstall.extra create mode 100755 support/make/m16c62p/sm16cf.extra create mode 100644 tos/chips/m16c62p/control/M16c62pControl.h create mode 100755 tos/chips/m16c62p/control/M16c62pControl.nc create mode 100755 tos/chips/m16c62p/control/M16c62pControlC.nc create mode 100755 tos/chips/m16c62p/control/M16c62pControlP.nc create mode 100644 tos/chips/m16c62p/control/M16c62pControlPlatform.nc create mode 100644 tos/chips/m16c62p/control/StopModeControl.nc create mode 100644 tos/chips/m16c62p/control/StopModeControlC.nc create mode 100644 tos/chips/m16c62p/control/SystemClockControl.nc create mode 100644 tos/chips/m16c62p/control/SystemClockControlC.nc create mode 100755 tos/chips/m16c62p/pins/HplM16c62pGeneralIOC.nc create mode 100755 tos/chips/m16c62p/pins/HplM16c62pGeneralIOPinP.nc create mode 100755 tos/chips/m16c62p/pins/HplM16c62pGeneralIOPortP.nc create mode 100755 tos/chips/m16c62p/pins/HplM16c62pInterrupt.nc create mode 100755 tos/chips/m16c62p/pins/HplM16c62pInterruptC.nc create mode 100755 tos/chips/m16c62p/pins/HplM16c62pInterruptPinP.nc create mode 100755 tos/chips/m16c62p/pins/HplM16c62pInterruptSig.nc create mode 100755 tos/chips/m16c62p/pins/HplM16c62pInterruptSigP.nc create mode 100755 tos/chips/m16c62p/pins/M16c62pInterruptC.nc create mode 100755 tos/chips/m16c62p/timer/HplM16c62pTimer.nc create mode 100755 tos/chips/m16c62p/timer/HplM16c62pTimerACtrl.nc create mode 100755 tos/chips/m16c62p/timer/HplM16c62pTimerACtrlP.nc create mode 100755 tos/chips/m16c62p/timer/HplM16c62pTimerBCtrl.nc create mode 100755 tos/chips/m16c62p/timer/HplM16c62pTimerBCtrlP.nc create mode 100755 tos/chips/m16c62p/timer/HplM16c62pTimerC.nc create mode 100755 tos/chips/m16c62p/timer/HplM16c62pTimerInterrupt.nc create mode 100755 tos/chips/m16c62p/timer/HplM16c62pTimerInterruptP.nc create mode 100755 tos/chips/m16c62p/timer/HplM16c62pTimerP.nc create mode 100755 tos/chips/m16c62p/timer/M16c62pAlarm16C.nc create mode 100755 tos/chips/m16c62p/timer/M16c62pAlarm32C.nc create mode 100755 tos/chips/m16c62p/timer/M16c62pCounter16C.nc create mode 100755 tos/chips/m16c62p/timer/M16c62pCounter32C.nc create mode 100755 tos/chips/m16c62p/timer/M16c62pTimer.h create mode 100755 tos/chips/m16c62p/timer/M16c62pTimerAInitC.nc create mode 100755 tos/chips/m16c62p/timer/M16c62pTimerBInitC.nc create mode 100755 tos/chips/m16c62p/uart/HplM16c62pUart.nc create mode 100755 tos/chips/m16c62p/uart/HplM16c62pUartC.nc create mode 100755 tos/chips/m16c62p/uart/HplM16c62pUartInterrupt.nc create mode 100755 tos/chips/m16c62p/uart/HplM16c62pUartInterruptP.nc create mode 100755 tos/chips/m16c62p/uart/HplM16c62pUartP.nc create mode 100755 tos/chips/m16c62p/uart/M16c62pUartC.nc create mode 100755 tos/chips/m16c62p/uart/M16c62pUartP.nc create mode 100644 tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlash.nc create mode 100644 tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlashC.nc create mode 100644 tos/lib/net/Deluge/extra/m16c62p/InternalFlashC.nc create mode 100644 tos/lib/net/Deluge/extra/m16c62p/InternalFlashP.nc create mode 100644 tos/lib/net/Deluge/extra/m16c62p/M16c62pFlash.h create mode 100644 tos/lib/net/Deluge/extra/mulle/NetProg_platform.h create mode 100644 tos/lib/net/Deluge/extra/mulle/ReprogramGuardC.nc create mode 100644 tos/lib/net/Deluge/extra/mulle/ReprogramGuardP.nc create mode 100644 tos/lib/net/Deluge/extra/mulle/TOSBoot_platform.h create mode 100644 tos/lib/tosboot/m16c62p/HardwareC.nc create mode 100644 tos/lib/tosboot/m16c62p/ProgFlashM.nc create mode 100644 tos/lib/tosboot/m16c62p/ProgFlashP.nc create mode 100644 tos/lib/tosboot/mulle/ExecC.nc create mode 100644 tos/lib/tosboot/mulle/PluginC.nc create mode 100644 tos/lib/tosboot/mulle/VoltageC.nc create mode 100644 tos/lib/tosboot/mulle/hardware.h create mode 100644 tos/lib/tosboot/mulle/m16chardware.h create mode 100755 tos/platforms/mulle/.platform create mode 100755 tos/platforms/mulle/ActiveMessageC.nc create mode 100755 tos/platforms/mulle/DemoSensorC.nc create mode 100755 tos/platforms/mulle/PlatformC.nc create mode 100755 tos/platforms/mulle/PlatformLedsC.nc create mode 100755 tos/platforms/mulle/PlatformP.nc create mode 100755 tos/platforms/mulle/PlatformSerialC.nc create mode 100755 tos/platforms/mulle/TimeSyncMessageC.nc create mode 100644 tos/platforms/mulle/chips/at45db/At45dbSpi.h create mode 100644 tos/platforms/mulle/chips/at45db/HplAt45dbC.nc create mode 100644 tos/platforms/mulle/chips/at45db/HplAt45dbP.nc create mode 100644 tos/platforms/mulle/chips/at45db/HplAt45db_chip.h create mode 100755 tos/platforms/mulle/chips/at45db/SoftSpiAt45dbC.nc create mode 100755 tos/platforms/mulle/chips/at45db/SoftSpiAt45dbP.nc create mode 100644 tos/platforms/mulle/chips/m16c62p/M16c62pControlPlatformC.nc create mode 100755 tos/platforms/mulle/chips/rf230/HplRF230C.nc create mode 100755 tos/platforms/mulle/chips/rf230/HplRF230P.nc create mode 100755 tos/platforms/mulle/chips/rf230/Mulle_RF230Spi.h create mode 100644 tos/platforms/mulle/chips/rf230/RF230SplitControlP.nc create mode 100644 tos/platforms/mulle/chips/rf230/RadioConfig.h create mode 100755 tos/platforms/mulle/chips/rf230/SoftSpiRF230C.nc create mode 100755 tos/platforms/mulle/chips/rf230/SoftSpiRF230P.nc create mode 100755 tos/platforms/mulle/chips/rv8564/RV8564.nc create mode 100755 tos/platforms/mulle/chips/rv8564/RV8564C.nc create mode 100755 tos/platforms/mulle/chips/rv8564/RV8564P.nc create mode 100755 tos/platforms/mulle/chips/rv8564/rv8564.h create mode 100644 tos/platforms/mulle/debug/m_printf.h create mode 100755 tos/platforms/mulle/hardware.h create mode 100755 tos/platforms/mulle/platform.h create mode 100755 tos/platforms/mulle/platform_message.h create mode 100755 tos/platforms/mulle/softwarei2c/MulleI2C.h create mode 100755 tos/platforms/mulle/softwarei2c/SoftI2CBatteryMonitorRTCC.nc create mode 100644 tos/platforms/mulle/softwarei2c/SoftI2CBatteryMonitorRTCP.nc create mode 100755 tos/platforms/mulle/softwarei2c/SoftI2CBus.nc create mode 100755 tos/platforms/mulle/softwarei2c/SoftI2CBusP.nc create mode 100755 tos/platforms/mulle/softwarei2c/SoftI2CMasterImplP.nc create mode 100755 tos/platforms/mulle/softwarei2c/SoftI2CMasterP.nc create mode 100755 tos/platforms/mulle/softwarei2c/SoftI2CMasterPacketP.nc create mode 100755 tos/platforms/mulle/softwarespi/SoftSpiBus.nc create mode 100755 tos/platforms/mulle/softwarespi/SoftSpiBusP.nc create mode 100755 tos/platforms/mulle/softwarespi/SoftSpiMasterImplP.nc create mode 100755 tos/platforms/mulle/softwarespi/SoftSpiMasterP.nc create mode 100755 tos/platforms/mulle/softwarespi/SoftSpiMasterPacketP.nc create mode 100755 tos/platforms/mulle/system/LedsP.nc create mode 100755 tos/platforms/mulle/timers/AlarmMicro16C.nc create mode 100755 tos/platforms/mulle/timers/AlarmMicro32C.nc create mode 100755 tos/platforms/mulle/timers/BusyWaitMicroC.nc create mode 100755 tos/platforms/mulle/timers/CounterMicro16C.nc create mode 100755 tos/platforms/mulle/timers/CounterMicro32C.nc create mode 100755 tos/platforms/mulle/timers/HilTimerMilliC.nc create mode 100755 tos/platforms/mulle/timers/LocalTimeMicroC.nc create mode 100755 tos/platforms/mulle/timers/TimerConfig.h create mode 100644 tos/platforms/mulle/timers/rf230/AlarmRF23016C.nc create mode 100644 tos/platforms/mulle/timers/rf230/CounterRF23016C.nc create mode 100755 tos/platforms/mulle/timers/stop/RV8564AlarmCounterMilli32C.nc create mode 100755 tos/platforms/mulle/timers/stop/RV8564AlarmCounterMilli32P.nc create mode 100755 tos/platforms/mulle/timers/wait/AlarmCounterMilli32C.nc diff --git a/support/make/m16c62p/crt.S b/support/make/m16c62p/crt.S new file mode 100755 index 00000000..14ea1722 --- /dev/null +++ b/support/make/m16c62p/crt.S @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 Henrik Makitaavola + * @author Per Lindgren + * @author Johan Eriksson + * @author Johan Nordlander + * @author Simon Aittamaa + */ + +.set PM0, 0x04 +.set PRCR, 0x0a + +.text + .global __vector_default + + .extern _main + +.section .init0,"ax",@progbits + .global _start + +_start: + /* Setup processor mode, single chip mode, and stack pointers */ + ldc #_istack, isp + mov.b #0x02, PRCR + mov.b #0x00, PM0 + mov.b #0x00, PRCR + + /* Setup the FLG register to some sane defaults. */ + ldc #0, flg + fset u + ldc #_ustack, sp + + /* Setup interrupt vector. */ + ldc #%hi16(_vectors_variable), intbh + ldc #%lo16(_vectors_variable), intbl + + /* Copy .data. */ + mov.b #%hi8(__data_start), r1h + mov.w #%lo16(__data_start), a0 + mov.w #__ram_start, a1 + mov.w #__data_size, r3 + smovf.b + + /* Zero out .bss. */ + mov.b #0x00, R0L + mov.w #__bss_size, r3 + mov.w #__bss_start, a1 + sstr.b + + /* Enter main(). */ + jsr.a _main + + /* In case we return, should realy generate a reset :/ */ + jmp.b 0 + +/* We should probably not get here. */ +__vector_default: + jmp.a __vector_default + +/* Fixed hardware vector table. */ +.section .vectors_fixed, "a",@progbits + +.size _vectors_fixed, 36 +.type _vectors_fixed, @object + +_vectors_fixed: + +.long 0 /* Undefined Instruction. */ +.long 0 /* Overflow INTO Instruction. */ +.long 0 /* BRK Instruction.*/ +.long 0 /* Address Match Interupt. */ +.long 0 /* Single Step Interrupt. */ +.long 0 /* Watchdog, Oscillation, Voltage Interrupt. */ +.long 0 /* DBC. */ +.long 0 /* NMI. */ +.long _start /* Reset. */ + + +/* Boot args for tosboot. */ +.section .boot_args, "a",@progbits + +.size _boot_args, 8 +.type _boot_args, @object + +_boot_args: + +.long 0xFFFFFFFF +.long 0xFFFFFFFF + +/* Variable vector table. */ +.section .vectors_variable + +.size _vectors_variable, 256 +.type _vectors_variable, @object + +_vectors_variable: + +.long __vector_0 +.long __vector_1 +.long __vector_2 +.long __vector_3 +.long __vector_4 +.long __vector_5 +.long __vector_6 +.long __vector_7 +.long __vector_8 +.long __vector_9 +.long __vector_10 +.long __vector_11 +.long __vector_12 +.long __vector_13 +.long __vector_14 +.long __vector_15 +.long __vector_16 +.long __vector_17 +.long __vector_18 +.long __vector_19 +.long __vector_20 +.long __vector_21 +.long __vector_22 +.long __vector_23 +.long __vector_24 +.long __vector_25 +.long __vector_26 +.long __vector_27 +.long __vector_28 +.long __vector_29 +.long __vector_30 +.long __vector_31 +.long __vector_32 +.long __vector_33 +.long __vector_34 +.long __vector_35 +.long __vector_36 +.long __vector_37 +.long __vector_38 +.long __vector_39 +.long __vector_40 +.long __vector_41 +.long __vector_42 +.long __vector_43 +.long __vector_44 +.long __vector_45 +.long __vector_46 +.long __vector_47 +.long __vector_48 +.long __vector_49 +.long __vector_50 +.long __vector_51 +.long __vector_52 +.long __vector_53 +.long __vector_54 +.long __vector_55 +.long __vector_56 +.long __vector_57 +.long __vector_58 +.long __vector_59 +.long __vector_60 +.long __vector_61 +.long __vector_62 +.long __vector_63 diff --git a/support/make/m16c62p/debug.extra b/support/make/m16c62p/debug.extra new file mode 100755 index 00000000..b02de828 --- /dev/null +++ b/support/make/m16c62p/debug.extra @@ -0,0 +1,4 @@ +#-*-Makefile-*- vim:syntax=make + +OPTFLAGS = -O1 -g -fnesc-no-inline + diff --git a/support/make/m16c62p/debugopt.extra b/support/make/m16c62p/debugopt.extra new file mode 100755 index 00000000..d150e3fb --- /dev/null +++ b/support/make/m16c62p/debugopt.extra @@ -0,0 +1,4 @@ +#-*-Makefile-*- vim:syntax=make + +OPTFLAGS += -g + diff --git a/support/make/m16c62p/install.extra b/support/make/m16c62p/install.extra new file mode 100755 index 00000000..db314bed --- /dev/null +++ b/support/make/m16c62p/install.extra @@ -0,0 +1,10 @@ +#-#-Makefile-#- vim:syntax=make + +NODEID = $(INSTALL) +BUILD_DEPS = srec tosimage bytes $(POST_BUILD_EXTRA_DEPS) setid program delsetid + +ifdef BOOTLOADER + ifeq ($(BOOTLOADER),tosboot) + BUILD_DEPS += program_bl + endif +endif diff --git a/support/make/m16c62p/m16c.x b/support/make/m16c62p/m16c.x new file mode 100755 index 00000000..a53e1a2d --- /dev/null +++ b/support/make/m16c62p/m16c.x @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 Henrik Makitaavola + * @author Per Lindgren + * @author Johan Eriksson + * @author Johan Nordlander + * @author Simon Aittamaa + */ + +ENTRY(_start) + +MEMORY { + ram (rw) : o = 0x0000400, l = 31k + flash (rx) : o = 0x00a0000, l = 384k +} + +/* Provide any vector symbols not defined. */ +PROVIDE(__vector_0 = __vector_default); +PROVIDE(__vector_1 = __vector_default); +PROVIDE(__vector_2 = __vector_default); +PROVIDE(__vector_3 = __vector_default); +PROVIDE(__vector_4 = __vector_default); +PROVIDE(__vector_5 = __vector_default); +PROVIDE(__vector_6 = __vector_default); +PROVIDE(__vector_7 = __vector_default); +PROVIDE(__vector_8 = __vector_default); +PROVIDE(__vector_9 = __vector_default); +PROVIDE(__vector_10 = __vector_default); +PROVIDE(__vector_11 = __vector_default); +PROVIDE(__vector_12 = __vector_default); +PROVIDE(__vector_13 = __vector_default); +PROVIDE(__vector_14 = __vector_default); +PROVIDE(__vector_15 = __vector_default); +PROVIDE(__vector_16 = __vector_default); +PROVIDE(__vector_17 = __vector_default); +PROVIDE(__vector_18 = __vector_default); +PROVIDE(__vector_19 = __vector_default); +PROVIDE(__vector_20 = __vector_default); +PROVIDE(__vector_21 = __vector_default); +PROVIDE(__vector_22 = __vector_default); +PROVIDE(__vector_23 = __vector_default); +PROVIDE(__vector_24 = __vector_default); +PROVIDE(__vector_25 = __vector_default); +PROVIDE(__vector_26 = __vector_default); +PROVIDE(__vector_27 = __vector_default); +PROVIDE(__vector_28 = __vector_default); +PROVIDE(__vector_29 = __vector_default); +PROVIDE(__vector_30 = __vector_default); +PROVIDE(__vector_31 = __vector_default); +PROVIDE(__vector_32 = __vector_default); +PROVIDE(__vector_33 = __vector_default); +PROVIDE(__vector_34 = __vector_default); +PROVIDE(__vector_35 = __vector_default); +PROVIDE(__vector_36 = __vector_default); +PROVIDE(__vector_37 = __vector_default); +PROVIDE(__vector_38 = __vector_default); +PROVIDE(__vector_39 = __vector_default); +PROVIDE(__vector_40 = __vector_default); +PROVIDE(__vector_41 = __vector_default); +PROVIDE(__vector_42 = __vector_default); +PROVIDE(__vector_43 = __vector_default); +PROVIDE(__vector_44 = __vector_default); +PROVIDE(__vector_45 = __vector_default); +PROVIDE(__vector_46 = __vector_default); +PROVIDE(__vector_47 = __vector_default); +PROVIDE(__vector_48 = __vector_default); +PROVIDE(__vector_49 = __vector_default); +PROVIDE(__vector_50 = __vector_default); +PROVIDE(__vector_51 = __vector_default); +PROVIDE(__vector_52 = __vector_default); +PROVIDE(__vector_53 = __vector_default); +PROVIDE(__vector_54 = __vector_default); +PROVIDE(__vector_55 = __vector_default); +PROVIDE(__vector_56 = __vector_default); +PROVIDE(__vector_57 = __vector_default); +PROVIDE(__vector_58 = __vector_default); +PROVIDE(__vector_59 = __vector_default); +PROVIDE(__vector_60 = __vector_default); +PROVIDE(__vector_61 = __vector_default); +PROVIDE(__vector_62 = __vector_default); +PROVIDE(__vector_63 = __vector_default); + +SECTIONS { + /* + * Ram starts at 0x400 but for some reason it does not allow med to + * start placing data at 0x400 since it's not into the ram... Life + * is great. + */ + __ram_start = 0x500; + __ram_end = 0x400 + 31k - 1; + + .start : { + *(.init0); + } > flash + + .data __ram_start : { + *(.data); + *(.rodata); /* Do NOT place in '.text'. */ + *(.rodata.*); /* Do NOT place in '.text'. */ + *(.plt); /* Do NOT place in '.text'. */ + } > ram AT > flash + + __data_start = LOADADDR(.data); + __data_size = SIZEOF(.data); + + .bss : { + *(.bss); + *(COMMON); + } > ram + + __bss_start = ADDR(.bss); + __bss_size = SIZEOF(.bss); + + .text /*0xc0000*/: { + *(.text); + *(.vectors_variable); + } > flash + + .bootargs /*boot_args_address*/ : { + *(.boot_args); + } > flash + + PROVIDE(_end = __bss_start + __bss_size); + + /* User Stack Pointer */ + .ustack 0x00007000 : + { + _ustack = .; + } > ram + + /* Interrupt Stack Pointer */ + .istack 0x00008000 : + { + _istack = .; + } > ram + + /* Vector offset is fixed. */ + .vectors 0x000FFFDC : { + *(.vectors_fixed); + } > flash +} diff --git a/support/make/m16c62p/m16c62p.rules b/support/make/m16c62p/m16c62p.rules new file mode 100755 index 00000000..2249214e --- /dev/null +++ b/support/make/m16c62p/m16c62p.rules @@ -0,0 +1,126 @@ +#-#-Makefile-#- vim:syntax=make + +define M16C62P_HELP + + M16C/62P extras: + + debug : compile with minimal optimization and debug symbols + debugopt : compile with debug symbols + + Programmer options: + + sm16cf : use SM16CF programmer on port '/dev/ttyUSB0'. + sm16cf, : use SM16CF programmer on port . + +endef +HELP += $(M16C62P_HELP) +THIS_FOLDER = m16c62p + +#ifdef MAKE_DEPUTY_FLAG +# NCC_SAFE_TINYOS_FLAGS = -DSAFE_TINYOS -fnesc-deputy -fnesc-deputy-args='-I$(TOSDIR)/lib/safe/include --FLIDs=build/$(PLATFORM)/flids.txt --envmachine -DSAFE_TINYOS --nolib ' $(TOSDIR)/lib/safe/avr/fail.c +#else +# NCC_SAFE_TINYOS_FLAGS = +#endif + +OBJCOPY = m32c-elf-objcopy +OBJDUMP = m32c-elf-objdump +SET_ID = tos-set-symbols +NCC = ncc +LIBS = -lm -lc -lgcc + +AMADDR = _ActiveMessageAddressC\$$addr +# Uncomment the next two lines if you have a toolchain without the dollar sign +# patch. This needs nesc 1.2.8 or newer (1.2.9 is recommended). +#PFLAGS += -fnesc-separator=__ +#AMADDR = ActiveMessageAddressC__addr +BUILDDIR ?= build/$(PLATFORM) +MAIN_EXE = $(BUILDDIR)/main.exe +MAIN_SREC = $(BUILDDIR)/main.srec +MAIN_IHEX = $(BUILDDIR)/main.ihex +INSTALL_SREC = $(MAIN_SREC).out$(if $(NODEID),-$(NODEID),) + +PFLAGS += -Wshadow $(NESC_FLAGS) +PFLAGS += -target=$(PLATFORM) -fnesc-cfile=$(BUILDDIR)/app.c -board=$(SENSORBOARD) +ifdef MSG_SIZE +PFLAGS += -DTOSH_DATA_LENGTH=$(MSG_SIZE) +endif +ifdef DEFAULT_LOCAL_GROUP +PFLAGS += -DDEFINED_TOS_AM_GROUP=$(DEFAULT_LOCAL_GROUP) +endif + +# We need a different start address for the flash in the linker script when building TOSBoot. +# Also program the boot_args address bytes with 0xFF so that we know if they are reprogrammable. +ifeq ($(COMPONENT),TOSBoot) +$(shell sed -e "s/0x00a0000/0x00e0000/ig" $(TINYOS_MAKE_PATH)/$(THIS_FOLDER)/m16c.x > $(TINYOS_MAKE_PATH)/$(THIS_FOLDER)/m16c_bootloader.x) +$(shell sed -e "s/\/\*boot_args_address\*\//0x00f0000/ig" $(TINYOS_MAKE_PATH)/$(THIS_FOLDER)/m16c_bootloader.x > $(TINYOS_MAKE_PATH)/$(THIS_FOLDER)/m16c_bootloader_args.x) +LDFLAGS += -nostartfiles -T$(TINYOS_MAKE_PATH)/$(THIS_FOLDER)/m16c_bootloader_args.x $(TINYOS_MAKE_PATH)/$(THIS_FOLDER)/crt.S +else +LDFLAGS += -nostartfiles -T$(TINYOS_MAKE_PATH)/$(THIS_FOLDER)/m16c.x $(TINYOS_MAKE_PATH)/$(THIS_FOLDER)/crt.S +endif + +DEFAULT_PROGRAM ?= sm16cf + +# Use the 'if' function instead of the 'ifdef' construct because ifdef freaks +# out with call in there. I don't know why. +$(if $(PROGRAM),,$(call TOSMake_include,$(THIS_FOLDER)/$(DEFAULT_PROGRAM).extra)) + +# Build storage file if volumes.xml present +ifneq ($(wildcard $(VOLUMEFILE)), ) +build_storage: $(BUILDDIR)/StorageVolumes.h + +exe0: build_storage + +VOLUME_ALLOCATOR_FLAGS ?= +$(BUILDDIR)/StorageVolumes.h: $(VOLUMEFILE) + $(VOLUME_ALLOCATOR) $(VOLUME_ALLOCATOR_FLAGS) $(PLATFORMDIR) <$(VOLUMEFILE) >$@ || rm -f $@ + +PFLAGS += -I$(BUILDDIR) +else + +build_storage: + +endif + +ifndef BUILD_DEPS + ifeq ($(filter $(BUILDLESS_DEPS),$(GOALS)),) + BUILD_DEPS = srec bytes tosimage $(POST_BUILD_EXTRA_DEPS) + endif +endif + +setid: FORCE + @cmd () { echo "$$@"; $$@; }; if [ x = x$(NODEID) ]; then cmd cp $(MAIN_SREC) $(INSTALL_SREC); else cmd $(SET_ID) $(MAIN_SREC) $(INSTALL_SREC) _TOS_NODE_ID=$(NODEID) $(AMADDR)=$(NODEID) ; fi + +delsetid: FORCE + rm -f $(subst .srec.,.exe.,$(INSTALL_SREC)) $(INSTALL_SREC) + +srec: exe FORCE + $(OBJCOPY) --output-target=srec $(MAIN_EXE) $(MAIN_SREC) + +tos_buildinfo: ihex build_buildinfo FORCE + @: + + # TODO(henrik) Remove interrupt vector table from the image. +tosimage: ihex build_tosimage FORCE + @: + +ihex: exe FORCE + $(OBJCOPY) --output-target=ihex $(MAIN_EXE) $(MAIN_IHEX) + +exe: exe0 FORCE bytes + @: + + +exe0: builddir $(BUILD_EXTRA_DEPS) FORCE + @echo " compiling $(COMPONENT) to a $(PLATFORM) binary" + $(NCC) -o $(MAIN_EXE) $(NCC_SAFE_TINYOS_FLAGS) $(OPTFLAGS) $(PFLAGS) $(CFLAGS) $(WIRING_CHECK_FLAGS) $(COMPONENT).nc $(LIBS) $(LDFLAGS) +ifdef WIRING_CHECK_FILE + @nescc-wiring $(WIRING_CHECK_FILE) +endif + @echo " compiled $(COMPONENT) to $(MAIN_EXE)" + +builddir: FORCE + mkdir -p $(BUILDDIR) +# bug fix 2009-3-11 by ZHF, here display the ROM and RAM consumption information. +bytes: FORCE + @$(OBJDUMP) -h $(MAIN_EXE) | perl -ne '$$b{$$1}=hex $$2 if /^\s*\d+\s*\.(text|data|bss)\s+(\S+)/; END { printf("%16d bytes in ROM\n%16d bytes in RAM\n",$$b{text}+$$b{data},$$b{data}+$$b{bss}); }' + diff --git a/support/make/m16c62p/reinstall.extra b/support/make/m16c62p/reinstall.extra new file mode 100644 index 00000000..1d78c132 --- /dev/null +++ b/support/make/m16c62p/reinstall.extra @@ -0,0 +1,6 @@ +#-*-Makefile-*- vim:syntax=make + +NODEID = $(REINSTALL) +BUILD_DEPS = setid program + + diff --git a/support/make/m16c62p/sm16cf.extra b/support/make/m16c62p/sm16cf.extra new file mode 100755 index 00000000..f83aa5f7 --- /dev/null +++ b/support/make/m16c62p/sm16cf.extra @@ -0,0 +1,27 @@ +### + # @author Henrik Makitaavola + ## + +ifeq ($(SM16CF), ) +#$(error SM16CF must be defined, try "make $(TARGETS) help") +SM16CF = /dev/ttyUSB0 +endif + +PROGRAM = sm16cf +PROGRAMMER = sm16cf + +ifdef BOOTLOADER + program: FORCE + @echo " installing $(PLATFORM) with bootloader using sm16cf" + srec_cat $(BOOTLOADER_IMG) $(INSTALL_SREC) -exclude 0x000FFFDC 0x00100000 -o $(BUILDDIR)/main_boot.srec -CRLF + sed '/S5/d' $(BUILDDIR)/main_boot.srec > $(BUILDDIR)/main_boot2.srec + $(PROGRAMMER) --device=$(SM16CF) --input-file=$(BUILDDIR)/main_boot2.srec --flash-program + rm $(BUILDDIR)/main_boot.srec + rm $(BUILDDIR)/main_boot2.srec +else +program: FORCE + @echo " installing $(PLATFORM) using sm16cf" + $(PROGRAMMER) --device=$(SM16CF) --input-file=$(INSTALL_SREC) --flash-program +endif + +program_bl: FORCE diff --git a/tos/chips/m16c62p/control/M16c62pControl.h b/tos/chips/m16c62p/control/M16c62pControl.h new file mode 100644 index 00000000..40bd38c2 --- /dev/null +++ b/tos/chips/m16c62p/control/M16c62pControl.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 includes defines to be used together with the control interfaces + * for the M16c/62p mcu. + * + * @author Henrik Makitaavola + */ + +#ifndef __M16C62P_CONTROL_H__ +#define __M16C62P_CONTROL_H__ + +#define UQ_M16C62P_STOP_MODE_CONTROL "UQ_M16C62P_STOP_MODE_CONTROL" +#define UQ_M16C62P_SYSTEM_CLOCK_CONTROL "UQ_M16C62P_SYSTEM_CLOCK_CONTROL" + + +/** + * Input to SystemClockControl.minSpeed() and + * M16c62pControl.defaultSystemClock(). + */ +typedef enum +{ + M16C62P_DONT_CARE = 0x0, + M16C62P_SUB_CLOCK = 0x1, + M16C62P_MAIN_CLOCK_DIV_0 = 0x2, + M16C62P_MAIN_CLOCK_DIV_2 = 0x4, + M16C62P_MAIN_CLOCK_DIV_4 = 0x8, + M16C62P_MAIN_CLOCK_DIV_8 = 0x9, + M16C62P_MAIN_CLOCK_DIV_16 = 0xc, + M16C62P_PLL_CLOCK = 0xd, +} M16c62pSystemClock; + +/** + * The different PLL multipliers supported by the M16c/62p mcu. + */ +typedef enum +{ + M16C62P_PLL_2 = 0x1, + M16C62P_PLL_4 = 0x2, + M16C62P_PLL_6 = 0x3, + M16C62P_PLL_8 = 0x4 +} M16c62pPLLMultiplier; + +#endif // __M16C62P_CONTROL_H__ + diff --git a/tos/chips/m16c62p/control/M16c62pControl.nc b/tos/chips/m16c62p/control/M16c62pControl.nc new file mode 100755 index 00000000..ba9b398c --- /dev/null +++ b/tos/chips/m16c62p/control/M16c62pControl.nc @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 to initialize, put the M16c/62p to sleep and default system speed. + * + * @author Henrik Makitaavola + */ + +#include "M16c62pControl.h" + +interface M16c62pControl +{ + /** + * Initializes the mcu. + */ + command error_t init(); + + /** + * Sets the default system clock speed. + * + * @param def Default system speed ( != M16C62P_DONT_CARE) + */ + async command error_t defaultSystemClock(M16c62pSystemClock def); + + /** + * Put the mcu to sleep. + */ + async command void sleep(); +} diff --git a/tos/chips/m16c62p/control/M16c62pControlC.nc b/tos/chips/m16c62p/control/M16c62pControlC.nc new file mode 100755 index 00000000..5e7b9900 --- /dev/null +++ b/tos/chips/m16c62p/control/M16c62pControlC.nc @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Wiring for the M16c62pControlP module. + * + * @author Henrik Makitaavola + */ +configuration M16c62pControlC +{ + provides interface M16c62pControl; +} +implementation +{ + components M16c62pControlP, + M16c62pControlPlatformC; + + M16c62pControl = M16c62pControlP; + M16c62pControlP.PlatformCtrl -> M16c62pControlPlatformC; + +} diff --git a/tos/chips/m16c62p/control/M16c62pControlP.nc b/tos/chips/m16c62p/control/M16c62pControlP.nc new file mode 100755 index 00000000..1f1cceb1 --- /dev/null +++ b/tos/chips/m16c62p/control/M16c62pControlP.nc @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Implementation of the Control Interfaces for the M16c/62p mcu. + * + * @author Henrik Makitaavola + */ + + +#include "M16c62pControl.h" + +module M16c62pControlP +{ + provides interface M16c62pControl; + provides interface StopModeControl[uint8_t client]; + provides interface SystemClockControl[uint8_t client]; + + uses interface M16c62pControlPlatform as PlatformCtrl; +} +implementation +{ + M16c62pSystemClock default_system_clock = M16C62P_MAIN_CLOCK_DIV_0; // Default system clock speed + M16c62pSystemClock system_clock = M16C62P_DONT_CARE; + uint8_t client_system_clock[uniqueCount(UQ_M16C62P_SYSTEM_CLOCK_CONTROL)]; + uint8_t num_system_clock_clients = uniqueCount(UQ_M16C62P_SYSTEM_CLOCK_CONTROL); + + // Take +1 incase of rest in the division + uint8_t client_allow_stop_mode[(uniqueCount(UQ_M16C62P_STOP_MODE_CONTROL)/8) + 1]; + uint8_t num_allow_stop_mode_clients = uniqueCount(UQ_M16C62P_STOP_MODE_CONTROL); + bool update_sleep_mode = false; + bool allow_stop_mode = true; // Stop mode enabled/disabled, Default: Enabled. + + void PLLOn() + { + uint8_t tmp; + uint32_t i; + + CM0.BYTE = 0x08; // Main clock + Sub clock. + CM1.BYTE = 0x20; //Clear previous cpu speed setting. + PM2.BYTE = 0x00; // PLL > 16MHz (2 waits). + tmp = 0x90 + PLL_MULTIPLIER; + PLC0.BYTE = tmp; // PLL ON. + // Wait for PLL to become stable (50 ms). + // TODO (henrik) Make this more efficient when time allows it.For example + // use timers or busy waiting. + // Tried busy waiting but tosboot started to include alot of + // things that it shouldn't which lead to compile errors. + for (i = 0; i < 50000 * MAIN_CRYSTAL_SPEED; ++i) + asm("nop"); + CM1.BYTE = 0x22; // PLL as system clock. + call PlatformCtrl.PLLOn(); + } + + void PLLOff() + { + uint8_t tmp; + CLR_BIT(CM1.BYTE, 1); // Main clock + tmp = 0x10 + PLL_MULTIPLIER; + PLC0.BYTE = tmp; // Turn off PLL clock + call PlatformCtrl.PLLOff(); + } + + error_t setSystemClock(M16c62pSystemClock set_clock) + { + M16c62pSystemClock clock = set_clock; + atomic + { + if (clock == M16C62P_DONT_CARE) + { + clock = default_system_clock; + } + + PRCR.BYTE = BIT1 | BIT0; // Turn off protection for cpu & clock register. + + if (system_clock == M16C62P_PLL_CLOCK) + { + PLLOff(); + } + + // Set correct system clock speed. + if (clock == M16C62P_MAIN_CLOCK_DIV_8) + { + SET_BIT(CM0.BYTE, 6); + } + else if (clock >= M16C62P_MAIN_CLOCK_DIV_0 && + clock <= M16C62P_MAIN_CLOCK_DIV_16) + { // Main clock divided by 0, 2 ,4 or 16 + CLR_BIT(CM0.BYTE, 6); // Remove division by 8 + CLR_FLAG(CM1.BYTE, (0x3 << 6)); // Clear previous cpu speed setting + SET_FLAG(CM1.BYTE, ((clock >> 2) << 6)); // New cpu speed + } + else if (clock == M16C62P_SUB_CLOCK) + { + SET_BIT(CM0.BYTE, 4); // Sub clock on. + SET_BIT(CM0.BYTE, 7); // Sub clock as CPU clock + } + else if (clock == M16C62P_PLL_CLOCK) + { + PLLOn(); + } + // TODO(Henrik) Maybe need to wait for a while to make sure that the + // crystals are stable? + CLR_BIT(CM1.BYTE, 5); // Low drive on Xin-Xout. + CLR_BIT(CM0.BYTE, 3); // Low drive on XCin-XCout. + PRCR.BYTE = 0; // Turn on protection on all registers. + atomic system_clock = set_clock; + return SUCCESS; + } + } + + error_t updateSystemClock() + { + M16c62pSystemClock clock = M16C62P_DONT_CARE; + uint8_t i; + + atomic + { + for (i = 0; i < num_system_clock_clients; ++i) + { + if (clock < client_system_clock[i]) + { + clock = client_system_clock[i]; + } + } + + if (clock == system_clock) + { + return SUCCESS; + } + + return setSystemClock(clock); + } + } + + command error_t M16c62pControl.init() + { + uint8_t i; + uint8_t tmp; + PRCR.BYTE = BIT1 | BIT0; // Turn off protection for cpu & clock register. + + PM0.BYTE = BIT7; // Single Chip mode. No BCLK output. + PM1.BYTE = BIT3; // Expand internal memory, no global wait state. + PCLKR.BIT.PCLK0 = 1; // Set Timer A and B clock bit to F1 + PCLKR.BIT.PCLK1 = 1; // Set Timer A and B clock bit to F1 + + tmp = 0x10 + PLL_MULTIPLIER; // Prepare PLL multiplier + PLC0.BYTE = tmp; // Set PLL multiplier + + PRCR.BYTE = 0; + + // Initialize the clock and stop mode control arrays. + for (i = 0; i < num_system_clock_clients; ++i) + { + client_system_clock[i] = M16C62P_DONT_CARE; + } + for (i = 0; i < (num_allow_stop_mode_clients/8) + 1; ++i) + { + client_allow_stop_mode[i] = 0xFF; + } + return setSystemClock(M16C62P_DONT_CARE); + } + + async command error_t M16c62pControl.defaultSystemClock( + M16c62pSystemClock def) + { + if (def == M16C62P_DONT_CARE) + { + return FAIL; + } + if (def == default_system_clock || system_clock != M16C62P_DONT_CARE) + { + default_system_clock = def; + return SUCCESS; + } + default_system_clock = def; + return setSystemClock(M16C62P_DONT_CARE); + } + + void updateSleepMode() + { + uint8_t i; + for (i = 0; i < (num_allow_stop_mode_clients/8) + 1; ++i) + { + if (client_allow_stop_mode[i] != 0xFF) + { + allow_stop_mode = false; + return; + } + } + allow_stop_mode = true; + } + + void waitMode() + { + __nesc_enable_interrupt(); + asm ("wait"); + asm volatile ("" : : : "memory"); + __nesc_disable_interrupt(); + } + + void stopMode() + { + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + __nesc_enable_interrupt(); + PRCR.BYTE = 1; // Turn off protection of system clock control registers + CM1.BYTE &= ~16; // Xin low drive capacity + CM1.BYTE |= 1; // Enter stop mode + PRCR.BYTE = 0; + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + asm("nop"); + asm volatile ("" : : : "memory"); + __nesc_disable_interrupt(); + PRCR.BIT.PRC0 = 0; // Turn on protection of system clock control registers + atomic setSystemClock(system_clock); + } + + async command void M16c62pControl.sleep() + { + atomic if (update_sleep_mode) + { + updateSleepMode(); + } + if (allow_stop_mode && system_clock != M16C62P_PLL_CLOCK) + { + stopMode(); + } + else + { + waitMode(); + } + } + + async command void StopModeControl.allowStopMode[uint8_t client](bool allow) + { + atomic + { + WRITE_BIT(client_allow_stop_mode[client >> 3], client % 8, allow); + if (allow != allow_stop_mode) + { + update_sleep_mode = true; + } + } + } + + async command error_t SystemClockControl.minSpeed[uint8_t client]( + M16c62pSystemClock speed) + { + atomic client_system_clock[client] = speed; + atomic if (system_clock < speed) + { + return updateSystemClock(); + } + return SUCCESS; + } +} diff --git a/tos/chips/m16c62p/control/M16c62pControlPlatform.nc b/tos/chips/m16c62p/control/M16c62pControlPlatform.nc new file mode 100644 index 00000000..c48ed1f7 --- /dev/null +++ b/tos/chips/m16c62p/control/M16c62pControlPlatform.nc @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 to signal the platform that the mcu has changed the main clock + * speed, PLL is being turned on/off, etc. + * Needed so that the platform can take appropriate actions so + * that timers can be set to handle the PLL for example. + * + * @author Henrik Makitaavola + */ + +interface M16c62pControlPlatform +{ + /** + * PLL is turned on. + */ + async command void PLLOn(); + + /** + * PLL is turned off. + */ + async command void PLLOff(); +} diff --git a/tos/chips/m16c62p/control/StopModeControl.nc b/tos/chips/m16c62p/control/StopModeControl.nc new file mode 100644 index 00000000..01d6cd86 --- /dev/null +++ b/tos/chips/m16c62p/control/StopModeControl.nc @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 used by components to signal if it + * allows the mcu to go into stop mode. + * + * @author Henrik Makitaavola + */ + +interface StopModeControl +{ + /** + * Tells the mcu if it is allowed to go into stop mode. + * + * @param allow True if stop mode is allowed. + */ + async command void allowStopMode(bool allow); +} diff --git a/tos/chips/m16c62p/control/StopModeControlC.nc b/tos/chips/m16c62p/control/StopModeControlC.nc new file mode 100644 index 00000000..b18ca725 --- /dev/null +++ b/tos/chips/m16c62p/control/StopModeControlC.nc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +#include "M16c62pControl.h" +/** + * All components that need to control the mcus sleep + * mode should instantiate a component of this configuration. + * + * @author Henrik Makitaavola + */ + +generic configuration StopModeControlC() +{ + provides interface StopModeControl; +} +implementation +{ + enum + { + CLIENT_ID = unique(UQ_M16C62P_STOP_MODE_CONTROL), + }; + + components M16c62pControlP; + + StopModeControl = M16c62pControlP.StopModeControl[CLIENT_ID]; +} diff --git a/tos/chips/m16c62p/control/SystemClockControl.nc b/tos/chips/m16c62p/control/SystemClockControl.nc new file mode 100644 index 00000000..18dde2b5 --- /dev/null +++ b/tos/chips/m16c62p/control/SystemClockControl.nc @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 to control the allowed minimum speed of the mcu. + * + * @author Henrik Makitaavola + */ +interface SystemClockControl +{ + /** + * Control the minimum speed of the mcu. + * + * @param speed The allowed minimum speed. + */ + async command error_t minSpeed(M16c62pSystemClock speed); +} diff --git a/tos/chips/m16c62p/control/SystemClockControlC.nc b/tos/chips/m16c62p/control/SystemClockControlC.nc new file mode 100644 index 00000000..be97af48 --- /dev/null +++ b/tos/chips/m16c62p/control/SystemClockControlC.nc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +#include "M16c62pControl.h" + +/** + * Every component that needs to control the minimum speed + * of the mcu should instantiate a new component of this configuration. + * + * @author Henrik Makitaavola + */ +generic configuration SystemClockControlC() +{ + provides interface SystemClockControl; +} +implementation +{ + enum + { + CLIENT_ID = unique(UQ_M16C62P_SYSTEM_CLOCK_CONTROL), + }; + + components M16c62pControlP; + + SystemClockControl = M16c62pControlP.SystemClockControl[CLIENT_ID]; +} diff --git a/tos/chips/m16c62p/pins/HplM16c62pGeneralIOC.nc b/tos/chips/m16c62p/pins/HplM16c62pGeneralIOC.nc new file mode 100755 index 00000000..ec6a85e6 --- /dev/null +++ b/tos/chips/m16c62p/pins/HplM16c62pGeneralIOC.nc @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + * @author Martin Turon + */ + +/** + * The HplM16c62pGeneralIOC configuration provides GeneralIO interfaces for all + * the M16c/62p's pins. + * + * @author Henrik Makitaavola + */ + +#include "iom16c62p.h" + +configuration HplM16c62pGeneralIOC +{ + // provides all the ports as raw ports + provides + { + interface GeneralIO as PortP00; + interface GeneralIO as PortP01; + interface GeneralIO as PortP02; + interface GeneralIO as PortP03; + interface GeneralIO as PortP04; + interface GeneralIO as PortP05; + interface GeneralIO as PortP06; + interface GeneralIO as PortP07; + + interface GeneralIO as PortP10; + interface GeneralIO as PortP11; + interface GeneralIO as PortP12; + interface GeneralIO as PortP13; + interface GeneralIO as PortP14; + interface GeneralIO as PortP15; + interface GeneralIO as PortP16; + interface GeneralIO as PortP17; + + interface GeneralIO as PortP20; + interface GeneralIO as PortP21; + interface GeneralIO as PortP22; + interface GeneralIO as PortP23; + interface GeneralIO as PortP24; + interface GeneralIO as PortP25; + interface GeneralIO as PortP26; + interface GeneralIO as PortP27; + + interface GeneralIO as PortP30; + interface GeneralIO as PortP31; + interface GeneralIO as PortP32; + interface GeneralIO as PortP33; + interface GeneralIO as PortP34; + interface GeneralIO as PortP35; + interface GeneralIO as PortP36; + interface GeneralIO as PortP37; + + interface GeneralIO as PortP40; + interface GeneralIO as PortP41; + interface GeneralIO as PortP42; + interface GeneralIO as PortP43; + interface GeneralIO as PortP44; + interface GeneralIO as PortP45; + interface GeneralIO as PortP46; + interface GeneralIO as PortP47; + + interface GeneralIO as PortP50; + interface GeneralIO as PortP51; + interface GeneralIO as PortP52; + interface GeneralIO as PortP53; + interface GeneralIO as PortP54; + interface GeneralIO as PortP55; + interface GeneralIO as PortP56; + interface GeneralIO as PortP57; + + interface GeneralIO as PortP60; + interface GeneralIO as PortP61; + interface GeneralIO as PortP62; + interface GeneralIO as PortP63; + interface GeneralIO as PortP64; + interface GeneralIO as PortP65; + interface GeneralIO as PortP66; + interface GeneralIO as PortP67; + + interface GeneralIO as PortP70; + interface GeneralIO as PortP71; + interface GeneralIO as PortP72; + interface GeneralIO as PortP73; + interface GeneralIO as PortP74; + interface GeneralIO as PortP75; + interface GeneralIO as PortP76; + interface GeneralIO as PortP77; + + interface GeneralIO as PortP80; + interface GeneralIO as PortP81; + interface GeneralIO as PortP82; + interface GeneralIO as PortP83; + interface GeneralIO as PortP84; + // TODO(henrik) What should be done with PortP85? +// interface GeneralIO as PortP85; + interface GeneralIO as PortP86; + interface GeneralIO as PortP87; + + interface GeneralIO as PortP90; + interface GeneralIO as PortP91; + interface GeneralIO as PortP92; + interface GeneralIO as PortP93; + interface GeneralIO as PortP94; + interface GeneralIO as PortP95; + interface GeneralIO as PortP96; + interface GeneralIO as PortP97; + + interface GeneralIO as PortP100; + interface GeneralIO as PortP101; + interface GeneralIO as PortP102; + interface GeneralIO as PortP103; + interface GeneralIO as PortP104; + interface GeneralIO as PortP105; + interface GeneralIO as PortP106; + interface GeneralIO as PortP107; + + } +} +implementation +{ + components + new HplM16c62pGeneralIOPortP((uint16_t)&P0.BYTE, (uint16_t)&PD0.BYTE) as PortP0, + new HplM16c62pGeneralIOPortP((uint16_t)&P1.BYTE, (uint16_t)&PD1.BYTE) as PortP1, + new HplM16c62pGeneralIOPortP((uint16_t)&P2.BYTE, (uint16_t)&PD2.BYTE) as PortP2, + new HplM16c62pGeneralIOPortP((uint16_t)&P3.BYTE, (uint16_t)&PD3.BYTE) as PortP3, + new HplM16c62pGeneralIOPortP((uint16_t)&P4.BYTE, (uint16_t)&PD4.BYTE) as PortP4, + new HplM16c62pGeneralIOPortP((uint16_t)&P5.BYTE, (uint16_t)&PD5.BYTE) as PortP5, + new HplM16c62pGeneralIOPortP((uint16_t)&P6.BYTE, (uint16_t)&PD6.BYTE) as PortP6, + new HplM16c62pGeneralIOPortP((uint16_t)&P7.BYTE, (uint16_t)&PD7.BYTE) as PortP7, + new HplM16c62pGeneralIOPortP((uint16_t)&P8.BYTE, (uint16_t)&PD8.BYTE) as PortP8, + new HplM16c62pGeneralIOPortP((uint16_t)&P9.BYTE, (uint16_t)&PD9.BYTE) as PortP9, + new HplM16c62pGeneralIOPortP((uint16_t)&P10.BYTE, (uint16_t)&PD10.BYTE) as PortP_10; + + PortP00 = PortP0.Pin0; + PortP01 = PortP0.Pin1; + PortP02 = PortP0.Pin2; + PortP03 = PortP0.Pin3; + PortP04 = PortP0.Pin4; + PortP05 = PortP0.Pin5; + PortP06 = PortP0.Pin6; + PortP07 = PortP0.Pin7; + + PortP10 = PortP1.Pin0; + PortP11 = PortP1.Pin1; + PortP12 = PortP1.Pin2; + PortP13 = PortP1.Pin3; + PortP14 = PortP1.Pin4; + PortP15 = PortP1.Pin5; + PortP16 = PortP1.Pin6; + PortP17 = PortP1.Pin7; + + PortP20 = PortP2.Pin0; + PortP21 = PortP2.Pin1; + PortP22 = PortP2.Pin2; + PortP23 = PortP2.Pin3; + PortP24 = PortP2.Pin4; + PortP25 = PortP2.Pin5; + PortP26 = PortP2.Pin6; + PortP27 = PortP2.Pin7; + + PortP30 = PortP3.Pin0; + PortP31 = PortP3.Pin1; + PortP32 = PortP3.Pin2; + PortP33 = PortP3.Pin3; + PortP34 = PortP3.Pin4; + PortP35 = PortP3.Pin5; + PortP36 = PortP3.Pin6; + PortP37 = PortP3.Pin7; + + PortP40 = PortP4.Pin0; + PortP41 = PortP4.Pin1; + PortP42 = PortP4.Pin2; + PortP43 = PortP4.Pin3; + PortP44 = PortP4.Pin4; + PortP45 = PortP4.Pin5; + PortP46 = PortP4.Pin6; + PortP47 = PortP4.Pin7; + + PortP50 = PortP5.Pin0; + PortP51 = PortP5.Pin1; + PortP52 = PortP5.Pin2; + PortP53 = PortP5.Pin3; + PortP54 = PortP5.Pin4; + PortP55 = PortP5.Pin5; + PortP56 = PortP5.Pin6; + PortP57 = PortP5.Pin7; + + PortP60 = PortP6.Pin0; + PortP61 = PortP6.Pin1; + PortP62 = PortP6.Pin2; + PortP63 = PortP6.Pin3; + PortP64 = PortP6.Pin4; + PortP65 = PortP6.Pin5; + PortP66 = PortP6.Pin6; + PortP67 = PortP6.Pin7; + + PortP70 = PortP7.Pin0; + PortP71 = PortP7.Pin1; + PortP72 = PortP7.Pin2; + PortP73 = PortP7.Pin3; + PortP74 = PortP7.Pin4; + PortP75 = PortP7.Pin5; + PortP76 = PortP7.Pin6; + PortP77 = PortP7.Pin7; + + PortP80 = PortP8.Pin0; + PortP81 = PortP8.Pin1; + PortP82 = PortP8.Pin2; + PortP83 = PortP8.Pin3; + PortP84 = PortP8.Pin4; + PortP86 = PortP8.Pin6; + PortP87 = PortP8.Pin7; + + PortP90 = PortP9.Pin0; + PortP91 = PortP9.Pin1; + PortP92 = PortP9.Pin2; + PortP93 = PortP9.Pin3; + PortP94 = PortP9.Pin4; + PortP95 = PortP9.Pin5; + PortP96 = PortP9.Pin6; + PortP97 = PortP9.Pin7; + + PortP100 = PortP_10.Pin0; + PortP101 = PortP_10.Pin1; + PortP102 = PortP_10.Pin2; + PortP103 = PortP_10.Pin3; + PortP104 = PortP_10.Pin4; + PortP105 = PortP_10.Pin5; + PortP106 = PortP_10.Pin6; + PortP107 = PortP_10.Pin7; +} diff --git a/tos/chips/m16c62p/pins/HplM16c62pGeneralIOPinP.nc b/tos/chips/m16c62p/pins/HplM16c62pGeneralIOPinP.nc new file mode 100755 index 00000000..bcaf970b --- /dev/null +++ b/tos/chips/m16c62p/pins/HplM16c62pGeneralIOPinP.nc @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + */ + +/** + * Generic pin access for pins mapped into I/O space. + * + * @author Henrik Makitaavola + * @author Martin Turon + * @author David Gay + */ +generic module HplM16c62pGeneralIOPinP (uint16_t port_addr, + uint16_t ddr_addr, + uint16_t bit) +{ + provides interface GeneralIO as IO; +} +implementation +{ +#define port (*TCAST(volatile uint8_t* ONE, port_addr)) +#define ddr (*TCAST(volatile uint8_t* ONE, ddr_addr)) + + inline async command bool IO.get() { return READ_BIT (port, bit); } + inline async command void IO.set() { SET_BIT (port, bit); } + inline async command void IO.clr() { CLR_BIT (port, bit); } + inline async command void IO.toggle() { atomic FLIP_BIT (port, bit); } + + inline async command void IO.makeInput() { CLR_BIT (ddr, bit); } + inline async command bool IO.isInput() { return !READ_BIT(ddr, bit); } + inline async command void IO.makeOutput() { SET_BIT (ddr, bit); } + inline async command bool IO.isOutput() { return READ_BIT(ddr, bit); } +} + diff --git a/tos/chips/m16c62p/pins/HplM16c62pGeneralIOPortP.nc b/tos/chips/m16c62p/pins/HplM16c62pGeneralIOPortP.nc new file mode 100755 index 00000000..05c22702 --- /dev/null +++ b/tos/chips/m16c62p/pins/HplM16c62pGeneralIOPortP.nc @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + */ + +/** + * Generic component to expose a full 8-bit port of GPIO pins. + * + * @author Henrik Makitaavola + * @author Martin Turon + */ + +generic configuration HplM16c62pGeneralIOPortP(uint16_t port_addr, + uint16_t ddr_addr) +{ + // provides all the ports as raw ports + provides + { + interface GeneralIO as Pin0; + interface GeneralIO as Pin1; + interface GeneralIO as Pin2; + interface GeneralIO as Pin3; + interface GeneralIO as Pin4; + interface GeneralIO as Pin5; + interface GeneralIO as Pin6; + interface GeneralIO as Pin7; + } +} +implementation +{ + components + new HplM16c62pGeneralIOPinP (port_addr, ddr_addr, 0) as Bit0, + new HplM16c62pGeneralIOPinP (port_addr, ddr_addr, 1) as Bit1, + new HplM16c62pGeneralIOPinP (port_addr, ddr_addr, 2) as Bit2, + new HplM16c62pGeneralIOPinP (port_addr, ddr_addr, 3) as Bit3, + new HplM16c62pGeneralIOPinP (port_addr, ddr_addr, 4) as Bit4, + new HplM16c62pGeneralIOPinP (port_addr, ddr_addr, 5) as Bit5, + new HplM16c62pGeneralIOPinP (port_addr, ddr_addr, 6) as Bit6, + new HplM16c62pGeneralIOPinP (port_addr, ddr_addr, 7) as Bit7; + + Pin0 = Bit0; + Pin1 = Bit1; + Pin2 = Bit2; + Pin3 = Bit3; + Pin4 = Bit4; + Pin5 = Bit5; + Pin6 = Bit6; + Pin7 = Bit7; +} diff --git a/tos/chips/m16c62p/pins/HplM16c62pInterrupt.nc b/tos/chips/m16c62p/pins/HplM16c62pInterrupt.nc new file mode 100755 index 00000000..0959f3b6 --- /dev/null +++ b/tos/chips/m16c62p/pins/HplM16c62pInterrupt.nc @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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." + * + */ + +/** + * Interface to control an M16c/62p external pin interrupt. + * + * @author Henrik Makitaavola + * @author Joe Polastre + * @author Martin Turon + */ + +interface HplM16c62pInterrupt +{ + /** + * Enables M16c/62p hardware interrupt on a particular port. + */ + async command void enable(); + + /** + * Disables M16c/62p hardware interrupt on a particular port. + */ + async command void disable(); + + /** + * Clears the M16c/62p Interrupt Pending Flag for a particular port. + */ + async command void clear(); + + /** + * Gets the current value of the input voltage of a port. + * + * @return TRUE if the pin is set high, FALSE if it is set low. + */ + async command bool getValue(); + + /** + * Sets whether the edge should be high to low or low to high. + * @param TRUE if the interrupt should be triggered on a low to high + * edge transition, false for interrupts on a high to low transition. + */ + async command void edge(bool low_to_high); + + /** + * Sets the edge mode to both edges. + */ + async command void bothEdges(); + + /** + * Signaled when an interrupt occurs on a port. + */ + async event void fired(); +} diff --git a/tos/chips/m16c62p/pins/HplM16c62pInterruptC.nc b/tos/chips/m16c62p/pins/HplM16c62pInterruptC.nc new file mode 100755 index 00000000..8c82ca2c --- /dev/null +++ b/tos/chips/m16c62p/pins/HplM16c62pInterruptC.nc @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + * @author Martin Turon + */ + +/** + * This component providing access to all external pin interrupts on M16c/62P. + * + * @author Henrik Makitaavola + */ + +configuration HplM16c62pInterruptC +{ + provides + { + interface HplM16c62pInterrupt as Int0; + interface HplM16c62pInterrupt as Int1; + interface HplM16c62pInterrupt as Int2; + interface HplM16c62pInterrupt as Int3; + interface HplM16c62pInterrupt as Int4; + interface HplM16c62pInterrupt as Int5; + } +} +implementation +{ + components + HplM16c62pInterruptSigP as IrqVector, + new HplM16c62pInterruptPinP((uint16_t)&INT0IC, 0) as IntPin0, + new HplM16c62pInterruptPinP((uint16_t)&INT1IC, 1) as IntPin1, + new HplM16c62pInterruptPinP((uint16_t)&INT2IC, 2) as IntPin2, + new HplM16c62pInterruptPinP((uint16_t)&INT3IC, 3) as IntPin3, + new HplM16c62pInterruptPinP((uint16_t)&INT4IC, 4) as IntPin4, + new HplM16c62pInterruptPinP((uint16_t)&INT5IC, 5) as IntPin5; + + Int0 = IntPin0; + Int1 = IntPin1; + Int2 = IntPin2; + Int3 = IntPin3; + Int4 = IntPin4; + Int5 = IntPin5; + + IntPin0.IrqSignal -> IrqVector.IntSig0; + IntPin1.IrqSignal -> IrqVector.IntSig1; + IntPin2.IrqSignal -> IrqVector.IntSig2; + IntPin3.IrqSignal -> IrqVector.IntSig3; + IntPin4.IrqSignal -> IrqVector.IntSig4; + IntPin5.IrqSignal -> IrqVector.IntSig5; +} + diff --git a/tos/chips/m16c62p/pins/HplM16c62pInterruptPinP.nc b/tos/chips/m16c62p/pins/HplM16c62pInterruptPinP.nc new file mode 100755 index 00000000..871c7d9a --- /dev/null +++ b/tos/chips/m16c62p/pins/HplM16c62pInterruptPinP.nc @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + * @author Martin Turon + */ + +/** + * Interrupt interface access for interrupt capable GPIO pins. + * + * @author Henrik Makitaavola + */ +generic module HplM16c62pInterruptPinP (uint16_t ctrl_addr, uint8_t edgebit) +{ + provides interface HplM16c62pInterrupt as Irq; + uses interface HplM16c62pInterruptSig as IrqSignal; +} +implementation +{ +#define ctrl (*TCAST(volatile uint8_t * ONE, ctrl_addr)) + + inline async command bool Irq.getValue() { return READ_BIT(ctrl, 3); } + inline async command void Irq.clear() { clear_interrupt(ctrl_addr); } + inline async command void Irq.disable() { CLR_BIT(ctrl, 0); } + + inline async command void Irq.enable() + { + if (edgebit > 3) + { + SET_BIT(IFSR.BYTE, (edgebit+2)); + } + SET_BIT(ctrl, 0); + + } + + inline async command void Irq.edge(bool low_to_high) + { + CLR_BIT(IFSR.BYTE, edgebit); // use edge mode + // and select rising vs falling + if (low_to_high) + { + SET_BIT(ctrl, 4); + } + else + { + CLR_BIT(ctrl, 4); + } + } + + inline async command void Irq.bothEdges() + { + SET_BIT(IFSR.BYTE, edgebit); + CLR_BIT(ctrl, 4); + } + + /** + * Forward the external interrupt event. + */ + async event void IrqSignal.fired() + { + call Irq.clear(); + signal Irq.fired(); + } + + default async event void Irq.fired() { } +} diff --git a/tos/chips/m16c62p/pins/HplM16c62pInterruptSig.nc b/tos/chips/m16c62p/pins/HplM16c62pInterruptSig.nc new file mode 100755 index 00000000..a35138b6 --- /dev/null +++ b/tos/chips/m16c62p/pins/HplM16c62pInterruptSig.nc @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + */ + +/** + * Interface to an M16c/62p external pin interrupt that exposes just the + * interrupt vector routine for easy linking to generic components (see + * HplM16c62pInterrupt for the full interface). + * + * @author Henrik Makitaavola + * @author Martin Turon + * @see HplM16c62pInterrupt + */ +interface HplM16c62pInterruptSig +{ + /** + * Signaled when an interrupt occurs on a pin + */ + async event void fired(); +} + diff --git a/tos/chips/m16c62p/pins/HplM16c62pInterruptSigP.nc b/tos/chips/m16c62p/pins/HplM16c62pInterruptSigP.nc new file mode 100755 index 00000000..64546911 --- /dev/null +++ b/tos/chips/m16c62p/pins/HplM16c62pInterruptSigP.nc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + * @author Martin Turon + */ + +/** + * Interrupt interface access for interrupt capable GPIO pins. + * Exposes just the interrupt vector routine for + * easy linking to generic components. + * + * @author Henrik Makitaavola + */ +module HplM16c62pInterruptSigP +{ + provides interface HplM16c62pInterruptSig as IntSig0; + provides interface HplM16c62pInterruptSig as IntSig1; + provides interface HplM16c62pInterruptSig as IntSig2; + provides interface HplM16c62pInterruptSig as IntSig3; + provides interface HplM16c62pInterruptSig as IntSig4; + provides interface HplM16c62pInterruptSig as IntSig5; +} +implementation +{ + default async event void IntSig0.fired() { } + M16C_INTERRUPT_HANDLER(M16C_INT0) + { + signal IntSig0.fired(); + } + + default async event void IntSig1.fired() { } + M16C_INTERRUPT_HANDLER(M16C_INT1) + { + signal IntSig1.fired(); + } + + default async event void IntSig2.fired() { } + M16C_INTERRUPT_HANDLER(M16C_INT2) + { + signal IntSig2.fired(); + } + + default async event void IntSig3.fired() { } + M16C_INTERRUPT_HANDLER(M16C_INT3) + { + signal IntSig3.fired(); + } + + default async event void IntSig4.fired() { } + M16C_INTERRUPT_HANDLER(M16C_INT4) + { + signal IntSig4.fired(); + } + + default async event void IntSig5.fired() { } + M16C_INTERRUPT_HANDLER(M16C_INT5) + { + signal IntSig5.fired(); + } + +} diff --git a/tos/chips/m16c62p/pins/M16c62pInterruptC.nc b/tos/chips/m16c62p/pins/M16c62pInterruptC.nc new file mode 100755 index 00000000..b5b3be59 --- /dev/null +++ b/tos/chips/m16c62p/pins/M16c62pInterruptC.nc @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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 + * @author Martin Turon + */ + +/** + * Creates a HIL interrupt component from a M16c/62p interrupt. + * + * @author Henrik Makitaavola + */ +generic module M16c62pInterruptC() +{ + provides interface GpioInterrupt; + uses interface HplM16c62pInterrupt; +} +implementation { + async command error_t GpioInterrupt.enableRisingEdge() + { + atomic + { + call HplM16c62pInterrupt.disable(); + call HplM16c62pInterrupt.edge(true); + call HplM16c62pInterrupt.clear(); + call HplM16c62pInterrupt.enable(); + } + return SUCCESS; + } + + async command error_t GpioInterrupt.enableFallingEdge() + { + atomic + { + call HplM16c62pInterrupt.disable(); + call HplM16c62pInterrupt.edge(false); + call HplM16c62pInterrupt.clear(); + call HplM16c62pInterrupt.enable(); + } + return SUCCESS; + } + + async command error_t GpioInterrupt.disable() + { + atomic + { + call HplM16c62pInterrupt.disable(); + call HplM16c62pInterrupt.clear(); + } + return SUCCESS; + } + + async event void HplM16c62pInterrupt.fired() + { + signal GpioInterrupt.fired(); + } + + default async event void GpioInterrupt.fired() { } +} diff --git a/tos/chips/m16c62p/timer/HplM16c62pTimer.nc b/tos/chips/m16c62p/timer/HplM16c62pTimer.nc new file mode 100755 index 00000000..a762e2c2 --- /dev/null +++ b/tos/chips/m16c62p/timer/HplM16c62pTimer.nc @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + */ + +/** + * Basic interface to the hardware timers on the M16C/62p. + * This interface provides four major groups of functionality:
    + *
  1. Timer Value: get/set current time + *
  2. Interrupt event, occurs when the timer under- or overflows. + *
  3. Control of Interrupt: enableInterrupt/disableInterrupt/clearInterrupt... + *
  4. Timer Initialization: turn on/off clock source + *
+ * + * @author Henrik Makitaavola + * @author Martin Turon + */ + +#include "M16c62pTimer.h" + +interface HplM16c62pTimer +{ + /** + * Turn on the clock. + */ + async command void on(); + + /** + * Turn off the clock. + */ + async command void off(); + + /** + * Check if the clock is on. + */ + async command bool isOn(); + + /** + * Get the current time. + * @return the current time. + */ + async command uint16_t get(); + + /** + * Set the current time. + * @param t the time to set. + */ + async command void set( uint16_t t ); + + /** + * Signalled on timer interrupt. + */ + async event void fired(); + + /** + * Clear the interrupt flag. + */ + async command void clearInterrupt(); + + /** + * Enable the interrupts. + */ + async command void enableInterrupt(); + + /** + * Turns off interrupts. + */ + async command void disableInterrupt(); + + /** + * Checks if an interrupt has occured. + * @return TRUE if interrupt has triggered. + */ + async command bool testInterrupt(); + + /** + * Checks if interrupts are on. + * @return TRUE if interrups are enabled. + */ + async command bool isInterruptOn(); + + /** + * Turn stop mode on/off while the timer is on. + * @param allow If true the mcu can go into stop mode while + * timer is on if false the mcu can only use + * wait mode while timer is on. + */ + async command void allowStopMode(bool allow); +} diff --git a/tos/chips/m16c62p/timer/HplM16c62pTimerACtrl.nc b/tos/chips/m16c62p/timer/HplM16c62pTimerACtrl.nc new file mode 100755 index 00000000..2151e994 --- /dev/null +++ b/tos/chips/m16c62p/timer/HplM16c62pTimerACtrl.nc @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 controlling the mode of a TimerA. + * + * @author Henrik Makitaavola + */ + +#include "M16c62pTimer.h" + +interface HplM16c62pTimerACtrl +{ + /** + * Sets the timer to timer mode. + * + * @param settings The settings for the timer mode. + */ + async command void setTimerMode(st_timer settings); + + /** + * Sets the timer to counter mode. + * + * @param settings The settings for the counter mode. + */ + async command void setCounterMode(sta_counter settings); + + /** + * Sets the timer to one-shot mode. + * + * @param settings The settings for the one-shot mode. + */ + async command void setOneShotMode(sta_one_shot settings); + + /** + * Starts the timer if in one-shot mode. + */ + async command void oneShotFire(); +} diff --git a/tos/chips/m16c62p/timer/HplM16c62pTimerACtrlP.nc b/tos/chips/m16c62p/timer/HplM16c62pTimerACtrlP.nc new file mode 100755 index 00000000..72b85794 --- /dev/null +++ b/tos/chips/m16c62p/timer/HplM16c62pTimerACtrlP.nc @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Implementation of the HplM16c62pTimerACtrl interface. + * + * @author Henrik Makitaavola + */ + +#include "M16c62pTimer.h" + +generic module HplM16c62pTimerACtrlP (uint8_t timer, + uint16_t mode_addr, + uint16_t taitg_addr, + uint8_t taitg_start_bit) +{ + provides interface HplM16c62pTimerACtrl as TimerACtrl; +} +implementation +{ +#define mode (*TCAST(volatile uint8_t* ONE, mode_addr)) +#define taitg (*TCAST(volatile uint8_t* ONE, taitg_addr)) + inline void UDFBit(uint16_t bit, uint16_t value) + { + uint8_t tmp = UDF; + WRITE_BIT(tmp, bit, value); + // Move tmp variable into UDF (adress 0x0384) + asm("mov.b %0,(0x0384)" : : "r"(tmp) ); + } + + inline void setTAiTG(uint8_t flag) + { + CLR_FLAG(taitg, 0x03 << taitg_start_bit); + SET_FLAG(taitg, flag << taitg_start_bit); + } + + async command void TimerACtrl.setTimerMode(st_timer settings) + { + uint8_t flags = 0; + // If timer nr > 1 set "Two-phase pulse signal" bit to zero. + if (timer > 1) + { + UDFBit(timer + 3, 0); + } + flags = settings.output_pulse << 2 | settings.gate_func << 3 | settings.count_src << 6; + mode = flags; + } + + async command void TimerACtrl.setCounterMode(sta_counter settings) + { + uint8_t flags; + uint8_t TAiTG; + mode = 1; + flags = settings.operation_type << 6; + if (settings.two_phase_pulse_mode && timer > 1) + { + uint8_t tmp = timer; // Used to remove left shift warning + // Set flags + flags |= 0x04 | settings.two_phase_processing << 7; + // If two-phase signal procressing is desired UDF TAiP bit must be set. + UDFBit(timer + 3, 1); + // Set TAiTGH and TAiTGL in TRGSR to "00b" (TAiIN pin input). + if (tmp == 0) + tmp = 1; // This line will never be executed because tmp is always > 1 + CLR_FLAG(TRGSR.BYTE, 0x03 << ((tmp - 1) * 2)); + TAiTG = 0x00; + } + else + { + flags |= settings.output_pulse << 2 | settings.count_rising_edge << 3 | + settings.up_down_switch << 4; + // If two-phase signal procressing is not desired UDF TAiP bit must be cleared. + // Note this is only availible for timers A2, A3 and A4 + if (timer > 1) + { + UDFBit(timer + 3, 0); + } + UDFBit(timer, settings.up_count); + TAiTG = settings.event_source; + } + setTAiTG(TAiTG); + mode |= flags; + } + + async command void TimerACtrl.setOneShotMode(sta_one_shot settings) + { + uint8_t flags; + mode = 0x02; + flags = settings.output_pulse << 2 | settings.ext_trigger_rising_edge << 3 | settings.trigger << 4 | settings.count_src << 6; + setTAiTG(settings.TAiTG_trigger_source); + mode |= flags; + } + + async command void TimerACtrl.oneShotFire() + { + SET_BIT(ONSF.BYTE, timer); + } +} diff --git a/tos/chips/m16c62p/timer/HplM16c62pTimerBCtrl.nc b/tos/chips/m16c62p/timer/HplM16c62pTimerBCtrl.nc new file mode 100755 index 00000000..e7c59847 --- /dev/null +++ b/tos/chips/m16c62p/timer/HplM16c62pTimerBCtrl.nc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 controlling the mode of a TimerB. +* Precaution when using timer mode, read M16c62pTimer.h for more information. +* +* @author Henrik Makitaavola +*/ + +#include "M16c62pTimer.h" + +interface HplM16c62pTimerBCtrl +{ + /** + * Sets the timer to timer mode. + * + * @param settings The settings for the timer mode. + */ + async command void setTimerMode(st_timer settings); + + /** + * Sets the timer to counter mode. + * + * @param settings The settings for the counter mode. + */ + async command void setCounterMode(stb_counter settings); +} diff --git a/tos/chips/m16c62p/timer/HplM16c62pTimerBCtrlP.nc b/tos/chips/m16c62p/timer/HplM16c62pTimerBCtrlP.nc new file mode 100755 index 00000000..ab59f19f --- /dev/null +++ b/tos/chips/m16c62p/timer/HplM16c62pTimerBCtrlP.nc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Implementation of the HplM16c62pTimerBCtrl interface. + * + * @author Henrik Makitaavola + */ + +#include "M16c62pTimer.h" + +generic module HplM16c62pTimerBCtrlP (uint16_t mode_addr) +{ + provides interface HplM16c62pTimerBCtrl as TimerBCtrl; +} +implementation +{ +#define mode (*TCAST(volatile uint8_t* ONE, mode_addr)) + async command void TimerBCtrl.setTimerMode(st_timer settings) + { + mode = settings.count_src << 6; + } + + async command void TimerBCtrl.setCounterMode(stb_counter settings) + { + mode = 1 | settings.count_polarity << 2 | settings.event_source << 7; + } +} diff --git a/tos/chips/m16c62p/timer/HplM16c62pTimerC.nc b/tos/chips/m16c62p/timer/HplM16c62pTimerC.nc new file mode 100755 index 00000000..d7f07daa --- /dev/null +++ b/tos/chips/m16c62p/timer/HplM16c62pTimerC.nc @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Interfaces to all the M16c/62p timers and controls. + * + * @author Henrik Makitaavola + */ +configuration HplM16c62pTimerC +{ + provides + { + interface HplM16c62pTimer as TimerA0; + interface HplM16c62pTimer as TimerA1; + interface HplM16c62pTimer as TimerA2; + interface HplM16c62pTimer as TimerA3; + interface HplM16c62pTimer as TimerA4; + + interface HplM16c62pTimerACtrl as TimerA0Ctrl; + interface HplM16c62pTimerACtrl as TimerA1Ctrl; + interface HplM16c62pTimerACtrl as TimerA2Ctrl; + interface HplM16c62pTimerACtrl as TimerA3Ctrl; + interface HplM16c62pTimerACtrl as TimerA4Ctrl; + + interface HplM16c62pTimer as TimerB0; + interface HplM16c62pTimer as TimerB1; + interface HplM16c62pTimer as TimerB2; + interface HplM16c62pTimer as TimerB3; + interface HplM16c62pTimer as TimerB4; + interface HplM16c62pTimer as TimerB5; + + interface HplM16c62pTimerBCtrl as TimerB0Ctrl; + interface HplM16c62pTimerBCtrl as TimerB1Ctrl; + interface HplM16c62pTimerBCtrl as TimerB2Ctrl; + interface HplM16c62pTimerBCtrl as TimerB3Ctrl; + interface HplM16c62pTimerBCtrl as TimerB4Ctrl; + interface HplM16c62pTimerBCtrl as TimerB5Ctrl; + } +} +implementation +{ + components + HplM16c62pTimerInterruptP as IrqVector, + new HplM16c62pTimerP((uint16_t)&TA0, (uint16_t)&TA0IC, (uint16_t)&TABSR, 0) as TimerA0_, + new HplM16c62pTimerP((uint16_t)&TA1, (uint16_t)&TA1IC, (uint16_t)&TABSR, 1) as TimerA1_, + new HplM16c62pTimerP((uint16_t)&TA2, (uint16_t)&TA2IC, (uint16_t)&TABSR, 2) as TimerA2_, + new HplM16c62pTimerP((uint16_t)&TA3, (uint16_t)&TA3IC, (uint16_t)&TABSR, 3) as TimerA3_, + new HplM16c62pTimerP((uint16_t)&TA4, (uint16_t)&TA4IC, (uint16_t)&TABSR, 4) as TimerA4_, + + new HplM16c62pTimerACtrlP(0, (uint16_t)&TA0MR, (uint16_t)&ONSF, 6) as TimerA0Ctrl_, + new HplM16c62pTimerACtrlP(1, (uint16_t)&TA1MR, (uint16_t)&TRGSR, 0) as TimerA1Ctrl_, + new HplM16c62pTimerACtrlP(2, (uint16_t)&TA2MR, (uint16_t)&TRGSR, 2) as TimerA2Ctrl_, + new HplM16c62pTimerACtrlP(3, (uint16_t)&TA3MR, (uint16_t)&TRGSR, 4) as TimerA3Ctrl_, + new HplM16c62pTimerACtrlP(4, (uint16_t)&TA4MR, (uint16_t)&TRGSR, 6) as TimerA4Ctrl_, + + new HplM16c62pTimerP((uint16_t)&TB0, (uint16_t)&TB0IC, (uint16_t)&TABSR, 5) as TimerB0_, + new HplM16c62pTimerP((uint16_t)&TB1, (uint16_t)&TB1IC, (uint16_t)&TABSR, 6) as TimerB1_, + new HplM16c62pTimerP((uint16_t)&TB2, (uint16_t)&TB2IC, (uint16_t)&TABSR, 7) as TimerB2_, + new HplM16c62pTimerP((uint16_t)&TB3, (uint16_t)&TB3IC, (uint16_t)&TBSR, 5) as TimerB3_, + new HplM16c62pTimerP((uint16_t)&TB4, (uint16_t)&TB4IC, (uint16_t)&TBSR, 6) as TimerB4_, + new HplM16c62pTimerP((uint16_t)&TB5, (uint16_t)&TB5IC, (uint16_t)&TBSR, 7) as TimerB5_, + + new HplM16c62pTimerBCtrlP((uint16_t)&TB0MR) as TimerB0Ctrl_, + new HplM16c62pTimerBCtrlP((uint16_t)&TB1MR) as TimerB1Ctrl_, + new HplM16c62pTimerBCtrlP((uint16_t)&TB2MR) as TimerB2Ctrl_, + new HplM16c62pTimerBCtrlP((uint16_t)&TB3MR) as TimerB3Ctrl_, + new HplM16c62pTimerBCtrlP((uint16_t)&TB4MR) as TimerB4Ctrl_, + new HplM16c62pTimerBCtrlP((uint16_t)&TB5MR) as TimerB5Ctrl_, + + new StopModeControlC() as TimerA0StopModeControl, + new StopModeControlC() as TimerA1StopModeControl, + new StopModeControlC() as TimerA2StopModeControl, + new StopModeControlC() as TimerA3StopModeControl, + new StopModeControlC() as TimerA4StopModeControl, + + new StopModeControlC() as TimerB0StopModeControl, + new StopModeControlC() as TimerB1StopModeControl, + new StopModeControlC() as TimerB2StopModeControl, + new StopModeControlC() as TimerB3StopModeControl, + new StopModeControlC() as TimerB4StopModeControl, + new StopModeControlC() as TimerB5StopModeControl; + + + TimerA0 = TimerA0_; + TimerA1 = TimerA1_; + TimerA2 = TimerA2_; + TimerA3 = TimerA3_; + TimerA4 = TimerA4_; + + TimerA0_.StopModeControl -> TimerA0StopModeControl; + TimerA1_.StopModeControl -> TimerA1StopModeControl; + TimerA2_.StopModeControl -> TimerA2StopModeControl; + TimerA3_.StopModeControl -> TimerA3StopModeControl; + TimerA4_.StopModeControl -> TimerA4StopModeControl; + + TimerB0 = TimerB0_; + TimerB1 = TimerB1_; + TimerB2 = TimerB2_; + TimerB3 = TimerB3_; + TimerB4 = TimerB4_; + TimerB5 = TimerB5_; + + TimerB0_.StopModeControl -> TimerB0StopModeControl; + TimerB1_.StopModeControl -> TimerB1StopModeControl; + TimerB2_.StopModeControl -> TimerB2StopModeControl; + TimerB3_.StopModeControl -> TimerB3StopModeControl; + TimerB4_.StopModeControl -> TimerB4StopModeControl; + TimerB5_.StopModeControl -> TimerB5StopModeControl; + + TimerA0_.IrqSignal -> IrqVector.TimerA0; + TimerA1_.IrqSignal -> IrqVector.TimerA1; + TimerA2_.IrqSignal -> IrqVector.TimerA2; + TimerA3_.IrqSignal -> IrqVector.TimerA3; + TimerA4_.IrqSignal -> IrqVector.TimerA4; + + TimerB0_.IrqSignal -> IrqVector.TimerB0; + TimerB1_.IrqSignal -> IrqVector.TimerB1; + TimerB2_.IrqSignal -> IrqVector.TimerB2; + TimerB3_.IrqSignal -> IrqVector.TimerB3; + TimerB4_.IrqSignal -> IrqVector.TimerB4; + TimerB5_.IrqSignal -> IrqVector.TimerB5; + + TimerA0Ctrl = TimerA0Ctrl_; + TimerA1Ctrl = TimerA1Ctrl_; + TimerA2Ctrl = TimerA2Ctrl_; + TimerA3Ctrl = TimerA3Ctrl_; + TimerA4Ctrl = TimerA4Ctrl_; + + TimerB0Ctrl = TimerB0Ctrl_; + TimerB1Ctrl = TimerB1Ctrl_; + TimerB2Ctrl = TimerB2Ctrl_; + TimerB3Ctrl = TimerB3Ctrl_; + TimerB4Ctrl = TimerB4Ctrl_; + TimerB5Ctrl = TimerB5Ctrl_; +} diff --git a/tos/chips/m16c62p/timer/HplM16c62pTimerInterrupt.nc b/tos/chips/m16c62p/timer/HplM16c62pTimerInterrupt.nc new file mode 100755 index 00000000..e373a298 --- /dev/null +++ b/tos/chips/m16c62p/timer/HplM16c62pTimerInterrupt.nc @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 interrupt signal from a timer. + * + * @author Henrik Makitaavola + */ +interface HplM16c62pTimerInterrupt +{ + /** + * Signal when an overflow/underflow interrupt occurs on a timer. + */ + async event void fired(); +} + diff --git a/tos/chips/m16c62p/timer/HplM16c62pTimerInterruptP.nc b/tos/chips/m16c62p/timer/HplM16c62pTimerInterruptP.nc new file mode 100755 index 00000000..42689764 --- /dev/null +++ b/tos/chips/m16c62p/timer/HplM16c62pTimerInterruptP.nc @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * All timer interrupt vector handlers. + * These are wired in HplM16c62pTimerC. + * + * @author Henrik Makitaavola + */ + +module HplM16c62pTimerInterruptP +{ + provides interface HplM16c62pTimerInterrupt as TimerA0; + provides interface HplM16c62pTimerInterrupt as TimerA1; + provides interface HplM16c62pTimerInterrupt as TimerA2; + provides interface HplM16c62pTimerInterrupt as TimerA3; + provides interface HplM16c62pTimerInterrupt as TimerA4; + provides interface HplM16c62pTimerInterrupt as TimerB0; + provides interface HplM16c62pTimerInterrupt as TimerB1; + provides interface HplM16c62pTimerInterrupt as TimerB2; + provides interface HplM16c62pTimerInterrupt as TimerB3; + provides interface HplM16c62pTimerInterrupt as TimerB4; + provides interface HplM16c62pTimerInterrupt as TimerB5; +} +implementation +{ + default async event void TimerA0.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRA0) + { + signal TimerA0.fired(); + } + + default async event void TimerA1.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRA1) + { + signal TimerA1.fired(); + } + + default async event void TimerA2.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRA2) + { + signal TimerA2.fired(); + } + + default async event void TimerA3.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRA3) + { + signal TimerA3.fired(); + } + + default async event void TimerA4.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRA4) + { + signal TimerA4.fired(); + } + + default async event void TimerB0.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRB0) + { + signal TimerB0.fired(); + } + + default async event void TimerB1.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRB1) + { + signal TimerB1.fired(); + } + + default async event void TimerB2.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRB2) + { + signal TimerB2.fired(); + } + + default async event void TimerB3.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRB3) + { + signal TimerB3.fired(); + } + + default async event void TimerB4.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRB4) + { + signal TimerB4.fired(); + } + + default async event void TimerB5.fired() { } + M16C_INTERRUPT_HANDLER(M16C_TMRB5) + { + signal TimerB5.fired(); + } + +} diff --git a/tos/chips/m16c62p/timer/HplM16c62pTimerP.nc b/tos/chips/m16c62p/timer/HplM16c62pTimerP.nc new file mode 100755 index 00000000..eef8fb12 --- /dev/null +++ b/tos/chips/m16c62p/timer/HplM16c62pTimerP.nc @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Implementation of a generic HplM16c62pTimer interface. + * + * @author Henrik Makitaavola + */ +generic module HplM16c62pTimerP (uint16_t timer_addr, + uint16_t interrupt_addr, + uint16_t start_addr, + uint8_t start_bit) +{ + provides interface HplM16c62pTimer as Timer; + + uses interface HplM16c62pTimerInterrupt as IrqSignal; + uses interface StopModeControl; +} +implementation +{ +#define timer (*TCAST(volatile uint16_t* ONE, timer_addr)) +#define start (*TCAST(volatile uint8_t* ONE, start_addr)) +#define interrupt (*TCAST(volatile uint8_t* ONE, interrupt_addr)) + + bool allow_stop_mode = false; + + async command uint16_t Timer.get() { return timer; } + + async command void Timer.set( uint16_t t ) + { + // If the timer is on it must be turned off, else the value will + // only be written to the reload register. + atomic + { + if(call Timer.isOn()) + { + call Timer.off(); + timer = t; + call Timer.on(); + } + else + { + timer = t; + } + } + } + + // When the timer is turned on in one-shot mode on TimerA + // the timer also needs an trigger event to start counting. + async command void Timer.on() + { + atomic if (!allow_stop_mode) + { + call StopModeControl.allowStopMode(false); + } + SET_BIT(start, start_bit); + } + + async command void Timer.off() + { + CLR_BIT(start, start_bit); + atomic if (!allow_stop_mode) + { + call StopModeControl.allowStopMode(true); + } + } + + async command bool Timer.isOn() { return READ_BIT(start, start_bit); } + async command void Timer.clearInterrupt() { clear_interrupt(interrupt_addr); } + async command void Timer.enableInterrupt() { SET_BIT(interrupt, 0); } + async command void Timer.disableInterrupt() { CLR_BIT(interrupt, 0); } + async command bool Timer.testInterrupt() { return READ_BIT(interrupt, 3); } + async command bool Timer.isInterruptOn() { return READ_BIT(interrupt, 0); } + + async command void Timer.allowStopMode(bool allow) + { + allow_stop_mode = allow; + } + + // Forward the timer interrupt event. + async event void IrqSignal.fired() { signal Timer.fired(); } + + default async event void Timer.fired() { } +} diff --git a/tos/chips/m16c62p/timer/M16c62pAlarm16C.nc b/tos/chips/m16c62p/timer/M16c62pAlarm16C.nc new file mode 100755 index 00000000..72028940 --- /dev/null +++ b/tos/chips/m16c62p/timer/M16c62pAlarm16C.nc @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Build a TEP102 16bits Alarm from a counter and a M16c62p hardware timers. + * Use the counter to get the "current time" and the hw timer to count down the + * remaining time for the alarm to be fired. + * + * @author Henrik Makitaavola + */ + +generic module M16c62pAlarm16C(typedef precision_tag) +{ + provides interface Alarm as Alarm @atmostonce(); + + uses interface HplM16c62pTimer as ATimer; // Alarm Timer + uses interface Counter; +} +implementation +{ + uint16_t alarm = 0; + async command uint16_t Alarm.getNow() + { + return call Counter.get(); + } + + async command uint16_t Alarm.getAlarm() + { + return alarm; + } + + async command bool Alarm.isRunning() + { + return call ATimer.isInterruptOn(); + } + + async command void Alarm.stop() + { + atomic + { + call ATimer.off(); + call ATimer.disableInterrupt(); + } + } + + async command void Alarm.start( uint16_t dt ) + { + call Alarm.startAt( call Alarm.getNow(), dt); + } + + async command void Alarm.startAt( uint16_t t0, uint16_t dt ) + { + atomic + { + uint16_t now, elapsed, expires; + + now = call Alarm.getNow(); + elapsed = now - t0; + + if (elapsed >= dt) + { + expires = 0; + } + else + { + expires = dt - elapsed - 1; + } + + call ATimer.off(); + call ATimer.set(expires); + call ATimer.clearInterrupt(); + call ATimer.enableInterrupt(); + call ATimer.on(); + } + } + + async event void ATimer.fired() + { + call Alarm.stop(); + signal Alarm.fired(); + } + + async event void Counter.overflow() {} +} diff --git a/tos/chips/m16c62p/timer/M16c62pAlarm32C.nc b/tos/chips/m16c62p/timer/M16c62pAlarm32C.nc new file mode 100755 index 00000000..2e94821c --- /dev/null +++ b/tos/chips/m16c62p/timer/M16c62pAlarm32C.nc @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Build a TEP102 32bit Alarm from a counter and two M16c62p hardware timers. + * Use the counter to get the "current time" and the hw timer to count down the + * remaining time for the alarm to be fired. + * + * @author Henrik Makitaavola + */ + +generic module M16c62pAlarm32C(typedef precision_tag) +{ + provides interface Alarm as Alarm @atmostonce(); + + uses interface HplM16c62pTimer as ATimerLow; // Alarm Timer low bits + uses interface HplM16c62pTimer as ATimerHigh; // Alarm Timer high bits + uses interface Counter; +} +implementation +{ + uint32_t alarm = 0; + + async command uint32_t Alarm.getNow() + { + return call Counter.get(); + } + + async command uint32_t Alarm.getAlarm() + { + atomic return alarm; + } + + async command bool Alarm.isRunning() + { + return call ATimerLow.isInterruptOn() || call ATimerHigh.isInterruptOn(); + } + + async command void Alarm.stop() + { + atomic + { + call ATimerLow.off(); + call ATimerLow.disableInterrupt(); + call ATimerHigh.off(); + call ATimerHigh.disableInterrupt(); + } + } + + async command void Alarm.start( uint32_t dt ) + { + call Alarm.startAt( call Alarm.getNow(), dt); + } + + async command void Alarm.startAt( uint32_t t0, uint32_t dt ) + { + atomic + { + uint32_t now, elapsed, expires; + + now = call Alarm.getNow(); + elapsed = now - t0; + + if (elapsed >= dt) + { + expires = 0; + } + else + { + expires = dt - elapsed - 1; + } + + alarm = expires; + + call Alarm.stop(); + + if (expires <= 0xFFFF) + { + call ATimerLow.set((uint16_t)expires); + call ATimerLow.clearInterrupt(); + call ATimerLow.enableInterrupt(); + call ATimerLow.on(); + } + else + { + uint16_t high_bits; + + high_bits = expires >> 16; + call ATimerHigh.set(high_bits-1); + call ATimerHigh.clearInterrupt(); + call ATimerHigh.enableInterrupt(); + call ATimerHigh.on(); + call ATimerLow.set(0xFFFF); + call ATimerLow.on(); + } + } + } + + async event void ATimerLow.fired() + { + call Alarm.stop(); + signal Alarm.fired(); + } + + async event void ATimerHigh.fired() + { + atomic + { + uint16_t remaining; + + call Alarm.stop(); + + // All the high bits should have been cleared so only the + // low should remain. + remaining = (uint16_t)(alarm & 0xFFFF); + if (remaining != 0) + { + call ATimerLow.set(remaining); + call ATimerLow.clearInterrupt(); + call ATimerLow.enableInterrupt(); + call ATimerLow.on(); + } + else + { + signal Alarm.fired(); + } + } + } + async event void Counter.overflow() {} +} diff --git a/tos/chips/m16c62p/timer/M16c62pCounter16C.nc b/tos/chips/m16c62p/timer/M16c62pCounter16C.nc new file mode 100755 index 00000000..9c97329b --- /dev/null +++ b/tos/chips/m16c62p/timer/M16c62pCounter16C.nc @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Build a TEP102 16bits Counter from an M16c/62p hardware timer. + * + * @author Henrik Makitaavola + */ + +generic module M16c62pCounter16C(typedef precision_tag) +{ + provides interface Counter as Counter; + uses interface HplM16c62pTimer as Timer; +} +implementation +{ + async command uint16_t Counter.get() + { + // The timer counts down so the time needs to be inverted. + return (0xFFFF) - call Timer.get(); + } + + async command bool Counter.isOverflowPending() + { + return call Timer.testInterrupt(); + } + + async command void Counter.clearOverflow() + { + call Timer.clearInterrupt(); + } + + async event void Timer.fired() + { + signal Counter.overflow(); + } +} + diff --git a/tos/chips/m16c62p/timer/M16c62pCounter32C.nc b/tos/chips/m16c62p/timer/M16c62pCounter32C.nc new file mode 100755 index 00000000..fb5c3b8f --- /dev/null +++ b/tos/chips/m16c62p/timer/M16c62pCounter32C.nc @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Build a TEP102 32 bit Counter from two M16c/62p hardware timers. + * + * @author Henrik Makitaavola + */ + +generic module M16c62pCounter32C(typedef precision_tag) +{ + provides interface Counter as Counter; + uses interface HplM16c62pTimer as TimerLow; + uses interface HplM16c62pTimer as TimerHigh; +} +implementation +{ + async command uint32_t Counter.get() + { + uint32_t time = 0; + atomic + { + time = (((uint32_t)call TimerHigh.get()) << 16) + call TimerLow.get(); + } + // The timers count down so the time needs to be inverted. + return (0xFFFFFFFF) - time; + } + + async command bool Counter.isOverflowPending() + { + return call TimerHigh.testInterrupt(); + } + + async command void Counter.clearOverflow() + { + call TimerHigh.clearInterrupt(); + } + + async event void TimerHigh.fired() + { + signal Counter.overflow(); + } + + async event void TimerLow.fired() {} +} + diff --git a/tos/chips/m16c62p/timer/M16c62pTimer.h b/tos/chips/m16c62p/timer/M16c62pTimer.h new file mode 100755 index 00000000..9f6786be --- /dev/null +++ b/tos/chips/m16c62p/timer/M16c62pTimer.h @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 contains structures and defines used together with timer + * interfaces and control. + * + * @author Henrik Makitaavola + */ + +#ifndef __M16C62PTIMER_H__ +#define __M16C62PTIMER_H__ +/* + * Precations when using Timer A1 and Timer A2. + * Read hardware manual page 139. + * + * Precations when using Timer B2. + * Read hardware manual page 156. + */ + +enum +{ + TMR_TIMER_MODE, + TMR_COUNTER_MODE, + TMR_ONE_SHOT_MODE +}; + + +/* Timer mode */ +typedef struct +{ + uint8_t output_pulse:1; // TAiMR: MR0 . TAiOUT pin is a pulse output pin if bit is set. No effect on TimerB. + uint8_t gate_func:2; // TAiMR: MR1, MR2 [ NO_GATE | TAiIN_LOW | TAiIN_HIGH ] . No effect on TimerB. + uint8_t count_src:2; // T*iMR: TCK0, TCK1 [ F1_2 | F8 | F32 | FC32 ] +} st_timer; + +// "gate_func" +enum +{ + M16C_TMR_TMR_GF_NO_GATE = 0x0, + M16C_TMR_TMR_GF_TAiIN_LOW = 0x2, + M16C_TMR_TMR_GF_TAiIN_HIGH = 0x3 +}; + + +/* TimerA Counter mode */ +typedef struct +{ + uint8_t two_phase_pulse_mode:1; // Use two phase mode, only available for timers A2, A3 and A4, will be ignored else. + // Flags active in two-phase mode + uint8_t two_phase_processing:1; // TAiMR: TCK1 [ NORMAL | MULTIPLY_BY_4 ] Only active for Timer A3. + + // Flags active when not using two-phase mode. + uint8_t output_pulse:1; // TAIMR: MR0 . TAiOUT is N-channel open drain output when bit is set. + uint8_t count_rising_edge:1; // TAiMR: MR1 . Active when event_trigger = TAiIN + uint8_t up_down_switch:1; // TAiMR: MR2 [ UDF | TAiOUT ] + uint8_t up_count:1; // UDF: TAiUD . Active when up_down_switch = UDF + uint8_t event_source:2; // ONSF/TRGS: TAiTG [ TAiIN | TB2 | TA_PREV | TA_NEXT ] + + // Flags active in both modes + uint8_t operation_type:1; // TAiMR: TCK0 [ RELOAD | FREE_RUN ] +} sta_counter; + +// "operation_type" +enum +{ + M16C_TMR_CTR_OT_RELOAD = 0x0, + M16C_TMR_CTR_OT_FREE_RUN = 0x1 +}; + +// "up_down_switch" +enum +{ + M16C_TMR_CTR_UDS_UDF = 0x0, + M16C_TMR_CTR_UDS_TAiOUT = 0x1 +}; + +// "two_phase_processing" +enum +{ + M16C_TMR_CTR_TPP_NORMAL = 0x0, + M16C_TMR_CTR_TPP_MULTIPLY_BY_4 = 0x1 +}; + + +/* TimerA one shot mode. */ +typedef struct +{ + uint8_t output_pulse:1; // TAiMR: MR0 . TAiOUT pin is a pulse output pin if bit is set. + uint8_t ext_trigger_rising_edge:1;// TAiMR: MR1 . Trigger on rising edge of input signal to TAiIN if bit is set. Active when TAiTG = 00b. + uint8_t trigger:1; // TAiMR: MR2 [ TAiOS | TAiTG ] + uint8_t count_src:2; // TAiMR: TCK0, TCK1 [ F1_2 | F8 | F32 | FC32 ] + uint8_t TAiTG_trigger_source:2; // ONSF/TRGS: TAiTG [ TAiIN | TB2 | TA_PREV | TA_NEXT ]. Active if trigger = TAiTG +} sta_one_shot; + +// "trigger" +enum +{ + M16C_TMRA_OS_T_TAiOS = 0x00, + M16C_TMRA_OS_T_TAiTG = 0x01 +}; + + + +/* TimerB Counter mode. */ +typedef struct +{ + uint8_t count_polarity:2; // TBiMR: MR0, MR1 [ EXT_FALLING_EDGE | EXT_RISING_EDGE | EXT_BOTH ] . Effective if event_source = TBiIN. + uint8_t event_source:1; // TBiMR: TCK1 [ TBiIN | TBj ] . j = i-1, except j = 2 if i = 0 and j = 5 if i = 3. +} stb_counter; + +// "counter_polarity" +enum +{ + M16C_TMRB_CTR_CP_EXT_FALLING_EDGE = 0x0, + M16C_TMRB_CTR_CP_EXT_RISING_EDGE = 0x1, + M16C_TMRB_CTR_CP_EXT_BOTH = 0x2, +}; + +// "event_source" +enum +{ + M16C_TMRB_CTR_ES_TBiIN = 0x0, + M16C_TMRB_CTR_ES_TBj = 0x1 +}; + + +/* Common settings */ + +// TimerA One Shot "TAiTG_trigger_source" , TimerA Counter "event_source" +enum +{ + M16C_TMRA_TES_TAiIN = 0x0, + M16C_TMRA_TES_TB2 = 0x1, + M16C_TMRA_TES_TA_PREV = 0x2, + M16C_TMRA_TES_TA_NEXT = 0x3 +}; + +// TimerA/B, TimerA One Shot : "count_src" +enum +{ + M16C_TMR_CS_F1_2 = 0x0, + M16C_TMR_CS_F8 = 0x1, + M16C_TMR_CS_F32 = 0x2, + M16C_TMR_CS_FC32 = 0x3 +}; + +#endif // __M16C62PTMR_H__ diff --git a/tos/chips/m16c62p/timer/M16c62pTimerAInitC.nc b/tos/chips/m16c62p/timer/M16c62pTimerAInitC.nc new file mode 100755 index 00000000..9b0743bd --- /dev/null +++ b/tos/chips/m16c62p/timer/M16c62pTimerAInitC.nc @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Initialize an M16c/62p TimerA to a particular mode. Expected to be + * used at boot time. + * @param mode The desired mode of the timer. + * @param count_src Count source if applicable. + * + * @author Henrik Makitaavola + */ + +#include "M16c62pTimer.h" + +generic module M16c62pTimerAInitC(uint8_t mode, + uint8_t count_src, + uint16_t reload, + bool enable_interrupt, + bool start, + bool allow_stop_mode) +{ + provides interface Init @atleastonce(); + uses interface HplM16c62pTimerACtrl as TimerCtrl; + uses interface HplM16c62pTimer as Timer; +} +implementation +{ + command error_t Init.init() + { + st_timer timer = {0}; + sta_counter counter = {0}; + sta_one_shot one_shot = {0}; + + atomic + { + call Timer.allowStopMode(allow_stop_mode); + if (mode == TMR_TIMER_MODE) + { + timer.gate_func = M16C_TMR_TMR_GF_NO_GATE; + timer.count_src = count_src; + + call TimerCtrl.setTimerMode(timer); + call Timer.set(reload); + } + else if (mode == TMR_COUNTER_MODE) + { + // 'tmp' only used for avoiding "large integer + // implicitly truncated to unsigned type" warning + counter.event_source = count_src; + + call TimerCtrl.setCounterMode(counter); + call Timer.set(reload); + } + else if (mode == TMR_ONE_SHOT_MODE) + { + one_shot.trigger = M16C_TMRA_OS_T_TAiOS; + one_shot.count_src = count_src; + call TimerCtrl.setOneShotMode(one_shot); + } + if (enable_interrupt) + { + call Timer.enableInterrupt(); + } + if (start) + { + call Timer.on(); + } + + } + return SUCCESS; + } + + async event void Timer.fired() {} +} diff --git a/tos/chips/m16c62p/timer/M16c62pTimerBInitC.nc b/tos/chips/m16c62p/timer/M16c62pTimerBInitC.nc new file mode 100755 index 00000000..ccd606b8 --- /dev/null +++ b/tos/chips/m16c62p/timer/M16c62pTimerBInitC.nc @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Initialize an M16c/62p TimerB to a particular mode. Expected to be + * used at boot time. + * @param mode The desired mode of the timer. + * @param count_src Count source if applicable. + * + * @author Henrik Makitaavola + */ +generic module M16c62pTimerBInitC(uint8_t mode, + uint8_t count_src, + uint16_t reload, + bool enable_interrupt, + bool start, + bool allow_stop_mode) +{ + provides interface Init @atleastonce(); + uses interface HplM16c62pTimerBCtrl as TimerCtrl; + uses interface HplM16c62pTimer as Timer; +} +implementation +{ + command error_t Init.init() + { + uint8_t tmp; + error_t ret = SUCCESS; + st_timer timer = {0}; + stb_counter counter = {0}; + + atomic + { + call Timer.allowStopMode(allow_stop_mode); + if (mode == TMR_TIMER_MODE) + { + timer.gate_func = M16C_TMR_TMR_GF_NO_GATE; + timer.count_src = count_src; + + call TimerCtrl.setTimerMode(timer); + call Timer.set(reload); + } + else if (mode == TMR_COUNTER_MODE) + { + // 'tmp' only used for avoiding "large integer + // implicitly truncated to unsigned type" warning + tmp = count_src & 1; + counter.event_source = tmp; + + call TimerCtrl.setCounterMode(counter); + call Timer.set(reload); + } + else + { + ret = FAIL; + } + if (enable_interrupt) + { + call Timer.enableInterrupt(); + } + if (start) + { + call Timer.on(); + } + } + return ret; + } + + async event void Timer.fired() {} +} diff --git a/tos/chips/m16c62p/uart/HplM16c62pUart.nc b/tos/chips/m16c62p/uart/HplM16c62pUart.nc new file mode 100755 index 00000000..40d9b0d1 --- /dev/null +++ b/tos/chips/m16c62p/uart/HplM16c62pUart.nc @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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 + */ + +/** + * HPL interface for a M16c/62p uart. + * + * @author Henrik Makitaavola + * @author Alec Woo + * @author Jonathan Hui + */ +interface HplM16c62pUart { + + async command error_t enableTxInterrupt(); + async command error_t disableTxInterrupt(); + async command error_t enableRxInterrupt(); + async command error_t disableRxInterrupt(); + async command bool isTxEmpty(); + async command bool isRxEmpty(); + async command void tx( uint8_t data ); + async event void txDone(); + async command uint8_t rx(); + async event void rxDone( uint8_t data ); + +} diff --git a/tos/chips/m16c62p/uart/HplM16c62pUartC.nc b/tos/chips/m16c62p/uart/HplM16c62pUartC.nc new file mode 100755 index 00000000..9e060670 --- /dev/null +++ b/tos/chips/m16c62p/uart/HplM16c62pUartC.nc @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + * @author Martin Turon + * @author David Gay + */ + +/** + * The M16c/62p uart ports. + * + * @author Henrik Makitaavola + */ +configuration HplM16c62pUartC +{ + provides + { + interface StdControl as Uart0TxControl; + interface StdControl as Uart0RxControl; + interface HplM16c62pUart as HplUart0; + + interface StdControl as Uart1TxControl; + interface StdControl as Uart1RxControl; + interface HplM16c62pUart as HplUart1; + + interface StdControl as Uart2TxControl; + interface StdControl as Uart2RxControl; + interface HplM16c62pUart as HplUart2; + } +} +implementation +{ + components + HplM16c62pGeneralIOC as IOs, + HplM16c62pUartInterruptP as Irqs, + new HplM16c62pUartP(0, + (uint16_t)&U0TB.BYTE.U0TBL, + (uint16_t)&U0RB.BYTE.U0RBL, + (uint16_t)&U0BRG, + (uint16_t)&U0MR.BYTE, + (uint16_t)&U0C0.BYTE, + (uint16_t)&U0C1.BYTE, + (uint16_t)&S0TIC.BYTE, + (uint16_t)&S0RIC.BYTE) as HplUart0P, + new HplM16c62pUartP(1, + (uint16_t)&U1TB.BYTE.U1TBL, + (uint16_t)&U1RB.BYTE.U1RBL, + (uint16_t)&U1BRG, + (uint16_t)&U1MR.BYTE, + (uint16_t)&U1C0.BYTE, + (uint16_t)&U1C1.BYTE, + (uint16_t)&S1TIC.BYTE, + (uint16_t)&S1RIC.BYTE) as HplUart1P, + new HplM16c62pUartP(2, + (uint16_t)&U2TB.BYTE.U2TBL, + (uint16_t)&U2RB.BYTE.U2RBL, + (uint16_t)&U2BRG, + (uint16_t)&U2MR.BYTE, + (uint16_t)&U2C0.BYTE, + (uint16_t)&U2C1.BYTE, + (uint16_t)&S2TIC.BYTE, + (uint16_t)&S2RIC.BYTE) as HplUart2P; + + components new StopModeControlC() as Uart0StopModeControl, + new StopModeControlC() as Uart1StopModeControl, + new StopModeControlC() as Uart2StopModeControl; + + Uart0TxControl = HplUart0P.UartTxControl; + Uart0RxControl = HplUart0P.UartRxControl; + HplUart0 = HplUart0P.HplUart; + HplUart0P.TxIO -> IOs.PortP63; + HplUart0P.RxIO -> IOs.PortP62; + HplUart0P.Irq -> Irqs.Uart0; + HplUart0P.StopModeControl -> Uart0StopModeControl; + + Uart1TxControl = HplUart1P.UartTxControl; + Uart1RxControl = HplUart1P.UartRxControl; + HplUart1 = HplUart1P.HplUart; + HplUart1P.TxIO -> IOs.PortP67; + HplUart1P.RxIO -> IOs.PortP66; + HplUart1P.Irq -> Irqs.Uart1; + HplUart1P.StopModeControl -> Uart1StopModeControl; + + Uart2TxControl = HplUart2P.UartTxControl; + Uart2RxControl = HplUart2P.UartRxControl; + HplUart2 = HplUart2P.HplUart; + HplUart2P.TxIO -> IOs.PortP70; + HplUart2P.RxIO -> IOs.PortP71; + HplUart2P.Irq -> Irqs.Uart2; + HplUart2P.StopModeControl -> Uart2StopModeControl; + + components MainC; + MainC.SoftwareInit -> HplUart0P.UartInit; + MainC.SoftwareInit -> HplUart1P.UartInit; + MainC.SoftwareInit -> HplUart2P.UartInit; + +} diff --git a/tos/chips/m16c62p/uart/HplM16c62pUartInterrupt.nc b/tos/chips/m16c62p/uart/HplM16c62pUartInterrupt.nc new file mode 100755 index 00000000..44206f5b --- /dev/null +++ b/tos/chips/m16c62p/uart/HplM16c62pUartInterrupt.nc @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 interrupt signals from a uart. + * + * @author Henrik Makitaavola + */ +interface HplM16c62pUartInterrupt +{ + /** + * Signal when an tx interrupt occurs. + */ + async event void tx(); + + /** + * Signal when an rx interrupt occurs. + */ + async event void rx(); +} + diff --git a/tos/chips/m16c62p/uart/HplM16c62pUartInterruptP.nc b/tos/chips/m16c62p/uart/HplM16c62pUartInterruptP.nc new file mode 100755 index 00000000..64fad636 --- /dev/null +++ b/tos/chips/m16c62p/uart/HplM16c62pUartInterruptP.nc @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * All uart interrupt vector handlers. + * These are wired in HplM16c62pUartC. + * + * @author Henrik Makitaavola + */ + +module HplM16c62pUartInterruptP +{ + provides interface HplM16c62pUartInterrupt as Uart0; + provides interface HplM16c62pUartInterrupt as Uart1; + provides interface HplM16c62pUartInterrupt as Uart2; +} +implementation +{ + default async event void Uart0.tx() { } + M16C_INTERRUPT_HANDLER(M16C_UART0_NACK) + { + signal Uart0.tx(); + } + + default async event void Uart0.rx() { } + M16C_INTERRUPT_HANDLER(M16C_UART0_ACK) + { + signal Uart0.rx(); + } + + + default async event void Uart1.tx() { } + M16C_INTERRUPT_HANDLER(M16C_UART1_NACK) + { + signal Uart1.tx(); + } + + default async event void Uart1.rx() { } + M16C_INTERRUPT_HANDLER(M16C_UART1_ACK) + { + signal Uart1.rx(); + } + + + default async event void Uart2.tx() { } + M16C_INTERRUPT_HANDLER(M16C_UART2_NACK) + { + signal Uart2.tx(); + } + + default async event void Uart2.rx() { } + M16C_INTERRUPT_HANDLER(M16C_UART2_ACK) + { + signal Uart2.rx(); + } +} diff --git a/tos/chips/m16c62p/uart/HplM16c62pUartP.nc b/tos/chips/m16c62p/uart/HplM16c62pUartP.nc new file mode 100755 index 00000000..77447c9d --- /dev/null +++ b/tos/chips/m16c62p/uart/HplM16c62pUartP.nc @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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 + * @author Jonathan Hui + */ + +/* + * 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. + */ +/** + * @author Martin Turon + * @author David Gay + */ + + +/** + * Generic HPL module for a Uart port on the M16c/62p MCU. + * + * @author Henrik Makitaavola + */ +generic module HplM16c62pUartP(uint8_t uartNr, + uint16_t tx_addr, + uint16_t rx_addr, + uint16_t brg_addr, + uint16_t mode_addr, + uint16_t ctrl0_addr, + uint16_t ctrl1_addr, + uint16_t txInterrupt_addr, + uint16_t rxInterrupt_addr) +{ + provides interface Init as UartInit; + provides interface StdControl as UartTxControl; + provides interface StdControl as UartRxControl; + provides interface HplM16c62pUart as HplUart; + + uses interface GeneralIO as TxIO; + uses interface GeneralIO as RxIO; + uses interface HplM16c62pUartInterrupt as Irq; + uses interface StopModeControl; + +} +implementation +{ +#define txBuf (*TCAST(volatile uint8_t* ONE, tx_addr)) +#define rxBuf (*TCAST(volatile uint8_t* ONE, rx_addr)) +#define txInterrupt (*TCAST(volatile uint8_t* ONE, txInterrupt_addr)) +#define rxInterrupt (*TCAST(volatile uint8_t* ONE, rxInterrupt_addr)) +#define brg (*TCAST(volatile uint8_t* ONE, brg_addr)) +#define mode (*TCAST(volatile uint8_t* ONE, mode_addr)) +#define ctrl0 (*TCAST(volatile uint8_t* ONE, ctrl0_addr)) +#define ctrl1 (*TCAST(volatile uint8_t* ONE, ctrl1_addr)) + + command error_t UartInit.init() + { + // Divide the mainclock get baudrate. + brg = (uint8_t)(((MAIN_CRYSTAL_SPEED * 1000000.0 / (16.0 * 57600.0))+ 0.5) - 1.0); + mode = BIT0 | BIT2; // Set 8 bit transfer length, 1 stop bit, no parity. + ctrl0 = BIT4; // set f1, no cts/rts. + + return SUCCESS; + } + + command error_t UartTxControl.start() + { + call TxIO.makeOutput(); + SET_BIT(ctrl1, 0); + call StopModeControl.allowStopMode(false); + return SUCCESS; + } + + command error_t UartTxControl.stop() + { + call TxIO.makeInput(); + CLR_BIT(ctrl1, 0); + call StopModeControl.allowStopMode(true); + return SUCCESS; + } + + command error_t UartRxControl.start() + { + SET_BIT(ctrl1, 2); + return SUCCESS; + } + + command error_t UartRxControl.stop() + { + CLR_BIT(ctrl1, 2); + return SUCCESS; + } + + async command error_t HplUart.enableTxInterrupt() + { + atomic + { + clear_interrupt(txInterrupt_addr); + SET_BIT(ctrl1, 1); + CLR_BIT(UCON.BYTE, uartNr); + SET_BIT(txInterrupt, 0); + } + return SUCCESS; + } + + async command error_t HplUart.disableTxInterrupt() + { + CLR_BIT(txInterrupt, 0); + return SUCCESS; + } + + async command error_t HplUart.enableRxInterrupt() + { + atomic + { + clear_interrupt(rxInterrupt_addr); + SET_BIT(rxInterrupt, 0); + } + return SUCCESS; + } + + async command error_t HplUart.disableRxInterrupt() + { + CLR_BIT(rxInterrupt, 0); + return SUCCESS; + } + + async command bool HplUart.isTxEmpty() + { + return READ_BIT(ctrl1, 1); + } + + async command bool HplUart.isRxEmpty() + { + return !READ_BIT(ctrl1, 3); + } + + async command uint8_t HplUart.rx() + { + return rxBuf; + } + + async command void HplUart.tx(uint8_t data) + { + txBuf = data; + } + + async event void Irq.rx() + { + if (!call HplUart.isRxEmpty()) { + signal HplUart.rxDone(call HplUart.rx()); + } + } + + async event void Irq.tx() + { + signal HplUart.txDone(); + } + + default async event void HplUart.txDone() {} + default async event void HplUart.rxDone(uint8_t data) {} +} diff --git a/tos/chips/m16c62p/uart/M16c62pUartC.nc b/tos/chips/m16c62p/uart/M16c62pUartC.nc new file mode 100755 index 00000000..40013d62 --- /dev/null +++ b/tos/chips/m16c62p/uart/M16c62pUartC.nc @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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 + * @author Jonathan Hui + */ + +/** + * HAL of the M16c/62p uarts. + * + * @author Henrik Makitaavola + */ +configuration M16c62pUartC +{ + provides interface StdControl as StdControl0; + provides interface UartByte as Uart0Byte; + provides interface UartStream as Uart0Stream; + + provides interface StdControl as StdControl1; + provides interface UartByte as Uart1Byte; + provides interface UartStream as Uart1Stream; + + provides interface StdControl as StdControl2; + provides interface UartByte as Uart2Byte; + provides interface UartStream as Uart2Stream; + + uses interface Counter; +} + +implementation +{ + components HplM16c62pUartC as HplUartC; + + components new M16c62pUartP() as Uart0P; + StdControl0 = Uart0P; + Uart0Byte = Uart0P; + Uart0Stream = Uart0P; + Uart0P.Counter = Counter; + + Uart0P.HplUartTxControl -> HplUartC.Uart0TxControl; + Uart0P.HplUartRxControl -> HplUartC.Uart0RxControl; + Uart0P.HplUart -> HplUartC.HplUart0; + + components new M16c62pUartP() as Uart1P; + StdControl1 = Uart1P; + Uart1Byte = Uart1P; + Uart1Stream = Uart1P; + Uart1P.Counter = Counter; + + Uart1P.HplUartTxControl -> HplUartC.Uart1TxControl; + Uart1P.HplUartRxControl -> HplUartC.Uart1RxControl; + Uart1P.HplUart -> HplUartC.HplUart1; + + components new M16c62pUartP() as Uart2P; + StdControl2 = Uart2P; + Uart2Byte = Uart2P; + Uart2Stream = Uart2P; + Uart2P.Counter = Counter; + + Uart2P.HplUartTxControl -> HplUartC.Uart2TxControl; + Uart2P.HplUartRxControl -> HplUartC.Uart2RxControl; + Uart2P.HplUart -> HplUartC.HplUart2; + + + components MainC; + MainC.SoftwareInit -> Uart0P; + MainC.SoftwareInit -> Uart1P; + MainC.SoftwareInit -> Uart2P; +} diff --git a/tos/chips/m16c62p/uart/M16c62pUartP.nc b/tos/chips/m16c62p/uart/M16c62pUartP.nc new file mode 100755 index 00000000..e966d6a5 --- /dev/null +++ b/tos/chips/m16c62p/uart/M16c62pUartP.nc @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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 + * + */ + +/** + * Generic HAL uart for M16c/62p. + * + * @author Henrik Makitaavola + * @author Alec Woo + * @author Jonathan Hui + * @author Philip Levis + */ + +#include + +generic module M16c62pUartP() +{ + provides interface Init; + provides interface StdControl; + provides interface UartByte; + provides interface UartStream; + + uses interface StdControl as HplUartTxControl; + uses interface StdControl as HplUartRxControl; + uses interface HplM16c62pUart as HplUart; + uses interface Counter; + +} +implementation +{ + + norace uint16_t m_tx_len, m_rx_len; + norace uint8_t *m_tx_buf, *m_rx_buf; + norace uint16_t m_tx_pos, m_rx_pos; + norace uint16_t m_byte_time; + norace uint8_t m_rx_intr; + norace uint8_t m_tx_intr; + + command error_t Init.init() + { + // TODO(henrik) fix this for the different uarts. + /*if (PLATFORM_BAUDRATE == 19200UL) + m_byte_time = 200; // 1 TMicor ~= 2.12 us, one byte = 417us ~= 200 + else if (PLATFORM_BAUDRATE == 57600UL) + m_byte_time = 68; // 1 TMicor ~= 2.12 us, one byte = 138us ~= 65*/ + m_byte_time = 68; + return SUCCESS; + } + + command error_t StdControl.start() + { + /* make sure interrupts are off and set flags */ + call HplUart.disableTxInterrupt(); + call HplUart.disableRxInterrupt(); + m_rx_intr = 0; + m_tx_intr = 0; + + /* enable tx/rx */ + call HplUartTxControl.start(); + call HplUartRxControl.start(); + + // Bug fix: pal 11/26/07: RX interrupts should be enabled on start + call HplUart.enableRxInterrupt(); + return SUCCESS; + } + + command error_t StdControl.stop() + { + call HplUartTxControl.stop(); + call HplUartRxControl.stop(); + return SUCCESS; + } + + async command error_t UartStream.enableReceiveInterrupt() + { + atomic + { + m_rx_intr = 3; + call HplUart.enableRxInterrupt(); + } + return SUCCESS; + } + + async command error_t UartStream.disableReceiveInterrupt() + { + atomic + { + call HplUart.disableRxInterrupt(); + m_rx_intr = 0; + } + return SUCCESS; + } + + async command error_t UartStream.receive( uint8_t* buf, uint16_t len ) + { + + if ( len == 0 ) + return FAIL; + atomic + { + if ( m_rx_buf ) + return EBUSY; + m_rx_buf = buf; + m_rx_len = len; + m_rx_pos = 0; + m_rx_intr |= 1; + call HplUart.enableRxInterrupt(); + } + + return SUCCESS; + + } + + async event void HplUart.rxDone( uint8_t data ) + { + + if ( m_rx_buf ) + { + m_rx_buf[ m_rx_pos++ ] = data; + if ( m_rx_pos >= m_rx_len ) + { + uint8_t* buf = m_rx_buf; + atomic + { + m_rx_buf = NULL; + if(m_rx_intr != 3) + { + call HplUart.disableRxInterrupt(); + m_rx_intr = 0; + } + } + signal UartStream.receiveDone( buf, m_rx_len, SUCCESS ); + } + } + else + { + signal UartStream.receivedByte( data ); + } + } + + async command error_t UartStream.send( uint8_t *buf, uint16_t len) + { + + if ( len == 0 ) + return FAIL; + else if ( m_tx_buf ) + return EBUSY; + + m_tx_len = len; + m_tx_buf = buf; + m_tx_pos = 0; + m_tx_intr = 1; + call HplUart.enableTxInterrupt(); + call HplUart.tx( buf[ m_tx_pos++ ] ); + + return SUCCESS; + + } + + async event void HplUart.txDone() + { + + if ( m_tx_pos < m_tx_len ) + { + call HplUart.tx( m_tx_buf[ m_tx_pos++ ] ); + } + else + { + uint8_t* buf = m_tx_buf; + m_tx_buf = NULL; + m_tx_intr = 0; + call HplUart.disableTxInterrupt(); + signal UartStream.sendDone( buf, m_tx_len, SUCCESS ); + } + + } + + async command error_t UartByte.send( uint8_t byte ) + { + if(m_tx_intr) + return FAIL; + + call HplUart.tx( byte ); + while ( !call HplUart.isTxEmpty() ); + return SUCCESS; + } + + async command error_t UartByte.receive( uint8_t * byte, uint8_t timeout) + { + + uint16_t timeout_micro = m_byte_time * timeout + 1; + uint16_t start; + + if(m_rx_intr) + return FAIL; + + start = call Counter.get(); + while ( call HplUart.isRxEmpty() ) + { + if ( ( (uint16_t)call Counter.get() - start ) >= timeout_micro ) + return FAIL; + } + *byte = call HplUart.rx(); + + return SUCCESS; + + } + + async event void Counter.overflow() {} + + default async event void UartStream.sendDone( uint8_t* buf, uint16_t len, error_t error ){} + default async event void UartStream.receivedByte( uint8_t byte ){} + default async event void UartStream.receiveDone( uint8_t* buf, uint16_t len, error_t error ){} + +} diff --git a/tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlash.nc b/tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlash.nc new file mode 100644 index 00000000..df011b8b --- /dev/null +++ b/tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlash.nc @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 to access the program flash of the M16c/62p mcu. + * + * @author Henrik Makitaavola + */ +interface HplM16c62pFlash +{ + /** + * Erases a block in the program flash. + * + * @param block The block that should be erased. + * @return False if the erase failed. + */ + command bool FlashRead(unsigned long flash_addr_in); + + /** + * Writes bytes into the program flash. + * + * @param flash_addr The program flash address where the write should begin. This MUST be an EVEN address. + * @param buffer_addr The bytes that should be written to the address. + * @param bytes The number of bytes that should be written. This MUST be an EVEN number. + * @return 1 if the flash control register reported an error. 2 if the parameters that where passed contained an error. + */ + command uint8_t FlashErase(unsigned char block); + + /** + * Reads the byte at am address using a LDE instruction. + * + * @param address The address that a byte should be read from. + * @return Byte read. + */ + command uint8_t FlashWrite(unsigned long flash_addr_in, + unsigned int* buffer_addr, + unsigned int bytes); +} \ No newline at end of file diff --git a/tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlashC.nc b/tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlashC.nc new file mode 100644 index 00000000..49d6ffd5 --- /dev/null +++ b/tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlashC.nc @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +#include "M16c62pFlash.h" +#include "iom16c62p.h" + +/** + * Implementation of the HplM16c62pFlash interface. Note that this module + * should be used with caution so that one doesn't erase the flash where the + * executing program lies. + * + * @author Henrik Makitaavola + * @author Renesas + */ +// TODO(henrik) This implementation expects a main clock speed <=10 MHz, fix it. +module HplM16c62pFlashC +{ + provides interface HplM16c62pFlash; +} +implementation +{ + +// Defines an array of highest even addresses for each block +const unsigned long block_addresses[14] = + {0xFFFFE,0xFEFFE,0xFDFFE,0xFBFFE,0xF9FFE,0xF7FFE,0xEFFFE,0xDFFFE,0xCFFFE, + 0xBFFFE,0xAFFFE,0x9FFFE,0x8FFFE,0xFFFE }; + +unsigned char cm0_saved; // For saving the Clock Mode 0 register +unsigned char cm1_saved; // For saving the Clock Mode 1 register +unsigned char pm0_saved; // For saving the Processor Mode 0 register +unsigned char pm1_saved; // For saving the Processor Mode 1 register +unsigned char prcr_saved; // Save Protection register + +/** + * Sets the processor mode for programming flash and saves current + * settings to restore later. You cannot run the processor faster + * than 10.0 MHz (with wait state) or 6.25MHz (without wait state) + * when sending commands to the flash controller. + */ +void SlowMCUClock(void) +{ + // Unprotect registers CM0 and CM1 and PM0 registers by writting to protection register + prcr_saved = *((char *)0xA); // Save Protection register + *((char *)0xA) = 3; // Allow writting to protected system registers + // Force to Single chip mode for processors that have memory expansion mode + pm0_saved = *((char *)0x4); // Save pm0 register + *((char *)0x4) = pm0_saved & 0xFC; // bit 0 and 1 to zero + + cm0_saved = *((char *)0x6); // Save cm0 register + cm1_saved = *((char *)0x7); // Save cm1 register + pm1_saved = *((char *)0x5); // Save pm1 register + + // Insert Wait state for all bus access (needed for talking to the + // internal flash controller) + asm("BSET 7,0x05"); // Set bit PM17 + CM0.BYTE = 0; + CM1.BYTE = 0; +} + +/** + * Restores the processor mode back to original settings. + */ +void RestoreMCUClock(void) +{ + *((char *)0x4) = pm0_saved; // Restore pm0 register + + /* Clock settings for R8C and M16C */ + *((char *)0x7) = cm1_saved; // Restore cm1 register + *((char *)0x6) = cm0_saved; // Restore cm0 register + *((char *)0x5) = pm1_saved; // Restore pm1 register + *((char *)0xA) = prcr_saved; // Protection back on +} + +command bool HplM16c62pFlash.FlashErase( unsigned char block ) +{ + unsigned int low = (unsigned int) block_addresses[ block ]; + unsigned int high = (unsigned int)( block_addresses[ block ] >> 16); + + // Must change main clock speed to meet flash requirements + SlowMCUClock(); + FMR0.BIT.FMR01 = 0; + FMR0.BIT.FMR01 = 1; + FMR1.BIT.FMR11 = 0; + FMR1.BIT.FMR11 = 1; + + asm volatile ("mov.w %[low], a0\n\t" + "mov.w %[high], a1\n\t" + + "mov.w #0x0050, r0\n\t" + "ste.w r0, [a1a0]\n\t" + + "mov.w #0x0020, r0\n\t" + "ste.w r0, [a1a0]\n\t" + + "mov.w #0x00D0, r0\n\t" + "ste.w r0, [a1a0]\n\t" + : + :[low] "r" (low), [high] "r" (high) + : "memory", "r0", "a0", "a1"); + + // Note: In EW1 Mode, the MCU is suspended until the operation is completed. + while (!FMR0.BIT.FMR00); + // Disable CPU rewriting commands by clearing EW entry bit. + FMR0.BYTE = 0; + + RestoreMCUClock(); // Restore clock back to original speed + + if( FMR0.BIT.FMR07) // Erasing error? + { + return 1; // Erase Fail + } + + return 0; // Erase Pass +} + +command uint8_t HplM16c62pFlash.FlashWrite( unsigned long flash_addr, + unsigned int * buffer_addr, + unsigned int bytes) +{ + unsigned char ret_value = 0; + unsigned int low = (unsigned int) flash_addr; + unsigned int high = (unsigned int)( flash_addr >> 16); + unsigned int i; + // Check for odd number of bytes + if( bytes & 1) + return 2; // ERROR!! You must always pass an even number of bytes. + + // Check for odd address + if( (int)flash_addr & 1) + return 2; // ERROR!! You must always pass an even flash address + + // Must change main clock speed to meet flash requirements + SlowMCUClock(); + + FMR0.BIT.FMR01 = 0; + FMR0.BIT.FMR01 = 1; + FMR1.BIT.FMR11 = 0; + FMR1.BIT.FMR11 = 1; + + // Clear status register + asm volatile ("mov.w %[low], a0\n\t" + "mov.w %[high], a1\n\t" + + "mov.w #0x0050, r0\n\t" + "ste.w r0, [a1a0]\n\t" + : + :[low] "r" (low), [high] "r" (high) + : "memory", "r0", "a1", "a0"); + + for (i = 0; i < (bytes >> 1); ++i) + { + // Write to the flash sequencer by writing to that area of flash memory + asm volatile ( + "mov.w %[low], a0\n\t" + "mov.w %[high], a1\n\t" + + "mov.w #0x0040, r0\n\t" // Send write command + "ste.w r0, [a1a0]\n\t" + + "mov.w %[data], r0\n\t" // Write data + "ste.w r0, [a1a0]\n\t" + : + :[low] "r" (low), [high] "r" (high), [data] "r" (*buffer_addr) + : "memory", "r0", "a1", "a0"); + + // Note: In EW1 Mode, the MCU is suspended until the operation completed + + // Read flash program status flag + if( FMR0.BIT.FMR06 ) // Write error? + { + ret_value = 1; // Signal that we had got an error + break; // Break out of while loop + } + + flash_addr += 2; // Advance to next flash write address + buffer_addr++; // Advance to next data buffer address + low = (unsigned int) flash_addr; + high = (unsigned int)( flash_addr >> 16); + } + + asm volatile ("mov.w %[low], a0\n\t" + "mov.w %[high], a1\n\t" + "ste.w 0x00FF, [a1a0]\n\t" + : + :[low] "r" (low), [high] "r" (high) + : "memory", "a0", "a1"); + + // Disable CPU rewriting commands by clearing EW entry bit + FMR0.BYTE = 0; + RestoreMCUClock(); // Restore clock back to original speed + + return ret_value; // Return Pass/Fail +} + +command uint8_t HplM16c62pFlash.FlashRead(unsigned long address) { + unsigned int low = (unsigned int)(address); + unsigned int high = (unsigned int)(address >> 16); + unsigned int data; + asm volatile ("mov.w %[low], a0\n\t" + "mov.w %[high], a1\n\t" + "ste.w 0x00FF, [a1a0]\n\t" + "lde.w [a1a0], %[data]" + :[data] "=r" (data) + :[low] "r" (low), [high] "r" (high) + : "memory", "a0", "a1"); + return data; +} +} \ No newline at end of file diff --git a/tos/lib/net/Deluge/extra/m16c62p/InternalFlashC.nc b/tos/lib/net/Deluge/extra/m16c62p/InternalFlashC.nc new file mode 100644 index 00000000..5b14bb09 --- /dev/null +++ b/tos/lib/net/Deluge/extra/m16c62p/InternalFlashC.nc @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Wiring so that the M16c/62p InternalFlashP module gets access to the + * HplM16c62pFlashC module. + * + * @author Henrik Makitaavola + */ +configuration InternalFlashC +{ + provides interface InternalFlash; +} +implementation +{ + components HplM16c62pFlashC, InternalFlashP; + InternalFlashP.Flash -> HplM16c62pFlashC; + InternalFlash = InternalFlashP; +} \ No newline at end of file diff --git a/tos/lib/net/Deluge/extra/m16c62p/InternalFlashP.nc b/tos/lib/net/Deluge/extra/m16c62p/InternalFlashP.nc new file mode 100644 index 00000000..5c73e54b --- /dev/null +++ b/tos/lib/net/Deluge/extra/m16c62p/InternalFlashP.nc @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +#include "M16c62pFlash.h" + +/** + * Implementation of the InternalFlash interface for the + * M16c/62p mcu. Currently flash block 5 is used for the + * internal flash and is hard coded. + * + * @author Henrik Makitaavola + */ +// TODO(henrik) Fix the hard coded value of the flash block. +module InternalFlashP { + provides interface InternalFlash; + + uses interface HplM16c62pFlash as Flash; +} + +implementation { + +#define INTERNAL_ADDRESS 0xF0000L +#define INTERNAL_BLOCK BLOCK_5 + + command error_t InternalFlash.write(void* addr, void* buf, uint16_t size) { + // TODO(henrik) Make this more sain by making use of the whole block before + // erasing the whole block. + if (call Flash.FlashErase(INTERNAL_BLOCK) != 0) + { + return FAIL; + } + if (call Flash.FlashWrite(INTERNAL_ADDRESS, (unsigned int*)buf, size) != 0) + { + return FAIL; + } + return SUCCESS; + } + + command error_t InternalFlash.read(void* addr, void* buf, uint16_t size) { + unsigned long address = INTERNAL_ADDRESS; + uint16_t i; + uint8_t* buffer = (uint8_t*)buf; + + for (i = 0; i < size; ++i, ++address) + { + buffer[i] = call Flash.FlashRead(address); + } + return SUCCESS; + } +} diff --git a/tos/lib/net/Deluge/extra/m16c62p/M16c62pFlash.h b/tos/lib/net/Deluge/extra/m16c62p/M16c62pFlash.h new file mode 100644 index 00000000..7b372149 --- /dev/null +++ b/tos/lib/net/Deluge/extra/m16c62p/M16c62pFlash.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Defines for the program flash blocks. + * + * @author Henrik Makitaavola + * @author Renesas + */ + +#ifndef __M16C62PFLASH_H__ +#define __M16C62PFLASH_H__ + +// User Block Area +#define BLOCK_0 0 // 4KB: FF000 - FFFFF +#define BLOCK_1 1 // 4KB: FE000 - FEFFF +#define BLOCK_2 2 // 8KB: FC000 - FDFFF +#define BLOCK_3 3 // 8KB: FA000 - FBFFF +#define BLOCK_4 4 // 8KB: F8000 - F9FFF +#define BLOCK_5 5 // 32KB: F0000 - F7FFF +#define BLOCK_6 6 // 64KB: E0000 - EFFFF +#define BLOCK_7 7 // 64KB: D0000 - DFFFF +#define BLOCK_8 8 // 64KB: C0000 - CFFFF +#define BLOCK_9 9 // 64KB: B0000 - BFFFF +#define BLOCK_10 10 // 64KB: A0000 - AFFFF +#define BLOCK_11 11 // 64KB: 90000 - 9FFFF +#define BLOCK_12 12 // 64KB: 80000 - 8FFFF + +// Data Block Area +#define BLOCK_A 13 // 4KB: F000 - FFFF + +#endif // __M16C62PFLASH_H__ \ No newline at end of file diff --git a/tos/lib/net/Deluge/extra/mulle/NetProg_platform.h b/tos/lib/net/Deluge/extra/mulle/NetProg_platform.h new file mode 100644 index 00000000..8081215b --- /dev/null +++ b/tos/lib/net/Deluge/extra/mulle/NetProg_platform.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 contains the netprog_reboot function that + * reboots the mcu. + * + * @author Henrik Makitaavola + */ + +#ifndef __NETPROG_PLATFORM_H__ +#define __NETPROG_PLATFORM_H__ + +void netprog_reboot() { + PRCR.BIT.PRC0 = 1; // Turn off protection on CM registers. + PRCR.BIT.PRC1 = 1; // Turn off protection on PM registers. + CM0.BIT.CM0_6 = 1; + PM1.BIT.PM1_2 = 1; // Reset on WDT underflow. + WDTS = 1; // Start watchdog timer. + PRCR.BIT.PRC0 = 0; // Turn on protection on CM registers. + PRCR.BIT.PRC1 = 0; // Turn on protection on PM registers. + while (1); // Wait for underflow in the watchdog timer. +} + +#endif // __NETPROG_PLATFORM_H__ diff --git a/tos/lib/net/Deluge/extra/mulle/ReprogramGuardC.nc b/tos/lib/net/Deluge/extra/mulle/ReprogramGuardC.nc new file mode 100644 index 00000000..943289d2 --- /dev/null +++ b/tos/lib/net/Deluge/extra/mulle/ReprogramGuardC.nc @@ -0,0 +1,11 @@ +configuration ReprogramGuardC +{ + provides interface ReprogramGuard; +} + +implementation +{ + components ReprogramGuardP; + + ReprogramGuard = ReprogramGuardP; +} diff --git a/tos/lib/net/Deluge/extra/mulle/ReprogramGuardP.nc b/tos/lib/net/Deluge/extra/mulle/ReprogramGuardP.nc new file mode 100644 index 00000000..b8064cb6 --- /dev/null +++ b/tos/lib/net/Deluge/extra/mulle/ReprogramGuardP.nc @@ -0,0 +1,22 @@ +// TODO(henrik) implement. + +module ReprogramGuardP +{ + provides interface ReprogramGuard; +} +implementation +{ + enum { + VTHRESH = 0x0, // 0V + }; + task void sendOk() + { + signal ReprogramGuard.okToProgramDone(true); + } + + command error_t ReprogramGuard.okToProgram() + { + post sendOk(); + return SUCCESS; + } +} diff --git a/tos/lib/net/Deluge/extra/mulle/TOSBoot_platform.h b/tos/lib/net/Deluge/extra/mulle/TOSBoot_platform.h new file mode 100644 index 00000000..ebeb735e --- /dev/null +++ b/tos/lib/net/Deluge/extra/mulle/TOSBoot_platform.h @@ -0,0 +1,15 @@ +/** + * @author Henrik Makitaavola + */ + +#ifndef __TOSBOOT_PLATFORM_H__ +#define __TOSBOOT_PLATFORM_H__ + +enum { + TOSBOOT_ARGS_ADDR = 0, // address of TOSBoot args in internal flash + TOSBOOT_GESTURE_MAX_COUNT = 3, // number of resets to force golden image + TOSBOOT_GOLDEN_IMG_ADDR = 0x0L, // address of the golden image in external flash + TOSBOOT_INT_PAGE_SIZE = 512L, // size of each internal program flash page. Each page is 64Kbytes but it is better to split it into 128 parts (65536/512=128). +}; + +#endif // __TOSBOOT_PLATFORM_H__ diff --git a/tos/lib/tosboot/m16c62p/HardwareC.nc b/tos/lib/tosboot/m16c62p/HardwareC.nc new file mode 100644 index 00000000..3fc4f2a1 --- /dev/null +++ b/tos/lib/tosboot/m16c62p/HardwareC.nc @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Hardware interface implementation for the M16c/62p MCU. + * The interface is responsible of initializing the mcu + * and rebooting it on request. + * + * @author Henrik Makitaavola + */ + +#include "NetProg_platform.h" + +module HardwareC +{ + provides interface Hardware; +} + +implementation +{ + command void Hardware.init() + { + PRCR.BYTE = BIT1 | BIT0; // Turn off protection for the cpu and clock register + + PM0.BYTE = BIT7; // Single Chip mode. No BCLK output. + PM1.BYTE = BIT3; // Expand internal memory, no global wait state. + + CM0.BYTE = 0x0; // No sub-clock (Xc) generation + CM1.BYTE = 0x0; // CPU_CLOCK = MAIN_CLOCK, low drive on Xin + + PRCR.BYTE = 0; // Turn on protection on all registers. + } + + + command void Hardware.reboot() + { + netprog_reboot(); + } +} diff --git a/tos/lib/tosboot/m16c62p/ProgFlashM.nc b/tos/lib/tosboot/m16c62p/ProgFlashM.nc new file mode 100644 index 00000000..64669891 --- /dev/null +++ b/tos/lib/tosboot/m16c62p/ProgFlashM.nc @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Wiring so that the ProgFlashP module gets access to the HplM16c62pFlashC + * module. + * + * @author Henrik Makitaavola + */ +configuration ProgFlashM +{ + provides interface ProgFlash; +} +implementation +{ + components ProgFlashP, HplM16c62pFlashC; + + ProgFlashP.Flash -> HplM16c62pFlashC; + ProgFlash = ProgFlashP; +} \ No newline at end of file diff --git a/tos/lib/tosboot/m16c62p/ProgFlashP.nc b/tos/lib/tosboot/m16c62p/ProgFlashP.nc new file mode 100644 index 00000000..6422f71e --- /dev/null +++ b/tos/lib/tosboot/m16c62p/ProgFlashP.nc @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Implementation of the ProgFlash interface for M16c/62p. + * The interface is responsible of reprogramming of the mcus + * program flash. + * + * @author Henrik Makitaavola + */ + +#include "M16c62pFlash.h" + +module ProgFlashP +{ + provides interface ProgFlash; + + uses interface HplM16c62pFlash as Flash; +} + +implementation +{ + + command error_t ProgFlash.write(in_flash_addr_t addr, uint8_t* buf, in_flash_addr_t len) + { + + // We dont need to rewrite the hw interrupt vector + if (addr >= 0xFFE00L) + { + return SUCCESS; + } + + if (addr + len >= TOSBOOT_START) + { + return FAIL; + } + + if (addr == 0xA0000L) + { + // Erase Block 10 + if (call Flash.FlashErase(BLOCK_10) != 0 ) + { + return FAIL; + } + } + else if ( addr == 0xB0000L ) + { + // Erase Block 9 + if (call Flash.FlashErase(BLOCK_9) != 0 ) + { + return FAIL; + } + } + else if ( addr == 0xC0000L ) + { + // Erase Block 8 + if (call Flash.FlashErase(BLOCK_8) != 0 ) + { + return FAIL; + } + } + else if ( addr == 0xD0000L ) + { + // Erase Block 7 + if (call Flash.FlashErase(BLOCK_7) != 0 ) + { + return FAIL; + } + } + + if (call Flash.FlashWrite(addr, (unsigned int*) buf, len) != 0) + { + return FAIL; + } + + return SUCCESS; + + } +} + diff --git a/tos/lib/tosboot/mulle/ExecC.nc b/tos/lib/tosboot/mulle/ExecC.nc new file mode 100644 index 00000000..cf5dd9b3 --- /dev/null +++ b/tos/lib/tosboot/mulle/ExecC.nc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Implementation of the Exec interface for the Mulle platform. + * The interface is responsible for starting the execution of + * the user program which is located with a starting address + * of 0xa0000 in the program flash. + * + * @author Henrik Makitaavola + */ + +#include "hardware.h" +module ExecC +{ + provides + { + interface Exec; + } +} + +implementation +{ + command void Exec.exec() + { + asm volatile ("jmp.a 0xa0000"); + } +} diff --git a/tos/lib/tosboot/mulle/PluginC.nc b/tos/lib/tosboot/mulle/PluginC.nc new file mode 100644 index 00000000..e7fc7cb3 --- /dev/null +++ b/tos/lib/tosboot/mulle/PluginC.nc @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * No extra plugins are required to be started for tosboot. + * + * @author Henrik Makitaavola + */ +module PluginC +{ + provides + { + interface StdControl; + } +} + +implementation +{ + command error_t StdControl.start() { return SUCCESS; } + command error_t StdControl.stop() { return SUCCESS; } +} diff --git a/tos/lib/tosboot/mulle/VoltageC.nc b/tos/lib/tosboot/mulle/VoltageC.nc new file mode 100644 index 00000000..e928bf5d --- /dev/null +++ b/tos/lib/tosboot/mulle/VoltageC.nc @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * VoltageC provides a implementation of the Voltage interface. + * + * @author Henrik Makitaavola + */ + +module VoltageC +{ + provides + { + interface Voltage; + } +} + +implementation +{ + command bool Voltage.okToProgram() + { + // TODO(henrik) Implement + return true; + } +} diff --git a/tos/lib/tosboot/mulle/hardware.h b/tos/lib/tosboot/mulle/hardware.h new file mode 100644 index 00000000..3821fc16 --- /dev/null +++ b/tos/lib/tosboot/mulle/hardware.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 Henrik Makitaavola + */ + +#ifndef __HARDWARE_H__ +#define __HARDWARE_H__ + +#include +#include + +typedef uint32_t in_flash_addr_t; +typedef uint32_t ex_flash_addr_t; + +static inline void wait( uint16_t dt ) { + uint16_t i; + for (i = 0; i < dt; ++i) { + TOSH_wait(); + } +} + +// LED assignments +TOSH_ASSIGN_PIN(RED_LED, 3, 6); +TOSH_ASSIGN_PIN(GREEN_LED, 3, 7); +TOSH_ASSIGN_PIN(YELLOW_LED, 3, 4); + +// Flash assignments +TOSH_ASSIGN_PIN(FLASH_IN, 4, 0); +TOSH_ASSIGN_PIN(FLASH_OUT, 4, 1); +TOSH_ASSIGN_PIN(FLASH_CLK, 4, 2); +TOSH_ASSIGN_PIN(FLASH_CS, 4, 5); +TOSH_ASSIGN_PIN(FLASH_VCC, 3, 2); + +void TOSH_SET_PIN_DIRECTIONS(void) +{ + TOSH_MAKE_RED_LED_OUTPUT(); + TOSH_MAKE_YELLOW_LED_OUTPUT(); + TOSH_MAKE_GREEN_LED_OUTPUT(); + + TOSH_MAKE_FLASH_VCC_OUTPUT(); + TOSH_CLR_FLASH_VCC_PIN(); +} + +// TODO(henrik) Insert correct value +enum { + VTHRESH = 0x0, // 0V +}; + +#endif // __HARDWARE_H__ + + + + diff --git a/tos/lib/tosboot/mulle/m16chardware.h b/tos/lib/tosboot/mulle/m16chardware.h new file mode 100644 index 00000000..656ba8f5 --- /dev/null +++ b/tos/lib/tosboot/mulle/m16chardware.h @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + */ + + +/** + * @author Henrik Makitaavola + * @author Jason Hill + * @author Philip Levis + * @author Nelson Lee + */ + +#ifndef __M16CHARDWARE_H__ +#define __M16CHARDWARE_H__ + +#define sbi(port, bit) SET_BIT(port, bit) +#define cbi(port, bit) CLR_BIT(port, bit) + +#define TOSH_ASSIGN_PIN(name, port, bit) \ +static inline void TOSH_SET_##name##_PIN() {sbi(P##port.BYTE , bit);} \ +static inline void TOSH_CLR_##name##_PIN() {cbi(P##port.BYTE , bit);} \ +static inline int TOSH_READ_##name##_PIN() \ + {return ((P##port.BYTE) & (1 << bit)) != 0;} \ +static inline void TOSH_MAKE_##name##_OUTPUT() {sbi(PD##port.BYTE , bit);} \ +static inline void TOSH_MAKE_##name##_INPUT() {cbi(PD##port.BYTE , bit);} + + + +#define TOSH_ASSIGN_OUTPUT_ONLY_PIN(name, port, bit) \ +static inline void TOSH_SET_##name##_PIN() {sbi(P##port , bit);} \ +static inline void TOSH_CLR_##name##_PIN() {cbi(P##port , bit);} \ +static inline void TOSH_MAKE_##name##_OUTPUT() {;} + +#define TOSH_ALIAS_OUTPUT_ONLY_PIN(alias, connector)\ +static inline void TOSH_SET_##alias##_PIN() {TOSH_SET_##connector##_PIN();} \ +static inline void TOSH_CLR_##alias##_PIN() {TOSH_CLR_##connector##_PIN();} \ +static inline void TOSH_MAKE_##alias##_OUTPUT() {} \ + +#define TOSH_ALIAS_PIN(alias, connector) \ +static inline void TOSH_SET_##alias##_PIN() {TOSH_SET_##connector##_PIN();} \ +static inline void TOSH_CLR_##alias##_PIN() {TOSH_CLR_##connector##_PIN();} \ +static inline char TOSH_READ_##alias##_PIN() {return TOSH_READ_##connector##_PIN();} \ +static inline void TOSH_MAKE_##alias##_OUTPUT() {TOSH_MAKE_##connector##_OUTPUT();} \ +static inline void TOSH_MAKE_##alias##_INPUT() {TOSH_MAKE_##connector##_INPUT();} + + + +void TOSH_wait() +{ + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); +} + +#endif // __M16CHARDWARE_H__ diff --git a/tos/platforms/mulle/.platform b/tos/platforms/mulle/.platform new file mode 100755 index 00000000..2cd00292 --- /dev/null +++ b/tos/platforms/mulle/.platform @@ -0,0 +1,36 @@ +push( @includes, qw( + %T/platforms/mulle + %T/platforms/mulle/chips/rf230 + %T/chips/rf2xx/rf230 + %T/chips/rf2xx/layers + %T/chips/rf2xx/util + %T/chips/at45db + %T/platforms/mulle/softwarei2c + %T/platforms/mulle/softwarespi + %T/platforms/mulle/chips/rv8564 + %T/platforms/mulle/chips/at45db + %T/platforms/mulle/chips/m16c62p + %T/platforms/mulle/debug + %T/platforms/mulle/system + %T/platforms/mulle/timers + %T/platforms/mulle/timers/stop + %T/platforms/mulle/timers/wait + %T/platforms/mulle/timers/rf230 + %T/chips/m16c62p + %T/chips/m16c62p/control + %T/chips/m16c62p/adc + %T/chips/m16c62p/pins + %T/chips/m16c62p/timer + %T/chips/m16c62p/uart + %T/chips/ds2745 + %T/lib/power + %T/lib/timer + %T/lib/serial + %T/lib/diagmsg +) ); + +@opts = qw( + -gcc=m32c-elf-gcc + -mcpu=m16c +); + diff --git a/tos/platforms/mulle/ActiveMessageC.nc b/tos/platforms/mulle/ActiveMessageC.nc new file mode 100755 index 00000000..0fe46197 --- /dev/null +++ b/tos/platforms/mulle/ActiveMessageC.nc @@ -0,0 +1,70 @@ +/* + * 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. + * + * Author: Miklos Maroti + */ + +configuration ActiveMessageC +{ + provides + { + interface SplitControl; + + interface AMSend[uint8_t id]; + interface Receive[uint8_t id]; + interface Receive as Snoop[uint8_t id]; + interface Packet; + interface AMPacket; + + interface PacketAcknowledgements; + interface LowPowerListening; +#ifdef PACKET_LINK + interface PacketLink; +#endif + + interface PacketTimeStamp as PacketTimeStampMicro; + interface PacketTimeStamp as PacketTimeStampMilli; + } +} + +implementation +{ + components RF230ActiveMessageC as MAC, + RF230SplitControlP, + new SystemClockControlC(); + + RF230SplitControlP.SplitControlOrig -> MAC; + RF230SplitControlP.SystemClockControl -> SystemClockControlC; + + SplitControl = RF230SplitControlP.SplitControl; + AMSend = MAC; + Receive = MAC.Receive; + Snoop = MAC.Snoop; + Packet = MAC; + AMPacket = MAC; +#ifdef PACKET_LINK + PacketLink = MAC; +#endif + + PacketAcknowledgements = MAC; + LowPowerListening = MAC; + PacketTimeStampMilli = MAC; + PacketTimeStampMicro = MAC; +} diff --git a/tos/platforms/mulle/DemoSensorC.nc b/tos/platforms/mulle/DemoSensorC.nc new file mode 100755 index 00000000..568bb9ed --- /dev/null +++ b/tos/platforms/mulle/DemoSensorC.nc @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * A dumb demo sensor used for testing. + * + * @author Henrik Makitaavola + */ +generic module DemoSensorC() +{ + provides interface Read; +} +implementation +{ + uint8_t counter = 0; + + task void signalReadDone() + { + atomic uint8_t tmp = counter; + atomic counter++; + + signal Read.readDone(SUCCESS, tmp); + } + + command error_t Read.read() + { + return SUCCESS; + } + default event void Read.readDone( error_t result, uint16_t val ) {} +} diff --git a/tos/platforms/mulle/PlatformC.nc b/tos/platforms/mulle/PlatformC.nc new file mode 100755 index 00000000..7811316f --- /dev/null +++ b/tos/platforms/mulle/PlatformC.nc @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * All the wiring of the Mulle platform components. + * + * @author Henrik Makitaavola + */ + +#include "hardware.h" +# +configuration PlatformC +{ + provides interface Init; + + uses interface Init as SubInit; + +} +implementation +{ + components + PlatformP, + LedsC, + M16c62pControlC, + new StopModeControlC(); + + Init = PlatformP; + SubInit = PlatformP.SubInit; + PlatformP.M16c62pControl -> M16c62pControlC; + + PlatformP.StopModeControl -> StopModeControlC; +#ifdef ENABLE_STOP_MODE + components RV8564C; + PlatformP.RTC -> RV8564C; +#endif +} + diff --git a/tos/platforms/mulle/PlatformLedsC.nc b/tos/platforms/mulle/PlatformLedsC.nc new file mode 100755 index 00000000..0dbf006e --- /dev/null +++ b/tos/platforms/mulle/PlatformLedsC.nc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Mulle platform-specific LED interface. + * + * @author Henrik Makitaavola + */ +configuration PlatformLedsC +{ + provides interface GeneralIO as Led0; + provides interface GeneralIO as Led1; + provides interface GeneralIO as Led2; + uses interface Init; +} +implementation +{ + components HplM16c62pGeneralIOC as IO; + components PlatformP; + + Init = PlatformP.SubInit; + + Led0 = IO.PortP36; // Pin P3_6 = Red LED + Led1 = IO.PortP37; // Pin P3_7 = Green LED + Led2 = IO.PortP34; // External LED, supplied by user. +} diff --git a/tos/platforms/mulle/PlatformP.nc b/tos/platforms/mulle/PlatformP.nc new file mode 100755 index 00000000..c4025efb --- /dev/null +++ b/tos/platforms/mulle/PlatformP.nc @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Mulle platform initialization code. + * + * @author Henrik Makitaavola + */ + +#include "hardware.h" +#include "rv8564.h" + +module PlatformP +{ + provides interface Init; + uses interface Init as SubInit; + uses interface M16c62pControl; + uses interface StopModeControl; +#ifdef ENABLE_STOP_MODE + uses interface RV8564 as RTC; +#endif +} + +implementation +{ + command error_t Init.init() + { + error_t ok = SUCCESS; + + ok = call M16c62pControl.init(); +#ifdef ENABLE_STOP_MODE + call StopModeControl.allowStopMode(true); + // Activate the RTC and set it to output 1024 tics on the CLKOUT pin. + call RTC.on(); + call RTC.writeRegister(RV8564_CLKF, 0x81); +#else + call StopModeControl.allowStopMode(false); +#endif + // Init the M16c/62p to run at 10MHz. + ok = ecombine (ok, call M16c62pControl.defaultSystemClock(MCU_SPEED_10MHz)); + + // Sub components initialization. + ok = ecombine(ok, call SubInit.init()); + + return SUCCESS; + } +#ifdef ENABLE_STOP_MODE + async event void RTC.fired() {} +#endif +} diff --git a/tos/platforms/mulle/PlatformSerialC.nc b/tos/platforms/mulle/PlatformSerialC.nc new file mode 100755 index 00000000..452c272e --- /dev/null +++ b/tos/platforms/mulle/PlatformSerialC.nc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * The wiring of the Serial interface used to communicate with the Mulle + * platform. + * + * @author Henrik Makitaavola + */ +configuration PlatformSerialC { + + provides interface StdControl; + provides interface UartStream; + provides interface UartByte; + +} +implementation { + + components M16c62pUartC as Uart, + CounterMicro16C; + + StdControl = Uart.StdControl1; + UartStream = Uart.Uart1Stream; + UartByte = Uart.Uart1Byte; + + Uart.Counter -> CounterMicro16C; + +} diff --git a/tos/platforms/mulle/TimeSyncMessageC.nc b/tos/platforms/mulle/TimeSyncMessageC.nc new file mode 100755 index 00000000..35573e8d --- /dev/null +++ b/tos/platforms/mulle/TimeSyncMessageC.nc @@ -0,0 +1,63 @@ +/* + * 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. + * + * Author: Miklos Maroti + */ + +#include + +configuration TimeSyncMessageC +{ + provides + { + interface SplitControl; + + interface Receive[uint8_t id]; + interface Receive as Snoop[am_id_t id]; + interface Packet; + interface AMPacket; + + interface TimeSyncAMSend as TimeSyncAMSendRadio[am_id_t id]; + interface TimeSyncPacket as TimeSyncPacketRadio; + + interface TimeSyncAMSend as TimeSyncAMSendMilli[am_id_t id]; + interface TimeSyncPacket as TimeSyncPacketMilli; + } +} + +implementation +{ + components RF230TimeSyncMessageC as MAC, + RF230SplitControlP; + + RF230SplitControlP.SplitControlOrig -> MAC; + RF230SplitControlP.SystemClockControl -> SystemClockControlC; + + SplitControl = RF230SplitControlP.SplitControl; + Receive = MAC.Receive; + Snoop = MAC.Snoop; + Packet = MAC; + AMPacket = MAC; + + TimeSyncAMSendRadio = MAC; + TimeSyncPacketRadio = MAC; + TimeSyncAMSendMilli = MAC; + TimeSyncPacketMilli = MAC; +} diff --git a/tos/platforms/mulle/chips/at45db/At45dbSpi.h b/tos/platforms/mulle/chips/at45db/At45dbSpi.h new file mode 100644 index 00000000..78b29ce9 --- /dev/null +++ b/tos/platforms/mulle/chips/at45db/At45dbSpi.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Unique identifier for the SPI used to communicate with the AT45DB chip. + * + * @author Henrik Makitaavola + */ +#ifndef __AT45DBSOFTSPI_H__ +#define __AT45DBSOFTSPI_H__ + +#define UQ_MULLE_SOFTSPIAT45DB "SoftSPIAt45dbC.SoftSPIPacket" + +#endif // __AT45DBSOFTSPI_H__ diff --git a/tos/platforms/mulle/chips/at45db/HplAt45dbC.nc b/tos/platforms/mulle/chips/at45db/HplAt45dbC.nc new file mode 100644 index 00000000..f7dcc2fa --- /dev/null +++ b/tos/platforms/mulle/chips/at45db/HplAt45dbC.nc @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Mulle specific wiring for the AT45DB161D Flash storage. + * + * @author Henrik Makitaavola + */ + +configuration HplAt45dbC +{ + provides interface HplAt45db; +} +implementation +{ + components new HplAt45dbByteC(10), + new SoftSpiAt45dbC() as Spi, + HplAt45dbP, + HplM16c62pGeneralIOC as IOs, + RealMainP, + BusyWaitMicroC; + + HplAt45db = HplAt45dbByteC; + + HplAt45dbByteC.Resource -> Spi; + HplAt45dbByteC.FlashSpi -> Spi; + HplAt45dbByteC.HplAt45dbByte -> HplAt45dbP; + + HplAt45dbP.VCC -> IOs.PortP32; + HplAt45dbP.WP -> IOs.PortP44; + HplAt45dbP.Select -> IOs.PortP45; + HplAt45dbP.RESET -> IOs.PortP46; + + HplAt45dbP.FlashSpi -> Spi; + HplAt45dbP.BusyWait -> BusyWaitMicroC; + RealMainP.PlatformInit -> HplAt45dbP.Init; +} diff --git a/tos/platforms/mulle/chips/at45db/HplAt45dbP.nc b/tos/platforms/mulle/chips/at45db/HplAt45dbP.nc new file mode 100644 index 00000000..021e1667 --- /dev/null +++ b/tos/platforms/mulle/chips/at45db/HplAt45dbP.nc @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 2006, Technische Universitat 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 Universitat 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. + */ + +/** + * Mulle specific HplAt45dbByte interface implementation + * for the AT45DB161D Flash storage. + * + * @author Henrik Makitaavola + */ + +module HplAt45dbP +{ + provides + { + interface HplAt45dbByte; + interface Init; + } + uses + { + interface SpiByte as FlashSpi; + interface GeneralIO as VCC; + interface GeneralIO as Select; + interface GeneralIO as RESET; + interface GeneralIO as WP; + interface BusyWait; + } +} +implementation +{ + command error_t Init.init() { + call Select.makeOutput(); + call Select.set(); + call VCC.makeOutput(); + call VCC.clr(); + return SUCCESS; + } + + command void HplAt45dbByte.select() { call Select.clr(); } + command void HplAt45dbByte.deselect() { call Select.set(); } + + task void idleTask() + { + uint8_t status; + status = call FlashSpi.write(0); + if (!(status & 0x80)) + { + post idleTask(); + } + else + { + signal HplAt45dbByte.idle(); + } + } + + command void HplAt45dbByte.waitIdle() + { + post idleTask(); + } + + command bool HplAt45dbByte.getCompareStatus() + { + uint8_t status; + status = call FlashSpi.write(0); + return (!(status & 0x40)); + } +} diff --git a/tos/platforms/mulle/chips/at45db/HplAt45db_chip.h b/tos/platforms/mulle/chips/at45db/HplAt45db_chip.h new file mode 100644 index 00000000..381ba927 --- /dev/null +++ b/tos/platforms/mulle/chips/at45db/HplAt45db_chip.h @@ -0,0 +1,45 @@ +// $Id$ + +/* + * "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-2006 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. + */ + +#ifndef __HPLAT45DB_CHIP_H__ +#define __HPLAT45DB_CHIP_H__ + +// flash characteristics +enum { + AT45_MAX_PAGES = 4096, + AT45_PAGE_SIZE = 528, + AT45_PAGE_SIZE_LOG2 = 9 // Ignores the last 16 bytes +}; + +typedef uint16_t at45page_t; +typedef uint16_t at45pageoffset_t; // must fit 0 to AT45_PAGE_SIZE - 1 + +#endif // __HPLAT45DB_CHIP_H__ diff --git a/tos/platforms/mulle/chips/at45db/SoftSpiAt45dbC.nc b/tos/platforms/mulle/chips/at45db/SoftSpiAt45dbC.nc new file mode 100755 index 00000000..96a627c8 --- /dev/null +++ b/tos/platforms/mulle/chips/at45db/SoftSpiAt45dbC.nc @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * A component that is going to use the Flash Spi bus should + * create a new component of this to get access to the bus. + * + * @author Henrik Makitaavola + */ + +#include "At45dbSpi.h" + +generic configuration SoftSpiAt45dbC() +{ + provides interface Resource; + provides interface SpiPacket; + provides interface SpiByte; +} +implementation +{ + enum + { + CLIENT_ID = unique(UQ_MULLE_SOFTSPIAT45DB), + }; + + components SoftSpiAt45dbP as Spi; + Resource = Spi.Resource[CLIENT_ID]; + SpiPacket = Spi.SpiPacket[CLIENT_ID]; + SpiByte = Spi.SpiByte[CLIENT_ID]; +} diff --git a/tos/platforms/mulle/chips/at45db/SoftSpiAt45dbP.nc b/tos/platforms/mulle/chips/at45db/SoftSpiAt45dbP.nc new file mode 100755 index 00000000..9efbb3f0 --- /dev/null +++ b/tos/platforms/mulle/chips/at45db/SoftSpiAt45dbP.nc @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Wiring for the software Spi bus used by the Mulle Flash storage. + * + * @author Henrik Makitaavola + */ + +configuration SoftSpiAt45dbP +{ + provides interface Resource[uint8_t client]; + provides interface SpiPacket[uint8_t client]; + provides interface SpiByte[uint8_t client]; +} +implementation +{ + components new SoftSpiMasterP(UQ_MULLE_SOFTSPIAT45DB) as Spi, + new SoftSpiBusP(), + HplM16c62pGeneralIOC as IOs; + + // Init the software SPI bus + SoftSpiBusP.MISO -> IOs.PortP40; + SoftSpiBusP.MOSI -> IOs.PortP41; + SoftSpiBusP.SCLK -> IOs.PortP42; + + Spi.SoftSpiBus -> SoftSpiBusP; + + Resource = Spi.Resource; + SpiPacket = Spi.SpiPacket; + SpiByte = Spi.SpiByte; + +} diff --git a/tos/platforms/mulle/chips/m16c62p/M16c62pControlPlatformC.nc b/tos/platforms/mulle/chips/m16c62p/M16c62pControlPlatformC.nc new file mode 100644 index 00000000..e71a862a --- /dev/null +++ b/tos/platforms/mulle/chips/m16c62p/M16c62pControlPlatformC.nc @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Mulle specific implementation of the M16c62pControlPlatform interface. + * + * @author Henrik Makitaavola + */ +module M16c62pControlPlatformC +{ + provides interface M16c62pControlPlatform; +} +implementation +{ + async command void M16c62pControlPlatform.PLLOn() + { + // Set all timers that uses the main clock + // as source to use F2 instead of F1 because + // the main clock will be twice as fast when PLL + // is on. + // Set the UARTS clock source to F2 instead of F1. + + // NOTE: No need to turn on/off protections for registers, + // this is handeled by the caller of this code. + CLR_BIT(PCLKR.BYTE, 0); // Timers + CLR_BIT(PCLKR.BYTE, 1); // Uarts + } + + async command void M16c62pControlPlatform.PLLOff() + { + // Restore settings done in PLLOn() + // NOTE: No need to turn on/off protections for registers, + // this is handeled by the caller of this code. + SET_BIT(PCLKR.BYTE, 0); + SET_BIT(PCLKR.BYTE, 1); + } +} diff --git a/tos/platforms/mulle/chips/rf230/HplRF230C.nc b/tos/platforms/mulle/chips/rf230/HplRF230C.nc new file mode 100755 index 00000000..747f130f --- /dev/null +++ b/tos/platforms/mulle/chips/rf230/HplRF230C.nc @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Mulle specific wiring of the HplRF230C configuration. + * + * @author Henrik Makitaavola + */ + +#include + +configuration HplRF230C +{ + provides + { + interface GeneralIO as SELN; + interface Resource as SpiResource; + interface SpiByte; + interface FastSpiByte; + + interface GeneralIO as SLP_TR; + interface GeneralIO as RSTN; + + interface GpioCapture as IRQ; + interface Alarm as Alarm; + interface LocalTime as LocalTimeRadio; + } +} +implementation +{ + components HplRF230P; + IRQ = HplRF230P.IRQ; + + components new SoftSpiRF230C() as Spi; + HplRF230P.Spi -> Spi; + SpiResource = Spi; + SpiByte = Spi; + FastSpiByte = HplRF230P.FastSpiByte; + + components HplM16c62pGeneralIOC as IOs; + HplRF230P.PortVCC -> IOs.PortP77; + HplRF230P.PortIRQ -> IOs.PortP83; + SLP_TR = IOs.PortP07; + RSTN = IOs.PortP43; + SELN = IOs.PortP35; + + components HplM16c62pInterruptC as Irqs, + new M16c62pInterruptC() as Irq; + HplRF230P.GIRQ -> Irq; + Irq -> Irqs.Int1; + + components AlarmRF23016C as AlarmRF230; + HplRF230P.Alarm -> AlarmRF230; + Alarm = AlarmRF230; + + components RealMainP; + RealMainP.PlatformInit -> HplRF230P.PlatformInit; + + components LocalTimeMicroC; + LocalTimeRadio = LocalTimeMicroC; +} diff --git a/tos/platforms/mulle/chips/rf230/HplRF230P.nc b/tos/platforms/mulle/chips/rf230/HplRF230P.nc new file mode 100755 index 00000000..1973c681 --- /dev/null +++ b/tos/platforms/mulle/chips/rf230/HplRF230P.nc @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Implementation of the time capture on RF230 interrupt and the + * FastSpiBus interface. + * + * @author Henrik Makitaavola + */ + +module HplRF230P +{ + provides + { + interface GpioCapture as IRQ; + interface Init as PlatformInit; + interface FastSpiByte; + } + + uses + { + interface GeneralIO as PortIRQ; + interface GeneralIO as PortVCC; + interface GpioInterrupt as GIRQ; + interface SoftSpiBus as Spi; + interface Alarm as Alarm; + } +} +implementation +{ + command error_t PlatformInit.init() + { + call PortIRQ.makeInput(); + call PortIRQ.clr(); + call GIRQ.disable(); + call PortVCC.makeOutput(); + call PortVCC.set(); + + return SUCCESS; + } + + async event void GIRQ.fired() + { + signal IRQ.captured(call Alarm.getNow()); + } + async event void Alarm.fired() {} + + default async event void IRQ.captured(uint16_t time) {} + + async command error_t IRQ.captureRisingEdge() + { + call GIRQ.enableRisingEdge(); + return SUCCESS; + } + + async command error_t IRQ.captureFallingEdge() + { + // falling edge comes when the IRQ_STATUS register of the RF230 is read + return FAIL; + } + + async command void IRQ.disable() + { + call GIRQ.disable(); + } + + uint8_t tmp_data; + async command void FastSpiByte.splitWrite(uint8_t data) + { + atomic tmp_data = data; + } + + async command uint8_t FastSpiByte.splitRead() + { + atomic return call Spi.write(tmp_data); + } + + async command uint8_t FastSpiByte.splitReadWrite(uint8_t data) + { + uint8_t b; + atomic + { + b = call Spi.write(tmp_data); + tmp_data = data; + } + return b; + } + + async command uint8_t FastSpiByte.write(uint8_t data) + { + return call Spi.write(data); + } +} diff --git a/tos/platforms/mulle/chips/rf230/Mulle_RF230Spi.h b/tos/platforms/mulle/chips/rf230/Mulle_RF230Spi.h new file mode 100755 index 00000000..3ea8b3b4 --- /dev/null +++ b/tos/platforms/mulle/chips/rf230/Mulle_RF230Spi.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Unique identifier for the RF230 SPI bus. + * + * @author Henrik Makitaavola + */ +#ifndef __MULLE_RF230SPI_H__ +#define __MULLE_RF230SPI_H__ + +#define UQ_MULLE_SOFTSPIRF230 "SoftSPIRF230C.SoftSPIPacket" + +#endif // __MULLE_RF230SPI_H__ diff --git a/tos/platforms/mulle/chips/rf230/RF230SplitControlP.nc b/tos/platforms/mulle/chips/rf230/RF230SplitControlP.nc new file mode 100644 index 00000000..bd87661d --- /dev/null +++ b/tos/platforms/mulle/chips/rf230/RF230SplitControlP.nc @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 module overrides the default SplitControl for the RF230 chip so that + * the PLL is turned on every time the RF230 chip is turned on. + * + * @author Henrik Makitaavola + */ +module RF230SplitControlP +{ + provides interface SplitControl; + uses interface SplitControl as SplitControlOrig; + uses interface SystemClockControl; +} +implementation +{ + command error_t SplitControl.start() + { + call SystemClockControl.minSpeed(M16C62P_PLL_CLOCK); + return call SplitControlOrig.start(); + } + + event void SplitControlOrig.startDone(error_t error) + { + if (error != SUCCESS) + { + call SystemClockControl.minSpeed(M16C62P_DONT_CARE); + } + signal SplitControl.startDone(error); + } + + command error_t SplitControl.stop() + { + return call SplitControlOrig.stop(); + } + + event void SplitControlOrig.stopDone(error_t error) + { + if (error == SUCCESS) + { + call SystemClockControl.minSpeed(M16C62P_DONT_CARE); + } + signal SplitControl.stopDone(error); + } +} diff --git a/tos/platforms/mulle/chips/rf230/RadioConfig.h b/tos/platforms/mulle/chips/rf230/RadioConfig.h new file mode 100644 index 00000000..3f5e0080 --- /dev/null +++ b/tos/platforms/mulle/chips/rf230/RadioConfig.h @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + * + * Author: Miklos Maroti + */ + +/** + * @author Henrik Makitaavola + */ +#ifndef __RADIOCONFIG_H__ +#define __RADIOCONFIG_H__ + +#include + + +enum +{ + /** + * This is the value of the TRX_CTRL_0 register + * which configures the output pin currents and the CLKM clock + */ + RF230_TRX_CTRL_0_VALUE = 0, + + /** + * This is the default value of the CCA_MODE field in the PHY_CC_CCA register + * which is used to configure the default mode of the clear channel assessment + */ + RF230_CCA_MODE_VALUE = RF230_CCA_MODE_3, + + /** + * This is the value of the CCA_THRES register that controls the + * energy levels used for clear channel assessment + */ + RF230_CCA_THRES_VALUE = 0xC7, +}; +/* This is the default value of the TX_PWR field of the PHY_TX_PWR register. 0-15*/ +#ifndef RF230_DEF_RFPOWER +#define RF230_DEF_RFPOWER 0 +#endif + +/* This is the default value of the CHANNEL field of the PHY_CC_CCA register. 11-26*/ +#ifndef RF230_DEF_CHANNEL +#define RF230_DEF_CHANNEL 11 +#endif + + +/* + * This is the command used to calculate the CRC for the RF230 chip. + * TODO: Check why the default crcByte implementation is in a different endianness + */ +inline uint16_t RF230_CRCBYTE_COMMAND(uint16_t crc, uint8_t data) +{ + uint8_t lo8 = crc & 0x00FF; + uint8_t hi8 = (crc >> 8) & 0x00FF; + data ^= lo8; //lo8 (crc); + data ^= data << 4; + + return ((((uint16_t)data << 8) | hi8 /*hi8 (crc)*/) ^ (uint8_t)(data >> 4) + ^ ((uint16_t)data << 3)); + +} + +/** + * This is the timer type of the radio alarm interface + */ + +typedef TMicro TRadio; +/** + * The number of alarm ticks per one second + */ +#define RADIO_ALARM_SEC 2500000 // 20MHz / 8 + +#define RADIO_ALARM_MICROSEC 2.5// RADIO_ALARM_SEC/1000000 + +/** + * The base two logarithm of the number of radio alarm ticks per one millisecond + */ +#define RADIO_ALARM_MILLI_EXP 11 + +#endif //__RADIOCONFIG_H__ diff --git a/tos/platforms/mulle/chips/rf230/SoftSpiRF230C.nc b/tos/platforms/mulle/chips/rf230/SoftSpiRF230C.nc new file mode 100755 index 00000000..3f4e1545 --- /dev/null +++ b/tos/platforms/mulle/chips/rf230/SoftSpiRF230C.nc @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * A component that is going to use the RF230 Spi bus should + * create a new component of this to get access to the bus. + * + * @author Henrik Makitaavola + */ + +#include "Mulle_RF230Spi.h" + +generic configuration SoftSpiRF230C() +{ + provides interface Resource; + provides interface SpiPacket; + provides interface SpiByte; + provides interface SoftSpiBus; +} +implementation +{ + enum + { + CLIENT_ID = unique(UQ_MULLE_SOFTSPIRF230), + }; + + components SoftSpiRF230P as Spi; + SoftSpiBus = Spi.SoftSpiBus; + Resource = Spi.Resource[CLIENT_ID]; + SpiPacket = Spi.SpiPacket[CLIENT_ID]; + SpiByte = Spi.SpiByte[CLIENT_ID]; +} diff --git a/tos/platforms/mulle/chips/rf230/SoftSpiRF230P.nc b/tos/platforms/mulle/chips/rf230/SoftSpiRF230P.nc new file mode 100755 index 00000000..94233595 --- /dev/null +++ b/tos/platforms/mulle/chips/rf230/SoftSpiRF230P.nc @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Creates a new Software Spi bus that will be used by the RF230 + * chip. + * + * @author Henrik Makitaavola + */ + +configuration SoftSpiRF230P +{ + provides interface Resource[uint8_t client]; + provides interface SpiPacket[uint8_t client]; + provides interface SpiByte[uint8_t client]; + provides interface SoftSpiBus; + +} +implementation +{ + components new SoftSpiMasterP(UQ_MULLE_SOFTSPIRF230) as Spi, + new SoftSpiBusP(), + HplM16c62pGeneralIOC as IOs; + + // Init the software SPI bus + SoftSpiBusP.SCLK -> IOs.PortP33; + SoftSpiBusP.MISO -> IOs.PortP10; + SoftSpiBusP.MOSI -> IOs.PortP11; + + Spi.SoftSpiBus -> SoftSpiBusP; + SoftSpiBus = SoftSpiBusP; + + Resource = Spi.Resource; + SpiPacket = Spi.SpiPacket; + SpiByte = Spi.SpiByte; +} diff --git a/tos/platforms/mulle/chips/rv8564/RV8564.nc b/tos/platforms/mulle/chips/rv8564/RV8564.nc new file mode 100755 index 00000000..16b492cd --- /dev/null +++ b/tos/platforms/mulle/chips/rv8564/RV8564.nc @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 the RV-8564-C2 real time clock. + * + * @author Henrik Makitaavola + */ +interface RV8564 +{ + /** + * Turns the chip on. + */ + async command void on(); + + /** + * Turns the chip off. + */ + async command void off(); + + /** + * Checks if the chip is on. + * + * @return true if on. + */ + async command bool isOn(); + + /** + * Enables/disables the interrupts generated by the CLKOUT. + */ + // TODO(henrik) This needs to be changed because there are different type of + // interrupts generated by the chip. + async command void enableInterrupt(); + async command void disableInterrupt(); + + /** + * Reads from a register. + * + * @param reg The register to be read. + * @return The value of the register. + */ + async command uint8_t readRegister(uint16_t reg); + + /** + * Writes to a register. + * + * @param reg The register that is written to. + * @param value The value that is written to the register. + */ + async command void writeRegister(uint16_t reg, uint8_t value); + + /** + * Signal when an interrupt occurs. + */ + async event void fired(); +} diff --git a/tos/platforms/mulle/chips/rv8564/RV8564C.nc b/tos/platforms/mulle/chips/rv8564/RV8564C.nc new file mode 100755 index 00000000..861b0535 --- /dev/null +++ b/tos/platforms/mulle/chips/rv8564/RV8564C.nc @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Configuration of the RV-8564 Real-time Clock on the Mulle platform. + * + * @author Henrik Makitaavola + */ + +configuration RV8564C +{ + provides interface RV8564 as RTC; +} +implementation +{ + components RV8564P as RTCP, + new SoftI2CBatteryMonitorRTCC() as I2C, + HplM16c62pGeneralIOC as IOs, + HplM16c62pInterruptC as Irqs, + new M16c62pInterruptC() as Irq; + + Irq.HplM16c62pInterrupt -> Irqs.Int0; + + RTC = RTCP; + RTCP -> IOs.PortP47; + RTCP.GpioInterrupt -> Irq; + RTCP.I2C -> I2C; + RTCP.I2CResource -> I2C; +} diff --git a/tos/platforms/mulle/chips/rv8564/RV8564P.nc b/tos/platforms/mulle/chips/rv8564/RV8564P.nc new file mode 100755 index 00000000..77e594cb --- /dev/null +++ b/tos/platforms/mulle/chips/rv8564/RV8564P.nc @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Implementation of the RV-8564-C2 real time clock. + * + * @author Henrik Makitaavola + */ + +#include "rv8564.h" +#include "I2C.h" +// TODO(henrik) The request to the I2C is done throuh a immediateRequest, this perhaps needs to be changed because +// its bad if the battery monitor has hold of the I2C bus. +module RV8564P +{ + provides interface RV8564 as RTC; + // TODO(henrik) Exactly how is the RTC connected to mulle, what is the functionallity of GeneralIO? + // Maybe there is only a init needed because the chip is always on? + uses interface GeneralIO; + uses interface GpioInterrupt; + uses interface I2CPacket as I2C; + uses interface Resource as I2CResource; +} +implementation +{ + async command void RTC.on() + { + call GeneralIO.makeOutput(); + call GeneralIO.set(); + } + + async command void RTC.off() + { + call GeneralIO.clr(); + call GeneralIO.makeInput(); + } + + async command bool RTC.isOn() + { + return (call GeneralIO.get() && call GeneralIO.isOutput()); + } + + async command void RTC.enableInterrupt() + { + call GpioInterrupt.enableFallingEdge(); + } + + async command void RTC.disableInterrupt() + { + call GpioInterrupt.disable(); + } + + async command uint8_t RTC.readRegister(uint16_t reg) + { + uint8_t val; + atomic + { + if (call I2CResource.immediateRequest() == SUCCESS) + { + call I2C.write(I2C_START, RV8564_WR_ADDR, 1, (uint8_t*)®); + call I2C.read(I2C_START | I2C_STOP, RV8564_RD_ADDR, 1, &val); + call I2CResource.release(); + } + } + return val; + } + + async command void RTC.writeRegister(uint16_t reg, uint8_t value) + { + uint8_t wr[2] = {reg, value}; + atomic + { + if (call I2CResource.immediateRequest() == SUCCESS) + { + call I2C.write(I2C_START | I2C_STOP, RV8564_WR_ADDR, 2, wr); + call I2CResource.release(); + } + } + } + + event void I2CResource.granted() + { + // TODO(henrik) Insert communication code here. + } + + async event void GpioInterrupt.fired() + { + signal RTC.fired(); + } + default async event void RTC.fired() { } + + async event void I2C.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) {} + async event void I2C.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) {} +} diff --git a/tos/platforms/mulle/chips/rv8564/rv8564.h b/tos/platforms/mulle/chips/rv8564/rv8564.h new file mode 100755 index 00000000..48195ab7 --- /dev/null +++ b/tos/platforms/mulle/chips/rv8564/rv8564.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 for the Microcrystal RV-8564 Real-time Clock on the Mulle + * platform. + * + * @author: Gong Liang + */ + +#ifndef __RV8564_H__ +#define __RV8564_H__ + +/* constants */ +#define RV8564_WR_ADDR 0xa2 //slave address write 0xa2 or read 0xa3 +#define RV8564_RD_ADDR 0xa3 + + +#define RV8564_CS1 0x00 +#define RV8564_CS2 0x01 + + +/* Control/Status registers */ +#define RV8564_CTR1 0x00 //00 Control status 1, + //Test1 0 Stop 0, Test 0 0 0 + +#define RV8564_CTR2 0x01 //01 Control status 2, + // 0 x 0 TI/TP, AF TF AIE TIE + // TI/TP=1,INT pulses +//Note that writing 1 to the alarm flags causes no change...0-1 is not applied. + +#define RV8564_SEC 0x02 // +#define RV8564_MIN 0x03 // +#define RV8564_HOUR 0x04 // +#define RV8564_DAY 0x05 // +#define RV8564_WEEK 0x06 // +#define RV8564_MON 0x07 // +#define RV8564_YEAR 0x08 // + +#define RV8564_MIN_ALARM 0x09 // +#define RV8564_HR_ALARM 0x0A // +#define RV8564_DAY_ALARM 0x0B // +#define RV8564_WK_ALARM 0x0C // + + +#define RV8564_CLKF 0x0D //FE x x x, x x FD1 FD0 + // 0 0 32768 Hz + // 0 1 61024 Hz + // 1 0 32 Hz + // 1 1 1 Hz + + + + +#define RV8564_TC 0x0E //TE x x x, x x TD1 TD0 + // 0 0 4096 Hz + // 0 1 64 Hz + // 1 0 1 Sec + // 1 1 1 Min + +#define RV8564_TIMER 0x0F //128 64 32 16, 8 4 2 1 + +/*********** Initial setting of the RV_8564ram, Set it before using (debug only) ***********/ +uint8_t RV_8564ram[16] = { 0x00, 0x13, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, + 0x07, 0x80, 0x80, 0x80, + 0x80, 0x83, 0x83, 1 }; + + +#endif /* __RV8564_H__ */ + diff --git a/tos/platforms/mulle/debug/m_printf.h b/tos/platforms/mulle/debug/m_printf.h new file mode 100644 index 00000000..ae9dfec3 --- /dev/null +++ b/tos/platforms/mulle/debug/m_printf.h @@ -0,0 +1,276 @@ +/* + Copyright 2001, 2002 Georges Menie (www.menie.org) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + + +/** + * The file is a debug tool for the Mulle-TinyOS platform. To use this tool, + * just need 2 steps. + * First, add #inclued "m_printf.h" to your component. + * Sencond, use _printf() function in the m_printf.h to print what you want + * to see. + * attention: don't forget to start your serialport, and just initialization. + * The serialport baudrate is at 57600, and you can choose a terminal to watch + * the output, for example, cutecom in linux. + * For more information see www.eistec.se. + * + * Modification to adopt printf for Mulle-TinyOS is made by + * @author Fan Zhang + * @author Cheng Zhong + */ +#ifndef __M_PRINTF_H__ +#define __M_PRINTF_H__ + +#include +#include +/* + * void m16c62p_putc(int c) is for the m16c62p. send a char through + * serial port 1. + */ +void m16c62p_putc(int c) +{ + while(U1C1.BIT.TI == 0); // wait for transmit buffer empty flag + U1TB.BYTE.U1TBL = c; +} +#define putchar(c) m16c62p_putc(c) + +static void printchar(char **str, int c) +{ + //extern int putchar(int c); + + if (str) { + **str = c; + ++(*str); + } + else (void)putchar(c); +} + +#define PAD_RIGHT 1 +#define PAD_ZERO 2 + +static int prints(char **out, const char *string, int width, int pad) +{ + register int pc = 0, padchar = ' '; + + if (width > 0) + { + register int len = 0; + register const char *ptr; + for (ptr = string; *ptr; ++ptr) ++len; + if (len >= width) width = 0; + else width -= len; + if (pad & PAD_ZERO) padchar = '0'; + } + if (!(pad & PAD_RIGHT)) { + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + } + for ( ; *string ; ++string) { + printchar (out, *string); + ++pc; + } + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + + return pc; +} + +/* + * the following should be enough for 32 bit int +*/ +#define PRINT_BUF_LEN 12 + +static int printi(char **out, long int i, int b, int sg, int width, int pad, int letbase) +{ + char print_buf[PRINT_BUF_LEN]; + register char *s; + register int t, neg = 0, pc = 0; + register unsigned long int u = i; + + if (i == 0) { + print_buf[0] = '0'; + print_buf[1] = '\0'; + return prints (out, print_buf, width, pad); + } + + if (sg && b == 10 && i < 0) { + neg = 1; + u = -i; + } + + s = print_buf + PRINT_BUF_LEN-1; + *s = '\0'; + + while (u) { + t = u % b; + if( t >= 10 ) + t += letbase - '0' - 10; + *--s = t + '0'; + u /= b; + } + + if (neg) { + if( width && (pad & PAD_ZERO) ) { + printchar (out, '-'); + ++pc; + --width; + } + else { + *--s = '-'; + } + } + + return pc + prints (out, s, width, pad); +} + +static int print(char **out, const char *format, va_list args ) +{ + register int width, pad; + register int pc = 0; + char scr[2]; + + for (; *format != 0; ++format) + { + if (*format == '%') + { + ++format; + width = pad = 0; + if (*format == '\0') break; + if (*format == '%') goto out; + if (*format == '-') + { + ++format; + pad = PAD_RIGHT; + } + while (*format == '0') + { + ++format; + pad |= PAD_ZERO; + } + for ( ; *format >= '0' && *format <= '9'; ++format) + { + width *= 10; + width += *format - '0'; + } + if( *format == 's' ) + { + register char *s = (char *)va_arg( args, int); + pc += prints (out, s?s:"(null)", width, pad); + continue; + } + if( *format == 'd' ) + { + pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); + continue; + } + if( *format == 'x' ) + { + pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); + continue; + } + if( *format == 'X' ) + { + pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); + continue; + } + if( *format == 'u' ) + { + pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); + continue; + } + if( *format == 'l' ) + { + ++format; + if( *format == 'u' ) + { + pc += printi (out, va_arg( args, uint32_t ), 10, 0, width, pad, 'a'); + continue; + } + } + if( *format == 'c' ) + { + /* char are converted to int then pushed on the stack */ + scr[0] = (char)va_arg( args, int ); + scr[1] = '\0'; + pc += prints (out, scr, width, pad); + continue; + } + } + else + { + out: + printchar (out, *format); + ++pc; + } + } + if (out) **out = '\0'; + va_end( args ); + return pc; +} +/* + * A simple printf function. Support the following format: + * Code Format + * %c character + * %d signed decimal integers + * %i signed decimal integers, the same as %d + * %s a string of characters + * %o octal + * %x unsigned hexadecimal + * %X unsigned hexadecimal with uppercase + * %u unsigned decimal integers + * %lu 32 bits decimal unsigned long int=uint32_t + */ +int _printf(const char *format, ...) +{ + va_list args; + + va_start( args, format ); + return print( 0, format, args ); +} + +int sprintf(char *out, const char *format, ...) +{ + va_list args; + + va_start( args, format ); + return print( &out, format, args ); +} + +void _puts(const char *str) +{ + while( *str != '\0' ) + putchar(*str++); + + putchar('\n'); +} +void printmsg(void *msg, uint8_t printLen) +{ + uint8_t i; + for(i=0; i < printLen; i++) + { + _printf("%x ", *( (uint8_t *)msg + i)); + + } + _printf("\n"); +} +#endif // __M_PRINTF_H__ + diff --git a/tos/platforms/mulle/hardware.h b/tos/platforms/mulle/hardware.h new file mode 100755 index 00000000..d478bdac --- /dev/null +++ b/tos/platforms/mulle/hardware.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 Henrik Makitaavola + */ + +#ifndef __HARDWARE_H__ +#define __HARDWARE_H__ + +#define MAIN_CRYSTAL_SPEED 10 /*MHz*/ +#define PLL_MULTIPLIER M16C62P_PLL_2 + +#include "m16c62phardware.h" // Header file for the MCU + +#endif // __HARDWARE_H__ + + diff --git a/tos/platforms/mulle/platform.h b/tos/platforms/mulle/platform.h new file mode 100755 index 00000000..bfe6a31f --- /dev/null +++ b/tos/platforms/mulle/platform.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Defines for the different speeds supported on the Mulle platform. + * + * @author Henrik Makitaavola + */ + +#ifndef __PLATFORM_H__ +#define __PLATFORM_H__ + + +#define MCU_SPEED_20MHz M16C62P_PLL_CLOCK +#define MCU_SPEED_10MHz M16C62P_MAIN_CLOCK_DIV_0 +#define MCU_SPEED_5MHz M16C62P_MAIN_CLOCK_DIV_2 +#define MCU_SPEED_2_5MHz M16C62P_MAIN_CLOCK_DIV_4 +#define MCU_SPEED_1_25MHz M16C62P_MAIN_CLOCK_DIV_8 +#define MCU_SPEED_0_625MHz M16C62P_MAIN_CLOCK_DIV_16 +#define MCU_SPEED_32KHz M16C62P_SUB_CLOCK + +#endif // __PLATFORM_H__ diff --git a/tos/platforms/mulle/platform_message.h b/tos/platforms/mulle/platform_message.h new file mode 100755 index 00000000..f2be256a --- /dev/null +++ b/tos/platforms/mulle/platform_message.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 Henrik Makitaavola + */ +#ifndef __PLATFORM_MESSAGE_H__ +#define __PLATFORM_MESSAGE_H__ + +#include "Serial.h" +#include + +typedef union message_header { + rf230packet_header_t rf230; + serial_header_t serial; +} message_header_t; + +typedef union message_footer { + rf230packet_footer_t rf230; +} message_footer_t; + +typedef union message_metadata { + rf230packet_metadata_t rf230; +} message_metadata_t; + + +#endif // __PLATFORM_MESSAGE_H__ diff --git a/tos/platforms/mulle/softwarei2c/MulleI2C.h b/tos/platforms/mulle/softwarei2c/MulleI2C.h new file mode 100755 index 00000000..64ccd8e2 --- /dev/null +++ b/tos/platforms/mulle/softwarei2c/MulleI2C.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 Henrik Makitaavola + */ +#ifndef __MULLEI2C_H__ +#define __MULLEI2C_H__ + +#define UQ_MULLE_SOFTI2C_BATTERY_RTC "SoftI2CMasterC.Battery_RTC" + +#endif // __MULLEI2C_H__ diff --git a/tos/platforms/mulle/softwarei2c/SoftI2CBatteryMonitorRTCC.nc b/tos/platforms/mulle/softwarei2c/SoftI2CBatteryMonitorRTCC.nc new file mode 100755 index 00000000..905a5b0a --- /dev/null +++ b/tos/platforms/mulle/softwarei2c/SoftI2CBatteryMonitorRTCC.nc @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * The basic client abstraction of the software I2C on Mulle used + * by the RTC and battery monitor. + * The device drivers should instantiate one of these to ensure + * exclusive access to the I2C bus. + * + * @author Henrik Makitaavola + */ + +#include "MulleI2C.h" +#include "I2C.h" +generic configuration SoftI2CBatteryMonitorRTCC() +{ + provides interface Resource; + provides interface I2CPacket; +} +implementation +{ + enum + { + CLIENT_ID = unique(UQ_MULLE_SOFTI2C_BATTERY_RTC), + }; + + components SoftI2CBatteryMonitorRTCP as I2C; + Resource = I2C.Resource[CLIENT_ID]; + I2CPacket = I2C.I2CPacket[CLIENT_ID]; +} diff --git a/tos/platforms/mulle/softwarei2c/SoftI2CBatteryMonitorRTCP.nc b/tos/platforms/mulle/softwarei2c/SoftI2CBatteryMonitorRTCP.nc new file mode 100644 index 00000000..bf4a3c51 --- /dev/null +++ b/tos/platforms/mulle/softwarei2c/SoftI2CBatteryMonitorRTCP.nc @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * The configuration that takes the underlying software I2C driver + * on Mulle and turns it into a shared abstraction for the RTC and battery + * monitor. + * + * @author Henrik Makitaavola + */ + +#include "MulleI2C.h" +#include "I2C.h" +configuration SoftI2CBatteryMonitorRTCP +{ + provides interface Resource[uint8_t client]; + provides interface I2CPacket[uint8_t client]; +} +implementation +{ + components new SoftI2CMasterP(UQ_MULLE_SOFTI2C_BATTERY_RTC) as I2C, + new SoftI2CBusP(), + HplM16c62pGeneralIOC as IOs; + + // Init the software I2C bus + SoftI2CBusP.I2CClk -> IOs.PortP71; + SoftI2CBusP.I2CData -> IOs.PortP70; + SoftI2CBusP.I2CCtrl -> IOs.PortP75; + + I2C.SoftI2CBus -> SoftI2CBusP; + + Resource = I2C.Resource; + I2CPacket = I2C.I2CPacket; +} + diff --git a/tos/platforms/mulle/softwarei2c/SoftI2CBus.nc b/tos/platforms/mulle/softwarei2c/SoftI2CBus.nc new file mode 100755 index 00000000..6dba0761 --- /dev/null +++ b/tos/platforms/mulle/softwarei2c/SoftI2CBus.nc @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 a software I2C bus. + * + * @author Henrik Makitaavola + */ +interface SoftI2CBus +{ + /* + * Initializes bus default state. + */ + async command void init(); + + /* + * Turn the bus off. + */ + async command void off(); + + /* + * Generates a start condition on the bus. + */ + async command void start(); + + /* + * Generates a stop condition. + */ + async command void stop(); + + /* + * Restarts a I2C bus transaction. + */ + async command void restart(); + + /* + * Reads a byte from the I2C bus. + * + * @param ack If true ack the read byte else nack. + * @return A byte from the bus. + */ + async command uint8_t readByte(bool ack); + + /* + * Writes a byte on th I2C bus. + * Send the data( or address) C and wait for acknowledge after finishing + * sending it. Nonacknowledge sets ACK=0 and normal sending sets ACK=1. + * + * @param byte the byte to write. + */ + async command void writeByte(uint8_t byte); + + /* + * Master sends the ACK (LowLevel), working as a master-receiver. + */ + async command void masterAck(); + + /* + * Master sends the NACK (HighLevel), working as a master-receiver. + */ + async command void masterNack(); +} diff --git a/tos/platforms/mulle/softwarei2c/SoftI2CBusP.nc b/tos/platforms/mulle/softwarei2c/SoftI2CBusP.nc new file mode 100755 index 00000000..0460da4c --- /dev/null +++ b/tos/platforms/mulle/softwarei2c/SoftI2CBusP.nc @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Mulle specific implementation of a software I2C bus. + * + * @author Gong Liang + * @author Henrik Makitaavola + */ +generic module SoftI2CBusP() +{ + provides interface SoftI2CBus as I2C; + + uses interface GeneralIO as I2CClk; + uses interface GeneralIO as I2CData; + uses interface GeneralIO as I2CCtrl; +} +implementation +{ + /***************************************************************************************/ + // Name:idle(), transition(),halfTransition() + // I2C-bus can be transferred at rates of up to 100 kbit/s in the Standard-mode + // 10MHz main clock frequency + // The Baud rate of IIC bus communication can be adjusted by altering the loop times. + /***************************************************************************************/ + // TODO(henrik) This must be altered to support different main clock speeds. + void idle(void) + { + volatile long int i; + for(i=0;i<1000;i++) + { + asm("nop"); + } + } + + void transition(void) + { + volatile int i; + for(i=0;i<100;i++) + { + asm("nop"); + } + } + + void halfTransition(void) + { + volatile int i; + for(i=0;i<50;i++) + { + asm("nop"); + } + } + + + async command void I2C.init() + { + call I2CData.makeOutput(); + call I2CClk.makeOutput(); + call I2CCtrl.makeOutput(); + call I2CCtrl.set(); + call I2CData.set(); // drive bus high (default) + call I2CClk.set(); // drive bus high (default) + } + + async command void I2C.off() + { + // TODO(henrik): Exactly what should be set if I2C bus should be turned off? + call I2CData.makeInput(); + call I2CClk.makeInput(); + call I2CCtrl.makeInput(); + call I2CCtrl.clr(); + call I2CClk.clr(); + call I2CData.clr(); + } + + async command void I2C.start() + { + atomic + { + call I2CData.makeOutput(); + call I2CClk.clr(); + call I2CData.set(); + idle(); + call I2CClk.set(); + idle(); + call I2CData.clr(); + idle(); + call I2CClk.clr(); + idle(); + } + } + + async command void I2C.stop() + { + atomic + { + call I2CData.makeOutput(); + + call I2CData.set(); + call I2CClk.clr(); + idle(); + call I2CData.clr(); + idle(); + call I2CClk.set(); + idle(); + call I2CData.set(); + idle(); + } + } + + async command void I2C.restart() + { + atomic + { + call I2CClk.clr(); + call I2CData.set(); + call I2CClk.set(); + idle(); + call I2CData.clr(); + idle(); + call I2CClk.clr(); + } + } + + async command uint8_t I2C.readByte(bool ack) + { + uint8_t retChar; + uint8_t bitCnt; + + atomic + { + call I2CData.makeInput(); + + retChar = 0; + + for (bitCnt=0; bitCnt<8; ++bitCnt) + { + asm("nop"); + call I2CClk.clr(); + transition(); + + call I2CClk.set(); // Validate the RevData on the SDA2 line + halfTransition(); + retChar<<=1; // Push each received bit toward MSB + if(call I2CData.get() == 1) retChar+=1; // Read the bit on SDA2 line + halfTransition(); + } + + call I2CClk.clr(); + if (ack) call I2C.masterAck(); + else call I2C.masterNack(); + } + return retChar; + } + + async command void I2C.writeByte(uint8_t byte) + { + uint8_t bitCnt; + + atomic + { + call I2CData.makeOutput(); + + for (bitCnt=0; bitCnt<8; ++bitCnt) + { + if ((byte< + */ +#include "I2C.h" +generic module SoftI2CMasterImplP() +{ + provides interface Resource[uint8_t client]; + provides interface I2CPacket[uint8_t client]; + uses interface Resource as SubResource[uint8_t]; + uses interface I2CPacket as SubPacket; +} +implementation +{ + enum + { + NO_CLIENT = 0xff + }; + + uint8_t currentClient = NO_CLIENT; + + async command error_t Resource.request[uint8_t id]() + { + return call SubResource.request[id](); + } + + async command error_t Resource.immediateRequest[uint8_t id]() + { + error_t rval = call SubResource.immediateRequest[id](); + if (rval == SUCCESS) + { + atomic currentClient = id; + } + return rval; + } + + event void SubResource.granted[uint8_t id]() + { + atomic currentClient = id; + signal Resource.granted[id](); + } + + async command error_t Resource.release[uint8_t id]() + { + return call SubResource.release[id](); + } + + async command bool Resource.isOwner[uint8_t id]() + { + return call SubResource.isOwner[id](); + } + + async command error_t I2CPacket.write[uint8_t id](i2c_flags_t flags, + uint16_t addr, + uint8_t len, + uint8_t* data) + { + atomic + { + if (currentClient != id) + { + return FAIL; + } + } + return call SubPacket.write(flags, addr, len, data); + } + + async command error_t I2CPacket.read[uint8_t id](i2c_flags_t flags, + uint16_t addr, + uint8_t len, + uint8_t* data) + { + atomic + { + if (currentClient != id) + { + return FAIL; + } + } + return call SubPacket.read(flags, addr, len, data); + } + + default event void Resource.granted[uint8_t id]() {} + + async event void SubPacket.readDone( + error_t error, uint16_t addr, uint8_t length, uint8_t* data) + { + signal I2CPacket.readDone[currentClient](error, addr, length, data); + } + + async event void SubPacket.writeDone( + error_t error, uint16_t addr, uint8_t length, uint8_t* data) + { + signal I2CPacket.writeDone[currentClient]( error, addr, length, data); + } + + default async event void I2CPacket.readDone[uint8_t id]( + error_t error, uint16_t addr, uint8_t length, uint8_t* data) { } + + default async event void I2CPacket.writeDone[uint8_t id]( + error_t error, uint16_t addr, uint8_t length, uint8_t* data) { } + +} diff --git a/tos/platforms/mulle/softwarei2c/SoftI2CMasterP.nc b/tos/platforms/mulle/softwarei2c/SoftI2CMasterP.nc new file mode 100755 index 00000000..14de59fa --- /dev/null +++ b/tos/platforms/mulle/softwarei2c/SoftI2CMasterP.nc @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + * @author Philip Levis + */ + +/** + * The configuration that takes the underlying software I2C driver + * Mulle and turns it into a shared abstraction. + * + * @author Henrik Makitaavola + */ + +#include "MulleI2C.h" +#include "I2C.h" +generic configuration SoftI2CMasterP(char resourceName[]) +{ + provides interface Resource[uint8_t client]; + provides interface I2CPacket[uint8_t client]; + uses interface SoftI2CBus; +} +implementation +{ + components new FcfsArbiterC(resourceName) as Arbiter; + components new AsyncPowerManagerP() as Power; + components new SoftI2CMasterImplP() as I2C; + components new SoftI2CMasterPacketP() as Master; + + Resource = I2C; + I2CPacket = I2C; + + I2C.SubResource -> Arbiter; + I2C.SubPacket -> Master; + + Power.AsyncStdControl -> Master; + Power.ResourceDefaultOwner -> Arbiter; + + Master.I2C = SoftI2CBus; +} + diff --git a/tos/platforms/mulle/softwarei2c/SoftI2CMasterPacketP.nc b/tos/platforms/mulle/softwarei2c/SoftI2CMasterPacketP.nc new file mode 100755 index 00000000..ce107f07 --- /dev/null +++ b/tos/platforms/mulle/softwarei2c/SoftI2CMasterPacketP.nc @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + * @author Philip Levis + */ + +/** + * This driver implements an software I2C Master controller. + * + * @author Henrik Makitaavola + */ +#include "I2C.h" +generic module SoftI2CMasterPacketP() +{ + provides interface AsyncStdControl; + provides interface I2CPacket; + + uses interface SoftI2CBus as I2C; +} +implementation +{ + enum + { + I2C_OFF = 0, + I2C_IDLE = 1, + I2C_BUSY = 2, + } soft_i2c_state_t; + + uint8_t state = I2C_OFF; + uint16_t _addr; + uint8_t _len; + uint8_t* _data; + error_t _error; + + task void writeDoneTask() + { + atomic + { + state = I2C_IDLE; + signal I2CPacket.writeDone( _error, _addr, _len, _data); + } + } + + task void readDoneTask() + { + atomic + { + state = I2C_IDLE; + signal I2CPacket.readDone( _error, _addr, _len, _data); + } + } + + async command error_t AsyncStdControl.start() + { + atomic + { + if (state == I2C_OFF) + { + call I2C.init(); + state = I2C_IDLE; + return SUCCESS; + } + else + { + return FAIL; + } + } + } + + async command error_t AsyncStdControl.stop() + { + atomic + { + if (state == I2C_IDLE) + { + call I2C.off(); + state = I2C_OFF; + return SUCCESS; + } + else + { + return FAIL; + } + } + } + + async command error_t I2CPacket.read(i2c_flags_t flags, + uint16_t addr, + uint8_t len, + uint8_t* data) + { + int i; + atomic + { + if (state == I2C_IDLE) + { + state = I2C_BUSY; + } + else if (state == I2C_OFF) + { + + return EOFF; + } + else + { + + return EBUSY; + } + } + atomic + { + if (len < 1) // A 0-length packet with no start and no stop.... + { + state = I2C_IDLE; + return FAIL; + } + + if (flags & I2C_START) + { + call I2C.start(); + call I2C.writeByte(addr+1); + } + + // Read the information. + for (i = 0; i < len-1; ++i) + { + data[i] = call I2C.readByte(true); + } + data[len-1] = call I2C.readByte(I2C_ACK_END); + if (flags & I2C_STOP) + { + call I2C.stop(); + } + + _error = SUCCESS; + _addr = addr; + _len = len; + _data = data; + } + post readDoneTask(); + + return SUCCESS; + } + + async command error_t I2CPacket.write(i2c_flags_t flags, + uint16_t addr, + uint8_t len, + uint8_t* data) + { + int i; + + atomic + { + if (state == I2C_IDLE) + { + state = I2C_BUSY; + } + else if (state == I2C_OFF) + { + return EOFF; + } + else + { + + return EBUSY; + } + } + atomic + { + if (len < 1) // A 0-length packet with no start and no stop.... + { + state = I2C_IDLE; + return FAIL; + } + if (flags & I2C_START) + { + call I2C.start(); + call I2C.writeByte(addr); + } + + // Send information. + for (i = 0; i < len; ++i) + { + call I2C.writeByte(data[i]); + } + + if (flags & I2C_STOP) + { + call I2C.stop(); + } + + _data = data; + _addr = addr; + _len = len; + _error = SUCCESS; + } + post writeDoneTask(); + return SUCCESS; + } + + + +} diff --git a/tos/platforms/mulle/softwarespi/SoftSpiBus.nc b/tos/platforms/mulle/softwarespi/SoftSpiBus.nc new file mode 100755 index 00000000..78ffde72 --- /dev/null +++ b/tos/platforms/mulle/softwarespi/SoftSpiBus.nc @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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 a software Spi bus. + * + * @author Henrik Makitaavola + */ +interface SoftSpiBus +{ + /** + * Initializes bus default state. + */ + async command void init(); + + /** + * Turn the bus off. + */ + async command void off(); + + /** + * Reads a byte from the Spi bus. + * + * @return A byte from the bus. + */ + async command uint8_t readByte(); + + /** + * Writes a byte on th Spi bus. + * + * @param byte the byte to write. + */ + async command void writeByte(uint8_t byte); + + /** + * Read and write a byte to the bus at the same time. + * + * @param byte The byte to write. + * @return Byte read from the bus. + */ + async command uint8_t write(uint8_t byte); +} diff --git a/tos/platforms/mulle/softwarespi/SoftSpiBusP.nc b/tos/platforms/mulle/softwarespi/SoftSpiBusP.nc new file mode 100755 index 00000000..0c61ed84 --- /dev/null +++ b/tos/platforms/mulle/softwarespi/SoftSpiBusP.nc @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Mulle specific implementation of a software Spi bus. + * + * @author Henrik Makitaavola + */ +generic module SoftSpiBusP() +{ + provides interface SoftSpiBus as Spi; + + uses interface GeneralIO as SCLK; + uses interface GeneralIO as MISO; + uses interface GeneralIO as MOSI; +} +implementation +{ + async command void Spi.init() + { + call SCLK.makeOutput(); + call MOSI.makeOutput(); + call MISO.makeInput(); + call SCLK.clr(); + } + + async command void Spi.off() + { + call SCLK.makeInput(); + call MISO.makeInput(); + call MOSI.makeInput(); + call SCLK.clr(); + call MISO.clr(); + call MOSI.clr(); + } + + async command uint8_t Spi.readByte() + { + uint8_t i; + uint8_t data = 0xde; + + atomic + { + for(i=0 ; i < 8; ++i) + { + call SCLK.clr(); + data = (data << 1) | (uint8_t) call MISO.get(); + call SCLK.set(); + } + } + return data; + } + + async command void Spi.writeByte(uint8_t byte) + { + uint8_t i = 8; + atomic + { + for (i = 0; i < 8 ; ++i) + { + if (byte & 0x80) + { + call MOSI.set(); + } + else + { + call MOSI.clr(); + } + call SCLK.clr(); + call SCLK.set(); + byte <<= 1; + } + } + } + + async command uint8_t Spi.write(uint8_t byte) + { + uint8_t data = 0; + uint8_t mask = 0x80; + + atomic do + { + if( (byte & mask) != 0 ) + call MOSI.set(); + else + call MOSI.clr(); + + call SCLK.clr(); + if( call MISO.get() ) + data |= mask; + call SCLK.set(); + } while( (mask >>= 1) != 0 ); + + return data; + } +} diff --git a/tos/platforms/mulle/softwarespi/SoftSpiMasterImplP.nc b/tos/platforms/mulle/softwarespi/SoftSpiMasterImplP.nc new file mode 100755 index 00000000..116e02dd --- /dev/null +++ b/tos/platforms/mulle/softwarespi/SoftSpiMasterImplP.nc @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + * @author Philip Levis + */ + +/** + * The configuration that takes an underlying software SPI on Mulle + * and turns it into a shared abstraction. + * + * @author Henrik Makitaavola + */ + +generic module SoftSpiMasterImplP() +{ + provides interface Resource[uint8_t client]; + provides interface SpiPacket[uint8_t client]; + provides interface SpiByte[uint8_t client]; + uses interface Resource as SubResource[uint8_t]; + uses interface SpiPacket as SubPacket; + uses interface SpiByte as SubByte; +} +implementation +{ + + enum + { + NO_CLIENT = 0xff + }; + + uint8_t currentClient = NO_CLIENT; + + async command error_t Resource.request[uint8_t id]() + { + return call SubResource.request[id](); + } + + async command error_t Resource.immediateRequest[uint8_t id]() + { + error_t rval = call SubResource.immediateRequest[id](); + if (rval == SUCCESS) + { + atomic currentClient = id; + } + return rval; + } + + event void SubResource.granted[uint8_t id]() + { + atomic currentClient = id; + signal Resource.granted[id](); + } + + async command error_t Resource.release[uint8_t id]() + { + return call SubResource.release[id](); + } + + async command bool Resource.isOwner[uint8_t id]() + { + return call SubResource.isOwner[id](); + } + + async command uint8_t SpiByte.write[uint8_t id](uint8_t tx) + { + atomic + { + if (currentClient != id) + { + return FAIL; + } + } + return call SubByte.write(tx); + } + + async command error_t SpiPacket.send[uint8_t id](uint8_t* txBuf, + uint8_t* rxBuf, + uint16_t len ) + { + atomic + { + if (currentClient != id) + { + return FAIL; + } + } + return call SubPacket.send(txBuf, rxBuf, len); + } + + async event void SubPacket.sendDone(uint8_t* txBuf, + uint8_t* rxBuf, + uint16_t len, + error_t error ) + { + signal SpiPacket.sendDone[currentClient](txBuf, rxBuf, len, error); + } + + default async event void SpiPacket.sendDone[uint8_t id](uint8_t* txBuf, + uint8_t* rxBuf, + uint16_t len, + error_t error) {} + + default event void Resource.granted[uint8_t id]() {} + + +} + diff --git a/tos/platforms/mulle/softwarespi/SoftSpiMasterP.nc b/tos/platforms/mulle/softwarespi/SoftSpiMasterP.nc new file mode 100755 index 00000000..e8803cc6 --- /dev/null +++ b/tos/platforms/mulle/softwarespi/SoftSpiMasterP.nc @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + * @author Philip Levis + */ + +/** + * The configuration that takes a underlying software Spi driver + * on Mulle and turns it into a shared abstraction. + * + * @author Henrik Makitaavola + */ + +generic configuration SoftSpiMasterP(char resourceName[]) +{ + provides interface Resource[uint8_t client]; + provides interface SpiPacket[uint8_t client]; + provides interface SpiByte[uint8_t client]; + uses interface SoftSpiBus; +} +implementation +{ + components new FcfsArbiterC(resourceName) as Arbiter; + components new AsyncPowerManagerP() as Power; + components new SoftSpiMasterImplP() as Spi; + components new SoftSpiMasterPacketP() as Master; + + Resource = Spi; + SpiPacket = Spi.SpiPacket; + SpiByte = Spi.SpiByte; + + Spi.SubResource -> Arbiter; + Spi.SubPacket -> Master.SpiPacket; + Spi.SubByte -> Master.SpiByte; + + Power.AsyncStdControl -> Master; + Power.ResourceDefaultOwner -> Arbiter; + + Master.Spi = SoftSpiBus; +} + diff --git a/tos/platforms/mulle/softwarespi/SoftSpiMasterPacketP.nc b/tos/platforms/mulle/softwarespi/SoftSpiMasterPacketP.nc new file mode 100755 index 00000000..87cbab81 --- /dev/null +++ b/tos/platforms/mulle/softwarespi/SoftSpiMasterPacketP.nc @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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. + * + * @author Philip Levis + */ + +/** + * This driver implements an software Spi Master controller. + * + * @author Henrik Makitaavola + */ + +generic module SoftSpiMasterPacketP() +{ + provides interface AsyncStdControl; + provides interface SpiByte; + provides interface SpiPacket; + + uses interface SoftSpiBus as Spi; +} +implementation +{ + enum + { + SPI_OFF = 0, + SPI_IDLE = 1, + SPI_BUSY = 2, + } soft_spi_state_t; + + uint8_t state = SPI_OFF; + + async command error_t AsyncStdControl.start() + { + atomic + { + if (state == SPI_OFF) + { + call Spi.init(); + state = SPI_IDLE; + return SUCCESS; + } + else + { + return FAIL; + } + } + } + + async command error_t AsyncStdControl.stop() + { + atomic + { + if (state == SPI_IDLE) + { + call Spi.off(); + state = SPI_OFF; + return SUCCESS; + } + else + { + return FAIL; + } + } + } + + async command uint8_t SpiByte.write( uint8_t tx ) + { + uint8_t rx; + atomic + { + if (state == SPI_IDLE) + { + state = SPI_BUSY; + } + else if (state == SPI_OFF) + { + return EOFF; + } + else + { + return EBUSY; + } + } + atomic + { + rx = call Spi.write(tx); + state = SPI_IDLE; + } + return rx; + } + + async command error_t SpiPacket.send( uint8_t* txBuf, uint8_t* rxBuf, uint16_t len ) + { + uint8_t i; + atomic + { + if (state == SPI_IDLE) + { + state = SPI_BUSY; + } + else if (state == SPI_OFF) + { + return EOFF; + } + else + { + return EBUSY; + } + } + atomic + { + for(i = 0; i < len; ++i) + { + rxBuf[i] = call Spi.write(txBuf[i]); + } + state = SPI_IDLE; + } + signal SpiPacket.sendDone(txBuf, rxBuf, len, SUCCESS); + return SUCCESS; + } + + default async event void SpiPacket.sendDone( uint8_t* txBuf, + uint8_t* rxBuf, + uint16_t len, + error_t error ) {} +} diff --git a/tos/platforms/mulle/system/LedsP.nc b/tos/platforms/mulle/system/LedsP.nc new file mode 100755 index 00000000..7a9679ab --- /dev/null +++ b/tos/platforms/mulle/system/LedsP.nc @@ -0,0 +1,152 @@ +// $Id$ + +/* + * "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." + */ + +/** + * The implementation of the standard 3 LED mote abstraction. + * + * @author Joe Polastre + * @author Philip Levis + * + * @date March 21, 2005 + */ + +/** + * Mulle needs a slightly different LedsP. + * + * @author Henrik Makitaavola + */ +module LedsP @safe() { + provides { + interface Init; + interface Leds; + } + uses { + interface GeneralIO as Led0; + interface GeneralIO as Led1; + interface GeneralIO as Led2; + } +} +implementation { + command error_t Init.init() { + atomic { + dbg("Init", "LEDS: initialized.\n"); + call Led0.makeOutput(); + call Led1.makeOutput(); + call Led2.makeOutput(); + call Led0.clr(); + call Led1.clr(); + call Led2.clr(); + } + return SUCCESS; + } + + /* Note: the call is inside the dbg, as it's typically a read of a volatile + location, so can't be deadcode eliminated */ +#define DBGLED(n) \ + dbg("LedsC", "LEDS: Led" #n " %s.\n", call Led ## n .get() ? "off" : "on"); + + async command void Leds.led0On() { + call Led0.set(); + DBGLED(0); + } + + async command void Leds.led0Off() { + call Led0.clr(); + DBGLED(0); + } + + async command void Leds.led0Toggle() { + call Led0.toggle(); + DBGLED(0); + } + + async command void Leds.led1On() { + call Led1.set(); + DBGLED(1); + } + + async command void Leds.led1Off() { + call Led1.clr(); + DBGLED(1); + } + + async command void Leds.led1Toggle() { + call Led1.toggle(); + DBGLED(1); + } + + async command void Leds.led2On() { + call Led2.set(); + DBGLED(2); + } + + async command void Leds.led2Off() { + call Led2.clr(); + DBGLED(2); + } + + async command void Leds.led2Toggle() { + call Led2.toggle(); + DBGLED(2); + } + + async command uint8_t Leds.get() { + uint8_t rval; + atomic { + rval = 0; + if (call Led0.get()) { + rval |= LEDS_LED0; + } + if (call Led1.get()) { + rval |= LEDS_LED1; + } + if (call Led2.get()) { + rval |= LEDS_LED2; + } + } + return rval; + } + + async command void Leds.set(uint8_t val) { + atomic { + if (val & LEDS_LED0) { + call Leds.led0On(); + } + else { + call Leds.led0Off(); + } + if (val & LEDS_LED1) { + call Leds.led1On(); + } + else { + call Leds.led1Off(); + } + if (val & LEDS_LED2) { + call Leds.led2On(); + } + else { + call Leds.led2Off(); + } + } + } +} diff --git a/tos/platforms/mulle/timers/AlarmMicro16C.nc b/tos/platforms/mulle/timers/AlarmMicro16C.nc new file mode 100755 index 00000000..4a6cd8a1 --- /dev/null +++ b/tos/platforms/mulle/timers/AlarmMicro16C.nc @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * AlarmMicro16C provides a 16-bit TMicro alarm. + * It uses 1 hw timer that is used as a alarm. + * + * NOTE: It uses the same source clock as the CounterMicro16C. + * + * @author Henrik Makitaavola + */ + +#include "TimerConfig.h" + +configuration AlarmMicro16C +{ + provides interface Alarm; +} +implementation +{ + components new M16c62pAlarm16C(TMicro) as AlarmFrom; + components new M16c62pTimerAInitC(TMR_COUNTER_MODE, M16C_TMRA_TES_TA_PREV, 0, false, false, false) as AlarmInit; + components McuSleepC; + + components HplM16c62pTimerC as Timers, + CounterMicro16C, + RealMainP; + + AlarmFrom -> Timers.ALARM_MICRO16; + AlarmFrom.Counter -> CounterMicro16C; + AlarmFrom.McuPowerState -> McuSleepC; + + AlarmInit -> Timers.ALARM_MICRO16; + AlarmInit -> Timers.ALARM_MICRO16_CTRL; + RealMainP.PlatformInit -> AlarmInit.Init; + Alarm = AlarmFrom; +} + + diff --git a/tos/platforms/mulle/timers/AlarmMicro32C.nc b/tos/platforms/mulle/timers/AlarmMicro32C.nc new file mode 100755 index 00000000..c5c1e308 --- /dev/null +++ b/tos/platforms/mulle/timers/AlarmMicro32C.nc @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * 32-bit microsecond Alarm component as per TEP102 HAL guidelines. + * + * @author Fan Zhang + */ + +generic configuration AlarmMicro32C() +{ + provides interface Alarm; +} +implementation +{ + components AlarmMicro16C as Alarm16, CounterMicro32C as Counter32; + components new TransformAlarmC(TMicro, uint32_t, TMicro, uint16_t, 0) as Transform32; + + Alarm = Transform32; + Transform32.AlarmFrom -> Alarm16; + Transform32.Counter -> Counter32; +} diff --git a/tos/platforms/mulle/timers/BusyWaitMicroC.nc b/tos/platforms/mulle/timers/BusyWaitMicroC.nc new file mode 100755 index 00000000..8dedf6c2 --- /dev/null +++ b/tos/platforms/mulle/timers/BusyWaitMicroC.nc @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Implementation of the HIL required micro busy wait. + * For more information see TEP 102. + * + * @author Henrik Makitaavola + */ +configuration BusyWaitMicroC +{ + provides interface BusyWait; +} +implementation +{ + components CounterMicro16C, + new BusyWaitCounterC(TMicro, uint16_t); + + BusyWait = BusyWaitCounterC; + BusyWaitCounterC.Counter -> CounterMicro16C; +} diff --git a/tos/platforms/mulle/timers/CounterMicro16C.nc b/tos/platforms/mulle/timers/CounterMicro16C.nc new file mode 100755 index 00000000..2a691a4a --- /dev/null +++ b/tos/platforms/mulle/timers/CounterMicro16C.nc @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * CounterMicro16C provides a 16-bit TMicro counter. + * It uses 2 hw timers, one generates a micro tick and the other + * counts the micro ticks. + * + * @author Henrik Makitaavola + * @see Please refer to TEP 102 for more information about this component. + */ + +#include "TimerConfig.h" + +configuration CounterMicro16C +{ + provides interface Counter; +} +implementation +{ + // Counter + components new M16c62pCounter16C(TMicro) as CounterFrom; + components new M16c62pTimerAInitC(TMR_COUNTER_MODE, M16C_TMRA_TES_TA_NEXT, 0xFFFF, true, true, true) as CounterInit; + + // Source + components new M16c62pTimerAInitC(TMR_TIMER_MODE, M16C_TMR_CS_F1_2, (MAIN_CRYSTAL_SPEED - 1), false, true, true) as TimerSourceInit; + + components HplM16c62pTimerC as Timers, + RealMainP, McuSleepC; + + // Counter + CounterFrom.Timer -> Timers.COUNTER_MICRO16; + CounterInit -> Timers.COUNTER_MICRO16; + CounterInit -> Timers.COUNTER_MICRO16_CTRL; + RealMainP.PlatformInit -> CounterInit; + Counter = CounterFrom; + + // Timer source + TimerSourceInit -> Timers.MICRO16_SOURCE; + TimerSourceInit -> Timers.MICRO16_SOURCE_CTRL; + RealMainP.PlatformInit -> TimerSourceInit; + +} diff --git a/tos/platforms/mulle/timers/CounterMicro32C.nc b/tos/platforms/mulle/timers/CounterMicro32C.nc new file mode 100755 index 00000000..3cd55fab --- /dev/null +++ b/tos/platforms/mulle/timers/CounterMicro32C.nc @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * 32-bit microsecond Counter component as per TEP102 HAL guidelines. + * + * @author Fan Zhang + */ + + +configuration CounterMicro32C +{ + provides interface Counter; +} +implementation +{ + components CounterMicro16C as Counter16, + new TransformCounterC(TMicro, uint32_t, TMicro, uint16_t, + 0, uint16_t) as Transform32; + + Counter = Transform32; + Transform32.CounterFrom -> Counter16; +} diff --git a/tos/platforms/mulle/timers/HilTimerMilliC.nc b/tos/platforms/mulle/timers/HilTimerMilliC.nc new file mode 100755 index 00000000..01af75fa --- /dev/null +++ b/tos/platforms/mulle/timers/HilTimerMilliC.nc @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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) 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 + */ + +/** + * HilTimerMilliC provides a parameterized interface to a virtualized + * millisecond timer and local time in milli precision. TimerMilliC in + * tos/system/ uses this component to allocate new timers. + * See TEP 102 for more information. + * + * @author Henrik Makitaavola + */ + +#include "TimerConfig.h" +configuration HilTimerMilliC +{ + provides interface Init; + + provides interface Timer as TimerMilli[ uint8_t num ]; + provides interface LocalTime; +} +implementation +{ + components new AlarmToTimerC(TMilli); + components new VirtualizeTimerC(TMilli,uniqueCount(UQ_TIMER_MILLI)); + components new CounterToLocalTimeC(TMilli); + components HIL_TIMERS as AlarmCounterMilli32C; + + TimerMilli = VirtualizeTimerC; + LocalTime = CounterToLocalTimeC; + + VirtualizeTimerC.TimerFrom -> AlarmToTimerC; + AlarmToTimerC.Alarm -> AlarmCounterMilli32C.Alarm; + CounterToLocalTimeC.Counter -> AlarmCounterMilli32C.Counter; + Init = AlarmCounterMilli32C; +} diff --git a/tos/platforms/mulle/timers/LocalTimeMicroC.nc b/tos/platforms/mulle/timers/LocalTimeMicroC.nc new file mode 100755 index 00000000..b61be3b7 --- /dev/null +++ b/tos/platforms/mulle/timers/LocalTimeMicroC.nc @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008, 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. + * + * Author: Miklos Maroti + */ + +/** + * This configuration provides a local time represented in Micro seconds. + * + * @author Henrik Makitaavola + */ + +#include "Timer.h" + +configuration LocalTimeMicroC +{ + provides interface LocalTime; +} + +implementation +{ + components CounterMicro16C; + components new TransformCounterC(TMicro, uint32_t, TMicro, uint16_t, 0, uint32_t); + components new CounterToLocalTimeC(TMicro); + + LocalTime = CounterToLocalTimeC; + CounterToLocalTimeC.Counter -> TransformCounterC; + TransformCounterC.CounterFrom -> CounterMicro16C; +} diff --git a/tos/platforms/mulle/timers/TimerConfig.h b/tos/platforms/mulle/timers/TimerConfig.h new file mode 100755 index 00000000..eded5300 --- /dev/null +++ b/tos/platforms/mulle/timers/TimerConfig.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * The M16c/62p hardware timer configuration used by Mulle. + * + * STOP MODE ENABLED: + * TB0 bridges its tics from the RV8564 to TB2 in TMilli speed. + * TA0 and TA1 are used to create a 32 bit counter. TA0 counts + * tics from TB2 and TA1 counts TA0 underflows. + * TB0 and TB1 are used to create a 32 bit Alarm. TB0 counts + * tics from TB2 and TB1 counts TB0 underflows. + * + * STOP MODE DISABLED: + * TA0 generates TMilli tics. + * TB0 generates TMilli tics. + * TA1 is a 16 bit counter that counts tics from TA0. + * TB1 is a 16 bit alarm that counts tics from TB0. + * + * ALWAYS USED: + * NOTE: Counter timers are turned off when the mcu goes into stop mode. + * TA3 generates TMicro tics. + * TA2 is a 16 bit TMicro counter that counts tics from TA3. + * TA4 is a 16 bit TMicro alarm that counts tics from TA3. + * TB3 is a 16 bit Radio counter. + * TB4 is a 16 bit Radio alarm. + * + * @author Henrik Makitaavola + */ + +#ifndef __TIMERCONFIG_H__ +#define __TIMERCONFIG_H__ + +#ifdef ENABLE_STOP_MODE + #define HIL_TIMERS RV8564AlarmCounterMilli32C +#else + #define HIL_TIMERS AlarmCounterMilli32C +#endif + +// Use hw timers alone. +#define COUNTER_MILLI32_SOURCE TimerB0 +#define COUNTER_MILLI32_SOURCE_CTRL TimerB0Ctrl +#define COUNTER_MILLI32 TimerB1 +#define COUNTER_MILLI32_CTRL TimerB1Ctrl + +#define ALARM_MILLI32_SOURCE TimerA0 +#define ALARM_MILLI32_SOURCE_CTRL TimerA0Ctrl +#define ALARM_MILLI32 TimerA1 +#define ALARM_MILLI32_CTRL TimerA1Ctrl +// End + +// Use the RV8564 chip to generate tics (stop mode enabled). +#define MILLI32_SOURCE_RV8564 TimerB2 +#define MILLI32_SOURCE_RV8564_CTRL TimerB2Ctrl + +#define COUNTER_MILLI32_LOW TimerA0 +#define COUNTER_MILLI32_LOW_CTRL TimerA0Ctrl +#define COUNTER_MILLI32_HIGH TimerA1 +#define COUNTER_MILLI32_HIGH_CTRL TimerA1Ctrl + +#define ALARM_MILLI32_LOW TimerB0 +#define ALARM_MILLI32_LOW_CTRL TimerB0Ctrl +#define ALARM_MILLI32_HIGH TimerB1 +#define ALARM_MILLI32_HIGH_CTRL TimerB1Ctrl +// end + +// Common settings. +#define COUNTER_MICRO16 TimerA2 +#define COUNTER_MICRO16_CTRL TimerA2Ctrl +#define MICRO16_SOURCE TimerA3 +#define MICRO16_SOURCE_CTRL TimerA3Ctrl +#define ALARM_MICRO16 TimerA4 +#define ALARM_MICRO16_CTRL TimerA4Ctrl + +#define COUNTER_RF23016 TimerB3 +#define COUNTER_RF23016_CTRL TimerB3Ctrl +#define ALARM_RF23016 TimerB4 +#define ALARM_RF23016_CTRL TimerB4Ctrl +// end. + +#endif // __TIMERCONFIG_H__ diff --git a/tos/platforms/mulle/timers/rf230/AlarmRF23016C.nc b/tos/platforms/mulle/timers/rf230/AlarmRF23016C.nc new file mode 100644 index 00000000..aa5d13ec --- /dev/null +++ b/tos/platforms/mulle/timers/rf230/AlarmRF23016C.nc @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * AlarmRF23016C provides a 16-bit TRF230 alarm. + * It uses 1 hw timer that is used as a alarm and runs with + * speed PLL_CLOCK_SPEED / 8. + * + * @author Henrik Makitaavola + */ + +#include "TimerConfig.h" +#include + +configuration AlarmRF23016C +{ + provides interface Alarm; +} +implementation +{ + components new M16c62pAlarm16C(TRadio) as AlarmFrom; + components new M16c62pTimerBInitC(TMR_TIMER_MODE, M16C_TMR_CS_F8, 0, false, false, false) as AlarmInit; + + components HplM16c62pTimerC as Timers, + CounterRF23016C, + RealMainP; + + AlarmFrom -> Timers.ALARM_RF23016; + AlarmFrom.Counter -> CounterRF23016C; + + AlarmInit -> Timers.ALARM_RF23016; + AlarmInit -> Timers.ALARM_RF23016_CTRL; + RealMainP.PlatformInit -> AlarmInit; + Alarm = AlarmFrom; +} + + diff --git a/tos/platforms/mulle/timers/rf230/CounterRF23016C.nc b/tos/platforms/mulle/timers/rf230/CounterRF23016C.nc new file mode 100644 index 00000000..fe34c846 --- /dev/null +++ b/tos/platforms/mulle/timers/rf230/CounterRF23016C.nc @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * CounterRF23016C provides a 16-bit TRF230 counter. + * It uses 1 hw timer that counts in PLL_CLOCK_SPEED / 8. + * + * @author Henrik Makitaavola + */ + +#include "TimerConfig.h" +#include + +configuration CounterRF23016C +{ + provides interface Counter; +} +implementation +{ + components new M16c62pCounter16C(TRadio) as CounterFrom; + components new M16c62pTimerBInitC(TMR_TIMER_MODE, M16C_TMR_CS_F8, 0xFFFF, false, true, true) as CounterInit; + + components HplM16c62pTimerC as Timers, + RealMainP; + + CounterFrom.Timer -> Timers.COUNTER_RF23016; + CounterInit -> Timers.COUNTER_RF23016; + CounterInit -> Timers.COUNTER_RF23016_CTRL; + RealMainP.PlatformInit -> CounterInit; + Counter = CounterFrom; +} diff --git a/tos/platforms/mulle/timers/stop/RV8564AlarmCounterMilli32C.nc b/tos/platforms/mulle/timers/stop/RV8564AlarmCounterMilli32C.nc new file mode 100755 index 00000000..7d30e5cd --- /dev/null +++ b/tos/platforms/mulle/timers/stop/RV8564AlarmCounterMilli32C.nc @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * RV8564AlarmCounterMilli32C provides a 32-bit TMilli alarm and counter. + * The counter and alarm is driven by the RV8564 chip on Mulle. This + * allows the M16c/62p mcu to be put into stop mode even when the timers + * are running. + * + * @author Henrik Makitaavola + * @see Please refer to TEP 102 for more information about this component. + */ + +#include "TimerConfig.h" + +configuration RV8564AlarmCounterMilli32C +{ + provides interface Counter; + provides interface Alarm; + provides interface Init; +} +implementation +{ + components new M16c62pCounter32C(TMilli) as CounterFrom; + components new M16c62pTimerAInitC(TMR_COUNTER_MODE, M16C_TMRA_TES_TB2, 0xFFFF, false, true, true) as CounterInit1; + components new M16c62pTimerAInitC(TMR_COUNTER_MODE, M16C_TMRA_TES_TA_PREV, 0xFFFF, true, true, true) as CounterInit2; + + components new M16c62pAlarm32C(TMilli) as AlarmFrom; + components new M16c62pTimerBInitC(TMR_COUNTER_MODE, M16C_TMRB_CTR_ES_TBj, 0, false, false, true) as AlarmInit1; + components new M16c62pTimerBInitC(TMR_COUNTER_MODE, M16C_TMRB_CTR_ES_TBj, 0, false, false, true) as AlarmInit2; + + components new M16c62pTimerBInitC(TMR_COUNTER_MODE, M16C_TMRB_CTR_ES_TBiIN, 0, false, true, true) as TimerSourceInit; + + components HplM16c62pTimerC as Timers, + RV8564AlarmCounterMilli32P, + HplM16c62pInterruptC as Irqs, + HplM16c62pGeneralIOC as IOs; + + // Setup the IO pin that RV8564 generates the clock to. + RV8564AlarmCounterMilli32P -> IOs.PortP92; + Init = RV8564AlarmCounterMilli32P; + + // Counter + CounterFrom.TimerLow -> Timers.COUNTER_MILLI32_LOW; + CounterFrom.TimerHigh -> Timers.COUNTER_MILLI32_HIGH; + CounterInit1 -> Timers.COUNTER_MILLI32_LOW; + CounterInit1 -> Timers.COUNTER_MILLI32_LOW_CTRL; + CounterInit2 -> Timers.COUNTER_MILLI32_HIGH; + CounterInit2 -> Timers.COUNTER_MILLI32_HIGH_CTRL; + Init = CounterInit1; + Init = CounterInit2; + Counter = CounterFrom; + + // Alarm + AlarmFrom.ATimerLow -> Timers.ALARM_MILLI32_LOW; + AlarmFrom.ATimerHigh -> Timers.ALARM_MILLI32_HIGH; + AlarmFrom.Counter -> CounterFrom; + AlarmInit1 -> Timers.ALARM_MILLI32_LOW; + AlarmInit1 -> Timers.ALARM_MILLI32_LOW_CTRL; + AlarmInit2 -> Timers.ALARM_MILLI32_HIGH; + AlarmInit2 -> Timers.ALARM_MILLI32_HIGH_CTRL; + Init = AlarmInit1; + Init = AlarmInit2; + Alarm = AlarmFrom; + + // Timer source + TimerSourceInit -> Timers.MILLI32_SOURCE_RV8564; + TimerSourceInit -> Timers.MILLI32_SOURCE_RV8564_CTRL; + Init = TimerSourceInit; +} + diff --git a/tos/platforms/mulle/timers/stop/RV8564AlarmCounterMilli32P.nc b/tos/platforms/mulle/timers/stop/RV8564AlarmCounterMilli32P.nc new file mode 100755 index 00000000..0dae1c3b --- /dev/null +++ b/tos/platforms/mulle/timers/stop/RV8564AlarmCounterMilli32P.nc @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * Init the port that the RV8564 chip is generating its tics to (TB0 in). + * + * @author Henrik Makitaavola + */ +module RV8564AlarmCounterMilli32P +{ + provides interface Init; + uses interface GeneralIO as IO; +} +implementation +{ + command error_t Init.init() + { + call IO.makeInput(); + call IO.clr(); + return SUCCESS; + } +} diff --git a/tos/platforms/mulle/timers/wait/AlarmCounterMilli32C.nc b/tos/platforms/mulle/timers/wait/AlarmCounterMilli32C.nc new file mode 100755 index 00000000..f48d7d45 --- /dev/null +++ b/tos/platforms/mulle/timers/wait/AlarmCounterMilli32C.nc @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2009 Communication Group and Eislab at + * Lulea University of Technology + * + * Contact: Laurynas Riliskis, LTU + * Mail: laurynas.riliskis@ltu.se + * 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 Communication Group at Lulea University of Technology + * 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. + */ + +/** + * AlarmCounterMilli32C provides a 32-bit TMilli alarm and counter. + * + * @author Henrik Makitaavola + * @see Please refer to TEP 102 for more information about this component. + */ + +#include "TimerConfig.h" + +configuration AlarmCounterMilli32C +{ + provides interface Counter; + provides interface Alarm; + provides interface Init; +} +implementation +{ + components new M16c62pCounter16C(TMilli) as CounterFrom; + components new M16c62pTimerBInitC(TMR_COUNTER_MODE, M16C_TMRB_CTR_ES_TBj, 0xFFFF, true, true, false) as CounterInit; + components new M16c62pTimerBInitC(TMR_TIMER_MODE, M16C_TMR_CS_F1_2, (1000 * MAIN_CRYSTAL_SPEED) - 1, false, true, true) as CounterSourceInit; + components new TransformCounterC(TMilli,uint32_t, TMilli,uint16_t, 0,uint16_t) as TCounter; + + components new M16c62pAlarm16C(TMilli) as AlarmFrom; + components new M16c62pTimerAInitC(TMR_COUNTER_MODE, M16C_TMRA_TES_TA_PREV, 0, false, false, false) as AlarmInit; + components new M16c62pTimerAInitC(TMR_TIMER_MODE, M16C_TMR_CS_F1_2, (1000 * MAIN_CRYSTAL_SPEED) - 1, false, true, true) as AlarmSourceInit; + components new TransformAlarmC(TMilli,uint32_t,TMilli,uint16_t,0) as TAlarm; + + + components HplM16c62pTimerC as Timers; + + // Counter + CounterFrom.Timer -> Timers.COUNTER_MILLI32; + CounterInit -> Timers.COUNTER_MILLI32; + CounterInit -> Timers.COUNTER_MILLI32_CTRL; + Init = CounterInit; + CounterSourceInit -> Timers.COUNTER_MILLI32_SOURCE; + CounterSourceInit -> Timers.COUNTER_MILLI32_SOURCE_CTRL; + Init = CounterSourceInit; + + // Alarm + AlarmFrom -> Timers.ALARM_MILLI32; + AlarmFrom.Counter -> CounterFrom; + AlarmInit -> Timers.ALARM_MILLI32; + AlarmInit -> Timers.ALARM_MILLI32_CTRL; + Init = AlarmInit.Init; + AlarmSourceInit -> Timers.ALARM_MILLI32_SOURCE; + AlarmSourceInit -> Timers.ALARM_MILLI32_SOURCE_CTRL; + Init = AlarmSourceInit; + + // Transformations + TCounter.CounterFrom -> CounterFrom; + Counter = TCounter; + TAlarm.AlarmFrom -> AlarmFrom; + TAlarm.Counter -> TCounter; + Alarm = TAlarm; +} + -- 2.39.2