1 |
2 |
jamro |
-- test file for log_anal.vhd
|
2 |
|
|
-- this entity tests the Logic Ananyser (LA) by recording up-counter states
|
3 |
|
|
-- for which only bit -4 is always one data_ce= data(4) or data(3)
|
4 |
|
|
-- trig_ce= data(5)
|
5 |
|
|
-- the triger value is set by the WISHBONE bus and then after all data
|
6 |
|
|
-- has been written to the internal memory the WISHBONE writes the data to la_data.bin file
|
7 |
|
|
-- which can be then read by la_view file
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
library IEEE;
|
11 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
12 |
|
|
use ieee.std_logic_unsigned.all;
|
13 |
|
|
use ieee.std_logic_arith.all;
|
14 |
|
|
|
15 |
|
|
entity la_test is
|
16 |
|
|
end la_test;
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
architecture la_test of la_test is
|
20 |
|
|
-- generic values for log_anal
|
21 |
|
|
constant data_width: integer:= 16; -- width of the data that are analysed (must be power of 2)
|
22 |
|
|
constant mem_adr_width: integer:= 9; -- internal memory address width
|
23 |
|
|
constant adr_width: integer:= 11; -- adr_I address width
|
24 |
|
|
constant trig_width: integer:= 8; -- width of the triger logic
|
25 |
|
|
constant two_clocks: integer:= 1;
|
26 |
|
|
|
27 |
|
|
constant Data_File : string := "la_data.bin"; -- a file to which acquired data are written
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
component log_anal
|
31 |
|
|
generic(data_width: integer:= 16; -- width of the data that are analysed (must be power of 2)
|
32 |
|
|
mem_adr_width: integer:= 9; -- internal memory address width
|
33 |
|
|
adr_width: integer:= 11; -- adr_I address width
|
34 |
|
|
trig_width: integer:= 8; -- width of the triger logic
|
35 |
|
|
two_clocks: integer:= 0); -- two seperate clocks for control interface and logic analyser
|
36 |
|
|
port (arst: in std_logic; -- global asynchronous set reset signal (mainly for simulation purposes)
|
37 |
|
|
-- interface for logic analyser
|
38 |
|
|
clk: in std_logic; -- seperate clock for logic analyzer
|
39 |
|
|
data: in std_logic_vector(data_width-1 downto 0); -- data that are analysied
|
40 |
|
|
ce_data: in std_logic; -- clock enable -- should be used if data are recorded e.g. every second la_clk
|
41 |
|
|
trig: in std_logic_vector(trig_width-1 downto 0); -- triger bus (can be different that data bus
|
42 |
|
|
ce_trig: in std_logic; -- clock enable for triger bus
|
43 |
|
|
-- control WISHBOBE slave interface - interface for setting logic analyser options and transfering analysed data to computer
|
44 |
|
|
wb_clk_I: in STD_LOGIC; -- clock (common for every logic every logic analyser signals) - common for loagic analyser and WISHBONE control interface
|
45 |
|
|
wb_adr_I: in std_logic_vector(adr_width-1 downto 0); -- address bus (one bit wider than mem_adr_width)
|
46 |
|
|
wb_dat_I: in std_logic_vector(7 downto 0);
|
47 |
|
|
wb_dat_O: out std_logic_vector(7 downto 0);
|
48 |
|
|
wb_stb_I, wb_we_I: in std_logic;
|
49 |
|
|
-- wb_cyc_I: in std_logic; -- signal is ignored
|
50 |
|
|
-- wb_rst_I: in std_logic; -- the WISHBONE interface need not be reseted
|
51 |
|
|
wb_ack_O: buffer std_logic);
|
52 |
|
|
end component;
|
53 |
|
|
-- signals the same as for log_anal
|
54 |
|
|
signal arst: std_logic; -- global asynchronous set reset signal (mainly for simulation purposes)
|
55 |
|
|
signal clk: std_logic; -- seperate clock for logic analyzer
|
56 |
|
|
signal data: std_logic_vector(data_width-1 downto 0); -- data that are analysied
|
57 |
|
|
signal ce_data: std_logic; -- clock enable -- should be used if data are recorded e.g. every second la_clk
|
58 |
|
|
signal trig: std_logic_vector(trig_width-1 downto 0); -- triger bus (can be different that data bus
|
59 |
|
|
signal ce_trig: std_logic; -- clock enable for triger bus
|
60 |
|
|
signal wb_clk_I: STD_LOGIC; -- clock (common for every logic every logic analyser signals) - common for loagic analyser and WISHBONE control interface
|
61 |
|
|
signal wb_adr_I: std_logic_vector(adr_width-1 downto 0); -- address bus (one bit wider than mem_adr_width)
|
62 |
|
|
signal wb_dat_I: std_logic_vector(7 downto 0);
|
63 |
|
|
signal wb_dat_O: std_logic_vector(7 downto 0);
|
64 |
|
|
signal wb_stb_I, wb_we_I: std_logic;
|
65 |
|
|
signal wb_ack_O, wb_ack_O_q: std_logic;
|
66 |
|
|
type wb_trig_reg_type is array (7 downto 0) of std_logic_vector(7 downto 0);
|
67 |
|
|
signal wb_trig_reg: wb_trig_reg_type; -- data written to the triger registers (address 8-F)
|
68 |
|
|
signal wb_status_reg: std_logic_vector(7 downto 0);
|
69 |
|
|
signal wb_access, la_data_read: integer:= 0;
|
70 |
|
|
signal la_finish: std_logic:= '0'; -- the LA has finished data acquisition
|
71 |
|
|
begin
|
72 |
|
|
UUT: log_anal
|
73 |
|
|
generic map (data_width=> data_width, mem_adr_width=>mem_adr_width,
|
74 |
|
|
adr_width=> adr_width, trig_width=> trig_width, two_clocks=> two_clocks)
|
75 |
|
|
port map (arst=> arst,
|
76 |
|
|
clk=> clk, data=> data, ce_data=> ce_data,
|
77 |
|
|
trig=>trig, ce_trig=> ce_trig,
|
78 |
|
|
wb_clk_I=> wb_clk_I, wb_adr_I=>wb_adr_I, wb_dat_I=>wb_dat_I,
|
79 |
|
|
wb_dat_O=>wb_dat_O, wb_stb_I=>wb_stb_I, wb_we_I=> wb_we_I, wb_ack_O=> wb_ack_O);
|
80 |
|
|
|
81 |
|
|
-------------------------------
|
82 |
|
|
-- clock generation
|
83 |
|
|
process begin
|
84 |
|
|
wait for 10 ns;
|
85 |
|
|
wb_clk_I<= '0';
|
86 |
|
|
wait for 10 ns;
|
87 |
|
|
wb_clk_I<= '1';
|
88 |
|
|
end process;
|
89 |
|
|
|
90 |
|
|
gclk0: if two_clocks= 0 generate
|
91 |
|
|
clk<= wb_clk_I;
|
92 |
|
|
end generate;
|
93 |
|
|
|
94 |
|
|
gclk1: if two_clocks= 1 generate
|
95 |
|
|
process begin
|
96 |
|
|
wait for 17 ns;
|
97 |
|
|
clk<= '0';
|
98 |
|
|
wait for 17 ns;
|
99 |
|
|
clk<= '1';
|
100 |
|
|
end process;
|
101 |
|
|
end generate;
|
102 |
|
|
|
103 |
|
|
arst<= '1' after 0ns, '0' after 20ns;
|
104 |
|
|
-----------------------------------------
|
105 |
|
|
-- the LA interface signals
|
106 |
|
|
-- counter
|
107 |
|
|
process(clk, arst) begin
|
108 |
|
|
if arst='1' then data<= (others=>'0');
|
109 |
|
|
elsif clk'event and clk='1' then
|
110 |
|
|
data<= data + 1 after 500ps;
|
111 |
|
|
end if;
|
112 |
|
|
end process;
|
113 |
|
|
|
114 |
|
|
ce_data<= data(4) or data(3);
|
115 |
|
|
trig<= data(trig_width-1 downto 0);
|
116 |
|
|
ce_trig<= data(5);
|
117 |
|
|
|
118 |
|
|
-------------------------------------------------------------
|
119 |
|
|
-- the WISHBONE interface
|
120 |
|
|
wb_status_reg<= "00111111"; -- triger at the end
|
121 |
|
|
wb_trig_reg(0)<= "11111111"; -- triger value
|
122 |
|
|
wb_trig_reg(4)<= "10001111"; -- triger care
|
123 |
|
|
|
124 |
|
|
wb_we_i<= '1' when wb_access<12 else '0'; -- at first write to configuration registers
|
125 |
|
|
-- wb_stb_i
|
126 |
|
|
wb_stb_i<= '0' when wb_ack_o_q='1' and (wb_access rem 7)=5 else '1'; -- only sametimes not active
|
127 |
|
|
-- wb_address
|
128 |
|
|
wb_adr_i<= conv_std_logic_vector(2**(adr_width-1) + 8 + wb_access, adr_width) -- triger register address
|
129 |
|
|
when wb_access< 8 else
|
130 |
|
|
conv_std_logic_vector(2**(adr_width-1), adr_width) when la_finish='0' else -- status register address
|
131 |
|
|
conv_std_logic_vector(la_data_read, adr_width); -- read
|
132 |
|
|
|
133 |
|
|
process(wb_clk_i)
|
134 |
|
|
-- file access variables
|
135 |
|
|
type integer_file_type is file of integer; -- data will be written to the file as integers
|
136 |
|
|
file integer_file: integer_file_type; --
|
137 |
|
|
variable data_out: std_logic_vector(31 downto 0); -- data that will be writen to the file
|
138 |
|
|
variable data_out_byte: integer:= 0; -- to which segment of 32-bit data_out the 8-bit WISHBONE bus is writting
|
139 |
|
|
variable data_out_int: integer;
|
140 |
|
|
begin
|
141 |
|
|
-- wb_dat_i
|
142 |
|
|
if wb_access<8 then wb_dat_i<= wb_trig_reg(wb_access);
|
143 |
|
|
else wb_dat_i<= wb_status_reg;
|
144 |
|
|
end if;
|
145 |
|
|
-- acctive transfer
|
146 |
|
|
if wb_clk_i='1' and wb_clk_i'event then
|
147 |
|
|
wb_ack_o_q<= wb_ack_o;
|
148 |
|
|
if wb_ack_o='1' then
|
149 |
|
|
if wb_access>=12 then
|
150 |
|
|
if la_finish='0' then
|
151 |
|
|
if wb_dat_o(6)='1' then -- check is data acquisition is finished
|
152 |
|
|
la_finish<= '1';
|
153 |
|
|
FILE_OPEN (integer_file, Data_File, WRITE_MODE);
|
154 |
|
|
end if;
|
155 |
|
|
else -- read data from internal memory and registers
|
156 |
|
|
if la_data_read< 2**(adr_width-1)+ 16 then -- not all data has been read
|
157 |
|
|
data_out_byte:= la_data_read rem 4;
|
158 |
|
|
data_out(7 + data_out_byte*8 downto data_out_byte*8):= wb_dat_o;
|
159 |
|
|
if data_out_byte=3 then -- whole 32 bits has been read
|
160 |
|
|
data_out_int:= conv_integer(data_out);
|
161 |
|
|
WRITE ( integer_file, data_out_int );
|
162 |
|
|
end if;
|
163 |
|
|
la_data_read<= la_data_read + 1;
|
164 |
|
|
else -- all data has been read
|
165 |
|
|
FILE_CLOSE ( integer_file );
|
166 |
|
|
assert false
|
167 |
|
|
report "O.K. Simulation has been finished successfully"
|
168 |
|
|
severity failure;
|
169 |
|
|
end if;
|
170 |
|
|
end if;
|
171 |
|
|
end if;
|
172 |
|
|
wb_access<= wb_access + 1; -- transfer cycle
|
173 |
|
|
end if; -- wb_ack_i='1'
|
174 |
|
|
end if;
|
175 |
|
|
end process;
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
end la_test;
|