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

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [hdl/] [port_icap/] [port_icap_buf.v] - Blame information for rev 9

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
module port_icap_buf (
2
// ICAP Module for PATLPP port interface
3
 
4
        // Inputs:
5
        clk,
6
        rst,
7
        en_wr,                  // Write Module Enable
8
        en_rd,                  // Read Module Enable
9
        in_data,                        // Input Data
10
        in_sof,                 // Input Start of Frame
11
        in_eof,                 // Input End of Frame
12
        in_src_rdy,             // Input Source Ready
13
        out_dst_rdy,    // Output Destination Ready
14
 
15
        // Outputs:
16
        out_data,               // Output Data
17
        out_sof,                        // Output Start of Frame
18
        out_eof,                        // Output End of Frame
19
        out_src_rdy,    // Output Source Ready
20
        in_dst_rdy//,   // Input Destination Ready
21
        //chipscope_data
22
);
23
 
24
// Port mode declarations:
25
        // Inputs:
26
input   clk;
27
input   rst;
28
input   en_wr;
29
input   en_rd;
30
input   [7:0]    in_data;
31
input   in_sof;
32
input   in_eof;
33
input   in_src_rdy;
34
input   out_dst_rdy;
35
 
36
        // Outputs:
37
output  [7:0]    out_data;
38
output  out_sof;
39
output  out_eof;
40
output  out_src_rdy;
41
output  in_dst_rdy;
42
//output        [19:0] chipscope_data;
43
 
44
 
45
// Signals --------------------------------------------------------------------------------
46
//ICAP
47
wire                            icap_en_n;              // ICAP enable
48
wire                            icap_wr_n;              // ICAP write (0: write, 1: read)
49
wire    [7:0]            icap_din;               // ICAP Data In
50
wire    [7:0]            icap_dout;              // ICAP Data Out
51
wire                            icap_busy;              // ICAP Busy
52
//Read FIFO
53
wire                            rfifo_rd_en;    // Read enable
54
wire                            rfifo_wr_en;    // Write enable
55
wire    [7:0]            rfifo_din;              // Data In
56
wire    [7:0]            rfifo_dout;             // Data Out
57
wire                            rfifo_full;             // FIFO Full
58
wire                            rfifo_empty;    // FIFO Empty
59
//Registers
60
reg                             icap_en_r;              // ICAP Enable Register
61
reg                             icap_wr_r;              // ICAP Write Register
62
reg     [7:0]            count_low_r;    // Count low bits
63
reg     [7:0]            count_high_r;   // Count high bits
64
reg     [10:0]   counter;                        // Counter
65
reg                             count_en;               // Counter Enable
66
reg                             can_write;              // Can write to the icap
67
//FSM
68
parameter       [2:0]            IDLE = 3'b000;
69
parameter       [2:0]            S_WRITE = 3'b001;
70
parameter       [2:0]            WRITE = 3'b010;
71
parameter       [2:0]            E_WRITE = 3'b011;
72
parameter       [2:0]            I_READ = 3'b100;
73
parameter       [2:0]            S_READ = 3'b101;
74
parameter       [2:0]            READ = 3'b110;
75
reg     [2:0]            state;                  // Current state
76
reg     [2:0]            next_state;             // Next State
77
 
78
// Instantiations -------------------------------------------------------------------------
79
shiftr_bram the_fifo
80
(
81
        .clk(clk),
82
        .rst(rst),
83
        .en_in(rfifo_wr_en),
84
        .en_out(rfifo_rd_en),
85
        .empty(rfifo_empty),
86
        .full(rfifo_full),
87
        .data_in(rfifo_din),
88
        .data_out(rfifo_dout)
89
);
90
 
91
assign rfifo_wr_en = ((state == READ) && ~icap_wr_r && ~icap_busy) ? 1'b1 : 1'b0;
92
assign rfifo_rd_en = en_rd & out_dst_rdy;
93
assign rfifo_din = icap_dout;
94
 
95
/* V5 Primitive */
96
 ICAP_VIRTEX5 #(
97
        .ICAP_WIDTH("X8")
98
) icap_inst (
99
        .CLK(clk),
100
        .CE(icap_en_n),
101
        .WRITE(icap_wr_n),
102
        .I({icap_din[0], icap_din[1], icap_din[2], icap_din[3], icap_din[4], icap_din[5], icap_din[6], icap_din[7]}),
103
        .BUSY(icap_busy),
104
        .O({icap_dout[0], icap_dout[1], icap_dout[2], icap_dout[3], icap_dout[4], icap_dout[5], icap_dout[6], icap_dout[7]})
105
);
106
/**/
107
 
108
/* V4 Primitive
109
ICAP_VIRTEX4 #(
110
        .ICAP_WIDTH("X8")
111
) icap_inst (
112
        .CLK(clk),
113
        .CE(icap_en_n),
114
        .WRITE(icap_wr_n),
115
        .I({icap_din[0], icap_din[1], icap_din[2], icap_din[3], icap_din[4], icap_din[5], icap_din[6], icap_din[7]}),
116
        .BUSY(icap_busy),
117
        .O({icap_dout[0], icap_dout[1], icap_dout[2], icap_dout[3], icap_dout[4], icap_dout[5], icap_dout[6], icap_dout[7]})
118
);
119
*/
120
 
121
// Test V4 ICAP
122
// icap_virtex4test #(
123
        // .ICAP_DWIDTH(8)
124
// ) v4testicap (
125
        // .clk(clk),
126
        // .Rst(rst),
127
        // .ce(icap_en_n),
128
        // .write(icap_wr_n),
129
        // .i({icap_din[0], icap_din[1], icap_din[2], icap_din[3], icap_din[4], icap_din[5], icap_din[6], icap_din[7]}),
130
        // .busy(icap_busy),
131
        // .o({icap_dout[0], icap_dout[1], icap_dout[2], icap_dout[3], icap_dout[4], icap_dout[5], icap_dout[6], icap_dout[7]})
132
// );
133
 
134
assign icap_en_n = ~icap_en_r;
135
assign icap_wr_n = ~icap_wr_r;
136
assign icap_din = in_data;
137
 
138
// Behavior -------------------------------------------------------------------------------
139
 
140
// Next State
141
always @(en_wr or in_src_rdy or en_rd or counter or in_eof or en_rd or state)
142
begin
143
        case (state)
144
        IDLE: begin
145
                if (en_wr & in_src_rdy)
146
                        next_state <= S_WRITE;
147
                else if (en_rd & in_src_rdy)
148
                        next_state <= I_READ;
149
                else
150
                        next_state <= IDLE;
151
        end
152
        S_WRITE: begin
153
                if (en_wr & in_src_rdy)
154
                        next_state <= WRITE;
155
                else
156
                        next_state <= S_WRITE;
157
        end
158
        WRITE: begin
159
                if (en_wr & in_src_rdy & in_eof)
160
                        next_state <= E_WRITE;
161
                else
162
                        next_state <= WRITE;
163
        end
164
        E_WRITE: begin
165
                next_state <= IDLE;
166
        end
167
        I_READ: begin
168
                 if (en_rd & in_src_rdy)
169
                        next_state <= S_READ;
170
                else
171
                        next_state <= I_READ;
172
        end
173
        S_READ: begin
174
                next_state <= READ;
175
        end
176
        READ: begin
177
                if (counter == 1)
178
                        next_state <= IDLE;
179
                else
180
                        next_state <= READ;
181
        end
182
        default: begin
183
                next_state <= IDLE;
184
        end
185
        endcase
186
end
187
 
188
always @(posedge clk)
189
begin
190
        state <= next_state;
191
end
192
 
193
// Registers
194
always @(posedge clk)
195
begin
196
        if (state == IDLE && en_rd && in_src_rdy)
197
        begin
198
                count_high_r <= in_data;
199
        end
200
        if (state == I_READ && en_rd && in_src_rdy)
201
        begin
202
                count_low_r <= in_data;
203
        end
204
        if (state == S_READ)
205
        begin
206
                counter <= {count_high_r, count_low_r};
207
        end
208
        else if (count_en)
209
        begin
210
                counter <= counter - 1;
211
        end
212
end
213
 
214
// Outputs
215
always @(state or en_wr or in_src_rdy or icap_busy or en_rd)
216
begin
217
        case (state)
218
        IDLE: begin
219
                icap_en_r = 0;
220
                icap_wr_r = 0;
221
                count_en = 0;
222
                can_write = en_rd;
223
        end
224
        S_WRITE: begin
225
                icap_en_r = 0;
226
                icap_wr_r = 1;
227
                count_en = 0;
228
                can_write = 0;
229
        end
230
        WRITE: begin
231
                icap_en_r = en_wr & in_src_rdy;
232
                icap_wr_r = 1;
233
                count_en = 0;
234
                can_write = 1;
235
        end
236
        E_WRITE: begin
237
                icap_en_r = 0;
238
                icap_wr_r = 1;
239
                count_en = 0;
240
                can_write = 0;
241
        end
242
        I_READ: begin
243
                icap_en_r = 0;
244
                icap_wr_r = 0;
245
                count_en = 0;
246
                can_write = 1;
247
        end
248
        S_READ: begin
249
                icap_en_r = 1;
250
                icap_wr_r = 0;
251
                count_en = 0;
252
                can_write = 0;
253
        end
254
        READ: begin
255
                icap_en_r = 1;
256
                icap_wr_r = 0;
257
                count_en = ~icap_busy;
258
                can_write = 0;
259
        end
260
        default: begin
261
                icap_en_r = 0;
262
                icap_wr_r = 0;
263
                count_en = 0;
264
                can_write = 0;
265
        end
266
        endcase
267
end
268
 
269
assign out_data = rfifo_dout;
270
assign out_sof = 0;
271
assign out_eof = 0;
272
assign out_src_rdy = ~rfifo_empty;
273
assign in_dst_rdy = can_write;
274
 
275
 
276
endmodule

powered by: WebSVN 2.1.0

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