| 1 |
46 |
budinero |
-------------------------------------------------------------------------------------------------100
|
| 2 |
|
|
--| Modular Oscilloscope
|
| 3 |
|
|
--| UNSL - Argentine
|
| 4 |
|
|
--|
|
| 5 |
|
|
--| File: ctrl_pkg.vhd
|
| 6 |
|
|
--| Version: 0.1
|
| 7 |
|
|
--| Tested in: Actel A3PE1500
|
| 8 |
|
|
--|-------------------------------------------------------------------------------------------------
|
| 9 |
|
|
--| Description:
|
| 10 |
|
|
--| CONTROL - Package
|
| 11 |
|
|
--| Package for instantiate Control modules.
|
| 12 |
|
|
--|
|
| 13 |
|
|
--|-------------------------------------------------------------------------------------------------
|
| 14 |
|
|
--| File history:
|
| 15 |
|
|
--| 0.01 | jul-2009 | First incomplete
|
| 16 |
|
|
--| 0.1 | aug-2009 | First incomplete
|
| 17 |
|
|
----------------------------------------------------------------------------------------------------
|
| 18 |
|
|
--| Copyright © 2009, Facundo Aguilera.
|
| 19 |
|
|
--|
|
| 20 |
|
|
--| This VHDL design file is an open design; you can redistribute it and/or
|
| 21 |
|
|
--| modify it and/or implement it after contacting the author.
|
| 22 |
|
|
----------------------------------------------------------------------------------------------------
|
| 23 |
|
|
|
| 24 |
|
|
|
| 25 |
|
|
|
| 26 |
|
|
-- Bloque completo
|
| 27 |
|
|
library IEEE;
|
| 28 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
| 29 |
|
|
use ieee.math_real.all;
|
| 30 |
|
|
|
| 31 |
|
|
package ctrl_pkg is
|
| 32 |
|
|
--------------------------------------------------------------------------------------------------
|
| 33 |
|
|
-- Componentes
|
| 34 |
|
|
|
| 35 |
|
|
component generic_decoder is
|
| 36 |
|
|
generic(
|
| 37 |
|
|
INPUT_WIDTH: integer := 5 -- Input with for decoder (decodes INPUT_WIDTH to 2^INPUT_WIDTH)
|
| 38 |
|
|
);
|
| 39 |
|
|
Port(
|
| 40 |
|
|
enable_I: in std_logic;
|
| 41 |
|
|
data_I: in std_logic_vector(INPUT_WIDTH-1 downto 0);
|
| 42 |
|
|
decoded_O: out std_logic_vector( integer(2**real(INPUT_WIDTH))-1 downto 0)
|
| 43 |
|
|
);
|
| 44 |
|
|
end component generic_decoder;
|
| 45 |
|
|
|
| 46 |
|
|
|
| 47 |
|
|
component generic_counter is
|
| 48 |
|
|
generic(
|
| 49 |
|
|
OUTPUT_WIDTH: integer := 32 -- Output width for counter.
|
| 50 |
|
|
);
|
| 51 |
|
|
port(
|
| 52 |
|
|
clk_I: in std_logic;
|
| 53 |
|
|
count_O: out std_logic_vector( OUTPUT_WIDTH downto 0);
|
| 54 |
|
|
reset_I: in std_logic;
|
| 55 |
|
|
enable_I: in std_logic
|
| 56 |
|
|
);
|
| 57 |
|
|
end component generic_counter;
|
| 58 |
|
|
|
| 59 |
|
|
component ctrl_output_manager is
|
| 60 |
|
|
generic(
|
| 61 |
|
|
MEM_ADD_WIDTH: integer := 14
|
| 62 |
|
|
);
|
| 63 |
|
|
port(
|
| 64 |
|
|
------------------------------------------------------------------------------------------------
|
| 65 |
|
|
-- MASTER (to memory)
|
| 66 |
|
|
DAT_I_mem: in std_logic_vector (15 downto 0);
|
| 67 |
|
|
--DAT_O_mem: out std_logic_vector (15 downto 0);
|
| 68 |
|
|
ADR_O_mem: out std_logic_vector (MEM_ADD_WIDTH - 1 downto 0);
|
| 69 |
|
|
CYC_O_mem: out std_logic;
|
| 70 |
|
|
STB_O_mem: out std_logic;
|
| 71 |
|
|
ACK_I_mem: in std_logic ;
|
| 72 |
|
|
WE_O_mem: out std_logic;
|
| 73 |
|
|
------------------------------------------------------------------------------------------------
|
| 74 |
|
|
-- SLAVE (to I/O ports)
|
| 75 |
|
|
--DAT_I_port: in std_logic_vector (15 downto 0);
|
| 76 |
|
|
DAT_O_port: out std_logic_vector (15 downto 0);
|
| 77 |
|
|
--ADR_I_port: in std_logic_vector (7 downto 0);
|
| 78 |
|
|
CYC_I_port: in std_logic;
|
| 79 |
|
|
STB_I_port: in std_logic;
|
| 80 |
|
|
ACK_O_port: out std_logic ;
|
| 81 |
|
|
WE_I_port: in std_logic;
|
| 82 |
|
|
------------------------------------------------------------------------------------------------
|
| 83 |
|
|
-- Common signals
|
| 84 |
|
|
RST_I: in std_logic;
|
| 85 |
|
|
CLK_I: in std_logic;
|
| 86 |
|
|
------------------------------------------------------------------------------------------------
|
| 87 |
|
|
-- Internal
|
| 88 |
|
|
load_I: in std_logic;
|
| 89 |
|
|
-- load initial address
|
| 90 |
|
|
enable_I: in std_logic;
|
| 91 |
|
|
-- continue reading from the actual address ('0' means pause, '1' means continue)
|
| 92 |
|
|
initial_address_I: in std_logic_vector (MEM_ADD_WIDTH - 1 downto 0);
|
| 93 |
|
|
-- buffer starts and ends here
|
| 94 |
|
|
biggest_address_I: in std_logic_vector (MEM_ADD_WIDTH - 1 downto 0);
|
| 95 |
|
|
-- when the buffer arrives here, address is changed to 0 (buffer size)
|
| 96 |
|
|
pause_address_I: in std_logic_vector (MEM_ADD_WIDTH - 1 downto 0);
|
| 97 |
|
|
-- address wich is being writed by control
|
| 98 |
|
|
finish_O: out std_logic
|
| 99 |
|
|
-- this is set when communication ends and remains until next restart or actual address change
|
| 100 |
|
|
);
|
| 101 |
|
|
end component ctrl_output_manager;
|
| 102 |
|
|
|
| 103 |
|
|
component ctrl_memory_writer is
|
| 104 |
|
|
generic(
|
| 105 |
|
|
MEM_ADD_WIDTH: integer := 14
|
| 106 |
|
|
);
|
| 107 |
|
|
port(
|
| 108 |
|
|
----------------------------------------------------------------------------------------------
|
| 109 |
|
|
-- to memory
|
| 110 |
|
|
DAT_O_mem: out std_logic_vector (15 downto 0);
|
| 111 |
|
|
ADR_O_mem: out std_logic_vector (MEM_ADD_WIDTH - 1 downto 0);
|
| 112 |
|
|
CYC_O_mem: out std_logic;
|
| 113 |
|
|
STB_O_mem: out std_logic;
|
| 114 |
|
|
ACK_I_mem: in std_logic ;
|
| 115 |
|
|
WE_O_mem: out std_logic;
|
| 116 |
|
|
----------------------------------------------------------------------------------------------
|
| 117 |
|
|
-- to acquistion module
|
| 118 |
|
|
DAT_I_adc: in std_logic_vector (15 downto 0);
|
| 119 |
|
|
-- Using an address generator, commented
|
| 120 |
|
|
-- ADR_O_adc: out std_logic_vector (ADC_ADD_WIDTH - 1 downto 0);
|
| 121 |
|
|
CYC_O_adc: out std_logic;
|
| 122 |
|
|
STB_O_adc: out std_logic;
|
| 123 |
|
|
ACK_I_adc: in std_logic ;
|
| 124 |
48 |
budinero |
--WE_O_adc: out std_logic;
|
| 125 |
46 |
budinero |
----------------------------------------------------------------------------------------------
|
| 126 |
|
|
-- Common signals
|
| 127 |
|
|
RST_I: in std_logic;
|
| 128 |
|
|
CLK_I: in std_logic;
|
| 129 |
|
|
----------------------------------------------------------------------------------------------
|
| 130 |
|
|
-- Internal
|
| 131 |
|
|
-- reset memory address to 0
|
| 132 |
|
|
reset_I: in std_logic;
|
| 133 |
|
|
-- read in clk edge from the actual address ('0' means pause, '1' means continue)
|
| 134 |
|
|
enable_I: in std_logic;
|
| 135 |
|
|
final_address_I: in std_logic_vector (MEM_ADD_WIDTH - 1 downto 0);
|
| 136 |
|
|
-- it is set when communication ends and remains until next restart or actual address change
|
| 137 |
|
|
finished_O: out std_logic;
|
| 138 |
|
|
-- when counter finishes, restart
|
| 139 |
48 |
budinero |
continuous_I: in std_logic
|
| 140 |
46 |
budinero |
);
|
| 141 |
|
|
end component ctrl_memory_writer;
|
| 142 |
|
|
|
| 143 |
|
|
|
| 144 |
|
|
component ctrl_data_skipper is
|
| 145 |
|
|
generic(
|
| 146 |
|
|
-- max losses = 2**(2**SELECTOR_WIDTH). (i.e., if SELECTOR_WIDTH = 5: 4.2950e+09)
|
| 147 |
|
|
SELECTOR_WIDTH: integer := 5
|
| 148 |
|
|
);
|
| 149 |
|
|
port(
|
| 150 |
|
|
-- enable output signal
|
| 151 |
|
|
ack_O: out std_logic;
|
| 152 |
|
|
-- sinal from wishbone interface
|
| 153 |
|
|
ack_I, stb_I: in std_logic;
|
| 154 |
|
|
-- selector from register, equation: losses = 2**(selector_I + 1) * enable_skipper_I
|
| 155 |
|
|
selector_I: in std_logic_vector(SELECTOR_WIDTH-1 downto 0);
|
| 156 |
|
|
-- enable from register
|
| 157 |
|
|
enable_skipper_I: in std_logic;
|
| 158 |
|
|
-- common signals
|
| 159 |
|
|
reset_I, clk_I: in std_logic;
|
| 160 |
|
|
-- set when returns to the first channel
|
| 161 |
|
|
first_channel_I: in std_logic
|
| 162 |
|
|
);
|
| 163 |
|
|
end component ctrl_data_skipper;
|
| 164 |
|
|
|
| 165 |
|
|
|
| 166 |
|
|
component ctrl_channel_selector is
|
| 167 |
|
|
generic(
|
| 168 |
|
|
CHANNEL_WIDTH: integer := 4 -- number of channels 2**CHANNEL_WIDTH, max. 4
|
| 169 |
|
|
);
|
| 170 |
|
|
port(
|
| 171 |
|
|
channels_I: in std_logic_vector(integer(2**real(CHANNEL_WIDTH))-1 downto 0);
|
| 172 |
54 |
budinero |
channel_number_O: out std_logic_vector(CHANNEL_WIDTH - 1 downto 0);
|
| 173 |
46 |
budinero |
first_channel_O: out std_logic;
|
| 174 |
|
|
clk_I: in std_logic;
|
| 175 |
|
|
enable_I: in std_logic;
|
| 176 |
|
|
reset_I: in std_logic
|
| 177 |
|
|
);
|
| 178 |
|
|
end component ctrl_channel_selector;
|
| 179 |
|
|
|
| 180 |
|
|
|
| 181 |
|
|
component ctrl_trigger_manager is
|
| 182 |
|
|
generic (
|
| 183 |
|
|
MEM_ADD_WIDTH: integer := 14;
|
| 184 |
|
|
DATA_WIDTH: integer := 10;
|
| 185 |
|
|
CHANNELS_WIDTH: integer := 4
|
| 186 |
|
|
);
|
| 187 |
|
|
port (
|
| 188 |
|
|
data_I: in std_logic_vector (DATA_WIDTH - 1 downto 0);
|
| 189 |
|
|
channel_I: in std_logic_vector (CHANNELS_WIDTH -1 downto 0);
|
| 190 |
|
|
trig_channel_I: in std_logic_vector (CHANNELS_WIDTH -1 downto 0);
|
| 191 |
|
|
address_I: in std_logic_vector (MEM_ADD_WIDTH - 1 downto 0);
|
| 192 |
|
|
final_address_I: in std_logic_vector (MEM_ADD_WIDTH - 1 downto 0);
|
| 193 |
|
|
-- offset from trigger address (signed). MUST BE:
|
| 194 |
|
|
-- -final_address_I < offset_I < final_address_I
|
| 195 |
|
|
offset_I: in std_logic_vector (MEM_ADD_WIDTH downto 0);
|
| 196 |
|
|
-- trigger level (from max to min, not signed)
|
| 197 |
|
|
level_I: in std_logic_vector (DATA_WIDTH - 1 downto 0);
|
| 198 |
|
|
-- use falling edge when falling_I = '1', else rising edge
|
| 199 |
|
|
falling_I: in std_logic;
|
| 200 |
|
|
clk_I: in std_logic;
|
| 201 |
|
|
reset_I: in std_logic;
|
| 202 |
|
|
enable_I: in std_logic;
|
| 203 |
|
|
-- it is set when trigger condition occurs
|
| 204 |
|
|
trigger_O: out std_logic;
|
| 205 |
|
|
-- address when trigger plus offset
|
| 206 |
|
|
address_O: out std_logic_vector (MEM_ADD_WIDTH - 1 downto 0)
|
| 207 |
|
|
);
|
| 208 |
|
|
end component ctrl_trigger_manager;
|
| 209 |
|
|
|
| 210 |
|
|
|
| 211 |
48 |
budinero |
component ctrl_address_allocation is
|
| 212 |
46 |
budinero |
port(
|
| 213 |
|
|
----------------------------------------------------------------------------------------------
|
| 214 |
|
|
-- From port
|
| 215 |
|
|
DAT_I_port: in std_logic_vector (15 downto 0);
|
| 216 |
|
|
DAT_O_port: out std_logic_vector (15 downto 0);
|
| 217 |
|
|
ADR_I_port: in std_logic_vector (3 downto 0);
|
| 218 |
|
|
CYC_I_port: in std_logic;
|
| 219 |
|
|
STB_I_port: in std_logic;
|
| 220 |
|
|
ACK_O_port: out std_logic ;
|
| 221 |
|
|
WE_I_port: in std_logic;
|
| 222 |
|
|
RST_I: in std_logic;
|
| 223 |
|
|
CLK_I: in std_logic;
|
| 224 |
|
|
----------------------------------------------------------------------------------------------
|
| 225 |
|
|
-- To internal
|
| 226 |
|
|
CYC_O_int: out std_logic;
|
| 227 |
|
|
STB_O_int: out std_logic;
|
| 228 |
|
|
ACK_I_int: in std_logic ;
|
| 229 |
|
|
DAT_I_int: in std_logic_vector(15 downto 0);
|
| 230 |
|
|
----------------------------------------------------------------------------------------------
|
| 231 |
|
|
-- Internal
|
| 232 |
|
|
start_O: out std_logic;
|
| 233 |
|
|
continuous_O: out std_logic;
|
| 234 |
48 |
budinero |
trigger_en_O: out std_logic;
|
| 235 |
46 |
budinero |
trigger_edge_O: out std_logic;
|
| 236 |
48 |
budinero |
trigger_channel_O:out std_logic_vector(0 downto 0);
|
| 237 |
46 |
budinero |
time_scale_O: out std_logic_vector(4 downto 0);
|
| 238 |
|
|
time_scale_en_O: out std_logic;
|
| 239 |
|
|
channels_sel_O: out std_logic_vector(1 downto 0);
|
| 240 |
|
|
buffer_size_O: out std_logic_vector(13 downto 0);
|
| 241 |
|
|
trigger_level_O: out std_logic_vector(9 downto 0);
|
| 242 |
|
|
trigger_offset_O: out std_logic_vector(14 downto 0);
|
| 243 |
|
|
|
| 244 |
48 |
budinero |
adc_conf_O: out std_logic_vector(15 downto 0);
|
| 245 |
|
|
|
| 246 |
46 |
budinero |
error_number_I: in std_logic_vector (2 downto 0);
|
| 247 |
|
|
running_I: in std_logic;
|
| 248 |
|
|
error_flag_I: in std_logic;
|
| 249 |
|
|
|
| 250 |
48 |
budinero |
write_in_adc_O: out std_logic;
|
| 251 |
46 |
budinero |
stop_O: out std_logic
|
| 252 |
|
|
);
|
| 253 |
48 |
budinero |
end component ctrl_address_allocation;
|
| 254 |
46 |
budinero |
|
| 255 |
|
|
|
| 256 |
48 |
budinero |
component ctrl is
|
| 257 |
|
|
port(
|
| 258 |
|
|
------------------------------------------------------------------------------------------------
|
| 259 |
|
|
-- From port
|
| 260 |
|
|
DAT_I_port: in std_logic_vector (15 downto 0);
|
| 261 |
|
|
DAT_O_port: out std_logic_vector (15 downto 0);
|
| 262 |
|
|
ADR_I_port: in std_logic_vector (3 downto 0);
|
| 263 |
|
|
CYC_I_port: in std_logic;
|
| 264 |
|
|
STB_I_port: in std_logic;
|
| 265 |
|
|
ACK_O_port: out std_logic ;
|
| 266 |
|
|
WE_I_port: in std_logic;
|
| 267 |
|
|
CLK_I_port: in std_logic;
|
| 268 |
|
|
RST_I_port: in std_logic;
|
| 269 |
|
|
|
| 270 |
|
|
------------------------------------------------------------------------------------------------
|
| 271 |
|
|
-- To ADC
|
| 272 |
|
|
DAT_I_daq: in std_logic_vector (15 downto 0);
|
| 273 |
|
|
DAT_O_daq: out std_logic_vector (15 downto 0);
|
| 274 |
|
|
ADR_O_daq: out std_logic_vector (1 downto 0);
|
| 275 |
|
|
CYC_O_daq: out std_logic;
|
| 276 |
|
|
STB_O_daq: out std_logic;
|
| 277 |
|
|
ACK_I_daq: in std_logic ;
|
| 278 |
|
|
WE_O_daq: out std_logic;
|
| 279 |
|
|
|
| 280 |
|
|
CLK_I_daq: in std_logic;
|
| 281 |
|
|
RST_I_daq: in std_logic;
|
| 282 |
|
|
|
| 283 |
|
|
------------------------------------------------------------------------------------------------
|
| 284 |
|
|
-- To memory, A (writing) interface (Higer prioriry)
|
| 285 |
|
|
--DAT_I_memw: in std_logic_vector (15 downto 0);
|
| 286 |
|
|
DAT_O_memw: out std_logic_vector (15 downto 0);
|
| 287 |
|
|
ADR_O_memw: out std_logic_vector (13 downto 0);
|
| 288 |
|
|
CYC_O_memw: out std_logic;
|
| 289 |
|
|
STB_O_memw: out std_logic;
|
| 290 |
|
|
ACK_I_memw: in std_logic ;
|
| 291 |
|
|
WE_O_memw: out std_logic;
|
| 292 |
|
|
|
| 293 |
|
|
------------------------------------------------------------------------------------------------
|
| 294 |
|
|
-- To memory, B (reading) interface
|
| 295 |
|
|
DAT_I_memr: in std_logic_vector (15 downto 0);
|
| 296 |
|
|
--DAT_O_memr: out std_logic_vector (15 downto 0);
|
| 297 |
|
|
ADR_O_memr: out std_logic_vector (13 downto 0);
|
| 298 |
|
|
CYC_O_memr: out std_logic;
|
| 299 |
|
|
STB_O_memr: out std_logic;
|
| 300 |
|
|
ACK_I_memr: in std_logic ;
|
| 301 |
|
|
WE_O_memr: out std_logic
|
| 302 |
|
|
|
| 303 |
|
|
);
|
| 304 |
|
|
end component ctrl;
|
| 305 |
|
|
|
| 306 |
46 |
budinero |
end package ctrl_pkg;
|
| 307 |
|
|
|