In embedded systems, registers are often configured by setting specific bits. To make the code cleaner and reusable, firmware developers use macros to set fields in a register.
You are given a 16-bit control register layout:
Field
Bits
Position (LSB-first)
ENABLE
1
Bit 0
MODE
2
Bits 1–2
SPEED
3
Bits 3–5
RESERVED
2
Bits 6–7 (must be 0)
Your task is to:
Write macros to:
Set the ENABLE bit
Set the MODE field
Set the SPEED field
Read ENABLE, MODE, SPEED from input
Use the macros to pack a final 16-bit register value