Skip to content
Snippets Groups Projects
Commit fd396045 authored by Bas Stottelaar's avatar Bas Stottelaar
Browse files

test: periph_timer: check if argument is passed.

parent 6eaffbb2
No related branches found
No related tags found
No related merge requests found
...@@ -34,15 +34,17 @@ ...@@ -34,15 +34,17 @@
#define MAX_CHANNELS (10U) #define MAX_CHANNELS (10U)
#define TIM_SPEED (1000000ul) /* try to run with 1MHz */ #define TIM_SPEED (1000000ul) /* try to run with 1MHz */
#define CHAN_OFFSET (5000U) /* fire every 5ms */ #define CHAN_OFFSET (5000U) /* fire every 5ms */
#define COOKIE (100U) /* for checking if arg is passed */
static volatile int fired; static volatile int fired;
static volatile uint32_t sw_count; static volatile uint32_t sw_count;
static volatile uint32_t timeouts[MAX_CHANNELS]; static volatile uint32_t timeouts[MAX_CHANNELS];
static volatile unsigned args[MAX_CHANNELS];
static void cb(void *arg, int chan) static void cb(void *arg, int chan)
{ {
(void)arg;
timeouts[chan] = sw_count; timeouts[chan] = sw_count;
args[chan] = (unsigned)arg + chan;
fired++; fired++;
} }
...@@ -55,10 +57,11 @@ static int test_timer(unsigned num) ...@@ -55,10 +57,11 @@ static int test_timer(unsigned num)
fired = 0; fired = 0;
for (unsigned i = 0; i < MAX_CHANNELS; i++) { for (unsigned i = 0; i < MAX_CHANNELS; i++) {
timeouts[i] = 0; timeouts[i] = 0;
args[i] = UINT_MAX;
} }
/* initialize and halt timer */ /* 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); printf("TIMER_%u: ERROR on initialization - skipping\n\n", num);
return 0; return 0;
} }
...@@ -91,6 +94,10 @@ static int test_timer(unsigned num) ...@@ -91,6 +94,10 @@ static int test_timer(unsigned num)
} while (fired != set); } while (fired != set);
/* collect results */ /* collect results */
for (int i = 0; i < fired; i++) { 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", printf("TIMER_%u: channel %i fired at SW count %8u",
num, i, (unsigned)timeouts[i]); num, i, (unsigned)timeouts[i]);
if (i == 0) { 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