]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/usci/Msp430SpiB1C.nc
Implement chip select query for SPI peripheral.
[tinyos-2.x.git] / tos / chips / msp430 / usci / Msp430SpiB1C.nc
index 9464555f812fde0fc5aa1f6a2fe202d5216f733f..5fc73fc23356aaf98e7a07844636a5efc83f9589 100644 (file)
  * This configuration provides the interface for using USCI_B1 in its SPI
  * mode.
  *
- * @author R. Steve McKown <smckown@gmail.com>
+ * The instantiator should set the blockSize, which represents the maximum
+ * number of bytes the underlying SPI stack will transmit or receive in a
+ * single interrupt service.  Increasing the block size decreases SPI
+ * communications time at the expense of reducing system responsiveness to
+ * other events.
+ *
+ * The blockSize is best set by considering the maximum time the SPI stack
+ * should be able to delay other events.  A rule of thumb formula would be:
+ *
+ * block_time = block_size / (spi_bitclock/8)
+ *
+ * For example, using a 500KHZ SPI bitclock, a block size of 64 bytes
+ * equates to a block time of 1 ms.  Note that this calculation is rough
+ * because it does not take into account ISR overhead and other factors.
+ *
+ * The implementation will use a default blockSize if set to 0 here.
+ *
+ * @author R. Steve McKown <rsmckown@gmail.com>
  */
  
 #if !defined(__MSP430_HAS_USCI_AB1__)
@@ -40,7 +57,7 @@
 
 #include "Msp430Usci.h"
 
-generic configuration Msp430SpiB1C() {
+generic configuration Msp430SpiB1C(uint16_t blockSize) {
   provides {
     interface Resource;
     interface ResourceRequested;
@@ -48,20 +65,23 @@ generic configuration Msp430SpiB1C() {
     interface SpiPacket;
     interface ArbiterInfo; /* ??? */
   }
-  uses interface AsyncConfigure<const msp430_usci_config_t*> as
-    Msp430UsciConfigure;
+  uses {
+    interface AsyncConfigure<const msp430_usci_spi_t*> as Configure;
+    interface GeneralIO as CSn;        /* wire only if a SPI slave only */
+  }
 }
 implementation {
   enum {
     CLIENT_ID = unique(MSP430_USCIB1_RESOURCE)
   };
 
-  components new Msp430SpiP() as SpiP;
+  components new Msp430SpiP(blockSize) as SpiP;
   SpiByte = SpiP;
   SpiPacket = SpiP;
-  Msp430UsciConfigure = SpiP;
+  Configure = SpiP;
+  CSn = SpiP;
 
-  components Msp430UsciA0C as UsciC;
+  components Msp430UsciB1C as UsciC;
   Resource = UsciC.Resource[CLIENT_ID];
   ResourceRequested = UsciC.ResourceRequested[CLIENT_ID];
   ArbiterInfo = UsciC.ArbiterInfo;
@@ -74,5 +94,5 @@ implementation {
   SpiP.STE -> IOC.UCB1STE;
   SpiP.SIMO -> IOC.UCB1SIMO;
   SpiP.SOMI -> IOC.UCB1SOMI;
-  SpiP.SCL -> IOC.UCB1SCL;
+  SpiP.CLK -> IOC.UCB1CLK;
 }