I have been messing around with bitfield structures and the GNU ARM compiler. Here is what has worked for me so far.
I am working with a OLIMEX LPC2138 header board and wiggler clone.
First off thnx to everyone who has taken the time to post and help others. This has saved me countless hours of hair pulling!
Here is a sample from an include file defining the bitfields
/* PLL Control register (PLLCON - 0xE01F C080) */
#define PLLCON_ADDRESS (0xE01FC080)
/* PLLCON bitfield structure */
typedef union t_PLLCON {
struct {
BYTE PLLE:1; /* PLL Enable */
BYTE PLLC:1; /* PLL Connect */
BYTE Reserved:6;
};
}t_PLLCON;
#define PLLCON_REG (*(volatile t_PLLCON *)PLLCON_ADDRESS)
#define PLLCON_REG_PLLE PLLCON_REG.PLLE
#define PLLCON_REG_PLLC PLLCON_REG.PLLC
/* PLL Configuration register (PLLCFG - 0xE01F C084) */
#define PLLCFG_ADDRESS (0xE01FC084)
/* PLLCFG bitfield structure */
typedef union t_PLLCFG {
struct {
BYTE MSEL:5; /* PLL Multiplier value. */
BYTE PSEL:2; /* PLL Divider value. */
BYTE Reserved:1;
};
}t_PLLCFG;
#define PLLCFG_REG (*(volatile t_PLLCFG *)PLLCFG_ADDRESS)
#define PLLCFG_REG_MSEL PLLCFG_REG.MSEL
#define PLLCFG_REG_PSEL PLLCFG_REG.PSEL
/* PLL Status register (PLLSTAT - 0xE01F C088) */
#define PLLSTAT_ADDRESS (0xE01FC088)
/* PLLSTAT bitfield structure */
typedef union t_PLLSTAT {
struct {
WORD MSEL:5; /* Read-back for the PLL Multiplier value. */
WORD PSEL:2; /* Read-back for the PLL Divider value. */
WORD Reserved1:1;
WORD PLLE:1; /* Read-back for the PLL Enable bit. */
WORD PLLC:1; /* Read-back for the PLL Connect bit. */
WORD PLOCK:1; /* Reflects the PLL Lock status. */
WORD Reserved2:5;
};
}t_PLLSTAT;
#define PLLSTAT_REG (*(volatile t_PLLSTAT *)PLLSTAT_ADDRESS)
#define PLLSTAT_REG_MSEL PLLSTAT_REG.MSEL
#define PLLSTAT_REG_PSEL PLLSTAT_REG.PSEL
#define PLLSTAT_REG_PLLE PLLSTAT_REG.PLLE
#define PLLSTAT_REG_PLLC PLLSTAT_REG.PLLC
#define PLLSTAT_REG_PLOC PLLSTAT_REG.PLOCK
Here is sample code using bitfield access
UINT32 CpuGetFrequency(void)
{
/* Local variables */
UINT32 msel;
/* Get MSEL value using bitfield access */
msel = PLLSTAT_REG_MSEL;
/* Calculate Cpu clock frequency */
CpuFrequency = CPU_OSC_FREQUENCY * (msel + 1);
/* Return calculated frequency */
return(CpuFrequency);
}