]> Pileus Git - ~andy/csm213a-hw/commitdiff
Start work on interfaces
authorAndy Spencer <andy753421@gmail.com>
Mon, 3 Mar 2014 17:54:44 +0000 (17:54 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 3 Mar 2014 17:54:44 +0000 (17:54 +0000)
hw2/main.cpp

index a43bc8e80c4b406e1165624a614ff0b46c847d1a..436f750508e6f815b32c6d2c617c8a054c2631dd 100644 (file)
@@ -1,8 +1,128 @@
 #include "mbed.h"\r
 \r
+/**\r
+ * Mode of operation:\r
+ *   Devices 1 and 2 synchronize clocks using serial messages.\r
+ *\r
+ *   1. Each serial message timestamped using the hardware timer capture\r
+ *      registers in both the sender and receiver.\r
+ *   2. The sender transmits the send timestamp during the next time-sync\r
+ *      message.\r
+ *   3. The receiver then compares the senders timestamp with it's own\r
+ *      timestamp for the corresponding messages and calculates an offset.\r
+ *   4. The offset is used to compensate the receivers local clock.\r
+ *\r
+ *   Time synchronization is performed in both directions.\r
+ */\r
+\r
+/***********************\r
+ * Message Definitions *\r
+ ***********************/\r
+\r
+#define MSG_HEADER 0x1234\r
+\r
+typedef enum {\r
+       MSG_ID_SYNC,       // Time synchronization\r
+       MSG_ID_EVENT,      // Event occurred\r
+} msgid_t;\r
+\r
+typedef struct {\r
+       uint32_t seconds;  // Seconds since 1970 (without leap seconds)\r
+       uint32_t nanosec;  // Nanoseconds since 'seconds'\r
+} ntime_t;\r
+\r
+typedef struct {\r
+       uint16_t header;   // Message Header\r
+       uint16_t mesgid;   // Message ID\r
+       uint16_t length;   // Body length\r
+       uint16_t cksum;    // Body checksum\r
+} header_t;\r
+\r
+typedef struct {\r
+       uint16_t seq;      // Current sequence counter\r
+       uint16_t prev;     // Sequence of previous message\r
+       ntime_t  time;     // Time of previous message\r
+} sync_msg_t;\r
+\r
+typedef struct {\r
+       uint16_t device;   // Device ID\r
+       uint16_t event;    // Event ID\r
+       ntime_t  time;     // Timestamp\r
+} event_msg_t;\r
+\r
+/*******************\r
+ * Timer functions *\r
+ *******************/\r
+\r
+/**\r
+ * Generate time stamp for an async event:\r
+ *   time:  drift compensated wall-clock time\r
+ *   stamp: event timestamp from Timer/PWM Module\r
+ */\r
+void time_stamp(ntime_t *time, uint32_t stamp)\r
+{\r
+       // todo\r
+}\r
+\r
+/**\r
+ * Compensate the Real-Time-Clock oscillator for\r
+ * temperature and drift errors. Called at 1Hz and\r
+ * synchronous to the RTC 1Hz output.\r
+ */\r
+void time_rtc_comp(void)\r
+{\r
+       // todo\r
+}\r
+\r
+/**\r
+ * Synchronize the timer internal state with updates\r
+ * from an external time sync message.\r
+ *   ours: our internal timestamp for the event\r
+ *   ref:  reference timestamp from the other device\r
+ */\r
+void time_ext_sync(ntime_t *ours, ntime_t *ref)\r
+{\r
+       // todo\r
+}\r
+\r
+/************************\r
+ * Serial I/O functions *\r
+ ************************/\r
+\r
+/**\r
+ * Output time sync message\r
+ */\r
+void serial_send_sync(void)\r
+{\r
+}\r
+\r
+/**\r
+ * Output external event received message\r
+ *   event: id of the received event\r
+ *   time:  compensated timestamp of the event \r
+ */\r
+void serial_send_event(uint16_t event, ntime_t *time)\r
+{\r
+}\r
+\r
+/**\r
+ * Process serial receive messages\r
+ */\r
+void serial_receive(void)\r
+{\r
+}\r
+\r
+/********************\r
+ * Data definitions *\r
+ ********************/\r
+\r
 DigitalOut led1(LED1);\r
 DigitalOut led2(LED2);\r
 \r
+/********\r
+ * Main *\r
+ ********/\r
+\r
 int main(int argc, char **argv)\r
 {\r
     while (1) {\r