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:
parent
bf94b6d3bd
commit
ac2cac1e1d
5 changed files with 17 additions and 25 deletions
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue