Merge pull request #7923 from basilfx/feature/timer_arg
test: periph_timer: check if argument is passed.
This commit is contained in:
commit
9d99add1d0
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user