From 0c5481263d4283c74dc3d8773cb6b97ad02e452d Mon Sep 17 00:00:00 2001 From: r-studio Date: Wed, 21 Apr 2010 14:50:06 +0000 Subject: [PATCH] Cleaned and rewrote the RV8564 interface and module a little. --- .../chips/rv8564/{RV8564.nc => HplRV8564.nc} | 36 ++--- .../rv8564/{RV8564C.nc => HplRV8564C.nc} | 11 +- .../rv8564/{RV8564P.nc => HplRV8564P.nc} | 134 +++++++++--------- 3 files changed, 82 insertions(+), 99 deletions(-) rename tos/platforms/mulle/chips/rv8564/{RV8564.nc => HplRV8564.nc} (82%) rename tos/platforms/mulle/chips/rv8564/{RV8564C.nc => HplRV8564C.nc} (92%) rename tos/platforms/mulle/chips/rv8564/{RV8564P.nc => HplRV8564P.nc} (63%) diff --git a/tos/platforms/mulle/chips/rv8564/RV8564.nc b/tos/platforms/mulle/chips/rv8564/HplRV8564.nc similarity index 82% rename from tos/platforms/mulle/chips/rv8564/RV8564.nc rename to tos/platforms/mulle/chips/rv8564/HplRV8564.nc index 3004be35..fd14983c 100755 --- a/tos/platforms/mulle/chips/rv8564/RV8564.nc +++ b/tos/platforms/mulle/chips/rv8564/HplRV8564.nc @@ -39,32 +39,19 @@ * * @author Henrik Makitaavola */ -interface RV8564 +interface HplRV8564 { /** - * Turns the chip on. + * Enables/disables the interrupts generated by the RV8564 chip. */ - 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(); + command void enableInterrupt(); + command void disableInterrupt(); /** - * Enables/disables the interrupts generated by the CLKOUT. + * Enables/disable CLKOUT from the RTC. */ - // TODO(henrik) This needs to be changed because there are different type of - // interrupts generated by the chip. - command void enableInterrupt(); - command void disableInterrupt(); + command void enableCLKOUT(); + command void disableCLKOUT(); /** * Reads from a register. @@ -88,22 +75,17 @@ interface RV8564 * @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); + 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(uint8_t reg); + async event void writeRegisterDone(error_t error, 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/HplRV8564C.nc similarity index 92% rename from tos/platforms/mulle/chips/rv8564/RV8564C.nc rename to tos/platforms/mulle/chips/rv8564/HplRV8564C.nc index 5b101a10..560576ad 100755 --- a/tos/platforms/mulle/chips/rv8564/RV8564C.nc +++ b/tos/platforms/mulle/chips/rv8564/HplRV8564C.nc @@ -40,13 +40,13 @@ * @author Henrik Makitaavola */ -configuration RV8564C +configuration HplRV8564C { - provides interface RV8564 as RTC; + provides interface HplRV8564; } implementation { - components RV8564P as RTCP, + components HplRV8564P as RTCP, new SoftwareI2C2C() as I2C, HplM16c62pGeneralIOC as IOs, HplM16c62pInterruptC as Irqs, @@ -54,10 +54,13 @@ implementation Irq.HplM16c62pInterrupt -> Irqs.Int0; - RTC = RTCP; + 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/RV8564P.nc b/tos/platforms/mulle/chips/rv8564/HplRV8564P.nc similarity index 63% rename from tos/platforms/mulle/chips/rv8564/RV8564P.nc rename to tos/platforms/mulle/chips/rv8564/HplRV8564P.nc index 35c0c0a6..7db76a52 100755 --- a/tos/platforms/mulle/chips/rv8564/RV8564P.nc +++ b/tos/platforms/mulle/chips/rv8564/HplRV8564P.nc @@ -42,11 +42,11 @@ #include "rv8564.h" #include "I2C.h" -module RV8564P +module HplRV8564P { - 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? + provides interface HplRV8564 as RTC; + provides interface Init; + uses interface GeneralIO as CLKOE; uses interface GeneralIO as CLKOUT; uses interface GeneralIO; @@ -59,53 +59,30 @@ implementation enum { - OFF, - IDLE, - READING, - WRITING + S_IDLE, + S_READING, + S_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; - } + norace uint8_t m_state = S_IDLE; + uint8_t m_buf[2]; - command error_t RTC.off() + command error_t Init.init() { - if (state == OFF) - { - return SUCCESS; - } - else if (state != IDLE) - { - return FAIL; - } + call CLKOUT.makeInput(); call CLKOE.clr(); - call CLKOUT.clr(); - return SUCCESS; + call CLKOE.makeOutput(); } - command bool RTC.isOn() + command void RTC.enableCLKOUT() { - return ((state != OFF) ? true : false); + call CLKOE.set(); } - command void RTC.enableCLKOUT() + command void RTC.disableCLKOUT() { - call CLKOUT.makeInput(); - call CLKOUT.clr(); - call CLKOE.makeOutput(); - call CLKOE.set(); + call CLKOE.clr(); } + command void RTC.enableInterrupt() { call GpioInterrupt.enableFallingEdge(); @@ -118,40 +95,55 @@ implementation command error_t RTC.readRegister(uint8_t reg) { - uint8_t val; - if (state != IDLE) + 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; } - 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 (m_state != S_IDLE) { return FAIL; } - state = WRITING; - atomic write_buffer[0] = reg; - atomic write_buffer[1] = value; - call I2CResource.request(); - return SUCCESS; + 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 (state == READING) + atomic + { + if (m_state == S_READING) { - call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 1, &read_register); + call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 1, m_buf); } - else if (state == WRITING) + else if (m_state == S_WRITING) { - call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 2, write_buffer); + call I2C.write(I2C_START | I2C_STOP, RV8564_ADDR, 2, m_buf); } } } @@ -165,30 +157,36 @@ implementation { atomic { - if (state == READING && data == &read_register_value) + if (m_state == S_READING && data == m_buf) { - state = IDLE; call I2CResource.release(); - signal RTC.readRegisterDone(read_register_value, read_register); + 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 (state == READING) + if (m_state == S_READING) { - call I2C.read(I2C_START | I2C_STOP, RV8564_ADDR, 1, &read_register_value); + 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 (state == WRITING) + else if (m_state == S_WRITING) { - state = IDLE; call I2CResource.release(); - signal RTC.writeRegisterDone(write_buffer[0]); + m_state = S_IDLE; + signal RTC.writeRegisterDone(error, m_buf[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() { } } -- 2.39.2