Complete the code to define a pointer to a memory-mapped I/O register at address 0x40021000.
volatile unsigned int *reg = (volatile unsigned int *)[1];The address 0x40021000 is the correct base address for the memory-mapped I/O register in this example.
Complete the code to write the value 0x01 to the memory-mapped register pointed by reg.
*reg = [1];Writing 0x01 sets the first bit of the register, often used to enable a feature.
Fix the error in the code to correctly read the value from the memory-mapped register.
unsigned int value = [1]reg;The dereference operator * is used to read the value pointed to by reg.
Fill both blanks to define a pointer to a volatile 8-bit register at address 0x50000010 and write 0xFF to it.
volatile [1] *reg8 = (volatile [2] *)0x50000010; *reg8 = 0xFF;
Using 'unsigned char' defines an 8-bit volatile pointer suitable for 8-bit registers.
Fill all three blanks to create a macro that reads a 16-bit memory-mapped register at a given address.
#define READ_REG16(addr) (*(volatile [1] *)[2]) unsigned short val = READ_REG16([3]);
The macro casts the address to a volatile unsigned short pointer and dereferences it. The address passed to the macro is 0x40002000.