introduce HWTIMER_SPIN_BARRIER (API change)

Boards should define HWTIMER_SPIN_BARRIER that is used to decide
whether it makes sense to set a timer and yield or call hwtimer_spin
instead.
Used by `core/hwtimer.c` and `sys/vtimer/vtimer.c`.
A default value is provided and a warning is printed when it is used.
dev/timer
Ludwig Ortmann 9 years ago
parent 223c5f63ca
commit da550bc913

@ -122,14 +122,15 @@ void hwtimer_wait(unsigned long ticks)
{
DEBUG("hwtimer_wait ticks=%lu\n", ticks);
if (ticks <= 6 || inISR()) {
if ((ticks <= (HWTIMER_SPIN_BARRIER)) || inISR()) {
hwtimer_spin(ticks);
return;
}
mutex_t mutex = MUTEX_INIT;
mutex_lock(&mutex);
/* -2 is to adjust the real value */
/* TODO: introduce HWTIMER_INSTRUCTIONS_PER_TICK?
* -2 is to adjust the real value */
int res = hwtimer_set(ticks - 2, hwtimer_releasemutex, &mutex);
if (res == -1) {
mutex_unlock(&mutex);

@ -35,6 +35,7 @@
#include <stdint.h>
#include "hwtimer_cpu.h"
#include "board.h"
/**
* @brief Number of kernel timer ticks per second
@ -44,6 +45,18 @@
#warning "HWTIMER_SPEED undefined. Set HWTIMER_SPEED to number of ticks per second for the current architecture."
#endif
/**
* @brief Upper bound for hwtimer_spin
* @verbatim Barrier below which hwtimer_spin is called instead of
* setting a timer and yielding the thread
* @def HWTIMER_SPIN_BARRIER
*/
#ifndef HWTIMER_SPIN_BARRIER
#warning "HWTIMER_SPIN_BARRIER undefined, using default. Set HWTIMER_SPIN_BARRIER to the \
number of ticks below which hwtimer_spin should be used for the current board."
#define HWTIMER_SPIN_BARRIER (6)
#endif
/**
* @brief Convert microseconds to kernel timer ticks
* @param[in] us number of microseconds

@ -347,11 +347,10 @@ int vtimer_sleep(timex_t time)
/**
* Use spin lock for short periods.
* Assumes that hardware timer ticks are shorter than a second.
* Decision based on hwtimer_wait implementation.
*/
if (time.seconds == 0) {
unsigned long ticks = HWTIMER_TICKS(time.microseconds);
if (ticks <= 6) {
if (ticks <= HWTIMER_SPIN_BARRIER) {
hwtimer_spin(ticks);
return 0;
}

Loading…
Cancel
Save