[Tinyos-help] [PATCH] StateC calls in Init.init() may be undone

Steve McKown rsmckown at gmail.com
Mon Apr 19 15:12:39 PDT 2010


Hi,

Consider the following:

module MyModP {
  provides interface Init;
  uses interface State;
}
implementation {
  enum {
    S_IDLE = 0,
    S_UNCONFIG,
    ...
  };

  command error_t Init.init()
  {
    call State.forceState(S_UNCONFIG);
    ...
    return SUCCESS;
  }

  ...
}

configuration MyModC {
}
implementation {
  components MainC, MyModP;
  MainC.SoftwareInit -> MyModP;
}

Note that MyModP sets its initial State to something other than zero (S_IDLE).  
However, if ncc happens to order the fanouts for MainC.SoftwareInit.Init() 
such that MyModP.Init.init() is called before StateImplP.Init.init(), then 
MyModP's initial state is reset to S_IDLE.

C specifies that all variables with static storage shall be initialized before 
program startup (C99 5.1.2) and variables with no explicit initializer are 
set to zero (C99 6.7.8.10).  This suggests that the initialization of state[] 
in StateImplP.Init.init() is unnecessary.  It's removal also solves the above 
issue.

All the best,
Steve

diff --git a/tos/system/StateImplP.nc b/tos/system/StateImplP.nc
index 3883ac1..edcde83 100644
--- a/tos/system/StateImplP.nc
+++ b/tos/system/StateImplP.nc
@@ -79,10 +79,6 @@ implementation {

   /***************** Init Commands ****************/
   command error_t Init.init() {
-    int i;
-    for(i = 0; i < uniqueCount(UQ_STATE); i++) {
-      state[i] = S_IDLE;
-    }
     return SUCCESS;
   }



More information about the Tinyos-help mailing list