]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Check function pointers.
authorscipio <scipio>
Fri, 15 Jun 2007 00:45:18 +0000 (00:45 +0000)
committerscipio <scipio>
Fri, 15 Jun 2007 00:45:18 +0000 (00:45 +0000)
tos/lib/tossim/TossimPacketModelC.nc
tos/lib/tossim/sim_tossim.c

index 981c65fcb4e3791046158ed3680e894b34b6d2f4..392682fb4e6f4f86222be1abb9f4cc67668eb784 100644 (file)
@@ -67,6 +67,7 @@ implementation {
   bool transmitting = FALSE;
   uint8_t sendingLength = 0;
   int destNode;
+  sim_event_t sendEvent;
   
   message_t receiveBuffer;
   
@@ -77,6 +78,10 @@ implementation {
   command error_t Init.init() {
     dbg("TossimPacketModelC", "TossimPacketModelC: Init.init() called\n");
     initialized = TRUE;
+    // We need to cancel in case an event is still lying around in the queue from
+    // before a reboot. Otherwise, the event will be executed normally (node is on),
+    // but its memory has been zeroed out.
+    sendEvent.cancelled = 1;
     return SUCCESS;
   }
 
@@ -167,7 +172,6 @@ implementation {
     return SUCCESS;
   }
 
-  sim_event_t sendEvent;
   void send_backoff(sim_event_t* evt);
   void send_transmit(sim_event_t* evt);
   void send_transmit_done(sim_event_t* evt);
index fb876ffb6d317bc9aa9dd91187a66546ddf58c2c..92df410fe7a0b69ad5f849cd610c7a571591950f 100644 (file)
@@ -111,8 +111,11 @@ bool sim_run_next_event() __attribute__ ((C, spontaneous)) {
     sim_set_time(event->time);
     sim_set_node(event->mote);
 
-    dbg("Tossim", "CORE: popping event for %i at %llu... ", sim_node(), sim_time());
-    if (sim_mote_is_on(event->mote) || event->force) {
+    // Need to test whether function pointers are for statically
+    // allocted events that are zeroed out on reboot
+    dbg("Tossim", "CORE: popping event 0x%p for %i at %llu with handler %p... ", event, sim_node(), sim_time(), event->handle);
+    if ((sim_mote_is_on(event->mote) || event->force) &&
+       event->handle != NULL) {
       result = TRUE;
       dbg_clear("Tossim", " mote is on (or forced event), run it.\n");
       event->handle(event);
@@ -120,7 +123,9 @@ bool sim_run_next_event() __attribute__ ((C, spontaneous)) {
     else {
       dbg_clear("Tossim", "\n");
     }
-    event->cleanup(event);
+    if (event->cleanup != NULL) {
+      event->cleanup(event);
+    }
   }
 
   return result;