-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtop.v
More file actions
executable file
·275 lines (193 loc) · 4.98 KB
/
top.v
File metadata and controls
executable file
·275 lines (193 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
module top
#(parameter numLanes = 4)
(UART_RXD, UART_TXD, CLOCK_50, KEY, SW);
// Declaration of inputs and outputs
input UART_RXD, CLOCK_50;
input [0:0] KEY;
input [1:0] SW;
output UART_TXD;
parameter RAM_SIZE = 128;
parameter ADDR_BITS = 7;
wire ready;
reg start = 0;
reg nextStart = 0;
wire [7:0] dataOut; // data that was read
reg [ADDR_BITS - 1:0] addr = 0; // address we are accessing
reg [ADDR_BITS - 1:0] nextAddr = 5'b11111;
reg writeEnable = 0;
reg nextWriteEnable = 0;
reg [7:0] dataIn; // data that was written to
reg [7:0] nextDataIn;
// State declarations
parameter IDLE = 0;
parameter READ = 1;
parameter WRITE = 2;
parameter INC = 3;
parameter LOAD_DATA_DISTRIBUTER = 4;
parameter SEND_DATA_DISTRIBUTER = 5;
parameter PREPARE_HISTOGRAM = 6;
parameter HISTOGRAM_INC = 7;
parameter COMPUTE_HIST_SUM = 8;
reg [0:3] currState = IDLE;
reg [0:3] nextState = IDLE;
wire [31:0] image_data_out;
reg [13:0] image_data_addr = 0;
wire image_received;
reg histogram_write_enable;
reg next_histogram_write_enable;
reg [2:0] histogram_write_address = 0;
wire [15:0] histogram_data;
reg histogram_transmit = 0;
reg resetm;
reg [numLanes:0] i; // incrementer for a for loop
reg [numLanes:0] histSumCounter = 0;
reg [numLanes:0] nextHistSumCounter = 0;
reg [12:0] next_image_data_addr = 0; //changed from 13 to 14 bits.
Data_Distributer dataDistributer(.clk(CLOCK_50),
.reset(~KEY[0]), // Active HIGH!!
// Signals for reading image data
.image_data_out(image_data_out),
.image_data_address(image_data_addr[11:0]),
//input wire [11:0] image_data_address,
.image_received(image_received),
// Signals for storing Histogram data
.histogram_write_enable(histogram_write_enable),
.histogram_write_address(histAddr),
//input wire [2:0] histogram_write_address,
.histogram_data(histSum),
.histogram_transmit(histogram_transmit),
// UART SIGNALS
.UART_TX(UART_TXD), // <---------------- May need these signals
.UART_RX(UART_RXD));
wire [15:0] histOut [numLanes];
reg [15:0] histSum = 0;
reg [15:0] nextHistSum = 0;
reg [3:0] histAddr = 0;
reg[3:0] nextHistAddr = 0;
reg enable = 0;
reg nextEnable = 0;
reg [13:0] counter = 0;
reg [13:0] nextCounter = 0;
reg [2:0] count;
genvar j;
generate
for (j = 0; j < numLanes; j = j + 1) begin : HIST
Histogram H(CLOCK_50, image_data_out[(j + 1) * 8 - 1: j * 8], histAddr, ~KEY[0], enable, histOut[j], resetm);
end
endgenerate
/*
Histogram hist1(CLOCK_50, image_data_out[31:24], histAddr, ~KEY[0], enable, histOut1, resetm);
Histogram hist2(CLOCK_50, image_data_out[23:16], histAddr, ~KEY[0], enable, histOut2, resetm);
Histogram hist3(CLOCK_50, image_data_out[15:8], histAddr, ~KEY[0], enable, histOut3, resetm);
Histogram hist4(CLOCK_50, image_data_out[7:0], histAddr, ~KEY[0], enable, histOut4, resetm);
*/
//assign histogram_data = histOut1 + histOut2 + histOut3 + histOut4;
// Sequential part of FSM
always @ (posedge CLOCK_50, negedge KEY[0])
begin
if(~KEY[0])
currState <= IDLE;
else if(CLOCK_50)
begin
currState <= nextState;
writeEnable <= nextWriteEnable;
start <= nextStart;
dataIn <= nextDataIn;
addr <= nextAddr;
enable <= nextEnable;
histAddr <= nextHistAddr;
histogram_write_enable <= next_histogram_write_enable;
image_data_addr <= next_image_data_addr;
histSum <= nextHistSum;
histSumCounter <= nextHistSumCounter;
end
end
always @(*)
begin
nextState = currState;
nextAddr = addr;
nextWriteEnable = writeEnable;
nextStart = start;
nextDataIn = 0;
nextHistAddr = histAddr;
nextEnable = enable;
next_histogram_write_enable = histogram_write_enable;
next_image_data_addr = image_data_addr;
histogram_transmit = 0;
resetm = 0;
case(currState)
IDLE:
begin
resetm = 1;
nextAddr = 0;
nextWriteEnable = 0;
nextStart = 0;
next_histogram_write_enable = 0;
histogram_transmit = 0;
i = 0;
nextCounter = 0;
//histSum = 0;
/*
if(ready)
begin
nextState = READ;
end
*/
if(image_received)
begin
nextState = SEND_DATA_DISTRIBUTER;
//nextEnable = 1;
resetm = 0;
end
end
SEND_DATA_DISTRIBUTER:
begin
if(image_data_addr == 4096)
begin
nextState = COMPUTE_HIST_SUM;
nextHistAddr = 0;
next_histogram_write_enable = 0;
nextEnable = 0;
count = 0;
end
else begin
nextEnable = 1;
next_image_data_addr = image_data_addr + 1;
nextState = SEND_DATA_DISTRIBUTER;
end
end
PREPARE_HISTOGRAM:
begin
nextEnable = 0;
//histSum= histOut[0] + histOut[1] +histOut[2] + histOut[3];
if(histAddr == 8)
begin
histogram_transmit = 1;
nextState = IDLE;
next_histogram_write_enable = 0;
end
else begin
next_histogram_write_enable = 1;
nextHistSumCounter = 0;
nextState = COMPUTE_HIST_SUM;
nextHistAddr = histAddr + 1;
end
//end
COPMUTE_HIST_SUM:
begin
if(histSumCounter < numLanes)
begin
nextHistSum = histSum + histOut[i];
nextState = COMPUTE_HIST_SUM;
nextHistSumCounter = histSumCounter + 1;
end
else
begin
nextState = PREPARE_HISTOGRAM;
next_histogram_write_enable = 1;
end
end
end
endcase
end
endmodule