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 44

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

powered by: WebSVN 2.1.0

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