]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Added support for pulling the SDA and SCL pins low on I2C 2 on Mulle when they are...
authorr-studio <r-studio>
Thu, 22 Apr 2010 08:44:30 +0000 (08:44 +0000)
committerr-studio <r-studio>
Thu, 22 Apr 2010 08:44:30 +0000 (08:44 +0000)
tos/platforms/mulle/chips/ds2782/DS2782InternalC.nc
tos/platforms/mulle/chips/ds2782/DS2782InternalP.nc [new file with mode: 0644]
tos/platforms/mulle/chips/rv8564/HplRV8564C.nc
tos/platforms/mulle/chips/rv8564/HplRV8564P.nc
tos/platforms/mulle/softwarei2c/SharedI2CPacketC.nc
tos/platforms/mulle/softwarei2c/SoftwareI2C2C.nc
tos/platforms/mulle/softwarei2c/SoftwareI2C2P.nc

index de4d272dd70cf16d7d4e6c72b4aeb9cd28b1a391..0041b06f33038eaf52c9e9ab771e4b2736cf0a91 100644 (file)
  * 
  * @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;
 }
diff --git a/tos/platforms/mulle/chips/ds2782/DS2782InternalP.nc b/tos/platforms/mulle/chips/ds2782/DS2782InternalP.nc
new file mode 100644 (file)
index 0000000..5d2b7cb
--- /dev/null
@@ -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 <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();
+  }
+}
index 560576ade11c42874b885df8a8f04b6bc02a3dbb..0ebcdb98673d0b33ef30f707764248e614f60b7b 100755 (executable)
@@ -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;
 }
index 7db76a52614544a55efcecc396247140def20479..7a3ee3a17624055f1e2ab6408c38fb8bfc6ffefd 100755 (executable)
@@ -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<TI2CBasicAddr> as I2C;
   uses interface Resource as I2CResource;
+  uses interface BusyWait<TMicro, uint16_t>;
 }
 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]);
-      }        
+      }
     }
   }
 
index e9d519e5037f1c401bd779322d0791c84757ef20..fd7e271c4cb6481b8388d72e962f4e5dd038c20b 100755 (executable)
@@ -80,6 +80,8 @@ generic configuration SharedI2CPacketC(char resourceName[])
 {
   provides interface Resource[uint8_t client];
   provides interface I2CPacket<TI2CBasicAddr>[uint8_t client];
+  provides interface ResourceDefaultOwner;
+  
   uses interface I2CPacket<TI2CBasicAddr> as SubPacket;
 }
 implementation
@@ -89,6 +91,7 @@ implementation
     
   Resource  = I2C.Resource;
   I2CPacket = I2C.I2CPacket;
+  ResourceDefaultOwner = Arbiter;
   
   I2C.SubResource -> Arbiter;
   I2C.SubPacket   = SubPacket;
index ec6a042bfeaeac34f99a761ccfadfb3d7a068635..5470e38937ea28facf9f661a171a49a8570f7f5d 100755 (executable)
@@ -50,6 +50,7 @@ generic configuration SoftwareI2C2C()
 {
   provides interface Resource;
   provides interface I2CPacket<TI2CBasicAddr>;
+  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;
 }
index 8d0ed1e94de3621db75f5caed43f37d5f681b5c6..6e790bc59ce23b458aacfa1379a0bf353f48c404 100644 (file)
@@ -47,16 +47,17 @@ configuration SoftwareI2C2P
 {
   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;
@@ -64,6 +65,7 @@ implementation
 
   Resource  = SharedI2CPacketC;
   I2CPacket = SharedI2CPacketC.I2CPacket;
+  ResourceDefaultOwner = SharedI2CPacketC;
   SharedI2CPacketC -> SoftwareI2CPacketC.I2CPacket;
 
   // Init the bus