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:
maralvira 2010-11-07 14:24:11 +00:00
parent 091e4cd84e
commit 5e00219a9c
5 changed files with 22 additions and 30 deletions

View File

@ -30,7 +30,7 @@
* This file is part of libmc1322x: see http://mc1322x.devl.org * This file is part of libmc1322x: see http://mc1322x.devl.org
* for details. * 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 #ifndef CRM_H
@ -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

@ -30,7 +30,7 @@
* This file is part of libmc1322x: see http://mc1322x.devl.org * This file is part of libmc1322x: see http://mc1322x.devl.org
* for details. * 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 #ifndef GPIO_H
@ -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

@ -30,7 +30,7 @@
* This file is part of libmc1322x: see http://mc1322x.devl.org * This file is part of libmc1322x: see http://mc1322x.devl.org
* for details. * 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 #ifndef ISR_H
@ -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

@ -30,7 +30,7 @@
* This file is part of libmc1322x: see http://mc1322x.devl.org * This file is part of libmc1322x: see http://mc1322x.devl.org
* for details. * 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 #ifndef TMR_H
@ -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

@ -30,7 +30,7 @@
* This file is part of libmc1322x: see http://mc1322x.devl.org * This file is part of libmc1322x: see http://mc1322x.devl.org
* for details. * 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 <mc1322x.h> #include <mc1322x.h>
@ -67,9 +67,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();
} }
} }