diff --git a/platform/cooja/lib/simEnvChange.c b/platform/cooja/lib/simEnvChange.c index b820a8d91..4faba58d3 100644 --- a/platform/cooja/lib/simEnvChange.c +++ b/platform/cooja/lib/simEnvChange.c @@ -26,14 +26,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: simEnvChange.c,v 1.7 2007/08/21 13:09:55 fros4943 Exp $ + * $Id: simEnvChange.c,v 1.8 2009/05/26 14:08:51 fros4943 Exp $ */ +#include "lib/simEnvChange.h" + #include #include -#include "lib/simEnvChange.h" - // All registered interfaces extern const struct simInterface *simInterfaces[]; @@ -43,7 +43,7 @@ char simDoReceiverCallback = 0; int simProcessRunValue; int simEtimerPending; -int simNextExpirationTime; +clock_time_t simNextExpirationTime; void doActionsBeforeTick() { // Poll all interfaces to do their thing before the tick diff --git a/platform/cooja/lib/simEnvChange.h b/platform/cooja/lib/simEnvChange.h index 7f5ac8c00..18527a1ac 100644 --- a/platform/cooja/lib/simEnvChange.h +++ b/platform/cooja/lib/simEnvChange.h @@ -26,12 +26,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: simEnvChange.h,v 1.7 2007/08/21 13:09:55 fros4943 Exp $ + * $Id: simEnvChange.h,v 1.8 2009/05/26 14:08:51 fros4943 Exp $ */ #ifndef __SIMENVCHANGE_H__ #define __SIMENVCHANGE_H__ +#include "contiki.h" + // Simulation interface structure struct simInterface { void (* doActionsBeforeTick) (void); @@ -41,7 +43,8 @@ struct simInterface { // Variable for keeping the last process_run() return value extern int simProcessRunValue; extern int simEtimerPending; -extern int simNextExpirationTime; +extern clock_time_t simNextExpirationTime; +extern clock_time_t simCurrentTime; // Variable that when set to != 0, stops the mote from falling asleep next tick extern char simDontFallAsleep; diff --git a/tools/cooja/config/contiki_template.c b/tools/cooja/config/contiki_template.c index 17881d2a4..6461a79bd 100644 --- a/tools/cooja/config/contiki_template.c +++ b/tools/cooja/config/contiki_template.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: contiki_template.c,v 1.13 2009/04/01 13:38:14 fros4943 Exp $ + * $Id: contiki_template.c,v 1.14 2009/05/26 14:08:51 fros4943 Exp $ */ /** @@ -117,6 +117,10 @@ print_processes(struct process * const processes[]) static void start_process_run_loop(void *data) { + /* Yield once during bootup */ + simProcessRunValue = 1; + cooja_mt_yield(); + /* Initialize random generator */ random_init(0); @@ -155,6 +159,10 @@ start_process_run_loop(void *data) } simProcessRunValue = process_run(); + while (simProcessRunValue-- > 0) { + process_run(); + } + simProcessRunValue = process_nevents(); // Check if we must stay awake if (simDontFallAsleep) { @@ -285,7 +293,7 @@ Java_se_sics_cooja_corecomm_[CLASS_NAME]_tick(JNIEnv *env, jobject obj) } /* Save nearest event timer expiration time (0 if no timers) */ - simNextExpirationTime = etimer_next_expiration_time(); + simNextExpirationTime = etimer_next_expiration_time() - simCurrentTime; } /*---------------------------------------------------------------------------*/ /**