2014-02-03 23:03:13 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 INRIA
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
|
|
|
* Public License. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup tests
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Hwtimer test application
|
|
|
|
*
|
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2014-01-10 16:21:35 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "hwtimer.h"
|
|
|
|
|
2014-02-22 13:28:21 +01:00
|
|
|
#define BASE_DELAY (1000UL * 1000UL)
|
|
|
|
#define DELTA_DELAY (1000UL * 1000UL)
|
|
|
|
#define MSGLEN 12 // == strlen("callback %2i")
|
|
|
|
char msg[MSGLEN * ARCH_MAXTIMERS]; // == [callback 1\0callback 2\0...]
|
|
|
|
|
2014-01-25 11:29:35 +01:00
|
|
|
void callback(void *ptr)
|
2014-01-10 16:21:35 +01:00
|
|
|
{
|
2014-01-25 11:29:35 +01:00
|
|
|
puts((char *) ptr);
|
2014-01-10 16:21:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2014-02-10 15:28:55 +01:00
|
|
|
puts("hwtimer test application...");
|
2014-01-10 16:21:35 +01:00
|
|
|
|
|
|
|
puts("Initializing hwtimer...");
|
|
|
|
hwtimer_init();
|
|
|
|
|
|
|
|
puts("Initializing hwtimer [OK].");
|
|
|
|
|
2014-01-25 11:29:35 +01:00
|
|
|
unsigned long delay = BASE_DELAY + ((ARCH_MAXTIMERS - 1) * DELTA_DELAY);
|
2014-01-10 16:21:35 +01:00
|
|
|
|
|
|
|
/* make the first timer first to fire so timers do not run out linearly */
|
|
|
|
char *msgn = msg;
|
|
|
|
snprintf(msgn, MSGLEN, "callback %2x", 1);
|
2014-01-25 11:29:35 +01:00
|
|
|
hwtimer_set(HWTIMER_TICKS(BASE_DELAY), callback, (void *) msgn);
|
2014-01-10 16:21:35 +01:00
|
|
|
printf("set %s\n", msgn);
|
|
|
|
|
|
|
|
/* set up to ARCH_MAXTIMERS-1 because hwtimer_wait below also
|
|
|
|
* needs a timer */
|
|
|
|
for (int i = 1; i < (ARCH_MAXTIMERS - 1); i++) {
|
2014-01-25 11:29:35 +01:00
|
|
|
msgn = msg + (i * MSGLEN);
|
2014-01-10 16:21:35 +01:00
|
|
|
delay -= DELTA_DELAY;
|
2014-01-25 11:29:35 +01:00
|
|
|
snprintf(msgn, MSGLEN, "callback %2x", i + 1);
|
|
|
|
hwtimer_set(HWTIMER_TICKS(delay), callback, (void *) msgn);
|
2014-01-10 16:21:35 +01:00
|
|
|
printf("set %s\n", msgn);
|
|
|
|
}
|
|
|
|
|
|
|
|
hwtimer_wait(HWTIMER_TICKS(1000UL * 1000UL));
|
|
|
|
|
|
|
|
puts("hwtimer set.");
|
|
|
|
}
|