CMX
CMX firmware code in-line documentation
 All Classes Namespaces Files Functions Variables
CMX_input_module_spy_mem_control_FSM.vhd
Go to the documentation of this file.
1 
4 
5 library IEEE;
6 use IEEE.STD_LOGIC_1164.ALL;
7 use IEEE.NUMERIC_STD.ALL;
8 
9 library UNISIM;
10 use UNISIM.VComponents.all;
11 
12 library work;
13 use work.CMXpackage.all;
15 
17  generic(
21  );
22  port (
23  clk : in std_logic;
24 
25  ncs : in std_logic; --vme ports
26  rd_nwr : in std_logic;
27  ds : in std_logic;
28  addr_vme : in std_logic_vector (15 downto 0);
29  data_vme_in : in std_logic_vector (15 downto 0);
30  data_vme_out : out std_logic_vector (15 downto 0);
31  bus_drive : out std_logic;
32 
33  mode_control : out std_logic_vector(3 downto 0); --controls the mode of
34  --running; modes can be
35  --CONST_DPR_CONTROL_SPY,
36  --CONST_DPR_CONTROL_PLAYBACK,
37  --CONST_DPR_CONTROL_VERIFY
38  --forwarded form the
39  --control register
40  --will be interpreted by
41  --the outside
42  --input_module to
43  --determine the data flow
44 
45  --memory steering ports
46  ena : out std_logic;
47  wea : out std_logic;
48  addra : out std_logic_vector(7 DOWNTO 0);
49 
50  mem_select_address : out std_logic_vector(3 downto 0); --
51 
52  dina : out std_logic_vector(95 DOWNTO 0);
53  douta : in std_logic_vector(95 DOWNTO 0);
54 
55  --this should be used to inhibit enb web when memory is being written to or
56  --read from vme on port a, high->inhibit, low->mode_control operation
57  port_b_master_inhibit : out std_logic);
58 
59 end CMX_input_module_spy_mem_control_FSM;
60 
61 architecture multi_seg of CMX_input_module_spy_mem_control_FSM is
62 
63  --FSM states
64  type state_spy_mem_control_type is (s_standby, --the normal running mode, ihibit is
65  --released, no reads or writes from vme
66  s_inhibit_init, --after r/w request we
67  --need to raise the
68  --inhibit for 2 cycles
69  --so it can be propagated to
70  --the port B domain
71  s_wait_for_vme_write, -- write has been
72  -- requested, FSM waits
73  -- for data writes from VME
74  s_writing_ram, --all data words have been
75  --written to VME, uploading to RAM
76  s_reading_ram, --read has been requested,
77  --reading RAM
78  s_wait_for_vme_read --data has been read from
79  --RAM and presented to VME,
80  --waiting for SW to read it
81  --all out from VME.
82  );
84 
85  signal wea_sig,ena_sig : std_logic;
86  signal dina_sig : std_logic_vector(95 downto 0);
87 
88 
89  component vme_local_switch is
90  port (
91  data_vme_up : out std_logic_vector (15 downto 0);
92  data_vme_from_below : in arr_16;
93  bus_drive_up : out std_logic;
94  bus_drive_from_below : in std_logic_vector);
95  end component vme_local_switch;
96 
97 
98  signal data_vme_from_below : arr_16(7 downto 0);
99  signal bus_drive_from_below : std_logic_vector(7 downto 0);
100 
101 
102  component vme_outreg_notri is
103  generic (
104  ia_vme : integer;
105  width : integer);
106  port (
107  clk : in std_logic;
108  ncs : in std_logic;
109  rd_nwr : in std_logic;
110  ds : in std_logic;
111  addr_vme : in std_logic_vector (15 downto 0);
112  data_vme : out std_logic_vector (15 downto 0);
113  bus_drive : out std_logic;
114  data_to_vme : in std_logic_vector (width-1 downto 0);
115  read_detect : out std_logic);
116  end component vme_outreg_notri;
117 
119  generic (
120  ia_vme : integer;
121  width : integer);
122  port (
123  ncs : in std_logic;
124  rd_nwr : in std_logic;
125  ds : in std_logic;
126  addr_vme : in std_logic_vector (15 downto 0);
127  data_vme : out std_logic_vector (15 downto 0);
128  bus_drive : out std_logic;
129  data_to_vme : in std_logic_vector (width-1 downto 0));
130  end component vme_outreg_notri_async;
131 
132 
133  component vme_inreg_notri is
134  generic (
135  ia_vme : integer;
136  width : integer);
137  port (
138  clk : in std_logic;
139  ncs : in std_logic;
140  rd_nwr : in std_logic;
141  ds : in std_logic;
142  addr_vme : in std_logic_vector (15 downto 0);
143  data_vme_in : in std_logic_vector (15 downto 0);
144  data_vme_out : out std_logic_vector (15 downto 0);
145  bus_drive : out std_logic;
146  data_from_vme : out std_logic_vector (width-1 downto 0);
147  data_to_vme : in std_logic_vector (width-1 downto 0);
148  read_detect : out std_logic;
149  write_detect : out std_logic);
150  end component vme_inreg_notri;
151 
153  generic (
154  ia_vme : integer;
155  width : integer);
156  port (
157  ncs : in std_logic;
158  rd_nwr : in std_logic;
159  ds : in std_logic;
160  addr_vme : in std_logic_vector (15 downto 0);
161  data_vme_in : in std_logic_vector (15 downto 0);
162  data_vme_out : out std_logic_vector (15 downto 0);
163  bus_drive : out std_logic;
164  data_from_vme : out std_logic_vector (width-1 downto 0);
165  data_to_vme : in std_logic_vector (width-1 downto 0));
166  end component vme_inreg_notri_async;
167 
168 
169 
170  --component vme_outreg
171  -- generic (
172  -- ia_vme : integer;
173  -- width : integer);
174  -- port (
175  -- clk : in std_logic;
176  -- ncs : in std_logic;
177  -- rd_nwr : in std_logic;
178  -- ds : in std_logic;
179  -- addr_vme : in std_logic_vector (15 downto 0);
180  -- data_vme : out std_logic_vector (15 downto 0);
181  -- data_to_vme : in std_logic_vector (width-1 downto 0);
182  -- read_detect : out std_logic);
183  --end component;
184  --
185  --component vme_inreg
186  -- generic (
187  -- ia_vme : integer;
188  -- width : integer);
189  -- port (
190  -- clk : in std_logic;
191  -- ncs : in std_logic;
192  -- rd_nwr : in std_logic;
193  -- ds : in std_logic;
194  -- addr_vme : in std_logic_vector (15 downto 0);
195  -- data_vme : inout std_logic_vector (15 downto 0);
196  -- data_from_vme : out std_logic_vector (width-1 downto 0);
197  -- data_to_vme : in std_logic_vector (width-1 downto 0);
198  -- read_detect : out std_logic;
199  -- write_detect : out std_logic);
200  --end component;
201 
202  --six sets of signals for the data registers
203  signal data_from_vme_REG_RW_INPUT_SPY_MEM_X_WORD : arr_16(5 downto 0);
204  signal data_to_vme_REG_RW_INPUT_SPY_MEM_X_WORD : arr_16(5 downto 0);
205  signal read_detect_REG_RW_INPUT_SPY_MEM_X_WORD : std_logic_vector(5 downto 0);
206  signal write_detect_REG_RW_INPUT_SPY_MEM_X_WORD : std_logic_vector(5 downto 0);
207 
208  --control register signals
209  signal data_from_vme_REG_RW_INPUT_SPY_MEM_X_CONTROL : std_logic_vector (15 downto 0);
210  signal data_to_vme_REG_RW_INPUT_SPY_MEM_X_CONTROL : std_logic_vector (15 downto 0);
213 
214  signal data_to_vme_REG_RO_INPUT_SPY_MEM_X_STATUS : std_logic_vector (15 downto 0);
215  --signal read_detect_REG_RO_INPUT_SPY_MEM_X_STATUS : std_logic;
216 
217  signal status_summary: std_logic_vector(3 downto 0); --included as part of
218  --the status register
219 
220  signal global_addr_counter: unsigned(12 downto 0); --counter specifying the
221  --memory that will be
222  --written to (upper 4
223  --bits) and the address
224  --(lower 8 bits)
225 
226  signal global_addr_counter_next: unsigned(12 downto 0);
227 
228  signal inhibit_init_counter: unsigned(0 downto 0);
229 
230  signal op_request: std_logic; --bit signalling operation is requested
231  --taken from
232  signal rw_request: std_logic; --0 for read, 1 for write
233  --
234 
235  signal port_b_master_inhibit_sig : std_logic;
236 
237  --component chipscope_icon_u2_c1
238  -- port (
239  -- CONTROL0 : inout std_logic_vector(35 downto 0));
240  --end component;
241  --
242  --signal CONTROL0 : std_logic_vector(35 downto 0);
243  --
244  --component chipscope_ila_CMX_input_module_spy_mem_control_FSM
245  -- port (
246  -- CONTROL : inout std_logic_vector(35 downto 0);
247  -- CLK : in std_logic;
248  -- DATA : in std_logic_vector(260 downto 0);
249  -- TRIG0 : in std_logic_vector(15 downto 0));
250  --end component;
251  --
252  --
253  --signal DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM : std_logic_vector(260 downto 0);
254  --signal TRIG0_chipscope_ila_CMX_input_module_spy_mem_control_FSM : std_logic_vector(15 downto 0);
255 
256 begin -- multi_seg
257 
258 
259 
260  --instantiate VME registers
261 
262 
263  vme_local_switch_inst: entity work.vme_local_switch
264  port map (
269 
270  ena<=ena_sig;
271  wea<=wea_sig;
272  dina<=dina_sig;
273 
275 
276  vme_data_word_reg_gen: for word_i in 0 to 5 generate
277 
279  generic map (
280  ia_vme => ADDR_REG_RW_INPUT_SPY_MEM_X_WORD+(2*word_i),
281  width => 16)
282  port map (
283  clk => clk,
284  ncs => ncs,
285  rd_nwr => rd_nwr,
286  ds => ds,
287  addr_vme => addr_vme,
289  data_vme_out => data_vme_from_below (word_i),
290  bus_drive => bus_drive_from_below (word_i),
295 
296 
297  --connect the output from RAM to VME for reading by SW
298  data_to_vme_REG_RW_INPUT_SPY_MEM_X_WORD(word_i) <= douta( (word_i+1)*16 - 1 downto word_i*16);
299 
300  end generate vme_data_word_reg_gen;
301 
303  generic map (
305  width => 16)
306  port map (
307  clk => clk,
308  ncs => ncs,
309  rd_nwr => rd_nwr,
310  ds => ds,
311  addr_vme => addr_vme,
319 
320 
322  generic map (
324  width => 16)
325  port map (
326  ncs => ncs,
327  rd_nwr => rd_nwr,
328  ds => ds,
329  addr_vme => addr_vme,
333  --read_detect => read_detect_REG_RO_INPUT_SPY_MEM_X_STATUS);
334 
335 
336  --klm edit out --we always write/read in the same order
337  --global_addr_counter_next<=global_addr_counter+1;
338 
339  --interpretation of portions of VME registers and connection to output ports
341  mem_select_address<=std_logic_vector(global_addr_counter(11 downto 8));
342  addra<=std_logic_vector(global_addr_counter(7 downto 0));
343 
347 
348  --for the control register data to read is simply the data written
350 
351  --data to/from vme is connected to data from/to RAM
355  --data_to_vme... was constructed in the generate loop above
356 
357  --update state on clock edge
358  process (clk)
359  begin -- process
360  if rising_edge(clk) then
361  --if state_next=s_writing_ram or (state_next=s_wait_for_vme_read and state_reg=s_reading_ram) then
362  -- if global_addr_counter=to_unsigned(256*numactchan,13) then
363  -- global_addr_counter<=to_unsigned(0,13);
364  -- else
365  -- global_addr_counter<=global_addr_counter_next;
366  -- end if;
367  --else
368  -- global_addr_counter<=global_addr_counter;--to_unsigned(0,13);
369  --end if;
371  -- start klm mod
373  end if;
374  end process;
375 
376 
377  --next state logic
379  begin
380  -- default values
381  global_addr_counter_next<=to_unsigned(0,13);
383  ena_sig<='0';
384  wea_sig<='0';
385  --addra<=(others=>'0');
386  --global_addr_counter<=(others=>'0');
387  status_summary<=(others=>'0');
388 
389  case state_reg is
390  when s_standby =>
391  status_summary<=CONST_DPR_STATUS_NORMAL&'0';
394  state_next<=s_inhibit_init;
396  else
397  state_next<=s_standby;
398  end if;
399  when s_inhibit_init =>
401  status_summary<=CONST_DPR_STATUS_WAIT_INHIBIT&'0';
402  if ( rw_request='1') then
403  state_next<=s_wait_for_vme_write;
404  else
405  state_next<=s_reading_ram;
406  end if;
407  when s_wait_for_vme_write =>
409  status_summary<=CONST_DPR_STATUS_WRITE&'0';
411  state_next<=s_writing_ram;
413  ena_sig<='1';
414  wea_sig<='1';
415  else
416  state_next<=s_wait_for_vme_write;
418  end if;
419  when s_writing_ram =>
421  status_summary<=CONST_DPR_STATUS_WAIT_WRITE&'0';
422  if global_addr_counter=to_unsigned(256*numactchan,13) then
423  global_addr_counter_next<=to_unsigned(0,13);
424  state_next<=s_standby;
425  else
426  state_next<=s_wait_for_vme_write;
428  end if;
429  when s_reading_ram =>
431  status_summary<=CONST_DPR_STATUS_WAIT_READ&'0';
432  ena_sig<='1';
434  state_next<=s_wait_for_vme_read;
435  when s_wait_for_vme_read =>
437  status_summary<=CONST_DPR_STATUS_READ&'0';
439  if global_addr_counter=to_unsigned(256*numactchan-1,13) then
440  state_next<=s_standby;
441  else
443  state_next<=s_reading_ram;
444  end if;
445  else
447  state_next<=s_wait_for_vme_read;
448  end if;
449  when others =>
450  state_next<=s_standby;
451  end case;
452 
453  end process;
454 
455 -- --Moore output
456 -- process (state_reg)
457 -- begin
458 -- counter_enable<='0';
459 -- case state_reg is
460 -- when s_counter_running =>
461 -- counter_enable<='1';
462 -- when s_counter_stopped =>
463 -- counter_enable<='0';
464 -- when others => null;
465 -- end case;
466 -- end process;
467 --
468 
469 
470  --chipscope_ila_CMX_input_module_spy_mem_control_FSM_inst: chipscope_ila_CMX_input_module_spy_mem_control_FSM
471  -- port map (
472  -- CONTROL => CONTROL0,
473  -- CLK => clk,
474  -- DATA => DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM,
475  -- TRIG0 => TRIG0_chipscope_ila_CMX_input_module_spy_mem_control_FSM);
476  --
477  --
478  --chipscope_icon_u2_c1_inst: chipscope_icon_u2_c1
479  -- port map (
480  -- CONTROL0 => CONTROL0);
481  --
482  --TRIG0_chipscope_ila_CMX_input_module_spy_mem_control_FSM(0)<=op_request;
483  --TRIG0_chipscope_ila_CMX_input_module_spy_mem_control_FSM(1)<=rw_request;
484  --TRIG0_chipscope_ila_CMX_input_module_spy_mem_control_FSM(2)<=write_detect_REG_RW_INPUT_SPY_MEM_X_CONTROL;
485  --TRIG0_chipscope_ila_CMX_input_module_spy_mem_control_FSM(8 downto 3)<=read_detect_REG_RW_INPUT_SPY_MEM_X_WORD;
486  --TRIG0_chipscope_ila_CMX_input_module_spy_mem_control_FSM(14 downto 9)<=write_detect_REG_RW_INPUT_SPY_MEM_X_WORD;
487  --TRIG0_chipscope_ila_CMX_input_module_spy_mem_control_FSM(15)<=ds;
488  --
489  --
490  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(0)<=op_request;
491  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(1)<=rw_request;
492  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(2)<=write_detect_REG_RW_INPUT_SPY_MEM_X_CONTROL;
493  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(8 downto 3)<=read_detect_REG_RW_INPUT_SPY_MEM_X_WORD;
494  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(14 downto 9)<=write_detect_REG_RW_INPUT_SPY_MEM_X_WORD;
495  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(27 downto 15)<=std_logic_vector(global_addr_counter);
496  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(31 downto 28)<=status_summary;
497  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(32)<=ena_sig;
498  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(33)<=wea_sig;
499  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(129 downto 34)<=douta;
500  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(225 downto 130)<=dina_sig;
501  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(226)<=ds;
502  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(227)<=rd_nwr;
503  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(243 downto 228)<=addr_vme;
504  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(259 downto 244)<=data_vme;
505  --DATA_chipscope_ila_CMX_input_module_spy_mem_control_FSM(260)<=port_b_master_inhibit_sig;
506 
507 
508 
509 
510 
511 
512 end multi_seg;
out read_detectstd_logic
in addr_vmestd_logic_vector (15 downto 0)
out data_vmestd_logic_vector (15 downto 0)
out data_vme_outstd_logic_vector (15 downto 0)
( s_standby ,s_inhibit_init ,s_wait_for_vme_write ,s_writing_ram ,s_reading_ram ,s_wait_for_vme_read ) state_spy_mem_control_type
out data_from_vmestd_logic_vector (width - 1 downto 0)
vme_inreg_notri vme_inreg_reg_rw_input_spy_mem_x_controlvme_inreg_reg_rw_input_spy_mem_x_control
in data_vme_from_belowarr_16
--! inputs from local registers and from
out data_from_vmestd_logic_vector (width - 1 downto 0)
out data_vmestd_logic_vector (15 downto 0)
_library_ UNISIMUNISIM
in data_vme_instd_logic_vector (15 downto 0)
out write_detectstd_logic
_library_ workwork
vme_inreg_notri vme_inreg_reg_rw_input_spy_mem_x_wordvme_inreg_reg_rw_input_spy_mem_x_word
in data_to_vmestd_logic_vector (width - 1 downto 0)
out data_vme_upstd_logic_vector (15 downto 0)
--! connect this to
in addr_vmestd_logic_vector (15 downto 0)
in data_to_vmestd_logic_vector (width - 1 downto 0)
out bus_drive_upstd_logic
or of all bus drive requests from below
vme_outreg_notri_async vme_outreg_reg_ro_input_spy_mem_x_statusvme_outreg_reg_ro_input_spy_mem_x_status
in addr_vmestd_logic_vector (15 downto 0)
in data_to_vmestd_logic_vector (width - 1 downto 0)
out data_vme_outstd_logic_vector (15 downto 0)
out bus_drivestd_logic
in addr_vmestd_logic_vector (15 downto 0)
test registers
in data_vme_instd_logic_vector (15 downto 0)
_library_ IEEEIEEE
out read_detectstd_logic
in data_to_vmestd_logic_vector (width - 1 downto 0)
in bus_drive_from_belowstd_logic_vector