]> Pileus Git - ~andy/csm213a-hw/commitdiff
Work on event output message
authorAndy Spencer <andy753421@gmail.com>
Tue, 11 Mar 2014 05:45:55 +0000 (05:45 +0000)
committerAndy Spencer <andy753421@gmail.com>
Tue, 11 Mar 2014 05:45:55 +0000 (05:45 +0000)
hw2/main.cpp
hw2/makefile

index 5065c3d939acb8e3d3ae6373c69ca744595cdf10..72beb38c7858f51dc40256ec126f1db294cf757b 100644 (file)
@@ -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);
 }
index 83ff18724715542f5b945145213edf4ebdffc5a9..07982822dc6d5f9c0c50a8310a621a3e61e6e3f5 100644 (file)
@@ -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: