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
This commit is contained in:
George Oikonomou 2012-04-03 14:54:30 +01:00
parent 57969259ce
commit 225a6aff8c
3 changed files with 53 additions and 108 deletions

View File

@ -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 <zach@sensinode.com> (Original)
@ -17,7 +15,6 @@
#include "dev/leds.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
#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

View File

@ -1,67 +0,0 @@
/**
* \file
* Tests related to clocks and timers
* \author
* Zach Shelby <zach@sensinode.com>
*/
#include "contiki.h"
#include "sys/clock.h"
#include "dev/bus.h"
#include "dev/leds.h"
#include <stdio.h> /* 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();
}
/*---------------------------------------------------------------------------*/

View File

@ -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 <zach@sensinode.com> (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();
}
/*---------------------------------------------------------------------------*/