]> Pileus Git - ~andy/csm213a-hw/blobdiff - hw2/main_comm.c
Fix event scheduling bug
[~andy/csm213a-hw] / hw2 / main_comm.c
index d5c66b168c7a66f1cc89ff7988cf6ee4245dd359..118f6b3cd42f2499528829e5568fd7c1f00a490e 100644 (file)
@@ -228,12 +228,6 @@ void comm_handle_init(header_t *head, init_msg_t *body)
        if (body->control & MSG_CTL_VALID_DEVICE)
                comm_device_id = body->device;
 
-       if (body->control & MSG_CTL_VALID_START)
-               emit_set_start(comm_read_time(body->start));
-
-       if (body->control & MSG_CTL_VALID_PERIOD)
-               emit_set_period(comm_read_time(body->period));
-
        if (body->control & MSG_CTL_VALID_WORLD)
                time_ext_init(tdma_time(), comm_read_time(body->world));
 
@@ -244,6 +238,13 @@ void comm_handle_init(header_t *head, init_msg_t *body)
 
        if (body->control & MSG_CTL_BEGIN_SYNC)
                comm_sync_due = tdma_time() + comm_sync_delay;
+
+       // Run these after world time is valid
+       if (body->control & MSG_CTL_VALID_START)
+               emit_set_start(comm_read_time(body->start));
+
+       if (body->control & MSG_CTL_VALID_PERIOD)
+               emit_set_period(comm_read_time(body->period));
 }
 
 /**