allow contiki motes to handle several contiki events each tick + corrected variables types

This commit is contained in:
fros4943 2009-05-26 14:08:51 +00:00
parent 990aa93d57
commit 300f3396ac
3 changed files with 19 additions and 8 deletions

View file

@ -26,14 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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 <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "lib/simEnvChange.h"
// All registered interfaces // All registered interfaces
extern const struct simInterface *simInterfaces[]; extern const struct simInterface *simInterfaces[];
@ -43,7 +43,7 @@ char simDoReceiverCallback = 0;
int simProcessRunValue; int simProcessRunValue;
int simEtimerPending; int simEtimerPending;
int simNextExpirationTime; clock_time_t simNextExpirationTime;
void doActionsBeforeTick() { void doActionsBeforeTick() {
// Poll all interfaces to do their thing before the tick // Poll all interfaces to do their thing before the tick

View file

@ -26,12 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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__ #ifndef __SIMENVCHANGE_H__
#define __SIMENVCHANGE_H__ #define __SIMENVCHANGE_H__
#include "contiki.h"
// Simulation interface structure // Simulation interface structure
struct simInterface { struct simInterface {
void (* doActionsBeforeTick) (void); void (* doActionsBeforeTick) (void);
@ -41,7 +43,8 @@ struct simInterface {
// Variable for keeping the last process_run() return value // Variable for keeping the last process_run() return value
extern int simProcessRunValue; extern int simProcessRunValue;
extern int simEtimerPending; 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 // Variable that when set to != 0, stops the mote from falling asleep next tick
extern char simDontFallAsleep; extern char simDontFallAsleep;

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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 static void
start_process_run_loop(void *data) start_process_run_loop(void *data)
{ {
/* Yield once during bootup */
simProcessRunValue = 1;
cooja_mt_yield();
/* Initialize random generator */ /* Initialize random generator */
random_init(0); random_init(0);
@ -155,6 +159,10 @@ start_process_run_loop(void *data)
} }
simProcessRunValue = process_run(); simProcessRunValue = process_run();
while (simProcessRunValue-- > 0) {
process_run();
}
simProcessRunValue = process_nevents();
// Check if we must stay awake // Check if we must stay awake
if (simDontFallAsleep) { 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) */ /* Save nearest event timer expiration time (0 if no timers) */
simNextExpirationTime = etimer_next_expiration_time(); simNextExpirationTime = etimer_next_expiration_time() - simCurrentTime;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** /**