From ac2cac1e1d71419a24b409845d04de593da0d470 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Sun, 26 Sep 2010 16:05:12 -0400 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. --- lib/include/crm.h | 3 +-- lib/include/gpio.h | 11 +++++------ lib/include/isr.h | 3 +-- lib/include/tmr.h | 21 ++++++++------------- src/isr.c | 4 ++-- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/lib/include/crm.h b/lib/include/crm.h index 0442fd9db..09da00988 100644 --- a/lib/include/crm.h +++ b/lib/include/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/lib/include/gpio.h b/lib/include/gpio.h index e2999c4d9..09a3a1373 100644 --- a/lib/include/gpio.h +++ b/lib/include/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/lib/include/isr.h b/lib/include/isr.h index 799f2b56e..1647e3b8a 100644 --- a/lib/include/isr.h +++ b/lib/include/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/lib/include/tmr.h b/lib/include/tmr.h index 011c6d18c..179be46d2 100644 --- a/lib/include/tmr.h +++ b/lib/include/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/src/isr.c b/src/isr.c index 93477b1be..4202726ec 100644 --- a/src/isr.c +++ b/src/isr.c @@ -66,9 +66,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(); } }