From 5e00219a9cf14eafa1cebc7ed2f699707cbffac1 Mon Sep 17 00:00:00 2001 From: maralvira Date: Sun, 7 Nov 2010 14:24:11 +0000 Subject: [PATCH] Register definitions: get rid of some macro magic that doesn't help much Instead of e.g. GPIO.DATA.GPIO_08, you now use GPIO->DATA.GPIO_08. --- cpu/mc1322x/lib/include/crm.h | 5 ++--- cpu/mc1322x/lib/include/gpio.h | 13 ++++++------- cpu/mc1322x/lib/include/isr.h | 5 ++--- cpu/mc1322x/lib/include/tmr.h | 23 +++++++++-------------- cpu/mc1322x/src/isr.c | 6 +++--- 5 files changed, 22 insertions(+), 30 deletions(-) diff --git a/cpu/mc1322x/lib/include/crm.h b/cpu/mc1322x/lib/include/crm.h index 111c7d4dd..501d9e4d9 100644 --- a/cpu/mc1322x/lib/include/crm.h +++ b/cpu/mc1322x/lib/include/crm.h @@ -30,7 +30,7 @@ * This file is part of libmc1322x: see http://mc1322x.devl.org * for details. * - * $Id: crm.h,v 1.3 2010/11/07 14:22:51 maralvira Exp $ + * $Id: crm.h,v 1.4 2010/11/07 14:24:11 maralvira Exp $ */ #ifndef CRM_H @@ -218,8 +218,7 @@ struct CRM_struct { uint32_t reserved6; }; -static volatile struct CRM_struct * const _CRM = (void *) (CRM_BASE); -#define CRM (*_CRM) +static volatile struct CRM_struct * const CRM = (void *) (CRM_BASE); /* Old register definitions, for compatibility */ diff --git a/cpu/mc1322x/lib/include/gpio.h b/cpu/mc1322x/lib/include/gpio.h index e730e04c8..4a0d7077e 100644 --- a/cpu/mc1322x/lib/include/gpio.h +++ b/cpu/mc1322x/lib/include/gpio.h @@ -30,7 +30,7 @@ * This file is part of libmc1322x: see http://mc1322x.devl.org * for details. * - * $Id: gpio.h,v 1.2 2010/11/07 14:17:45 maralvira Exp $ + * $Id: gpio.h,v 1.3 2010/11/07 14:24:11 maralvira Exp $ */ #ifndef GPIO_H @@ -39,13 +39,13 @@ /* Structure-based GPIO access Example usage: - GPIO.FUNC_SEL0 |= 0x00008000; // set a whole register + GPIO->FUNC_SEL0 |= 0x00008000; // set a whole register - GPIO.FUNC_SEL_08 = 2; // set just one pin + GPIO->FUNC_SEL_08 = 2; // set just one pin #define MY_PIN GPIO_08 - GPIO.FUNC_SEL.MY_PIN = 2; // same, to allow #define for pin names - GPIO.DATA.MY_PIN = 1; + GPIO->FUNC_SEL.MY_PIN = 2; // same, to allow #define for pin names + GPIO->DATA.MY_PIN = 1; */ #define _V(x,n,i) uint32_t x##_##i : n; @@ -87,8 +87,7 @@ struct GPIO_struct { #undef _REP #undef _V -static volatile struct GPIO_struct * const _GPIO = (void *) (0x80000000); -#define GPIO (*_GPIO) +static volatile struct GPIO_struct * const GPIO = (void *) (0x80000000); /* Old register definitions, for compatibility */ diff --git a/cpu/mc1322x/lib/include/isr.h b/cpu/mc1322x/lib/include/isr.h index f22e61b88..96348d9cd 100644 --- a/cpu/mc1322x/lib/include/isr.h +++ b/cpu/mc1322x/lib/include/isr.h @@ -30,7 +30,7 @@ * This file is part of libmc1322x: see http://mc1322x.devl.org * for details. * - * $Id: isr.h,v 1.3 2010/11/07 14:23:15 maralvira Exp $ + * $Id: isr.h,v 1.4 2010/11/07 14:24:11 maralvira Exp $ */ #ifndef ISR_H @@ -83,8 +83,7 @@ struct ITC_struct { }; #undef __INTERRUPT_union -static volatile struct ITC_struct * const _ITC = (void *) (INTBASE); -#define ITC (*_ITC) +static volatile struct ITC_struct * const ITC = (void *) (INTBASE); /* Old register definitions, for compatibility */ diff --git a/cpu/mc1322x/lib/include/tmr.h b/cpu/mc1322x/lib/include/tmr.h index 5de31613a..975d116ff 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.6 2010/11/07 14:21:06 maralvira Exp $ + * $Id: tmr.h,v 1.7 2010/11/07 14:24:11 maralvira Exp $ */ #ifndef TMR_H @@ -48,12 +48,12 @@ /* Structure-based register definitions */ /* Example use: - TMR2.CTRL = 0x1234; - TMR2.CTRLbits = (struct TMR_CTRL) { + TMR2->CTRL = 0x1234; + TMR2->CTRLbits = (struct TMR_CTRL) { .DIR = 1, .OUTPUT_MODE = 2, }; - TMR2.CTRLbits.PRIMARY_CNT_SOURCE = 3; + TMR2->CTRLbits.PRIMARY_CNT_SOURCE = 3; */ struct TMR_struct { @@ -134,21 +134,16 @@ struct TMR_struct { }; }; -static volatile struct TMR_struct * const _TMR0 = (void *) (TMR0_BASE); -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); -#define TMR0 (*_TMR0) -#define TMR1 (*_TMR1) -#define TMR2 (*_TMR2) -#define TMR3 (*_TMR3) +static volatile struct TMR_struct * const TMR0 = (void *) (TMR0_BASE); +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); /* 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) (((x) == TMR0) ? 1 : ((x) == TMR1) ? 2 : ((x) == TMR2) ? 4 : ((x) == TMR3) ? 8 : 0) #define TMR0_PIN GPIO_08 #define TMR1_PIN GPIO_09 #define TMR2_PIN GPIO_10 diff --git a/cpu/mc1322x/src/isr.c b/cpu/mc1322x/src/isr.c index 70b5509c6..9f7f92f5f 100644 --- a/cpu/mc1322x/src/isr.c +++ b/cpu/mc1322x/src/isr.c @@ -30,7 +30,7 @@ * This file is part of libmc1322x: see http://mc1322x.devl.org * for details. * - * $Id: isr.c,v 1.2 2010/11/07 14:21:59 maralvira Exp $ + * $Id: isr.c,v 1.3 2010/11/07 14:24:11 maralvira Exp $ */ #include @@ -67,9 +67,9 @@ void irq(void) if(kbi_evnt(6) && (kbi6_isr != 0)) { kbi6_isr(); } if(kbi_evnt(7) && (kbi7_isr != 0)) { kbi7_isr(); } - if (CRM.STATUSbits.CAL_DONE && CRM.CAL_CNTLbits.CAL_IEN && cal_isr) + if (CRM->STATUSbits.CAL_DONE && CRM->CAL_CNTLbits.CAL_IEN && cal_isr) { - CRM.STATUSbits.CAL_DONE = 0; + CRM->STATUSbits.CAL_DONE = 0; cal_isr(); } }