]> Pileus Git - ~andy/csm213a-hw/blob - hw2/main.cpp
Debug PWM output
[~andy/csm213a-hw] / hw2 / main.cpp
1 #include "messages.h"
2
3 #include "mbed.h"
4 #include "serial_irq.h"
5 #include "serial_dma.h"
6 #include "timer_dma.h"
7
8 /**
9  * Mode of operation:
10  *   Devices 1 and 2 synchronize clocks using serial messages.
11  *
12  *   1. Each serial message timestamped using the hardware timer capture
13  *      registers in both the sender and receiver.
14  *   2. The sender transmits the send timestamp during the next time-sync
15  *      message.
16  *   3. The receiver then compares the senders timestamp with it's own
17  *      timestamp for the corresponding messages and calculates an offset.
18  *   4. The offset is used to compensate the receivers local clock.
19  *
20  *   Time synchronization is performed in both directions.
21  */
22
23 /*******************
24  * Timer functions *
25  *******************/
26
27 #define NSEC_PER_SEC 1000000000ULL
28
29 uint64_t time_last_local; // timestamp at last time sync
30 uint64_t time_last_world; // offset at last time sync
31
32 /**
33  * Generate time stamp for an async event:
34  *   time:  drift compensated wall-clock time
35  *   stamp: event timestamp from PIT Module
36  */
37 uint64_t time_to_world(uint64_t local)
38 {
39         uint64_t elapsed = local - time_last_local;
40         return time_last_world + elapsed;
41 }
42
43 /**
44  * Synchronize the timer internal state with updates
45  * from an external time sync message.
46  *   local: our internal timestamp for the event
47  *   world: reference timestamp from the other device
48  */
49 void time_ext_init(uint64_t local, uint64_t world)
50 {
51         sirq_printf("initialize clocks: %d -> %d\r\n",
52                         (int)(local/NSEC_PER_SEC),
53                         (int)(world/NSEC_PER_SEC));
54
55         time_last_local = local;
56         time_last_world = world;
57 }
58
59 /**
60  * Synchronize the timer internal state with updates
61  * from an external time sync message.
62  *   local: our internal timestamp for the event
63  *   world: reference timestamp from the other device
64  */
65 void time_ext_sync(uint64_t local, uint64_t world)
66 {
67         uint64_t guess = time_to_world(local);
68
69         time_last_local = local;
70         time_last_world = (guess/2) + (world/2);
71         //time_last_world = (guess * 3 / 4) + (world * 1 / 4);
72         //time_last_world =
73         //      (guess - (        guess / 2)) +
74         //      (world - (world - world / 2));
75         //time_last_world =
76         //      (guess - (guess - guess / 4)) +
77         //      (world - (        world / 4));
78
79         world = time_last_world;
80
81 //#ifdef VERBOSE
82 #if 0
83         uint64_t error = world > guess ? world - guess :
84                          guess > world ? guess - world : 0;
85         int      ahead = guess > world;
86         sirq_printf("syncing clocks: %6d=%d.%04u -> %d.%04u (err: %s%ld.%09lu)\r\n",
87                         (int)((local / NSEC_PER_SEC)),
88                         (int)((guess / NSEC_PER_SEC)),
89                         (int)((guess % NSEC_PER_SEC)/(NSEC_PER_SEC/10000)),
90                         (int)((world / NSEC_PER_SEC)),
91                         (int)((world % NSEC_PER_SEC)/(NSEC_PER_SEC/10000)),
92                         ahead ? "-" : " ",
93                         (int32_t )(error / (int64_t)NSEC_PER_SEC),
94                         (uint32_t)(error % (int64_t)NSEC_PER_SEC));
95 #endif
96 //#endif
97 }
98
99 void time_printf(const char *label, uint64_t local)
100 {
101         uint64_t world = time_to_world(local);
102         sirq_printf("%s -- %d.%09u -> %d.%09u\r\n",
103                         label,
104                         (int)(local / NSEC_PER_SEC),
105                         (int)(local % NSEC_PER_SEC),
106                         (int)(world / NSEC_PER_SEC),
107                         (int)(world % NSEC_PER_SEC));
108 }
109
110 /*********************
111  * Signal generation *
112  *********************/
113
114 static uint32_t *emit_pcr    = 0; // transmit pin name
115
116 static uint64_t  emit_start  = 0; // transmit start time (world time)
117 static uint64_t  emit_period = 0; // transmit period
118 static uint64_t  emit_due    = 0; // next transmit (world time)
119
120 static uint32_t  emit_slack  = 0; // how far ahead we need to schedule, in us
121 static uint32_t  emit_worst  = 0; // worst-case latency in task table
122
123 void emit_init(int alt, PinName pin, PinMode mode)
124 {
125         // Find pin
126         emit_pcr = (uint32_t*)(PORTA_BASE + pin);
127
128         // Enable clocks
129         SIM->SCGC6            |= SIM_SCGC6_TPM1_MASK;
130         SIM->SOPT2            |= SIM_SOPT2_TPMSRC(1);
131
132         // Set pin mode
133         emit_pcr[0]            = PORT_PCR_ISF_MASK
134                                | PORT_PCR_MUX(alt)
135                                | mode;
136
137         // Setup Timer/PWM Module
138         TPM1->SC               = TPM_SC_TOF_MASK;
139         TPM1->CNT              = TPM_CNT_COUNT(0);
140         TPM1->MOD              = TPM_MOD_MOD(0xFFFF);
141
142         TPM1->CONTROLS[0].CnSC = TPM_CnSC_CHF_MASK    // clear flag
143                                | TPM_CnSC_MSB_MASK    // set output highon match,
144                                | TPM_CnSC_ELSB_MASK   // cleared on overflow
145                                | TPM_CnSC_ELSA_MASK;  // ..
146
147         TPM1->STATUS           = TPM_STATUS_CH0F_MASK
148                                | TPM_STATUS_TOF_MASK;
149
150         TPM1->CONF             = TPM_CONF_CSOO_MASK;
151 }
152
153 void emit_enable(uint64_t start, uint64_t period)
154 {
155         const int slack_tick = 0x8000; // tune based on emit_worst
156
157         emit_start  = start;
158         emit_period = period;
159         emit_due    = start + period;
160
161         emit_slack  = slack_tick * 1000 / 24;
162
163         time_printf("emit scheduled", emit_due);
164 }
165
166 #define CLOCKS(x) ((uint16_t)((x) * 24 / 1000))
167
168 void emit_schedule(uint64_t when)
169 {
170         uint64_t now    = time_to_world(tdma_time());
171         uint64_t start  = when - now;
172         uint64_t stop   = start + 100000;
173
174         // Disable timer
175         TPM1->SC               = TPM_SC_TOF_MASK;
176
177         // Set transmit time
178         TPM1->CONTROLS[0].CnV  = CLOCKS(start);
179         TPM1->MOD              = TPM_MOD_MOD(CLOCKS(stop));
180
181         // Start the timer
182         TPM1->SC               = TPM_SC_TOF_MASK
183                                | TPM_SC_PS(1)
184                                | TPM_SC_CMOD(1);
185
186         // Debug
187         //sirq_printf("emitting event\r\n");
188 }
189
190 void emit_transmit(uint64_t local, uint64_t world)
191 {
192         static uint64_t prev = 0;
193
194         // Record how how much time we have to reschedule
195         if (prev && (local-prev) > emit_worst)
196                 emit_worst = (local-prev);
197         prev = local;
198
199         // Schedule task if needed
200         if (emit_due && emit_period &&
201             world+emit_slack > emit_due) {
202                 emit_schedule(emit_due);
203                 emit_due += emit_period;
204         }
205 }
206
207 /************************
208  * Serial I/O functions *
209  ************************/
210
211 typedef struct {
212         int      index;
213         int      state;
214         uint8_t  buffer[256];
215 } parser_t;
216
217 static uint32_t serial_device_id   = 0;
218
219 const  uint64_t serial_sync_delay  = NSEC_PER_SEC / 100; // 1hz
220 static uint64_t serial_sync_due    = 0;
221
222 static tdma_t  *serial_tdma_rcv    = NULL;
223 static tdma_t  *serial_tdma_xmt    = NULL;
224
225 static uint64_t serial_prev_local  = 0;
226 static uint64_t serial_prev_seq    = 0;
227
228 static uint64_t serial_xmt_local   = 0;
229 static uint64_t serial_xmt_seq     = 0;
230
231 /**
232  * Convert world to local time
233  */
234 uint64_t serial_read_time(ntime_t time)
235 {
236         return ((uint64_t)time.seconds) * NSEC_PER_SEC
237              + ((uint64_t)time.nanosec);
238 }
239
240 ntime_t serial_write_time(uint64_t time)
241 {
242         ntime_t buf = {};
243         buf.seconds = time / NSEC_PER_SEC;
244         buf.nanosec = time % NSEC_PER_SEC;
245         return buf;
246 }
247
248 /**
249  * Output initialization message init message
250  */
251 void serial_send_init(uint16_t device, uint64_t local)
252 {
253 }
254
255 /**
256  * Output time sync message
257  */
258 void serial_send_sync(sirq_t *port, uint64_t now)
259 {
260         if (serial_sync_due == 0 || now < serial_sync_due)
261                 return; // not ready
262
263         //sirq_printf("sending sync\r\n");
264
265         // Calculate world time
266         uint64_t local = 0;
267         uint64_t world = time_to_world(serial_xmt_local);
268
269         // Message data
270         header_t   head;
271         sync_msg_t body;
272
273         // Transmit sync message
274         head.header = MSG_HEADER;
275         head.msgid  = MSG_ID_SYNC;
276         head.length = sizeof(body);
277         head.cksum  = 0; // todo
278
279         body.seq          = serial_xmt_seq;
280         body.time.seconds = world / NSEC_PER_SEC;
281         body.time.nanosec = world % NSEC_PER_SEC;
282
283         tdma_stop(serial_tdma_rcv);
284
285         tdma_start(serial_tdma_xmt);
286         sirq_write(port, &head, sizeof(head));
287         sirq_write(port, &body, sizeof(body));
288         tdma_stop(serial_tdma_xmt);
289
290         // save transmit time
291         int valid = tdma_stamp(serial_tdma_xmt, &local);
292         if (!valid)
293                 sirq_printf("sync transmit time -- missed\r\n");
294         else
295                 //time_printf("sync transmit time ", local);
296
297         tdma_start(serial_tdma_rcv);
298
299         serial_xmt_seq  += 1;
300         serial_sync_due  = 0;
301         serial_xmt_local = local;
302 }
303
304 /**
305  * Output external event received message
306  *   event: id of the received event
307  *   time:  compensated timestamp of the event
308  */
309 void serial_send_event(uint16_t event, uint64_t local)
310 {
311         time_printf("event received", local);
312
313 #if 0
314         // Message data
315         header_t    head;
316         event_msg_t body;
317
318         uint64_t world = time_to_world(local);
319
320         ntime_t time = {};
321         time.seconds = (uint32_t)(world / NSEC_PER_SEC);
322         time.nanosec = (uint32_t)(world % NSEC_PER_SEC);
323
324         // Transmit sync message
325         head.header = MSG_HEADER;
326         head.msgid  = MSG_ID_SYNC;
327         head.length = sizeof(body);
328         head.cksum  = 0; // todo
329
330         body.seq          = serial_xmt_seq;
331         body.time.seconds = world / NSEC_PER_SEC;
332         body.time.nanosec = world % NSEC_PER_SEC;
333
334         tdma_stop(serial_tdma_rcv);
335
336         tdma_start(serial_tdma_xmt);
337         sirq_write(port, &head, sizeof(head));
338         sirq_write(port, &body, sizeof(body));
339         tdma_stop(serial_tdma_xmt);
340 #endif
341 }
342
343 /**
344  * Handle init message
345  */
346 void serial_handle_init(init_msg_t *msg)
347 {
348         sirq_printf("initialize: %s %s %s %s %s\r\n",
349                 msg->valid & MSG_VALID_DEVICE ? "DEV"    : "dev",
350                 msg->valid & MSG_VALID_START  ? "START"  : "start",
351                 msg->valid & MSG_VALID_PERIOD ? "PERIOD" : "period",
352                 msg->valid & MSG_VALID_WORLD  ? "WORLD"  : "world",
353                 msg->valid & MSG_VALID_SYNC   ? "SYNC"   : "sync");
354         sirq_printf("  dev    -- %d\r\n", msg->device);
355         time_printf("  start ", serial_read_time(msg->start));
356         time_printf("  period", serial_read_time(msg->period));
357         time_printf("  world ", serial_read_time(msg->world));
358
359         if (msg->valid & MSG_VALID_DEVICE)
360                 serial_device_id = msg->device;
361
362         if (msg->valid & MSG_VALID_START ||
363             msg->valid & MSG_VALID_PERIOD) {
364                 uint64_t start  = serial_read_time(msg->start);
365                 uint64_t period = serial_read_time(msg->period);
366                 emit_enable(start, period);
367         }
368
369         if (msg->valid & MSG_VALID_WORLD) {
370                 uint64_t world = serial_read_time(msg->world);
371                 uint64_t local = tdma_time();
372                 time_ext_init(local, world);
373         }
374
375         if (msg->valid & MSG_VALID_SYNC)
376                 serial_sync_due = tdma_time() + serial_sync_delay;
377 }
378
379 /**
380  * Handle sync message
381  */
382 void serial_handle_sync(sync_msg_t *msg)
383 {
384         // Read receive timestamp for next time sync message
385         uint64_t current = 0;
386         int valid = tdma_stamp(serial_tdma_rcv, &current);
387         if (!valid)
388                 sirq_printf("sync receive time  -- missing\r\n");
389         //else
390         //      time_printf("sync receive time ", current);
391         tdma_stop(serial_tdma_rcv);
392
393         // Lookup times
394         uint64_t world = ((uint64_t)msg->time.seconds) * NSEC_PER_SEC
395                        + ((uint64_t)msg->time.nanosec);
396
397         // Valid times timestamp
398         if (serial_prev_seq == (msg->seq-1)) {
399                 uint64_t local = serial_prev_local;
400                 time_ext_sync(local, world);
401         }
402
403         // Queue transmit to other board
404         serial_sync_due   = tdma_time() + serial_sync_delay;
405
406         // Update states
407         serial_prev_local = current;
408         serial_prev_seq   = msg->seq;
409 }
410
411 /**
412  * Handle event message
413  */
414 void serial_handle_event(event_msg_t *msg)
415 {
416 }
417
418 /**
419  * Deliver message
420  */
421 void serial_deliver(int msgid, void *body)
422 {
423         switch (msgid) {
424                 case MSG_ID_INIT:
425                         //sirq_printf("received init msg\r\n");
426                         serial_handle_init((init_msg_t*)body);
427                         break;
428                 case MSG_ID_SYNC:
429                         //sirq_printf("received sync msg\r\n");
430                         serial_handle_sync((sync_msg_t*)body);
431                         break;
432                 case MSG_ID_EVENT:
433                         //sirq_printf("received event msg\r\n");
434                         serial_handle_event((event_msg_t*)body);
435                         break;
436         }
437 }
438
439 /**
440  * Process serial receive messages
441  */
442 void serial_receive(parser_t *parser, int byte)
443 {
444         //sirq_printf("serial_receive - %02x\r\n", byte);
445
446         // Lookup pointers
447         header_t *head = (header_t*)parser->buffer;
448         void     *body = (void*)(head+1);
449         const int max_length = sizeof(parser->buffer)-sizeof(header_t);
450
451         // Process uart messages
452         parser->buffer[parser->index++] = byte;
453         switch (parser->state) {
454                 case 0: // Search
455                         if (parser->index == sizeof(uint16_t)) {
456                                 if (head->header == MSG_HEADER) {
457                                         parser->state = 1;
458                                 } else {
459                                         parser->buffer[0] = parser->buffer[1];
460                                         parser->index = 1;
461                                 }
462                         }
463                         break;
464                 case 1: // Header
465                         if (parser->index == sizeof(header_t)) {
466                                 if (head->length <= max_length &&
467                                     head->msgid  <= MSG_MAX_ID) {
468                                         parser->state = 2;
469                                 } else {
470                                         parser->index = 0;
471                                         parser->state = 0;
472                                 }
473                         }
474                         break;
475                 case 2: // Data
476                         if (parser->index == (int)sizeof(header_t)+head->length) {
477                                 serial_deliver(head->msgid, body);
478                                 parser->index = 0;
479                                 parser->state = 0;
480                         }
481                         break;
482         }
483 }
484
485 /********************
486  * Data definitions *
487  ********************/
488
489 // LEDs
490 DigitalOut led1(LED1);
491 DigitalOut led2(LED2);
492
493 // Message Parsers
494 parser_t   parser_dbg;
495 parser_t   parser_bbb;
496 parser_t   parser_mbed;
497
498 // Serial IRQ
499 sirq_t    *sirq_dbg;
500 sirq_t    *sirq_bbb;
501 sirq_t    *sirq_mbed;
502
503 // Timer DMA
504 tdma_t    *tdma_evt;
505 tdma_t    *tdma_rcv;
506 tdma_t    *tdma_xmt;
507
508 /*********
509  * Tasks *
510  *********/
511
512 void task_serial(uint64_t local, uint64_t world)
513 {
514         while (sirq_ready(sirq_dbg)) {
515                 //sirq_printf("serial recv - dbg\r\n");
516                 serial_receive(&parser_dbg,  sirq_getc(sirq_dbg));
517         }
518
519         while (sirq_ready(sirq_bbb)) {
520                 //sirq_printf("serial recv - bbb\r\n");
521                 serial_receive(&parser_bbb,  sirq_getc(sirq_bbb));
522         }
523
524         while (sirq_ready(sirq_mbed)) {
525                 //sirq_printf("serial recv - mbed\r\n");
526                 serial_receive(&parser_mbed, sirq_getc(sirq_mbed));
527         }
528 }
529
530 void task_events(uint64_t local, uint64_t world)
531 {
532         uint64_t event = 0;
533
534 #ifdef VERBOSE
535         if (tdma_stamp(tdma_evt, &event)) {
536                 sirq_printf("event received - evt\r\n");
537         if (tdma_stamp(tdma_rcv, &event))
538                 sirq_printf("event received - rcv\r\n");
539         if (tdma_stamp(tdma_xmt, &event))
540                 sirq_printf("event received - xmt\r\n");
541 #endif
542
543         if (tdma_stamp(tdma_evt, &event))
544                 serial_send_event(0, event);
545         tdma_stop(tdma_evt);
546         tdma_start(tdma_evt);
547 }
548
549 void task_sync(uint64_t local, uint64_t world)
550 {
551         serial_send_sync(sirq_mbed, local);
552 }
553
554 void task_leds(uint64_t local, uint64_t world)
555 {
556         static uint32_t which = 0;
557         led1 = (which == 0);
558         led2 = (which == 1);
559         which ^= 1;
560 }
561
562 void task_emit(uint64_t local, uint64_t world)
563 {
564         emit_transmit(local, world);
565 }
566
567 void task_debug(uint64_t local, uint64_t world)
568 {
569         //tdma_debug(tdma_rcv);
570         //tdma_debug(tdma_xmt);
571
572         //sirq_debug(sirq_mbed);
573
574 #ifdef VERBOSE
575         sirq_printf("background - %6u.%02u -> %u.%02u\r\n",
576                         (uint32_t)(local / NSEC_PER_SEC),
577                         (uint32_t)(local % NSEC_PER_SEC / 10000000),
578                         (uint32_t)(world / NSEC_PER_SEC),
579                         (uint32_t)(world % NSEC_PER_SEC / 10000000));
580 #endif
581 }
582
583 /********
584  * Main *
585  ********/
586
587 #define N_ELEM(x) (sizeof(x) / sizeof((x)[0]))
588
589 extern void test_main(void);
590 extern serial_t stdio_uart;
591
592 static struct {
593         void (*task)(uint64_t, uint64_t);
594         uint64_t period;
595         uint64_t due;
596 } tasks[] = {
597         { task_serial, 0          }, // always
598         { task_events, 0          }, // always -- testing
599         { task_sync,   0          }, // always
600         { task_emit,   0          }, // always
601         { task_leds,   100000000  }, // 10hz
602         { task_debug,  1000000000 }, // 1hz
603 };
604
605 void background(void)
606 {
607         // Debugging
608         uint64_t local = tdma_time();
609         uint64_t world = time_to_world(local);
610
611         // Run the scheduler
612         for (unsigned i = 0; i < N_ELEM(tasks); i++) {
613                 if (local >= tasks[i].due) {
614                         tasks[i].task(local, world);
615                         tasks[i].due += tasks[i].period;
616                 }
617         }
618 }
619
620 int main(int argc, char **argv)
621 {
622         tdma_init();
623         emit_init(3, PTE20, PullDown);
624
625         //pin = 1;
626
627         // Open serial ports
628         sirq_dbg   = sirq_open(SIRQ_UART0, USBTX, USBRX, 115200); // to pc
629         sirq_bbb   = sirq_open(SIRQ_UART1, PTE0,  PTE1,  115200); // to bbb
630         sirq_mbed  = sirq_open(SIRQ_UART2, PTD3,  PTD2,  115200); // to mbed
631
632         // Setup timers
633         tdma_evt   = tdma_open(TDMA_CHAN0, 3, PTC9,  PullDown); // async event
634
635         // mbed time sync
636         tdma_rcv   = tdma_open(TDMA_CHAN2, 3, PTD2,  PullUp);   // time sync rcv
637         tdma_xmt   = tdma_open(TDMA_CHAN3, 3, PTD3,  PullUp);   // time sync xmt
638
639         // host time sync
640         //tdma_rcv   = tdma_open(TDMA_CHAN2, 2, USBRX, PullUp); // time sync rcv
641         //tdma_xmt   = tdma_open(TDMA_CHAN3, 2, USBTX, PullUp); // time sync xmt
642
643         // start timers
644         tdma_start(tdma_evt);
645         tdma_start(tdma_rcv);
646         tdma_start(tdma_xmt);
647
648         // Serial timestamping
649         serial_tdma_rcv = tdma_rcv;
650         serial_tdma_xmt = tdma_xmt;
651
652         // Test clocks
653         //MCG->C1    = 0x05; // was 0x1A
654         //MCG->C2    = 0x2C; // was 0x24
655         //MCG->C3    = 0x91; // was 0x91
656         //MCG->C4    = 0x10; // was 0x10
657         //MCG->C5    = 0x01; // was 0x01
658         //MCG->C6    = 0x40; // was 0x40
659         //MCG->S     = 0x6E; // was 0x6E
660         //MCG->SC    = 0x02; // was 0x02
661         //MCG->ATCVH = 0x00; // was 0x00
662         //MCG->ATCVL = 0x00; // was 0x00
663         //MCG->C7    = 0x00; // was 0x00
664         //MCG->C8    = 0x80; // was 0x80
665         //MCG->C9    = 0x00; // was 0x00
666         //MCG->C10   = 0x00; // was 0x00
667
668         //sirq_printf("MGC - C1    %02hx\r\n", MCG->C1);     // 1A
669         //sirq_printf("MGC - C2    %02hx\r\n", MCG->C2);     // 24
670         //sirq_printf("MGC - C3    %02hx\r\n", MCG->C3);     // 91
671         //sirq_printf("MGC - C4    %02hx\r\n", MCG->C4);     // 10
672         //sirq_printf("MGC - C5    %02hx\r\n", MCG->C5);     // 01
673         //sirq_printf("MGC - C6    %02hx\r\n", MCG->C6);     // 40
674         //sirq_printf("MGC - S     %02hx\r\n", MCG->S);      // 6E
675         //sirq_printf("MGC - SC    %02hx\r\n", MCG->SC);     // 02
676         //sirq_printf("MGC - ATCVH %02hx\r\n", MCG->ATCVH);  // 00
677         //sirq_printf("MGC - ATCVL %02hx\r\n", MCG->ATCVL);  // 00
678         //sirq_printf("MGC - C7    %02hx\r\n", MCG->C7);     // 00
679         //sirq_printf("MGC - C8    %02hx\r\n", MCG->C8);     // 80
680         //sirq_printf("MGC - C9    %02hx\r\n", MCG->C9);     // 00
681         //sirq_printf("MGC - C10   %02hx\r\n", MCG->C10);    // 00
682
683         // Run background loop
684         while (true)
685                 background();
686
687         // Performance testing
688         //uint64_t prev = 0, due = 0;
689         //uint64_t worst[10] = {};
690         //int      count = 0;
691         //while (true) {
692         //      uint64_t local = tdma_time();
693         //      if (prev && (local-prev) > worst[count])
694         //              worst[count] = (local-prev);
695         //      prev = local;
696         //      if (local > due) {
697         //              if (count == 5) {
698         //                      static char str[] = "background background background\r\n";
699         //                      sirq_write(sirq_dbg, str, sizeof(str));
700         //              }
701         //              if (count == 9) {
702         //                      sirq_printf("background\r\n");
703         //                      for (int i = 0; i < 10; i++) {
704         //                              sirq_printf("  worst[%d] = 0.%09u\r\n",
705         //                                              i, worst[i]);
706         //                              worst[i] = 0;
707         //                      }
708         //              }
709         //              due += NSEC_PER_SEC;
710         //              count = (count + 1) % 10;
711         //      }
712         //}
713
714         // Run tests
715         //test_main();
716
717         return 0;
718 }