Masked Registers¶
Masked registers were introduced to pack indepedend information to one 16-bit register. To extract information user has to apply correct mask by using and logic operator (\(\land\)) and shift operator (\(\Rightarrow\)).
Masked Register Example¶
Fuse state for EC/3V/Roof fans, information can be read from 4 bits.
Parameter name |
Description |
Shift |
Mask |
Value |
---|---|---|---|---|
FAN_ROOF |
Fan roof fuse state |
0 |
15 |
fuse_condition |
FAN_EC |
Fan EC fuse state |
4 |
240 |
fuse_condition |
FAN_3V |
Fan 3V fuse state |
8 |
3840 |
fuse_condition |
Note
Table shows indepedend information that can be extraced from this register. Value column points to expected return values and their interpretation.
fuse_condition
Parameter name |
Description |
Value |
---|---|---|
NOT_SET |
Not set. |
0 |
FUSE_OK |
Fan fuse is OK |
1 |
FUSE_BLOWN |
Fan fuse is BLOWN. |
2 |
Note
Table shows how to interpret information after applying mask and shift.
How to extract values¶
- assumption
Device returned value 4384 from masked register example.
- task
Extract FAN_EC fuse condition.
Math representation¶
Python implementation¶
1def extract_masked_value(value, mask, shift):
2 return (value & mask) >> shift
C implementation¶
1uint16_t extract_masked_value(uint16_t value, uint16_t mask, uint16_t shift) {
2 return ((value & mask) >> shift);
3};
Lastly interpret recived value according to fuse_condition table.
FUSE_BLOWN |
Fan fuse is BLOWN. |
2 |
Tip
Depending on how the information is split through the register it might be easier to read in a hexadecimal format. From our example 4384 can be represented as hex 0x1120 (0 - NOT_SET, 1 - FUSE_OK etc.). Presenting value in hex format helps when information is written on nibbles, binary format is more suitable for information written on bits.