When working with FPGAs, you may sometimes need to use libraries provided by the vendor. SCode provides methods to include and use Xilinx libraries.
If you need to use a library component that is not already defined in SCode’s built-in xilinx_lib.sh, there are two ways to add it:
- Modify
xilinx_lib.sh: You can edit the file directly, following the pattern of existing definitions. - Add via functions in your code: Use the
xilinx_unisim_lib_appendorxilinx_unimacro_lib_appendfunctions directly in your SCode logic.
To use the second method, you need to provide the I/O information for the library component. The function parameters are as follows:
xilinx_unisim_lib_append(name, i, o, io=[], generic={})
xilinx_unimacro_lib_append(name, i, o, io=[], generic={})
Pass the library component name as a string, and the input (i) and output (o) pin names as lists. If there are inout (io) pins, provide them as a list; otherwise, this can be omitted. Generics can be provided as a dictionary and are also optional.
For example, the following code adds the IBUFGDS_DIFF_OUT component, which takes a differential input and produces a differential output:
xilinx_unisim_lib_append('IBUFGDS_DIFF_OUT', ['I', 'IB'], ['O', 'OB'])
Since there are no inout pins or generics required for this component, those parameters are omitted. Once added, you can instantiate the component as follows:
IBUFGDS_DIFF_OUT(I=I, IB=IB, O=O, OB=OB)
The resulting converted VHDL code will look like this:
u0_IBUFGDS_DIFF_OUT : IBUFGDS_DIFF_OUT port map (
I => I,
IB => IB,
O => O,
OB => OB
);