From: r-studio Date: Thu, 22 Apr 2010 08:44:30 +0000 (+0000) Subject: Added support for pulling the SDA and SCL pins low on I2C 2 on Mulle when they are... X-Git-Url: https://oss.titaniummirror.com/gitweb?a=commitdiff_plain;h=31ff2c2cf814676d013f819729ee17c1d26f2f29;p=tinyos-2.x.git Added support for pulling the SDA and SCL pins low on I2C 2 on Mulle when they are not in use. This allows the batterymonitor chip to go into sleep. Also added a delay to allow the RTC to startup when used. --- diff --git a/tos/platforms/mulle/chips/ds2782/DS2782InternalC.nc b/tos/platforms/mulle/chips/ds2782/DS2782InternalC.nc index de4d272d..0041b06f 100644 --- a/tos/platforms/mulle/chips/ds2782/DS2782InternalC.nc +++ b/tos/platforms/mulle/chips/ds2782/DS2782InternalC.nc @@ -39,19 +39,25 @@ * * @author Henrik Makitaavola */ -configuration DS2782InternalC { +configuration DS2782InternalC +{ provides interface StdControl; provides interface HplDS2782; } -implementation { - components new SoftwareI2C2C() as I2C; - components new HplDS2782LogicP(0x68) as Logic; - +implementation +{ + components new SoftwareI2C2C() as I2C, + new HplDS2782LogicP(0x68) as Logic, + DS2782InternalP, + HplM16c62pGeneralIOC as IOs; + Logic.I2CPacket -> I2C; Logic.I2CResource -> I2C; HplDS2782 = Logic; - StdControl = Logic; + DS2782InternalP.SDA -> IOs.PortP70; + DS2782InternalP.SCL -> IOs.PortP71; + DS2782InternalP.ResourceDefaultOwner -> I2C; } diff --git a/tos/platforms/mulle/chips/ds2782/DS2782InternalP.nc b/tos/platforms/mulle/chips/ds2782/DS2782InternalP.nc new file mode 100644 index 00000000..5d2b7cbc --- /dev/null +++ b/tos/platforms/mulle/chips/ds2782/DS2782InternalP.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. + */ + +/** + * The DS2782 only goes to sleep if SDA and SCL are pulled low. + * So everytime the default owner of the resource becomes the + * owner of the I2C bus the pins are pulled low. + * + * @author Henrik Makitaavola + */ +module DS2782InternalP +{ + uses interface ResourceDefaultOwner; + uses interface GeneralIO as SDA; + uses interface GeneralIO as SCL; +} +implementation +{ + async event void ResourceDefaultOwner.granted() + { + call SDA.clr(); + call SDA.makeOutput(); + call SCL.clr(); + call SCL.makeOutput(); + } + + async event void ResourceDefaultOwner.requested() + { + call ResourceDefaultOwner.release(); + } + + async event void ResourceDefaultOwner.immediateRequested() + { + call ResourceDefaultOwner.release(); + } +} diff --git a/tos/platforms/mulle/chips/rv8564/HplRV8564C.nc b/tos/platforms/mulle/chips/rv8564/HplRV8564C.nc index 560576ad..0ebcdb98 100755 --- a/tos/platforms/mulle/chips/rv8564/HplRV8564C.nc +++ b/tos/platforms/mulle/chips/rv8564/HplRV8564C.nc @@ -47,10 +47,11 @@ configuration HplRV8564C implementation { components HplRV8564P as RTCP, - new SoftwareI2C2C() as I2C, - HplM16c62pGeneralIOC as IOs, - HplM16c62pInterruptC as Irqs, - new M16c62pInterruptC() as Irq; + new SoftwareI2C2C() as I2C, + HplM16c62pGeneralIOC as IOs, + HplM16c62pInterruptC as Irqs, + new M16c62pInterruptC() as Irq, + BusyWaitMicroC; Irq.HplM16c62pInterrupt -> Irqs.Int0; @@ -60,7 +61,9 @@ implementation RTCP.GpioInterrupt -> Irq; RTCP.I2C -> I2C; RTCP.I2CResource -> I2C; + RTCP.BusyWait -> BusyWaitMicroC; - components PlatformC; + components PlatformC, RealMainP; PlatformC.SubInit -> RTCP.Init; + RealMainP.SoftwareInit -> RTCP.Startup; } diff --git a/tos/platforms/mulle/chips/rv8564/HplRV8564P.nc b/tos/platforms/mulle/chips/rv8564/HplRV8564P.nc index 7db76a52..7a3ee3a1 100755 --- a/tos/platforms/mulle/chips/rv8564/HplRV8564P.nc +++ b/tos/platforms/mulle/chips/rv8564/HplRV8564P.nc @@ -46,6 +46,7 @@ module HplRV8564P { provides interface HplRV8564 as RTC; provides interface Init; + provides interface Init as Startup; uses interface GeneralIO as CLKOE; uses interface GeneralIO as CLKOUT; @@ -53,6 +54,7 @@ module HplRV8564P uses interface GpioInterrupt; uses interface I2CPacket as I2C; uses interface Resource as I2CResource; + uses interface BusyWait; } implementation { @@ -64,13 +66,25 @@ implementation S_WRITING }; norace uint8_t m_state = S_IDLE; - uint8_t m_buf[2]; + norace uint8_t m_buf[2]; command error_t Init.init() { call CLKOUT.makeInput(); call CLKOE.clr(); call CLKOE.makeOutput(); + return SUCCESS; + } + + command error_t Startup.init() + { + int i; + // The RTC needs a maximum of 500ms to startup + for (i = 0; i < 10; ++i) + { + call BusyWait.wait(50000); + } + return SUCCESS; } command void RTC.enableCLKOUT() @@ -145,7 +159,7 @@ implementation { call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 2, m_buf); } - } + } } async event void GpioInterrupt.fired() @@ -157,12 +171,12 @@ implementation { atomic { - if (m_state == S_READING && data == m_buf) + if (m_state == S_READING) { call I2CResource.release(); m_state = S_IDLE; signal RTC.readRegisterDone(error, m_buf[0], m_buf[1]); - } + } } } diff --git a/tos/platforms/mulle/softwarei2c/SharedI2CPacketC.nc b/tos/platforms/mulle/softwarei2c/SharedI2CPacketC.nc index e9d519e5..fd7e271c 100755 --- a/tos/platforms/mulle/softwarei2c/SharedI2CPacketC.nc +++ b/tos/platforms/mulle/softwarei2c/SharedI2CPacketC.nc @@ -80,6 +80,8 @@ generic configuration SharedI2CPacketC(char resourceName[]) { provides interface Resource[uint8_t client]; provides interface I2CPacket[uint8_t client]; + provides interface ResourceDefaultOwner; + uses interface I2CPacket as SubPacket; } implementation @@ -89,6 +91,7 @@ implementation Resource = I2C.Resource; I2CPacket = I2C.I2CPacket; + ResourceDefaultOwner = Arbiter; I2C.SubResource -> Arbiter; I2C.SubPacket = SubPacket; diff --git a/tos/platforms/mulle/softwarei2c/SoftwareI2C2C.nc b/tos/platforms/mulle/softwarei2c/SoftwareI2C2C.nc index ec6a042b..5470e389 100755 --- a/tos/platforms/mulle/softwarei2c/SoftwareI2C2C.nc +++ b/tos/platforms/mulle/softwarei2c/SoftwareI2C2C.nc @@ -50,6 +50,7 @@ generic configuration SoftwareI2C2C() { provides interface Resource; provides interface I2CPacket; + provides interface ResourceDefaultOwner; } implementation { @@ -61,4 +62,5 @@ implementation components SoftwareI2C2P as I2C; Resource = I2C.Resource[CLIENT_ID]; I2CPacket = I2C.I2CPacket[CLIENT_ID]; + ResourceDefaultOwner = I2C; } diff --git a/tos/platforms/mulle/softwarei2c/SoftwareI2C2P.nc b/tos/platforms/mulle/softwarei2c/SoftwareI2C2P.nc index 8d0ed1e9..6e790bc5 100644 --- a/tos/platforms/mulle/softwarei2c/SoftwareI2C2P.nc +++ b/tos/platforms/mulle/softwarei2c/SoftwareI2C2P.nc @@ -47,16 +47,17 @@ configuration SoftwareI2C2P { provides interface Resource[uint8_t client]; provides interface I2CPacket[uint8_t client]; + provides interface ResourceDefaultOwner; } implementation { components new SoftwareI2CPacketC(1000), - HplM16c62pGeneralIOC as IOs, - BusyWaitMicroC, - new SharedI2CPacketC(UQ_MULLE_SOFTWAREI2C_2), - SoftwareI2C2InitP, - PlatformP; - + HplM16c62pGeneralIOC as IOs, + BusyWaitMicroC, + new SharedI2CPacketC(UQ_MULLE_SOFTWAREI2C_2), + SoftwareI2C2InitP, + PlatformP; + // Wire the software I2C bus SoftwareI2CPacketC.SCL -> IOs.PortP71; SoftwareI2CPacketC.SDA -> IOs.PortP70; @@ -64,6 +65,7 @@ implementation Resource = SharedI2CPacketC; I2CPacket = SharedI2CPacketC.I2CPacket; + ResourceDefaultOwner = SharedI2CPacketC; SharedI2CPacketC -> SoftwareI2CPacketC.I2CPacket; // Init the bus