Java_se_sics_cooja_corecomm_[CLASS_NAME]_tick(JNIEnv *env, jobject obj) { /* Let all simulation interfaces act first */ simNoYield = 1; doActionsBeforeTick(); simNoYield = 0; /* Check if any e-timers are pending (save result for state decisions) */ if (etimer_pending()) { /* Poll etimers */ etimer_request_poll(); simEtimerPending = 1; } else { simEtimerPending = 0; } /* Let Contiki execute one or a part of the process_run()-function via the thread. This call stores the process_run() return value */ cooja_mt_exec(&process_run_thread); /* Let all simulation interfaces act before returning to java */ simNoYield = 1; doActionsAfterTick(); simNoYield = 0; /* Look for new e-timers */ if (!simEtimerPending && etimer_pending()) { /* Poll etimers */ etimer_request_poll(); simEtimerPending = 1; } /* Save nearest event timer expiration time (0 if no timers) */ simNextExpirationTime = etimer_next_expiration_time(); }
Java_se_sics_cooja_corecomm_[CLASS_NAME]_tick(JNIEnv *env, jobject obj) { /* Let all simulation interfaces act first */ simNoYield = 1; doActionsBeforeTick(); simNoYield = 0; /* Poll etimer process */ if (etimer_pending()) { etimer_request_poll(); } /* Let Contiki handle a few events. This call stores the process_run() return value */ cooja_mt_exec(&process_run_thread); /* Let all simulation interfaces act before returning to java */ simNoYield = 1; doActionsAfterTick(); simNoYield = 0; /* Look for new e-timers */ simEtimerPending = etimer_pending(); /* Save nearest event timer expiration time */ if (simEtimerPending) { simNextExpirationTime = etimer_next_expiration_time() - simCurrentTime; } }
/** * \brief Let mote execute one "block" of code (tick mote). * * Let mote defined by the active contiki processes and current * process memory execute some program code. This code must not block * or else this function will never return. A typical contiki * process will return when it executes PROCESS_WAIT..() statements. * * Before the control is left to contiki processes, any messages * from the Java part are handled. These may for example be * incoming network data. After the contiki processes return control, * messages to the Java part are also handled (those which may need * special attention). * * This is a JNI function and should only be called via the * responsible Java part (MoteType.java). */ JNIEXPORT void JNICALL Java_org_contikios_cooja_corecomm_CLASSNAME_tick(JNIEnv *env, jobject obj) { clock_time_t nextEtimer; rtimer_clock_t nextRtimer; simProcessRunValue = 0; /* Let all simulation interfaces act first */ doActionsBeforeTick(); /* Poll etimer process */ if (etimer_pending()) { etimer_request_poll(); } /* Let rtimers run. * Sets simProcessRunValue */ cooja_mt_exec(&rtimer_thread); if(simProcessRunValue == 0) { /* Rtimers done: Let Contiki handle a few events. * Sets simProcessRunValue */ cooja_mt_exec(&process_run_thread); } /* Let all simulation interfaces act before returning to java */ doActionsAfterTick(); /* Do we have any pending timers */ simEtimerPending = etimer_pending() || rtimer_arch_pending(); if(!simEtimerPending) { return; } /* Save nearest expiration time */ nextEtimer = etimer_next_expiration_time() - (clock_time_t) simCurrentTime; nextRtimer = rtimer_arch_next() - (rtimer_clock_t) simCurrentTime; if(etimer_pending() && rtimer_arch_pending()) { simNextExpirationTime = MIN(nextEtimer, nextRtimer); } else if (etimer_pending()) { simNextExpirationTime = nextEtimer; } else if (rtimer_arch_pending()) { simNextExpirationTime = nextRtimer; } }