diff --git a/cpu/atmega_common/periph/timer.c b/cpu/atmega_common/periph/timer.c index 11e1bd0c1e..2b9084469b 100644 --- a/cpu/atmega_common/periph/timer.c +++ b/cpu/atmega_common/periph/timer.c @@ -126,11 +126,6 @@ int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t tim, int channel, unsigned int timeout) -{ - return timer_set_absolute(tim, channel, timer_read(tim) + timeout); -} - int timer_set_absolute(tim_t tim, int channel, unsigned int value) { if (channel >= CHANNELS) { diff --git a/cpu/cc2538/periph/timer.c b/cpu/cc2538/periph/timer.c index 1165172da1..61a64b442d 100644 --- a/cpu/cc2538/periph/timer.c +++ b/cpu/cc2538/periph/timer.c @@ -150,38 +150,6 @@ int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t dev, int channel, unsigned int timeout) -{ - /* get timer base register address */ - cc2538_gptimer_t *gptimer = timer_config[dev].dev; - - if ( (dev >= TIMER_NUMOF) || (channel >= timer_config[dev].channels) ) { - return -1; - } - - switch (channel) { - case 0: - /* clear any pending match interrupts */ - gptimer->ICR = TAMIM; - - /* set timeout value */ - gptimer->TAMATCHR = (gptimer->CFG == GPTMCFG_32_BIT_TIMER)? (gptimer->TAV + timeout) : (gptimer->TAV - timeout); - gptimer->cc2538_gptimer_imr.IMR |= TAMIM; /**< Enable the Timer A Match Interrupt */ - break; - - case 1: - /* clear any pending match interrupts */ - gptimer->ICR = TBMIM; - - /* set timeout value */ - gptimer->TBMATCHR = (gptimer->CFG == GPTMCFG_32_BIT_TIMER)? (gptimer->TBV + timeout) : (gptimer->TBV - timeout); - gptimer->cc2538_gptimer_imr.IMR |= TBMIM; /**< Enable the Timer B Match Interrupt */ - break; - } - - return 1; -} - int timer_set_absolute(tim_t dev, int channel, unsigned int value) { DEBUG("%s(%u, %u, %u)\n", __FUNCTION__, dev, channel, value); diff --git a/cpu/cc26x0/periph/timer.c b/cpu/cc26x0/periph/timer.c index 68c38bd3a6..8d0bb8bbf6 100644 --- a/cpu/cc26x0/periph/timer.c +++ b/cpu/cc26x0/periph/timer.c @@ -74,11 +74,6 @@ int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t tim, int channel, unsigned int timeout) -{ - return timer_set_absolute(tim, channel, timer_read(tim) + timeout); -} - int timer_set_absolute(tim_t tim, int channel, unsigned int value) { if (channel != 0) { diff --git a/cpu/cc430/periph/timer.c b/cpu/cc430/periph/timer.c index fbabb508e1..1f0933a170 100644 --- a/cpu/cc430/periph/timer.c +++ b/cpu/cc430/periph/timer.c @@ -67,12 +67,6 @@ int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t dev, int channel, unsigned int timeout) -{ - uint16_t target = TIMER_BASE->R + (uint16_t)timeout; - return timer_set_absolute(dev, channel, (unsigned int)target); -} - int timer_set_absolute(tim_t dev, int channel, unsigned int value) { if (dev != 0 || channel > TIMER_CHAN) { diff --git a/cpu/ezr32wg/periph/timer.c b/cpu/ezr32wg/periph/timer.c index 00715b3304..bcf1d3554b 100644 --- a/cpu/ezr32wg/periph/timer.c +++ b/cpu/ezr32wg/periph/timer.c @@ -82,13 +82,6 @@ int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t dev, int channel, unsigned int timeout) -{ - unsigned int now = timer_read(dev); - timer_set_absolute(dev, channel, now + timeout); - return 0; -} - int timer_set_absolute(tim_t dev, int channel, unsigned int value) { TIMER_TypeDef *tim; diff --git a/cpu/kinetis_common/include/periph_cpu.h b/cpu/kinetis_common/include/periph_cpu.h index d4ca43c4b9..345dc7201b 100644 --- a/cpu/kinetis_common/include/periph_cpu.h +++ b/cpu/kinetis_common/include/periph_cpu.h @@ -92,6 +92,11 @@ typedef uint16_t gpio_t; #define PERIPH_SPI_NEEDS_TRANSFER_REGS /** @} */ +/** + * @brief Prevent shared timer functions from being used + */ +#define PERIPH_TIMER_PROVIDES_SET + /** * @brief define number of usable power modes */ diff --git a/cpu/lm4f120/periph/timer.c b/cpu/lm4f120/periph/timer.c index 3938bad2da..070714eb43 100644 --- a/cpu/lm4f120/periph/timer.c +++ b/cpu/lm4f120/periph/timer.c @@ -124,21 +124,6 @@ int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t dev, int channel, unsigned int timeout) -{ - unsigned int corrected_now; - int retval; - - if (dev >= TIMER_NUMOF){ - return -1; - } - - corrected_now = timer_read(dev); - retval = timer_set_absolute(dev, channel, corrected_now+timeout); - - return retval; -} - int timer_set_absolute(tim_t dev, int channel, unsigned int value) { unsigned int timer_base; diff --git a/cpu/lpc11u34/periph/timer.c b/cpu/lpc11u34/periph/timer.c index 3ca4104ada..8a8ad7a7f6 100644 --- a/cpu/lpc11u34/periph/timer.c +++ b/cpu/lpc11u34/periph/timer.c @@ -63,15 +63,6 @@ int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg) return -1; } -int timer_set(tim_t dev, int channel, unsigned int timeout) -{ - if (dev == TIMER_0) { - unsigned int now = timer_read(dev); - return timer_set_absolute(dev, channel, now + timeout); - } - return -1; -} - int timer_set_absolute(tim_t dev, int channel, unsigned int value) { if (dev == TIMER_0) { diff --git a/cpu/lpc1768/periph/timer.c b/cpu/lpc1768/periph/timer.c index 87ddcd0bc3..afe0854498 100644 --- a/cpu/lpc1768/periph/timer.c +++ b/cpu/lpc1768/periph/timer.c @@ -65,15 +65,6 @@ int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg) return -1; } -int timer_set(tim_t dev, int channel, unsigned int timeout) -{ - if (dev == TIMER_0) { - unsigned int now = timer_read(dev); - return timer_set_absolute(dev, channel, now + timeout); - } - return -1; -} - int timer_set_absolute(tim_t dev, int channel, unsigned int value) { if (dev == TIMER_0) { diff --git a/cpu/lpc2387/periph/timer.c b/cpu/lpc2387/periph/timer.c index ad9d515c1a..2b56dc7bfe 100644 --- a/cpu/lpc2387/periph/timer.c +++ b/cpu/lpc2387/periph/timer.c @@ -133,12 +133,6 @@ int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t tim, int channel, unsigned int timeout) -{ - unsigned int now = timer_read(tim); - return timer_set_absolute(tim, channel, (timeout + now)); -} - int timer_set_absolute(tim_t tim, int channel, unsigned int value) { if (((unsigned) tim >= TIMER_NUMOF) || ((unsigned) channel >= TIMER_CHAN_NUMOF)) { diff --git a/cpu/mips_pic32_common/include/periph_cpu_common.h b/cpu/mips_pic32_common/include/periph_cpu_common.h index 2f838c8aec..e9cd0c4074 100644 --- a/cpu/mips_pic32_common/include/periph_cpu_common.h +++ b/cpu/mips_pic32_common/include/periph_cpu_common.h @@ -40,6 +40,11 @@ enum { PORT_G = 6, /**< port G */ }; +/** + * @brief Prevent shared timer functions from being used + */ +#define PERIPH_TIMER_PROVIDES_SET + #ifdef __cplusplus } #endif diff --git a/cpu/msp430fxyz/periph/timer.c b/cpu/msp430fxyz/periph/timer.c index 18059d398b..7553146199 100644 --- a/cpu/msp430fxyz/periph/timer.c +++ b/cpu/msp430fxyz/periph/timer.c @@ -67,12 +67,6 @@ int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t dev, int channel, unsigned int timeout) -{ - uint16_t target = TIMER_BASE->R + (uint16_t)timeout; - return timer_set_absolute(dev, channel, (unsigned int)target); -} - int timer_set_absolute(tim_t dev, int channel, unsigned int value) { if (dev != 0 || channel > TIMER_CHAN) { diff --git a/cpu/native/include/periph_cpu.h b/cpu/native/include/periph_cpu.h index 523e90726f..14d91ff820 100644 --- a/cpu/native/include/periph_cpu.h +++ b/cpu/native/include/periph_cpu.h @@ -32,6 +32,11 @@ extern "C" { #define CPUID_LEN (4U) #endif +/** + * @brief Prevent shared timer functions from being used + */ +#define PERIPH_TIMER_PROVIDES_SET + #ifdef __cplusplus } #endif diff --git a/cpu/nrf5x_common/periph/timer.c b/cpu/nrf5x_common/periph/timer.c index 845173e090..c40f940815 100644 --- a/cpu/nrf5x_common/periph/timer.c +++ b/cpu/nrf5x_common/periph/timer.c @@ -91,12 +91,6 @@ int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t tim, int chan, unsigned int value) -{ - uint32_t now = timer_read(tim); - return timer_set_absolute(tim, chan, (now + value)); -} - int timer_set_absolute(tim_t tim, int chan, unsigned int value) { /* see if channel is valid */ diff --git a/cpu/sam3/periph/timer.c b/cpu/sam3/periph/timer.c index e8b843db9e..729e1036c5 100644 --- a/cpu/sam3/periph/timer.c +++ b/cpu/sam3/periph/timer.c @@ -121,11 +121,6 @@ int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t tim, int channel, unsigned int timeout) -{ - return timer_set_absolute(tim, channel, timer_read(tim) + timeout); -} - int timer_set_absolute(tim_t tim, int channel, unsigned int value) { if (channel >=TIMER_CHANNELS) { diff --git a/cpu/samd21/periph/timer.c b/cpu/samd21/periph/timer.c index 998238f1f8..2306663924 100644 --- a/cpu/samd21/periph/timer.c +++ b/cpu/samd21/periph/timer.c @@ -129,11 +129,6 @@ int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t dev, int channel, unsigned int timeout) -{ - return timer_set_absolute(dev, channel, timer_read(dev) + timeout); -} - int timer_set_absolute(tim_t dev, int channel, unsigned int value) { DEBUG("Setting timer %i channel %i to %i\n", dev, channel, value); diff --git a/cpu/saml21/periph/timer.c b/cpu/saml21/periph/timer.c index 44e82ae586..1b87de3b48 100644 --- a/cpu/saml21/periph/timer.c +++ b/cpu/saml21/periph/timer.c @@ -84,11 +84,6 @@ int timer_init(tim_t dev, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t dev, int channel, unsigned int timeout) -{ - return timer_set_absolute(dev, channel, timer_read(dev) + timeout); -} - int timer_set_absolute(tim_t dev, int channel, unsigned int value) { DEBUG("Setting timer %i channel %i to %i\n", dev, channel, value); diff --git a/cpu/stm32_common/periph/timer.c b/cpu/stm32_common/periph/timer.c index f3e8aba9e5..bdd7441be5 100644 --- a/cpu/stm32_common/periph/timer.c +++ b/cpu/stm32_common/periph/timer.c @@ -90,12 +90,6 @@ int timer_init(tim_t tim, unsigned long freq, timer_cb_t cb, void *arg) return 0; } -int timer_set(tim_t tim, int channel, unsigned int timeout) -{ - int now = timer_read(tim); - return timer_set_absolute(tim, channel, now + timeout); -} - int timer_set_absolute(tim_t tim, int channel, unsigned int value) { if (channel >= TIMER_CHAN) { diff --git a/drivers/periph_common/timer.c b/drivers/periph_common/timer.c new file mode 100644 index 0000000000..1d9f8a58f4 --- /dev/null +++ b/drivers/periph_common/timer.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2017 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 drivers + * @{ + * + * @file + * @brief Shared peripheral timer code + * + * @author Hauke Petersen + * + * @} + */ + +#include "periph/timer.h" + +#ifndef PERIPH_TIMER_PROVIDES_SET +int timer_set(tim_t dev, int channel, unsigned int timeout) +{ + return timer_set_absolute(dev, channel, timer_read(dev) + timeout); +} +#endif