From 0921bce5dd7ffdb5bf678e9bb44782d97f448e69 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 4 May 2015 16:43:29 +0200 Subject: [PATCH 1/2] sys: add hwtimer layer for periph timers --- sys/Makefile | 3 ++ sys/compat/Makefile | 1 + sys/compat/hwtimer/Makefile | 3 ++ sys/compat/hwtimer/hwtimer_arch.c | 75 +++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 sys/compat/Makefile create mode 100644 sys/compat/hwtimer/Makefile create mode 100644 sys/compat/hwtimer/hwtimer_arch.c diff --git a/sys/Makefile b/sys/Makefile index 4d2bc7642c..515cc13148 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -137,6 +137,9 @@ endif ifneq (,$(filter ng_udp,$(USEMODULE))) DIRS += net/transport_layer/ng_udp endif +ifneq (,$(filter hwtimer_compat,$(USEMODULE))) + DIRS += compat/hwtimer +endif DIRS += $(dir $(wildcard $(addsuffix /Makefile, ${USEMODULE}))) diff --git a/sys/compat/Makefile b/sys/compat/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/sys/compat/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/compat/hwtimer/Makefile b/sys/compat/hwtimer/Makefile new file mode 100644 index 0000000000..316bf04d47 --- /dev/null +++ b/sys/compat/hwtimer/Makefile @@ -0,0 +1,3 @@ +MODULE = hwtimer_compat + +include $(RIOTBASE)/Makefile.base diff --git a/sys/compat/hwtimer/hwtimer_arch.c b/sys/compat/hwtimer/hwtimer_arch.c new file mode 100644 index 0000000000..0325e33026 --- /dev/null +++ b/sys/compat/hwtimer/hwtimer_arch.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2015 Kaspar Schleiser + * 2014 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 sys_compat + * @{ + * + * @file hwtimer_arch.c + * @brief Implementation of the kernels hwtimer interface over periph timers + * + * This hwtimer implementation wraps one periph timer + * + * @author Thomas Eichinger + * @author Kaspar Schleiser + * + * @} + */ + +#include "arch/hwtimer_arch.h" +#include "board.h" +#include "periph/timer.h" +#include "thread.h" + + +void irq_handler(int channel); +void (*timeout_handler)(int); + + +void hwtimer_arch_init(void (*handler)(int), uint32_t fcpu) +{ + timeout_handler = handler; + timer_init(HW_TIMER, 1, &irq_handler); +} + +void hwtimer_arch_enable_interrupt(void) +{ + timer_irq_enable(HW_TIMER); +} + +void hwtimer_arch_disable_interrupt(void) +{ + timer_irq_disable(HW_TIMER); +} + +void hwtimer_arch_set(unsigned long offset, short timer) +{ + timer_set(HW_TIMER, timer, offset); +} + +void hwtimer_arch_set_absolute(unsigned long value, short timer) +{ + timer_set_absolute(HW_TIMER, timer, value); +} + +void hwtimer_arch_unset(short timer) +{ + timer_clear(HW_TIMER, timer); +} + +unsigned long hwtimer_arch_now(void) +{ + return timer_read(HW_TIMER); +} + +void irq_handler(int channel) +{ + timeout_handler((short)(channel)); +} From df3ed49305fa17adec180206a0e43b9047631921 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Mon, 4 May 2015 16:44:31 +0200 Subject: [PATCH 2/2] cpu: samd21: switch to hwtimer compat wrapper --- cpu/samd21/Makefile.include | 2 +- cpu/samd21/hwtimer_arch.c | 72 ------------------------------------- 2 files changed, 1 insertion(+), 73 deletions(-) delete mode 100644 cpu/samd21/hwtimer_arch.c diff --git a/cpu/samd21/Makefile.include b/cpu/samd21/Makefile.include index 78ef97db95..96226ee5d4 100644 --- a/cpu/samd21/Makefile.include +++ b/cpu/samd21/Makefile.include @@ -22,7 +22,7 @@ export UNDEF += $(BINDIR)cpu/syscalls.o export UNDEF += $(BINDIR)cpu/startup.o # export the peripheral drivers to be linked into the final binary -export USEMODULE += periph +export USEMODULE += periph hwtimer_compat # CPU depends on the cortex-m common module, so include it include $(CORTEX_COMMON)Makefile.include diff --git a/cpu/samd21/hwtimer_arch.c b/cpu/samd21/hwtimer_arch.c deleted file mode 100644 index 28825e51e3..0000000000 --- a/cpu/samd21/hwtimer_arch.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2014 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 cpu_samd21 - * @{ - * - * @file hwtimer_arch.c - * @brief Implementation of the kernels hwtimer interface - * - * The hardware timer implementation uses the Cortex build-in system timer as back-end. - * - * @author Thomas Eichinger - * - * @} - */ - -#include "arch/hwtimer_arch.h" -#include "board.h" -#include "periph/timer.h" -#include "thread.h" - - -void irq_handler(int channel); -void (*timeout_handler)(int); - - -void hwtimer_arch_init(void (*handler)(int), uint32_t fcpu) -{ - timeout_handler = handler; - timer_init(HW_TIMER, 1, &irq_handler); -} - -void hwtimer_arch_enable_interrupt(void) -{ - timer_irq_enable(HW_TIMER); -} - -void hwtimer_arch_disable_interrupt(void) -{ - timer_irq_disable(HW_TIMER); -} - -void hwtimer_arch_set(unsigned long offset, short timer) -{ - timer_set(HW_TIMER, timer, offset); -} - -void hwtimer_arch_set_absolute(unsigned long value, short timer) -{ - timer_set_absolute(HW_TIMER, timer, value); -} - -void hwtimer_arch_unset(short timer) -{ - timer_clear(HW_TIMER, timer); -} - -unsigned long hwtimer_arch_now(void) -{ - return timer_read(HW_TIMER); -} - -void irq_handler(int channel) -{ - timeout_handler((short)(channel)); -}