
HDL Synthesis Coding Guidelines
Lattice Semiconductor
for Lattice Semiconductor FPGAs
15-15
Inferring Bi-directional I/O
Users can either structurally instantiate the bi-directional I/O library elements, or behaviorally describe the I/O
paths to infer bi-directional buffers. The following VHDL and Verilog examples show how to infer bi-directional I/O
buffers.
Specifying I/O Types and Locations
Users can either assign I/O types and unique I/O locations in the Preference Editor or specify them as attributes in
the VHDL or Verilog source code. The following examples show how to add attributes in the Synplify and Leonardo-
Spectrum synthesis tool sets. For a complete list of supported attributes, refer to the HDL Attributes section of the
ispLEVER on-line help system.
-- VHDL example of specifying I/O type and location attributes for Synplify & Leonardo
entity cnt is
port(clk: in std_logic;
res: out std_logic);
attribute LEVELMODE: string:
attribute LEVELMODE of clk : signal is “SSTL2”;
attribute LOC of clk : signal is “V2”;
attribute LEVELMODE of res : signal is “SSTL2”;
attribute LOC of res : signal is “V3”;
end entity cnt;
-- Verilog example of specifying I/O type and location attributes for Synplify & Leonardo
module cnt(clk,res);
input clk /* synthesis LEVELMODE=”SSTL2” LOC=”V2”*/;
output res /* synthesis LEVELMODE=”SSTL2” LOC=”V3” */;
...
// exemplar begin
// exemplar attribute clk LEVELMODE SSTL2
// exemplar attribute clk LOC V2
// exemplar attribute res LEVELMODE SSTL2
// exemplar attribute res LOC V3
// exemplar end
endmodule
// Inferring Bi-directional I/O in Verilog
module bidir_infer (A, B, DIR);
inout A, B;
input DIR;
assign B = (DIR)
? A : 1'bz;
assign A = (~DIR) ? B : 1'bz;
endmodule
-- Inferring Bi-directional I/O in VHDL
library ieee;
use ieee.std_logic_1164.all;
entity bidir_infer is
port(A, B
: inout std_logic;
dir
: in std_logic);
end bidir_infer;
architecture lattice_fpga of bidir_infer is
begin
B <= A when (dir='1') else 'Z';
A <= B when (dir='0') else 'Z';
end lattice_fpga