Last active
October 17, 2020 18:03
-
-
Save jorgeacortes/a531d404c3592ccccffb24b35c9e4b06 to your computer and use it in GitHub Desktop.
Sample type for 32bit register with bit and value access in C (little endian machine).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
union register32_t { | |
uint32_t val; | |
struct { | |
uint32_t b0:1; | |
uint32_t b1:1; | |
uint32_t b2:1; | |
uint32_t b3:1; | |
uint32_t b4:1; | |
uint32_t b5:1; | |
uint32_t b6:1; | |
uint32_t b7:1; | |
uint32_t b8:1; | |
uint32_t b9:1; | |
uint32_t b10:1; | |
uint32_t b11:1; | |
uint32_t b12:1; | |
uint32_t b13:1; | |
uint32_t b14:1; | |
uint32_t b15:1; | |
uint32_t b16:1; | |
uint32_t b17:1; | |
uint32_t b18:1; | |
uint32_t b19:1; | |
uint32_t b20:1; | |
uint32_t b21:1; | |
uint32_t b22:1; | |
uint32_t b23:1; | |
uint32_t b24:1; | |
uint32_t b25:1; | |
uint32_t b26:1; | |
uint32_t b27:1; | |
uint32_t b28:1; | |
uint32_t b29:1; | |
uint32_t b30:1; | |
uint32_t b31:1; | |
}B; | |
}reg; | |
// Set value of the register | |
// reg.val = 0x02000349; | |
// Read value of a bit | |
// uint8_t bit = reg.B.b0; // 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment