Winston Jenks

Structured C access to Coldfire peripheral registers

Discussion created by Winston Jenks on Jul 21, 2006
Latest reply on Jul 21, 2006 by Marc Vincent
I am just moving from the 8-bit world to a Coldfire project. Am I missing something, or do the .h header files that get copied into a Coldfire Stationary project not have bit-wise and grouped bits access via structures like in the HCS08 headers?

I had to cook something up like the following to get simple bit access to various structures. I am sure with a little more thought I could have made the names just like the names in the HCS08 headers. That might make porting easier. Hopefully, somebody else has already done this. I sure would hate to have to reproduce this for all the peripheral registers on the MCF5xxx family!

typedef union {
unsigned char Byte;
struct {
unsigned char x7 :1;
unsigned char x6 :1;
unsigned char x5 :1;
unsigned char x4 :1;
unsigned char x3 :1;
unsigned char x2 :1;
unsigned char x1 :1;
unsigned char x0 :1;
} Bits;
} ByteSTR;
#define _PORTAS ((ByteSTR*)(&__IPSBAR[0x10000C]))
#define PORTAS _PORTAS->Byte
#define PORTAS_x0 _PORTAS->Bits.x0
#define PORTAS_x1 _PORTAS->Bits.x1
#define PORTAS_x2 _PORTAS->Bits.x2
#define PORTAS_x3 _PORTAS->Bits.x3
#define PORTAS_x4 _PORTAS->Bits.x4
#define PORTAS_x5 _PORTAS->Bits.x5
#define PORTAS_x6 _PORTAS->Bits.x6
#define PORTAS_x7 _PORTAS->Bits.x7
#define _PORTASDD ((ByteSTR*)(&__IPSBAR[0x100020]))
#define PORTASDD _PORTASDD->Byte
#define PORTASDD_x0 _PORTASDD->Bits.x0
#define PORTASDD_x1 _PORTASDD->Bits.x1
#define PORTASDD_x2 _PORTASDD->Bits.x2
#define PORTASDD_x3 _PORTASDD->Bits.x3
#define PORTASDD_x4 _PORTASDD->Bits.x4
#define PORTASDD_x5 _PORTASDD->Bits.x5
#define PORTASDD_x6 _PORTASDD->Bits.x6
#define PORTASDD_x7 _PORTASDD->Bits.x7

Outcomes