1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2026-01-01 01:41:18 +01:00

Merge pull request #3344 from kaspar030/fix_native_timer_possible_underflow

native: periph/timer: prevent underflow in timer_set_absolute
This commit is contained in:
Kaspar Schleiser 2015-07-09 22:17:44 +02:00
commit d15f0990b3

View File

@ -133,8 +133,15 @@ int timer_set(tim_t dev, int channel, unsigned int offset)
int timer_set_absolute(tim_t dev, int channel, unsigned int value)
{
uint32_t now = timer_read(dev);
int64_t target = (int32_t)(value - now);
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;
}
timer_set(dev, channel, target);
return 1;
}