6 #include <rtsSystems.h>
7 #include <daqFormats.h>
13 int ric_reader(
char *m,
struct ric_t *ric, u_int driver)
23 ric->max_channels = 16*960 ;
26 if(datap == NULL)
return 0 ;
28 len = ntohl(datap->det[RIC_ID].len) * 4 ;
29 if(len == 0)
return 0 ;
31 off = ntohl(datap->det[RIC_ID].off) ;
32 if(off == 0)
return 0 ;
35 LOG(DBG,
"RIC len %d, off %d",len,off,0,0,0) ;
37 ricp = (
struct RICP *)((u_int *)m + off) ;
39 if(checkBank(ricp->bh.bank_type,CHAR_RICP) < 0) {
46 memset(ric->adc,0,
sizeof(ric->adc)) ;
51 for(cram=0;cram<16;cram++) {
54 if(ricp->crams[cram].len <= 0) continue ;
56 riccramp = (
struct RICCRAMP *)((u_int *)ricp + b2h32(ricp->crams[cram].off)) ;
58 if(checkBank(riccramp->bh.bank_type,CHAR_RICCRAMP) < 0) {
62 for(banks=0;banks<8;banks++) {
66 if(riccramp->banks[banks].len <= 0) continue ;
68 if(banks != RIC_BANK_DATAD) {
69 LOG(DBG,
"Found non-DATAD bank %d - skipping...",banks,0,0,0,0) ;
75 ricdatad = (
struct RICDATAD *)((u_int *)riccramp + b2h32(riccramp->banks[banks].off)) ;
78 LOG(DBG,
"Bank id is %d...",banks,0,0,0,0) ;
80 if(checkBank(ricdatad->bh.bank_type,CHAR_RICDATAD) < 0) {
85 cou = b2h32(ricdatad->bh.length) -
sizeof(
struct bankHeader)/4 ;
87 LOG(DBG,
"RICH bank %d, CRAM %d has %d entries...",banks,cram,cou,0,0) ;
89 if(cou == 0) continue ;
92 for(i=0;i<cou*2;i+=2) {
95 ch = b2h16(ricdatad->data[i]) ;
96 adc = b2h16(ricdatad->data[i+1]) ;
98 if(adc > 1023) adc = 1023 ;
100 if(adc == 0) continue ;
104 LOG(ERR,
"RICH channel %d >= 960!",ch,0,0,0,0) ;
108 ric->adc[cram][ch] = adc ;