--- /dev/null
+/**
+ * The DS2745 works well to be used with the DS2782 chip on the Mulle.
+ *
+ * @author Henrik Makitaavola <henrik.makitaavola@gmail.com>
+ */
+
+// TODO(henrik) Clean and comment this code better. Also Make the chip request
+// access to the I2C bus instead of how its now that the program
+// needs to request it.
+configuration DS2745InternalC {
+ provides interface SplitControl;
+ provides interface Resource;
+ provides interface HplDS2745;
+}
+
+implementation {
+ components MainC;
+
+ components new SoftI2CBatteryMonitorRTCC() as I2C;
+ Resource = I2C;
+
+ components new HplDS2745LogicP(0x68) as Logic;
+ MainC.SoftwareInit -> Logic;
+ Logic.I2CPacket -> I2C;
+ HplDS2745 = Logic;
+
+ SplitControl = Logic;
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2005-2006 Arch Rock Corporation
+ * 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 the Arched Rock Corporation 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 THE
+ * ARCHED ROCK 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
+ */
+
+/**
+ *
+ * @author Phil Buonadonna <pbuonadonna@archrock.com>
+ * @version $Revision$ $Date$
+ */
+
+module DS2745InternalP {
+ provides interface HplDS2745[uint8_t id];
+ uses interface HplDS2745 as ToHPLC;
+}
+
+implementation {
+ uint8_t currentId;
+
+ command error_t HplDS2745.setConfig[uint8_t id](uint8_t val) {
+ currentId = id;
+ return call ToHPLC.setConfig(val);
+ }
+ command error_t HplDS2745.measureTemperature[uint8_t id]() {
+ currentId = id;
+ return call ToHPLC.measureTemperature();
+ }
+ command error_t HplDS2745.measureVoltage[uint8_t id]() {
+ currentId = id;
+ return call ToHPLC.measureVoltage();
+ }
+ command error_t HplDS2745.measureCurrent[uint8_t id]() {
+ currentId = id;
+ return call ToHPLC.measureCurrent();
+ }
+ command error_t HplDS2745.measureAccCurrent[uint8_t id]() {
+ currentId = id;
+ return call ToHPLC.measureAccCurrent();
+ }
+ command error_t HplDS2745.setOffsetBias[uint8_t id](int8_t val) {
+ currentId = id;
+ return call ToHPLC.setOffsetBias(val);
+ }
+ command error_t HplDS2745.setAccOffsetBias[uint8_t id](int8_t val) {
+ currentId = id;
+ return call ToHPLC.setAccOffsetBias(val);
+ }
+
+ async event void ToHPLC.setConfigDone(error_t error) {
+ signal HplDS2745.setConfigDone[currentId](error);
+ }
+ async event void ToHPLC.measureTemperatureDone(error_t result, uint16_t val) {
+ signal HplDS2745.measureTemperatureDone[currentId](result, val);
+ }
+ async event void ToHPLC.measureVoltageDone(error_t result, uint16_t val) {
+ signal HplDS2745.measureVoltageDone[currentId](result, val);
+ }
+ async event void ToHPLC.measureCurrentDone(error_t result, uint16_t val) {
+ signal HplDS2745.measureCurrentDone[currentId](result, val);
+ }
+ async event void ToHPLC.measureAccCurrentDone(error_t result, uint16_t val) {
+ signal HplDS2745.measureAccCurrentDone[currentId](result, val);
+ }
+ async event void ToHPLC.setOffsetBiasDone(error_t error) {
+ signal HplDS2745.setOffsetBiasDone[currentId](error);
+ }
+ async event void ToHPLC.setAccOffsetBiasDone(error_t error) {
+ signal HplDS2745.setAccOffsetBiasDone[currentId](error);
+ }
+
+ default async event void HplDS2745.setConfigDone[uint8_t id]( error_t error ){ return; }
+ default async event void HplDS2745.measureTemperatureDone[uint8_t id]( error_t error, uint16_t val ){ return; }
+ default async event void HplDS2745.measureVoltageDone[uint8_t id]( error_t error, uint16_t val ){ return; }
+ default async event void HplDS2745.measureCurrentDone[uint8_t id]( error_t error, uint16_t val ){ return; }
+ default async event void HplDS2745.measureAccCurrentDone[uint8_t id]( error_t error, uint16_t val ){ return; }
+ default async event void HplDS2745.setOffsetBiasDone[uint8_t id]( error_t error ){ return; }
+ default async event void HplDS2745.setAccOffsetBiasDone[uint8_t id](error_t error){ return; }
+
+}
+
+
-module M16c62pAdcPlatformC
+/*
+ * 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.
+ */
+
+/**
+ * Mulle specific implementation of the M16c62pAdcPlatform interface.
+ *
+ * @author Henrik Makitaavola <henrik.makitaavola@gmail.com>
+ */
+configuration M16c62pAdcPlatformC
{
provides interface M16c62pAdcPlatform;
}
implementation
{
- async command void M16c62pAdcPlatform.adcOn()
- {
- // turn on AVcc
- PD7.BIT.PD7_6 = 1;
- P7.BIT.P7_6 = 1;
-
- // turn on AVref
- PD3.BIT.PD3_1 = 1;
- P3.BIT.P3_1 = 1;
- }
-
- async command void M16c62pAdcPlatform.adcOff()
- {
-// // turn off AVcc
-// PD7.BIT.PD7_6 = 0;
-// P7.BIT.P7_6 = 0;
-//
-// // turn off AVref
-// PD3.BIT.PD3_1 = 0;
-// P3.BIT.P3_1 = 0;
- }
-}
\ No newline at end of file
+ components M16c62pAdcPlatformP, HplM16c62pGeneralIOC as IOs;
+
+ M16c62pAdcPlatform = M16c62pAdcPlatformP;
+ M16c62pAdcPlatformP -> IOs.PortP76;
+}
--- /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.
+ */
+
+/**
+ * Mulle specific implementation of the M16c62pAdcPlatform interface.
+ *
+ * @author Henrik Makitaavola <henrik.makitaavola@gmail.com>
+ */
+module M16c62pAdcPlatformP
+{
+ provides interface M16c62pAdcPlatform;
+ uses interface GeneralIO VRef;
+}
+implementation
+{
+ async command void M16c62pAdcPlatform.adcOn()
+ {
+ call VRef.makeOutput();
+ call VRef.set();
+ }
+
+ async command void M16c62pAdcPlatform.adcOff()
+ {
+ call VRef.clr();
+ }
+}
{
command error_t SplitControl.start()
{
+#ifndef RF230_SLOW_SPI
call SystemClockControl.minSpeed(M16C62P_PLL_CLOCK);
+#endif
return call SplitControlOrig.start();
}
event void SplitControlOrig.startDone(error_t error)
{
+#ifndef RF230_SLOW_SPI
if (error != SUCCESS)
{
call SystemClockControl.minSpeed(M16C62P_DONT_CARE);
}
+#endif
signal SplitControl.startDone(error);
}
event void SplitControlOrig.stopDone(error_t error)
{
+#ifndef RF230_SLOW_SPI
if (error == SUCCESS)
{
call SystemClockControl.minSpeed(M16C62P_DONT_CARE);
}
+#endif
signal SplitControl.stopDone(error);
}
}
#define __RADIOCONFIG_H__
#include <RF230DriverLayer.h>
-
+#include "Timer.h"
enum
{
/**
* Turns the chip on.
*/
- async command void on();
+ command error_t on();
/**
* Turns the chip off.
*/
- async command void off();
+ command error_t off();
/**
* Checks if the chip is on.
*
* @return true if on.
*/
- async command bool isOn();
+ 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.
- async command void enableInterrupt();
- async command void disableInterrupt();
+ command void enableInterrupt();
+ command void disableInterrupt();
/**
* Reads from a register.
* @param reg The register to be read.
* @return The value of the register.
*/
- async command uint8_t readRegister(uint16_t reg);
+ 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.
*/
- async command void writeRegister(uint16_t reg, uint8_t value);
-
+ 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();
}
Irq.HplM16c62pInterrupt -> Irqs.Int0;
RTC = RTCP;
- RTCP -> IOs.PortP47;
+ RTCP.CLKOE -> IOs.PortP47;
+ RTCP.CLKOUT -> IOs.PortP92;
RTCP.GpioInterrupt -> Irq;
RTCP.I2C -> I2C;
RTCP.I2CResource -> I2C;
#include "rv8564.h"
#include "I2C.h"
-// TODO(henrik) The request to the I2C is done throuh a immediateRequest, this perhaps needs to be changed because
-// its bad if the battery monitor has hold of the I2C bus.
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;
}
implementation
{
- async command void RTC.on()
+
+ 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()
{
- call GeneralIO.makeOutput();
- call GeneralIO.set();
+ if (state != OFF)
+ {
+ return SUCCESS;
+ }
+ state = IDLE;
+ return SUCCESS;
}
- async command void RTC.off()
+ command error_t RTC.off()
{
- call GeneralIO.clr();
- call GeneralIO.makeInput();
+ if (state == OFF)
+ {
+ return SUCCESS;
+ }
+ else if (state != IDLE)
+ {
+ return FAIL;
+ }
+ call CLKOE.clr();
+ call CLKOUT.clr();
+ return SUCCESS;
}
- async command bool RTC.isOn()
+ command bool RTC.isOn()
{
- return (call GeneralIO.get() && call GeneralIO.isOutput());
+ return ((state != OFF) ? true : false);
}
- async command void RTC.enableInterrupt()
+ command void RTC.enableCLKOUT()
+ {
+ call CLKOUT.makeInput();
+ call CLKOUT.clr();
+ call CLKOE.makeOutput();
+ call CLKOE.set();
+ }
+ command void RTC.enableInterrupt()
{
call GpioInterrupt.enableFallingEdge();
}
- async command void RTC.disableInterrupt()
+ command void RTC.disableInterrupt()
{
call GpioInterrupt.disable();
}
-
- async command uint8_t RTC.readRegister(uint16_t reg)
+
+ command error_t RTC.readRegister(uint8_t reg)
{
uint8_t val;
- atomic
+ 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)
{
- if (call I2CResource.immediateRequest() == SUCCESS)
+ return FAIL;
+ }
+ state = WRITING;
+ write_buffer[0] = reg;
+ write_buffer[1] = value;
+ call I2CResource.request();
+ return SUCCESS;
+ }
+
+ event void I2CResource.granted()
+ {
+ atomic {
+ if (state == READING)
{
- call I2C.write(I2C_START, RV8564_WR_ADDR, 1, (uint8_t*)®);
- call I2C.read(I2C_START | I2C_STOP, RV8564_RD_ADDR, 1, &val);
- call I2CResource.release();
+ call I2C.write(I2C_START, RV8564_ADDR, 1, &read_register);
}
- }
- return val;
+ else if (state == WRITING)
+ {
+ call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 2, write_buffer);
+ }
+ }
}
- async command void RTC.writeRegister(uint16_t reg, uint8_t value)
+ 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)
{
- uint8_t wr[2] = {reg, value};
atomic
{
- if (call I2CResource.immediateRequest() == SUCCESS)
+ if (state == READING && data == &read_register_value)
{
- call I2C.write(I2C_START | I2C_STOP, RV8564_WR_ADDR, 2, wr);
+ state = IDLE;
call I2CResource.release();
- }
+ signal RTC.readRegisterDone(read_register_value, read_register);
+ }
}
}
- event void I2CResource.granted()
+ async event void I2C.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data)
{
- // TODO(henrik) Insert communication code here.
- }
-
- async event void GpioInterrupt.fired()
- {
- signal RTC.fired();
+ 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.fired() { }
- async event void I2C.readDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) {}
- async event void I2C.writeDone(error_t error, uint16_t addr, uint8_t length, uint8_t* data) {}
+ 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() { }
}
#define __RV8564_H__
/* constants */
-#define RV8564_WR_ADDR 0xa2 //slave address write 0xa2 or read 0xa3
-#define RV8564_RD_ADDR 0xa3
+#define RV8564_ADDR 0xa2 //slave address
#define RV8564_CS1 0x00
}
call I2CClk.clr();
- if (ack) call I2C.masterAck();
- else call I2C.masterNack();
+ if (ack)
+ {
+ call I2C.masterAck();
+ }
+ else
+ {
+ call I2C.masterNack();
+ }
}
return retChar;
}
transition();
call I2CClk.clr();
- // ...Check the ACK from the receiver....
-
- // if(SDA2==1){ACK=0;} /* ACK received£¿*/
- // else ACK= 1;
-
- // SCL2 = LOW;
- // transition();
idle();
}
}
{
atomic
{
+ call I2CData.makeOutput();
call I2CClk.clr();
call I2CData.clr(); // Low for ack
transition();
{
atomic
{
+ call I2CData.makeOutput();
call I2CClk.clr();
call I2CData.set(); // High for nack