Turn off radio DEBUGFLOW printing
[contiki-2.x.git] / examples / sensinode / clock_test.c
blob758b4d040e91f7393ac8e1912faf769816608761
1 /**
2 * \file
3 * Tests related to clocks and timers
4 * \author
5 * Zach Shelby <zach@sensinode.com>
6 */
8 #include "contiki.h"
9 #include "sys/clock.h"
10 #include "dev/bus.h"
11 #include "dev/leds.h"
12 #include <stdio.h> /* For printf() */
13 /*---------------------------------------------------------------------------*/
14 PROCESS(clock_test_process, "Clock test process");
15 AUTOSTART_PROCESSES(&clock_test_process);
16 /*---------------------------------------------------------------------------*/
17 PROCESS_THREAD(clock_test_process, ev, data)
19 static struct etimer et;
20 static clock_time_t count, start_count, end_count, diff;
21 static unsigned long sec;
22 static u8_t i;
24 PROCESS_BEGIN();
26 printf("Clock delay test (10 x (10,000xi) cycles):\n");
27 i = 1;
28 while(i < 6) {
29 start_count = clock_time();
30 clock_delay(10000*i);
31 end_count = clock_time();
32 diff = end_count-start_count;
33 printf("Delayed %u = %u ticks = ~%u ms\n", 10000*i, diff, diff*8 );
34 i++;
37 printf("Clock tick and etimer test (10 x 1s):\n");
38 i = 0;
39 while(i < 10) {
40 etimer_set(&et, CLOCK_SECOND);
41 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
42 etimer_reset(&et);
44 count = clock_time();
45 printf("%u ticks\n", count);
47 leds_toggle(LEDS_RED);
48 i++;
51 printf("Clock seconds test (10 x 5s):\n");
52 i = 0;
53 while(i < 10) {
54 etimer_set(&et, 5 * CLOCK_SECOND);
55 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
56 etimer_reset(&et);
58 sec = clock_seconds();
59 printf("%u seconds\n", (u16_t) sec);
61 leds_toggle(LEDS_GREEN);
62 i++;
65 PROCESS_END();
67 /*---------------------------------------------------------------------------*/