5 # install escape sequence translation on Windows
6 if os
.getenv("COLORAMA", "") == "force":
7 colorama
.init(strip
=False)
12 _have_colorama
= False
14 from litex
.gen
.fhdl
.structure
import *
15 from litex
.gen
.fhdl
.specials
import Instance
16 from litex
.gen
.fhdl
.module
import Module
17 from litex
.gen
.genlib
.cdc
import *
18 from litex
.gen
.genlib
.resetsync
import AsyncResetSynchronizer
19 from litex
.gen
.genlib
.io
import *
21 from litex
.build
import tools
27 ("^ERROR:.*$", colorama
.Fore
.RED
+ colorama
.Style
.BRIGHT
+
28 r
"\g<0>" + colorama
.Style
.RESET_ALL
),
29 ("^CRITICAL WARNING:.*$", colorama
.Fore
.RED
+
30 r
"\g<0>" + colorama
.Style
.RESET_ALL
),
31 ("^WARNING:.*$", colorama
.Fore
.YELLOW
+
32 r
"\g<0>" + colorama
.Style
.RESET_ALL
),
33 ("^INFO:.*$", colorama
.Fore
.GREEN
+
34 r
"\g<0>" + colorama
.Style
.RESET_ALL
),
38 def settings(path
, name
=None, ver
=None, first
=None):
39 if first
== "version":
41 vers
= tools
.versions(path
)
44 full
= os
.path
.join(path
, str(ver
), name
)
47 path
= os
.path
.join(path
, name
)
50 vers
= tools
.versions(path
)
53 full
= os
.path
.join(path
, str(ver
))
57 "no version directory for Xilinx tools found in {}".format(
61 if tools
.arch_bits() == 32:
64 if sys
.platform
== "win32" or sys
.platform
== "cygwin":
71 settings
= os
.path
.join(full
, "settings{0}.{1}".format(b
, script_ext
))
72 if os
.path
.exists(settings
):
74 searched_in
.append(settings
)
77 "no Xilinx tools settings file found.\n"
80 "\n ".join(searched_in
))
83 class XilinxMultiRegImpl(MultiRegImpl
):
84 def __init__(self
, *args
, **kwargs
):
85 MultiRegImpl
.__init
__(self
, *args
, **kwargs
)
87 r
.attr
.add("async_reg")
88 r
.attr
.add("no_shreg_extract")
94 return XilinxMultiRegImpl(dr
.i
, dr
.o
, dr
.odomain
, dr
.n
)
97 class XilinxAsyncResetSynchronizerImpl(Module
):
98 def __init__(self
, cd
, async_reset
):
99 if not hasattr(async_reset
, "attr"):
100 i
, async_reset
= async_reset
, Signal()
101 self
.comb
+= async_reset
.eq(i
)
104 Instance("FDPE", p_INIT
=1, i_D
=0, i_PRE
=async_reset
,
105 i_CE
=1, i_C
=cd
.clk
, o_Q
=rst_meta
,
106 attr
={"async_reg", "ars_ff"}),
107 Instance("FDPE", p_INIT
=1, i_D
=rst_meta
, i_PRE
=async_reset
,
108 i_CE
=1, i_C
=cd
.clk
, o_Q
=cd
.rst
,
109 attr
={"async_reg", "ars_ff"})
111 async_reset
.attr
.add("ars_false_path")
114 class XilinxAsyncResetSynchronizer
:
117 return XilinxAsyncResetSynchronizerImpl(dr
.cd
, dr
.async_reset
)
120 class XilinxDifferentialInputImpl(Module
):
121 def __init__(self
, i_p
, i_n
, o
):
122 self
.specials
+= Instance("IBUFDS", i_I
=i_p
, i_IB
=i_n
, o_O
=o
)
125 class XilinxDifferentialInput
:
128 return XilinxDifferentialInputImpl(dr
.i_p
, dr
.i_n
, dr
.o
)
131 class XilinxDifferentialOutputImpl(Module
):
132 def __init__(self
, i
, o_p
, o_n
):
133 self
.specials
+= Instance("OBUFDS", i_I
=i
, o_O
=o_p
, o_OB
=o_n
)
136 class XilinxDifferentialOutput
:
139 return XilinxDifferentialOutputImpl(dr
.i
, dr
.o_p
, dr
.o_n
)
142 class XilinxDDROutputImpl(Module
):
143 def __init__(self
, i1
, i2
, o
, clk
):
144 self
.specials
+= Instance("ODDR2",
145 p_DDR_ALIGNMENT
="NONE", p_INIT
=0, p_SRTYPE
="SYNC",
146 i_C0
=clk
, i_C1
=~clk
, i_CE
=1, i_S
=0, i_R
=0,
147 i_D0
=i1
, i_D1
=i2
, o_Q
=o
,
151 class XilinxDDROutput
:
154 return XilinxDDROutputImpl(dr
.i1
, dr
.i2
, dr
.o
, dr
.clk
)
157 xilinx_special_overrides
= {
158 MultiReg
: XilinxMultiReg
,
159 AsyncResetSynchronizer
: XilinxAsyncResetSynchronizer
,
160 DifferentialInput
: XilinxDifferentialInput
,
161 DifferentialOutput
: XilinxDifferentialOutput
,
162 DDROutput
: XilinxDDROutput
166 class XilinxDDROutputImplS7(Module
):
167 def __init__(self
, i1
, i2
, o
, clk
):
168 self
.specials
+= Instance("ODDR",
169 p_DDR_CLK_EDGE
="SAME_EDGE",
170 i_C
=clk
, i_CE
=1, i_S
=0, i_R
=0,
171 i_D1
=i1
, i_D2
=i2
, o_Q
=o
,
175 class XilinxDDROutputS7
:
178 return XilinxDDROutputImplS7(dr
.i1
, dr
.i2
, dr
.o
, dr
.clk
)
181 xilinx_s7_special_overrides
= {
182 DDROutput
: XilinxDDROutputS7