You are implementing UART data transmission logic. A control register configures parity settings for data framing. The control register is defined as an 8-bit register:
typedef struct {
uint8_t parity_enable : 1; // 0 = Disabled, 1 = Enabled
uint8_t parity_type : 1; // 0 = Even parity, 1 = Odd parity
uint8_t reserved : 6; // Reserved bits
} UART_Control;
You’re given a 7-bit data (0–127). Your task is to create an 8-bit UART frame using the control register:
Parity in Simple Terms
Parity is an error-detection bit added to the data:
Example-1
Input: data = 85, parity_enable = 1, parity_type = 0
Output: frame = 0x55
Example-2
Input: data = 3, parity_enable = 1, parity_type = 1
Output: frame = 0x83
Example-3
Input: data = 25, parity_enable = 0, parity_type = 0
Output: frame = 0x19
Input
85 1 0
Expected Output
frame = 0x55