3 from ..hdl
.rec
import *
4 from ..back
.pysim
import *
8 class PinLayoutTestCase(FHDLTestCase
):
9 def assertLayoutEqual(self
, layout
, expected
):
11 for name
, (shape
, dir) in layout
.items():
12 casted_layout
[name
] = (Shape
.cast(shape
), dir)
14 self
.assertEqual(casted_layout
, expected
)
17 class PinLayoutCombTestCase(PinLayoutTestCase
):
18 def test_pin_layout_i(self
):
19 layout_1
= pin_layout(1, dir="i")
20 self
.assertLayoutEqual(layout_1
.fields
, {
21 "i": ((1, False), DIR_NONE
),
24 layout_2
= pin_layout(2, dir="i")
25 self
.assertLayoutEqual(layout_2
.fields
, {
26 "i": ((2, False), DIR_NONE
),
29 def test_pin_layout_o(self
):
30 layout_1
= pin_layout(1, dir="o")
31 self
.assertLayoutEqual(layout_1
.fields
, {
32 "o": ((1, False), DIR_NONE
),
35 layout_2
= pin_layout(2, dir="o")
36 self
.assertLayoutEqual(layout_2
.fields
, {
37 "o": ((2, False), DIR_NONE
),
40 def test_pin_layout_oe(self
):
41 layout_1
= pin_layout(1, dir="oe")
42 self
.assertLayoutEqual(layout_1
.fields
, {
43 "o": ((1, False), DIR_NONE
),
44 "oe": ((1, False), DIR_NONE
),
47 layout_2
= pin_layout(2, dir="oe")
48 self
.assertLayoutEqual(layout_2
.fields
, {
49 "o": ((2, False), DIR_NONE
),
50 "oe": ((1, False), DIR_NONE
),
53 def test_pin_layout_io(self
):
54 layout_1
= pin_layout(1, dir="io")
55 self
.assertLayoutEqual(layout_1
.fields
, {
56 "i": ((1, False), DIR_NONE
),
57 "o": ((1, False), DIR_NONE
),
58 "oe": ((1, False), DIR_NONE
),
61 layout_2
= pin_layout(2, dir="io")
62 self
.assertLayoutEqual(layout_2
.fields
, {
63 "i": ((2, False), DIR_NONE
),
64 "o": ((2, False), DIR_NONE
),
65 "oe": ((1, False), DIR_NONE
),
69 class PinLayoutSDRTestCase(PinLayoutTestCase
):
70 def test_pin_layout_i(self
):
71 layout_1
= pin_layout(1, dir="i", xdr
=1)
72 self
.assertLayoutEqual(layout_1
.fields
, {
73 "i_clk": ((1, False), DIR_NONE
),
74 "i": ((1, False), DIR_NONE
),
77 layout_2
= pin_layout(2, dir="i", xdr
=1)
78 self
.assertLayoutEqual(layout_2
.fields
, {
79 "i_clk": ((1, False), DIR_NONE
),
80 "i": ((2, False), DIR_NONE
),
83 def test_pin_layout_o(self
):
84 layout_1
= pin_layout(1, dir="o", xdr
=1)
85 self
.assertLayoutEqual(layout_1
.fields
, {
86 "o_clk": ((1, False), DIR_NONE
),
87 "o": ((1, False), DIR_NONE
),
90 layout_2
= pin_layout(2, dir="o", xdr
=1)
91 self
.assertLayoutEqual(layout_2
.fields
, {
92 "o_clk": ((1, False), DIR_NONE
),
93 "o": ((2, False), DIR_NONE
),
96 def test_pin_layout_oe(self
):
97 layout_1
= pin_layout(1, dir="oe", xdr
=1)
98 self
.assertLayoutEqual(layout_1
.fields
, {
99 "o_clk": ((1, False), DIR_NONE
),
100 "o": ((1, False), DIR_NONE
),
101 "oe": ((1, False), DIR_NONE
),
104 layout_2
= pin_layout(2, dir="oe", xdr
=1)
105 self
.assertLayoutEqual(layout_2
.fields
, {
106 "o_clk": ((1, False), DIR_NONE
),
107 "o": ((2, False), DIR_NONE
),
108 "oe": ((1, False), DIR_NONE
),
111 def test_pin_layout_io(self
):
112 layout_1
= pin_layout(1, dir="io", xdr
=1)
113 self
.assertLayoutEqual(layout_1
.fields
, {
114 "i_clk": ((1, False), DIR_NONE
),
115 "i": ((1, False), DIR_NONE
),
116 "o_clk": ((1, False), DIR_NONE
),
117 "o": ((1, False), DIR_NONE
),
118 "oe": ((1, False), DIR_NONE
),
121 layout_2
= pin_layout(2, dir="io", xdr
=1)
122 self
.assertLayoutEqual(layout_2
.fields
, {
123 "i_clk": ((1, False), DIR_NONE
),
124 "i": ((2, False), DIR_NONE
),
125 "o_clk": ((1, False), DIR_NONE
),
126 "o": ((2, False), DIR_NONE
),
127 "oe": ((1, False), DIR_NONE
),
131 class PinLayoutDDRTestCase(PinLayoutTestCase
):
132 def test_pin_layout_i(self
):
133 layout_1
= pin_layout(1, dir="i", xdr
=2)
134 self
.assertLayoutEqual(layout_1
.fields
, {
135 "i_clk": ((1, False), DIR_NONE
),
136 "i0": ((1, False), DIR_NONE
),
137 "i1": ((1, False), DIR_NONE
),
140 layout_2
= pin_layout(2, dir="i", xdr
=2)
141 self
.assertLayoutEqual(layout_2
.fields
, {
142 "i_clk": ((1, False), DIR_NONE
),
143 "i0": ((2, False), DIR_NONE
),
144 "i1": ((2, False), DIR_NONE
),
147 def test_pin_layout_o(self
):
148 layout_1
= pin_layout(1, dir="o", xdr
=2)
149 self
.assertLayoutEqual(layout_1
.fields
, {
150 "o_clk": ((1, False), DIR_NONE
),
151 "o0": ((1, False), DIR_NONE
),
152 "o1": ((1, False), DIR_NONE
),
155 layout_2
= pin_layout(2, dir="o", xdr
=2)
156 self
.assertLayoutEqual(layout_2
.fields
, {
157 "o_clk": ((1, False), DIR_NONE
),
158 "o0": ((2, False), DIR_NONE
),
159 "o1": ((2, False), DIR_NONE
),
162 def test_pin_layout_oe(self
):
163 layout_1
= pin_layout(1, dir="oe", xdr
=2)
164 self
.assertLayoutEqual(layout_1
.fields
, {
165 "o_clk": ((1, False), DIR_NONE
),
166 "o0": ((1, False), DIR_NONE
),
167 "o1": ((1, False), DIR_NONE
),
168 "oe": ((1, False), DIR_NONE
),
171 layout_2
= pin_layout(2, dir="oe", xdr
=2)
172 self
.assertLayoutEqual(layout_2
.fields
, {
173 "o_clk": ((1, False), DIR_NONE
),
174 "o0": ((2, False), DIR_NONE
),
175 "o1": ((2, False), DIR_NONE
),
176 "oe": ((1, False), DIR_NONE
),
179 def test_pin_layout_io(self
):
180 layout_1
= pin_layout(1, dir="io", xdr
=2)
181 self
.assertLayoutEqual(layout_1
.fields
, {
182 "i_clk": ((1, False), DIR_NONE
),
183 "i0": ((1, False), DIR_NONE
),
184 "i1": ((1, False), DIR_NONE
),
185 "o_clk": ((1, False), DIR_NONE
),
186 "o0": ((1, False), DIR_NONE
),
187 "o1": ((1, False), DIR_NONE
),
188 "oe": ((1, False), DIR_NONE
),
191 layout_2
= pin_layout(2, dir="io", xdr
=2)
192 self
.assertLayoutEqual(layout_2
.fields
, {
193 "i_clk": ((1, False), DIR_NONE
),
194 "i0": ((2, False), DIR_NONE
),
195 "i1": ((2, False), DIR_NONE
),
196 "o_clk": ((1, False), DIR_NONE
),
197 "o0": ((2, False), DIR_NONE
),
198 "o1": ((2, False), DIR_NONE
),
199 "oe": ((1, False), DIR_NONE
),
203 class PinTestCase(FHDLTestCase
):
204 def test_attributes(self
):
205 pin
= Pin(2, dir="io", xdr
=2)
206 self
.assertEqual(pin
.width
, 2)
207 self
.assertEqual(pin
.dir, "io")
208 self
.assertEqual(pin
.xdr
, 2)