1 |
145 |
lanttu |
-------------------------------------------------------------------------------
|
2 |
|
|
-- Title : Avalon cfg reader
|
3 |
|
|
-- Project :
|
4 |
|
|
-------------------------------------------------------------------------------
|
5 |
|
|
-- File : avalon_cfg_reader.vhd
|
6 |
|
|
-- Author : kulmala3
|
7 |
|
|
-- Created : 22.03.2005
|
8 |
|
|
-- Last update: 2011-11-10
|
9 |
|
|
-- Description: testbench block to test the config of the dma via avalon
|
10 |
|
|
-------------------------------------------------------------------------------
|
11 |
|
|
-- Copyright (c) 2005
|
12 |
|
|
-------------------------------------------------------------------------------
|
13 |
|
|
-- Revisions :
|
14 |
|
|
-- Date Version Author Description
|
15 |
|
|
-- 22.03.2005 1.0 AK Created
|
16 |
|
|
-------------------------------------------------------------------------------
|
17 |
|
|
-------------------------------------------------------------------------------
|
18 |
|
|
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
|
19 |
|
|
--
|
20 |
|
|
-- This file is part of HIBI
|
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 |
|
|
library ieee;
|
46 |
|
|
use ieee.std_logic_1164.all;
|
47 |
|
|
use ieee.std_logic_arith.all;
|
48 |
|
|
use ieee.std_logic_unsigned.all;
|
49 |
|
|
use std.textio.all;
|
50 |
|
|
use work.txt_util.all;
|
51 |
|
|
--use work.log2_pkg.all;
|
52 |
|
|
use work.tb_n2h2_pkg.all;
|
53 |
|
|
|
54 |
|
|
entity avalon_cfg_reader is
|
55 |
|
|
generic (
|
56 |
|
|
n_chans_g : integer := 0;
|
57 |
|
|
data_width_g : integer := 0;
|
58 |
|
|
conf_file_g : string := ""
|
59 |
|
|
);
|
60 |
|
|
port (
|
61 |
|
|
clk : in std_logic;
|
62 |
|
|
rst_n : in std_logic;
|
63 |
|
|
start_in : in std_logic;
|
64 |
|
|
avalon_cfg_addr_out : out std_logic_vector(log2(n_chans_g)+conf_bits_c-1 downto 0);
|
65 |
|
|
avalon_cfg_readdata_in : in std_logic_vector(data_width_g-1 downto 0);
|
66 |
|
|
avalon_cfg_re_out : out std_logic;
|
67 |
|
|
avalon_cfg_cs_out : out std_logic;
|
68 |
|
|
done_out : out std_logic
|
69 |
|
|
);
|
70 |
|
|
end avalon_cfg_reader;
|
71 |
|
|
|
72 |
|
|
architecture rtl of avalon_cfg_reader is
|
73 |
|
|
|
74 |
|
|
signal state_r : integer;
|
75 |
|
|
signal chan_counter_r : integer;
|
76 |
|
|
begin -- rtl
|
77 |
|
|
|
78 |
|
|
-----------------------------------------------------------------------------
|
79 |
|
|
-- Go through states 0-7
|
80 |
|
|
------------------------------------------------------------------------------
|
81 |
|
|
process (clk, rst_n)
|
82 |
|
|
file conf_file : text open read_mode is conf_file_g;
|
83 |
|
|
variable mem_addr_r : integer;
|
84 |
|
|
variable dst_addr_r : integer;
|
85 |
|
|
variable irq_amount_r : integer;
|
86 |
|
|
variable max_amount_r : integer;
|
87 |
|
|
begin -- process
|
88 |
|
|
if rst_n = '0' then -- asynchronous reset (active low)
|
89 |
|
|
chan_counter_r <= 0;
|
90 |
|
|
avalon_cfg_addr_out <= (others => '0');
|
91 |
|
|
avalon_cfg_re_out <= '0';
|
92 |
|
|
avalon_cfg_cs_out <= '0';
|
93 |
|
|
done_out <= '0';
|
94 |
|
|
state_r <= 0;
|
95 |
|
|
|
96 |
|
|
elsif clk'event and clk = '1' then -- rising clock edge
|
97 |
|
|
|
98 |
|
|
case state_r is
|
99 |
|
|
when 0 =>
|
100 |
|
|
if start_in = '1' then
|
101 |
|
|
state_r <= 1;
|
102 |
|
|
done_out <= '0';
|
103 |
|
|
avalon_cfg_addr_out <= conv_std_logic_vector(chan_counter_r, log2(n_chans_g)) &
|
104 |
|
|
conv_std_logic_vector(0, conf_bits_c);
|
105 |
|
|
avalon_cfg_re_out <= '1';
|
106 |
|
|
avalon_cfg_cs_out <= '1';
|
107 |
|
|
else
|
108 |
|
|
state_r <= 0;
|
109 |
|
|
end if;
|
110 |
|
|
|
111 |
|
|
when 1 =>
|
112 |
|
|
read_conf_file (
|
113 |
|
|
mem_addr => mem_addr_r ,
|
114 |
|
|
dst_addr => dst_addr_r,
|
115 |
|
|
irq_amount => irq_amount_r,
|
116 |
|
|
-- max_amount => max_amount_r,
|
117 |
|
|
file_txt => conf_file
|
118 |
|
|
);
|
119 |
|
|
|
120 |
|
|
assert avalon_cfg_readdata_in = conv_std_logic_vector(mem_addr_r, data_width_g) report "config mismatch mem addr: " & str(avalon_cfg_readdata_in) severity error;
|
121 |
|
|
|
122 |
|
|
state_r <= 2;
|
123 |
|
|
avalon_cfg_addr_out <= conv_std_logic_vector(chan_counter_r, log2(n_chans_g)) &
|
124 |
|
|
conv_std_logic_vector(1, conf_bits_c);
|
125 |
|
|
avalon_cfg_re_out <= '1';
|
126 |
|
|
avalon_cfg_cs_out <= '1';
|
127 |
|
|
|
128 |
|
|
when 2 =>
|
129 |
|
|
|
130 |
|
|
assert avalon_cfg_readdata_in = conv_std_logic_vector(dst_addr_r, data_width_g) report "config mismatch sender addr" severity error;
|
131 |
|
|
avalon_cfg_addr_out <= conv_std_logic_vector(chan_counter_r, log2(n_chans_g)) &
|
132 |
|
|
conv_std_logic_vector(2, conf_bits_c);
|
133 |
|
|
avalon_cfg_re_out <= '1';
|
134 |
|
|
avalon_cfg_cs_out <= '1';
|
135 |
|
|
|
136 |
|
|
state_r <= 3;
|
137 |
|
|
|
138 |
|
|
when 3 =>
|
139 |
|
|
|
140 |
|
|
assert avalon_cfg_readdata_in = conv_std_logic_vector(irq_amount_r, data_width_g) report "config mismatch irq amount" severity error;
|
141 |
|
|
avalon_cfg_addr_out <= conv_std_logic_vector(chan_counter_r, log2(n_chans_g)) &
|
142 |
|
|
conv_std_logic_vector(3, conf_bits_c);
|
143 |
|
|
avalon_cfg_re_out <= '1';
|
144 |
|
|
avalon_cfg_cs_out <= '1';
|
145 |
|
|
|
146 |
|
|
state_r <= 4;
|
147 |
|
|
|
148 |
|
|
when 4 =>
|
149 |
|
|
assert avalon_cfg_readdata_in = conv_std_logic_vector(mem_addr_r, data_width_g) report "config mismatch curr addr ptr" severity error;
|
150 |
|
|
avalon_cfg_addr_out <= conv_std_logic_vector(chan_counter_r, log2(n_chans_g)) &
|
151 |
|
|
conv_std_logic_vector(5, conf_bits_c);
|
152 |
|
|
avalon_cfg_re_out <= '1';
|
153 |
|
|
avalon_cfg_cs_out <= '1';
|
154 |
|
|
|
155 |
|
|
state_r <= 5;
|
156 |
|
|
|
157 |
|
|
when 5 =>
|
158 |
|
|
assert avalon_cfg_readdata_in = conv_std_logic_vector(0, data_width_g) report "config mismatch inits not reseted" severity error;
|
159 |
|
|
avalon_cfg_re_out <= '0';
|
160 |
|
|
|
161 |
|
|
state_r <= 6;
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
when 6 =>
|
165 |
|
|
avalon_cfg_cs_out <= '0';
|
166 |
|
|
chan_counter_r <= chan_counter_r+1;
|
167 |
|
|
state_r <= 7;
|
168 |
|
|
|
169 |
|
|
when 7 =>
|
170 |
|
|
if chan_counter_r = n_chans_g then
|
171 |
|
|
state_r <= 0;
|
172 |
|
|
done_out <= '1';
|
173 |
|
|
else
|
174 |
|
|
avalon_cfg_addr_out <= conv_std_logic_vector(chan_counter_r, log2(n_chans_g)) &
|
175 |
|
|
conv_std_logic_vector(0, conf_bits_c);
|
176 |
|
|
avalon_cfg_re_out <= '1';
|
177 |
|
|
avalon_cfg_cs_out <= '1';
|
178 |
|
|
state_r <= 1;
|
179 |
|
|
end if;
|
180 |
|
|
|
181 |
|
|
when others => null;
|
182 |
|
|
end case;
|
183 |
|
|
end if;
|
184 |
|
|
end process;
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
end rtl;
|