From: r-studio Date: Thu, 5 Nov 2009 12:02:07 +0000 (+0000) Subject: nativ tos PrintF support, demosensors based on accelerometer, better low power X-Git-Tag: rc_6_tinyos_2_1_1~152 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=3a993e16707c4fde0d1df1f2826205563ca980e1 nativ tos PrintF support, demosensors based on accelerometer, better low power --- diff --git a/tos/chips/m16c62p/pins/HplM16c62pGeneralIOPinPRC2P.nc b/tos/chips/m16c62p/pins/HplM16c62pGeneralIOPinPRC2P.nc new file mode 100755 index 00000000..bea643e9 --- /dev/null +++ b/tos/chips/m16c62p/pins/HplM16c62pGeneralIOPinPRC2P.nc @@ -0,0 +1,80 @@ +/* + * 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. + */ + +/** + * Generic pin access for pins on the P9 port. The PD9 register + * is locked by the PRC2 bit in the PRCR register so it needs + * to be unlocked before each access. + * + * @author Henrik Makitaavola + */ + +generic module HplM16c62pGeneralIOPinPRC2P() +{ + provides interface GeneralIO as IO; + + uses interface GeneralIO as Wrap; +} +implementation +{ + + inline async command bool IO.get() { return call Wrap.get(); } + inline async command void IO.set() { call Wrap.set(); } + inline async command void IO.clr() { call Wrap.clr(); } + inline async command void IO.toggle() { call Wrap.toggle(); } + + inline async command void IO.makeInput() + { + atomic + { + PRCR.BYTE = BIT2; + call Wrap.makeInput(); + } + } + + inline async command bool IO.isInput() { return call Wrap.isInput(); } + inline async command void IO.makeOutput() + { + atomic + { + PRCR.BYTE = BIT2; + call Wrap.makeOutput(); + } + } + + inline async command bool IO.isOutput() { return call Wrap.isOutput(); } +} + diff --git a/tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlashC.nc b/tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlashC.nc index 49d6ffd5..bc8255d0 100644 --- a/tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlashC.nc +++ b/tos/lib/net/Deluge/extra/m16c62p/HplM16c62pFlashC.nc @@ -187,14 +187,14 @@ command uint8_t HplM16c62pFlash.FlashWrite( unsigned long flash_addr, "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 #0x0040, r1\n\t" // Send write command + "ste.w r1, [a1a0]\n\t" - "mov.w %[data], r0\n\t" // Write data - "ste.w r0, [a1a0]\n\t" + "mov.w %[data], r1\n\t" // Write data + "ste.w r1, [a1a0]\n\t" : :[low] "r" (low), [high] "r" (high), [data] "r" (*buffer_addr) - : "memory", "r0", "a1", "a0"); + : "memory", "a1", "a0", "r1"); // Note: In EW1 Mode, the MCU is suspended until the operation completed @@ -238,4 +238,4 @@ command uint8_t HplM16c62pFlash.FlashRead(unsigned long address) { : "memory", "a0", "a1"); return data; } -} \ No newline at end of file +} diff --git a/tos/lib/printf/PrintfP.nc b/tos/lib/printf/PrintfP.nc index 01219e07..2ebed371 100644 --- a/tos/lib/printf/PrintfP.nc +++ b/tos/lib/printf/PrintfP.nc @@ -169,6 +169,9 @@ implementation { #endif #ifdef _H_atmega128hardware_H int uart_putchar(char c, FILE *stream) __attribute__((noinline)) @C() @spontaneous() { +#endif +#ifdef __M16C62PHARDWARE_H__ + int lowlevel_putc(int c) __attribute__((noinline)) @C() @spontaneous() { #endif if((state == S_STARTED) && (call Queue.size() >= ((PRINTF_BUFFER_SIZE)/2))) { state = S_FLUSHING; diff --git a/tos/platforms/mulle/.platform b/tos/platforms/mulle/.platform index 932d67fa..0ecae8e1 100755 --- a/tos/platforms/mulle/.platform +++ b/tos/platforms/mulle/.platform @@ -5,13 +5,14 @@ push( @includes, qw( %T/chips/rf2xx/layers %T/chips/rf2xx/util %T/chips/at45db + %T/platforms/mulle/button %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/chips/mma7261qt - %T/platforms/mulle/debug + %T/platforms/mulle/chips/ds2745 %T/platforms/mulle/system %T/platforms/mulle/timers %T/platforms/mulle/timers/stop @@ -23,6 +24,7 @@ push( @includes, qw( %T/chips/m16c62p/pins %T/chips/m16c62p/timer %T/chips/m16c62p/uart + %T/chips/m16c62p/printf %T/chips/mma7261qt %T/chips/ds2745 %T/lib/power diff --git a/tos/platforms/mulle/DemoSensorC.nc b/tos/platforms/mulle/DemoSensorC.nc index 568bb9ed..3c88114e 100755 --- a/tos/platforms/mulle/DemoSensorC.nc +++ b/tos/platforms/mulle/DemoSensorC.nc @@ -35,29 +35,28 @@ */ /** - * A dumb demo sensor used for testing. + * Demo sensor that connects to the AN0 channel on the MCU. This can + * easily be used together with the potentiometer on the Mulle + * expansionboard. * * @author Henrik Makitaavola */ -generic module DemoSensorC() +generic configuration 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 ) {} + components new AdcReadClientC(), DemoSensorP, + HplM16c62pGeneralIOC as IOs, + RealMainP; + + DemoSensorP.Pin -> IOs.PortP100; + DemoSensorP.AVcc -> IOs.PortP76; + + Read = AdcReadClientC; + + AdcReadClientC.M16c62pAdcConfig -> DemoSensorP; + + RealMainP.PlatformInit -> DemoSensorP; } diff --git a/tos/platforms/mulle/DemoSensorNowC.nc b/tos/platforms/mulle/DemoSensorNowC.nc new file mode 100644 index 00000000..22b60e3c --- /dev/null +++ b/tos/platforms/mulle/DemoSensorNowC.nc @@ -0,0 +1,27 @@ +/** + * Demo sensor for the mica2 platform. + * + * @author Henrik Makitaavola + */ + +generic configuration DemoSensorNowC() +{ + provides interface Resource; + provides interface ReadNow; +} +implementation { + components new AdcReadNowClientC(), + DemoSensorP, + HplM16c62pGeneralIOC as IOs, + RealMainP; + + DemoSensorP.Pin -> IOs.PortP100; + DemoSensorP.AVcc -> IOs.PortP76; + + ReadNow = AdcReadNowClientC; + Resource = AdcReadNowClientC; + + AdcReadNowClientC.M16c62pAdcConfig -> DemoSensorP; + + RealMainP.PlatformInit -> DemoSensorP; +} diff --git a/tos/platforms/mulle/DemoSensorP.nc b/tos/platforms/mulle/DemoSensorP.nc new file mode 100644 index 00000000..d3242d7d --- /dev/null +++ b/tos/platforms/mulle/DemoSensorP.nc @@ -0,0 +1,36 @@ +module DemoSensorP +{ + provides interface M16c62pAdcConfig; + provides interface Init; + + uses interface GeneralIO as Pin; + uses interface GeneralIO as AVcc; +} +implementation +{ + command error_t Init.init() + { + call Pin.makeInput(); + // TODO(henrik) This Vref should be turned on in connection to the A/D + // converter code and not here. + // Turn on the Vref + call AVcc.makeOutput(); + call AVcc.set(); + } + + async command uint8_t M16c62pAdcConfig.getChannel() + { + // select the AN0 = P10_0 to potentiometer on the expansion board. + return M16c62p_ADC_CHL_AN0; + } + + async command uint8_t M16c62pAdcConfig.getPrecision() + { + return M16c62p_ADC_PRECISION_10BIT; + } + + async command uint8_t M16c62pAdcConfig.getPrescaler() + { + return M16c62p_ADC_PRESCALE_4; + } +} diff --git a/tos/platforms/mulle/DemoSensorStreamC.nc b/tos/platforms/mulle/DemoSensorStreamC.nc new file mode 100644 index 00000000..43c50ea4 --- /dev/null +++ b/tos/platforms/mulle/DemoSensorStreamC.nc @@ -0,0 +1,34 @@ +/* $Id$ + * Copyright (c) 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. + */ +/** + * Demo sensor for the mica2 platform. + * + * @author David Gay + */ + +generic configuration DemoSensorStreamC() +{ + provides interface ReadStream; +} +implementation { + components new AdcReadStreamClientC(), + DemoSensorP, + HplM16c62pGeneralIOC as IOs, + RealMainP; + + DemoSensorP.Pin -> IOs.PortP100; + DemoSensorP.AVcc -> IOs.PortP76; + + ReadStream = AdcReadStreamClientC; + + AdcReadStreamClientC.M16c62pAdcConfig -> DemoSensorP; + + RealMainP.PlatformInit -> DemoSensorP; +} diff --git a/tos/platforms/mulle/PlatformP.nc b/tos/platforms/mulle/PlatformP.nc index c4025efb..733d112f 100755 --- a/tos/platforms/mulle/PlatformP.nc +++ b/tos/platforms/mulle/PlatformP.nc @@ -65,6 +65,7 @@ implementation call StopModeControl.allowStopMode(true); // Activate the RTC and set it to output 1024 tics on the CLKOUT pin. call RTC.on(); + call RTC.enableCLKOUT(); call RTC.writeRegister(RV8564_CLKF, 0x81); #else call StopModeControl.allowStopMode(false); @@ -79,5 +80,7 @@ implementation } #ifdef ENABLE_STOP_MODE async event void RTC.fired() {} + async event void RTC.readRegisterDone(uint8_t val, uint8_t reg) {} + async event void RTC.writeRegisterDone(uint8_t reg) {} #endif } diff --git a/tos/platforms/mulle/PlatformSerialC.nc b/tos/platforms/mulle/PlatformSerialC.nc index 452c272e..2b3cf7c6 100755 --- a/tos/platforms/mulle/PlatformSerialC.nc +++ b/tos/platforms/mulle/PlatformSerialC.nc @@ -50,12 +50,17 @@ configuration PlatformSerialC { implementation { components M16c62pUartC as Uart, - CounterMicro16C; + PlatformSerialP, CounterMicro16C; - StdControl = Uart.StdControl1; + StdControl = PlatformSerialP; + PlatformSerialP -> Uart.Uart1Control; UartStream = Uart.Uart1Stream; UartByte = Uart.Uart1Byte; Uart.Counter -> CounterMicro16C; + components MainC; + + MainC.SoftwareInit -> PlatformSerialP; + } diff --git a/tos/platforms/mulle/PlatformSerialP.nc b/tos/platforms/mulle/PlatformSerialP.nc new file mode 100644 index 00000000..81c8e11b --- /dev/null +++ b/tos/platforms/mulle/PlatformSerialP.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. + */ + +/** + * Initialization of the PlatformSerial uart and a StdControl implementation + * for it. + * + * @author Henrik Makitaavola + */ + +module PlatformSerialP +{ + provides interface StdControl; + provides interface Init; + + uses interface UartControl; +} +implementation +{ + command error_t Init.init() { + call UartControl.setParity(TOS_UART_PARITY_NONE); + call UartControl.setNoStop(); + call UartControl.setSpeed(TOS_UART_57600); + return SUCCESS; + } + + + command error_t StdControl.start() + { + call UartControl.setDuplexMode(TOS_UART_DUPLEX); + return SUCCESS; + } + + command error_t StdControl.stop() + { + call UartControl.setDuplexMode(TOS_UART_OFF); + return SUCCESS; + } +} diff --git a/tos/platforms/mulle/timers/AlarmMicro16C.nc b/tos/platforms/mulle/timers/AlarmMicro16C.nc index 4a6cd8a1..bf62fad2 100755 --- a/tos/platforms/mulle/timers/AlarmMicro16C.nc +++ b/tos/platforms/mulle/timers/AlarmMicro16C.nc @@ -53,7 +53,6 @@ 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, @@ -61,7 +60,6 @@ implementation AlarmFrom -> Timers.ALARM_MICRO16; AlarmFrom.Counter -> CounterMicro16C; - AlarmFrom.McuPowerState -> McuSleepC; AlarmInit -> Timers.ALARM_MICRO16; AlarmInit -> Timers.ALARM_MICRO16_CTRL;