]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/rf230/MessageBufferLayerP.nc
moving files from rf230 to rf2xx, prepare the support of rf212
[tinyos-2.x.git] / tos / chips / rf230 / MessageBufferLayerP.nc
index 76ef080b397e911e3f613a3df5c6373f5c79a93a..374edaadbeaee492d79c197ef8045a13c36498e2 100644 (file)
@@ -33,6 +33,7 @@ module MessageBufferLayerP
 
                interface Send;
                interface Receive;
+               interface RadioChannel;
        }
        uses
        {
@@ -58,6 +59,7 @@ implementation
                STATE_TX_DONE = 3,
                STATE_TURN_ON = 4,
                STATE_TURN_OFF = 5,
+               STATE_CHANNEL = 6,
        };
 
        command error_t SplitControl.start()
@@ -98,19 +100,47 @@ implementation
                return error;
        }
 
+       command error_t RadioChannel.setChannel(uint8_t channel)
+       {
+               error_t error;
+
+               call Tasklet.suspend();
+
+               if( state != STATE_READY )
+                       error = EBUSY;
+               else
+                       error = call RadioState.setChannel(channel);
+
+               if( error == SUCCESS )
+                       state = STATE_CHANNEL;
+
+               call Tasklet.resume();
+
+               return error;
+       }
+
+       command uint8_t RadioChannel.getChannel()
+       {
+               return call RadioState.getChannel();
+       }
+
        task void stateDoneTask()
        {
                uint8_t s;
                
                s = state;
 
-               if( s == STATE_TURN_ON || s == STATE_TURN_OFF )
-                       state = STATE_READY;
+               // change the state before so we can be reentered from the event
+               state = STATE_READY;
 
                if( s == STATE_TURN_ON )
                        signal SplitControl.startDone(SUCCESS);
-               else
+               else if( s == STATE_TURN_OFF )
                        signal SplitControl.stopDone(SUCCESS);
+               else if( s == STATE_CHANNEL )
+                       signal RadioChannel.setChannelDone();
+               else    // not our event, ignore it
+                       state = s;
        }
 
        tasklet_async event void RadioState.done()
@@ -126,6 +156,10 @@ implementation
        {
        }
 
+       default event void RadioChannel.setChannelDone()
+       {
+       }
+
 /*----------------- Send -----------------*/
 
        message_t* txMsg;
@@ -257,7 +291,7 @@ implementation
        {
                bool notFull;
 
-               // this prevents undelivered messages to be acknowledged
+               // this prevents undeliverable messages to be acknowledged
                atomic notFull = receiveQueueSize < RECEIVE_QUEUE_SIZE;
 
                return notFull;