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

Subversion Repositories rio

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

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

Line No. Rev Author Line
1 6 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 a bridge between a RapidIO network and a Wishbone bus. Packets
10 39 magro732
-- NWRITE, NWRITER and NREAD are currently supported.
11 6 magro732
-- 
12
-- To Do:
13
-- -
14
-- 
15
-- Author(s): 
16 39 magro732
-- - Magnus Rosenius, magro732@opencores.org
17 6 magro732
-- 
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 39 magro732
-------------------------------------------------------------------------------
46
-- RioWbBridge.
47
-------------------------------------------------------------------------------
48
-- REMARK: Add support for EXTENDED_ADDRESS...
49 6 magro732
library ieee;
50
use ieee.std_logic_1164.all;
51 42 magro732
use ieee.numeric_std.all;
52 6 magro732
use work.rio_common.all;
53
 
54
-------------------------------------------------------------------------------
55 39 magro732
-- Entity for RioWbBridge.
56 6 magro732
-------------------------------------------------------------------------------
57 39 magro732
entity RioWbBridge is
58 6 magro732
  generic(
59 39 magro732
    EXTENDED_ADDRESS : natural range 0 to 2 := 0;
60 6 magro732
    DEVICE_IDENTITY : std_logic_vector(15 downto 0);
61
    DEVICE_VENDOR_IDENTITY : std_logic_vector(15 downto 0);
62
    DEVICE_REV : std_logic_vector(31 downto 0);
63
    ASSY_IDENTITY : std_logic_vector(15 downto 0);
64
    ASSY_VENDOR_IDENTITY : std_logic_vector(15 downto 0);
65 39 magro732
    ASSY_REV : std_logic_vector(15 downto 0));
66 6 magro732
  port(
67 39 magro732
    clk : in std_logic;
68
    areset_n : in std_logic;
69 6 magro732
 
70
    readFrameEmpty_i : in std_logic;
71
    readFrame_o : out std_logic;
72
    readContent_o : out std_logic;
73
    readContentEnd_i : in std_logic;
74
    readContentData_i : in std_logic_vector(31 downto 0);
75
    writeFrameFull_i : in std_logic;
76
    writeFrame_o : out std_logic;
77
    writeFrameAbort_o : out std_logic;
78
    writeContent_o : out std_logic;
79
    writeContentData_o : out std_logic_vector(31 downto 0);
80
 
81 39 magro732
    cyc_o : out std_logic;
82
    stb_o : out std_logic;
83
    we_o : out std_logic;
84
    adr_o : out std_logic_vector(16*EXTENDED_ADDRESS+30 downto 0);
85
    sel_o : out std_logic_vector(7 downto 0);
86
    dat_o : out std_logic_vector(63 downto 0);
87
    dat_i : in std_logic_vector(63 downto 0);
88
    err_i : in std_logic;
89
    ack_i : in std_logic);
90
end entity;
91 6 magro732
 
92 39 magro732
 
93 6 magro732
-------------------------------------------------------------------------------
94
-- Architecture for RioWbBridge.
95
-------------------------------------------------------------------------------
96 39 magro732
architecture RioWbBridgeImpl of RioWbBridge is
97 6 magro732
 
98 39 magro732
  component RequestClassInbound is
99
    generic(
100
      EXTENDED_ADDRESS : natural range 0 to 2 := 0);
101 6 magro732
    port(
102 39 magro732
      clk : in std_logic;
103
      areset_n : in std_logic;
104
      enable : in std_logic;
105
 
106
      ready_o : out std_logic;
107
      vc_o : out std_logic;
108
      crf_o : out std_logic;
109
      prio_o : out std_logic_vector(1 downto 0);
110
      tt_o : out std_logic_vector(1 downto 0);
111
      dstId_o : out std_logic_vector(31 downto 0);
112
      srcId_o : out std_logic_vector(31 downto 0);
113
      tid_o : out std_logic_vector(7 downto 0);
114
      address_o : out std_logic_vector(16*EXTENDED_ADDRESS+30 downto 0);
115
      length_o : out std_logic_vector(3 downto 0);
116
      select_o : out std_logic_vector(7 downto 0);
117
      done_i : in std_logic;
118
 
119
      slaveCyc_i : in std_logic;
120
      slaveStb_i : in std_logic;
121
      slaveAdr_i : in std_logic_vector(7 downto 0);
122
      slaveDat_i : in std_logic_vector(31 downto 0);
123
      slaveAck_o : out std_logic);
124 6 magro732
  end component;
125
 
126 39 magro732
  component WriteClassInbound is
127
    generic(
128
      EXTENDED_ADDRESS : natural range 0 to 2 := 0);
129
    port(
130
      clk : in std_logic;
131
      areset_n : in std_logic;
132
      enable : in std_logic;
133 6 magro732
 
134 39 magro732
      ready_o : out std_logic;
135
      vc_o : out std_logic;
136
      crf_o : out std_logic;
137
      prio_o : out std_logic_vector(1 downto 0);
138
      tt_o : out std_logic_vector(1 downto 0);
139
      dstId_o : out std_logic_vector(31 downto 0);
140
      srcId_o : out std_logic_vector(31 downto 0);
141
      tid_o : out std_logic_vector(7 downto 0);
142
      address_o : out std_logic_vector(16*EXTENDED_ADDRESS+30 downto 0);
143
      length_o : out std_logic_vector(3 downto 0);
144
      select_o : out std_logic_vector(7 downto 0);
145
      payloadSetFirst_i : in std_logic;
146
      payloadSetNext_i : in std_logic;
147
      payload_o : out std_logic_vector(31 downto 0);
148
      done_i : in std_logic;
149
 
150
      slaveCyc_i : in std_logic;
151
      slaveStb_i : in std_logic;
152
      slaveAdr_i : in std_logic_vector(7 downto 0);
153
      slaveDat_i : in std_logic_vector(31 downto 0);
154
      slaveAck_o : out std_logic);
155
  end component;
156 6 magro732
 
157 39 magro732
  component ResponseClassOutbound is
158
    port(
159
      clk : in std_logic;
160
      areset_n : in std_logic;
161
      enable : in std_logic;
162 6 magro732
 
163 39 magro732
      ready_i : in std_logic;
164
      vc_i : in std_logic;
165
      crf_i : in std_logic;
166
      prio_i : in std_logic_vector(1 downto 0);
167
      tt_i : in std_logic_vector(1 downto 0);
168
      dstid_i : in std_logic_vector(31 downto 0);
169
      srcid_i : in std_logic_vector(31 downto 0);
170
      tid_i : in std_logic_vector(7 downto 0);
171
      error_i : in std_logic;
172
      payloadPresent_i :  in std_logic;
173
      payloadLength_i : in std_logic_vector(3 downto 0);
174
      payloadWrite_i : in std_logic;
175
      payloadIndex_i : in std_logic_vector(3 downto 0);
176
      payload_i : in std_logic_vector(31 downto 0);
177
      done_o : out std_logic;
178
 
179
      masterCyc_o : out std_logic;
180
      masterStb_o : out std_logic;
181
      masterDat_o : out std_logic_vector(31 downto 0);
182
      masterAck_i : in std_logic);
183
  end component;
184 6 magro732
 
185 39 magro732
  component RioLogicalCommon is
186
    port(
187
      clk : in std_logic;
188
      areset_n : in std_logic;
189
      enable : in std_logic;
190
 
191
      readFrameEmpty_i : in std_logic;
192
      readFrame_o : out std_logic;
193
      readContent_o : out std_logic;
194
      readContentEnd_i : in std_logic;
195
      readContentData_i : in std_logic_vector(31 downto 0);
196 6 magro732
 
197 39 magro732
      writeFrameFull_i : in std_logic;
198
      writeFrame_o : out std_logic;
199
      writeFrameAbort_o : out std_logic;
200
      writeContent_o : out std_logic;
201
      writeContentData_o : out std_logic_vector(31 downto 0);
202
 
203
      masterCyc_o : out std_logic;
204
      masterStb_o : out std_logic;
205
      masterAdr_o : out std_logic_vector(7 downto 0);
206
      masterDat_o : out std_logic_vector(31 downto 0);
207
      masterAck_i : in std_logic;
208
 
209
      slaveCyc_i : in std_logic;
210
      slaveStb_i : in std_logic;
211
      slaveDat_i : in std_logic_vector(31 downto 0);
212
      slaveAck_o : out std_logic);
213
  end component;
214
 
215
--  signal configStb : std_logic;
216
--  signal configWe : std_logic;
217
--  signal configAdr : std_logic_vector(23 downto 0);
218
--  signal configDatWrite : std_logic_vector(31 downto 0);
219
--  signal configDatRead : std_logic_vector(31 downto 0);
220
--  signal configAck : std_logic;
221 6 magro732
 
222 39 magro732
--  signal componentTag : std_logic_vector(31 downto 0);
223
--  signal baseDeviceId : std_logic_vector(15 downto 0) := DEFAULT_BASE_DEVICE_ID;
224
--  signal hostBaseDeviceIdLocked : std_logic;
225
--  signal hostBaseDeviceId : std_logic_vector(15 downto 0) := (others => '1');
226
 
227
begin
228
 
229 6 magro732
  -----------------------------------------------------------------------------
230 39 magro732
  -- 
231 6 magro732
  -----------------------------------------------------------------------------
232 39 magro732
  adr_o <= adr;
233
  dat_o <= datOut;
234
 
235
  Bridge: process(clk, areset_n)
236 6 magro732
  begin
237 39 magro732
    if (areset_n = '0') then
238
      cyc_o <= '0';
239
      stb_o <= '0';
240
      we_o <= '0';
241
      adr <= (others=>'0');
242
      datOut <= (others=>'0');
243 6 magro732
 
244 39 magro732
      responseReadReady <= '0';
245
      responseWriteReady <= '0';
246
      responsePayloadWrite <= '0';
247
 
248
      requestDone <= '0';
249
 
250
      requestPayloadIndex <= (others=>'0');
251
    elsif (clk'event and clk = '1') then
252
      requestDone <= '0';
253
      responsePayloadWrite <= '0';
254
 
255
      if (responsePayloadWrite = '1') then
256
        responsePayloadIndex <= std_logic_vector(unsigned(responsePayloadIndex) + 1);
257
      end if;
258
 
259
      case state is
260 6 magro732
        when IDLE =>
261 39 magro732
          ---------------------------------------------------------------------
262
          -- 
263
          ---------------------------------------------------------------------
264
          if (requestReady = '1') then
265
            cyc_o <= '1';
266
            stb_o <= '1';
267
            we_o <= '0';
268
            adr <= requestAddress;
269
            responsePayloadPresent <= '1';
270
            state <= REQUEST_CLASS;
271
          elsif (writeReady = '1') then
272
            cyc_o <= '1';
273
            stb_o <= '1';
274
            we_o <= '1';
275
            adr <= writeAddress;
276
            datOut <= writePayload;
277
            writePayloadNext <= '1';
278
            responsePayloadPresent <= '0';
279
            state <= WRITE_CLASS;
280
          end if;
281
 
282
        when REQUEST_CLASS =>
283
          ---------------------------------------------------------------------
284
          -- 
285
          ---------------------------------------------------------------------
286
          if (ack_i = '1') then
287
            responsePayloadWrite <= '1';
288
 
289
            if (responsePayloadIndex /= requestPayloadLength) then
290
              adr <= std_logic_vector(unsigned(adr) + 1);
291
            else
292
              requestDone <= '1';
293
              cyc_o <= '0';
294
              stb_o <= '0';
295
              state <= NREAD_RESPONSE;
296
            end if;
297
--          elsif(err_i = '1') then
298
--            REMARK: Implement error indication from wb-bus...
299
          end if;
300
 
301
        when REQUEST_CLASS_RESPONSE =>
302
          ---------------------------------------------------------------------
303
          -- 
304
          ---------------------------------------------------------------------
305
          if (responseDone = '1') then
306
            responseReadReady <= '0';
307
            state <= IDLE;
308 6 magro732
          else
309 39 magro732
            responseReadReady <= '1';
310 6 magro732
          end if;
311
 
312 39 magro732
        when WRITE_CLASS =>
313
          ---------------------------------------------------------------------
314
          -- 
315
          ---------------------------------------------------------------------
316
          if (ack_i = '1') then
317
            responsePayloadWrite <= '1';
318 6 magro732
 
319 39 magro732
            if (responsePayloadIndex /= requestPayloadLength) then
320
              adr <= std_logic_vector(unsigned(configAdr) + 1);
321
              datOut <= writePayload;
322
              requestPayloadIndex <= std_logic_vector(unsigned(requestPayloadIndex) + 1);
323
            else
324
              writeDone <= '1';
325
              cyc_o <= '0';
326
              stb_o <= '0';
327
              state <= WRITE_CLASS_RESPONSE;
328
            end if;
329
          end if;
330 6 magro732
 
331 39 magro732
        when WRITE_CLASS_RESPONSE =>
332
          ---------------------------------------------------------------------
333
          -- 
334
          ---------------------------------------------------------------------
335
          if (responseDone = '1') then
336
            responseWriteReady <= '0';
337
            state <= IDLE;
338
          else
339
            responseWriteReady <= '1';
340
          end if;
341 6 magro732
 
342 39 magro732
        when others =>
343 6 magro732
 
344 39 magro732
      end case;
345
    end if;
346
  end process;
347
 
348
  -----------------------------------------------------------------------------
349
  -- 
350
  -----------------------------------------------------------------------------
351 6 magro732
 
352 39 magro732
  RequestClassInboundInst: RequestClassInbound
353
    generic map(
354
      EXTENDED_ADDRESS=>EXTENDED_ADDRESS)
355
    port map(
356
      clk=>clk,
357
      areset_n=>areset_n,
358
      enable=>enable,
359
      ready_o=>requestReady,
360
      vc_o=>requestVc,
361
      crf_o=>requestCrf,
362
      prio_o=>requestPrio,
363
      tt_o=>requestTt,
364
      dstId_o=>requestDstId,
365
      srcId_o=>requestSrcId,
366
      tid_o=>requestTid,
367
      address_o=>requestAddress,
368
      length_o=>requestPayloadLength,
369
      select_o=>requestSelect,
370
      done_i=>requestDone,
371
      slaveCyc_i=>inboundCyc,
372
      slaveStb_i=>inboundStb,
373
      slaveAdr_i=>inboundAdr,
374
      slaveDat_i=>inboundDat,
375
      slaveAck_o=>inboundAck);
376 6 magro732
 
377 39 magro732
  WriteClassInboundInst: WriteClassInbound
378
    generic map(
379
      EXTENDED_ADDRESS=>EXTENDED_ADDRESS)
380
    port map(
381
      clk=>clk,
382
      areset_n=>areset_n,
383
      enable=>enable,
384
      ready_o=>writeReady,
385
      vc_o=>writeVc,
386
      crf_o=>writeCrf,
387
      prio_o=>writePrio,
388
      tt_o=>writeTt,
389
      dstId_o=>writeDstId,
390
      srcId_o=>writeSrcId,
391
      tid_o=>writeTid,
392
      address_o=>writeAddress,
393
      length_o=>writeLength,
394
      select_o=>writeSelect,
395
      payloadSetFirst_i=>writePayloadFirst,
396
      payloadSetNext_i=>writePayloadNext,
397
      payload_o=>writePayload,
398
      done_i=>writeDone,
399
      slaveCyc_i=>inboundCyc_i,
400
      slaveStb_i=>inboundStb_i,
401
      slaveAdr_i=>inboundAdr_i,
402
      slaveDat_i=>inboundDat_i,
403
      slaveAck_o=>inboundAck_o);
404 6 magro732
 
405 39 magro732
  ResponseClassOutboundInst: ResponseClassOutbound
406
    port map(
407
      clk=>clk,
408
      areset_n=>areset_n,
409
      enable=>enable,
410
      ready_i=>responseReady,
411
      vc_i=>vc,
412
      crf_i=>crf,
413
      prio_i=>prio,
414
      tt_i=>tt,
415
      dstid_i=>srcid,
416
      srcid_i=>dstid,
417
      tid_i=>tid,
418
      error_i=>responseError,
419
      payloadPresent_i=>responsePayloadPresent,
420
      payloadLength_i=>responsePayloadLength,
421
      payloadWrite_i=>responsePayloadWrite,
422
      payloadIndex_i=>responsePayloadIndex,
423
      payload_i=>responsePayload,
424
      done_o=>responseDone,
425
      masterCyc_o=>outboundCyc,
426
      masterStb_o=>outboundStb,
427
      masterDat_o=>outboundDat,
428
      masterAck_i=>outboundAck);
429
 
430
  RioLogicalCommonInst: RioLogicalCommon
431
    port map(
432
      clk=>clk,
433
      areset_n=>areset_n,
434
      enable=>enable,
435
      readFrameEmpty_i=>readFrameEmpty_i,
436
      readFrame_o=>readFrame_o,
437
      readContent_o=>readContent_o,
438
      readContentEnd_i=>readContentEnd_i,
439
      readContentData_i=>readContentData_i,
440
      writeFrameFull_i=>writeFrameFull_i,
441
      writeFrame_o=>writeFrame_o,
442
      writeFrameAbort_o=>writeFrameAbort_o,
443
      writeContent_o=>writeContent_o,
444
      writeContentData_o=>writeContentData_o,
445
      masterCyc_o=>inboundCyc,
446
      masterStb_o=>inboundStb,
447
      masterAdr_o=>inboundAdr,
448
      masterDat_o=>inboundDat,
449
      masterAck_i=>inboundAck,
450
      slaveCyc_i=>outboundCyc,
451
      slaveStb_i=>outboundStb,
452
      slaveDat_i=>outboundDat,
453
      slaveAck_o=>outboundAck);
454 6 magro732
 
455 39 magro732
  -----------------------------------------------------------------------------
456
  -- Configuration memory.
457
  -----------------------------------------------------------------------------
458
--  memoryConfig : process(clk, areset_n)
459
--  begin
460
--    if (areset_n = '0') then
461
--      configDataRead <= (others => '0');
462
--      baseDeviceId <= DEFAULT_BASE_DEVICE_ID;
463
--      componentTag <= (others => '0');
464
--      hostBaseDeviceIdLocked <= '0';
465
--      hostBaseDeviceId <= (others => '1');
466
--    elsif (clk'event and clk = '1') then
467 6 magro732
 
468 39 magro732
--      if (configEnable = '1') then
469
--        case (configAddress) is
470
--          when x"000000" =>
471
--            -- Device Identity CAR. Read-only.
472
--            configDataRead(31 downto 16) <= DEVICE_IDENTITY;
473
--            configDataRead(15 downto 0) <= DEVICE_VENDOR_IDENTITY;
474
--          when x"000004" =>
475
--            -- Device Information CAR. Read-only.
476
--            configDataRead(31 downto 0) <= DEVICE_REV;
477
--          when x"000008" =>
478
--            -- Assembly Identity CAR. Read-only.
479
--            configDataRead(31 downto 16) <= ASSY_IDENTITY;
480
--            configDataRead(15 downto 0) <= ASSY_VENDOR_IDENTITY;
481
--          when x"00000c" =>
482
--            -- Assembly Informaiton CAR. Read-only.
483
--            -- Extended features pointer to "0000".
484
--            configDataRead(31 downto 16) <= ASSY_REV;
485
--            configDataRead(15 downto 0) <= x"0000";
486
--          when x"000010" =>
487
--            -- Processing Element Features CAR. Read-only.
488
--            -- Bridge(31), Memory(30), Processor(29), Switch(28).
489
--            configDataRead(31) <= '1';
490
--            configDataRead(30 downto 4) <= (others => '0');
491
--            configDataRead(3) <= '1';            -- support 16 bits common transport large system
492
--            configDataRead(2 downto 0) <= "001"; -- support 34 bits address
493
--          when x"000018" =>
494
--            -- Source Operations CAR. Read-only.
495
--            configDataRead(31 downto 0) <= (others => '0');
496
--          when x"00001C" =>
497
--            -- Destination Operations CAR. Read-only.
498
--            configDataRead(31 downto 16) <= (others => '0');
499
--            configDataRead(15) <= '1';
500
--            configDataRead(14) <= '1';
501
--            configDataRead(13 downto 0) <= (others => '0');
502
--          when x"00004C" =>
503
--            -- Processing Element Logical Layer Control CSR.
504
--            configDataRead(31 downto 3) <= (others => '0');
505
--            configDataRead(2 downto 0) <= "001"; -- support 34 bits address
506
--          when x"000060" =>
507
--            -- Base Device ID CSR.
508
--            -- Only valid for end point devices.
509
--            if (configWrite = '1') then
510
--              baseDeviceId <= configDataWrite(15 downto 0);
511
--            else
512
--              configDataRead(15 downto 0) <= baseDeviceId;
513
--            end if;
514
--          when x"000068" =>
515
--            -- Host Base Device ID Lock CSR.
516
--            if (configWrite = '1') then
517
--              -- Check if this field has been written before.
518
--              if (hostBaseDeviceIdLocked = '0') then
519
--                -- The field has not been written.
520
--                -- Lock the field and set the host base device id.
521
--                hostBaseDeviceIdLocked <= '1';
522
--                hostBaseDeviceId <= configDataWrite(15 downto 0);
523
--              else
524
--                -- The field has been written.
525
--                -- Check if the written data is the same as the stored.
526
--                if (hostBaseDeviceId = configDataWrite(15 downto 0)) then
527
--                  -- Same as stored, reset the value to its initial value.
528
--                  hostBaseDeviceIdLocked <= '0';
529
--                  hostBaseDeviceId <= (others => '1');
530
--                else
531
--                  -- Not writing the same as the stored value.
532
--                  -- Ignore the write.
533
--                end if;
534
--              end if;
535
--            else
536
--              configDataRead(31 downto 16) <= (others => '0');
537
--              configDataRead(15 downto 0) <= hostBaseDeviceId;
538
--            end if;
539
--          when x"00006C" =>
540
--            -- Component TAG CSR.
541
--            if (configWrite = '1') then
542
--              componentTag <= configDataWrite;
543
--            else
544
--              configDataRead <= componentTag;
545
--            end if;
546 6 magro732
 
547 39 magro732
--          when others =>
548
--            configDataRead <= (others => '0');
549
--        end case;
550
--      else
551
--        -- Config memory not enabled.
552
--      end if;
553
--    end if;
554
--  end process;
555 6 magro732
 
556 39 magro732
end architecture;
557 6 magro732
 
558
 
559 39 magro732
-------------------------------------------------------------------------------
560
-- 
561
-------------------------------------------------------------------------------
562
-- REMARK: Extended addresses are not supported yet...
563
library ieee;
564
use ieee.std_logic_1164.all;
565
use ieee.numeric_std.all;
566
use work.rio_common.all;
567 6 magro732
 
568
 
569 39 magro732
-------------------------------------------------------------------------------
570
-- 
571
-------------------------------------------------------------------------------
572
entity RequestClassInbound is
573
  generic(
574
    EXTENDED_ADDRESS : natural range 0 to 2 := 0);
575
  port(
576
    clk : in std_logic;
577
    areset_n : in std_logic;
578
    enable : in std_logic;
579 6 magro732
 
580 39 magro732
    ready_o : out std_logic;
581
    vc_o : out std_logic;
582
    crf_o : out std_logic;
583
    prio_o : out std_logic_vector(1 downto 0);
584
    tt_o : out std_logic_vector(1 downto 0);
585
    dstId_o : out std_logic_vector(31 downto 0);
586
    srcId_o : out std_logic_vector(31 downto 0);
587
    tid_o : out std_logic_vector(7 downto 0);
588
    address_o : out std_logic_vector(16*EXTENDED_ADDRESS+30 downto 0);
589
    length_o : out std_logic_vector(3 downto 0);
590
    select_o : out std_logic_vector(7 downto 0);
591
    done_i : in std_logic;
592
 
593
    slaveCyc_i : in std_logic;
594
    slaveStb_i : in std_logic;
595
    slaveAdr_i : in std_logic_vector(7 downto 0);
596
    slaveDat_i : in std_logic_vector(31 downto 0);
597
    slaveAck_o : out std_logic);
598
end entity;
599
 
600
 
601
-------------------------------------------------------------------------------
602
-- 
603
-------------------------------------------------------------------------------
604
architecture RequestClassInbound of RequestClassInbound is
605
  type StateType is (RECEIVE_PACKET, READY);
606
  signal state : StateType;
607
 
608
  signal rdsize : std_logic_vector(3 downto 0);
609
  signal wdptr : std_logic;
610
 
611
  signal slaveAck : std_logic;
612
  signal complete : std_logic;
613
 
614
  signal packetIndex : natural range 0 to 68;
615
 
616
begin
617
 
618
  slaveAck_o <= slaveAck;
619
 
620
  ready_o <= complete when (state = READY) else '0';
621
 
622
  RequestClass: process(clk, areset_n)
623
  begin
624
    if (areset_n = '0') then
625
      slaveAck <= '0';
626
 
627
      complete <= '0';
628
 
629
      vc_o <= '0';
630
      crf_o <= '0';
631
      prio_o <= "00";
632
      tt_o <= "00";
633
      address_o <= (others=>'0');
634
 
635
      rdsize <= (others=>'0');
636
      wdptr <= '0';
637
 
638
      packetIndex <= 0;
639
    elsif (clk'event and clk = '1') then
640
      case state is
641
        when RECEIVE_PACKET =>
642
          ---------------------------------------------------------------------
643
          -- This state waits for a new REQUEST class packet, receives it
644
          -- and parses it.
645
          ---------------------------------------------------------------------
646
          if (slaveCyc_i = '1') then
647
            if (slaveAck = '0') then
648
              if (slaveStb_i = '1') then
649
                if (slaveAdr_i = x"24") then
650
                  -------------------------------------------------------------
651
                  -- NREAD packet parser.
652
                  -------------------------------------------------------------
653
                  case (packetIndex) is
654
                    when 0 =>
655
                      -- x"0000" & ackid & vc & crf & prio & tt & ftype
656
                      vc_o <= slaveDat_i(9);
657
                      crf_o <= slaveDat_i(8);
658
                      prio_o <= slaveDat_i(7 downto 6);
659
                      tt_o <= slaveDat_i(5 downto 4);
660
                      packetIndex <= packetIndex + 1;
661
                    when 1 =>
662
                      -- dstid
663
                      dstId_o <= slaveDat_i;
664
                      packetIndex <= packetIndex + 1;
665
                    when 2 =>
666
                      -- srcid
667
                      srcId_o <= slaveDat_i;
668
                      packetIndex <= packetIndex + 1;
669
                    when 3 =>
670
                      -- transaction(3:0) & rdsize(3:0) & srcTID(7:0) & address(28:13)
671
                      -- REMARK: Add support for extended addresses here...
672
                      rdsize <= slaveDat_i(27 downto 24);
673
                      tid_o <= slaveDat_i(23 downto 16);
674
                      address_o(28 downto 13) <= slaveDat_i(15 downto 0);
675
                      packetIndex <= packetIndex + 1;
676
                    when 4 =>
677
                      -- address(12:0) & wdptr & xamsbs(1:0) & crc(15:0)
678
                      address_o(12 downto 0) <= slaveDat_i(31 downto 19);
679
                      wdptr <= slaveDat_i(18);
680
                      address_o(30 downto 29) <= slaveDat_i(17 downto 16);
681
                      packetIndex <= packetIndex + 1;
682
                      complete <= '1';
683
                    when others =>
684
                      -- There should be no more content in an NREAD.
685
                      -- Discard.
686
                  end case;
687 6 magro732
                end if;
688 39 magro732
                slaveAck <= '1';
689 6 magro732
              end if;
690
            else
691 39 magro732
              slaveAck <= '0';
692 6 magro732
            end if;
693
          else
694 39 magro732
            if (complete = '1') then
695
              state <= READY;
696 6 magro732
            end if;
697 39 magro732
            packetIndex <= 0;
698 6 magro732
          end if;
699
 
700 39 magro732
        when READY =>
701
          ---------------------------------------------------------------------
702
          -- Wait for the handler of the packet to signal that it has been
703
          -- processed.
704
          ---------------------------------------------------------------------
705
          if (done_i = '1') then
706
            complete <= '0';
707
            state <= RECEIVE_PACKET;
708 6 magro732
          end if;
709
 
710 39 magro732
        when others =>
711
          ---------------------------------------------------------------------
712
          -- 
713
          ---------------------------------------------------------------------
714 6 magro732
 
715 39 magro732
      end case;
716
    end if;
717
  end process;
718
 
719
  -----------------------------------------------------------------------------
720
  -- Transformation of rdsize and wdptr into length of access and byte lanes.
721
  -----------------------------------------------------------------------------
722
 
723
  process(clk, areset_n)
724
  begin
725
    if (areset_n = '0') then
726
      length_o <= 0;
727
      select_o <= (others=>'0');
728
    elsif (clk'event and clk = '1') then
729
      if (complete = '1') then
730
        if (wdptr = '0') then
731
          case rdsize is
732
            when "0000" =>
733
              length_o <= 0;
734
              select_o <= "10000000";
735
            when "0001" =>
736
              length_o <= 0;
737
              select_o <= "01000000";
738
            when "0010" =>
739
              length_o <= 0;
740
              select_o <= "00100000";
741
            when "0011" =>
742
              length_o <= 0;
743
              select_o <= "00010000";
744
            when "0100" =>
745
              length_o <= 0;
746
              select_o <= "11000000";
747
            when "0101" =>
748
              length_o <= 0;
749
              select_o <= "11100000";
750
            when "0110" =>
751
              length_o <= 0;
752
              select_o <= "00110000";
753
            when "0111" =>
754
              length_o <= 0;
755
              select_o <= "11111000";
756
            when "1000" =>
757
              length_o <= 0;
758
              select_o <= "11110000";
759
            when "1001" =>
760
              length_o <= 0;
761
              select_o <= "11111100";
762
            when "1010" =>
763
              length_o <= 0;
764
              select_o <= "11111110";
765
            when "1011" =>
766
              length_o <= 0;
767
              select_o <= "11111111";
768
            when "1100" =>
769
              length_o <= 3;
770
              select_o <= "11111111";
771
            when "1101" =>
772
              length_o <= 11;
773
              select_o <= "11111111";
774
            when "1110" =>
775
              length_o <= 19;
776
              select_o <= "11111111";
777
            when others =>
778
              length_o <= 27;
779
              select_o <= "11111111";
780
          end case;
781
        else
782
          case rdsize is
783
            when "0000" =>
784
              length_o <= 0;
785
              select_o <= "00001000";
786
            when "0001" =>
787
              length_o <= 0;
788
              select_o <= "00000100";
789
            when "0010" =>
790
              length_o <= 0;
791
              select_o <= "00000010";
792
            when "0011" =>
793
              length_o <= 0;
794
              select_o <= "00000001";
795
            when "0100" =>
796
              length_o <= 0;
797
              select_o <= "00001100";
798
            when "0101" =>
799
              length_o <= 0;
800
              select_o <= "00000111";
801
            when "0110" =>
802
              length_o <= 0;
803
              select_o <= "00000011";
804
            when "0111" =>
805
              length_o <= 0;
806
              select_o <= "00011111";
807
            when "1000" =>
808
              length_o <= 0;
809
              select_o <= "00001111";
810
            when "1001" =>
811
              length_o <= 0;
812
              select_o <= "00111111";
813
            when "1010" =>
814
              length_o <= 0;
815
              select_o <= "01111111";
816
            when "1011" =>
817
              length_o <= 1;
818
              select_o <= "11111111";
819
            when "1100" =>
820
              length_o <= 7;
821
              select_o <= "11111111";
822
            when "1101" =>
823
              length_o <= 15;
824
              select_o <= "11111111";
825
            when "1110" =>
826
              length_o <= 23;
827
              select_o <= "11111111";
828
            when others =>
829
              length_o <= 31;
830
              select_o <= "11111111";
831
          end case;
832
        end if;
833
      end if;
834
    end if;
835
  end process;
836
 
837
end architecture;
838
 
839
 
840
-------------------------------------------------------------------------------
841
-- 
842
-------------------------------------------------------------------------------
843
-- REMARK: Support inbound data with full bandwidth, not just half...
844
library ieee;
845
use ieee.std_logic_1164.all;
846
use ieee.numeric_std.all;
847
use work.rio_common.all;
848
 
849
 
850
-------------------------------------------------------------------------------
851
-- 
852
-------------------------------------------------------------------------------
853
entity WriteClassInbound is
854
  generic(
855
    EXTENDED_ADDRESS : natural range 0 to 2 := 0);
856
  port(
857
    clk : in std_logic;
858
    areset_n : in std_logic;
859
    enable : in std_logic;
860
 
861
    ready_o : out std_logic;
862
    vc_o : out std_logic;
863
    crf_o : out std_logic;
864
    prio_o : out std_logic_vector(1 downto 0);
865
    tt_o : out std_logic_vector(1 downto 0);
866
    dstId_o : out std_logic_vector(31 downto 0);
867
    srcId_o : out std_logic_vector(31 downto 0);
868
    tid_o : out std_logic_vector(7 downto 0);
869
    address_o : out std_logic_vector(16*EXTENDED_ADDRESS+30 downto 0);
870
    length_o : out std_logic_vector(3 downto 0);
871
    select_o : out std_logic_vector(7 downto 0);
872
    payloadSetFirst_i : in std_logic;
873
    payloadSetNext_i : in std_logic;
874
    payload_o : out std_logic_vector(31 downto 0);
875
    done_i : in std_logic;
876
 
877
    slaveCyc_i : in std_logic;
878
    slaveStb_i : in std_logic;
879
    slaveAdr_i : in std_logic_vector(7 downto 0);
880
    slaveDat_i : in std_logic_vector(31 downto 0);
881
    slaveAck_o : out std_logic);
882
end entity;
883
 
884
 
885
-------------------------------------------------------------------------------
886
-- 
887
-------------------------------------------------------------------------------
888
architecture WriteClassInbound of WriteClassInbound is
889
  component MemorySimpleDualPort
890
    generic(
891
      ADDRESS_WIDTH : natural := 1;
892
      DATA_WIDTH : natural := 1);
893
    port(
894
      clkA_i : in std_logic;
895
      enableA_i : in std_logic;
896
      addressA_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
897
      dataA_i : in std_logic_vector(DATA_WIDTH-1 downto 0);
898
 
899
      clkB_i : in std_logic;
900
      enableB_i : in std_logic;
901
      addressB_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
902
      dataB_o : out std_logic_vector(DATA_WIDTH-1 downto 0));
903
  end component;
904
 
905
  type StateType is (RECEIVE_PACKET, READY);
906
  signal state : StateType;
907
 
908
  signal wdptr : std_logic;
909
  signal wrsize : std_logic_vector(3 downto 0);
910
 
911
  signal slaveAck : std_logic;
912
  signal complete : std_logic;
913
 
914
  signal packetIndex : natural range 0 to 68;
915
  signal requestData : std_logic_vector(31 downto 0);
916
 
917
  signal payloadIndex : std_logic_vector(4 downto 0);
918
  signal memoryWrite : std_logic;
919
  signal memoryAddress : std_logic_vector(4 downto 0);
920
  signal memoryDataIn : std_logic_vector(63 downto 0);
921
 
922
begin
923
 
924
  slaveAck_o <= slaveAck;
925
 
926
  ready_o <= complete when (state = READY) else '0';
927
 
928
  WriteClass: process(clk, areset_n)
929
  begin
930
    if (areset_n = '0') then
931
      slaveAck <= '0';
932
 
933
      complete <= '0';
934
 
935
      vc_o <= '0';
936
      crf_o <= '0';
937
      prio_o <= "00";
938
      tt_o <= "00";
939
      tid_o <= (others=>'0');
940
 
941
      address_o <= (others=>'0');
942
 
943
      wdptr <= '0';
944
      wrsize <= (others=>'0');
945
 
946
      packetIndex <= 0;
947
 
948
      memoryWrite <= '0';
949
      memoryAddress <= (others=>'0');
950
      memoryDataIn <= (others=>'0');
951
    elsif (clk'event and clk = '1') then
952
      case state is
953
        when RECEIVE_PACKET =>
954
          ---------------------------------------------------------------------
955
          -- This state waits for a new WRITE class packet, receives it
956
          -- and parses it.
957
          ---------------------------------------------------------------------
958
          if (slaveCyc_i = '1') then
959
            if (slaveAck = '0') then
960
              if (slaveStb_i = '1') then
961
                if (slaveAdr_i = x"55") then
962
                  -------------------------------------------------------------
963
                  -- NWRITER packet parser.
964
                  -------------------------------------------------------------
965
                  -- REMARK: Add support for NWRITE without response...
966
                  case (packetIndex) is
967
                    when 0 =>
968
                      -- x"0000" & ackid & vc & crf & prio & tt & ftype
969
                      vc_o <= slaveDat_i(9);
970
                      crf_o <= slaveDat_i(8);
971
                      prio_o <= slaveDat_i(7 downto 6);
972
                      tt_o <= slaveDat_i(5 downto 4);
973
                      packetIndex <= packetIndex + 1;
974
                    when 1 =>
975
                      -- destId
976
                      dstId_o <= slaveDat_i;
977
                      packetIndex <= packetIndex + 1;
978
                    when 2 =>
979
                      -- srcId
980
                      srcId_o <= slaveDat_i;
981
                      packetIndex <= packetIndex + 1;
982
                    when 3 =>
983
                      -- transaction & wrsize & srcTID & address(28:13)
984
                      -- REMARK: Add support for extended addresses here...
985
                      wrsize <= slaveDat_i(27 downto 24);
986
                      tid_o <= slaveDat_i(23 downto 16);
987
                      address_o(28 downto 13) <= slaveDat_i(15 downto 0);
988
                      packetIndex <= packetIndex + 1;
989
                    when 4 =>
990
                      -- address(12:0) & wdptr & xamsbs(1:0) & double-word(63:48)
991
                      address_o(12 downto 0) <= slaveDat_i(31 downto 19);
992
                      wdptr <= slaveDat_i(18);
993
                      doubleWord(63 downto 48) <= slaveDat_i(15 downto 0);
994
                      packetIndex <= packetIndex + 1;
995
                    when 5 | 7 | 9 | 11 | 13 | 15 | 17 | 19 | 21 | 23 | 25 | 27 | 29 | 31  | 33 | 35 |
996
                      37 | 39 | 41 | 43 | 45 | 47 | 49 | 51 | 53 | 55 | 57 | 59 | 61 | 63 | 65 | 67 =>
997
                      -- double-word(47:16)
998
                      doubleWord(31 downto 16) <= slaveDat_i(15 downto 0);
999
                      packetIndex <= packetIndex + 1;
1000
                    when 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32  | 34 |
1001
                      36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 =>
1002
                      -- double-word(15:0) & double-word(63:48)
1003
                      doubleWord(63 downto 48) <= slaveDat_i(15 downto 0);
1004
                      packetIndex <= packetIndex + 1;
1005
 
1006
                      memoryWrite <= '1';
1007
                      memoryDataIn <= doubleWord(63 downto 16) & slaveDat_i(31 downto 16);
1008
                      complete <= '1';
1009
                    when others =>
1010
                      -- There should be no more content in an NWRITE request.
1011
                      -- Discard.
1012
                  end case;
1013 6 magro732
                end if;
1014 39 magro732
                slaveAck <= '1';
1015 6 magro732
              end if;
1016
            else
1017 39 magro732
              if (memoryWrite = '1') then
1018
                memoryAddress <= std_logic_vector(unsigned(memoryAddress) + 1);
1019
              end if;
1020
 
1021
              memoryWrite <= '0';
1022
              slaveAck <= '0';
1023 6 magro732
            end if;
1024
          else
1025 39 magro732
            if (complete = '1') then
1026
              state <= READY;
1027
            end if;
1028
            packetIndex <= 0;
1029
            memoryAddress <= (others=>'0');
1030 6 magro732
          end if;
1031
 
1032 39 magro732
        when READY =>
1033
          ---------------------------------------------------------------------
1034
          -- Wait for the handler of the packet to signal that it has been
1035
          -- processed.
1036
          ---------------------------------------------------------------------
1037
          if (done_i = '1') then
1038
            complete <= '0';
1039
            state <= RECEIVE_PACKET;
1040 6 magro732
          end if;
1041
 
1042
        when others =>
1043 39 magro732
          ---------------------------------------------------------------------
1044
          -- 
1045
          ---------------------------------------------------------------------
1046 6 magro732
 
1047
      end case;
1048 39 magro732
    end if;
1049
  end process;
1050 6 magro732
 
1051 39 magro732
  -----------------------------------------------------------------------------
1052
  -- Transformation of wrsize and wdptr into length of access and byte lanes.
1053
  -----------------------------------------------------------------------------
1054
 
1055
  process(clk, areset_n)
1056
  begin
1057
    if (areset_n = '0') then
1058
      length_o <= 0;
1059
      select_o <= (others=>'0');
1060
    elsif (clk'event and clk = '1') then
1061
      if (complete = '1') then
1062
        if (wdptr = '0') then
1063
          case wrsize is
1064
            when "0000" =>
1065
              length_o <= 0;
1066
              select_o <= "10000000";
1067
            when "0001" =>
1068
              length_o <= 0;
1069
              select_o <= "01000000";
1070
            when "0010" =>
1071
              length_o <= 0;
1072
              select_o <= "00100000";
1073
            when "0011" =>
1074
              length_o <= 0;
1075
              select_o <= "00010000";
1076
            when "0100" =>
1077
              length_o <= 0;
1078
              select_o <= "11000000";
1079
            when "0101" =>
1080
              length_o <= 0;
1081
              select_o <= "11100000";
1082
            when "0110" =>
1083
              length_o <= 0;
1084
              select_o <= "00110000";
1085
            when "0111" =>
1086
              length_o <= 0;
1087
              select_o <= "11111000";
1088
            when "1000" =>
1089
              length_o <= 0;
1090
              select_o <= "11110000";
1091
            when "1001" =>
1092
              length_o <= 0;
1093
              select_o <= "11111100";
1094
            when "1010" =>
1095
              length_o <= 0;
1096
              select_o <= "11111110";
1097
            when "1011" =>
1098
              length_o <= 0;
1099
              select_o <= "11111111";
1100
            when others =>
1101
              length_o <= memoryAddress;
1102
              select_o <= "11111111";
1103
          end case;
1104
        else
1105
          case wrsize is
1106
            when "0000" =>
1107
              length_o <= 0;
1108
              select_o <= "00001000";
1109
            when "0001" =>
1110
              length_o <= 0;
1111
              select_o <= "00000100";
1112
            when "0010" =>
1113
              length_o <= 0;
1114
              select_o <= "00000010";
1115
            when "0011" =>
1116
              length_o <= 0;
1117
              select_o <= "00000001";
1118
            when "0100" =>
1119
              length_o <= 0;
1120
              select_o <= "00001100";
1121
            when "0101" =>
1122
              length_o <= 0;
1123
              select_o <= "00000111";
1124
            when "0110" =>
1125
              length_o <= 0;
1126
              select_o <= "00000011";
1127
            when "0111" =>
1128
              length_o <= 0;
1129
              select_o <= "00011111";
1130
            when "1000" =>
1131
              length_o <= 0;
1132
              select_o <= "00001111";
1133
            when "1001" =>
1134
              length_o <= 0;
1135
              select_o <= "00111111";
1136
            when "1010" =>
1137
              length_o <= 0;
1138
              select_o <= "01111111";
1139
            when others =>
1140
              length_o <= memoryAddress;
1141
              select_o <= "11111111";
1142
          end case;
1143
        end if;
1144
      end if;
1145 6 magro732
    end if;
1146 39 magro732
  end process;
1147 6 magro732
 
1148
  -----------------------------------------------------------------------------
1149 39 magro732
  -- Payload content memory.
1150 6 magro732
  -----------------------------------------------------------------------------
1151 39 magro732
  process(clk, areset_n)
1152 6 magro732
  begin
1153
    if (areset_n = '0') then
1154 39 magro732
      payloadIndex <= (others=>'0');
1155 6 magro732
    elsif (clk'event and clk = '1') then
1156 39 magro732
      if (payloadSetFirst_i = '1') then
1157
        payloadIndex <= (others=>'0');
1158
      elsif (payloadSetNext_i = '1') then
1159
        payloadIndex <= std_logic_vector(unsigned(payloadIndex) + 1);
1160
      end if;
1161
    end if;
1162
  end process;
1163
 
1164
  PayloadMemory: MemorySimpleDualPort
1165
    generic map(ADDRESS_WIDTH=>5, DATA_WIDTH=>64)
1166
    port map(clkA_i=>clk,
1167
             enableA_i=>memoryWrite,
1168
             addressA_i=>memoryAddress,
1169
             dataA_i=>memoryDataIn,
1170
             clkB_i=>clk,
1171
             enableB_i=>enable,
1172
             addressB_i=>payloadIndex,
1173
             dataB_o=>payload_o);
1174 6 magro732
 
1175 39 magro732
end architecture;
1176
 
1177
 
1178
 
1179
-------------------------------------------------------------------------------
1180
-- 
1181
-------------------------------------------------------------------------------
1182
library ieee;
1183
use ieee.std_logic_1164.all;
1184
use ieee.numeric_std.all;
1185
use work.rio_common.all;
1186
 
1187
-------------------------------------------------------------------------------
1188
-- 
1189
-------------------------------------------------------------------------------
1190
entity ResponseClassOutbound is
1191
  port(
1192
    clk : in std_logic;
1193
    areset_n : in std_logic;
1194
    enable : in std_logic;
1195
 
1196
    ready_i : in std_logic;
1197
    vc_i : in std_logic;
1198
    crf_i : in std_logic;
1199
    prio_i : in std_logic_vector(1 downto 0);
1200
    tt_i : in std_logic_vector(1 downto 0);
1201
    dstid_i : in std_logic_vector(31 downto 0);
1202
    srcid_i : in std_logic_vector(31 downto 0);
1203
    tid_i : in std_logic_vector(7 downto 0);
1204
    error_i : in std_logic;
1205
    payloadPresent_i :  in std_logic;
1206
    payloadLength_i : in std_logic_vector(3 downto 0);
1207
    payloadWrite_i : in std_logic;
1208
    payloadIndex_i : in std_logic_vector(3 downto 0);
1209
    payload_i : in std_logic_vector(31 downto 0);
1210
    done_o : out std_logic;
1211
 
1212
    masterCyc_o : out std_logic;
1213
    masterStb_o : out std_logic;
1214
    masterDat_o : out std_logic_vector(31 downto 0);
1215
    masterAck_i : in std_logic);
1216
end entity;
1217
 
1218
 
1219
-------------------------------------------------------------------------------
1220
-- 
1221
-------------------------------------------------------------------------------
1222
architecture ResponseClassOutbound of ResponseClassOutbound is
1223
  component MemorySimpleDualPort
1224
    generic(
1225
      ADDRESS_WIDTH : natural := 1;
1226
      DATA_WIDTH : natural := 1);
1227
    port(
1228
      clkA_i : in std_logic;
1229
      enableA_i : in std_logic;
1230
      addressA_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
1231
      dataA_i : in std_logic_vector(DATA_WIDTH-1 downto 0);
1232
 
1233
      clkB_i : in std_logic;
1234
      enableB_i : in std_logic;
1235
      addressB_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
1236
      dataB_o : out std_logic_vector(DATA_WIDTH-1 downto 0));
1237
  end component;
1238
 
1239
  type StateType is (WAIT_PACKET,
1240
                     READ_RESPONSE, WRITE_RESPONSE,
1241
                     WAIT_COMPLETE, RESPONSE_DONE);
1242
  signal state : StateType;
1243
 
1244
  signal packetIndex : natural range 0 to 65;
1245
  signal header : std_logic_vector(31 downto 0);
1246
  signal payload : std_logic_vector(63 downto 0);
1247
  signal payloadIndex : std_logic_vector(4 downto 0);
1248
 
1249
  signal memoryEnable : std_logic;
1250
  signal memoryAddress : std_logic_vector(4 downto 0);
1251
  signal memoryDataRead : std_logic_vector(63 downto 0);
1252
 
1253
begin
1254
 
1255
  header <= x"0000" & "000000" & vc_i & crf_i & prio_i & tt_i & x"d";
1256
 
1257
  Response: process(clk, areset_n)
1258
  begin
1259
    if (areset_n = '0') then
1260
      masterCyc_o <= '0';
1261
      masterStb_o <= '0';
1262
 
1263
      memoryEnable <= '0';
1264
      memoryAddress <= (others=>'0');
1265
 
1266
      payloadIndex <= (others=>'0');
1267
      done_o <= '0';
1268
 
1269
      state <= WAIT_PACKET;
1270
    elsif (clk'event and clk = '1') then
1271
      if (enable = '1') then
1272
        case state is
1273
          when WAIT_PACKET =>
1274
            -------------------------------------------------------------------
1275
            -- 
1276
            -------------------------------------------------------------------
1277
            if (ready_i = '1') then
1278
              masterCyc_o <= '1';
1279
              masterStb_o <= '1';
1280
              masterDat_o <= responseHeader;
1281
 
1282
              packetIndex <= 1;
1283
 
1284
              memoryEnable <= '1';
1285
              memoryAddress <= (others=>'0');
1286
 
1287
              payloadIndex <= (others=>'0');
1288
              state <= SEND_RESPONSE;
1289 6 magro732
            end if;
1290 39 magro732
 
1291
          when SEND_RESPONSE =>
1292
            ---------------------------------------------------------------------
1293
            -- 
1294
            ---------------------------------------------------------------------
1295
            if (masterAck_i = '1') then
1296
              case (packetIndex) is
1297
                when 1 =>
1298
                  -- destination
1299
                  masterDat_o <= dstId_i;
1300
                  packetIndex <= packetIndex + 1;
1301
                when 2 =>
1302
                  -- source 
1303
                  masterDat_o <= srcId_i;
1304
                  packetIndex <= packetIndex + 1;
1305
                when 3 =>
1306
                  -- transaction & status & targetTID & double-word0(63:48)
1307
                  if (error_i = '0') then
1308
                    if (payloadPresent_i = '0') then
1309
                      masterDat_o <= "0000" & "0000" & tid_i & x"0000";
1310
                      state <= WAIT_COMPLETE;
1311
                    else
1312 42 magro732
                      masterDat_o <= "1000" & "0000" & tid_i & memoryDataRead(63 downto 48);
1313 39 magro732
                    end if;
1314
                  else
1315
                    masterDat_o <= "0000" & "0111" & tid_i & x"0000";
1316
                    state <= WAIT_COMPLETE;
1317
                  end if;
1318
                  packetIndex <= packetIndex + 1;
1319
                when 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 |
1320
                  36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 =>
1321
                  -- double-wordN(47:16)
1322
                  masterDat_o <= memoryDataRead(47 downto 16);
1323
                  responsePayload <= memoryDataRead(15 downto 0);
1324
                  memoryAddress <= std_logic_vector(unsigned(memoryAddress) + 1);
1325
                  packetIndex <= packetIndex + 1;
1326
                when 5 | 7 | 9 | 11 | 13 | 15 | 17 | 19 | 21 | 23 | 25 | 27 | 29 | 31 | 33 | 35 |
1327
                  37 | 39 | 41 | 43 | 45 | 47 | 49 | 51 | 53 | 55 | 57 | 59 | 61 | 63 | 65 | 67 =>
1328
                  -- double-wordN(15:0) & double-wordN(63:48)
1329
                  masterDat_o <= responsePayload & memoryDataRead(31 downto 16);
1330
                  packetIndex <= packetIndex + 1;
1331
 
1332
                  responsePayloadIndex <=
1333
                    std_logic_vector(unsigned(responsePayloadIndex) + 1);
1334
 
1335
                  if (responsePayloadIndex = responsePayloadLength_i) then
1336
                    state <= WAIT_COMPLETE;
1337
                  else
1338
                    packetIndex <= packetIndex + 1;
1339
                  end if;
1340
                when others =>
1341
                  -- Unallowed response length.
1342
                  -- Dont do anything.
1343
              end case;
1344 6 magro732
            end if;
1345 39 magro732
 
1346
          when WAIT_COMPLETE =>
1347
            -------------------------------------------------------------------
1348
            -- 
1349
            -------------------------------------------------------------------
1350
            if (masterAck_i = '1') then
1351
              masterCyc_o <= '0';
1352
              masterStb_o <= '0';
1353
              state <= RESPONSE_DONE;
1354
            end if;
1355
 
1356
          when RESPONSE_DONE =>
1357
            ---------------------------------------------------------------------
1358
            -- 
1359
            ---------------------------------------------------------------------
1360
            memoryEnable <= '0';
1361
            if (ready_i = '0') then
1362
              state <= WAIT_PACKET;
1363
              done_o <= '0';
1364 6 magro732
            else
1365 39 magro732
              done_o <= '1';
1366 6 magro732
            end if;
1367 39 magro732
 
1368 6 magro732
          when others =>
1369 39 magro732
            ---------------------------------------------------------------------
1370
            -- 
1371
            ---------------------------------------------------------------------
1372
            state <= WAIT_PACKET;
1373
 
1374 6 magro732
        end case;
1375
      end if;
1376
    end if;
1377
  end process;
1378
 
1379
  -----------------------------------------------------------------------------
1380 39 magro732
  -- Payload content memory.
1381 6 magro732
  -----------------------------------------------------------------------------
1382 39 magro732
  PayloadMemory: MemorySimpleDualPort
1383
    generic map(ADDRESS_WIDTH=>5, DATA_WIDTH=>64)
1384
    port map(clkA_i=>clk,
1385
             enableA_i=>payloadWrite_i,
1386
             addressA_i=>payloadIndex_i,
1387
             dataA_i=>payload_i,
1388
             clkB_i=>clk,
1389
             enableB_i=>memoryEnable,
1390
             addressB_i=>memoryAddress,
1391
             dataB_o=>memoryDataRead);
1392 6 magro732
 
1393
end architecture;

powered by: WebSVN 2.1.0

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