SURF  1.0
SaciMultiPixelPkg.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SaciMultiPixelPkg.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 07/21/2016
5 -- Last update: 07/21/2016
6 -------------------------------------------------------------------------------
7 -- Description: SaciMultiPixel Package File
8 -------------------------------------------------------------------------------
9 -- This file is part of 'SLAC Firmware Standard Library'.
10 -- It is subject to the license terms in the LICENSE.txt file found in the
11 -- top-level directory of this distribution and at:
12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
13 -- No part of 'SLAC Firmware Standard Library', including this file,
14 -- may be copied, modified, propagated, or distributed except according to
15 -- the terms contained in the LICENSE.txt file.
16 ------------------------------------------------------------------------------
17 
18 library ieee;
19 use ieee.std_logic_1164.all;
20 use ieee.std_logic_arith.all;
21 use ieee.std_logic_unsigned.all;
22 
23 use work.StdRtlPkg.all;
24 
26 --! @file
27  --! @ingroup protocols_saci
28 
29  constant FPGA_VERSION_C : slv(31 downto 0) := x"00000000";
30 
31  type MultiPixelWriteType is record
32  asic : slv(1 downto 0);
33  row : slv(9 downto 0);
34  col : slv(9 downto 0);
35  data : Slv16Array(3 downto 0);
36  bankFlag : slv(3 downto 0);
39  req : sl;
40  end record;
42  asic => (others => '0'),
43  row => (others => '0'),
44  col => (others => '0'),
45  data => (others => (others => '0')),
46  bankFlag => (others => '0'),
47  calRowFlag => '0',
48  calBotFlag => '0',
49  req => '0'
50  );
51 
52  function asicBaseAddr ( asic : natural ) return slv;
53 
54  --Functions to allow use of EPIX100 or 10k
55  function getNumColumns ( version : slv ) return integer;
56  function getWordsPerSuperRow ( version : slv ) return integer;
57 
58  constant NCOL_C : integer := getNumColumns(FPGA_VERSION_C);
59  --Number of columns in ePix "super row"
60  -- (columns / ch) * (channels / asic) * (asics / row) / (adc values / word)
61  -- constant WORDS_PER_SUPER_ROW_C : integer := NCOL_C * 4 * 2 / 2;
62  constant WORDS_PER_SUPER_ROW_C : integer := getWordsPerSuperRow(FPGA_VERSION_C);
63  constant EPIX100_COLS_PER_ROW : integer := 96;
64  constant EPIX10K_COLS_PER_ROW : integer := 48;
65  constant EPIXS_COLS_PER_ROW : integer := 10;
66  constant EPIX100A_ROWS_PER_ASIC : integer := 352;
67 
68  procedure globalToLocalPixel( signal globalRow : in slv;
69  signal globalCol : in slv;
70  signal calRowFlag : in sl;
71  signal calBotFlag : in sl;
72  signal inputData : in Slv16Array;
73  variable localAsic : inout slv;
74  variable localRow : inout slv;
75  variable localCol : inout slv;
76  variable localData : inout Slv16Array);
77  procedure globalToLocalPixelEpix100A( signal globalRow : in slv;
78  signal globalCol : in slv;
79  signal calRowFlag : in sl;
80  signal calBotFlag : in sl;
81  signal inputData : in Slv16Array;
82  variable localAsic : inout slv;
83  variable localRow : inout slv;
84  variable localCol : inout slv;
85  variable localData : inout Slv16Array) ;
86 
87 end SaciMultiPixelPkg;
88 
89 package body SaciMultiPixelPkg is
90 
91  function asicBaseAddr(asic : natural) return slv is
92  begin
93  return toSlv(asic*(2**22), 32);
94  end function;
95 
96  function getNumColumns (version : slv ) return integer is
97  begin
98  assert (version(31 downto 24) = x"E0" or
99  version(31 downto 24) = x"EA" or
100  version(31 downto 24) = x"E2" or
101  version(31 downto 24) = x"E3") report "Unable to determine ASIC type from version string!" severity failure;
102  --Epix 100p and Epix100a
103  if (version(31 downto 24) = x"E0" or version(31 downto 24) = x"EA") then
104  return EPIX100_COLS_PER_ROW;
105  --Epix 10k
106  elsif (version(31 downto 24) = x"E2") then
107  return EPIX10K_COLS_PER_ROW;
108  --Epix S
109  elsif (version(31 downto 24) = x"E3") then
110  return EPIXS_COLS_PER_ROW;
111  --Other (default to Epix 100)
112  else
113  return EPIX100_COLS_PER_ROW;
114  end if;
115  end function;
116 
117  function getWordsPerSuperRow (version : slv ) return integer is
118  begin
119  --EpixS reads only the active ASICs
120  if (version(31 downto 24) = x"E3") then
121  return EPIXS_COLS_PER_ROW * 2 / 2;
122  --Other
123  else
124  return NCOL_C * 4 * 2 / 2;
125  end if;
126  end function;
127 
128  procedure globalToLocalPixel (
129  signal globalRow : in slv;
130  signal globalCol : in slv;
131  signal calRowFlag : in sl;
132  signal calBotFlag : in sl;
133  signal inputData : in Slv16Array;
134  variable localAsic : inout slv;
135  variable localRow : inout slv;
136  variable localCol : inout slv;
137  variable localData : inout Slv16Array)
138  is
139  begin
140  assert (FPGA_VERSION_C(31 downto 24) = x"EA") report "Multi-pixel writes not supported for this ASIC!" severity warning;
141  if FPGA_VERSION_C(31 downto 24) = x"EA" then
142  globalToLocalPixelEpix100A(globalRow,globalCol,calRowFlag,calBotFlag,inputData,localAsic,localRow,localCol,localData);
143  end if;
144  end procedure globalToLocalPixel;
145 
146  procedure globalToLocalPixelEpix100A (
147  signal globalRow : in slv;
148  signal globalCol : in slv;
149  signal calRowFlag : in sl;
150  signal calBotFlag : in sl;
151  signal inputData : in Slv16Array;
152  variable localAsic : inout slv;
153  variable localRow : inout slv;
154  variable localCol : inout slv;
155  variable localData : inout Slv16Array)
156  is
157  variable asicCol : slv(9 downto 0);
158  begin
159  -- Top 2 ASICs
160  if (globalRow < EPIX100A_ROWS_PER_ASIC and calRowFlag = '0') or (calRowFlag = '1' and calBotFlag = '0') then
161  -- ASIC 2 (upper left)
162  if globalCol < NCOL_C * 4 then
163  localAsic := "10";
164  asicCol := NCOL_C * 4 - globalCol - 1;
165  -- ASIC 1 (upper right)
166  else
167  localAsic := "01";
168  asicCol := NCOL_C * 4 * 2 - 1 - globalCol;
169  end if;
170  -- For both top ASICs, translate row to local space
171  if calRowFlag = '1' then
172  localRow := conv_std_logic_vector(EPIX100A_ROWS_PER_ASIC,localRow'length);
173  else
174  localRow := EPIX100A_ROWS_PER_ASIC - 1 - globalRow;
175  end if;
176  -- Readout order for top ASICs is 3->0
177  for i in 0 to 3 loop
178  localData(3-i) := inputData(i);
179  end loop;
180  -- Bottom two ASICs
181  else
182  -- ASIC 3 (lower left)
183  if (globalCol < NCOL_C * 4) then
184  localAsic := "11";
185  asicCol := globalCol;
186  -- ASIC 0 (lower right)
187  else
188  localAsic := "00";
189  asicCol := globalCol - NCOL_C * 4;
190  end if;
191  -- For both bottom ASICs, translate row to local space
192  if calRowFlag = '1' then
193  localRow := conv_std_logic_vector(EPIX100A_ROWS_PER_ASIC,localRow'length);
194  else
195  localRow := globalRow - EPIX100A_ROWS_PER_ASIC;
196  end if;
197  -- Readout order for bottom ASICs is 0->3
198  for i in 0 to 3 loop
199  localData(i) := inputData(i);
200  end loop;
201  end if;
202  -- Decode column to column within a bank
203  if asicCol < NCOL_C then
204  localCol := asicCol;
205  elsif asicCol < NCOL_C * 2 then
206  localCol := asicCol - NCOL_C;
207  elsif asicCol < NCOL_C * 3 then
208  localCol := asicCol - NCOL_C * 2;
209  else
210  localCol := asicCol - NCOL_C * 3;
211  end if;
212  end procedure globalToLocalPixelEpix100A;
213 
214 end package body SaciMultiPixelPkg;
integer := 48 EPIX10K_COLS_PER_ROW
std_logic sl
Definition: StdRtlPkg.vhd:28
integer getNumColumnsversion,
globalToLocalPixelEpix100AglobalRow,globalCol,calRowFlag,calBotFlag,inputData,localAsic,localRow,localCol,localData,
slv( 1 downto 0) asic
slv( 31 downto 0) := x"00000000" FPGA_VERSION_C
globalToLocalPixelglobalRow,globalCol,calRowFlag,calBotFlag,inputData,localAsic,localRow,localCol,localData,
integer := 10 EPIXS_COLS_PER_ROW
MultiPixelWriteType :=(asic =>( others => '0'),row =>( others => '0'),col =>( others => '0'),data =>( others =>( others => '0')),bankFlag =>( others => '0'),calRowFlag => '0',calBotFlag => '0',req => '0') MULTI_PIXEL_WRITE_INIT_C
Slv16Array( 3 downto 0) data
array(natural range <> ) of slv( 15 downto 0) Slv16Array
Definition: StdRtlPkg.vhd:395
_library_ ieeeieee
integer := getWordsPerSuperRow(FPGA_VERSION_C ) WORDS_PER_SUPER_ROW_C
integer := 352 EPIX100A_ROWS_PER_ASIC
slv( 9 downto 0) row
integer getWordsPerSuperRowversion,
integer := 96 EPIX100_COLS_PER_ROW
slv( 3 downto 0) bankFlag
integer := getNumColumns(FPGA_VERSION_C ) NCOL_C
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
slv( 9 downto 0) col