80746be0fd3ae8e4d8ff3a06b520bb3f760720cd
[yosys.git] / techlibs / greenpak4 / cells_sim.v
1 `timescale 1ns/1ps
2
3 module GP_2LUT(input IN0, IN1, output OUT);
4 parameter [3:0] INIT = 0;
5 assign OUT = INIT[{IN1, IN0}];
6 endmodule
7
8 module GP_3LUT(input IN0, IN1, IN2, output OUT);
9 parameter [7:0] INIT = 0;
10 assign OUT = INIT[{IN2, IN1, IN0}];
11 endmodule
12
13 module GP_4LUT(input IN0, IN1, IN2, IN3, output OUT);
14 parameter [15:0] INIT = 0;
15 assign OUT = INIT[{IN3, IN2, IN1, IN0}];
16 endmodule
17
18 module GP_ABUF(input wire IN, output wire OUT);
19
20 assign OUT = IN;
21
22 //cannot simulate mixed signal IP
23
24 endmodule
25
26 module GP_ACMP(input wire PWREN, input wire VIN, input wire VREF, output reg OUT);
27
28 parameter BANDWIDTH = "HIGH";
29 parameter VIN_ATTEN = 1;
30 parameter VIN_ISRC_EN = 0;
31 parameter HYSTERESIS = 0;
32
33 initial OUT = 0;
34
35 //cannot simulate mixed signal IP
36
37 endmodule
38
39 module GP_BANDGAP(output reg OK);
40 parameter AUTO_PWRDN = 1;
41 parameter CHOPPER_EN = 1;
42 parameter OUT_DELAY = 100;
43
44 //cannot simulate mixed signal IP
45
46 endmodule
47
48 module GP_COUNT8(input CLK, input wire RST, output reg OUT);
49
50 parameter RESET_MODE = "RISING";
51
52 parameter COUNT_TO = 8'h1;
53 parameter CLKIN_DIVIDE = 1;
54
55 //more complex hard IP blocks are not supported for simulation yet
56
57 reg[7:0] count = COUNT_TO;
58
59 //Combinatorially output whenever we wrap low
60 always @(*) begin
61 OUT <= (count == 8'h0);
62 end
63
64 //POR or SYSRST reset value is COUNT_TO. Datasheet is unclear but conversations w/ Silego confirm.
65 //Runtime reset value is clearly 0 except in count/FSM cells where it's configurable but we leave at 0 for now.
66 //Datasheet seems to indicate that reset is asynchronous, but for now we model as sync due to Yosys issues...
67 always @(posedge CLK) begin
68
69 count <= count - 1'd1;
70
71 if(count == 0)
72 count <= COUNT_TO;
73
74 /*
75 if((RESET_MODE == "RISING") && RST)
76 count <= 0;
77 if((RESET_MODE == "FALLING") && !RST)
78 count <= 0;
79 if((RESET_MODE == "BOTH") && RST)
80 count <= 0;
81 */
82 end
83
84 endmodule
85
86 module GP_COUNT14(input CLK, input wire RST, output reg OUT);
87
88 parameter RESET_MODE = "RISING";
89
90 parameter COUNT_TO = 14'h1;
91 parameter CLKIN_DIVIDE = 1;
92
93 //more complex hard IP blocks are not supported for simulation yet
94
95 endmodule
96
97 module GP_COUNT8_ADV(input CLK, input RST, output reg OUT,
98 input UP, input KEEP);
99
100 parameter RESET_MODE = "RISING";
101 parameter RESET_VALUE = "ZERO";
102
103 parameter COUNT_TO = 8'h1;
104 parameter CLKIN_DIVIDE = 1;
105
106 //more complex hard IP blocks are not supported for simulation yet
107
108 endmodule
109
110 module GP_COUNT14_ADV(input CLK, input RST, output reg OUT,
111 input UP, input KEEP);
112
113 parameter RESET_MODE = "RISING";
114 parameter RESET_VALUE = "ZERO";
115
116 parameter COUNT_TO = 14'h1;
117 parameter CLKIN_DIVIDE = 1;
118
119 //more complex hard IP blocks are not supported for simulation yet
120
121 endmodule
122
123 module GP_DAC(input[7:0] DIN, input wire VREF, output reg VOUT);
124
125 initial VOUT = 0;
126
127 //analog hard IP is not supported for simulation
128
129 endmodule
130
131 module GP_DELAY(input IN, output reg OUT);
132
133 parameter DELAY_STEPS = 1;
134 parameter GLITCH_FILTER = 0;
135
136 initial OUT = 0;
137
138 generate
139
140 //TODO: These delays are PTV dependent! For now, hard code 3v3 timing
141 //Change simulation-mode delay depending on global Vdd range (how to specify this?)
142 always @(*) begin
143 case(DELAY_STEPS)
144 1: #166 OUT = IN;
145 2: #318 OUT = IN;
146 2: #471 OUT = IN;
147 3: #622 OUT = IN;
148 default: begin
149 $display("ERROR: GP_DELAY must have DELAY_STEPS in range [1,4]");
150 $finish;
151 end
152 endcase
153 end
154
155 endgenerate
156
157 endmodule
158
159 module GP_DFF(input D, CLK, output reg Q);
160 parameter [0:0] INIT = 1'bx;
161 initial Q = INIT;
162 always @(posedge CLK) begin
163 Q <= D;
164 end
165 endmodule
166
167 module GP_DFFI(input D, CLK, output reg nQ);
168 parameter [0:0] INIT = 1'bx;
169 initial nQ = INIT;
170 always @(posedge CLK) begin
171 nQ <= ~D;
172 end
173 endmodule
174
175 module GP_DFFR(input D, CLK, nRST, output reg Q);
176 parameter [0:0] INIT = 1'bx;
177 initial Q = INIT;
178 always @(posedge CLK, negedge nRST) begin
179 if (!nRST)
180 Q <= 1'b0;
181 else
182 Q <= D;
183 end
184 endmodule
185
186 module GP_DFFRI(input D, CLK, nRST, output reg nQ);
187 parameter [0:0] INIT = 1'bx;
188 initial nQ = INIT;
189 always @(posedge CLK, negedge nRST) begin
190 if (!nRST)
191 nQ <= 1'b1;
192 else
193 nQ <= ~D;
194 end
195 endmodule
196
197 module GP_DFFS(input D, CLK, nSET, output reg Q);
198 parameter [0:0] INIT = 1'bx;
199 initial Q = INIT;
200 always @(posedge CLK, negedge nSET) begin
201 if (!nSET)
202 Q <= 1'b1;
203 else
204 Q <= D;
205 end
206 endmodule
207
208 module GP_DFFSI(input D, CLK, nSET, output reg nQ);
209 parameter [0:0] INIT = 1'bx;
210 initial nQ = INIT;
211 always @(posedge CLK, negedge nSET) begin
212 if (!nSET)
213 nQ <= 1'b0;
214 else
215 nQ <= ~D;
216 end
217 endmodule
218
219 module GP_DFFSR(input D, CLK, nSR, output reg Q);
220 parameter [0:0] INIT = 1'bx;
221 parameter [0:0] SRMODE = 1'bx;
222 initial Q = INIT;
223 always @(posedge CLK, negedge nSR) begin
224 if (!nSR)
225 Q <= SRMODE;
226 else
227 Q <= D;
228 end
229 endmodule
230
231 module GP_DFFSRI(input D, CLK, nSR, output reg nQ);
232 parameter [0:0] INIT = 1'bx;
233 parameter [0:0] SRMODE = 1'bx;
234 initial nQ = INIT;
235 always @(posedge CLK, negedge nSR) begin
236 if (!nSR)
237 nQ <= ~SRMODE;
238 else
239 nQ <= ~D;
240 end
241 endmodule
242
243 module GP_EDGEDET(input IN, output reg OUT);
244
245 parameter EDGE_DIRECTION = "RISING";
246 parameter DELAY_STEPS = 1;
247 parameter GLITCH_FILTER = 0;
248
249 //not implemented for simulation
250
251 endmodule
252
253 module GP_IBUF(input IN, output OUT);
254 assign OUT = IN;
255 endmodule
256
257 module GP_IOBUF(input IN, input OE, output OUT, inout IO);
258 assign OUT = IO;
259 assign IO = OE ? IN : 1'bz;
260 endmodule
261
262 module GP_INV(input IN, output OUT);
263 assign OUT = ~IN;
264 endmodule
265
266 module GP_LFOSC(input PWRDN, output reg CLKOUT);
267
268 parameter PWRDN_EN = 0;
269 parameter AUTO_PWRDN = 0;
270 parameter OUT_DIV = 1;
271
272 initial CLKOUT = 0;
273
274 //auto powerdown not implemented for simulation
275 //output dividers not implemented for simulation
276
277 always begin
278 if(PWRDN)
279 CLKOUT = 0;
280 else begin
281 //half period of 1730 Hz
282 #289017;
283 CLKOUT = ~CLKOUT;
284 end
285 end
286
287 endmodule
288
289 module GP_OBUF(input IN, output OUT);
290 assign OUT = IN;
291 endmodule
292
293 module GP_OBUFT(input IN, input OE, output OUT);
294 assign OUT = OE ? IN : 1'bz;
295 endmodule
296
297 module GP_PGA(input wire VIN_P, input wire VIN_N, input wire VIN_SEL, output reg VOUT);
298
299 parameter GAIN = 1;
300 parameter INPUT_MODE = "SINGLE";
301
302 initial VOUT = 0;
303
304 //cannot simulate mixed signal IP
305
306 endmodule
307
308 module GP_PGEN(input wire nRST, input wire CLK, output reg OUT);
309 initial OUT = 0;
310 parameter PATTERN_DATA = 16'h0;
311 parameter PATTERN_LEN = 5'd16;
312
313 reg[3:0] count = 0;
314 always @(posedge CLK) begin
315 if(!nRST)
316 OUT <= PATTERN_DATA[0];
317
318 else begin
319 count <= count + 1;
320 OUT <= PATTERN_DATA[count];
321
322 if( (count + 1) == PATTERN_LEN)
323 count <= 0;
324 end
325 end
326
327 endmodule
328
329 module GP_POR(output reg RST_DONE);
330 parameter POR_TIME = 500;
331
332 initial begin
333 RST_DONE = 0;
334
335 if(POR_TIME == 4)
336 #4000;
337 else if(POR_TIME == 500)
338 #500000;
339 else begin
340 $display("ERROR: bad POR_TIME for GP_POR cell");
341 $finish;
342 end
343
344 RST_DONE = 1;
345
346 end
347
348 endmodule
349
350 module GP_RCOSC(input PWRDN, output reg CLKOUT_HARDIP, output reg CLKOUT_FABRIC);
351
352 parameter PWRDN_EN = 0;
353 parameter AUTO_PWRDN = 0;
354 parameter HARDIP_DIV = 1;
355 parameter FABRIC_DIV = 1;
356 parameter OSC_FREQ = "25k";
357
358 initial CLKOUT_HARDIP = 0;
359 initial CLKOUT_FABRIC = 0;
360
361 //output dividers not implemented for simulation
362 //auto powerdown not implemented for simulation
363
364 always begin
365 if(PWRDN) begin
366 CLKOUT_HARDIP = 0;
367 CLKOUT_FABRIC = 0;
368 end
369 else begin
370
371 if(OSC_FREQ == "25k") begin
372 //half period of 25 kHz
373 #20000;
374 end
375
376 else begin
377 //half period of 2 MHz
378 #250;
379 end
380
381 CLKOUT_HARDIP = ~CLKOUT_HARDIP;
382 CLKOUT_FABRIC = ~CLKOUT_FABRIC;
383 end
384 end
385
386 endmodule
387
388 module GP_RINGOSC(input PWRDN, output reg CLKOUT_HARDIP, output reg CLKOUT_FABRIC);
389
390 parameter PWRDN_EN = 0;
391 parameter AUTO_PWRDN = 0;
392 parameter HARDIP_DIV = 1;
393 parameter FABRIC_DIV = 1;
394
395 initial CLKOUT_HARDIP = 0;
396 initial CLKOUT_FABRIC = 0;
397
398 //output dividers not implemented for simulation
399 //auto powerdown not implemented for simulation
400
401 always begin
402 if(PWRDN) begin
403 CLKOUT_HARDIP = 0;
404 CLKOUT_FABRIC = 0;
405 end
406 else begin
407 //half period of 27 MHz
408 #18.518;
409 CLKOUT_HARDIP = ~CLKOUT_HARDIP;
410 CLKOUT_FABRIC = ~CLKOUT_FABRIC;
411 end
412 end
413
414 endmodule
415
416 module GP_SHREG(input nRST, input CLK, input IN, output OUTA, output OUTB);
417
418 parameter OUTA_TAP = 1;
419 parameter OUTA_INVERT = 0;
420 parameter OUTB_TAP = 1;
421
422 reg[15:0] shreg = 0;
423
424 always @(posedge CLK, negedge nRST) begin
425
426 if(!nRST)
427 shreg = 0;
428
429 else
430 shreg <= {shreg[14:0], IN};
431
432 end
433
434 assign OUTA = (OUTA_INVERT) ? ~shreg[OUTA_TAP - 1] : shreg[OUTA_TAP - 1];
435 assign OUTB = shreg[OUTB_TAP - 1];
436
437 endmodule
438
439 //keep constraint needed to prevent optimization since we have no outputs
440 (* keep *)
441 module GP_SYSRESET(input RST);
442 parameter RESET_MODE = "EDGE";
443 parameter EDGE_SPEED = 4;
444
445 //cannot simulate whole system reset
446
447 endmodule
448
449 module GP_VDD(output OUT);
450 assign OUT = 1;
451 endmodule
452
453 module GP_VREF(input VIN, output reg VOUT);
454 parameter VIN_DIV = 1;
455 parameter VREF = 0;
456 //cannot simulate mixed signal IP
457 endmodule
458
459 module GP_VSS(output OUT);
460 assign OUT = 0;
461 endmodule