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.
This commit is contained in:
Jim Paris 2010-09-26 16:05:12 -04:00
parent bf94b6d3bd
commit ac2cac1e1d
5 changed files with 17 additions and 25 deletions

View file

@ -218,8 +218,7 @@ struct CRM_struct {
uint32_t reserved6; uint32_t reserved6;
}; };
static volatile struct CRM_struct * const _CRM = (void *) (CRM_BASE); static volatile struct CRM_struct * const CRM = (void *) (CRM_BASE);
#define CRM (*_CRM)
/* Old register definitions, for compatibility */ /* Old register definitions, for compatibility */

View file

@ -39,13 +39,13 @@
/* Structure-based GPIO access /* Structure-based GPIO access
Example usage: 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 #define MY_PIN GPIO_08
GPIO.FUNC_SEL.MY_PIN = 2; // same, to allow #define for pin names GPIO->FUNC_SEL.MY_PIN = 2; // same, to allow #define for pin names
GPIO.DATA.MY_PIN = 1; GPIO->DATA.MY_PIN = 1;
*/ */
#define _V(x,n,i) uint32_t x##_##i : n; #define _V(x,n,i) uint32_t x##_##i : n;
@ -87,8 +87,7 @@ struct GPIO_struct {
#undef _REP #undef _REP
#undef _V #undef _V
static volatile struct GPIO_struct * const _GPIO = (void *) (0x80000000); static volatile struct GPIO_struct * const GPIO = (void *) (0x80000000);
#define GPIO (*_GPIO)
/* Old register definitions, for compatibility */ /* Old register definitions, for compatibility */

View file

@ -83,8 +83,7 @@ struct ITC_struct {
}; };
#undef __INTERRUPT_union #undef __INTERRUPT_union
static volatile struct ITC_struct * const _ITC = (void *) (INTBASE); static volatile struct ITC_struct * const ITC = (void *) (INTBASE);
#define ITC (*_ITC)
/* Old register definitions, for compatibility */ /* Old register definitions, for compatibility */

View file

@ -48,12 +48,12 @@
/* Structure-based register definitions */ /* Structure-based register definitions */
/* Example use: /* Example use:
TMR2.CTRL = 0x1234; TMR2->CTRL = 0x1234;
TMR2.CTRLbits = (struct TMR_CTRL) { TMR2->CTRLbits = (struct TMR_CTRL) {
.DIR = 1, .DIR = 1,
.OUTPUT_MODE = 2, .OUTPUT_MODE = 2,
}; };
TMR2.CTRLbits.PRIMARY_CNT_SOURCE = 3; TMR2->CTRLbits.PRIMARY_CNT_SOURCE = 3;
*/ */
struct TMR_struct { 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 TMR0 = (void *) (TMR0_BASE);
static volatile struct TMR_struct * const _TMR1 = (void *) (TMR1_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 TMR2 = (void *) (TMR2_BASE);
static volatile struct TMR_struct * const _TMR3 = (void *) (TMR3_BASE); static volatile struct TMR_struct * const TMR3 = (void *) (TMR3_BASE);
#define TMR0 (*_TMR0)
#define TMR1 (*_TMR1)
#define TMR2 (*_TMR2)
#define TMR3 (*_TMR3)
/* Used to compute which enable bit to set for a particular timer, e.g. /* Used to compute which enable bit to set for a particular timer, e.g.
TMR0.ENBL |= TMR_ENABLE_BIT(TMR2); TMR0.ENBL |= TMR_ENABLE_BIT(TMR2);
Helpful when you're using macros to define timers 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 TMR0_PIN GPIO_08
#define TMR1_PIN GPIO_09 #define TMR1_PIN GPIO_09
#define TMR2_PIN GPIO_10 #define TMR2_PIN GPIO_10

View file

@ -66,9 +66,9 @@ void irq(void)
if(kbi_evnt(6) && (kbi6_isr != 0)) { kbi6_isr(); } if(kbi_evnt(6) && (kbi6_isr != 0)) { kbi6_isr(); }
if(kbi_evnt(7) && (kbi7_isr != 0)) { kbi7_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(); cal_isr();
} }
} }