OpenCores
URL https://opencores.org/ocsvn/can/can/trunk

Subversion Repositories can

[/] [can/] [tags/] [asyst_3/] [rtl/] [verilog/] [can_fifo.v] - Blame information for rev 35

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

Line No. Rev Author Line
1 11 mohor
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  can_fifo.v                                                  ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the CAN Protocol Controller            ////
7
////  http://www.opencores.org/projects/can/                      ////
8
////                                                              ////
9
////                                                              ////
10
////  Author(s):                                                  ////
11
////       Igor Mohor                                             ////
12
////       igorm@opencores.org                                    ////
13
////                                                              ////
14
////                                                              ////
15
////  All additional information is available in the README.txt   ////
16
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2002, 2003 Authors                             ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43 28 mohor
//// The CAN protocol is developed by Robert Bosch GmbH and       ////
44
//// protected by patents. Anybody who wants to implement this    ////
45
//// CAN IP core on silicon has to obtain a CAN protocol license  ////
46
//// from Bosch.                                                  ////
47
////                                                              ////
48 11 mohor
//////////////////////////////////////////////////////////////////////
49
//
50
// CVS Revision History
51
//
52
// $Log: not supported by cvs2svn $
53 35 mohor
// Revision 1.10  2003/02/11 00:56:06  mohor
54
// Wishbone interface added.
55
//
56 31 mohor
// Revision 1.9  2003/02/09 02:24:33  mohor
57
// Bosch license warning added. Error counters finished. Overload frames
58
// still need to be fixed.
59
//
60 28 mohor
// Revision 1.8  2003/01/31 01:13:38  mohor
61
// backup.
62
//
63 24 mohor
// Revision 1.7  2003/01/17 17:44:31  mohor
64
// Fifo corrected to be synthesizable.
65
//
66 23 mohor
// Revision 1.6  2003/01/15 13:16:47  mohor
67 31 mohor
// When a frame with "remote request" is received, no data is stored
68
// to fifo, just the frame information (identifier, ...). Data length
69
// that is stored is the received data length and not the actual data
70
// length that is stored to fifo.
71 23 mohor
//
72 18 mohor
// Revision 1.5  2003/01/14 17:25:09  mohor
73
// Addresses corrected to decimal values (previously hex).
74
//
75 17 mohor
// Revision 1.4  2003/01/14 12:19:35  mohor
76
// rx_fifo is now working.
77
//
78 16 mohor
// Revision 1.3  2003/01/09 21:54:45  mohor
79
// rx fifo added. Not 100 % verified, yet.
80
//
81 14 mohor
// Revision 1.2  2003/01/09 14:46:58  mohor
82
// Temporary files (backup).
83
//
84 13 mohor
// Revision 1.1  2003/01/08 02:10:55  mohor
85
// Acceptance filter added.
86 11 mohor
//
87
//
88
//
89 13 mohor
//
90 11 mohor
 
91
// synopsys translate_off
92
`include "timescale.v"
93
// synopsys translate_on
94
`include "can_defines.v"
95
 
96
module can_fifo
97
(
98
  clk,
99
  rst,
100
 
101
  wr,
102
 
103
  data_in,
104 14 mohor
  addr,
105 11 mohor
  data_out,
106
 
107
  reset_mode,
108 14 mohor
  release_buffer,
109 35 mohor
  extended_mode,
110
  overrun,
111
  info_empty
112 13 mohor
 
113 11 mohor
);
114
 
115
parameter Tp = 1;
116
 
117
input         clk;
118
input         rst;
119
input         wr;
120
input   [7:0] data_in;
121 14 mohor
input   [7:0] addr;
122 11 mohor
input         reset_mode;
123
input         release_buffer;
124 14 mohor
input         extended_mode;
125 11 mohor
 
126 13 mohor
output  [7:0] data_out;
127 35 mohor
output        overrun;
128
output        info_empty;
129 11 mohor
 
130
 
131
reg     [7:0] fifo [0:63];
132
reg     [5:0] rd_pointer;
133
reg     [5:0] wr_pointer;
134 14 mohor
reg     [5:0] read_address;
135 16 mohor
reg     [3:0] length_info[0:63];
136
reg     [5:0] wr_info_pointer;
137
reg     [5:0] rd_info_pointer;
138
reg           overrun_info[0:63];
139 13 mohor
reg           wr_q;
140
reg     [3:0] len_cnt;
141 16 mohor
reg     [6:0] fifo_cnt;
142 24 mohor
reg     [6:0] info_cnt;
143 16 mohor
reg           latch_overrun;
144 11 mohor
 
145 13 mohor
wire          write_length_info;
146 16 mohor
wire          fifo_empty;
147
wire          fifo_full;
148 24 mohor
wire          info_full;
149 11 mohor
 
150 13 mohor
assign write_length_info = (~wr) & wr_q;
151
 
152
// Delayed write signal
153
always @ (posedge clk or posedge rst)
154
begin
155
  if (rst)
156
    wr_q <= 0;
157
  else if (reset_mode)
158
    wr_q <=#Tp 0;
159
  else
160
    wr_q <=#Tp wr;
161
end
162
 
163
 
164
// length counter
165
always @ (posedge clk or posedge rst)
166
begin
167
  if (rst)
168
    len_cnt <= 0;
169
  else if (reset_mode | write_length_info)
170
    len_cnt <=#Tp 1'b0;
171 16 mohor
  else if (wr & (~fifo_full))
172 13 mohor
    len_cnt <=#Tp len_cnt + 1'b1;
173
end
174
 
175
 
176
// wr_info_pointer
177
always @ (posedge clk or posedge rst)
178
begin
179
  if (rst)
180
    wr_info_pointer <= 0;
181
  else if (reset_mode)
182
    wr_info_pointer <=#Tp 0;
183 24 mohor
  else if (write_length_info & (~info_full))
184 13 mohor
    wr_info_pointer <=#Tp wr_info_pointer + 1'b1;
185
end
186
 
187
 
188 11 mohor
// length_info
189 13 mohor
always @ (posedge clk)
190
begin
191 24 mohor
  if (write_length_info & (~info_full))
192 13 mohor
    length_info[wr_info_pointer] <=#Tp len_cnt;
193
end
194
 
195
 
196 16 mohor
// overrun_info
197
always @ (posedge clk)
198
begin
199 24 mohor
  if (write_length_info & (~info_full))
200 16 mohor
    overrun_info[wr_info_pointer] <=#Tp latch_overrun | (wr & fifo_full);
201
end
202
 
203
 
204 35 mohor
// reading overrun
205
assign overrun = overrun_info[rd_info_pointer];
206 16 mohor
 
207 13 mohor
// rd_info_pointer
208 11 mohor
always @ (posedge clk or posedge rst)
209
begin
210
  if (rst)
211 13 mohor
    rd_info_pointer <= 0;
212 11 mohor
  else if (reset_mode)
213 13 mohor
    rd_info_pointer <=#Tp 0;
214 16 mohor
  else if (release_buffer & (~fifo_empty))
215 13 mohor
    rd_info_pointer <=#Tp rd_info_pointer + 1'b1;
216 11 mohor
end
217
 
218
 
219
// rd_pointer
220
always @ (posedge clk or posedge rst)
221
begin
222
  if (rst)
223
    rd_pointer <= 0;
224 16 mohor
  else if (release_buffer & (~fifo_empty))
225 13 mohor
    rd_pointer <=#Tp rd_pointer + length_info[rd_info_pointer];
226 11 mohor
  else if (reset_mode)
227
    rd_pointer <=#Tp 0;
228
end
229
 
230
 
231
// wr_pointer
232
always @ (posedge clk or posedge rst)
233
begin
234
  if (rst)
235
    wr_pointer <= 0;
236 16 mohor
  else if (wr & (~fifo_full))
237 13 mohor
    wr_pointer <=#Tp wr_pointer + 1'b1;
238 11 mohor
  else if (reset_mode)
239
    wr_pointer <=#Tp 0;
240
end
241
 
242
 
243 16 mohor
// latch_overrun
244
always @ (posedge clk or posedge rst)
245
begin
246
  if (rst)
247
    latch_overrun <= 0;
248
  else if (reset_mode | write_length_info)
249
    latch_overrun <=#Tp 0;
250
  else if (wr & fifo_full)
251
    latch_overrun <=#Tp 1'b1;
252
end
253
 
254
 
255
// Counting data in fifo
256
always @ (posedge clk or posedge rst)
257
begin
258
  if (rst)
259
    fifo_cnt <= 0;
260
  else if (wr & (~release_buffer) & (~fifo_full))
261
    fifo_cnt <=#Tp fifo_cnt + 1'b1;
262
  else if ((~wr) & release_buffer & (~fifo_empty))
263
    fifo_cnt <=#Tp fifo_cnt - length_info[rd_info_pointer];
264
  else if (wr & release_buffer & (~fifo_full) & (~fifo_empty))
265
    fifo_cnt <=#Tp fifo_cnt - length_info[rd_info_pointer] + 1'b1;
266
  else if (reset_mode)
267
    fifo_cnt <=#Tp 0;
268
end
269
 
270
assign fifo_full = fifo_cnt == 64;
271
assign fifo_empty = fifo_cnt == 0;
272
 
273
 
274 24 mohor
// Counting data in length_info and overrun_info fifo
275
always @ (posedge clk or posedge rst)
276
begin
277
  if (rst)
278
    info_cnt <= 0;
279
  else if (write_length_info ^ release_buffer)
280
    begin
281
      if (release_buffer & (~info_empty))
282
        info_cnt <=#Tp info_cnt - 1'b1;
283
      else if (write_length_info & (~info_full))
284
        info_cnt <=#Tp info_cnt + 1'b1;
285
    end
286
end
287
 
288
assign info_full = info_cnt == 64;
289
assign info_empty = info_cnt == 0;
290 16 mohor
 
291 24 mohor
 
292 11 mohor
// writing data to fifo
293 23 mohor
always @ (posedge clk)
294 11 mohor
begin
295 16 mohor
  if (wr & (~fifo_full))
296 11 mohor
    fifo[wr_pointer] <=#Tp data_in;
297
end
298
 
299
 
300
 
301 14 mohor
// Selecting which address will be used for reading data from rx fifo
302
always @ (extended_mode or rd_pointer or addr)
303
begin
304
  if (extended_mode)      // extended mode
305
    begin
306 17 mohor
      read_address <= rd_pointer + (addr - 8'd16);
307 14 mohor
    end
308
  else                    // normal mode
309
    begin
310 17 mohor
      read_address <= rd_pointer + (addr - 8'd20);
311 14 mohor
    end
312
end
313 11 mohor
 
314
 
315 14 mohor
 
316
assign data_out = fifo[read_address];
317
 
318
 
319
 
320
 
321 11 mohor
endmodule

powered by: WebSVN 2.1.0

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