Debian Codegraph @

himbaechel/uarch/gatemate/tests/testing.cc

raw
1 /*
2 * nextpnr -- Next Generation Place and Route
3 *
4 * Copyright (C) 2024 The Project Peppercorn Authors.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 */
19
20 #include "testing.h"
21 #include <vector>
22 #include "command.h"
23 #include "uarch/gatemate/pack.h"
24 #define HIMBAECHEL_CONSTIDS "uarch/gatemate/constids.inc"
25 #include "himbaechel_constids.h"
26
27 NEXTPNR_NAMESPACE_BEGIN
28
29 void GateMateTest::SetUp()
30 {
31 init_share_dirname();
32 chipArgs.device = "CCGM1A1";
33 chipArgs.vopts.push_back("vopt");
34 chipArgs.vopts.push_back("--allow-unconstrained");
35 ctx = new Context(chipArgs);
36 ctx->uarch->init(ctx);
37 ctx->late_init();
38 impl = (GateMateImpl *)(ctx->uarch.get());
39 }
40
41 void GateMateTest::TearDown() { delete ctx; }
42
43 CellInfo *GateMateTest::create_cell_ptr(IdString type, std::string name)
44 {
45 CellInfo *cell = ctx->createCell(ctx->id(name), type);
46
47 auto add_port = [&](const IdString id, PortType dir) {
48 cell->ports[id].name = id;
49 cell->ports[id].type = dir;
50 };
51 switch (type.index) {
52 case id_CC_IBUF.index:
53 add_port(id_I, PORT_IN);
54 add_port(id_Y, PORT_OUT);
55 break;
56 case id_CC_OBUF.index:
57 add_port(id_A, PORT_IN);
58 add_port(id_O, PORT_OUT);
59 break;
60 case id_CC_TOBUF.index:
61 add_port(id_A, PORT_IN);
62 add_port(id_T, PORT_IN);
63 add_port(id_O, PORT_OUT);
64 break;
65 case id_CC_IOBUF.index:
66 add_port(id_A, PORT_IN);
67 add_port(id_T, PORT_IN);
68 add_port(id_Y, PORT_OUT);
69 add_port(id_IO, PORT_INOUT);
70 break;
71 case id_CC_LVDS_IBUF.index:
72 add_port(id_I_P, PORT_IN);
73 add_port(id_I_N, PORT_IN);
74 add_port(id_Y, PORT_OUT);
75 break;
76 case id_CC_LVDS_OBUF.index:
77 add_port(id_A, PORT_IN);
78 add_port(id_O_P, PORT_OUT);
79 add_port(id_O_N, PORT_OUT);
80 break;
81 case id_CC_LVDS_TOBUF.index:
82 add_port(id_A, PORT_IN);
83 add_port(id_T, PORT_IN);
84 add_port(id_O_P, PORT_OUT);
85 add_port(id_O_N, PORT_OUT);
86 break;
87 case id_CC_LVDS_IOBUF.index:
88 add_port(id_A, PORT_IN);
89 add_port(id_T, PORT_IN);
90 add_port(id_Y, PORT_OUT);
91 add_port(id_IO_P, PORT_INOUT);
92 add_port(id_IO_N, PORT_INOUT);
93 break;
94 case id_CC_IDDR.index:
95 add_port(id_D, PORT_IN);
96 add_port(id_CLK, PORT_IN);
97 add_port(id_Q0, PORT_OUT);
98 add_port(id_Q1, PORT_OUT);
99 break;
100 case id_CC_ODDR.index:
101 add_port(id_D0, PORT_IN);
102 add_port(id_D1, PORT_IN);
103 add_port(id_CLK, PORT_IN);
104 add_port(id_DDR, PORT_IN);
105 add_port(id_Q, PORT_OUT);
106 break;
107 case id_CC_DFF.index:
108 add_port(id_D, PORT_IN);
109 add_port(id_CLK, PORT_IN);
110 add_port(id_EN, PORT_IN);
111 add_port(id_SR, PORT_IN);
112 add_port(id_Q, PORT_OUT);
113 break;
114 case id_CC_DLT.index:
115 add_port(id_D, PORT_IN);
116 add_port(id_G, PORT_IN);
117 add_port(id_SR, PORT_IN);
118 add_port(id_Q, PORT_OUT);
119 break;
120 case id_CC_L2T4.index:
121 add_port(id_I0, PORT_IN);
122 add_port(id_I1, PORT_IN);
123 add_port(id_I2, PORT_IN);
124 add_port(id_I3, PORT_IN);
125 add_port(id_O, PORT_OUT);
126 break;
127 case id_CC_L2T5.index:
128 add_port(id_I0, PORT_IN);
129 add_port(id_I1, PORT_IN);
130 add_port(id_I2, PORT_IN);
131 add_port(id_I3, PORT_IN);
132 add_port(id_I4, PORT_IN);
133 add_port(id_O, PORT_OUT);
134 break;
135 case id_CC_LUT1.index:
136 add_port(id_I0, PORT_IN);
137 add_port(id_O, PORT_OUT);
138 break;
139 case id_CC_LUT2.index:
140 add_port(id_I0, PORT_IN);
141 add_port(id_I1, PORT_IN);
142 add_port(id_O, PORT_OUT);
143 break;
144 case id_CC_MX2.index:
145 add_port(id_D0, PORT_IN);
146 add_port(id_D1, PORT_IN);
147 add_port(id_S0, PORT_IN);
148 add_port(id_Y, PORT_OUT);
149 break;
150 case id_CC_MX4.index:
151 add_port(id_D0, PORT_IN);
152 add_port(id_D1, PORT_IN);
153 add_port(id_D2, PORT_IN);
154 add_port(id_D3, PORT_IN);
155 add_port(id_S0, PORT_IN);
156 add_port(id_S1, PORT_IN);
157 add_port(id_Y, PORT_OUT);
158 break;
159 case id_CC_ADDF.index:
160 add_port(id_A, PORT_IN);
161 add_port(id_B, PORT_IN);
162 add_port(id_CI, PORT_IN);
163 add_port(id_CO, PORT_OUT);
164 add_port(id_S, PORT_OUT);
165 break;
166 case id_CC_BUFG.index:
167 add_port(id_I, PORT_IN);
168 add_port(id_O, PORT_OUT);
169 break;
170 case id_CC_USR_RSTN.index:
171 add_port(id_USR_RSTN, PORT_OUT);
172 break;
173 case id_CC_PLL_ADV.index:
174 add_port(id_USR_SEL_A_B, PORT_IN);
175 [[fallthrough]];
176 case id_CC_PLL.index:
177 add_port(id_CLK_REF, PORT_IN);
178 add_port(id_USR_CLK_REF, PORT_IN);
179 add_port(id_CLK_FEEDBACK, PORT_IN);
180 add_port(id_USR_LOCKED_STDY_RST, PORT_IN);
181 add_port(id_USR_PLL_LOCKED_STDY, PORT_OUT);
182 add_port(id_USR_PLL_LOCKED, PORT_OUT);
183 add_port(id_CLK0, PORT_OUT);
184 add_port(id_CLK90, PORT_OUT);
185 add_port(id_CLK180, PORT_OUT);
186 add_port(id_CLK270, PORT_OUT);
187 add_port(id_CLK_REF_OUT, PORT_OUT);
188 break;
189 case id_CC_CFG_CTRL.index:
190 for (int i = 0; i < 8; i++)
191 add_port(ctx->idf("DATA[%d]", i), PORT_IN);
192 add_port(id_CLK, PORT_IN);
193 add_port(id_EN, PORT_IN);
194 add_port(id_RECFG, PORT_IN);
195 add_port(id_VALID, PORT_IN);
196 break;
197
198 default:
199 log_error("Trying to create unknown cell type %s.\n", type.c_str(ctx));
200 break;
201 }
202 return cell;
203 }
204
205 void GateMateTest::direct_connect(CellInfo *o_cell, IdString o_port, CellInfo *i_cell, IdString i_port)
206 {
207 NetInfo *net = ctx->createNet(ctx->idf("%s_%s", o_cell->name.c_str(ctx), o_port.c_str(ctx)));
208 o_cell->connectPort(o_port, net);
209 i_cell->connectPort(i_port, net);
210 }
211
212 NEXTPNR_NAMESPACE_END