1 -- --------------------------------------------------------------------- 3 --- b2tt_payload.vhd -- TT-link payload filler 5 -- Mikihiko Nakao, KEK IPNS 8 -- 20140806 first version, split from b2tt_encode.vhd 9 -- 20160316 SEU mitigation bits rearranged 10 -- 20160831 major payload rearrangement 11 -- 20170713 ver, id, rstmask, ebit 14 -- --------------------------------------------------------------------- 16 --- b2tt_payload: library 18 use ieee.std_logic_1164.
all;
19 use ieee.std_logic_unsigned.
all;
20 use ieee.numeric_std.
all;
24 --- b2tt_payload: entity 28 id : in (23 downto 0);
29 ver : in (23 downto 0);
30 utime : in (31 downto 0);
31 myaddr : in (19 downto 0);
39 staictrl : in (1 downto 0);
43 busysrc : in (7 downto 0);
44 feeerr : in (7 downto 0);
46 tag : in (31 downto 0);
57 idly : in (23 downto 0);
60 usrreg : in (7 downto 0);
61 usrdat : in (15 downto 0);
62 cntb2lwe : out (15 downto 0);
63 cntftag : out (15 downto 0);
64 payload : out (111 downto 0) );
67 --- b2tt_payload: architecture 69 signal buf_btime : (23 downto 0) := (others => '0');
70 signal buf_etime : (23 downto 0) := (others => '0');
71 signal cnt_b2lwe : (47 downto 0) := (others => '0');
72 signal cnt_ftag : (23 downto 0) := (others => '0');
73 signal seq_seudet : (1 downto 0) := (others => '0');
74 signal cnt_seudet : (9 downto 0) := (others => '0');
75 signal seq_seuscan : (1 downto 0) := (others => '0');
76 signal cnt_seuscan : (7 downto 0) := (others => '0');
77 signal cnt_payload : (7 downto 0) := (others => '0');
78 signal sta_feeerr : (7 downto 0) := (others => '0');
79 signal sta_fifoerr : := '0';
80 --signal sta_fifoful : std_logic := '0'; 81 signal sta_tagerr : := '0';
82 signal sta_timerr : := '0';
83 signal sta_clkup : := '0';
84 signal sta_ttup : := '0';
85 signal sta_b2lup : := '0';
86 signal sta_b2pll : := '0';
87 signal sig_clklost : := '0';
88 signal sig_ttlost : := '0';
89 signal sig_b2llost : := '0';
90 signal sig_plllost : := '0';
91 signal sta_clklost : := '0';
92 signal sta_ttlost : := '0';
93 signal sta_b2llost : := '0';
94 signal sta_plllost : := '0';
95 signal sig_errreset : := '0';
96 signal sta_anyerr : := '0';
97 signal seq_anyerr : := '0';
98 signal seq_ereg : := '0';
99 signal seq_b2lwe : (1 downto 0) := (others => '0');
101 signal sta_clost : := '0';
102 signal sta_terr : := '0';
103 signal sta_rerr : := '0';
104 signal sta_ebit : (5 downto 0) := (others => '0');
106 signal cnt_cklost : (2 downto 0) := (others => '0');
107 signal cnt_ttlost : (2 downto 0) := (others => '0');
108 signal cnt_lklost : (2 downto 0) := (others => '0');
110 signal sta_anybsy : := '0';
112 signal buf_ereg : (31 downto 0) := (others => '0');
113 signal buf_payload : (111 downto 0) := (others => '0');
114 alias rega : (31 downto 0) is buf_payload(63 downto 32);
115 alias regb : (31 downto 0) is buf_payload(31 downto 0);
118 ( sta: ; rst: ; sig: )
return is 127 --- b2tt_payload: begin 130 sig_errreset <= errreset or runreset;
132 sta_clost <= '1' when staictrl /= "11" else (sta_clklost or sta_plllost);
133 sta_terr <= '1' when sta_ebit /= 0 else '0';
134 sta_rerr <= '1' when sta_feeerr /= 0 else '0';
135 sta_anyerr <= sta_terr or sta_clost or (not b2ttup) or sta_ttlost or 136 sta_rerr or (not b2linkup) or sta_b2llost;
137 sta_anybsy <= '1' when busysrc /= 0 else fifoful;
140 proc_b2l:
process (b2lclk)
142 if rising_edge(b2lclk) then 143 if b2clkup = '0' or b2linkup = '0' or runreset = '1' then 144 cnt_b2lwe <= (others => '0');
145 cnt_ftag <= (others => '0');
147 if b2linkwe = '1' then 148 cnt_b2lwe <= cnt_b2lwe + 1;
150 if b2ttnext = '1' then 151 cnt_ftag <= cnt_ftag + 1;
158 proc:
process (clock)
160 if clock'event and clock = '1' then 162 --- seq_seudet, cnt_seudet 163 seq_seudet <= seq_seudet(0) & semdet;
164 if semreset = '1' then 165 cnt_seudet <= (others => '0');
166 elsif seq_seudet = "01" then 167 cnt_seudet <= cnt_seudet + 1;
170 --- seq_seuscan, cnt_seuscan 171 seq_seuscan <= seq_seuscan(0) & semscan;
172 if semreset = '1' then 173 cnt_seuscan <= (others => '0');
174 elsif seq_seuscan = "01" then 175 cnt_seuscan <= cnt_seuscan + 1;
179 sta_clkup <= b2clkup;
181 sta_b2lup <= b2linkup;
182 sta_b2pll <= b2plllk;
184 sig_clklost <= sta_clkup and (not b2clkup);
185 sig_ttlost <= sta_ttup and (not b2ttup);
186 sig_b2llost <= sta_b2lup and (not b2linkup);
187 sig_plllost <= sta_b2pll and (not b2plllk);
189 sta_clklost <= setsta(sta_clklost, sig_errreset, sig_clklost);
190 sta_ttlost <= setsta(sta_ttlost, sig_errreset, sig_ttlost);
191 sta_b2llost <= setsta(sta_b2llost, sig_errreset, sig_b2llost);
192 sta_plllost <= setsta(sta_plllost, sig_errreset, sig_plllost);
195 if sig_errreset = '1' then 196 sta_feeerr <= (others => '0');
198 sta_feeerr <= sta_feeerr or feeerr;
200 sta_fifoerr <= setsta(sta_fifoerr, sig_errreset, fifoerr);
201 sta_tagerr <= setsta(sta_tagerr, sig_errreset, tagerr);
202 sta_timerr <= setsta(sta_timerr, sig_errreset, timerr);
204 sta_ebit <= sta_tagerr & 212 if buf_btime = 0 then 213 buf_btime <= utime(23 downto 0);
216 -- etime (event time) 217 seq_anyerr <= sta_anyerr;
218 seq_b2lwe <= seq_b2lwe(0) & b2linkwe;
219 if sta_anyerr /= seq_anyerr or seq_b2lwe(1) /= seq_b2lwe(0) then 220 buf_etime <= utime(23 downto 0);
225 if seq_ereg = '1' then 229 -- "count" lost transitions 230 if sig_errreset = '1' then 235 -- 2017.0708.0721 no limit to detect frequent lost 236 if sig_clklost = '1' then 237 cnt_cklost(2) <= cnt_cklost(2) or (cnt_cklost(1) and cnt_cklost(0));
238 cnt_cklost(1 downto 0) <= cnt_cklost(1 downto 0) + 1;
240 if sig_ttlost = '1' then 241 cnt_ttlost(2) <= cnt_ttlost(2) or (cnt_ttlost(1) and cnt_ttlost(0));
242 cnt_ttlost(1 downto 0) <= cnt_ttlost(1 downto 0) + 1;
244 if sig_b2llost = '1' then 245 cnt_lklost(2) <= cnt_lklost(2) or (cnt_lklost(1) and cnt_lklost(0));
246 cnt_lklost(1 downto 0) <= cnt_lklost(1 downto 0) + 1;
251 buf_payload(91 downto 84) <= cnt_payload;
252 buf_payload(83) <= '0';
-- dsel is always 0 at FEE 253 buf_payload(82) <= not b2ttup;
254 buf_payload(81) <= sta_anybsy;
255 buf_payload(80) <= sta_anyerr;
256 buf_payload(79 downto 70) <= (others => '0');
-- 10 bit reserved 259 if b2clkup = '0' then 260 buf_payload(111 downto 92) <= x"feeee";
-- impossible address 261 rega <= "
000" & TTREG_CLOST & "
0010" & x"0dead";
262 elsif fillsig = '1' then 263 buf_payload(111 downto 92) <= myaddr;
265 -- here we don't care overflow, it is watched in the upstream 266 buf_payload(69 downto 64) <= cnt_seudet(5 downto 0);
269 -- trigger will be blocked if rega /= TTREG_FTAG 270 if sta_clklost = '1' or sta_plllost = '1' or staictrl /= "11" then 271 rega <= "
000" & TTREG_CLOST & "000"
272 & sta_clklost & (not b2plllk) & sta_plllost 273 & (not staictrl) & cnt_cklost & "0" & x"000";
-- 1d 274 elsif b2ttup = '0' then 275 rega <= "
000" & TTREG_TDOWN & '0' & cnt_ttlost & x"00000"; --
1c 276 elsif sta_ttlost = '1' then 277 rega <= "
000" & TTREG_TLOST & '0' & cnt_ttlost & x"00000"; --
1b 278 elsif sta_ebit /= 0 then 279 rega <= "
000" & TTREG_TERR & sta_ebit & "
00" & x"0000"; --
1a 280 elsif feeerr /= 0 then 281 rega <= "
000" & TTREG_FERR & feeerr & x"0000"; --
19 282 elsif sta_feeerr /= 0 then 283 rega <= "
000" & TTREG_RERR & sta_feeerr & x"0000"; --
18 284 elsif b2linkup = '0' then 285 rega <= "
000" & TTREG_LDOWN & '0' & cnt_lklost & x"00000"; --
17 286 elsif sta_b2llost = '1' then 287 rega <= "
000" & TTREG_LLOST & '0' & cnt_lklost & x"00000"; --
16 289 -- always showing "tagdone" unless there is an error 290 -- which unrecoverable without runreset 291 rega <= "
000" & TTREG_FTAG & cnt_ftag; --
0c 295 -- if regb is not selected by regsel, error bit is sent, which 296 -- will be merged in upstream 298 -- registers used for rega has not much meaning for regsel at FEE 299 -- and has no effect here, but they makes sense at intemediate FTSWs 300 if regsel = TTREG_USR then -- 01 301 regb <= "
000" & regsel & usrreg & usrdat;
302 elsif regsel = TTREG_VER then -- 02 303 regb <= "
000" & regsel & ver;
304 elsif regsel = TTREG_ID then -- 03 305 regb <= "
000" & regsel & id;
306 elsif regsel = TTREG_PREG then -- 04 308 elsif regsel = TTREG_EREG then -- 05 309 regb <= "
000" & buf_ereg(
28 downto 0);
310 elsif regsel = TTREG_BTIME then -- 06 311 regb <= "
000" & regsel & buf_btime(
23 downto 0);
312 elsif regsel = TTREG_ETIME then -- 07 313 regb <= "
000" & regsel & buf_etime;
314 elsif regsel = TTREG_WCNTL then -- 08 315 regb <= "
000" & regsel & cnt_b2lwe(
23 downto 0);
316 elsif regsel = TTREG_WCNTH then -- 09 317 regb <= "
000" & regsel & cnt_b2lwe(
47 downto 24);
318 elsif regsel = TTREG_FTAG then -- 0a 319 regb <= "
000" & regsel & cnt_ftag;
320 elsif regsel = TTREG_TTAG then -- 0b 321 regb <= "
000" & regsel & tag(
23 downto 0);
322 elsif regsel = TTREG_SEM then -- 0c 323 regb <= "
000" & regsel &
324 semmbe & semcrc & semdet & semscan & "00" & 325 cnt_seudet & cnt_seuscan;
326 elsif regsel = TTREG_IDLY then -- 13 327 regb <= "
000" & regsel & idly;
328 elsif regsel = TTREG_EBIT then -- 15 329 regb <= "
000" & regsel &
332 sta_clost & (not b2ttup) & sta_ttlost & -- 3 bit 333 (not b2linkup) & sta_b2llost & -- 2 bit 335 elsif regsel = TTREG_FERR then -- 19 336 regb <= "
000" & regsel & feeerr & x"0000";
337 elsif regsel = TTREG_TMASK or 338 (regsel /= TTREG_BUSY and trgmask = '1') then -- 0f 339 regb <= "
000" & TTREG_TMASK & sta_anyerr & sta_anybsy &
340 rstmask & trgmask & (not b2ttup) & "000" & x"0000";
341 elsif regsel = TTREG_BUSY or busysrc /= 0 then -- 14 342 regb <= "
000" & TTREG_BUSY & busysrc & fifoful & "
000" & x"000";
347 cnt_payload <= cnt_payload + 1;
353 payload <= buf_payload;
354 cntftag <= cnt_ftag(cntftag'left downto 0);
355 cntb2lwe <= cnt_b2lwe(cntb2lwe'left downto 0);
357 --- b2tt_payload: end