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

@ -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