From 813ccd9a39dd0810febb285f17bcd72ba451f536 Mon Sep 17 00:00:00 2001 From: mmaroti Date: Fri, 6 Mar 2009 13:11:37 +0000 Subject: [PATCH] separate the FastSpiInterface from the HplRF230 interface --- .../rf230/FastSpiByte.nc} | 29 ++++++++------ tos/chips/rf230/HplRF230.nc | 31 ++++++++++++++ tos/chips/rf230/RF230LayerC.nc | 2 +- tos/chips/rf230/RF230LayerP.nc | 40 +++++++++---------- tos/platforms/iris/chips/rf230/HplRF230C.nc | 4 +- tos/platforms/iris/chips/rf230/HplRF230P.nc | 9 +++-- 6 files changed, 75 insertions(+), 40 deletions(-) rename tos/{platforms/iris/chips/rf230/HplRF230.nc => chips/rf230/FastSpiByte.nc} (71%) create mode 100644 tos/chips/rf230/HplRF230.nc diff --git a/tos/platforms/iris/chips/rf230/HplRF230.nc b/tos/chips/rf230/FastSpiByte.nc similarity index 71% rename from tos/platforms/iris/chips/rf230/HplRF230.nc rename to tos/chips/rf230/FastSpiByte.nc index 29faa760..f4e56ffb 100644 --- a/tos/platforms/iris/chips/rf230/HplRF230.nc +++ b/tos/chips/rf230/FastSpiByte.nc @@ -22,39 +22,42 @@ */ /** - * There should be standard interfaces/commands for these -*/ -interface HplRF230 + * This is a natural extension of the SpiByte interface which allows fast + * data transfers comparable to the SpiStream interface. Use may want to + * use the following code sequence to write a buffer as fast as possible + * + * call FastSpiByte.spiSplitWrite(data[0]); // the first byte + * for(i = 1; i < length; ++i) { + * // finish the previous one and write the next one + * call FastSpiByte.spiSplitReadWrite(data[i]); + * } + * call FastSpiByte.spiSlitRead(); // finish the last one + */ +interface FastSpiByte { - /** - * Calculates the crc. For some unknown reason the standard - * tinyos crcByte command swiches endianness. - */ - async command uint16_t crcByte(uint16_t crc, uint8_t data); - /** * Starts a split-phase SPI data transfer with the given data. * A spiSplitRead command must follow this command even if the * result is unimportant. The SpiByte interface should be * extended with this protocol. */ - async command void spiSplitWrite(uint8_t data); + async command void splitWrite(uint8_t data); /** * Finishes the split-phase SPI data transfer by waiting till * the write command comletes and returning the received data. */ - async command uint8_t spiSplitRead(); + async command uint8_t splitRead(); /** * This command first reads the SPI register and then writes * there the new data, then returns */ - async command uint8_t spiSplitReadWrite(uint8_t data); + async command uint8_t splitReadWrite(uint8_t data); /** * This is the standard SpiByte.write command but a little * faster as we shuold not need to adjust the power state there. */ - async command uint8_t spiWrite(uint8_t data); + async command uint8_t write(uint8_t data); } diff --git a/tos/chips/rf230/HplRF230.nc b/tos/chips/rf230/HplRF230.nc new file mode 100644 index 00000000..75d6592e --- /dev/null +++ b/tos/chips/rf230/HplRF230.nc @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2007, Vanderbilt University + * All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose, without fee, and without written agreement is + * hereby granted, provided that the above copyright notice, the following + * two paragraphs and the author appear in all copies of this software. + * + * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT + * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT + * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Author: Miklos Maroti + */ + +interface HplRF230 +{ + /** + * Calculates the crc. For some unknown reason the standard + * tinyos crcByte command swiches endianness. + */ + async command uint16_t crcByte(uint16_t crc, uint8_t data); +} diff --git a/tos/chips/rf230/RF230LayerC.nc b/tos/chips/rf230/RF230LayerC.nc index 5e842c0f..43c1a836 100644 --- a/tos/chips/rf230/RF230LayerC.nc +++ b/tos/chips/rf230/RF230LayerC.nc @@ -59,7 +59,7 @@ implementation RF230LayerP.SELN -> HplRF230C.SELN; RF230LayerP.SpiResource -> HplRF230C.SpiResource; - RF230LayerP.SpiByte -> HplRF230C; + RF230LayerP.FastSpiByte -> HplRF230C; RF230LayerP.HplRF230 -> HplRF230C; RF230LayerP.SLP_TR -> HplRF230C.SLP_TR; diff --git a/tos/chips/rf230/RF230LayerP.nc b/tos/chips/rf230/RF230LayerP.nc index 4bdfb512..0099fab0 100644 --- a/tos/chips/rf230/RF230LayerP.nc +++ b/tos/chips/rf230/RF230LayerP.nc @@ -45,7 +45,7 @@ module RF230LayerP interface GeneralIO as SELN; interface Resource as SpiResource; - interface SpiByte; + interface FastSpiByte; interface HplRF230; interface GeneralIO as SLP_TR; @@ -126,9 +126,9 @@ implementation ASSERT( reg == (reg & RF230_CMD_REGISTER_MASK) ); call SELN.clr(); - call HplRF230.spiSplitWrite(RF230_CMD_REGISTER_WRITE | reg); - call HplRF230.spiSplitReadWrite(value); - call HplRF230.spiSplitRead(); + call FastSpiByte.splitWrite(RF230_CMD_REGISTER_WRITE | reg); + call FastSpiByte.splitReadWrite(value); + call FastSpiByte.splitRead(); call SELN.set(); } @@ -138,9 +138,9 @@ implementation ASSERT( reg == (reg & RF230_CMD_REGISTER_MASK) ); call SELN.clr(); - call HplRF230.spiSplitWrite(RF230_CMD_REGISTER_READ | reg); - call HplRF230.spiSplitReadWrite(0); - reg = call HplRF230.spiSplitRead(); + call FastSpiByte.splitWrite(RF230_CMD_REGISTER_READ | reg); + call FastSpiByte.splitReadWrite(0); + reg = call FastSpiByte.splitRead(); call SELN.set(); return reg; @@ -444,13 +444,13 @@ implementation ASSERT( ! radioIrq ); call SELN.clr(); - call HplRF230.spiSplitWrite(RF230_CMD_FRAME_WRITE); + call FastSpiByte.splitWrite(RF230_CMD_FRAME_WRITE); length = call RF230Config.getLength(msg); data = call RF230Config.getPayload(msg); // length | data[0] ... data[length-3] | automatically generated FCS - call HplRF230.spiSplitReadWrite(length); + call FastSpiByte.splitReadWrite(length); // the FCS is atomatically generated (2 bytes) length -= 2; @@ -463,7 +463,7 @@ implementation // first upload the header to gain some time do { - call HplRF230.spiSplitReadWrite(*(data++)); + call FastSpiByte.splitReadWrite(*(data++)); } while( --header != 0 ); @@ -473,12 +473,12 @@ implementation *(timesync_relative_t*)timesync = (*(timesync_absolute_t*)timesync) - time32; do { - call HplRF230.spiSplitReadWrite(*(data++)); + call FastSpiByte.splitReadWrite(*(data++)); } while( --length != 0 ); // wait for the SPI transfer to finish - call HplRF230.spiSplitRead(); + call FastSpiByte.splitRead(); call SELN.set(); /* @@ -552,10 +552,10 @@ implementation uint16_t crc; call SELN.clr(); - call HplRF230.spiWrite(RF230_CMD_FRAME_READ); + call FastSpiByte.write(RF230_CMD_FRAME_READ); // read the length byte - length = call HplRF230.spiWrite(0); + length = call FastSpiByte.write(0); // if correct length if( length >= 3 && length <= call RF230Config.getMaxLength() ) @@ -564,7 +564,7 @@ implementation uint8_t* data; // initiate the reading - call HplRF230.spiSplitWrite(0); + call FastSpiByte.splitWrite(0); call RF230Config.setLength(rxMsg, length); data = call RF230Config.getPayload(rxMsg); @@ -580,19 +580,19 @@ implementation length -= read; do { - crc = call HplRF230.crcByte(crc, *(data++) = call HplRF230.spiSplitReadWrite(0)); + crc = call HplRF230.crcByte(crc, *(data++) = call FastSpiByte.splitReadWrite(0)); } while( --read != 0 ); if( signal RadioReceive.header(rxMsg) ) { while( length-- != 0 ) - crc = call HplRF230.crcByte(crc, *(data++) = call HplRF230.spiSplitReadWrite(0)); + crc = call HplRF230.crcByte(crc, *(data++) = call FastSpiByte.splitReadWrite(0)); - crc = call HplRF230.crcByte(crc, call HplRF230.spiSplitReadWrite(0)); - crc = call HplRF230.crcByte(crc, call HplRF230.spiSplitReadWrite(0)); + crc = call HplRF230.crcByte(crc, call FastSpiByte.splitReadWrite(0)); + crc = call HplRF230.crcByte(crc, call FastSpiByte.splitReadWrite(0)); - call PacketLinkQuality.set(rxMsg, call HplRF230.spiSplitRead()); + call PacketLinkQuality.set(rxMsg, call FastSpiByte.splitRead()); } else crc = 1; diff --git a/tos/platforms/iris/chips/rf230/HplRF230C.nc b/tos/platforms/iris/chips/rf230/HplRF230C.nc index bb515895..0394f93e 100644 --- a/tos/platforms/iris/chips/rf230/HplRF230C.nc +++ b/tos/platforms/iris/chips/rf230/HplRF230C.nc @@ -29,7 +29,7 @@ configuration HplRF230C { interface GeneralIO as SELN; interface Resource as SpiResource; - interface SpiByte; + interface FastSpiByte; interface GeneralIO as SLP_TR; interface GeneralIO as RSTN; @@ -51,9 +51,9 @@ implementation components Atm128SpiC as SpiC; SpiResource = SpiC.Resource[unique("Atm128SpiC.Resource")]; - SpiByte = SpiC; HplRF230 = HplRF230P; + FastSpiByte = HplRF230P; components HplAtm128GeneralIOC as IO; SLP_TR = IO.PortB7; diff --git a/tos/platforms/iris/chips/rf230/HplRF230P.nc b/tos/platforms/iris/chips/rf230/HplRF230P.nc index cbe6c948..2b9bf487 100644 --- a/tos/platforms/iris/chips/rf230/HplRF230P.nc +++ b/tos/platforms/iris/chips/rf230/HplRF230P.nc @@ -31,6 +31,7 @@ module HplRF230P interface GpioCapture as IRQ; interface Init as PlatformInit; + interface FastSpiByte; interface HplRF230; } @@ -91,7 +92,7 @@ implementation return _crc_ccitt_update(crc, data); } - inline async command void HplRF230.spiSplitWrite(uint8_t data) + inline async command void FastSpiByte.splitWrite(uint8_t data) { // the SPI must have been started, so do not waste time here // SET_BIT(SPCR, SPE); @@ -99,14 +100,14 @@ implementation SPDR = data; } - inline async command uint8_t HplRF230.spiSplitRead() + inline async command uint8_t FastSpiByte.splitRead() { while( !( SPSR & 0x80 ) ) ; return SPDR; } - inline async command uint8_t HplRF230.spiSplitReadWrite(uint8_t data) + inline async command uint8_t FastSpiByte.splitReadWrite(uint8_t data) { uint8_t b; @@ -118,7 +119,7 @@ implementation return b; } - inline async command uint8_t HplRF230.spiWrite(uint8_t data) + inline async command uint8_t FastSpiByte.write(uint8_t data) { // the SPI must have been started, so do not waste time here // SET_BIT(SPCR, SPE); -- 2.39.2