1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/tests/xtimer_now_irq/main.c
JulianHolzwarth 921d9cf633 tests/xtimer_now_irq/: New test for xtimer_now() with irq_disable()
This test checks, if the timer returns the correct time (xtimer_now_usec() is called), when interrupts are disabled. Specifically tested is if the time is correct after a low-level timer overflow.
2020-05-01 15:37:51 +02:00

48 lines
1.0 KiB
C

/*
* Copyright (C) 2020 Freie Universität Berlin,
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief testing xtimer_now_usec function with irq disabled
*
*
* @author Julian Holzwarth <julian.holzwarth@fu-berlin.de>
*
*/
#include <stdio.h>
#include "xtimer.h"
#include "irq.h"
#define TEST_COUNT 4
int main(void)
{
puts("xtimer_now_irq test application.\n");
uint8_t count = TEST_COUNT;
while (count) {
unsigned int state = irq_disable();
uint32_t t1 = xtimer_now_usec();
xtimer_spin(xtimer_ticks((uint32_t)(~XTIMER_MASK) / 2));
uint32_t t2 = xtimer_now_usec();
irq_restore(state);
if (t2 < t1) {
puts("ERROR: wrong time with interrupts disabled");
return -1;
}
puts("OK");
count --;
}
puts("SUCCESS");
return 0;
}