mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:12:57 +01:00
Merge pull request #7129 from haukepetersen/opt_periph_sharetimerset
cpu: add and use shared code for timer_set()
This commit is contained in:
commit
f2efd88f98
@ -127,11 +127,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) {
|
||||
|
@ -151,38 +151,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);
|
||||
|
@ -75,11 +75,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) {
|
||||
|
@ -68,12 +68,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) {
|
||||
|
@ -83,13 +83,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;
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -125,21 +125,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;
|
||||
|
@ -64,15 +64,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) {
|
||||
|
@ -66,15 +66,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) {
|
||||
|
@ -134,12 +134,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)) {
|
||||
|
@ -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
|
||||
|
@ -68,12 +68,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) {
|
||||
|
@ -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
|
||||
|
@ -92,12 +92,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 */
|
||||
|
@ -122,11 +122,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) {
|
||||
|
@ -131,11 +131,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);
|
||||
|
@ -85,11 +85,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);
|
||||
|
@ -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 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) {
|
||||
|
28
drivers/periph_common/timer.c
Normal file
28
drivers/periph_common/timer.c
Normal file
@ -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 <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#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
|
Loading…
Reference in New Issue
Block a user