StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
stage_3_tonko_202101.cxx
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <string.h>
4 
5 #include "fcs_trg_base.h"
6 #include "fcs_ecal_epd_mask.h"
7 
8 /*
9  Tonko's test code used in Feb+ 2021
10 
11 
12  Will be stage_version 0xFF210201
13 */
14 
15 // 4 stage2 links: 2 north, 2 south
16 // 1 DSM output
17 // 6 FPRE links
18 
19 static int or_reduce(int d8)
20 {
21  if(d8) return 1 ;
22  return 0 ;
23 }
24 
25 void fcs_trg_base::stage_3_tonko_202101(link_t s2[], u_short *dsm)
26 {
27  u_short out_s ;
28  u_short out_n ;
29  u_short n_or = 0 ;
30  u_short s_or = 0 ;
31  u_short big_or = 0 ;
32 
33  out_s = 0 ;
34  out_n = 0 ;
35 
36  for(int i=0;i<8;i++) {
37  out_n |= (or_reduce(s2[0].d[i]) || or_reduce(s2[1].d[i]))<<i ;
38  out_s |= (or_reduce(s2[2].d[i]) || or_reduce(s2[3].d[i]))<<i ;
39  }
40 
41  big_or = s2[0].d[7] & 0x80 ;
42  big_or |= s2[1].d[7] & 0x80 ;
43  big_or |= s2[2].d[7] & 0x80 ;
44  big_or |= s2[3].d[7] & 0x80 ;
45 
46  if(big_or) big_or = 1 ;
47  else big_or = 0 ;
48 
49  n_or = s2[0].d[7] & 0x80 ;
50  n_or |= s2[1].d[7] & 0x80 ;
51  s_or = s2[2].d[7] & 0x80 ;
52  s_or |= s2[3].d[7] & 0x80 ;
53 
54  if(n_or) n_or = 1 ;
55  if(s_or) s_or = 1 ;
56 
57 
58  out_n &= 0xF8 ;
59  out_n |= (s_or<<2)|(n_or<<1)|big_or ; // bit(0) is a HT-like indicator
60 
61 
62  int sel = (stage_params[3][0]>>1)&0x7 ;
63 
64  switch(sel) {
65  case 0 :
66  *dsm = (out_s<<8)|out_n ;
67  break ;
68  case 3 :
69  *dsm = stage_params[3][1] ;
70  break ;
71  default :
72  *dsm = 0xDEAD ;
73  break ;
74  }
75 
76 #if 0
77  for(int i=0;i<8;i++) {
78  printf("%d: 0x%X 0x%X 0x%X 0x%X\n",i,s2[0].d[i],s2[1].d[i],s2[2].d[i],s2[3].d[i]) ;
79  }
80  printf(" sel is %d, dsm is 0x%04X\n",sel,*dsm) ;
81 #endif
82  return ;
83 }
84