]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/mac/tkn154/RadioControlImplP.nc
- fixed an issue with the beacon sequence number being set incorrectly
[tinyos-2.x.git] / tos / lib / mac / tkn154 / RadioControlImplP.nc
index 189d87614f7db0def978f0aec2ae7dd5ea3f9204..afafb8ccfbdde5103492ee244663be4ce808d682 100644 (file)
  * @author Jan Hauer <hauer@tkn.tu-berlin.de>
  * ========================================================================
  */
+
 #include "TKN154_MAC.h"
-#include "TKN154_DEBUG.h"
+
 module RadioControlImplP 
 {
   provides
   {
     interface RadioRx as MacRx[uint8_t client];
     interface RadioTx as MacTx[uint8_t client];
+    interface SlottedCsmaCa as SlottedCsmaCa[uint8_t client];
+    interface UnslottedCsmaCa as UnslottedCsmaCa[uint8_t client];
     interface RadioOff as MacRadioOff[uint8_t client];
   } uses {
     interface ArbiterInfo;
     interface RadioRx as PhyRx;
     interface RadioTx as PhyTx;
+    interface SlottedCsmaCa as PhySlottedCsmaCa;
+    interface UnslottedCsmaCa as PhyUnslottedCsmaCa;
     interface RadioOff as PhyRadioOff;
     interface Get<bool> as RadioPromiscuousMode;
     interface Leds;
-    interface Ieee802154Debug as Debug;
   }
 }
 implementation
 {
 
-/* ----------------------- RadioRx ----------------------- */
-
-  async command error_t MacRx.prepare[uint8_t client]()
-  {
-    if (client == call ArbiterInfo.userId())
-      return call PhyRx.prepare();
-    else {
-      call Leds.led0On();
-      return FAIL;
-    } 
-  }
-    
-  async event void PhyRx.prepareDone()
-  {
-    signal MacRx.prepareDone[call ArbiterInfo.userId()]();
-  }
-
-  async command bool MacRx.isPrepared[uint8_t client]()
-  {
-    if (client == call ArbiterInfo.userId())
-      return call PhyRx.isPrepared();
-    else {
-      call Leds.led0On();
-      return FAIL;
-    } 
-  }
+  /* ----------------------- RadioRx ----------------------- */
 
-  async command error_t MacRx.receive[uint8_t client](ieee154_reftime_t *t0, uint32_t dt)
+  async command error_t MacRx.enableRx[uint8_t client](uint32_t t0, uint32_t dt)
   {
     if (client == call ArbiterInfo.userId()) 
-      return call PhyRx.receive(t0, dt);
+      return call PhyRx.enableRx(t0, dt);
     else {
-      call Leds.led0On();
+      ASSERT(0);
       return IEEE154_TRANSACTION_OVERFLOW;
     }
   }
 
-  event message_t* PhyRx.received(message_t *msg, ieee154_reftime_t *timestamp)
+  async event void PhyRx.enableRxDone()
+  {
+    signal MacRx.enableRxDone[call ArbiterInfo.userId()]();
+  }
+
+  event message_t* PhyRx.received(message_t *msg, const ieee154_timestamp_t *timestamp)
   {
     uint8_t *mhr = MHR(msg);
+
+    dbg("RadioControlImplP", "Received frame, DSN: %lu, type: 0x%lu\n", 
+        (uint32_t) mhr[MHR_INDEX_SEQNO], (uint32_t) mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK);
+
     if (((mhr[1] & FC2_FRAME_VERSION_MASK) > FC2_FRAME_VERSION_1)
         && (!call RadioPromiscuousMode.get()))
       return msg;
+
 #ifndef IEEE154_SECURITY_ENABLED
     if ((mhr[0] & FC1_SECURITY_ENABLED)
         && (!call RadioPromiscuousMode.get()))
@@ -110,64 +99,103 @@ implementation
     if (client == call ArbiterInfo.userId())
       return call PhyRx.isReceiving();
     else {
-      call Leds.led0On();
+      ASSERT(0);
       return FAIL;
     } 
   }
 
-/* ----------------------- RadioTx ----------------------- */
+  default async event void MacRx.enableRxDone[uint8_t client]() { ASSERT(0); }
 
-  async command error_t MacTx.load[uint8_t client](ieee154_txframe_t *frame)
+  default event message_t* MacRx.received[uint8_t client](message_t *frame, const ieee154_timestamp_t *timestamp)
+  {
+    ASSERT(0);
+    return frame;
+  }
+
+  /* ----------------------- RadioTx ----------------------- */
+
+  async command error_t MacTx.transmit[uint8_t client](ieee154_txframe_t *frame, 
+      const ieee154_timestamp_t *t0, uint32_t dt)
   {
     if (client == call ArbiterInfo.userId())
-      return call PhyTx.load(frame);
+      return call PhyTx.transmit(frame, t0, dt);
     else {
-      call Leds.led0On();
+      ASSERT(0);
       return IEEE154_TRANSACTION_OVERFLOW;
     }
   }
-    
-  async event void PhyTx.loadDone()
+  
+  async event void PhyTx.transmitDone(ieee154_txframe_t *frame, 
+      const ieee154_timestamp_t *timestamp, error_t result)
+  {
+    signal MacTx.transmitDone[call ArbiterInfo.userId()](frame, timestamp, result);
+  }
+
+  default async event void MacTx.transmitDone[uint8_t client](ieee154_txframe_t *frame, 
+      const ieee154_timestamp_t *timestamp, error_t result) 
   {
-    signal MacTx.loadDone[call ArbiterInfo.userId()]();
+    ASSERT(0);
   }
 
-  async command ieee154_txframe_t* MacTx.getLoadedFrame[uint8_t client]()
+  /* ----------------------- Unslotted CSMA ----------------------- */
+
+  async command error_t UnslottedCsmaCa.transmit[uint8_t client](ieee154_txframe_t *frame, ieee154_csma_t *csma)
   {
-    if (client == call ArbiterInfo.userId())
-      return call PhyTx.getLoadedFrame();
+    if (client == call ArbiterInfo.userId()) 
+      return call PhyUnslottedCsmaCa.transmit(frame, csma);
     else {
-      call Leds.led0On();
-      return NULL;
+      ASSERT(0);
+      return IEEE154_TRANSACTION_OVERFLOW;
     }
   }
 
+  async event void PhyUnslottedCsmaCa.transmitDone(ieee154_txframe_t *frame, ieee154_csma_t *csma, bool ackPendingFlag, error_t result)
+  {
+    signal UnslottedCsmaCa.transmitDone[call ArbiterInfo.userId()](
+        frame, csma, ackPendingFlag, result);
+  }
+
+  default async event void UnslottedCsmaCa.transmitDone[uint8_t client](
+      ieee154_txframe_t *frame, ieee154_csma_t *csma, bool ackPendingFlag, error_t result)
+  {
+    ASSERT(0);
+  }
+
+  /* ----------------------- Slotted CSMA ----------------------- */
 
-  async command error_t MacTx.transmit[uint8_t client](ieee154_reftime_t *referenceTime, 
-      uint32_t timeOffset, uint8_t numCCA, bool ackRequest)
+  async command error_t SlottedCsmaCa.transmit[uint8_t client](ieee154_txframe_t *frame, ieee154_csma_t *csma,
+      const ieee154_timestamp_t *slot0Time, uint32_t dtMax, bool resume, uint16_t remainingBackoff)
   {
     if (client == call ArbiterInfo.userId()) 
-      return call PhyTx.transmit(referenceTime, timeOffset, numCCA, ackRequest);
+      return call PhySlottedCsmaCa.transmit(frame, csma, slot0Time, dtMax, resume, remainingBackoff);
     else {
-      call Leds.led0On();
+      ASSERT(0);
       return IEEE154_TRANSACTION_OVERFLOW;
     }
   }
 
-  async event void PhyTx.transmitDone(ieee154_txframe_t *frame, 
-      ieee154_reftime_t *referenceTime, bool ackPendingFlag, error_t error)   
+  async event void PhySlottedCsmaCa.transmitDone(ieee154_txframe_t *frame, ieee154_csma_t *csma, 
+      bool ackPendingFlag,  uint16_t remainingBackoff, error_t result)
+  {
+    signal SlottedCsmaCa.transmitDone[call ArbiterInfo.userId()](
+        frame, csma, ackPendingFlag, remainingBackoff, result);
+  }
+
+  default async event void SlottedCsmaCa.transmitDone[uint8_t client](
+      ieee154_txframe_t *frame, ieee154_csma_t *csma, 
+      bool ackPendingFlag,  uint16_t remainingBackoff, error_t result)
   {
-    signal MacTx.transmitDone[call ArbiterInfo.userId()](frame, referenceTime, ackPendingFlag, error);
+    ASSERT(0);
   }
 
-/* ----------------------- RadioOff ----------------------- */
+  /* ----------------------- RadioOff ----------------------- */
 
   async command error_t MacRadioOff.off[uint8_t client]()
   {
     if (client == call ArbiterInfo.userId())
       return call PhyRadioOff.off();
     else {
-      call Leds.led0On();
+      ASSERT(0);
       return EBUSY;
     }
   }
@@ -186,28 +214,8 @@ implementation
       return EBUSY;
   }
 
-/* ----------------------- Defaults ----------------------- */
-
-  default async event void MacTx.loadDone[uint8_t client]()
-  {
-    call Debug.log(LEVEL_CRITICAL, RadioRxTxP_DEFAULT_PREPARE_TX_DONE, 0, 0, 0);
-  }
-  default async event void MacTx.transmitDone[uint8_t client](ieee154_txframe_t *frame, 
-      ieee154_reftime_t *referenceTime, bool ackPendingFlag, error_t error) 
-  {
-    call Debug.log(LEVEL_CRITICAL, RadioRxTxP_DEFAULT_TX_DONE, 0, 0, 0);
-  }
-  default async event void MacRx.prepareDone[uint8_t client]()
-  {
-    call Debug.log(LEVEL_CRITICAL, RadioRxTxP_DEFAULT_PREPARE_RX_DONE, 0, 0, 0);
-  }
-  default event message_t* MacRx.received[uint8_t client](message_t *frame, ieee154_reftime_t *timestamp)
-  {
-    call Debug.log(LEVEL_INFO, RadioRxTxP_DEFAULT_RECEIVED, client, call ArbiterInfo.userId(), 0xff);
-    return frame;
-  }
   default async event void MacRadioOff.offDone[uint8_t client]()
   {
-    call Debug.log(LEVEL_CRITICAL, RadioRxTxP_DEFAULT_OFFDONE, 0, 0, 0);
+    ASSERT(0);
   }
 }