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

Subversion Repositories rio

[/] [rio/] [branches/] [parallelSymbols/] [rtl/] [vhdl/] [RioPacketBuffer.vhd] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 magro732
-------------------------------------------------------------------------------
2
-- 
3
-- RapidIO IP Library Core
4
-- 
5
-- This file is part of the RapidIO IP library project
6
-- http://www.opencores.org/cores/rio/
7
-- 
8
-- Description
9
-- Containing RapidIO packet buffering functionallity. Two different entities
10
-- are implemented, one with transmission window support and one without.
11
-- 
12
-- To Do:
13
-- -
14
-- 
15
-- Author(s): 
16
-- - Magnus Rosenius, magro732@opencores.org 
17
-- 
18
-------------------------------------------------------------------------------
19
-- 
20
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
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
-------------------------------------------------------------------------------
44
 
45
 
46
-------------------------------------------------------------------------------
47
-- RioPacketBuffer
48
-------------------------------------------------------------------------------
49
 
50
library ieee;
51
use ieee.std_logic_1164.all;
52
use ieee.numeric_std.all;
53
use work.rio_common.all;
54
 
55
 
56
-------------------------------------------------------------------------------
57
-- Entity for RioPacketBuffer.
58
-------------------------------------------------------------------------------
59
entity RioPacketBuffer is
60 7 magro732
  generic(
61
    SIZE_ADDRESS_WIDTH : natural := 6;
62
    CONTENT_ADDRESS_WIDTH : natural := 8);
63 3 magro732
  port(
64
    clk : in std_logic;
65
    areset_n : in std_logic;
66
 
67
    inboundWriteFrameFull_o : out std_logic;
68
    inboundWriteFrame_i : in std_logic;
69
    inboundWriteFrameAbort_i : in std_logic;
70
    inboundWriteContent_i : in std_logic;
71
    inboundWriteContentData_i : in std_logic_vector(31 downto 0);
72
    inboundReadFrameEmpty_o : out std_logic;
73
    inboundReadFrame_i : in std_logic;
74
    inboundReadFrameRestart_i : in std_logic;
75
    inboundReadFrameAborted_o : out std_logic;
76
    inboundReadContentEmpty_o : out std_logic;
77
    inboundReadContent_i : in std_logic;
78
    inboundReadContentEnd_o : out std_logic;
79
    inboundReadContentData_o : out std_logic_vector(31 downto 0);
80
 
81
    outboundWriteFrameFull_o : out std_logic;
82
    outboundWriteFrame_i : in std_logic;
83
    outboundWriteFrameAbort_i : in std_logic;
84
    outboundWriteContent_i : in std_logic;
85
    outboundWriteContentData_i : in std_logic_vector(31 downto 0);
86
    outboundReadFrameEmpty_o : out std_logic;
87
    outboundReadFrame_i : in std_logic;
88
    outboundReadFrameRestart_i : in std_logic;
89
    outboundReadFrameAborted_o : out std_logic;
90
    outboundReadContentEmpty_o : out std_logic;
91
    outboundReadContent_i : in std_logic;
92
    outboundReadContentEnd_o : out std_logic;
93
    outboundReadContentData_o : out std_logic_vector(31 downto 0));
94
end entity;
95
 
96
 
97
-------------------------------------------------------------------------------
98
-- Architecture for RioPacketBuffer.
99
-------------------------------------------------------------------------------
100
architecture RioPacketBufferImpl of RioPacketBuffer is
101
 
102
  component PacketBufferContinous is
103 7 magro732
    generic(
104
      SIZE_ADDRESS_WIDTH : natural;
105
      CONTENT_ADDRESS_WIDTH : natural);
106
    port(
107
      clk : in std_logic;
108
      areset_n : in std_logic;
109 3 magro732
 
110 7 magro732
      writeFrameFull_o : out std_logic;
111
      writeFrame_i : in std_logic;
112
      writeFrameAbort_i : in std_logic;
113
      writeContent_i : in std_logic;
114
      writeContentData_i : in std_logic_vector(31 downto 0);
115 3 magro732
 
116 7 magro732
      readFrameEmpty_o : out std_logic;
117
      readFrame_i : in std_logic;
118
      readFrameRestart_i : in std_logic;
119
      readFrameAborted_o : out std_logic;
120
      readContentEmpty_o : out std_logic;
121
      readContent_i : in std_logic;
122
      readContentEnd_o : out std_logic;
123
      readContentData_o : out std_logic_vector(31 downto 0));
124 3 magro732
  end component;
125
 
126
begin
127
 
128
  -----------------------------------------------------------------------------
129
  -- Outbound frame buffers.
130
  -----------------------------------------------------------------------------
131
  OutboundPacketBuffer: PacketBufferContinous
132 7 magro732
    generic map(
133
      SIZE_ADDRESS_WIDTH=>SIZE_ADDRESS_WIDTH,
134
      CONTENT_ADDRESS_WIDTH=>CONTENT_ADDRESS_WIDTH)
135 3 magro732
    port map(
136
      clk=>clk,
137
      areset_n=>areset_n,
138
      writeFrameFull_o=>outboundWriteFrameFull_o,
139
      writeFrame_i=>outboundWriteFrame_i, writeFrameAbort_i=>outboundWriteFrameAbort_i,
140
      writeContent_i=>outboundWriteContent_i, writeContentData_i=>outboundWriteContentData_i,
141
 
142
      readFrameEmpty_o=>outboundReadFrameEmpty_o,
143
      readFrame_i=>outboundReadFrame_i, readFrameRestart_i=>outboundReadFrameRestart_i,
144
      readFrameAborted_o=>outboundReadFrameAborted_o,
145
      readContentEmpty_o=>outboundReadContentEmpty_o,
146
      readContent_i=>outboundReadContent_i, readContentEnd_o=>outboundReadContentEnd_o,
147
      readContentData_o=>outboundReadContentData_o);
148
 
149
  -----------------------------------------------------------------------------
150
  -- Inbound frame buffers.
151
  -----------------------------------------------------------------------------
152
  InboundPacketBuffer: PacketBufferContinous
153 7 magro732
    generic map(
154
      SIZE_ADDRESS_WIDTH=>SIZE_ADDRESS_WIDTH,
155
      CONTENT_ADDRESS_WIDTH=>CONTENT_ADDRESS_WIDTH)
156 3 magro732
    port map(
157
      clk=>clk,
158
      areset_n=>areset_n,
159
      writeFrameFull_o=>inboundWriteFrameFull_o,
160
      writeFrame_i=>inboundWriteFrame_i, writeFrameAbort_i=>inboundWriteFrameAbort_i,
161
      writeContent_i=>inboundWriteContent_i, writeContentData_i=>inboundWriteContentData_i,
162
 
163
      readFrameEmpty_o=>inboundReadFrameEmpty_o,
164
      readFrame_i=>inboundReadFrame_i, readFrameRestart_i=>inboundReadFrameRestart_i,
165
      readFrameAborted_o=>inboundReadFrameAborted_o,
166
      readContentEmpty_o=>inboundReadContentEmpty_o,
167
      readContent_i=>inboundReadContent_i, readContentEnd_o=>inboundReadContentEnd_o,
168
      readContentData_o=>inboundReadContentData_o);
169
 
170
end architecture;
171
 
172
 
173
 
174
 
175
-------------------------------------------------------------------------------
176
-- RioPacketBufferWindow
177
-------------------------------------------------------------------------------
178
 
179
library ieee;
180
use ieee.std_logic_1164.all;
181
use ieee.numeric_std.all;
182
use work.rio_common.all;
183
 
184
 
185
-------------------------------------------------------------------------------
186
-- Entity for RioPacketBufferWindow.
187
-------------------------------------------------------------------------------
188
entity RioPacketBufferWindow is
189 7 magro732
  generic(
190
    SIZE_ADDRESS_WIDTH : natural := 6;
191
    CONTENT_ADDRESS_WIDTH : natural := 8);
192 3 magro732
  port(
193
    clk : in std_logic;
194
    areset_n : in std_logic;
195
 
196
    inboundWriteFrameFull_o : out std_logic;
197
    inboundWriteFrame_i : in std_logic;
198
    inboundWriteFrameAbort_i : in std_logic;
199
    inboundWriteContent_i : in std_logic;
200
    inboundWriteContentData_i : in std_logic_vector(31 downto 0);
201
    inboundReadFrameEmpty_o : out std_logic;
202
    inboundReadFrame_i : in std_logic;
203
    inboundReadFrameRestart_i : in std_logic;
204
    inboundReadFrameAborted_o : out std_logic;
205
    inboundReadContentEmpty_o : out std_logic;
206
    inboundReadContent_i : in std_logic;
207
    inboundReadContentEnd_o : out std_logic;
208
    inboundReadContentData_o : out std_logic_vector(31 downto 0);
209
 
210
    outboundWriteFrameFull_o : out std_logic;
211
    outboundWriteFrame_i : in std_logic;
212
    outboundWriteFrameAbort_i : in std_logic;
213
    outboundWriteContent_i : in std_logic;
214
    outboundWriteContentData_i : in std_logic_vector(31 downto 0);
215
    outboundReadFrameEmpty_o : out std_logic;
216
    outboundReadFrame_i : in std_logic;
217
    outboundReadFrameRestart_i : in std_logic;
218
    outboundReadFrameAborted_o : out std_logic;
219
    outboundReadWindowEmpty_o : out std_logic;
220
    outboundReadWindowReset_i : in std_logic;
221
    outboundReadWindowNext_i : in std_logic;
222
    outboundReadContentEmpty_o : out std_logic;
223
    outboundReadContent_i : in std_logic;
224
    outboundReadContentEnd_o : out std_logic;
225
    outboundReadContentData_o : out std_logic_vector(31 downto 0));
226
end entity;
227
 
228
 
229
-------------------------------------------------------------------------------
230
-- Architecture for RioPacketBufferWindow.
231
-------------------------------------------------------------------------------
232
architecture RioPacketBufferWindowImpl of RioPacketBufferWindow is
233
 
234
  component PacketBufferContinous is
235 7 magro732
    generic(
236
      SIZE_ADDRESS_WIDTH : natural;
237
      CONTENT_ADDRESS_WIDTH : natural);
238
    port(
239
      clk : in std_logic;
240
      areset_n : in std_logic;
241 3 magro732
 
242 7 magro732
      writeFrameFull_o : out std_logic;
243
      writeFrame_i : in std_logic;
244
      writeFrameAbort_i : in std_logic;
245
      writeContent_i : in std_logic;
246
      writeContentData_i : in std_logic_vector(31 downto 0);
247 3 magro732
 
248 7 magro732
      readFrameEmpty_o : out std_logic;
249
      readFrame_i : in std_logic;
250
      readFrameRestart_i : in std_logic;
251
      readFrameAborted_o : out std_logic;
252
 
253
      readContentEmpty_o : out std_logic;
254
      readContent_i : in std_logic;
255
      readContentEnd_o : out std_logic;
256
      readContentData_o : out std_logic_vector(31 downto 0));
257 3 magro732
  end component;
258
 
259
  component PacketBufferContinousWindow is
260 7 magro732
    generic(
261
      SIZE_ADDRESS_WIDTH : natural;
262
      CONTENT_ADDRESS_WIDTH : natural);
263
    port(
264
      clk : in std_logic;
265
      areset_n : in std_logic;
266 3 magro732
 
267 7 magro732
      writeFrameFull_o : out std_logic;
268
      writeFrame_i : in std_logic;
269
      writeFrameAbort_i : in std_logic;
270
      writeContent_i : in std_logic;
271
      writeContentData_i : in std_logic_vector(31 downto 0);
272 3 magro732
 
273 7 magro732
      readFrameEmpty_o : out std_logic;
274
      readFrame_i : in std_logic;
275
      readFrameRestart_i : in std_logic;
276
      readFrameAborted_o : out std_logic;
277
 
278
      readWindowEmpty_o : out std_logic;
279
      readWindowReset_i : in std_logic;
280
      readWindowNext_i : in std_logic;
281
 
282
      readContentEmpty_o : out std_logic;
283
      readContent_i : in std_logic;
284
      readContentEnd_o : out std_logic;
285
      readContentData_o : out std_logic_vector(31 downto 0));
286 3 magro732
  end component;
287
 
288
begin
289
 
290
  -----------------------------------------------------------------------------
291
  -- Outbound frame buffers.
292
  -----------------------------------------------------------------------------
293
  OutboundPacketBuffer: PacketBufferContinousWindow
294 7 magro732
    generic map(
295
      SIZE_ADDRESS_WIDTH=>SIZE_ADDRESS_WIDTH,
296
      CONTENT_ADDRESS_WIDTH=>CONTENT_ADDRESS_WIDTH)
297 3 magro732
    port map(
298
      clk=>clk,
299
      areset_n=>areset_n,
300
      writeFrameFull_o=>outboundWriteFrameFull_o,
301
      writeFrame_i=>outboundWriteFrame_i, writeFrameAbort_i=>outboundWriteFrameAbort_i,
302
      writeContent_i=>outboundWriteContent_i, writeContentData_i=>outboundWriteContentData_i,
303
 
304
      readFrameEmpty_o=>outboundReadFrameEmpty_o,
305
      readFrame_i=>outboundReadFrame_i, readFrameRestart_i=>outboundReadFrameRestart_i,
306
      readFrameAborted_o=>outboundReadFrameAborted_o,
307
      readWindowEmpty_o=>outboundReadWindowEmpty_o,
308
      readWindowReset_i=>outboundReadWindowReset_i,
309
      readWindowNext_i=>outboundReadWindowNext_i,
310
      readContentEmpty_o=>outboundReadContentEmpty_o,
311
      readContent_i=>outboundReadContent_i, readContentEnd_o=>outboundReadContentEnd_o,
312
      readContentData_o=>outboundReadContentData_o);
313
 
314
  -----------------------------------------------------------------------------
315
  -- Inbound frame buffers.
316
  -----------------------------------------------------------------------------
317
  InboundPacketBuffer: PacketBufferContinous
318 7 magro732
    generic map(
319
      SIZE_ADDRESS_WIDTH=>SIZE_ADDRESS_WIDTH,
320
      CONTENT_ADDRESS_WIDTH=>CONTENT_ADDRESS_WIDTH)
321 3 magro732
    port map(
322
      clk=>clk,
323
      areset_n=>areset_n,
324
      writeFrameFull_o=>inboundWriteFrameFull_o,
325
      writeFrame_i=>inboundWriteFrame_i, writeFrameAbort_i=>inboundWriteFrameAbort_i,
326
      writeContent_i=>inboundWriteContent_i, writeContentData_i=>inboundWriteContentData_i,
327
 
328
      readFrameEmpty_o=>inboundReadFrameEmpty_o,
329
      readFrame_i=>inboundReadFrame_i, readFrameRestart_i=>inboundReadFrameRestart_i,
330
      readFrameAborted_o=>inboundReadFrameAborted_o,
331
      readContentEmpty_o=>inboundReadContentEmpty_o,
332
      readContent_i=>inboundReadContent_i, readContentEnd_o=>inboundReadContentEnd_o,
333
      readContentData_o=>inboundReadContentData_o);
334
 
335
end architecture;
336
 
337
 
338
 
339
 
340
-------------------------------------------------------------------------------
341
-- PacketBufferContinous
342
-- This component stores data in chuncks and stores the size of them. The full
343
-- memory can be used, except for one word, or a specified (using generic)
344
-- maximum number of frames.
345
-------------------------------------------------------------------------------
346
 
347
library ieee;
348
use ieee.std_logic_1164.all;
349
use ieee.numeric_std.all;
350
 
351
 
352
-------------------------------------------------------------------------------
353
-- Entity for PacketBufferContinous.
354
-------------------------------------------------------------------------------
355
entity PacketBufferContinous is
356
  generic(
357 7 magro732
    SIZE_ADDRESS_WIDTH : natural;
358
    CONTENT_ADDRESS_WIDTH : natural);
359 3 magro732
  port(
360
    clk : in std_logic;
361
    areset_n : in std_logic;
362
 
363
    writeFrameFull_o : out std_logic;
364
    writeFrame_i : in std_logic;
365
    writeFrameAbort_i : in std_logic;
366
    writeContent_i : in std_logic;
367
    writeContentData_i : in std_logic_vector(31 downto 0);
368
 
369
    readFrameEmpty_o : out std_logic;
370
    readFrame_i : in std_logic;
371
    readFrameRestart_i : in std_logic;
372
    readFrameAborted_o : out std_logic;
373
 
374
    readContentEmpty_o : out std_logic;
375
    readContent_i : in std_logic;
376
    readContentEnd_o : out std_logic;
377
    readContentData_o : out std_logic_vector(31 downto 0));
378
end entity;
379
 
380
 
381
-------------------------------------------------------------------------------
382
-- Architecture for PacketBufferContinous.
383
-------------------------------------------------------------------------------
384
architecture PacketBufferContinousImpl of PacketBufferContinous is
385
 
386
  component MemorySimpleDualPortAsync is
387
    generic(
388
      ADDRESS_WIDTH : natural := 1;
389
      DATA_WIDTH : natural := 1);
390
    port(
391
      clkA_i : in std_logic;
392
      enableA_i : in std_logic;
393
      addressA_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
394
      dataA_i : in std_logic_vector(DATA_WIDTH-1 downto 0);
395
 
396
      addressB_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
397
      dataB_o : out std_logic_vector(DATA_WIDTH-1 downto 0));
398
  end component;
399
 
400
  component MemorySimpleDualPort is
401
    generic(
402
      ADDRESS_WIDTH : natural := 1;
403
      DATA_WIDTH : natural := 1);
404
    port(
405
      clkA_i : in std_logic;
406
      enableA_i : in std_logic;
407
      addressA_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
408
      dataA_i : in std_logic_vector(DATA_WIDTH-1 downto 0);
409
 
410
      clkB_i : in std_logic;
411
      enableB_i : in std_logic;
412
      addressB_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
413
      dataB_o : out std_logic_vector(DATA_WIDTH-1 downto 0));
414
  end component;
415
 
416
  -- The number of available word positions left in the memory.
417
  signal available : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
418
 
419
  -- The position to place new frames.
420
  signal backIndex, backIndexNext : unsigned(SIZE_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
421
 
422
  -- The position to remove old frames.
423
  signal frontIndex, frontIndexNext : unsigned(SIZE_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
424
 
425
  -- The size of the current frame.
426
  signal readFrameEnd_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
427
 
428
  -- The start of unread content.
429
  signal memoryStart_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
430
 
431
  -- The current reading position.
432
  signal memoryRead_p, memoryReadNext_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
433
 
434
  -- The end of unread content.
435
  signal memoryEnd_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
436
 
437
  -- The current writing position.
438
  signal memoryWrite_p, memoryWriteNext_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
439
 
440
  -- Memory output signal containing the position of a frame.
441
  signal framePositionReadData : std_logic_vector(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
442
begin
443
 
444
  -----------------------------------------------------------------------------
445
  -- Internal signal assignments.
446
  -----------------------------------------------------------------------------
447
 
448
  available <= not (memoryEnd_p - memoryStart_p);
449
 
450
  backIndexNext <= backIndex + 1;
451
  frontIndexNext <= frontIndex + 1;
452
 
453
  memoryWriteNext_p <= memoryWrite_p + 1;
454
  memoryReadNext_p <= memoryRead_p + 1;
455
 
456
  -----------------------------------------------------------------------------
457
  -- Writer logic.
458
  -----------------------------------------------------------------------------
459
 
460
  writeFrameFull_o <= '1' when ((backIndexNext = frontIndex) or
461
                                (available <= 68)) else '0';
462
 
463
  Writer: process(clk, areset_n)
464
  begin
465
    if (areset_n = '0') then
466
      backIndex <= (others=>'0');
467
 
468
      memoryEnd_p <= (others=>'0');
469
      memoryWrite_p <= (others=>'0');
470
    elsif (clk'event and clk = '1') then
471
 
472
      if (writeFrameAbort_i = '1') then
473
        memoryWrite_p <= memoryEnd_p;
474
      elsif (writeContent_i = '1') then
475
        memoryWrite_p <= memoryWriteNext_p;
476
      end if;
477
 
478
      if(writeFrame_i = '1') then
479
        memoryEnd_p <= memoryWrite_p;
480
        backIndex <= backIndexNext;
481
      end if;
482
 
483
    end if;
484
  end process;
485
 
486
  -----------------------------------------------------------------------------
487
  -- Frame cancellation logic.
488
  -----------------------------------------------------------------------------
489
 
490
  process(clk, areset_n)
491
  begin
492
    if (areset_n = '0') then
493
      readFrameAborted_o <= '0';
494
    elsif (clk'event and clk = '1') then
495
 
496
      if ((frontIndex = backIndex) and
497
          ((writeFrameAbort_i = '1') and (readFrameRestart_i = '0'))) then
498
        readFrameAborted_o <= '1';
499
      elsif ((writeFrameAbort_i = '0') and (readFrameRestart_i = '1')) then
500
        readFrameAborted_o <= '0';
501
      end if;
502
 
503
    end if;
504
  end process;
505
 
506
  -----------------------------------------------------------------------------
507
  -- Reader logic.
508
  -----------------------------------------------------------------------------
509
 
510
  readFrameEmpty_o <= '1' when (frontIndex = backIndex) else '0';
511
  readContentEmpty_o <= '1' when ((frontIndex = backIndex) and
512
                                  (memoryWrite_p = memoryRead_p)) else '0';
513
 
514
  Reader: process(clk, areset_n)
515
  begin
516
    if (areset_n = '0') then
517
      frontIndex <= (others=>'0');
518
 
519
      memoryStart_p <= (others=>'0');
520
      memoryRead_p <= (others=>'0');
521
 
522
      readContentEnd_o <= '0';
523
    elsif (clk'event and clk = '1') then
524
 
525
      -- REMARK: Break apart into registers to avoid priority ladder???
526
      if(readFrameRestart_i = '1') then
527
        memoryRead_p <= memoryStart_p;
528
      elsif(readContent_i = '1') then
529
        if(memoryRead_p = readFrameEnd_p) then
530
          readContentEnd_o <= '1';
531
        else
532
          readContentEnd_o <= '0';
533
          memoryRead_p <= memoryReadNext_p;
534
        end if;
535
      elsif(readFrame_i = '1') then
536
        memoryStart_p <= readFrameEnd_p;
537
        frontIndex <= frontIndexNext;
538
        memoryRead_p <= readFrameEnd_p;
539
      end if;
540
 
541
    end if;
542
  end process;
543
 
544
  -----------------------------------------------------------------------------
545
  -- Frame positioning memory signals.
546
  -----------------------------------------------------------------------------
547
 
548
  readFrameEnd_p <= unsigned(framePositionReadData);
549
 
550
  -- Memory to keep frame starting/ending positions in.
551
  FramePosition: MemorySimpleDualPortAsync
552
    generic map(ADDRESS_WIDTH=>SIZE_ADDRESS_WIDTH, DATA_WIDTH=>CONTENT_ADDRESS_WIDTH)
553
    port map(
554
      clkA_i=>clk, enableA_i=>writeFrame_i,
555
      addressA_i=>std_logic_vector(backIndex), dataA_i=>std_logic_vector(memoryWrite_p),
556
      addressB_i=>std_logic_vector(frontIndex), dataB_o=>framePositionReadData);
557
 
558
  -----------------------------------------------------------------------------
559
  -- Frame content memory signals.
560
  -----------------------------------------------------------------------------
561
 
562
  -- Memory to keep frame content in.
563
  -- REMARK: Use paritybits here as well to make sure the frame data does not
564
  -- become corrupt???
565
  FrameContent: MemorySimpleDualPort
566
    generic map(ADDRESS_WIDTH=>CONTENT_ADDRESS_WIDTH, DATA_WIDTH=>32)
567
    port map(
568
      clkA_i=>clk, enableA_i=>writeContent_i,
569
      addressA_i=>std_logic_vector(memoryWrite_p), dataA_i=>writeContentData_i,
570
      clkB_i=>clk, enableB_i=>readContent_i,
571
      addressB_i=>std_logic_vector(memoryRead_p), dataB_o=>readContentData_o);
572
 
573
end architecture;
574
 
575
 
576
 
577
-------------------------------------------------------------------------------
578
-- PacketBufferContinousWindow
579
-- This component stores data in chuncks and stores the size of them. The full
580
-- memory can be used, except for one word, or a specified (using generic)
581
-- maximum number of frames.
582
-------------------------------------------------------------------------------
583
 
584
library ieee;
585
use ieee.std_logic_1164.all;
586
use ieee.numeric_std.all;
587
 
588
 
589
-------------------------------------------------------------------------------
590
-- Entity for PacketBufferContinousWindow.
591
-------------------------------------------------------------------------------
592
entity PacketBufferContinousWindow is
593
  generic(
594 7 magro732
    SIZE_ADDRESS_WIDTH : natural;
595
    CONTENT_ADDRESS_WIDTH : natural);
596 3 magro732
  port(
597
    clk : in std_logic;
598
    areset_n : in std_logic;
599
 
600
    writeFrameFull_o : out std_logic;
601
    writeFrame_i : in std_logic;
602
    writeFrameAbort_i : in std_logic;
603
    writeContent_i : in std_logic;
604
    writeContentData_i : in std_logic_vector(31 downto 0);
605
 
606
    readFrameEmpty_o : out std_logic;
607
    readFrame_i : in std_logic;
608
    readFrameRestart_i : in std_logic;
609
    readFrameAborted_o : out std_logic;
610
 
611
    readWindowEmpty_o : out std_logic;
612
    readWindowReset_i : in std_logic;
613
    readWindowNext_i : in std_logic;
614
 
615
    readContentEmpty_o : out std_logic;
616
    readContent_i : in std_logic;
617
    readContentEnd_o : out std_logic;
618
    readContentData_o : out std_logic_vector(31 downto 0));
619
end entity;
620
 
621
 
622
-------------------------------------------------------------------------------
623
-- Architecture for PacketBufferContinousWindow.
624
-------------------------------------------------------------------------------
625
architecture PacketBufferContinousWindowImpl of PacketBufferContinousWindow is
626
 
627
  component MemorySimpleDualPortAsync is
628
    generic(
629
      ADDRESS_WIDTH : natural := 1;
630
      DATA_WIDTH : natural := 1);
631
    port(
632
      clkA_i : in std_logic;
633
      enableA_i : in std_logic;
634
      addressA_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
635
      dataA_i : in std_logic_vector(DATA_WIDTH-1 downto 0);
636
 
637
      addressB_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
638
      dataB_o : out std_logic_vector(DATA_WIDTH-1 downto 0));
639
  end component;
640
 
641
  component MemorySimpleDualPort is
642
    generic(
643
      ADDRESS_WIDTH : natural := 1;
644
      DATA_WIDTH : natural := 1);
645
    port(
646
      clkA_i : in std_logic;
647
      enableA_i : in std_logic;
648
      addressA_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
649
      dataA_i : in std_logic_vector(DATA_WIDTH-1 downto 0);
650
 
651
      clkB_i : in std_logic;
652
      enableB_i : in std_logic;
653
      addressB_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
654
      dataB_o : out std_logic_vector(DATA_WIDTH-1 downto 0));
655
  end component;
656
 
657
  -- The number of available word positions left in the memory.
658
  signal available : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
659
 
660
  signal backIndex, backIndexNext : unsigned(SIZE_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
661
  signal frontIndex, frontIndexNext : unsigned(SIZE_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
662
  signal windowIndex, windowIndexNext : unsigned(SIZE_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
663
 
664
  -- The size of the current frame.
665
  signal readFrameEnd_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
666
 
667
  -- The start of unread content.
668
  signal memoryStart_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
669
 
670
  -- The start of unread window content.
671
  signal memoryStartWindow_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
672
 
673
  -- The current reading position.
674
  signal memoryRead_p, memoryReadNext_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
675
 
676
  -- The end of unread content.
677
  signal memoryEnd_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
678
 
679
  -- The current writing position.
680
  signal memoryWrite_p, memoryWriteNext_p : unsigned(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
681
 
682
  signal framePositionReadAddress : std_logic_vector(SIZE_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
683
  signal framePositionReadData : std_logic_vector(CONTENT_ADDRESS_WIDTH-1 downto 0) := (others=>'0');
684
begin
685
 
686
  -----------------------------------------------------------------------------
687
  -- Internal signal assignments.
688
  -----------------------------------------------------------------------------
689
 
690
  available <= not (memoryEnd_p - memoryStart_p);
691
 
692
  backIndexNext <= backIndex + 1;
693
  frontIndexNext <= frontIndex + 1;
694
  windowIndexNext <= windowIndex + 1;
695
 
696
  memoryWriteNext_p <= memoryWrite_p + 1;
697
  memoryReadNext_p <= memoryRead_p + 1;
698
 
699
  -----------------------------------------------------------------------------
700
  -- Writer logic.
701
  -----------------------------------------------------------------------------
702
 
703
  writeFrameFull_o <= '1' when ((backIndexNext = frontIndex) or
704
                                (available <= 68)) else '0';
705
 
706
  Writer: process(clk, areset_n)
707
  begin
708
    if (areset_n = '0') then
709
      backIndex <= (others=>'0');
710
 
711
      memoryEnd_p <= (others=>'0');
712
      memoryWrite_p <= (others=>'0');
713
    elsif (clk'event and clk = '1') then
714
 
715
      if (writeFrameAbort_i = '1') then
716
        memoryWrite_p <= memoryEnd_p;
717
      elsif (writeContent_i = '1') then
718
        memoryWrite_p <= memoryWriteNext_p;
719
      end if;
720
 
721
      if(writeFrame_i = '1') then
722
        memoryEnd_p <= memoryWrite_p;
723
        backIndex <= backIndexNext;
724
      end if;
725
 
726
    end if;
727
  end process;
728
 
729
  -----------------------------------------------------------------------------
730
  -- Frame cancellation logic.
731
  -----------------------------------------------------------------------------
732
 
733
  process(clk, areset_n)
734
  begin
735
    if (areset_n = '0') then
736
      readFrameAborted_o <= '0';
737
    elsif (clk'event and clk = '1') then
738
 
739
      if ((windowIndex = backIndex) and
740
          ((writeFrameAbort_i = '1') and (readFrameRestart_i = '0'))) then
741
        readFrameAborted_o <= '1';
742
      elsif ((writeFrameAbort_i = '0') and (readFrameRestart_i = '1')) then
743
        readFrameAborted_o <= '0';
744
      end if;
745
 
746
    end if;
747
  end process;
748
 
749
  -----------------------------------------------------------------------------
750
  -- Reader logic.
751
  -----------------------------------------------------------------------------
752
 
753
  readFrameEmpty_o <= '1' when (frontIndex = backIndex) else '0';
754
  readWindowEmpty_o <= '1' when (windowIndex = backIndex) else '0';
755
  readContentEmpty_o <= '1' when ((windowIndex = backIndex) and
756
                                  (memoryWrite_p = memoryRead_p)) else '0';
757
 
758
  Reader: process(clk, areset_n)
759
  begin
760
    if (areset_n = '0') then
761
      frontIndex <= (others=>'0');
762
      windowIndex <= (others=>'0');
763
 
764
      memoryStart_p <= (others=>'0');
765
      memoryStartWindow_p <= (others=>'0');
766
      memoryRead_p <= (others=>'0');
767
 
768
      readContentEnd_o <= '0';
769
    elsif (clk'event and clk = '1') then
770
 
771
      -- REMARK: Break apart into registers to avoid priority ladder???
772
      if(readFrameRestart_i = '1') then
773
        memoryRead_p <= memoryStartWindow_p;
774
      elsif(readContent_i = '1') then
775 16 magro732
        if(memoryReadNext_p = readFrameEnd_p) then
776 3 magro732
          readContentEnd_o <= '1';
777
        else
778
          readContentEnd_o <= '0';
779
          memoryRead_p <= memoryReadNext_p;
780
        end if;
781
      elsif(readFrame_i = '1') then
782
        memoryStart_p <= readFrameEnd_p;
783
        frontIndex <= frontIndexNext;
784
      elsif(readWindowReset_i = '1') then
785
        memoryStartWindow_p <= memoryStart_p;
786
        windowIndex <= frontIndex;
787
        memoryRead_p <= memoryStart_p;
788
      elsif(readWindowNext_i = '1') then
789
        memoryStartWindow_p <= readFrameEnd_p;
790
        windowIndex <= windowIndexNext;
791
        memoryRead_p <= readFrameEnd_p;
792
      end if;
793
 
794
    end if;
795
  end process;
796
 
797
  -----------------------------------------------------------------------------
798
  -- Frame positioning memory signals.
799
  -----------------------------------------------------------------------------
800
 
801
  -- Assign the address from both frontIndex and windowIndex to be able to
802
  -- share the memory between the two different types of accesses. This assumes
803
  -- that the window is not accessed at the same time as the other signal.
804
  framePositionReadAddress <= std_logic_vector(frontIndex) when (readFrame_i = '1') else
805
                              std_logic_vector(windowIndex);
806
  readFrameEnd_p <= unsigned(framePositionReadData);
807
 
808
  -- Memory to keep frame starting/ending positions in.
809
  FramePosition: MemorySimpleDualPortAsync
810
    generic map(ADDRESS_WIDTH=>SIZE_ADDRESS_WIDTH, DATA_WIDTH=>CONTENT_ADDRESS_WIDTH)
811
    port map(
812
      clkA_i=>clk, enableA_i=>writeFrame_i,
813
      addressA_i=>std_logic_vector(backIndex), dataA_i=>std_logic_vector(memoryWrite_p),
814
      addressB_i=>framePositionReadAddress, dataB_o=>framePositionReadData);
815
 
816
  -----------------------------------------------------------------------------
817
  -- Frame content memory signals.
818
  -----------------------------------------------------------------------------
819
 
820
  -- Memory to keep frame content in.
821
  -- REMARK: Use paritybits here as well to make sure the frame data does not
822
  -- become corrupt???
823
  FrameContent: MemorySimpleDualPort
824
    generic map(ADDRESS_WIDTH=>CONTENT_ADDRESS_WIDTH, DATA_WIDTH=>32)
825
    port map(
826
      clkA_i=>clk, enableA_i=>writeContent_i,
827
      addressA_i=>std_logic_vector(memoryWrite_p), dataA_i=>writeContentData_i,
828
      clkB_i=>clk, enableB_i=>readContent_i,
829
      addressB_i=>std_logic_vector(memoryRead_p), dataB_o=>readContentData_o);
830
 
831
end architecture;

powered by: WebSVN 2.1.0

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