--- /dev/null
+/*
+ * 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
+ */
+
+/**
+ * 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
+{
+ /**
+ * 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 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 splitRead();
+
+ /**
+ * This command first reads the SPI register and then writes
+ * there the new data, then returns
+ */
+ 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 write(uint8_t data);
+}
--- /dev/null
+/*
+ * 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);
+}
RF230LayerP.SELN -> HplRF230C.SELN;
RF230LayerP.SpiResource -> HplRF230C.SpiResource;
- RF230LayerP.SpiByte -> HplRF230C;
+ RF230LayerP.FastSpiByte -> HplRF230C;
RF230LayerP.HplRF230 -> HplRF230C;
RF230LayerP.SLP_TR -> HplRF230C.SLP_TR;
interface GeneralIO as SELN;
interface Resource as SpiResource;
- interface SpiByte;
+ interface FastSpiByte;
interface HplRF230;
interface GeneralIO as SLP_TR;
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();
}
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;
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;
// first upload the header to gain some time
do {
- call HplRF230.spiSplitReadWrite(*(data++));
+ call FastSpiByte.splitReadWrite(*(data++));
}
while( --header != 0 );
*(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();
/*
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() )
uint8_t* data;
// initiate the reading
- call HplRF230.spiSplitWrite(0);
+ call FastSpiByte.splitWrite(0);
call RF230Config.setLength(rxMsg, length);
data = call RF230Config.getPayload(rxMsg);
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;
+++ /dev/null
-/*
- * 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
- */
-
-/**
- * There should be standard interfaces/commands for these
-*/
-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);
-
- /**
- * 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);
-
- /**
- * Finishes the split-phase SPI data transfer by waiting till
- * the write command comletes and returning the received data.
- */
- async command uint8_t spiSplitRead();
-
- /**
- * This command first reads the SPI register and then writes
- * there the new data, then returns
- */
- async command uint8_t spiSplitReadWrite(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);
-}
{
interface GeneralIO as SELN;
interface Resource as SpiResource;
- interface SpiByte;
+ interface FastSpiByte;
interface GeneralIO as SLP_TR;
interface GeneralIO as RSTN;
components Atm128SpiC as SpiC;
SpiResource = SpiC.Resource[unique("Atm128SpiC.Resource")];
- SpiByte = SpiC;
HplRF230 = HplRF230P;
+ FastSpiByte = HplRF230P;
components HplAtm128GeneralIOC as IO;
SLP_TR = IO.PortB7;
interface GpioCapture as IRQ;
interface Init as PlatformInit;
+ interface FastSpiByte;
interface HplRF230;
}
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);
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;
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);