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

Subversion Repositories rio

[/] [rio/] [branches/] [2.0.0-development/] [rtl/] [vhdl/] [RioLogicalCommon.vhd] - Blame information for rev 47

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

Line No. Rev Author Line
1 33 magro732
-------------------------------------------------------------------------------
2 36 magro732
-- 
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
-- Contains a platform to build endpoints on.
10
-- 
11
-- To Do:
12 47 magro732
-- - Fix bug with one extra write in inbound direction.
13
-- - Rewrite to decrease resource usage.
14 46 magro732
-- - Clean up and increase the speed of the interface to packet handlers.
15
-- - 8-bit deviceId has not been verified, fix.
16
-- - Egress; Place packets in different queues depending on the packet priority?
17
-- - Add verification of all sizes of packets.
18 36 magro732
-- 
19
-- Author(s): 
20
-- - Magnus Rosenius, magro732@opencores.org 
21
-- 
22
-------------------------------------------------------------------------------
23
-- 
24
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
25
-- 
26
-- This source file may be used and distributed without 
27
-- restriction provided that this copyright statement is not 
28
-- removed from the file and that any derivative work contains 
29
-- the original copyright notice and the associated disclaimer. 
30
-- 
31
-- This source file is free software; you can redistribute it 
32
-- and/or modify it under the terms of the GNU Lesser General 
33
-- Public License as published by the Free Software Foundation; 
34
-- either version 2.1 of the License, or (at your option) any 
35
-- later version. 
36
-- 
37
-- This source is distributed in the hope that it will be 
38
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
39
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
40
-- PURPOSE. See the GNU Lesser General Public License for more 
41
-- details. 
42
-- 
43
-- You should have received a copy of the GNU Lesser General 
44
-- Public License along with this source; if not, download it 
45
-- from http://www.opencores.org/lgpl.shtml 
46
-- 
47
-------------------------------------------------------------------------------
48
 
49 47 magro732
 
50 36 magro732
-------------------------------------------------------------------------------
51 33 magro732
-- RioLogicalCommon.
52
-------------------------------------------------------------------------------
53
-- Ingress:
54 35 magro732
-- * Removes in-the-middle and trailing CRC.
55 33 magro732
-- * Forwards packets to logical-layer handlers depending on ftype and
56
--   transaction (output as address).
57
-- * Outputs header and deviceIDs in seperate accesses to facilitate 8- and
58
--   16-bit deviceAddress support. All fields are right-justified.
59
-- Egress:
60 35 magro732
-- * Adds in-the-middle and trailing CRC.
61 33 magro732
-- * Receives packets from logical-layer handlers.
62 35 magro732
-- * Receives header and deviceIDs in seperate accesses to facilitate 8- and
63
--   16-bit deviceAddress support. All fields are right-justified.
64 33 magro732
-------------------------------------------------------------------------------
65 36 magro732
library ieee;
66
use ieee.std_logic_1164.all;
67
use ieee.numeric_std.all;
68
use work.rio_common.all;
69
 
70
 
71 38 magro732
-------------------------------------------------------------------------------
72 47 magro732
-- Entity for RioLogicalCommon.
73 38 magro732
-------------------------------------------------------------------------------
74 36 magro732
entity RioLogicalCommon is
75 45 magro732
  generic(
76
    PORTS : natural);
77 36 magro732
  port(
78
    clk : in std_logic;
79
    areset_n : in std_logic;
80
    enable : in std_logic;
81
 
82
    readFrameEmpty_i : in std_logic;
83
    readFrame_o : out std_logic;
84
    readContent_o : out std_logic;
85
    readContentEnd_i : in std_logic;
86
    readContentData_i : in std_logic_vector(31 downto 0);
87 39 magro732
 
88 36 magro732
    writeFrameFull_i : in std_logic;
89
    writeFrame_o : out std_logic;
90
    writeFrameAbort_o : out std_logic;
91
    writeContent_o : out std_logic;
92
    writeContentData_o : out std_logic_vector(31 downto 0);
93
 
94 45 magro732
    inboundCyc_o : out std_logic;
95
    inboundStb_o : out std_logic;
96
    inboundAdr_o : out std_logic_vector(7 downto 0);
97
    inboundDat_o : out std_logic_vector(31 downto 0);
98
    inboundAck_i : in std_logic;
99 39 magro732
 
100 45 magro732
    outboundCyc_i : in std_logic_vector(PORTS-1 downto 0);
101
    outboundStb_i : in std_logic_vector(PORTS-1 downto 0);
102
    outboundDat_i : in std_logic_vector(32*PORTS-1 downto 0);
103
    outboundAck_o : out std_logic_vector(PORTS-1 downto 0));
104 36 magro732
end entity;
105
 
106
 
107 38 magro732
-------------------------------------------------------------------------------
108 47 magro732
-- Architecture for RioLogicalCommon.
109 38 magro732
-------------------------------------------------------------------------------
110 36 magro732
architecture RioLogicalCommon of RioLogicalCommon is
111
 
112 45 magro732
  component RioLogicalCommonInterconnect is
113
    generic(
114
      WIDTH : natural);
115
    port(
116
      clk : in std_logic;
117
      areset_n : in std_logic;
118
 
119
      stb_i : in std_logic_vector(WIDTH-1 downto 0);
120
      dataM_i : in std_logic_vector(32*WIDTH-1 downto 0);
121
      ack_o : out std_logic_vector(WIDTH-1 downto 0);
122
 
123
      stb_o : out std_logic;
124
      dataS_o : out std_logic_vector(31 downto 0);
125
      ack_i : in std_logic);
126
  end component;
127
 
128 36 magro732
  component RioLogicalCommonIngress is
129
    port(
130
      clk : in std_logic;
131
      areset_n : in std_logic;
132
 
133
      readFrameEmpty_i : in std_logic;
134
      readFrame_o : out std_logic;
135
      readContent_o : out std_logic;
136
      readContentEnd_i : in std_logic;
137
      readContentData_i : in std_logic_vector(31 downto 0);
138
 
139 45 magro732
      inboundCyc_o : out std_logic;
140
      inboundStb_o : out std_logic;
141
      inboundAdr_o : out std_logic_vector(7 downto 0);
142
      inboundDat_o : out std_logic_vector(31 downto 0);
143
      inboundAck_i : in std_logic);
144 36 magro732
  end component;
145
 
146
  component RioLogicalCommonEgress is
147
    port(
148
      clk : in std_logic;
149
      areset_n : in std_logic;
150
 
151
      writeFrameFull_i : in std_logic;
152
      writeFrame_o : out std_logic;
153
      writeFrameAbort_o : out std_logic;
154
      writeContent_o : out std_logic;
155
      writeContentData_o : out std_logic_vector(31 downto 0);
156
 
157 45 magro732
      outboundCyc_i : in std_logic;
158
      outboundStb_i : in std_logic;
159
      outboundDat_i : in std_logic_vector(31 downto 0);
160
      outboundAck_o : out std_logic);
161 36 magro732
  end component;
162
 
163 45 magro732
  signal outboundStb : std_logic;
164
  signal outboundDat : std_logic_vector(31 downto 0);
165
  signal outboundAck : std_logic;
166
 
167 36 magro732
begin
168
 
169 38 magro732
  Ingress: RioLogicalCommonIngress
170
    port map(
171
      clk=>clk, areset_n=>areset_n,
172
      readFrameEmpty_i=>readFrameEmpty_i,
173
      readFrame_o=>readFrame_o,
174
      readContent_o=>readContent_o,
175
      readContentEnd_i=>readContentEnd_i,
176
      readContentData_i=>readContentData_i,
177 45 magro732
      inboundCyc_o=>inboundCyc_o,
178
      inboundStb_o=>inboundStb_o,
179
      inboundAdr_o=>inboundAdr_o,
180
      inboundDat_o=>inboundDat_o,
181
      inboundAck_i=>inboundAck_i);
182 38 magro732
 
183 45 magro732
  EgressInterconnect: RioLogicalCommonInterconnect
184
    generic map(WIDTH=>PORTS)
185
    port map(
186
      clk=>clk, areset_n=>areset_n,
187
      stb_i=>outboundStb_i,
188
      dataM_i=>outboundDat_i,
189
      ack_o=>outboundAck_o,
190
      stb_o=>outboundStb,
191
      dataS_o=>outboundDat,
192
      ack_i=>outboundAck);
193
 
194 36 magro732
  Egress: RioLogicalCommonEgress
195
    port map(
196
      clk=>clk, areset_n=>areset_n,
197
      writeFrameFull_i=>writeFrameFull_i,
198
      writeFrame_o=>writeFrame_o,
199
      writeFrameAbort_o=>writeFrameAbort_o,
200
      writeContent_o=>writeContent_o,
201
      writeContentData_o=>writeContentData_o,
202 45 magro732
      outboundCyc_i=>'1',
203
      outboundStb_i=>outboundStb,
204
      outboundDat_i=>outboundDat,
205
      outboundAck_o=>outboundAck);
206 36 magro732
 
207
end architecture;
208
 
209
 
210
 
211 34 magro732
-------------------------------------------------------------------------------
212
-- RioLogicalCommonIngress.
213
-------------------------------------------------------------------------------
214 33 magro732
library ieee;
215 34 magro732
use ieee.std_logic_1164.all;
216 33 magro732
use ieee.numeric_std.all;
217
use work.rio_common.all;
218
 
219 47 magro732
 
220 33 magro732
-------------------------------------------------------------------------------
221
-- Entity for RioLogicalCommonIngress.
222
-------------------------------------------------------------------------------
223
entity RioLogicalCommonIngress is
224
  port(
225
    clk : in std_logic;
226
    areset_n : in std_logic;
227
 
228
    readFrameEmpty_i : in std_logic;
229
    readFrame_o : out std_logic;
230
    readContent_o : out std_logic;
231
    readContentEnd_i : in std_logic;
232
    readContentData_i : in std_logic_vector(31 downto 0);
233
 
234 45 magro732
    inboundCyc_o : out std_logic;
235
    inboundStb_o : out std_logic;
236
    inboundAdr_o : out std_logic_vector(7 downto 0);
237
    inboundDat_o : out std_logic_vector(31 downto 0);
238
    inboundAck_i : in std_logic);
239 33 magro732
end entity;
240
 
241
 
242
-------------------------------------------------------------------------------
243 47 magro732
-- Architecture for RioLogicalCommonIngress.
244 33 magro732
-------------------------------------------------------------------------------
245
architecture RioLogicalCommonIngress of RioLogicalCommonIngress is
246 36 magro732
  type StateType is (IDLE,
247
                     WAIT_HEADER_0, HEADER_0, HEADER_1,
248
                     SEND_HEADER, SEND_DESTINATION, SEND_SOURCE,
249
                     FORWARD_SHORT, FORWARD_CRC, FORWARD_LONG, FORWARD_LAST,
250
                     END_PACKET);
251
  signal state : StateType;
252 33 magro732
 
253 45 magro732
  signal packetPosition : natural range 0 to 68;
254 36 magro732
  signal packetContent : std_logic_vector(63 downto 0);
255
 
256
  signal tt : std_logic_vector(1 downto 0);
257
  signal ftype : std_logic_vector(3 downto 0);
258
  signal transaction : std_logic_vector(3 downto 0);
259
 
260 33 magro732
begin
261
 
262
  process(clk, areset_n)
263
  begin
264
    if (areset_n = '0') then
265 44 magro732
      state <= IDLE;
266 38 magro732
 
267 36 magro732
      packetPosition <= 0;
268
      packetContent <= (others=>'0');
269 44 magro732
 
270 36 magro732
      tt <= "00";
271
      ftype <= "0000";
272
      transaction <= "0000";
273 38 magro732
 
274
      readContent_o <= '0';
275
      readFrame_o <= '0';
276 44 magro732
 
277 45 magro732
      inboundCyc_o <= '0';
278
      inboundStb_o <= '0';
279
      inboundAdr_o <= (others=>'0');
280
      inboundDat_o <= (others=>'0');
281 33 magro732
    elsif (clk'event and clk = '1') then
282
      readContent_o <= '0';
283 38 magro732
      readFrame_o <= '0';
284 33 magro732
 
285
      case state is
286
        when IDLE =>
287
          ---------------------------------------------------------------------
288
          -- 
289
          ---------------------------------------------------------------------
290
          packetPosition <= 0;
291
          if (readFrameEmpty_i = '0') then
292
            readContent_o <= '1';
293
            state <= WAIT_HEADER_0;
294
          end if;
295
 
296
        when WAIT_HEADER_0 =>
297
          ---------------------------------------------------------------------
298
          -- 
299
          ---------------------------------------------------------------------
300
          readContent_o <= '1';
301
          state <= HEADER_0;
302
 
303
        when HEADER_0 =>
304
          ---------------------------------------------------------------------
305
          -- 
306
          ---------------------------------------------------------------------
307
          packetContent <= packetContent(31 downto 0) & readContentData_i;
308
          packetPosition <= packetPosition + 1;
309
          readContent_o <= '1';
310
 
311
          tt <= readContentData_i(21 downto 20);
312
          ftype <= readContentData_i(19 downto 16);
313
 
314
          state <= HEADER_1;
315
 
316
        when HEADER_1 =>
317
          ---------------------------------------------------------------------
318
          -- 
319
          ---------------------------------------------------------------------
320
          packetContent <= packetContent(31 downto 0) & readContentData_i;
321
          packetPosition <= packetPosition + 1;
322
 
323
          if (tt = "00") then
324
            transaction <= readContentData_i(31 downto 28);
325
          elsif (tt = "01") then
326
            transaction <= readContentData_i(15 downto 12);
327
          end if;
328
 
329
          state <= SEND_HEADER;
330
 
331
        when SEND_HEADER =>
332
          ---------------------------------------------------------------------
333
          -- 
334
          ---------------------------------------------------------------------
335 45 magro732
          inboundCyc_o <= '1';
336
          inboundStb_o <= '1';
337
          inboundAdr_o <= ftype & transaction;
338
          inboundDat_o <= x"0000" & packetContent(63 downto 48);
339 33 magro732
          packetContent <= packetContent(47 downto 0) & x"0000";
340
 
341
          state <= SEND_DESTINATION;
342
 
343
        when SEND_DESTINATION =>
344
          ---------------------------------------------------------------------
345
          -- 
346
          ---------------------------------------------------------------------
347 45 magro732
          if (inboundAck_i = '1') then
348 33 magro732
            if (tt = "00") then
349 45 magro732
              inboundDat_o <= x"000000" & packetContent(63 downto 56);
350 33 magro732
              packetContent <= packetContent(55 downto 0) & x"00";
351
            elsif (tt = "01") then
352 45 magro732
              inboundDat_o <= x"0000" & packetContent(63 downto 48);
353 38 magro732
              packetContent <= packetContent(47 downto 0) & x"0000";
354 33 magro732
            end if;
355
 
356
            state <= SEND_SOURCE;
357
          end if;
358
 
359
        when SEND_SOURCE =>
360
          ---------------------------------------------------------------------
361
          -- 
362
          ---------------------------------------------------------------------
363 45 magro732
          if (inboundAck_i = '1') then
364 33 magro732
            if (tt = "00") then
365 45 magro732
              inboundDat_o <= x"000000" & packetContent(63 downto 56);
366 33 magro732
              packetContent <= packetContent(55 downto 0) & x"00";
367
            elsif (tt = "01") then
368 45 magro732
              inboundDat_o <= x"0000" & packetContent(63 downto 48);
369 38 magro732
              packetContent <= packetContent(47 downto 32) & readContentData_i & x"0000";
370
              readContent_o <= '1';
371 33 magro732
            end if;
372
 
373 36 magro732
            state <= FORWARD_SHORT;
374 33 magro732
          end if;
375
 
376 36 magro732
        when FORWARD_SHORT =>
377 33 magro732
          ---------------------------------------------------------------------
378
          -- 
379
          ---------------------------------------------------------------------
380 45 magro732
          if (inboundAck_i = '1') then
381 38 magro732
            packetPosition <= packetPosition + 1;
382 33 magro732
 
383 38 magro732
            if (tt = "00") then
384 45 magro732
              inboundDat_o <= packetContent(63 downto 32);
385 38 magro732
              packetContent <= packetContent(31 downto 0) & readContentData_i;
386
            elsif (tt = "01") then
387 45 magro732
              inboundDat_o <= packetContent(63 downto 32);
388 38 magro732
              packetContent <= packetContent(31 downto 16) & readContentData_i & x"0000";
389
            end if;
390 36 magro732
 
391
            if (readContentEnd_i = '0') then
392 45 magro732
              if (packetPosition = 18) then
393 36 magro732
                state <= FORWARD_CRC;
394
              end if;
395
 
396
              readContent_o <= '1';
397
            else
398
              readFrame_o <= '1';
399 44 magro732
              state <= FORWARD_LAST;
400 36 magro732
            end if;
401
          end if;
402 33 magro732
 
403 36 magro732
        when FORWARD_CRC =>
404
          ---------------------------------------------------------------------
405
          -- 
406
          ---------------------------------------------------------------------
407 45 magro732
          if (inboundAck_i = '1') then
408
            inboundDat_o <= packetContent(63 downto 32);
409 36 magro732
 
410
            packetPosition <= packetPosition + 1;
411
            packetContent <=
412 45 magro732
              packetContent(31 downto 16) & readContentData_i(15 downto 0) & x"00000000";
413 36 magro732
 
414
            if (readContentEnd_i = '0') then
415
              readContent_o <= '1';
416
              state <= FORWARD_LONG;
417 33 magro732
            else
418 36 magro732
              readFrame_o <= '1';
419
              state <= FORWARD_LAST;
420 33 magro732
            end if;
421 36 magro732
          end if;
422
 
423
        when FORWARD_LONG =>
424
          ---------------------------------------------------------------------
425
          -- 
426
          ---------------------------------------------------------------------
427 45 magro732
          if (inboundAck_i = '1') then
428
            inboundDat_o <= packetContent(63 downto 32);
429 36 magro732
 
430
            packetPosition <= packetPosition + 1;
431
            packetContent <=
432 45 magro732
              readContentData_i & x"00000000";
433 33 magro732
 
434
            if (readContentEnd_i = '0') then
435
              readContent_o <= '1';
436
            else
437
              readFrame_o <= '1';
438
              state <= FORWARD_LAST;
439
            end if;
440
          end if;
441
 
442
        when FORWARD_LAST =>
443
          ---------------------------------------------------------------------
444
          -- 
445
          ---------------------------------------------------------------------
446 45 magro732
          if (inboundAck_i = '1') then
447
            inboundDat_o <= packetContent(63 downto 32);
448 33 magro732
            state <= END_PACKET;
449
          end if;
450
 
451
        when END_PACKET =>
452
          ---------------------------------------------------------------------
453
          -- 
454
          ---------------------------------------------------------------------
455 45 magro732
          if (inboundAck_i = '1') then
456
            inboundCyc_o <= '0';
457
            inboundStb_o <= '0';
458 33 magro732
            state <= IDLE;
459
          end if;
460
 
461
        when others =>
462
          ---------------------------------------------------------------------
463
          -- 
464
          ---------------------------------------------------------------------
465
          state <= IDLE;
466
      end case;
467
    end if;
468
  end process;
469
 
470
end architecture;
471
 
472
 
473 47 magro732
 
474 34 magro732
-------------------------------------------------------------------------------
475
-- RioLogicalCommonEgress.
476
-- Only 8-bit and 16-bit deviceId are supported. The first write must contain
477
-- the 16-bit header, the second write must contain the destination address and
478
-- the third must contain the source address.
479 36 magro732
-- CRC is calculated during the transfer and is inserted at byte 81 and 82 and
480 34 magro732
-- appended to the packet when it ends.
481
-------------------------------------------------------------------------------
482
library ieee;
483
use ieee.std_logic_1164.all;
484
use ieee.numeric_std.all;
485
use work.rio_common.all;
486 33 magro732
 
487 47 magro732
 
488 34 magro732
-------------------------------------------------------------------------------
489
-- Entity for RioLogicalCommonEgress.
490
-------------------------------------------------------------------------------
491
entity RioLogicalCommonEgress is
492
  port(
493
    clk : in std_logic;
494
    areset_n : in std_logic;
495 33 magro732
 
496 34 magro732
    writeFrameFull_i : in std_logic;
497
    writeFrame_o : out std_logic;
498
    writeFrameAbort_o : out std_logic;
499
    writeContent_o : out std_logic;
500
    writeContentData_o : out std_logic_vector(31 downto 0);
501
 
502 45 magro732
    outboundCyc_i : in std_logic;
503
    outboundStb_i : in std_logic;
504
    outboundDat_i : in std_logic_vector(31 downto 0);
505
    outboundAck_o : out std_logic);
506 34 magro732
end entity;
507
 
508
 
509 33 magro732
-------------------------------------------------------------------------------
510 34 magro732
-- Architecture for RioLogicalCommonEgress.
511
-------------------------------------------------------------------------------
512
architecture RioLogicalCommonEgress of RioLogicalCommonEgress is
513
 
514
  component Crc16CITT is
515
    port(
516
      d_i : in  std_logic_vector(15 downto 0);
517
      crc_i : in  std_logic_vector(15 downto 0);
518
      crc_o : out std_logic_vector(15 downto 0));
519
  end component;
520
 
521 36 magro732
  type StateType is (IDLE,
522
                     HEADER_GET, HEADER_ACK,
523
                     DESTINATION_GET, DESTINATION_ACK,
524
                     SOURCE_GET, SOURCE_ACK,
525 44 magro732
                     CONTENT_GET, CONTENT_ACK,
526
                     CRC_APPEND, CRC_UPDATE, CRC_LAST, SEND_FRAME,
527 36 magro732
                     RESTART_FRAME, WAIT_UPDATE);
528
  signal state : StateType;
529 44 magro732
  signal packetPosition : natural range 0 to 69;
530 36 magro732
 
531 44 magro732
  signal temp : std_logic_vector(15 downto 0);
532
 
533 36 magro732
  signal tt : std_logic_vector(1 downto 0);
534 38 magro732
  signal dstAddr : std_logic_vector(7 downto 0);
535 37 magro732
 
536 44 magro732
  signal writeContent : std_logic;
537
  signal writeContentData1 : std_logic_vector(31 downto 0);
538
  signal writeContentData2 : std_logic_vector(31 downto 0);
539
 
540
  signal crcReset : std_logic;
541 34 magro732
  signal crc16Current, crc16Temp, crc16Next: std_logic_vector(15 downto 0);
542
 
543
begin
544
 
545 44 magro732
  writeContent_o <= writeContent;
546
  writeContentData_o <= writeContentData1;
547
 
548 37 magro732
 
549 34 magro732
  process(clk, areset_n)
550
  begin
551
    if (areset_n = '0') then
552 44 magro732
      crc16Current <= x"0000";
553
    elsif (clk'event and clk = '1') then
554
      if (crcReset = '1') then
555
        crc16Current <= x"ffff";
556
      elsif (writeContent = '1') then
557
        crc16Current <= crc16Next;
558
      end if;
559
    end if;
560
  end process;
561
 
562
  process(clk, areset_n)
563
  begin
564
    if (areset_n = '0') then
565 36 magro732
      state <= IDLE;
566 44 magro732
      packetPosition <= 0;
567 38 magro732
 
568 44 magro732
      tt <= (others=>'0');
569
      dstAddr <= (others=>'0');
570
 
571
      temp <= (others=>'0');
572
      writeContent <= '0';
573
      writeContentData1 <= (others=>'0');
574
      writeContentData2 <= (others=>'0');
575
 
576
      crcReset <= '0';
577
 
578 45 magro732
      outboundAck_o <= '0';
579 38 magro732
 
580
      writeFrame_o <= '0';
581
      writeFrameAbort_o <= '0';
582 34 magro732
    elsif (clk'event and clk = '1') then
583 44 magro732
      writeContent <= '0';
584 34 magro732
      writeFrame_o <= '0';
585
 
586 44 magro732
      crcReset <= '0';
587
 
588 34 magro732
      case state is
589
        when IDLE =>
590
          ---------------------------------------------------------------------
591
          -- 
592
          ---------------------------------------------------------------------
593 35 magro732
          packetPosition <= 0;
594 44 magro732
          crcReset <= '1';
595 34 magro732
          if (writeFrameFull_i = '0') then
596
            state <= HEADER_GET;
597
          end if;
598
 
599 36 magro732
        when HEADER_GET =>
600 34 magro732
          ---------------------------------------------------------------------
601
          -- 
602
          ---------------------------------------------------------------------
603 45 magro732
          if ((outboundCyc_i = '1') and (outboundStb_i = '1')) then
604
            temp <= outboundDat_i(15 downto 0);
605
            tt <= outboundDat_i(5 downto 4);
606 37 magro732
 
607 45 magro732
            outboundAck_o <= '1';
608 34 magro732
            state <= HEADER_ACK;
609
          else
610 38 magro732
            state <= HEADER_GET;
611 34 magro732
          end if;
612
 
613
        when HEADER_ACK =>
614
          ---------------------------------------------------------------------
615
          -- 
616
          ---------------------------------------------------------------------
617 45 magro732
          outboundAck_o <= '0';
618 34 magro732
          state <= DESTINATION_GET;
619
 
620
        when DESTINATION_GET =>
621
          ---------------------------------------------------------------------
622
          -- 
623
          ---------------------------------------------------------------------
624
 
625 45 magro732
          if ((outboundCyc_i = '1') and (outboundStb_i = '1')) then
626 44 magro732
            if (tt = "01") then
627 45 magro732
              writeContentData2 <= temp & outboundDat_i(15 downto 0);
628 34 magro732
            else
629 44 magro732
              report "TT-field not supported." severity error;
630 34 magro732
            end if;
631
 
632 45 magro732
            outboundAck_o <= '1';
633 34 magro732
            state <= DESTINATION_ACK;
634
          else
635
            state <= RESTART_FRAME;
636
          end if;
637
 
638
        when DESTINATION_ACK =>
639
          ---------------------------------------------------------------------
640
          -- 
641
          ---------------------------------------------------------------------
642 45 magro732
          outboundAck_o <= '0';
643 34 magro732
          state <= SOURCE_GET;
644
 
645
        when SOURCE_GET =>
646
          ---------------------------------------------------------------------
647
          -- 
648
          ---------------------------------------------------------------------
649
 
650 45 magro732
          if ((outboundCyc_i = '1') and (outboundStb_i = '1')) then
651 44 magro732
            if (tt = "01") then
652 45 magro732
              temp <= outboundDat_i(15 downto 0);
653 34 magro732
            end if;
654
 
655 45 magro732
            outboundAck_o <= '1';
656 34 magro732
            state <= SOURCE_ACK;
657
          else
658
            state <= RESTART_FRAME;
659
          end if;
660
 
661
        when SOURCE_ACK =>
662
          ---------------------------------------------------------------------
663
          -- 
664
          ---------------------------------------------------------------------
665 45 magro732
          outboundAck_o <= '0';
666 34 magro732
          state <= CONTENT_GET;
667
 
668
        when CONTENT_GET =>
669
          ---------------------------------------------------------------------
670
          -- 
671
          ---------------------------------------------------------------------
672 45 magro732
          if ((outboundCyc_i = '1') and (outboundStb_i = '1')) then
673 44 magro732
            if (packetPosition < 19) then
674
              if (tt = "01") then
675 45 magro732
                writeContentData2 <= temp & outboundDat_i(31 downto 16);
676
                temp <= outboundDat_i(15 downto 0);
677
                outboundAck_o <= '1';
678 44 magro732
              end if;
679
            elsif (packetPosition = 19) then
680
              if (tt = "01") then
681
                writeContentData2 <= crc16Next & temp;
682
              end if;
683 37 magro732
            else
684 44 magro732
              if (tt = "01") then
685 45 magro732
                writeContentData2 <= outboundDat_i;
686
                outboundAck_o <= '1';
687 44 magro732
              end if;
688 34 magro732
            end if;
689 44 magro732
            writeContent <= '1';
690
            writeContentData1 <= writeContentData2;
691
            packetPosition <= packetPosition + 1;
692 34 magro732
            state <= CONTENT_ACK;
693
          else
694
            state <= CRC_APPEND;
695
          end if;
696 44 magro732
 
697 34 magro732
        when CONTENT_ACK =>
698
          ---------------------------------------------------------------------
699
          -- 
700
          ---------------------------------------------------------------------
701 44 magro732
          if (packetPosition = 20) then
702
            if (tt = "01") then
703
              writeContentData2 <= crc16Next & temp;
704
            end if;
705
          end if;
706 45 magro732
          outboundAck_o <= '0';
707 44 magro732
          state <= CONTENT_GET;
708 34 magro732
 
709 44 magro732
        when CRC_APPEND =>
710
          ---------------------------------------------------------------------
711
          -- 
712
          ---------------------------------------------------------------------
713
          if (packetPosition < 19) then
714
            if (tt = "01") then
715
              writeContent <= '1';
716
              writeContentData1 <= writeContentData2;
717 34 magro732
              packetPosition <= packetPosition + 1;
718
            end if;
719 44 magro732
          elsif (packetPosition = 19) then
720
            if (tt = "01") then
721
              writeContent <= '1';
722
              writeContentData1 <= writeContentData2;
723
              packetPosition <= packetPosition + 1;
724
            end if;
725
          else
726
            if (tt = "01") then
727
              writeContentData1 <= writeContentData2(31 downto 16) & x"0000";
728
              packetPosition <= packetPosition + 1;
729
            end if;
730 34 magro732
          end if;
731 44 magro732
          state <= CRC_UPDATE;
732 34 magro732
 
733 44 magro732
        when CRC_UPDATE =>
734
          ---------------------------------------------------------------------
735
          -- 
736
          ---------------------------------------------------------------------
737
          state <= CRC_LAST;
738 34 magro732
 
739 44 magro732
        when CRC_LAST =>
740 34 magro732
          ---------------------------------------------------------------------
741
          -- 
742
          ---------------------------------------------------------------------
743 47 magro732
          if (packetPosition <= 19) then
744 44 magro732
            if (tt = "01") then
745
              writeContent <= '1';
746
              writeContentData1 <= crc16Current & x"0000";
747
            end if;
748
          else
749
            if (tt = "01") then
750
              writeContent <= '1';
751
              writeContentData1 <= writeContentData2(31 downto 16) & crc16Temp;
752
            end if;
753 34 magro732
          end if;
754 44 magro732
 
755 34 magro732
          state <= SEND_FRAME;
756 44 magro732
 
757 34 magro732
        when SEND_FRAME =>
758
          ---------------------------------------------------------------------
759
          -- 
760
          ---------------------------------------------------------------------
761
          writeFrame_o <= '1';
762
          state <= WAIT_UPDATE;
763
 
764
        when RESTART_FRAME =>
765
          ---------------------------------------------------------------------
766
          -- 
767
          ---------------------------------------------------------------------
768
          writeFrameAbort_o <= '1';
769
          state <= WAIT_UPDATE;
770
 
771
        when WAIT_UPDATE =>
772
          ---------------------------------------------------------------------
773
          -- 
774
          ---------------------------------------------------------------------
775 38 magro732
          writeFrameAbort_o <= '0';
776 34 magro732
          state <= IDLE;
777
 
778
        when others =>
779
          ---------------------------------------------------------------------
780
          -- 
781
          ---------------------------------------------------------------------
782
      end case;
783
    end if;
784
  end process;
785
 
786
  -----------------------------------------------------------------------------
787
  -- Packet CRC calculation.
788
  -----------------------------------------------------------------------------
789
 
790
  Crc16High: Crc16CITT
791
    port map(
792 44 magro732
      d_i=>writeContentData1(31 downto 16), crc_i=>crc16Current, crc_o=>crc16Temp);
793 34 magro732
  Crc16Low: Crc16CITT
794
    port map(
795 44 magro732
      d_i=>writeContentData1(15 downto 0), crc_i=>crc16Temp, crc_o=>crc16Next);
796 34 magro732
 
797
end architecture;
798 45 magro732
 
799
 
800
 
801
-------------------------------------------------------------------------------
802 47 magro732
-- RioLogicalCommonIngress.
803 45 magro732
-------------------------------------------------------------------------------
804
library ieee;
805
use ieee.std_logic_1164.all;
806
use ieee.numeric_std.all;
807
use work.rio_common.all;
808
 
809
 
810
-------------------------------------------------------------------------------
811 47 magro732
-- Entity for RioLogicalCommonInterconnect.
812 45 magro732
-------------------------------------------------------------------------------
813
entity RioLogicalCommonInterconnect is
814
  generic(
815
    WIDTH : natural);
816
  port(
817
    clk : in std_logic;
818
    areset_n : in std_logic;
819
 
820
    stb_i : in std_logic_vector(WIDTH-1 downto 0);
821
    dataM_i : in std_logic_vector(32*WIDTH-1 downto 0);
822
    ack_o : out std_logic_vector(WIDTH-1 downto 0);
823
 
824
    stb_o : out std_logic;
825
    dataS_o : out std_logic_vector(31 downto 0);
826
    ack_i : in std_logic);
827
end entity;
828
 
829
 
830
-------------------------------------------------------------------------------
831 47 magro732
-- Architecture for RioLogicalCommonInterconnect.
832 45 magro732
-------------------------------------------------------------------------------
833
architecture RioLogicalCommonInterconnectImpl of RioLogicalCommonInterconnect is
834
  signal activeCycle : std_logic;
835
  signal selectedMaster : natural range 0 to WIDTH-1;
836
begin
837
 
838
  -----------------------------------------------------------------------------
839
  -- Arbitration.
840
  -----------------------------------------------------------------------------
841
  Arbiter: process(areset_n, clk)
842
  begin
843
    if (areset_n = '0') then
844
      activeCycle <= '0';
845
      selectedMaster <= 0;
846
    elsif (clk'event and clk = '1') then
847
      if (activeCycle = '0') then
848
        for i in 0 to WIDTH-1 loop
849
          if (stb_i(i) = '1') then
850
            activeCycle <= '1';
851
            selectedMaster <= i;
852
          end if;
853
        end loop;
854
      else
855
        if (stb_i(selectedMaster) = '0') then
856
          activeCycle <= '0';
857
        end if;
858
      end if;
859
    end if;
860
  end process;
861
 
862
  -----------------------------------------------------------------------------
863
  -- Interconnection.
864
  -----------------------------------------------------------------------------
865
  stb_o <= stb_i(selectedMaster) and activeCycle;
866
  dataS_o <= dataM_i(32*(selectedMaster+1)-1 downto 32*selectedMaster);
867
 
868
  Interconnect: for i in 0 to WIDTH-1 generate
869
    ack_o(i) <= ack_i when (selectedMaster = i) else '0';
870
  end generate;
871
 
872
end architecture;
873
 
874
 

powered by: WebSVN 2.1.0

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