/*---------------------------------------------------------------------------*/ static void process_run_thread_loop(void *data) { /* Yield once during bootup */ simProcessRunValue = 1; cooja_mt_yield(); contiki_init(); while(1) { simProcessRunValue = process_run(); while(simProcessRunValue-- > 0) { process_run(); } simProcessRunValue = process_nevents(); /* Check if we must stay awake */ if(simDontFallAsleep) { simDontFallAsleep=0; simProcessRunValue = 1; } /* Return to COOJA */ cooja_mt_yield(); } }
/*---------------------------------------------------------------------------*/ int main(int argc, char **argv) { PRINTF(">> %s:main()\n", __FILE__); start: /* Yield once during bootup */ kleenet_schedule_state(MILLISECOND); kleenet_yield_state(); simCurrentTime = NODE_TIME(); PRINTF("> Executing Contiki at simulation time %lu\n", clock_time()); /* Code from contiki-cooja-main.c:process_run_thread_loop (before loop) */ doActionsBeforeTick(); contiki_init(); doActionsAfterTick(); while (1) { /* reboot */ if ((clock_seconds() >= failure_delay()) && reboot_once) { /* symbolic node reboot every 10 seconds */ if (clock_seconds() % 10 == 0) { if (failure_reboot_node()) { PRINTF("main(): rebooting node once @ %lu, %lu seconds\n", clock_time(), clock_seconds()); reboot_once = 0; exit_all_processes(); goto start; } } } /* halt */ if ((clock_seconds() >= failure_delay()) && halt_once) { /* symbolic node outage every 10 seconds */ if (clock_seconds() % 10 == 0) { if (failure_halt_node()) { PRINTF("main(): halting node once @ %lu, %lu seconds\n", clock_time(), clock_seconds()); halt_once = 0; exit_all_processes(); /* loop forerver */ while(1) { kleenet_schedule_state(MILLISECOND); kleenet_yield_state(); } } } } /* Update time */ simCurrentTime = NODE_TIME(); simProcessRunValue = 0; /* Do actions before tick */ doActionsBeforeTick(); /* Poll etimer process */ if (etimer_pending()) { etimer_request_poll(); } /* Code from contiki-cooja-main.c:process_run_thread_loop */ simProcessRunValue = process_run(); while(simProcessRunValue-- > 0) { process_run(); } simProcessRunValue = process_nevents(); /* Do actions after tick */ doActionsAfterTick(); /* Request next tick for remaining events / timers */ if (simProcessRunValue != 0) { kleenet_schedule_state(MILLISECOND); kleenet_yield_state(); continue; } /* Request tick next wakeup time */ if (etimer_pending()) { simNextExpirationTime = etimer_next_expiration_time() - simCurrentTime; } else { simNextExpirationTime = 0; PRINTF("WARNING: No more timers pending\n"); kleenet_schedule_state(MILLISECOND); kleenet_yield_state(); continue; } /* check next expiration time */ if (simNextExpirationTime <= 0) { PRINTF("WARNING: Event timer already expired, but has been delayed: %lu\n", simNextExpirationTime); kleenet_schedule_state(MILLISECOND); } else { kleenet_schedule_state(simNextExpirationTime*MILLISECOND); } /* yield active state */ kleenet_yield_state(); } return 0; }
/*-----------------------------------------------------------------------------------*/ int main(int argc, char **argv) { /* irqload_init();*/ #ifdef WITH_UIP uip_init(); uip_main_init(); resolv_init(); #ifdef WITH_TFE cs8900a_init(); #endif /* WITH_TFE */ #ifdef WITH_RS232 rs232dev_init(); #endif /* WITH_RS232 */ #ifdef WITH_TAPDEV tapdev_init(); #endif /* WITH_TAPDEV */ #endif /* WITH_UIP */ conio_init(); textcolor(1);bgcolor(0); clrscr(); conio_update(); //joy_load_driver(joy_stddrv); #if 0 { int i,j; clrscr(); textcolor(0);bgcolor(1); while(1) { gotoxy(0,0); cprintf("%d\n",i++); conio_update(); if(kbhit()) { cprintf(" "); cprintf("%02x",cgetc()); cprintf("\n"); } else { cprintf("pressed: ---------\n"); } j=joy_read(0); cprintf("%08x\n",j); } } #endif ek_init(); dispatcher_init(); ctk_init(); contiki_init(); programs_init(); ctk_redraw(); ek_run(); clrscr(); return 0; argv = argv; argc = argc; }