36. Pointer to Struct with Bitfields

You are given a pointer to a UART_ControlRegister struct representing a 32-bit hardware register.
The struct has the following bitfields:

struct UART_ControlRegister {
    unsigned int baudrate : 4;   // Bits 0-3
    unsigned int tx_enable : 1;  // Bit 4
    unsigned int rx_enable : 1;  // Bit 5
    unsigned int tx_irq_en : 1;  // Bit 6
    unsigned int rx_irq_en : 1;  // Bit 7
    unsigned int parity_en : 1;  // Bit 8
    unsigned int stop_bits : 1;  // Bit 9
    unsigned int reserved : 22;  // Bits 10-31
};
  • Your task:
  • Write a function that receives a pointer to this struct.
  • Set the UART configuration:
    • Baud rate = 9
    • TX & RX enable = 1
    • TX IRQ = 1, RX IRQ = 0
    • Parity = 1
    • Stop bit = 0
  • Print each field’s value after configuration.

     

Example

Output:
baudrate = 9
tx_enable = 1
rx_enable = 1
tx_irq_en = 1
rx_irq_en = 0
parity_en = 1
stop_bits = 0

 

 

Loading...

Input

Expected Output

baudrate = 9 tx_enable = 1 rx_enable = 1 tx_irq_en = 1 rx_irq_en = 0 parity_en = 1 stop_bits = 0