b7dbe81a272c6c73dc30cd7330d1d9edbb3f2f12
[yosys.git] / techlibs / greenpak4 / cells_sim.v
1 module GP_2LUT(input IN0, IN1, output OUT);
2 parameter [3:0] INIT = 0;
3 assign OUT = INIT[{IN1, IN0}];
4 endmodule
5
6 module GP_3LUT(input IN0, IN1, IN2, output OUT);
7 parameter [7:0] INIT = 0;
8 assign OUT = INIT[{IN2, IN1, IN0}];
9 endmodule
10
11 module GP_4LUT(input IN0, IN1, IN2, IN3, output OUT);
12 parameter [15:0] INIT = 0;
13 assign OUT = INIT[{IN3, IN2, IN1, IN0}];
14 endmodule
15
16 module GP_ACMP(input wire PWREN, input wire VIN, input wire VREF, output reg OUT);
17
18 parameter BANDWIDTH = "HIGH";
19 parameter VIN_ATTEN = 1;
20 parameter VIN_ISRC_EN = 0;
21 parameter HYSTERESIS = 0;
22
23 initial OUT = 0;
24
25 //cannot simulate mixed signal IP
26
27 endmodule
28
29 module GP_BANDGAP(output reg OK, output reg VOUT);
30 parameter AUTO_PWRDN = 1;
31 parameter CHOPPER_EN = 1;
32 parameter OUT_DELAY = 100;
33
34 //cannot simulate mixed signal IP
35
36 endmodule
37
38 module GP_COUNT8(input CLK, input wire RST, output reg OUT);
39
40 parameter RESET_MODE = "RISING";
41
42 parameter COUNT_TO = 8'h1;
43 parameter CLKIN_DIVIDE = 1;
44
45 //more complex hard IP blocks are not supported for simulation yet
46
47 reg[7:0] count = COUNT_TO;
48
49 //Combinatorially output whenever we wrap low
50 always @(*) begin
51 OUT <= (count == 8'h0);
52 end
53
54 //POR or SYSRST reset value is COUNT_TO. Datasheet is unclear but conversations w/ Silego confirm.
55 //Runtime reset value is clearly 0 except in count/FSM cells where it's configurable but we leave at 0 for now.
56 //Datasheet seems to indicate that reset is asynchronous, but for now we model as sync due to Yosys issues...
57 always @(posedge CLK) begin
58
59 count <= count - 1'd1;
60
61 if(count == 0)
62 count <= COUNT_MAX;
63
64 /*
65 if((RESET_MODE == "RISING") && RST)
66 count <= 0;
67 if((RESET_MODE == "FALLING") && !RST)
68 count <= 0;
69 if((RESET_MODE == "BOTH") && RST)
70 count <= 0;
71 */
72 end
73
74 endmodule
75
76 module GP_COUNT14(input CLK, input wire RST, output reg OUT);
77
78 parameter RESET_MODE = "RISING";
79
80 parameter COUNT_TO = 14'h1;
81 parameter CLKIN_DIVIDE = 1;
82
83 //more complex hard IP blocks are not supported for simulation yet
84
85 endmodule
86
87 module GP_DFF(input D, CLK, output reg Q);
88 parameter [0:0] INIT = 1'bx;
89 initial Q = INIT;
90 always @(posedge CLK) begin
91 Q <= D;
92 end
93 endmodule
94
95 module GP_DFFR(input D, CLK, nRST, output reg Q);
96 parameter [0:0] INIT = 1'bx;
97 initial Q = INIT;
98 always @(posedge CLK, negedge nRST) begin
99 if (!nRST)
100 Q <= 1'b0;
101 else
102 Q <= D;
103 end
104 endmodule
105
106 module GP_DFFS(input D, CLK, nSET, output reg Q);
107 parameter [0:0] INIT = 1'bx;
108 initial Q = INIT;
109 always @(posedge CLK, negedge nSET) begin
110 if (!nSET)
111 Q <= 1'b1;
112 else
113 Q <= D;
114 end
115 endmodule
116
117 module GP_DFFSR(input D, CLK, nSR, output reg Q);
118 parameter [0:0] INIT = 1'bx;
119 parameter [0:0] SRMODE = 1'bx;
120 initial Q = INIT;
121 always @(posedge CLK, negedge nSR) begin
122 if (!nSR)
123 Q <= SRMODE;
124 else
125 Q <= D;
126 end
127 endmodule
128
129 module GP_INV(input IN, output OUT);
130 assign OUT = ~IN;
131 endmodule
132
133 module GP_LFOSC(input PWRDN, output reg CLKOUT);
134
135 parameter PWRDN_EN = 0;
136 parameter AUTO_PWRDN = 0;
137 parameter OUT_DIV = 1;
138
139 initial CLKOUT = 0;
140
141 //auto powerdown not implemented for simulation
142 //output dividers not implemented for simulation
143
144 always begin
145 if(PWRDN)
146 CLKOUT = 0;
147 else begin
148 //half period of 1730 Hz
149 #289017;
150 CLKOUT = ~CLKOUT;
151 end
152 end
153
154 endmodule
155
156 module GP_PGA(input wire VIN_P, input wire VIN_N, input wire VIN_SEL, output reg VOUT);
157
158 parameter GAIN = 1;
159 parameter INPUT_MODE = "SINGLE";
160
161 initial VOUT = 0;
162
163 //cannot simulate mixed signal IP
164
165 endmodule
166
167 module GP_POR(output reg RST_DONE);
168 parameter POR_TIME = 500;
169
170 initial begin
171 RST_DONE = 0;
172
173 if(POR_TIME == 4)
174 #4000;
175 else if(POR_TIME == 500)
176 #500000;
177 else begin
178 $display("ERROR: bad POR_TIME for GP_POR cell");
179 $finish;
180 end
181
182 RST_DONE = 1;
183
184 end
185
186 endmodule
187
188 module GP_RCOSC(input PWRDN, output reg CLKOUT_PREDIV, output reg CLKOUT_FABRIC);
189
190 parameter PWRDN_EN = 0;
191 parameter AUTO_PWRDN = 0;
192 parameter PRE_DIV = 1;
193 parameter FABRIC_DIV = 1;
194 parameter OSC_FREQ = "25k";
195
196 initial CLKOUT_PREDIV = 0;
197 initial CLKOUT_FABRIC = 0;
198
199 //output dividers not implemented for simulation
200 //auto powerdown not implemented for simulation
201
202 always begin
203 if(PWRDN) begin
204 CLKOUT_PREDIV = 0;
205 CLKOUT_FABRIC = 0;
206 end
207 else begin
208
209 if(OSC_FREQ == "25k") begin
210 //half period of 25 kHz
211 #20000;
212 end
213
214 else begin
215 //half period of 2 MHz
216 #250;
217 end
218
219 CLKOUT_PREDIV = ~CLKOUT_PREDIV;
220 CLKOUT_FABRIC = ~CLKOUT_FABRIC;
221 end
222 end
223
224 endmodule
225
226 module GP_RINGOSC(input PWRDN, output reg CLKOUT_PREDIV, output reg CLKOUT_FABRIC);
227
228 parameter PWRDN_EN = 0;
229 parameter AUTO_PWRDN = 0;
230 parameter PRE_DIV = 1;
231 parameter FABRIC_DIV = 1;
232
233 initial CLKOUT_PREDIV = 0;
234 initial CLKOUT_FABRIC = 0;
235
236 //output dividers not implemented for simulation
237 //auto powerdown not implemented for simulation
238
239 always begin
240 if(PWRDN) begin
241 CLKOUT_PREDIV = 0;
242 CLKOUT_FABRIC = 0;
243 end
244 else begin
245 //half period of 27 MHz
246 #18.518;
247 CLKOUT_PREDIV = ~CLKOUT_PREDIV;
248 CLKOUT_FABRIC = ~CLKOUT_FABRIC;
249 end
250 end
251
252 endmodule
253
254 module GP_SHREG(input nRST, input CLK, input IN, output OUTA, output OUTB);
255
256 parameter OUTA_DELAY = 1;
257 parameter OUTA_INVERT = 0;
258 parameter OUTB_DELAY = 1;
259
260 reg[15:0] shreg = 0;
261
262 always @(posedge clk, negedge nRST) begin
263
264 if(!nRST)
265 shreg = 0;
266
267 else
268 shreg <= {shreg[14:0], IN};
269
270 end
271
272 assign OUTA = (OUTA_INVERT) ? ~shreg[OUTA_DELAY - 1] : shreg[OUTA_DELAY - 1];
273 assign OUTB = shreg[OUTB_DELAY - 1];
274
275 endmodule
276
277 //keep constraint needed to prevent optimization since we have no outputs
278 (* keep *)
279 module GP_SYSRESET(input RST);
280 parameter RESET_MODE = "RISING";
281
282 //cannot simulate whole system reset
283
284 endmodule
285
286 module GP_VDD(output OUT);
287 assign OUT = 1;
288 endmodule
289
290 module GP_VREF(input VIN, output reg VOUT);
291 parameter VIN_DIV = 1;
292 parameter VREF = 0;
293 //cannot simulate mixed signal IP
294 endmodule
295
296 module GP_VSS(output OUT);
297 assign OUT = 0;
298 endmodule