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));
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));
}
/**
// | @ | @ | @ |
// utc-^ last-^ now-^
if (emit_period) {
- uint64_t now = tdma_time();
+ uint64_t now = time_to_world(tdma_time());
uint64_t phase = emit_start % emit_period;
uint64_t last = (now / emit_period) * emit_period;
emit_due = last + phase;
+ time_printf("emit scheduled", emit_due);
} else {
emit_due = 0;
}
-
- time_printf("emit scheduled", emit_due);
}
void emit_init(int alt, PinName pin, PinMode mode)
prev = local;
// Schedule task if needed
- if (emit_due && emit_period &&
- world+emit_slack > emit_due) {
+ if (emit_period && world+emit_slack > emit_due) {
emit_schedule(emit_due);
emit_due += emit_period;
- if (emit_due < local)
- sirq_printf("missed emit deadline\r\n");
+ }
+ if (emit_period && emit_due < world) {
+ sirq_printf("missed emit deadline\r\n");
+ time_printf(" due ", emit_due);
+ time_printf(" period", emit_period);
+ time_printf(" world ", world);
+ emit_setup();
}
}
-