Skip to content

Commit 3995978

Browse files
committedJun 20, 2017
XC2C model: implemented PLA AND array
1 parent e0cd3cc commit 3995978

File tree

2 files changed

+87
-17
lines changed

2 files changed

+87
-17
lines changed
 

Diff for: ‎hdl/xc2c-model/XC2CAndArray.v

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
`default_nettype none
2+
/***********************************************************************************************************************
3+
* Copyright (C) 2016-2017 Andrew Zonenberg and contributors *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General *
6+
* Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) *
7+
* any later version. *
8+
* *
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
10+
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
11+
* more details. *
12+
* *
13+
* You should have received a copy of the GNU Lesser General Public License along with this program; if not, you may *
14+
* find one here: *
15+
* https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt *
16+
* or you may search the http://www.gnu.org website for the version 2.1 license, or you may write to the Free Software *
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
18+
**********************************************************************************************************************/
19+
module XC2CAndArray(zia_in, config_bits, pterm_out);
20+
21+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
22+
// No configuration, all AND arrays are the same.
23+
// Differences in bitstream ordering, if any, are handled by XC2CDevice
24+
25+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
26+
// I/Os
27+
28+
input wire[39:0] zia_in;
29+
input wire[80*56 - 1 : 0] config_bits;
30+
output reg[55:0] pterm_out;
31+
32+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
33+
// Shuffle the config bits back to their proper 2D form
34+
35+
integer nterm;
36+
integer nrow;
37+
integer nin;
38+
39+
reg[79:0] and_config[55:0];
40+
always @(*) begin
41+
for(nterm=0; nterm<56; nterm=nterm+1) begin
42+
for(nin=0; nin<80; nin=nin + 1)
43+
and_config[nterm][nin] <= config_bits[nterm*80 + nin];
44+
end
45+
end
46+
47+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48+
// The actual AND array
49+
50+
//Higher value is X, lower is !X
51+
always @(*) begin
52+
for(nterm=0; nterm<56; nterm = nterm+1) begin
53+
pterm_out[nterm] = 1; //default if no terms selected
54+
55+
//AND in the ZIA stuff
56+
for(nrow=0; nrow<40; nrow=nrow+1) begin
57+
if(!and_config[nterm][nrow*2])
58+
pterm_out[nterm] = pterm_out[nterm] & zia_in[nrow];
59+
if(!and_config[nterm][nrow*2 + 1])
60+
pterm_out[nterm] = pterm_out[nterm] & !zia_in[nrow];
61+
end
62+
end
63+
end
64+
65+
endmodule

Diff for: ‎hdl/xc2c-model/XC2CDevice.v

+22-17
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ module XC2CDevice(
168168
//TODO: pipeline this or are we OK in one cycle?
169169
//If we go multicycle, how do we handle this with no clock? Real chip is self-timed internally
170170
if(config_erase) begin
171-
for(i=0; i<MEM_DEPTH; i=i+1)
172-
ram_bitstream[i] <= {SHREG_WIDTH{1'b1}};
171+
for(row=0; row<MEM_DEPTH; row=row+1)
172+
ram_bitstream[row] <= {SHREG_WIDTH{1'b1}};
173173
end
174174

175175
end
@@ -256,8 +256,8 @@ module XC2CDevice(
256256
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
257257
// PLA AND array
258258

259-
reg[56*80-1:0] left_and_config;
260-
reg[56*80-1:0] right_and_config;
259+
reg[80*56-1:0] left_and_config;
260+
reg[80*56-1:0] right_and_config;
261261

262262
wire[55:0] left_pterms;
263263
wire[55:0] right_pterms;
@@ -277,24 +277,33 @@ module XC2CDevice(
277277
);
278278

279279
//Hook up the config bits
280+
integer nterm;
280281
always @(*) begin
281282

282283
for(row=0; row<40; row=row+1) begin
283284

284285
//We have stuff at the top and bottom of array, with OR array in the middle
285-
//Left side: 249:138
286-
//Right side: 121:10 (mirrored)
286+
//Each row is two bits from PT0, two from PT1, two from PT2, etc
287+
288+
//Right side: 249:138 (mirrored)
289+
//Left side: 121:10
287290
if(row >= 20) begin
288-
for(nbit=0; nbit<112; nbit=nbit+1) begin
289-
right_and_config[row*112 + nbit] <= ram_bitstream[row-8][138 + nbit];
290-
left_and_config[row*112 + nbit] <= ram_bitstream[row-8][121 - nbit];
291+
for(nterm=0; nterm<56; nterm=nterm+1) begin
292+
right_and_config[nterm*80 + row*2 + 0] <= ram_bitstream[row-8][249 - nterm*2 - 1];
293+
right_and_config[nterm*80 + row*2 + 1] <= ram_bitstream[row-8][249 - nterm*2 - 0];
294+
295+
left_and_config[nterm*80 + row*2 + 0] <= ram_bitstream[row-8][10 + nterm*2 + 0];
296+
left_and_config[nterm*80 + row*2 + 1] <= ram_bitstream[row-8][10 + nterm*2 + 1];
291297
end
292298
end
293299

294300
else begin
295-
for(nbit=0; nbit<112; nbit=nbit+1) begin
296-
right_and_config[row*112 + nbit] <= ram_bitstream[row][138 + nbit];
297-
left_and_config[row*112 + nbit] <= ram_bitstream[row][121 - nbit];
301+
for(nterm=0; nterm<56; nterm=nterm+1) begin
302+
right_and_config[nterm*80 + row*2 + 0] <= ram_bitstream[row][249 - nterm*2 - 1];
303+
right_and_config[nterm*80 + row*2 + 1] <= ram_bitstream[row][249 - nterm*2 - 0];
304+
305+
left_and_config[nterm*80 + row*2 + 0] <= ram_bitstream[row][10 + nterm*2 + 0];
306+
left_and_config[nterm*80 + row*2 + 1] <= ram_bitstream[row][10 + nterm*2 + 1];
298307
end
299308
end
300309

@@ -313,11 +322,7 @@ module XC2CDevice(
313322
//Drive all unused outputs to 0, then hook up our outputs
314323
//Should be X, !X, X, X
315324
assign iob_out[31:7] = 25'h0;
316-
//assign iob_out[6:3] = {right_pterms[19], right_pterms[22], right_pterms[25], right_pterms[28]};
317-
assign iob_out[6] = &right_pterms;
318-
assign iob_out[5] = &left_pterms;
319-
assign iob_out[4] = &left_and_config[19*80 +: 80];
320-
assign iob_out[3] = &right_and_config[19*80 +: 80];
325+
assign iob_out[6:3] = {right_pterms[19], right_pterms[22], right_pterms[25], right_pterms[28]};
321326
assign iob_out[2:0] = 3'h0;
322327

323328
endmodule

0 commit comments

Comments
 (0)
Please sign in to comment.