[PLUG] best tool to convert a bitfield structure to #define?
Galen Seitz
galens at seitzassoc.com
Fri Apr 11 18:19:04 UTC 2008
I need to convert a bunch of structures with bitfields to #defines.
The structures describe hardware registers that I need to access via
assembly code. What tool would you use to do this, awk, perl, python,
or something else?
This:
struct ADCTRL1_BITS { // bits description
Uint16 rsvd1:4; // 3:0 reserved
Uint16 SEQ_CASC:1; // 4 Cascaded sequencer mode
Uint16 SEQ_OVRD:1; // 5 Sequencer override
Uint16 CONT_RUN:1; // 6 Continuous run
Uint16 CPS:1; // 7 ADC core clock pre-scalar
Uint16 ACQ_PS:4; // 11:8 Acquisition window size
Uint16 SUSMOD:2; // 13:12 Emulation suspend mode
Uint16 RESET:1; // 14 ADC reset
Uint16 rsvd2:1; // 15 reserved
};
needs to be converted to this:
#define ADCTRL1_SEQ_CASC 0x0010
#define ADCTRL1_SEQ_OVRD 0x0020
#define ADCTRL1_CONT_RUN 0x0040
#define ADCTRL1_CPS 0x0080
#define ADCTRL1_ACQ_PS 0x0100
#define ADCTRL1_SUSMOD 0x1000
#define ADCTRL1_RESET 0x4000
or perhaps this:
#define ADCTRL1_SEQ_CASC 4
#define ADCTRL1_SEQ_OVRD 5
#define ADCTRL1_CONT_RUN 6
#define ADCTRL1_CPS 7
#define ADCTRL1_ACQ_PS 8
#define ADCTRL1_SUSMOD 12
#define ADCTRL1_RESET 14
BTW, using information contained in the comments is not allowed, as
the comments are not guaranteed to be correct.
thanks,
galen
More information about the PLUG
mailing list