CMX
CMX firmware code in-line documentation
 All Classes Namespaces Files Functions Variables
BCID_counter.vhd
Go to the documentation of this file.
1 ----------------------------------------------------------------------------------
9 ----------------------------------------------------------------------------------
10 library IEEE;
11 use IEEE.STD_LOGIC_1164.ALL;
12 
13 
14 library work;
15 use work.CMXpackage.all;
17 
18 
19 -- Uncomment the following library declaration if using
20 -- arithmetic functions with Signed or Unsigned values
21 use IEEE.NUMERIC_STD.ALL;
22 
23 -- Uncomment the following library declaration if instantiating
24 -- any Xilinx primitives in this code.
25 --library UNISIM;
26 --use UNISIM.VComponents.all;
27 
28 entity BCID_counter is
29  port (
30  reset : in std_logic;
31  clk_40 : in std_logic;
32  BCID_out : out std_logic_vector(11 downto 0);
33  --VME control:
34  ncs : in std_logic; --ports forwarded to the vme register instances
35  rd_nwr : in std_logic;
36  ds : in std_logic;
37  addr_vme : in std_logic_vector (15 downto 0);
38  data_vme_in : in std_logic_vector (15 downto 0);
39  data_vme_out : out std_logic_vector (15 downto 0);
40  bus_drive : out std_logic
41  );
42 end BCID_counter;
43 
44 architecture Behavioral of BCID_counter is
45  signal BCID_next : unsigned(11 downto 0);
46  signal BCID_reg : unsigned(11 downto 0);
47  signal BCID_reset_val : unsigned(11 downto 0);
48 
49  component vme_local_switch is
50  port (
51  data_vme_up : out std_logic_vector (15 downto 0);
52  data_vme_from_below : in arr_16;
53  bus_drive_up : out std_logic;
54  bus_drive_from_below : in std_logic_vector);
55  end component vme_local_switch;
56 
57  component vme_inreg_notri_async is
58  generic (
59  ia_vme : integer;
60  width : integer);
61  port (
62  ncs : in std_logic;
63  rd_nwr : in std_logic;
64  ds : in std_logic;
65  addr_vme : in std_logic_vector (15 downto 0);
66  data_vme_in : in std_logic_vector (15 downto 0);
67  data_vme_out : out std_logic_vector (15 downto 0);
68  bus_drive : out std_logic;
69  data_from_vme : out std_logic_vector (width-1 downto 0);
70  data_to_vme : in std_logic_vector (width-1 downto 0));
71  end component vme_inreg_notri_async;
72 
74  generic (
75  ia_vme : integer;
76  width : integer);
77  port (
78  ncs : in std_logic;
79  rd_nwr : in std_logic;
80  ds : in std_logic;
81  addr_vme : in std_logic_vector (15 downto 0);
82  data_vme : out std_logic_vector (15 downto 0);
83  bus_drive : out std_logic;
84  data_to_vme : in std_logic_vector (width-1 downto 0));
85  end component vme_outreg_notri_async;
86 
87  signal data_vme_out_local : arr_16(2 downto 0);
88  signal bus_drive_local : std_logic_vector(2 downto 0);
89 
90  signal data_from_vme_REG_RW_BCID_RESET_VAL: std_logic_vector(15 downto 0);
91  signal data_to_vme_REG_RW_BCID_RESET_VAL: std_logic_vector(15 downto 0);
92 
93  signal data_from_vme_REG_RW_BC_RESET_ERROR_COUNTER_RESET : std_logic_vector(15 downto 0);
94  signal data_to_vme_REG_RW_BC_RESET_ERROR_COUNTER_RESET : std_logic_vector(15 downto 0);
95 
96 
97  signal bc_reset_error_counter : unsigned(15 downto 0);
98 
99  signal error_counter_reset : std_logic;
100 
101 begin
102 
103 
104  vme_local_switch_inst: entity work.vme_local_switch
105  port map (
110 
111 
112  vme_inreg_async_REG_RW_BCID_RESET_VAL: entity work.vme_inreg_notri_async
113  generic map (
114  ia_vme => ADDR_REG_RW_BCID_RESET_VAL ,
115  width => 16)
116  port map (
117  ncs => ncs,
118  rd_nwr => rd_nwr,
119  ds => ds,
120  addr_vme => addr_vme,
123  bus_drive => bus_drive_local (0),
126 
128  BCID_reset_val<=unsigned(data_from_vme_REG_RW_BCID_RESET_VAL(11 downto 0));
129 
130 
131  vme_outreg_notri_async_REG_RO_BC_RESET_ERROR_COUNTER: entity work.vme_outreg_notri_async
132  generic map (
133  ia_vme => ADDR_REG_RO_BC_RESET_ERROR_COUNTER ,
134  width => 16)
135  port map (
136  ncs => ncs,
137  rd_nwr => rd_nwr,
138  ds => ds,
139  addr_vme => addr_vme,
141  bus_drive => bus_drive_local (1),
142  data_to_vme => std_logic_vector(bc_reset_error_counter));
143 
144 
145  vme_inreg_async_REG_RW_BC_RESET_ERROR_COUNTER_RESET: entity work.vme_inreg_notri_async
146  generic map (
147  ia_vme => ADDR_REG_RW_BC_RESET_ERROR_COUNTER_RESET,
148  width => 16)
149  port map (
150  ncs => ncs,
151  rd_nwr => rd_nwr,
152  ds => ds,
153  addr_vme => addr_vme,
156  bus_drive => bus_drive_local (2),
159 
162 
163  BCID_next<=BCID_reg+1 when BCID_reg/=to_unsigned(3563,12) else to_unsigned(0,12);
164  --orbit has 3564 bunches
165 
166  process(clk_40)
167  begin
168  if rising_edge(clk_40) then
169  if reset = '1' then
170  if BCID_next/=BCID_reset_val then
171  if bc_reset_error_counter/=to_unsigned(16#FFFF#,16) then
173  else
174  bc_reset_error_counter<=to_unsigned(16#FFFF#,16);
175  end if;
176  end if;
177 
179 
180  else
181 
183 
184  if error_counter_reset='1' then
185  bc_reset_error_counter<=to_unsigned(0,16);
186  end if;
187 
188  end if;
189  end if;
190  end process;
191 
192  BCID_out<=std_logic_vector(BCID_reg);
193 
194 end Behavioral;
195 
in addr_vmestd_logic_vector (15 downto 0)
std_logic_vector (15 downto 0) data_from_vme_REG_RW_BCID_RESET_VAL
std_logic_vector (2 downto 0) bus_drive_local
out data_vmestd_logic_vector (15 downto 0)
std_logic_vector (15 downto 0) data_from_vme_REG_RW_BC_RESET_ERROR_COUNTER_RESET
out data_from_vmestd_logic_vector (width - 1 downto 0)
out BCID_outstd_logic_vector (11 downto 0)
unsigned (11 downto 0) BCID_reg
in dsstd_logic
in data_vme_from_belowarr_16
--! inputs from local registers and from
in data_vme_instd_logic_vector (15 downto 0)
in rd_nwrstd_logic
_library_ workwork
Definition: and_all.vhd:15
unsigned (11 downto 0) BCID_reset_val
std_logic_vector (15 downto 0) data_to_vme_REG_RW_BCID_RESET_VAL
out data_vme_outstd_logic_vector (15 downto 0)
in data_to_vmestd_logic_vector (width - 1 downto 0)
arr_16 (2 downto 0) data_vme_out_local
out data_vme_upstd_logic_vector (15 downto 0)
--! connect this to
in clk_40std_logic
in addr_vmestd_logic_vector (15 downto 0)
in data_vme_instd_logic_vector (15 downto 0)
in resetstd_logic
in ncsstd_logic
out bus_drive_upstd_logic
or of all bus drive requests from below
std_logic_vector (15 downto 0) data_to_vme_REG_RW_BC_RESET_ERROR_COUNTER_RESET
in addr_vmestd_logic_vector (15 downto 0)
out bus_drivestd_logic
_library_ IEEEIEEE
Definition: and_all.vhd:12
out data_vme_outstd_logic_vector (15 downto 0)
unsigned (11 downto 0) BCID_next
test registers
unsigned (15 downto 0) bc_reset_error_counter
in data_to_vmestd_logic_vector (width - 1 downto 0)
in bus_drive_from_belowstd_logic_vector