![Lattice Semiconductor LatticeMico32 Hardware Developer User Manual Download Page 106](http://html1.mh-extra.com/html/lattice-semiconductor/latticemico32/latticemico32_hardware-developer-user-manual_3843852106.webp)
C
REATING
C
USTOM
C
OMPONENTS
IN
L
ATTICE
M
ICO
S
YSTEM
:
Custom Component Example
100
LatticeMico32 Hardware Developer User Guide
Software Support
For illustrative purposes, the example component’s initialization function must
set the reg_00 register to the value that was used to initialize the reg_08
register in the RTL. At run time, you can read this value from the reg_00
register and compare it to the RTL-initialized value in the reg_08 register.
Additionally, you can also read the platform frequency for which the platform
was configured in the reg_04 register.
The initialization function must be able to initialize all the instances in a
platform. This initialization routine, init_reg_device, is listed in the Reg_Dev.c
source file. It relies on the presence of the data structure shown in Figure 51:
This data structure must be initialized according to the instance’s
configuration in MSB. The data structure contains a member, b_addr, that
corresponds to the component’s base address, which is assigned by MSB. It
also contains a member, reg_08_
value
, which must contain the 32-bit value
used for initializing the reg_08 register in the RTL in MSB. This example
illustrates how to specify this data structure so that the SPE managed-build
process initializes and instantiates the data structure according to the
instances in the platform.
While simple, the sample custom component contains enough useful features
to illustrate the key steps needed to import it into MSB:
WISHBONE slave interface
External pins
INterrupt signal
RTL parameter initialization
Software support
Adding the Custom Component
In this section, you will add the example custom component to the MSB
graphical user interface.
It is assumed that the sources are located in the C:\Demo\MyComponent\
folder, as shown in Figure 52.
The intended destination repository for the custom component is
C:\Demo\MSBComponents.
Figure 51: Data Structure for Initialization
typedef
struct
st_reg_device {
unsigned
int
reg_08_value;
unsigned
int
b_addr;
} reg_device;