From 225a6aff8c74b23ece5652d36d20563baeaae7da Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Tue, 3 Apr 2012 14:54:30 +0100 Subject: [PATCH] Improved cc2x30 timer test examples * Adjusted the cc2530 timer-test example to reflect recent changes to clock_delay() * Sensinode now uses the newer timer-test example copied over from cc2530dk * Deleted the obsolete clock-test. timer-test is a superset --- examples/cc2530dk/timer-test.c | 16 +++---- examples/sensinode/clock_test.c | 67 ---------------------------- examples/sensinode/timer-test.c | 78 +++++++++++++++++++-------------- 3 files changed, 53 insertions(+), 108 deletions(-) delete mode 100644 examples/sensinode/clock_test.c diff --git a/examples/cc2530dk/timer-test.c b/examples/cc2530dk/timer-test.c index 6843e4df3..65f641fc0 100644 --- a/examples/cc2530dk/timer-test.c +++ b/examples/cc2530dk/timer-test.c @@ -1,9 +1,7 @@ /** * \file * Tests related to clocks and timers - * - * This is clock_test.c plus a small addition by George Oikonomou - * (Loughborough University) in order to test the rtimer + * This is based on clock_test.c from the original sensinode port * * \author * Zach Shelby (Original) @@ -17,7 +15,6 @@ #include "dev/leds.h" #include - /*---------------------------------------------------------------------------*/ #define TEST_CLOCK_DELAY 1 #define TEST_RTIMER 1 @@ -27,7 +24,7 @@ static struct etimer et; #if TEST_CLOCK_DELAY -static clock_time_t start_count, end_count, diff; +static rtimer_clock_t start_count, end_count, diff; #endif #if TEST_CLOCK_SECONDS @@ -70,12 +67,13 @@ PROCESS_THREAD(clock_test_process, ev, data) #if TEST_CLOCK_DELAY printf("Clock delay test, (10,000 x i) cycles:\n"); i = 1; - while(i < 6) { - start_count = clock_time(); + while(i < 7) { + start_count = RTIMER_NOW(); clock_delay(10000 * i); - end_count = clock_time(); + end_count = RTIMER_NOW(); diff = end_count - start_count; - printf("Delayed %u = %u ticks = ~%u ms\n", 10000 * i, diff, diff * 8); + printf("Delayed %u = %u rtimer ticks = ~%u us\n", 10000 * i, diff, + diff * 64); i++; } #endif diff --git a/examples/sensinode/clock_test.c b/examples/sensinode/clock_test.c deleted file mode 100644 index 24d3c6417..000000000 --- a/examples/sensinode/clock_test.c +++ /dev/null @@ -1,67 +0,0 @@ -/** - * \file - * Tests related to clocks and timers - * \author - * Zach Shelby - */ - -#include "contiki.h" -#include "sys/clock.h" -#include "dev/bus.h" -#include "dev/leds.h" -#include /* For printf() */ -/*---------------------------------------------------------------------------*/ -PROCESS(clock_test_process, "Clock test process"); -AUTOSTART_PROCESSES(&clock_test_process); -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(clock_test_process, ev, data) -{ - static struct etimer et; - static clock_time_t count, start_count, end_count, diff; - static unsigned long sec; - static uint8_t i; - - PROCESS_BEGIN(); - - printf("Clock delay test (10 x (10,000xi) cycles):\n"); - i = 1; - while(i < 6) { - start_count = clock_time(); - clock_delay(10000*i); - end_count = clock_time(); - diff = end_count-start_count; - printf("Delayed %u = %u ticks = ~%u ms\n", 10000*i, diff, diff*8 ); - i++; - } - - printf("Clock tick and etimer test (10 x 1s):\n"); - i = 0; - while(i < 10) { - etimer_set(&et, CLOCK_SECOND); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - etimer_reset(&et); - - count = clock_time(); - printf("%u ticks\n", count); - - leds_toggle(LEDS_RED); - i++; - } - - printf("Clock seconds test (10 x 5s):\n"); - i = 0; - while(i < 10) { - etimer_set(&et, 5 * CLOCK_SECOND); - PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); - etimer_reset(&et); - - sec = clock_seconds(); - printf("%u seconds\n", (uint16_t) sec); - - leds_toggle(LEDS_GREEN); - i++; - } - - PROCESS_END(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sensinode/timer-test.c b/examples/sensinode/timer-test.c index 3afc53320..65f641fc0 100644 --- a/examples/sensinode/timer-test.c +++ b/examples/sensinode/timer-test.c @@ -1,9 +1,7 @@ /** * \file * Tests related to clocks and timers - * - * This is clock_test.c plus a small addition by George Oikonomou - * (Loughborough University)in order to test the rtimer + * This is based on clock_test.c from the original sensinode port * * \author * Zach Shelby (Original) @@ -23,59 +21,73 @@ #define TEST_ETIMER 1 #define TEST_CLOCK_SECONDS 1 /*---------------------------------------------------------------------------*/ +static struct etimer et; + +#if TEST_CLOCK_DELAY +static rtimer_clock_t start_count, end_count, diff; +#endif + +#if TEST_CLOCK_SECONDS +static unsigned long sec; +#endif + +#if TEST_ETIMER +static clock_time_t count; +#endif + +#if TEST_RTIMER +static struct rtimer rt; +rtimer_clock_t rt_now, rt_for; +static clock_time_t ct; +#endif + +static uint8_t i; +/*---------------------------------------------------------------------------*/ PROCESS(clock_test_process, "Clock test process"); AUTOSTART_PROCESSES(&clock_test_process); /*---------------------------------------------------------------------------*/ #if TEST_RTIMER void rt_callback(struct rtimer *t, void *ptr) { - printf("Task called at %u\n", RTIMER_NOW()); + rt_now = RTIMER_NOW(); + ct = clock_time(); + printf("Task called at %u (clock = %u)\n", rt_now, ct); } #endif /*---------------------------------------------------------------------------*/ PROCESS_THREAD(clock_test_process, ev, data) { - static struct etimer et; - -#if TEST_CLOCK_DELAY - static clock_time_t start_count, end_count, diff; -#endif -#if TEST_CLOCK_SECONDS - static unsigned long sec; -#endif -#if TEST_ETIMER - static clock_time_t count; -#endif -#if TEST_RTIMER - uint16_t rt_now, rt_for; - static struct rtimer rt; -#endif - static uint8_t i; PROCESS_BEGIN(); + etimer_set(&et, 2 * CLOCK_SECOND); + + PROCESS_YIELD(); + #if TEST_CLOCK_DELAY - printf("Clock delay test (10 x (10,000xi) cycles):\n"); + printf("Clock delay test, (10,000 x i) cycles:\n"); i = 1; - while(i < 6) { - start_count = clock_time(); + while(i < 7) { + start_count = RTIMER_NOW(); clock_delay(10000 * i); - end_count = clock_time(); + end_count = RTIMER_NOW(); diff = end_count - start_count; - printf("Delayed %u = %u ticks = ~%u ms\n", 10000 * i, diff, diff * 8); + printf("Delayed %u = %u rtimer ticks = ~%u us\n", 10000 * i, diff, + diff * 64); i++; } #endif #if TEST_RTIMER - printf("Rtimer Test (10 x 1s):\n"); + printf("Rtimer Test, 1 sec (%u rtimer ticks):\n", RTIMER_SECOND); i = 0; - while(i < 10) { + while(i < 5) { etimer_set(&et, 2*CLOCK_SECOND); - puts("======================="); + printf("=======================\n"); + ct = clock_time(); rt_now = RTIMER_NOW(); rt_for = rt_now + RTIMER_SECOND; - printf("%Now=%u - For=%u\n", rt_now, rt_for); + printf("Now=%u (clock = %u) - For=%u\n", rt_now, ct, rt_for); if (rtimer_set(&rt, rt_for, 1, (void (*)(struct rtimer *, void *))rt_callback, NULL) != RTIMER_OK) { printf("Error setting\n"); @@ -87,7 +99,7 @@ PROCESS_THREAD(clock_test_process, ev, data) #endif #if TEST_ETIMER - printf("Clock tick and etimer test (10 x 1s):\n"); + printf("Clock tick and etimer test, 1 sec (%u clock ticks):\n", CLOCK_SECOND); i = 0; while(i < 10) { etimer_set(&et, CLOCK_SECOND); @@ -103,7 +115,7 @@ PROCESS_THREAD(clock_test_process, ev, data) #endif #if TEST_CLOCK_SECONDS - printf("Clock seconds test (10 x 5s):\n"); + printf("Clock seconds test (5s):\n"); i = 0; while(i < 10) { etimer_set(&et, 5 * CLOCK_SECOND); @@ -111,13 +123,15 @@ PROCESS_THREAD(clock_test_process, ev, data) etimer_reset(&et); sec = clock_seconds(); - printf("%u seconds\n", (uint16_t) sec); + printf("%lu seconds\n", sec); leds_toggle(LEDS_GREEN); i++; } #endif + printf("Done!\n"); + PROCESS_END(); } /*---------------------------------------------------------------------------*/