The command line program mkhdr can generate a C/C++ header file from a crossworks memory map file.

For each register definition in the memory map file a corresponding #define is generated in the header file. The #define is named the same as the register name and is defined as a volatile pointer to the address. The type of the pointer is derived from the size of the register. A 4 byte register will generate an unsigned long pointer. A 2 byte register will generate an unsigned short pointer. A 1 byte register will generate an unsigned char pointer.

If a register definition in the memory map file has bitfields then #defines are generated for each bitfield. Each bitfield will have two #defines generated, one representing the mask and one defining the start bit position. The bitfield #define names are formed by prepending the register name to the bitfield name. The mask definition has _MASK appended to it and the start definition has _BIT appended to it.

For example given the following definitions in the the file memorymap.xml.

<RegisterGroup start="0xFFFFF000" name="AIC" >
  <Register start="+0x00" size="4" name="AIC_SMR0">
    <BitField size="3" name="PRIOR" start="0" />
    <BitField size="2" name="SRCTYPE" start="5" />
  </Register>
  ...

The command line

mkhdr memorymap.xml memorymap.h

Will generate the following definitions in the file memorymap.h.

#define AIC_SMR0 (*(volatile unsigned long *)0xFFFFF000)
#define AIC_SMR0_PRIOR_MASK 0x7
#define AIC_SMR0_PRIOR_BIT 0
#define AIC_SMR0_SRCTYPE_MASK 0x60
#define AIC_SMR0_SRCTYPE_BIT 5

These definitions can be used in the following way in a C/C++ program.

Reading from a register.

unsigned r = AIC_SMR0;

Writing to a register.

AIC_SMR0 = (priority << AIC_SMR0_PRIOR_BIT) | (srctype << AIC_SMR0_SRCTYPE_BIT);

Reading a bitfield.

unsigned srctype = (AIC_SMR0 & AIC_SMR0_SRCTYPE_MASK) >> AIC_SMR0_SRCTYPE_BIT;

Writing a bitfield.

AIC_SMR0 = (AIC_SMR0 & ~AIC_SMR0_SRCTYPE_MASK) | ((srctype & AIC_SMR0_SRCTYPE_MASK) << AIC_SMR0_SRCTYPE_BIT);

Usage:

mkhdr inputfile outputfile [targetname] [option]

Element Description
inputfile The name of the source CrossWorks memory map file.
outputfile The name of the file to generated.
-regbaseoffsets Include offsets of registers from the peripheral base.
-nobitfields Do not generate any definitions for bitfields.