]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
separate the FastSpiInterface from the HplRF230 interface
authormmaroti <mmaroti>
Fri, 6 Mar 2009 13:11:37 +0000 (13:11 +0000)
committermmaroti <mmaroti>
Fri, 6 Mar 2009 13:11:37 +0000 (13:11 +0000)
tos/chips/rf230/FastSpiByte.nc [new file with mode: 0644]
tos/chips/rf230/HplRF230.nc [new file with mode: 0644]
tos/chips/rf230/RF230LayerC.nc
tos/chips/rf230/RF230LayerP.nc
tos/platforms/iris/chips/rf230/HplRF230.nc [deleted file]
tos/platforms/iris/chips/rf230/HplRF230C.nc
tos/platforms/iris/chips/rf230/HplRF230P.nc

diff --git a/tos/chips/rf230/FastSpiByte.nc b/tos/chips/rf230/FastSpiByte.nc
new file mode 100644 (file)
index 0000000..f4e56ff
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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);
+}
diff --git a/tos/chips/rf230/HplRF230.nc b/tos/chips/rf230/HplRF230.nc
new file mode 100644 (file)
index 0000000..75d6592
--- /dev/null
@@ -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);
+}
index 5e842c0f3a17abca051196381121d20459f37f27..43c1a836def01b5ba8f91bccd2a6f1190ad4a369 100644 (file)
@@ -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;
index 4bdfb51257553ada0edb0647951767fea0d66e10..0099fab001562d70aa70aaaeb21a01f3377bad13 100644 (file)
@@ -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/HplRF230.nc b/tos/platforms/iris/chips/rf230/HplRF230.nc
deleted file mode 100644 (file)
index 29faa76..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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);
-}
index bb5158956dc3ec2a084b20d52306f4a9d86b3f28..0394f93e31208dca324759b3127064a13cfd034f 100644 (file)
@@ -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;
index cbe6c9487d5555bb986a60f7dab130fb3aa00362..2b9bf4875d0f7dcfb2f87467346057742541c1cc 100644 (file)
@@ -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);