From: Andy Spencer Date: Tue, 11 Mar 2014 05:45:55 +0000 (+0000) Subject: Work on event output message X-Git-Url: http://pileus.org/git/?p=~andy%2Fcsm213a-hw;a=commitdiff_plain;h=0a7391e68bb9279c509e4066365adf71079c178d Work on event output message --- diff --git a/hw2/main.cpp b/hw2/main.cpp index 5065c3d..72beb38 100644 --- a/hw2/main.cpp +++ b/hw2/main.cpp @@ -79,7 +79,7 @@ void time_ext_sync(uint64_t local, uint64_t world) world = time_last_world; //#ifdef VERBOSE -#if 0 +#if 1 uint64_t error = world > guess ? world - guess : guess > world ? guess - world : 0; int ahead = guess > world; @@ -111,6 +111,9 @@ void time_printf(const char *label, uint64_t local) * Signal generation * *********************/ +#define EMIT_CLOCKS(nsec) ((uint16_t)((nsec) * 24 / 1000)) +#define EMIT_NSEC(clocks) ((uint16_t)((clocks) * 1000 / 24)) + static uint32_t *emit_pcr = 0; // transmit pin name static uint64_t emit_start = 0; // transmit start time (world time) @@ -152,38 +155,39 @@ void emit_init(int alt, PinName pin, PinMode mode) void emit_enable(uint64_t start, uint64_t period) { - const int slack_tick = 0x8000; // tune based on emit_worst + const int slack_clocks = 0x8000; // tune based on emit_worst emit_start = start; emit_period = period; emit_due = start + period; - emit_slack = slack_tick * 1000 / 24; + // TODO - tune slack time + // TODO - check clock power + // TODO - TPM clock source + emit_slack = EMIT_NSEC(slack_clocks); time_printf("emit scheduled", emit_due); } -#define CLOCKS(x) ((uint16_t)((x) * 24 / 1000)) - void emit_schedule(uint64_t when) { uint64_t now = time_to_world(tdma_time()); - uint64_t start = when - now; - uint64_t stop = start + 100000; + uint64_t start = when - now; // transmit time + uint64_t stop = start + 100000; // 100 us pulse // Disable timer TPM1->SC = TPM_SC_TOF_MASK; // Set transmit time - TPM1->CONTROLS[0].CnV = CLOCKS(start); - TPM1->MOD = TPM_MOD_MOD(CLOCKS(stop)); + TPM1->CONTROLS[0].CnV = EMIT_CLOCKS(start); + TPM1->MOD = TPM_MOD_MOD(EMIT_CLOCKS(stop)); // Start the timer TPM1->SC = TPM_SC_TOF_MASK | TPM_SC_PS(1) | TPM_SC_CMOD(1); - // Debug + // Debug output //sirq_printf("emitting event\r\n"); } @@ -306,38 +310,31 @@ void serial_send_sync(sirq_t *port, uint64_t now) * event: id of the received event * time: compensated timestamp of the event */ -void serial_send_event(uint16_t event, uint64_t local) +void serial_send_event(sirq_t *port, uint16_t event, uint64_t local) { time_printf("event received", local); -#if 0 - // Message data - header_t head; - event_msg_t body; - + // Convert timestamp uint64_t world = time_to_world(local); + ntime_t ntime = serial_write_time(world); - ntime_t time = {}; - time.seconds = (uint32_t)(world / NSEC_PER_SEC); - time.nanosec = (uint32_t)(world % NSEC_PER_SEC); + // Message data + header_t head = {}; + event_msg_t body = {}; // Transmit sync message head.header = MSG_HEADER; - head.msgid = MSG_ID_SYNC; + head.msgid = MSG_ID_EVENT; head.length = sizeof(body); head.cksum = 0; // todo - body.seq = serial_xmt_seq; - body.time.seconds = world / NSEC_PER_SEC; - body.time.nanosec = world % NSEC_PER_SEC; - - tdma_stop(serial_tdma_rcv); + body.device = serial_device_id; + body.event = event; + body.time = ntime; - tdma_start(serial_tdma_xmt); + // Transmit message to BBB sirq_write(port, &head, sizeof(head)); sirq_write(port, &body, sizeof(body)); - tdma_stop(serial_tdma_xmt); -#endif } /** @@ -541,7 +538,7 @@ void task_events(uint64_t local, uint64_t world) #endif if (tdma_stamp(tdma_evt, &event)) - serial_send_event(0, event); + serial_send_event(sirq_bbb, 0, event); tdma_stop(tdma_evt); tdma_start(tdma_evt); } diff --git a/hw2/makefile b/hw2/makefile index 83ff187..0798282 100644 --- a/hw2/makefile +++ b/hw2/makefile @@ -14,7 +14,6 @@ control: control.c messages.h run: all control install.sh @./install.sh $(PROG).bin @./control $(UART0) 0 - @sleep 0.0001 @./control $(UART1) 1 sync terms: