1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu: add and use shared code for timer_set()

This commit is contained in:
Hauke Petersen 2017-06-02 12:21:56 +02:00
parent 12a9c5e3b4
commit a1499f4190
19 changed files with 43 additions and 127 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

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

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

View File

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

View File

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

View File

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

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

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

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

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

View File

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

View File

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

View File

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

View File

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

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