]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Cleaned and rewrote the RV8564 interface and module a little.
authorr-studio <r-studio>
Wed, 21 Apr 2010 14:50:06 +0000 (14:50 +0000)
committerr-studio <r-studio>
Wed, 21 Apr 2010 14:50:06 +0000 (14:50 +0000)
tos/platforms/mulle/chips/rv8564/HplRV8564.nc [new file with mode: 0755]
tos/platforms/mulle/chips/rv8564/HplRV8564C.nc [new file with mode: 0755]
tos/platforms/mulle/chips/rv8564/HplRV8564P.nc [new file with mode: 0755]
tos/platforms/mulle/chips/rv8564/RV8564.nc [deleted file]
tos/platforms/mulle/chips/rv8564/RV8564C.nc [deleted file]
tos/platforms/mulle/chips/rv8564/RV8564P.nc [deleted file]

diff --git a/tos/platforms/mulle/chips/rv8564/HplRV8564.nc b/tos/platforms/mulle/chips/rv8564/HplRV8564.nc
new file mode 100755 (executable)
index 0000000..fd14983
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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 <henrik.makitaavola@gmail.com>
+ */
+interface HplRV8564
+{
+  /**
+   * Enables/disables the interrupts generated by the RV8564 chip.
+   */
+  command void enableInterrupt();
+  command void disableInterrupt();
+
+  /**
+   * Enables/disable CLKOUT from the RTC.
+   */
+  command void enableCLKOUT();
+  command void disableCLKOUT();
+
+  /**
+   * Reads from a register.
+   *
+   * @param reg The register to be read.
+   * @return The value of the register.
+   */
+  command error_t readRegister(uint8_t reg);
+
+  /**
+   * Writes to a register.
+   *
+   * @param reg The register that is written to.
+   * @param value The value that is written to the register.
+   */
+  command error_t writeRegister(uint8_t reg, uint8_t value);
+
+  /**
+   * Signals when a register read finished.
+   *
+   * @param val The value read from the register.
+   * @param reg The register the value was read from.
+   */
+  async event void readRegisterDone(error_t error, uint8_t reg, uint8_t val);
+
+  /**
+   * Signals when a register write finished.
+   *
+   * @param reg The register the value was written to.
+   */
+  async event void writeRegisterDone(error_t error, uint8_t reg);
+
+  /**
+   * Signal when an interrupt occurs.
+   */
+  async event void fired();
+}
diff --git a/tos/platforms/mulle/chips/rv8564/HplRV8564C.nc b/tos/platforms/mulle/chips/rv8564/HplRV8564C.nc
new file mode 100755 (executable)
index 0000000..560576a
--- /dev/null
@@ -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.
+ */
+
+/**
+ * Configuration of the RV-8564 Real-time Clock on the Mulle platform.
+ * 
+ * @author Henrik Makitaavola <henrik.makitaavola@gmail.com>
+ */
+
+configuration HplRV8564C
+{
+  provides interface HplRV8564;
+}
+implementation
+{
+  components HplRV8564P as RTCP,
+    new SoftwareI2C2C() as I2C,
+    HplM16c62pGeneralIOC as IOs,
+    HplM16c62pInterruptC as Irqs,
+    new M16c62pInterruptC() as Irq;
+
+  Irq.HplM16c62pInterrupt -> Irqs.Int0;
+
+  HplRV8564 = RTCP;
+  RTCP.CLKOE -> IOs.PortP47;
+  RTCP.CLKOUT -> IOs.PortP92;
+  RTCP.GpioInterrupt -> Irq;
+  RTCP.I2C -> I2C;
+  RTCP.I2CResource -> I2C;
+
+  components PlatformC;
+  PlatformC.SubInit -> RTCP.Init;
+}
diff --git a/tos/platforms/mulle/chips/rv8564/HplRV8564P.nc b/tos/platforms/mulle/chips/rv8564/HplRV8564P.nc
new file mode 100755 (executable)
index 0000000..7db76a5
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * 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 <henrik.makitaavola@gmail.com>
+ */
+
+#include "rv8564.h"
+#include "I2C.h"
+module HplRV8564P
+{
+  provides interface HplRV8564 as RTC;
+  provides interface Init;
+
+  uses interface GeneralIO as CLKOE;
+  uses interface GeneralIO as CLKOUT;
+  uses interface GeneralIO;
+  uses interface GpioInterrupt;
+  uses interface I2CPacket<TI2CBasicAddr> as I2C;
+  uses interface Resource as I2CResource;
+}
+implementation
+{
+
+  enum
+  {
+    S_IDLE,
+    S_READING,
+    S_WRITING
+  };
+  norace uint8_t m_state = S_IDLE;
+  uint8_t m_buf[2];
+
+  command error_t Init.init()
+  {
+    call CLKOUT.makeInput();
+    call CLKOE.clr();
+    call CLKOE.makeOutput();
+  }
+
+  command void RTC.enableCLKOUT()
+  {
+    call CLKOE.set();
+  }
+
+  command void RTC.disableCLKOUT()
+  {
+    call CLKOE.clr();
+  }
+
+  command void RTC.enableInterrupt()
+  {
+    call GpioInterrupt.enableFallingEdge();
+  }
+
+  command void RTC.disableInterrupt()
+  {
+    call GpioInterrupt.disable();
+  }
+
+  command error_t RTC.readRegister(uint8_t reg)
+  {
+    if (m_state != S_IDLE)
+    {  
+      return EBUSY;
+    }
+    m_state = S_READING;
+    m_buf[0] = reg;
+    if (call I2CResource.request() == SUCCESS)
+    {
+      return SUCCESS;
+    }
+    else
+    {
+      m_state = S_IDLE;
+      return FAIL;
+    }
+    return SUCCESS;
+  }
+
+  command error_t RTC.writeRegister(uint8_t reg, uint8_t value)
+  { 
+    if (m_state != S_IDLE)
+    {
+      return FAIL;
+    }
+    m_state = S_WRITING;
+    atomic m_buf[0] = reg;
+    atomic m_buf[1] = value;
+    if (call I2CResource.request() == SUCCESS)
+    {
+      return SUCCESS;
+    }
+    else
+    {
+      m_state = S_IDLE;
+      return FAIL;
+    }
+  }
+
+  event void I2CResource.granted()
+  {
+    atomic
+    {
+      if (m_state == S_READING)
+      {
+        call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 1, m_buf);
+      }
+      else if (m_state == S_WRITING)
+      {
+        call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 2, m_buf);    
+      }
+    }  
+  }
+
+  async event void GpioInterrupt.fired()
+  {
+    signal RTC.fired();
+  }
+
+  async event void I2C.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data)
+  {
+    atomic
+    {
+      if (m_state == S_READING && data == m_buf)
+      {
+        call I2CResource.release();
+        m_state = S_IDLE;
+        signal RTC.readRegisterDone(error, m_buf[0], m_buf[1]);
+      }        
+    }
+  }
+
+  async event void I2C.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data)
+  {
+    if (m_state == S_READING)
+    {
+      if (error != SUCCESS)
+      {
+        call I2CResource.release();
+        m_state = S_IDLE;
+        signal RTC.readRegisterDone(error, m_buf[0], 0);
+        return;
+      }
+      else
+      {
+        call I2C.read(I2C_START | I2C_STOP, RV8564_ADDR, 1, m_buf + 1);
+      }
+    }
+    else if (m_state == S_WRITING)
+    {
+      call I2CResource.release();
+      m_state = S_IDLE;
+      signal RTC.writeRegisterDone(error, m_buf[0]);
+    }
+  }
+}
diff --git a/tos/platforms/mulle/chips/rv8564/RV8564.nc b/tos/platforms/mulle/chips/rv8564/RV8564.nc
deleted file mode 100755 (executable)
index 3004be3..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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 <henrik.makitaavola@gmail.com>
- */
-interface RV8564
-{
-  /**
-   * Turns the chip on.
-   */
-  command error_t on();
-
-  /**
-   * Turns the chip off.
-   */
-  command error_t off();
-
-  /**
-   * Checks if the chip is on.
-   *
-   * @return true if on.
-   */
-  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.
-  command void enableInterrupt();
-  command void disableInterrupt();
-
-  /**
-   * Reads from a register.
-   *
-   * @param reg The register to be read.
-   * @return The value of the register.
-   */
-  command error_t readRegister(uint8_t reg);
-
-  /**
-   * Writes to a register.
-   *
-   * @param reg The register that is written to.
-   * @param value The value that is written to the register.
-   */
-  command error_t writeRegister(uint8_t reg, uint8_t value);
-
-  /**
-   * Signals when a register read finished.
-   *
-   * @param val The value read from the register.
-   * @param reg The register the value was read from.
-   */
-  async event void readRegisterDone(uint8_t val, uint8_t reg);
-
-  /**
-   * Signals when a register write finished.
-   *
-   * @param reg The register the value was written to.
-   */
-  async event void writeRegisterDone(uint8_t reg);
-
-  /**
-   * Signal when an interrupt occurs.
-   */
-  async event void fired();
-  
-  /**
-   * Enables CLKOUT from the RTC.
-   */
-  command void enableCLKOUT();
-}
diff --git a/tos/platforms/mulle/chips/rv8564/RV8564C.nc b/tos/platforms/mulle/chips/rv8564/RV8564C.nc
deleted file mode 100755 (executable)
index 5b101a1..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 <henrik.makitaavola@gmail.com>
- */
-
-configuration RV8564C
-{
-  provides interface RV8564 as RTC;
-}
-implementation
-{
-  components RV8564P as RTCP,
-    new SoftwareI2C2C() as I2C,
-    HplM16c62pGeneralIOC as IOs,
-    HplM16c62pInterruptC as Irqs,
-    new M16c62pInterruptC() as Irq;
-
-  Irq.HplM16c62pInterrupt -> Irqs.Int0;
-
-  RTC = RTCP;
-  RTCP.CLKOE -> IOs.PortP47;
-  RTCP.CLKOUT -> IOs.PortP92;
-  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
deleted file mode 100755 (executable)
index 35c0c0a..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * 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 <henrik.makitaavola@gmail.com>
- */
-
-#include "rv8564.h"
-#include "I2C.h"
-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 as CLKOE;
-  uses interface GeneralIO as CLKOUT;
-  uses interface GeneralIO;
-  uses interface GpioInterrupt;
-  uses interface I2CPacket<TI2CBasicAddr> as I2C;
-  uses interface Resource as I2CResource;
-}
-implementation
-{
-
-  enum
-  {
-    OFF,
-    IDLE,
-    READING,
-    WRITING
-  };
-  norace uint8_t state = OFF;
-  norace uint8_t read_register;
-  uint8_t read_register_value;
-  uint8_t write_buffer[2];
-
-  command error_t RTC.on()
-  {
-    if (state != OFF)
-    {
-      return SUCCESS;
-    }
-    state = IDLE;
-    return SUCCESS;
-  }
-
-  command error_t RTC.off()
-  {
-    if  (state == OFF)
-    {
-      return SUCCESS;
-    }
-    else if (state != IDLE)
-    {
-      return FAIL;
-    }
-    call CLKOE.clr();
-    call CLKOUT.clr();
-    return SUCCESS;
-  }
-
-  command bool RTC.isOn()
-  {
-    return ((state != OFF) ? true : false);
-  }
-
-  command void RTC.enableCLKOUT()
-  {
-       call CLKOUT.makeInput();
-       call CLKOUT.clr();
-       call CLKOE.makeOutput();
-       call CLKOE.set();
-  }
-  command void RTC.enableInterrupt()
-  {
-    call GpioInterrupt.enableFallingEdge();
-  }
-
-  command void RTC.disableInterrupt()
-  {
-    call GpioInterrupt.disable();
-  }
-
-  command error_t RTC.readRegister(uint8_t reg)
-  {
-    uint8_t val;
-    if (state != IDLE)
-    {  
-      return FAIL;
-    }
-    state = READING;
-    read_register = reg;
-    call I2CResource.request();
-    return SUCCESS;
-  }
-
-  command error_t RTC.writeRegister(uint8_t reg, uint8_t value)
-  { 
-    if (state != IDLE)
-    {
-      return FAIL;
-    }
-    state = WRITING;
-    atomic write_buffer[0] = reg;
-    atomic write_buffer[1] = value;
-    call I2CResource.request();
-    return SUCCESS;
-  }
-
-  event void I2CResource.granted()
-  {
-    atomic {
-      if (state == READING)
-      {
-        call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 1, &read_register);
-      }
-      else if (state == WRITING)
-      {
-        call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 2, write_buffer);    
-      }
-    }  
-  }
-
-  async event void GpioInterrupt.fired()
-  {
-    signal RTC.fired();
-  }
-
-  async event void I2C.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data)
-  {
-    atomic
-    {
-      if (state == READING && data == &read_register_value)
-      {
-        state = IDLE;
-        call I2CResource.release();
-        signal RTC.readRegisterDone(read_register_value, read_register);
-      }        
-    }
-  }
-
-  async event void I2C.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data)
-  {
-    if (state == READING)
-    {
-      call I2C.read(I2C_START | I2C_STOP, RV8564_ADDR, 1, &read_register_value);
-    }
-    else if (state == WRITING)
-    {
-      state = IDLE;
-      call I2CResource.release();
-      signal RTC.writeRegisterDone(write_buffer[0]);
-    }
-  }
-
-  default async event void RTC.readRegisterDone(uint8_t val, uint8_t reg) {}
-  default async event void RTC.writeRegisterDone(uint8_t reg) {}
-  default async event void RTC.fired() { }
-}