LatticeMico32 Microprocessor Software Support
16
LatticeMico GPIO
Assume that you have a design that contains a 32-bit GPIO that has been
assigned a base address of 0x80000100. The GPIO data register for input
and output of data is located at offset 0 from the base address. Byte 0 ( bits 7-
0) of this GPIO data register is located at byte offset 0 (address 0x80000100),
while byte 3 (bits 31-24) is located at byte offset 3 from the base address
(0x800001003). Lets assume that the GPIO has received a value [31:0] =
32'h12345678 and the programmer is writing C code to read the 32-bit GPIO.
Figure 10 shows a sample code to read the 32-bit GPIO using byte reads (i.e.,
"unsigned char" or "signed char").
The execution of the code in Figure 10 will result in byte0 = 0x78, byte1 =
0x56, byte2 = 0x34, and byte3 = 0x12.
Now consider the sample code of Figure 11 in which the programmer is
reading the same 32-bit GPIO using word reads ("unsigned int" or "signed
int").
As mentioned, LatticeMico32 is a big-endian microprocessor. Therefore, from
the programmer's perspective, the least-significant byte of the GPIO will
appear in the most-significant location. The execution of the code in Figure 11
will result in 'word' being loaded with a value of 0x78563412.
Register Map Structure
The structure shown in Figure 5 depicts the register map layout for the GPIO
component. The elements are self-explanatory and are based on the register,
as shown in Table 4 on page 10. This structure, which is defined in the
MicoGPIO.h header file, enables you to directly access the GPIO registers, if
desired. It is used internally by the device driver for manipulating the GPIO.
Figure 10: Access to a 32-bit GPIO using byte reads
unsigned char byte0, byte1, byte2, byte3;
byte0 = *(volatile unsigned char *)0x80000100;
byte1 = *(volatile unsigned char *)0x80000101;
byte2 = *(volatile unsigned char *)0x80000102;
byte3 = *(volatile unsigned char *)0x80000103;
Figure 11: Access to a 32-bit GPIO using word reads
unsigned int word;
word = *(volatile unsigned int *)0x80000100;