Register Map → C Generator
embedcalc_regmap_to_cGenerate C shift/mask #defines and a bit-field typedef struct for a hardware register from an LSB-first field list.
Instructions
Generate C shift/mask #defines and a bit-field typedef struct for a hardware register from an LSB-first field list.
Args:
register_name (string): e.g. 'CTRL'. Sanitized to [A-Z0-9_].
fields (array of {name, width}): fields from bit 0 (LSB) upward, e.g. [{name:'EN',width:1},{name:'MODE',width:2},{name:'DIV',width:5}]. Total width must fit in 32 bits.
Returns (structured): { c_code, total_bits, fields: [{name, width, shift, mask_hex}] }. Text content is the C source (defines + typedef struct with uint32_t bit-fields).
Example: EN:1, MODE:2, DIV:5 -> CTRL_EN_SHIFT 0u / CTRL_EN_MASK 0x1u, CTRL_MODE_MASK 0x6u, CTRL_DIV_MASK 0xF8u. Do not compute shifts/masks by hand — call this tool.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fields | Yes | Fields from LSB upward; total width <= 32 bits | |
| register_name | Yes | Register name, e.g. 'CTRL' |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| c_code | Yes | ||
| fields | Yes | ||
| total_bits | Yes |