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

Subversion Repositories astron_fifo

[/] [astron_fifo/] [trunk/] [common_rl_decrease.vhd] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3 3 danv
-- Copyright 2020
4 2 danv
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6 3 danv
-- 
7
-- Licensed under the Apache License, Version 2.0 (the "License");
8
-- you may not use this file except in compliance with the License.
9
-- You may obtain a copy of the License at
10
-- 
11
--     http://www.apache.org/licenses/LICENSE-2.0
12
-- 
13
-- Unless required by applicable law or agreed to in writing, software
14
-- distributed under the License is distributed on an "AS IS" BASIS,
15
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
-- See the License for the specific language governing permissions and
17
-- limitations under the License.
18 2 danv
--
19
-------------------------------------------------------------------------------
20
 
21
-- >>> Ported from UniBoard dp_latency_adapter for fixed RL 0 --> 1
22
 
23
LIBRARY IEEE;
24
USE IEEE.std_logic_1164.ALL;
25
 
26
-- Purpose: Adapt from ready latency 1 to 0 to make a look ahead FIFO
27
-- Description: -
28
-- Remark:
29
-- . A show ahead FIFO with RL=0 does not need a rd_emp output signal, because
30
--   with RL=0 the rd_val='0' when it is empty (so emp <= NOT rd_val).
31
 
32
 
33
ENTITY common_rl_decrease IS
34
  GENERIC (
35
    g_adapt       : BOOLEAN := TRUE;    -- default when TRUE then decrease sink RL 1 to source RL 0, else then implement wires
36
    g_dat_w       : NATURAL := 18
37
  );
38
  PORT (
39
    rst           : IN  STD_LOGIC;
40
    clk           : IN  STD_LOGIC;
41
    -- ST sink: RL = 1
42
    snk_out_ready : OUT STD_LOGIC;
43
    snk_in_dat    : IN  STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
44
    snk_in_val    : IN  STD_LOGIC := 'X';
45
    -- ST source: RL = 0
46
    src_in_ready  : IN  STD_LOGIC;
47
    src_out_dat   : OUT STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
48
    src_out_val   : OUT STD_LOGIC
49
  );
50
END common_rl_decrease;
51
 
52
 
53
ARCHITECTURE rtl OF common_rl_decrease IS
54
 
55
  -- Internally use streaming record for the SOSI, for the SISO.ready directly use src_in_ready
56
  TYPE t_sosi IS RECORD  -- Source Out or Sink In
57
    data     : STD_LOGIC_VECTOR(g_dat_w-1 DOWNTO 0);
58
    valid    : STD_LOGIC;
59
  END RECORD;
60
 
61
  TYPE t_sosi_arr IS ARRAY (INTEGER RANGE <>) OF t_sosi;
62
 
63
  CONSTANT c_sosi_rst : t_sosi := ((OTHERS=>'0'), '0');
64
 
65
  -- SOSI IO  
66
  SIGNAL snk_in       : t_sosi;
67
  SIGNAL src_out      : t_sosi;
68
 
69
  -- The default FIFO has ready latency RL = 1, need to use input RL + 1 words for the buf array, to go to output RL = 0 for show ahead FIFO
70
  SIGNAL buf          : t_sosi_arr(1 DOWNTO 0);
71
  SIGNAL nxt_buf      : t_sosi_arr(1 DOWNTO 0);
72
 
73
BEGIN
74
 
75
  gen_wires : IF g_adapt=FALSE GENERATE
76
    snk_out_ready <= src_in_ready;
77
 
78
    src_out_dat   <= snk_in_dat;
79
    src_out_val   <= snk_in_val;
80
  END GENERATE;
81
 
82
  gen_adapt : IF g_adapt=TRUE GENERATE
83
    snk_in.data  <= snk_in_dat;
84
    snk_in.valid <= snk_in_val;
85
 
86
    src_out_dat <= src_out.data;
87
    src_out_val <= src_out.valid;
88
 
89
    -- Buf[0] contains the FIFO output with zero ready latency
90
    src_out <= buf(0);
91
 
92
    p_clk : PROCESS(rst, clk)
93
    BEGIN
94
      IF rst='1' THEN
95
        buf <= (OTHERS=>c_sosi_rst);
96
      ELSIF rising_edge(clk) THEN
97
        buf <= nxt_buf;
98
      END IF;
99
    END PROCESS;
100
 
101
    p_snk_out_ready : PROCESS(buf, src_in_ready, snk_in)
102
    BEGIN
103
      snk_out_ready <= '0';
104
      IF src_in_ready='1' THEN
105
        -- Default snk_out_ready when src_in_ready.
106
        snk_out_ready <= '1';
107
      ELSE
108
        -- Extra snk_out_ready to look ahead for RL = 0.
109
        IF buf(0).valid='0' THEN
110
          snk_out_ready <= '1';
111
        ELSIF buf(1).valid='0' THEN
112
          snk_out_ready <= NOT(snk_in.valid);
113
        END IF;
114
      END IF;
115
    END PROCESS;
116
 
117
    p_buf : PROCESS(buf, src_in_ready, snk_in)
118
    BEGIN
119
      -- Keep or shift the buf dependent on src_in_ready, no need to explicitly check buf().valid
120
      nxt_buf <= buf;
121
      IF src_in_ready='1' THEN
122
        nxt_buf(0) <= buf(1);
123
        nxt_buf(1).valid <= '0';  -- not strictly necessary, but robust
124
      END IF;
125
 
126
      -- Put input data at the first available location dependent on src_in_ready, no need to explicitly check snk_in_val
127
      IF buf(0).valid='0' THEN
128
        nxt_buf(0) <= snk_in;
129
      ELSE
130
        IF buf(1).valid='0' THEN
131
          IF src_in_ready='0' THEN
132
            nxt_buf(1) <= snk_in;
133
          ELSE
134
            nxt_buf(0) <= snk_in;
135
          END IF;
136
        END IF;
137
      END IF;
138
    END PROCESS;
139
  END GENERATE;
140
 
141
END rtl;

powered by: WebSVN 2.1.0

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