OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [hdl/] [md5/] [channel5_md5.v] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 peteralieb
// MD5 FCP Channel Interface
2
 
3
`timescale 1ns/100ps
4
 
5
module channel5(
6
        input                                   clk,
7
        input                                   rst,
8
        input                                   wen,
9
        input                                   ren,
10
        input                                   in_sof,
11
        input                                   in_eof,
12
        input                                   in_src_rdy,
13
        output                          in_dst_rdy,
14
        input           [7:0]            in_data,
15
 
16
        output                          out_sof,
17
        output                          out_eof,
18
        input                                   out_dst_rdy,
19
        output                          out_src_rdy,
20
        output  [7:0]            out_data
21
);
22
 
23
 
24
//------------------------------------------------------------------
25
//---------------- Functions
26
//------------------------------------------------------------------
27
 
28
function [31:0] littleEndianize;
29
        input [31:0] in_word;
30
        begin
31
                littleEndianize[7:0] = in_word[31:24];
32
                littleEndianize[15:8] = in_word[23:16];
33
                littleEndianize[23:16] = in_word[15:8];
34
                littleEndianize[31:24] = in_word[7:0];
35
        end
36
endfunction
37
 
38
//------------------------------------------------------------------
39
//---------------- MD5 Signals 
40
//------------------------------------------------------------------
41
 
42
wire    [127:0]  md5_data_i;
43
wire    [127:0]  md5_data_o;
44
wire                            md5_load_i;
45
wire                            md5_newtext_i;
46
wire                            md5_ready_o;
47
wire                            md5_reset_n;
48
 
49
//------------------------------------------------------------------
50
//---------------- Control Signals
51
//------------------------------------------------------------------
52
 
53
wire                            load_next_byte;
54
wire                            in_byte_en;
55
wire                            out_byte_en;
56
reg     [127:0]  in_word_reg;
57
reg     [127:0]  out_word_reg;
58
wire                            ready;
59
 
60
 
61
//------------------------------------------------------------------
62
//---------------- Write FSM Signals
63
//------------------------------------------------------------------
64
 
65
reg rdy, wload;
66
reg [3:0]        wcount;
67
reg wcount_en, newtext_en, wcount_rst;
68
reg [1:0]        wrdcount;
69
reg                     wrdcount_en;
70
reg [2:0] wfsm_state;
71
reg [2:0] wnext_state;
72
 
73
`define INIT                    3'd0
74
`define NEW_TEXT                3'd1
75
`define LOAD_WORD               3'd2
76
`define FILL_WORD               3'd3
77
`define LOAD_MD5                3'd4
78
 
79
//------------------------------------------------------------------
80
//---------------- Read FSM Signals
81
//------------------------------------------------------------------
82
 
83
reg [3:0]        rcount;
84
reg rcount_rst, rcount_dec, res_byte_en, rload;
85
reg [1:0]        rfsm_state;
86
reg [1:0]        rnext_state;
87
 
88
`define WAIT_READ               2'd0
89
`define RDY_READ                2'd1
90
`define READING         2'd2
91
 
92
//------------------------------------------------------------------
93
//---------------- Read FSM
94
//------------------------------------------------------------------
95
 
96
assign out_byte_en = ren & out_dst_rdy;
97
 
98
// Next State
99
always @(rfsm_state or ready or rcount or out_byte_en)
100
begin
101
        case (rfsm_state)
102
        `WAIT_READ: rnext_state = ready ? `RDY_READ : `WAIT_READ;
103
        `RDY_READ: rnext_state = out_byte_en ? `READING : `RDY_READ;
104
        `READING: rnext_state = (rcount == 0 && out_byte_en == 1) ? `WAIT_READ : `READING;
105
        default: rnext_state = `WAIT_READ;
106
        endcase
107
end
108
 
109
always @(posedge clk or posedge rst)
110
begin
111
        if (rst) rfsm_state <= 0;
112
        else rfsm_state <= rnext_state;
113
end
114
 
115
// Mealy Outputs
116
always @(rfsm_state or ready or out_byte_en or rcount)
117
begin
118
        rcount_dec = 0;
119
        rcount_rst = 0;
120
        rload = 0;
121
        case (rfsm_state)
122
        `WAIT_READ: begin
123
                if (ready)
124
                begin
125
                        rload = 1;
126
                        rcount_rst = 1;
127
                end
128
        end
129
        `RDY_READ: begin
130
                if (out_byte_en) rcount_dec = 1;
131
        end
132
        `READING: begin
133
                if (rcount > 0 && out_byte_en == 1) rcount_dec = 1;
134
        end
135
        endcase
136
end
137
 
138
// Moore Output
139
always @(rfsm_state)
140
begin
141
        case (rfsm_state)
142
        `WAIT_READ: res_byte_en = 0;
143
        `RDY_READ: res_byte_en = 1;
144
        `READING: res_byte_en = 1;
145
        default: res_byte_en = 0;
146
        endcase
147
end
148
 
149
//------------------------------------------------------------------
150
//---------------- Write FSM
151
//------------------------------------------------------------------
152
 
153
assign load_next_byte = wcount_en;
154
assign in_byte_en = wen & in_src_rdy;
155
 
156
// Next State
157
always @(wfsm_state or in_byte_en or wcount or ready)
158
begin
159
        case (wfsm_state)
160
        `INIT: wnext_state = in_byte_en ? `NEW_TEXT : `INIT;
161
        `NEW_TEXT: wnext_state = (in_byte_en == 1) ? `LOAD_WORD : `NEW_TEXT;
162
        `LOAD_WORD: wnext_state = (in_byte_en == 1 && wcount == 15) ? `FILL_WORD : `LOAD_WORD;
163
        `FILL_WORD: wnext_state = `LOAD_MD5;
164
        `LOAD_MD5: wnext_state = (ready == 1 || wrdcount != 0) ? `INIT : `LOAD_MD5;
165
        default: wnext_state = `INIT;
166
        endcase
167
end
168
 
169
always @(posedge clk or posedge rst)
170
begin
171
        if (rst) wfsm_state <= 0;
172
        else wfsm_state <= wnext_state;
173
end
174
 
175
// Moore Outputs
176
always @(wfsm_state)
177
begin
178
        case (wfsm_state)
179
        `INIT: begin
180
                rdy = 0;
181
                wload = 0;
182
                wrdcount_en = 0;
183
        end
184
        `NEW_TEXT: begin
185
                rdy = 1;
186
                wload = 0;
187
                wrdcount_en = 0;
188
        end
189
        `LOAD_WORD: begin
190
                rdy = 1;
191
                wload = 0;
192
                wrdcount_en = 0;
193
        end
194
        `FILL_WORD: begin
195
                rdy = 0;
196
                wload = 1;
197
                wrdcount_en = 1;
198
        end
199
        `LOAD_MD5: begin
200
                rdy = 0;
201
                wload = 0;
202
                wrdcount_en = 0;
203
        end
204
        endcase
205
end
206
 
207
// Mealy Outputs
208
always @(wfsm_state or in_byte_en or wcount or ready)
209
begin
210
        wcount_en = 0;
211
        wcount_rst = 0;
212
        newtext_en = 0;
213
        case (wfsm_state)
214
        `INIT: begin
215
                if (in_byte_en) begin
216
                        wcount_en = 0;
217
                        newtext_en = 1;
218
                end
219
        end
220
        `NEW_TEXT: begin
221
                if (in_byte_en) begin
222
                        wcount_en = 1;
223
                end
224
        end
225
        `LOAD_WORD: begin
226
                if (in_byte_en == 1 && wcount <= 15) begin
227
                        wcount_en = 1;
228
                end
229
        end
230
        `LOAD_MD5: begin
231
                wcount_rst = 1;
232
        end
233
        endcase
234
end
235
 
236
//------------------------------------------------------------------
237
//---------------- wcount Register
238
//------------------------------------------------------------------
239
wire rst_or_wcount_rst;
240
assign rst_or_wcount_rst = rst | wcount_rst;
241
 
242
always @(posedge clk or posedge rst_or_wcount_rst)
243
begin
244
        if (rst_or_wcount_rst) wcount <= 0;
245
        else if (wcount_en) wcount <= wcount + 1;
246
end
247
 
248
//------------------------------------------------------------------
249
//---------------- wrdcount Register
250
//------------------------------------------------------------------
251
 
252
always @(posedge clk or posedge rst)
253
begin
254
        if (rst) wrdcount <= 0;
255
        else if (wrdcount_en) wrdcount <= wrdcount + 1;
256
end
257
 
258
//------------------------------------------------------------------
259
//---------------- rcount Register
260
//------------------------------------------------------------------
261
wire rst_or_rcount_rst;
262
assign rst_or_rcount_rst = rst | rcount_rst;
263
 
264
always @(posedge clk or posedge rst_or_rcount_rst)
265
begin
266
        if (rst_or_rcount_rst) rcount <= 4'hF;
267
        else if (rcount_dec) rcount <= rcount - 1;
268
end
269
 
270
//------------------------------------------------------------------
271
//---------------- In Word Register
272
//------------------------------------------------------------------
273
 
274
always @(posedge clk or posedge rst)
275
begin
276
        if (rst) in_word_reg <= 0;
277
        else if (load_next_byte)
278
        begin
279
                in_word_reg[7:0]         <= in_data;
280
                in_word_reg[15:8]               <= in_word_reg[7:0];
281
                in_word_reg[23:16]      <= in_word_reg[15:8];
282
                in_word_reg[31:24]      <= in_word_reg[23:16];
283
                in_word_reg[39:32]      <= in_word_reg[31:24];
284
                in_word_reg[47:40]      <= in_word_reg[39:32];
285
                in_word_reg[55:48]      <= in_word_reg[47:40];
286
                in_word_reg[63:56]      <= in_word_reg[55:48];
287
                in_word_reg[71:64]      <= in_word_reg[63:56];
288
                in_word_reg[79:72]      <= in_word_reg[71:64];
289
                in_word_reg[87:80]      <= in_word_reg[79:72];
290
                in_word_reg[95:88]      <= in_word_reg[87:80];
291
                in_word_reg[103:96]     <= in_word_reg[95:88];
292
                in_word_reg[111:104]    <= in_word_reg[103:96];
293
                in_word_reg[119:112]    <= in_word_reg[111:104];
294
                in_word_reg[127:120]    <= in_word_reg[119:112];
295
        end
296
end
297
 
298
//------------------------------------------------------------------
299
//---------------- Out Word Register
300
//------------------------------------------------------------------
301
 
302
always @(posedge clk or posedge rst)
303
begin
304
        if (rst) out_word_reg <= 0;
305
        else if (rload) out_word_reg <= { littleEndianize(md5_data_o[127:96]), littleEndianize(md5_data_o[95:64]), littleEndianize(md5_data_o[63:32]), littleEndianize(md5_data_o[31:0]) };
306
        else if (res_byte_en & out_byte_en)
307
        begin
308
                out_word_reg[7:0]                        <= 0;
309
                out_word_reg[15:8]              <= out_word_reg[7:0];
310
                out_word_reg[23:16]             <= out_word_reg[15:8];
311
                out_word_reg[31:24]             <= out_word_reg[23:16];
312
                out_word_reg[39:32]             <= out_word_reg[31:24];
313
                out_word_reg[47:40]             <= out_word_reg[39:32];
314
                out_word_reg[55:48]             <= out_word_reg[47:40];
315
                out_word_reg[63:56]             <= out_word_reg[55:48];
316
                out_word_reg[71:64]             <= out_word_reg[63:56];
317
                out_word_reg[79:72]             <= out_word_reg[71:64];
318
                out_word_reg[87:80]             <= out_word_reg[79:72];
319
                out_word_reg[95:88]             <= out_word_reg[87:80];
320
                out_word_reg[103:96]            <= out_word_reg[95:88];
321
                out_word_reg[111:104]   <= out_word_reg[103:96];
322
                out_word_reg[119:112]   <= out_word_reg[111:104];
323
                out_word_reg[127:120]   <= out_word_reg[119:112];
324
        end
325
end
326
 
327
//------------------------------------------------------------------
328
//---------------- MD5 Instance
329
//------------------------------------------------------------------
330
 
331
assign md5_data_i = { littleEndianize(in_word_reg[127:96]), littleEndianize(in_word_reg[95:64]), littleEndianize(in_word_reg[63:32]), littleEndianize(in_word_reg[31:0]) };
332
assign md5_newtext_i = newtext_en & in_sof;
333
assign md5_load_i = wload;
334
assign md5_reset_n = ~rst;
335
assign ready = md5_ready_o;
336
 
337
md5 themd5 (
338
        .clk(clk),
339
        .reset(md5_reset_n),
340
        .load_i(md5_load_i),
341
        .ready_o(md5_ready_o),
342
        .newtext_i(md5_newtext_i),
343
        .data_i(md5_data_i),
344
        .data_o(md5_data_o)
345
);
346
 
347
//------------------------------------------------------------------
348
//---------------- Output Logic
349
//------------------------------------------------------------------
350
 
351
assign in_dst_rdy = rdy;
352
assign out_data = out_word_reg[127:120];
353
assign out_sof = (rfsm_state == `RDY_READ) ? 1 : 0;
354
assign out_eof = (rfsm_state == `READING && rcount == 0) ? 1 : 0;
355
assign out_src_rdy = res_byte_en;
356
 
357
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.