1
0
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:
Francisco Acosta 2017-08-01 15:09:48 +02:00 committed by GitHub
commit f2efd88f98
19 changed files with 43 additions and 127 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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;

View File

@ -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
*/

View File

@ -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;

View File

@ -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) {

View File

@ -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) {

View File

@ -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)) {

View File

@ -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

View File

@ -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) {

View File

@ -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

View File

@ -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 */

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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) {

View 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