Skip to content
Snippets Groups Projects
Unverified Commit 9d99add1 authored by Bas Stottelaar's avatar Bas Stottelaar Committed by GitHub
Browse files

Merge pull request #7923 from basilfx/feature/timer_arg

test: periph_timer: check if argument is passed.
parents 300db9f6 fd396045
No related branches found
No related tags found
No related merge requests found
......@@ -34,15 +34,17 @@
#define MAX_CHANNELS (10U)
#define TIM_SPEED (1000000ul) /* try to run with 1MHz */
#define CHAN_OFFSET (5000U) /* fire every 5ms */
#define COOKIE (100U) /* for checking if arg is passed */
static volatile int fired;
static volatile uint32_t sw_count;
static volatile uint32_t timeouts[MAX_CHANNELS];
static volatile unsigned args[MAX_CHANNELS];
static void cb(void *arg, int chan)
{
(void)arg;
timeouts[chan] = sw_count;
args[chan] = (unsigned)arg + chan;
fired++;
}
......@@ -55,10 +57,11 @@ static int test_timer(unsigned num)
fired = 0;
for (unsigned i = 0; i < MAX_CHANNELS; i++) {
timeouts[i] = 0;
args[i] = UINT_MAX;
}
/* initialize and halt timer */
if (timer_init(TIMER_DEV(num), TIM_SPEED, cb, NULL) < 0) {
if (timer_init(TIMER_DEV(num), TIM_SPEED, cb, (void *)(COOKIE * num)) < 0) {
printf("TIMER_%u: ERROR on initialization - skipping\n\n", num);
return 0;
}
......@@ -91,6 +94,10 @@ static int test_timer(unsigned num)
} while (fired != set);
/* collect results */
for (int i = 0; i < fired; i++) {
if (args[i] != ((COOKIE * num) + i)) {
printf("TIMER_%u: ERROR callback argument mismatch\n\n", num);
return 0;
}
printf("TIMER_%u: channel %i fired at SW count %8u",
num, i, (unsigned)timeouts[i]);
if (i == 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment