From d930ce0e2b855f1f96c0f8b7d937aa0241d510ba Mon Sep 17 00:00:00 2001 From: maralvira Date: Sun, 7 Nov 2010 14:24:36 +0000 Subject: [PATCH] Add some useful timer macros --- cpu/mc1322x/lib/include/tmr.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cpu/mc1322x/lib/include/tmr.h b/cpu/mc1322x/lib/include/tmr.h index 975d116ff..49ceac607 100644 --- a/cpu/mc1322x/lib/include/tmr.h +++ b/cpu/mc1322x/lib/include/tmr.h @@ -30,7 +30,7 @@ * This file is part of libmc1322x: see http://mc1322x.devl.org * for details. * - * $Id: tmr.h,v 1.7 2010/11/07 14:24:11 maralvira Exp $ + * $Id: tmr.h,v 1.8 2010/11/07 14:24:36 maralvira Exp $ */ #ifndef TMR_H @@ -139,11 +139,15 @@ static volatile struct TMR_struct * const TMR1 = (void *) (TMR1_BASE); static volatile struct TMR_struct * const TMR2 = (void *) (TMR2_BASE); static volatile struct TMR_struct * const TMR3 = (void *) (TMR3_BASE); +/* Get timer number from the timer pointer. */ +#define TMR_NUM(x) (((uint32_t)(x) - TMR_BASE) / TMR_OFFSET) + /* Used to compute which enable bit to set for a particular timer, e.g. TMR0.ENBL |= TMR_ENABLE_BIT(TMR2); Helpful when you're using macros to define timers */ -#define TMR_ENABLE_BIT(x) (((x) == TMR0) ? 1 : ((x) == TMR1) ? 2 : ((x) == TMR2) ? 4 : ((x) == TMR3) ? 8 : 0) +#define TMR_ENABLE_BIT(x) (1 << TMR_NUM(x)) + #define TMR0_PIN GPIO_08 #define TMR1_PIN GPIO_09 #define TMR2_PIN GPIO_10