mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
45 lines
1.1 KiB
C
45 lines
1.1 KiB
C
#include <stdio.h>
|
|
|
|
#include "hwtimer.h"
|
|
|
|
void callback(void* ptr)
|
|
{
|
|
puts((char*) ptr);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
puts("hwtimer test project...");
|
|
|
|
puts("Initializing hwtimer...");
|
|
hwtimer_init();
|
|
|
|
puts("Initializing hwtimer [OK].");
|
|
|
|
#define BASE_DELAY 100000UL
|
|
#define DELTA_DELAY 10000UL
|
|
#define MSGLEN 12 // == strlen("callback %2i")
|
|
char msg[MSGLEN * ARCH_MAXTIMERS]; // == [callback 1\0callback 2\0...]
|
|
unsigned long delay = BASE_DELAY + (ARCH_MAXTIMERS * DELTA_DELAY);
|
|
|
|
/* make the first timer first to fire so timers do not run out linearly */
|
|
char *msgn = msg;
|
|
snprintf(msgn, MSGLEN, "callback %2x", 1);
|
|
hwtimer_set(BASE_DELAY, callback, (void*) msgn);
|
|
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++) {
|
|
msgn = msg + (i*MSGLEN);
|
|
delay -= DELTA_DELAY;
|
|
snprintf(msgn, MSGLEN, "callback %2x", i+1);
|
|
hwtimer_set(delay, callback, (void*) msgn);
|
|
printf("set %s\n", msgn);
|
|
}
|
|
|
|
hwtimer_wait(HWTIMER_TICKS(1000UL * 1000UL));
|
|
|
|
puts("hwtimer set.");
|
|
}
|