]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/cc2420/control/CC2420ControlP.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / tos / chips / cc2420 / control / CC2420ControlP.nc
index 582d8b0afafcca15ad3e36839311b9596a711797..c6fdd8c2bc7fb70ef4da70353df6fdf33ea13795 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "Timer.h"
 
-module CC2420ControlP {
+module CC2420ControlP @safe() {
 
   provides interface Init;
   provides interface Resource;
@@ -65,7 +65,6 @@ module CC2420ControlP {
   uses interface CC2420Strobe as SRFOFF;
   uses interface CC2420Strobe as SXOSCOFF;
   uses interface CC2420Strobe as SXOSCON;
-  uses interface AMPacket;
   
   uses interface Resource as SpiResource;
   uses interface Resource as RssiResource;
@@ -95,10 +94,18 @@ implementation {
   
   bool m_sync_busy;
   
+  /** TRUE if acknowledgments are enabled */
   bool autoAckEnabled;
   
+  /** TRUE if acknowledgments are generated in hardware only */
   bool hwAutoAckDefault;
   
+  /** TRUE if software or hardware address recognition is enabled */
+  bool addressRecognition;
+  
+  /** TRUE if address recognition should also be performed in hardware */
+  bool hwAddressRecognition;
+  
   norace cc2420_control_state_t m_state = S_VREG_STOPPED;
   
   /***************** Prototypes ****************/
@@ -121,18 +128,34 @@ implementation {
     m_tx_power = CC2420_DEF_RFPOWER;
     m_channel = CC2420_DEF_CHANNEL;
     
+    
+#if defined(CC2420_NO_ADDRESS_RECOGNITION)
+    addressRecognition = FALSE;
+#else
+    addressRecognition = TRUE;
+#endif
+    
+#if defined(CC2420_HW_ADDRESS_RECOGNITION)
+    hwAddressRecognition = TRUE;
+#else
+    hwAddressRecognition = FALSE;
+#endif
+    
+    
 #if defined(CC2420_NO_ACKNOWLEDGEMENTS)
     autoAckEnabled = FALSE;
 #else
     autoAckEnabled = TRUE;
 #endif
-
+    
 #if defined(CC2420_HW_ACKNOWLEDGEMENTS)
     hwAutoAckDefault = TRUE;
+    hwAddressRecognition = TRUE;
 #else
     hwAutoAckDefault = FALSE;
 #endif
-
+    
+    
     return SUCCESS;
   }
 
@@ -253,7 +276,7 @@ implementation {
     atomic m_channel = channel;
   }
 
-  command uint16_t CC2420Config.getShortAddr() {
+  async command uint16_t CC2420Config.getShortAddr() {
     atomic return m_short_addr;
   }
 
@@ -261,8 +284,8 @@ implementation {
     atomic m_short_addr = addr;
   }
 
-  command uint16_t CC2420Config.getPanAddr() {
-    return m_pan;
+  async command uint16_t CC2420Config.getPanAddr() {
+    atomic return m_pan;
   }
 
   command void CC2420Config.setPanAddr( uint16_t pan ) {
@@ -290,6 +313,34 @@ implementation {
     return SUCCESS;
   }
 
+  /**
+   * @param enableAddressRecognition TRUE to turn address recognition on
+   * @param useHwAddressRecognition TRUE to perform address recognition first
+   *     in hardware. This doesn't affect software address recognition. The
+   *     driver must sync with the chip after changing this value.
+   */
+  command void CC2420Config.setAddressRecognition(bool enableAddressRecognition, bool useHwAddressRecognition) {
+    atomic {
+      addressRecognition = enableAddressRecognition;
+      hwAddressRecognition = useHwAddressRecognition;
+    }
+  }
+  
+  /**
+   * @return TRUE if address recognition is enabled
+   */
+  async command bool CC2420Config.isAddressRecognitionEnabled() {
+    atomic return addressRecognition;
+  }
+  
+  /**
+   * @return TRUE if address recognition is performed first in hardware.
+   */
+  async command bool CC2420Config.isHwAddressRecognitionDefault() {
+    atomic return hwAddressRecognition;
+  }
+  
+  
   /**
    * Sync must be called for acknowledgement changes to take effect
    * @param enableAutoAck TRUE to enable auto acknowledgements
@@ -297,8 +348,8 @@ implementation {
    *     default to software auto acknowledgements
    */
   command void CC2420Config.setAutoAck(bool enableAutoAck, bool hwAutoAck) {
-    autoAckEnabled = enableAutoAck;
-    hwAutoAckDefault = hwAutoAck;
+    atomic autoAckEnabled = enableAutoAck;
+    atomic hwAutoAckDefault = hwAutoAck;
   }
   
   /**
@@ -306,22 +357,14 @@ implementation {
    *     acks are the default
    */
   async command bool CC2420Config.isHwAutoAckDefault() {
-    bool isHwAck;
-    atomic {
-      isHwAck = hwAutoAckDefault;
-    }
-    return isHwAck;    
+    atomic return hwAutoAckDefault;    
   }
   
   /**
    * @return TRUE if auto acks are enabled
    */
   async command bool CC2420Config.isAutoAckEnabled() {
-    bool isAckEnabled;
-    atomic {
-      isAckEnabled = autoAckEnabled;
-    }
-    return isAckEnabled;
+    atomic return autoAckEnabled;
   }
   
   /***************** ReadRssi Commands ****************/
@@ -350,7 +393,7 @@ implementation {
   }
 
   event void RssiResource.granted() { 
-    uint16_t data;
+    uint16_t data = 0;
     call CSN.clr();
     call RSSI.read(&data);
     call CSN.set();
@@ -423,11 +466,14 @@ implementation {
 
   /**
    * Write the MDMCTRL0 register
+   * Disabling hardware address recognition improves acknowledgment success
+   * rate and low power communications reliability by causing the local node
+   * to do work while the real destination node of the packet is acknowledging.
    */
   void writeMdmctrl0() {
     atomic {
       call MDMCTRL0.write( ( 1 << CC2420_MDMCTRL0_RESERVED_FRAME_MODE ) |
-          ( 1 << CC2420_MDMCTRL0_ADR_DECODE ) |
+          ( (addressRecognition && hwAddressRecognition) << CC2420_MDMCTRL0_ADR_DECODE ) |
           ( 2 << CC2420_MDMCTRL0_CCA_HYST ) |
           ( 3 << CC2420_MDMCTRL0_CCA_MOD ) |
           ( 1 << CC2420_MDMCTRL0_AUTOCRC ) |