*
* @author Henrik Makitaavola <henrik.makitaavola@gmail.com>
*/
-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;
}
--- /dev/null
+/*
+ * 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 <henrik.makitaavola@gmail.com>
+ */
+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();
+ }
+}
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;
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;
}
{
provides interface HplRV8564 as RTC;
provides interface Init;
+ provides interface Init as Startup;
uses interface GeneralIO as CLKOE;
uses interface GeneralIO as CLKOUT;
uses interface GpioInterrupt;
uses interface I2CPacket<TI2CBasicAddr> as I2C;
uses interface Resource as I2CResource;
+ uses interface BusyWait<TMicro, uint16_t>;
}
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()
{
call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 2, m_buf);
}
- }
+ }
}
async event void GpioInterrupt.fired()
{
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]);
- }
+ }
}
}
{
provides interface Resource[uint8_t client];
provides interface I2CPacket<TI2CBasicAddr>[uint8_t client];
+ provides interface ResourceDefaultOwner;
+
uses interface I2CPacket<TI2CBasicAddr> as SubPacket;
}
implementation
Resource = I2C.Resource;
I2CPacket = I2C.I2CPacket;
+ ResourceDefaultOwner = Arbiter;
I2C.SubResource -> Arbiter;
I2C.SubPacket = SubPacket;
{
provides interface Resource;
provides interface I2CPacket<TI2CBasicAddr>;
+ provides interface ResourceDefaultOwner;
}
implementation
{
components SoftwareI2C2P as I2C;
Resource = I2C.Resource[CLIENT_ID];
I2CPacket = I2C.I2CPacket[CLIENT_ID];
+ ResourceDefaultOwner = I2C;
}
{
provides interface Resource[uint8_t client];
provides interface I2CPacket<TI2CBasicAddr>[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;
Resource = SharedI2CPacketC;
I2CPacket = SharedI2CPacketC.I2CPacket;
+ ResourceDefaultOwner = SharedI2CPacketC;
SharedI2CPacketC -> SoftwareI2CPacketC.I2CPacket;
// Init the bus