File: /__w/ctu-can-regression/ctu-can-regression/src/common_blocks/dp_inf_ram.vhd
0: --------------------------------------------------------------------------------
1: --
2: -- CTU CAN FD IP Core
3: -- Copyright (C) 2021-2023 Ondrej Ille
4: -- Copyright (C) 2023- Logic Design Services Ltd.s
5: --
6: -- Permission is hereby granted, free of charge, to any person obtaining a copy
7: -- of this VHDL component and associated documentation files (the "Component"),
8: -- to use, copy, modify, merge, publish, distribute the Component for
9: -- non-commercial purposes. Using the Component for commercial purposes is
10: -- forbidden unless previously agreed with Copyright holder.
11: --
12: -- The above copyright notice and this permission notice shall be included in
13: -- all copies or substantial portions of the Component.
14: --
15: -- THE COMPONENT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16: -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17: -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18: -- AUTHORS OR COPYRIGHTHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19: -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20: -- FROM, OUT OF OR IN CONNECTION WITH THE COMPONENT OR THE USE OR OTHER DEALINGS
21: -- IN THE COMPONENT.
22: --
23: -- The CAN protocol is developed by Robert Bosch GmbH and protected by patents.
24: -- Anybody who wants to implement this IP core on silicon has to obtain a CAN
25: -- protocol license from Bosch.
26: --
27: -- -------------------------------------------------------------------------------
28: --
29: -- CTU CAN FD IP Core
30: -- Copyright (C) 2015-2020 MIT License
31: --
32: -- Authors:
33: -- Ondrej Ille <ondrej.ille@gmail.com>
34: -- Martin Jerabek <martin.jerabek01@gmail.com>
35: --
36: -- Project advisors:
37: -- Jiri Novak <jnovak@fel.cvut.cz>
38: -- Pavel Pisa <pisa@cmp.felk.cvut.cz>
39: --
40: -- Department of Measurement (http://meas.fel.cvut.cz/)
41: -- Faculty of Electrical Engineering (http://www.fel.cvut.cz)
42: -- Czech Technical University (http://www.cvut.cz/)
43: --
44: -- Permission is hereby granted, free of charge, to any person obtaining a copy
45: -- of this VHDL component and associated documentation files (the "Component"),
46: -- to deal in the Component without restriction, including without limitation
47: -- the rights to use, copy, modify, merge, publish, distribute, sublicense,
48: -- and/or sell copies of the Component, and to permit persons to whom the
49: -- Component is furnished to do so, subject to the following conditions:
50: --
51: -- The above copyright notice and this permission notice shall be included in
52: -- all copies or substantial portions of the Component.
53: --
54: -- THE COMPONENT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55: -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56: -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57: -- AUTHORS OR COPYRIGHTHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58: -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
59: -- FROM, OUT OF OR IN CONNECTION WITH THE COMPONENT OR THE USE OR OTHER DEALINGS
60: -- IN THE COMPONENT.
61: --
62: -- The CAN protocol is developed by Robert Bosch GmbH and protected by patents.
63: -- Anybody who wants to implement this IP core on silicon has to obtain a CAN
64: -- protocol license from Bosch.
65: --
66: --------------------------------------------------------------------------------
67:
68: --------------------------------------------------------------------------------
69: -- Module:
70: -- Dual Port Inferred RAM
71: --
72: -- Purpose:
73: -- Dual port Memory wrapper for inferrence of RAM blocks in Intel and Xilinx
74: -- FPGAs. Port A is write only. Port B is read only. Port A interface is
75: -- synchronous. Read interface is either combinatorial (asynchronous) or
76: -- registered (synchronous). Clock is shared between the two ports. If used
77: -- on ASIC or FPGA without memories, synthesized as DFFs without Set or Reset.
78: --------------------------------------------------------------------------------
79:
80: Library ieee;
81: USE IEEE.std_logic_1164.all;
82: USE IEEE.numeric_std.ALL;
83:
84: entity dp_inf_ram is
85: generic (
86: -- Width of memory word (in bits)
87: G_WORD_WIDTH : natural := 32;
88:
89: -- Memory depth (in words)
90: G_DEPTH : natural := 32;
91:
92: -- Address width (in bits)
93: G_ADDRESS_WIDTH : natural := 8;
94:
95: -- Synchronous read
96: G_SYNC_READ : boolean := true;
97:
98: -- If true, res_n causes RAM to be reset
99: G_RESETABLE : boolean := false
100: );
101: port (
102: -------------------------------------------------------------------------------------------
103: -- Clock and Reset
104: -------------------------------------------------------------------------------------------
105: clk_sys : in std_logic;
106: res_n : in std_logic;
107:
108: -------------------------------------------------------------------------------------------
109: -- Port A - Data input
110: -------------------------------------------------------------------------------------------
111: addr_A : in std_logic_vector(G_ADDRESS_WIDTH - 1 downto 0);
112: write : in std_logic;
113: data_in : in std_logic_vector(G_WORD_WIDTH - 1 downto 0);
114:
115: -------------------------------------------------------------------------------------------
116: -- Port B - Data output
117: -------------------------------------------------------------------------------------------
118: addr_B : in std_logic_vector(G_ADDRESS_WIDTH - 1 downto 0);
119: data_out : out std_logic_vector(G_WORD_WIDTH - 1 downto 0)
120: );
121: end entity;
122:
123: architecture rtl of dp_inf_ram is
124:
125: -----------------------------------------------------------------------------------------------
126: -- Memory definition
127: -----------------------------------------------------------------------------------------------
128: type memory_type is array(0 to G_DEPTH - 1) of
129: std_logic_vector(G_WORD_WIDTH - 1 downto 0);
130: signal ram_memory : memory_type;
131:
132: signal int_read_data : std_logic_vector(G_WORD_WIDTH - 1 downto 0);
133:
134: begin
135:
136: -----------------------------------------------------------------------------------------------
137: -- RAM memory (non-resetable version)
138: -----------------------------------------------------------------------------------------------
139: ram_rst_false_gen : if (not G_RESETABLE) generate
140:
141: ram_write_process : process(clk_sys)
142: begin
143: if (rising_edge(clk_sys)) then
144: if (write = '1') then
145: ram_memory(to_integer(unsigned(addr_A))) <= data_in;
146: end if;
147: end if;
148: end process;
149:
150: end generate;
151:
152: -----------------------------------------------------------------------------------------------
153: -- RAM memory (resetable version)
154: -----------------------------------------------------------------------------------------------
155: ram_rst_true_gen : if (G_RESETABLE) generate
156:
157: ram_write_process : process(clk_sys, res_n)
158: begin
159: if (res_n = '0') then
160: ram_memory <= (others => (others => '0'));
161: elsif (rising_edge(clk_sys)) then
162: if (write = '1') then
163: ram_memory(to_integer(unsigned(addr_A))) <= data_in;
164: end if;
165: end if;
166: end process;
167:
168: end generate;
169:
170: -----------------------------------------------------------------------------------------------
171: -- Memory read access
172: -----------------------------------------------------------------------------------------------
173: int_read_data <= ram_memory(to_integer(unsigned(addr_B)));
174:
175: -- Synchronous read
176: sync_read_gen : if (G_SYNC_READ) generate
177: ram_read_process : process(clk_sys)
178: begin
179: if (rising_edge(clk_sys)) then
180: data_out <= int_read_data;
181: end if;
182: end process;
183: end generate;
184:
185: -- Asynchronous read
186: async_read_gen : if (not G_SYNC_READ) generate
187: data_out <= int_read_data;
188: end generate;
189:
190:
191: -----------------------------------------------------------------------------------------------
192: -- Assertions on size
193: -----------------------------------------------------------------------------------------------
194: -- coverage off
195: assert ((G_WORD_WIDTH = 8) or
196: (G_WORD_WIDTH = 16) or
197: (G_WORD_WIDTH = 32) or
198: (G_WORD_WIDTH = 64) or
199: (G_WORD_WIDTH = 128))
200: report "Unsupported inferred RAM word width! " &
201: "Only 8, 16, 32, 64 and 128 are allowed!"
202: severity failure;
203: -- coverage on
204:
205: end architecture;