From 300f3396ac04cfcd11e2455becfd9fea484d3bbe Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 26 May 2009 14:08:51 +0000 Subject: [PATCH] allow contiki motes to handle several contiki events each tick + corrected variables types --- platform/cooja/lib/simEnvChange.c | 8 ++++---- platform/cooja/lib/simEnvChange.h | 7 +++++-- tools/cooja/config/contiki_template.c | 12 ++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) 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; } /*---------------------------------------------------------------------------*/ /**