Skip to content
Snippets Groups Projects
Commit 2cd2738e authored by Cenk Gündoğan's avatar Cenk Gündoğan
Browse files

Merge pull request #4585 from kaspar030/fix_native_timer_set_absolute

cpu: native: fix native timer_set_absolute()
parents 461365f3 781ee875
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,14 @@ ...@@ -54,6 +54,14 @@
*/ */
#define XTIMER_OVERHEAD 14 #define XTIMER_OVERHEAD 14
#define XTIMER_USLEEP_UNTIL_OVERHEAD 1 #define XTIMER_USLEEP_UNTIL_OVERHEAD 1
/* timer_set_absolute() has a high margin for possible underflow if set with
* value not far in the future. To prevent this, we set high backoff values
* here.
*/
#define XTIMER_BACKOFF 200
#define XTIMER_ISR_BACKOFF 200
/** @} */ /** @} */
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -135,15 +135,7 @@ int timer_set(tim_t dev, int channel, unsigned int offset) ...@@ -135,15 +135,7 @@ int timer_set(tim_t dev, int channel, unsigned int offset)
int timer_set_absolute(tim_t dev, int channel, unsigned int value) int timer_set_absolute(tim_t dev, int channel, unsigned int value)
{ {
uint32_t now = timer_read(dev); uint32_t now = timer_read(dev);
int64_t target = (int32_t)(value - now); return timer_set(dev, channel, value - now);
DEBUG("timer_set_absolute(): delta=%lli\n", target);
if (target < 0 && target > -NATIVE_TIMER_MIN_RES) {
DEBUG("timer_set_absolute(): preventing underflow.\n");
target = NATIVE_TIMER_MIN_RES;
}
return timer_set(dev, channel, target);
} }
int timer_clear(tim_t dev, int channel) int timer_clear(tim_t dev, int channel)
......
export APPLICATION = xtimer_now64_continuity
include ../Makefile.tests_common
FEATURES_REQUIRED = periph_timer
USEMODULE += xtimer
include $(RIOTBASE)/Makefile.include
Description
===========
This test measures the difference of two consecutive calls to xtimer_now64() 10k times.
Should the difference be larger then 1000us, the test fails, otherwise it succeeds.
/*
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
*
* 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 xtimer_now64 continuity test application
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include <stdio.h>
#include <stdint.h>
#include "xtimer.h"
#define ITERATIONS (100000LU)
#define MAXDIFF 1000
int main(void)
{
uint32_t n = ITERATIONS;
uint64_t now;
uint64_t before = xtimer_now64();
while(--n) {
now = xtimer_now64();
if ((now-before) > MAXDIFF) {
puts("TEST FAILED.");
break;
}
before = now;
}
if (!n) {
puts("TEST SUCCESSFUL.");
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment