-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_tofmap.c
executable file
·356 lines (287 loc) · 9.33 KB
/
process_tofmap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/*******************************************************************************
process_tofmap.c
*******************************************************************************/
/*******************************************************************************
includes
*******************************************************************************/
#include "controlshm.h"
#include "debugshm.h"
#include "datashm.h"
#include "needfullthings.h"
#include "process_common.h"
#include "sinqhm_errors.h"
/*******************************************************************************
global vars
*******************************************************************************/
extern volatile unsigned int *shm_cfg_ptr ;
static volatile uint32 *histoDataPtr = 0;
// axis 0 is tube number
static process_axis_type axis_0;
// axis 1 is position in tube
static process_axis_type axis_1;
// axis 2 is Time Of Flight
static process_axis_type axis_2;
static int whole_inc = 1;
static int b0_rank;
static int axis_1_lookup = 0;
/*******************************************************************************
function prototypes;
*******************************************************************************/
void process_tofmap_init_daq(void);
void process_tofmap_destruct(void);
void process_tofmap(packet_type *p);
/*******************************************************************************
function declarations
*******************************************************************************/
/*******************************************************************************
*
* FUNCTION
* process_tofmap_construct
*
* DESCRIPTION
*
*
* PARAMETERS
*
*
* RETURNS
*
*
******************************************************************************/
int process_tofmap_construct(void)
{
volatile histo_descr_type *histo_descr_ptr;
volatile bank_descr_type *bank_descr_ptr;
volatile axis_descr_type *axis_descr_ptr;
int status;
histo_descr_ptr = getShmHistoPtr();
if(!histo_descr_ptr)
{
dbg_printf(DBGMSG_ERROR, "process_tofmap_construct(): can not get data pointer\n");
return SINQHM_ERR_NO_HISTO_DESCR_PTR;
}
if (histo_descr_ptr->nBank != 1)
{
dbg_printf(DBGMSG_ERROR, "process_tofmap_construct(): nbank must be 1 for this filler type\n");
return SINQHM_ERR_WRONG_NUMBER_OF_BANKS;
}
bank_descr_ptr = getBankDescription(0);
if(!bank_descr_ptr)
{
dbg_printf(DBGMSG_ERROR, "process_tofmap_construct(): can not get bank description pointer\n");
return SINQHM_ERR_NO_BANK_DESCR_PTR;
}
b0_rank = bank_descr_ptr->rank;
if ((b0_rank != 2) && (b0_rank != 3))
{
dbg_printf(DBGMSG_ERROR, "process_tofmap_construct(): naxis must be 2 or 3 for this filler type\n");
return SINQHM_ERR_WRONG_NUMBER_OF_AXIS;
}
whole_inc = histo_descr_ptr->increment;
process_packet_fcn = process_tofmap;
process_init_daq_fcn = process_tofmap_init_daq;
process_destruct_fcn = process_tofmap_destruct;
// bank 0, axis 0 is tube - axis
axis_descr_ptr = getAxisDescription(0, 0);
status = SetAxisMapping(axis_descr_ptr, &axis_0, DO_RANGE_CHECK);
if (status<0) return status;
// bank 0, axis 1 is position inside a tube
axis_descr_ptr = getAxisDescription(0, 1);
// Mapping type for axis 1 must be AXLOOKUP
if (axis_descr_ptr->type == AXLOOKUP)
{
axis_1_lookup = 1;
status = SetAxisMapping(axis_descr_ptr, &axis_1, NO_CHECK);
if (status<0) return status;
}
else
{
axis_1_lookup = 0;
status = SetAxisMapping(axis_descr_ptr, &axis_1, DO_RANGE_CHECK);
if (status<0) return status;
}
if (b0_rank > 2)
{
// bank 0, axis 2 is tof - axis
axis_descr_ptr = getAxisDescription(0, 2);
status = SetAxisMapping(axis_descr_ptr, &axis_2, DO_RANGE_CHECK);
if (status<0) return status;
}
histoDataPtr=getHistDataPtr();
if(!histoDataPtr)
{
dbg_printf(DBGMSG_ERROR, "process_tofmap_construct(): can not get histo data pointer\n");
return SINQHM_ERR_NO_HISTO_DATA_PTR;
}
return SINQHM_OK;
}
/******************************************************************************/
void process_tofmap_init_daq(void)
{
*(axis_0.cnt_low_ptr) = 0;
*(axis_0.cnt_high_ptr) = 0;
*(axis_1.cnt_low_ptr) = 0;
*(axis_1.cnt_high_ptr) = 0;
if (b0_rank > 2)
{
*(axis_2.cnt_low_ptr) = 0;
*(axis_2.cnt_high_ptr) = 0;
}
}
/*******************************************************************************
*
* FUNCTION
* process_tofmap_destruct
*
* DESCRIPTION
*
*
* PARAMETERS
*
*
* RETURNS
*
*
******************************************************************************/
void process_tofmap_destruct(void)
{
histoDataPtr = 0;
}
/*******************************************************************************
*
* FUNCTION
* process_tofmap
*
* DESCRIPTION
*
*
* PARAMETERS
*
*
* RETURNS
*
*
******************************************************************************/
void process_tofmap(packet_type *p)
{
uint32 header_type;
uint32 timestamp,binpos;
int32 tube, channel, tofpos, pos;
uint32 data, lookupidx, pos_inc, inc;
// print_packet(p);
header_type = p->data[0] & LWL_HDR_TYPE_MASK;
if ((header_type >= LWL_TOF_C1) && (header_type <= LWL_TOF_C10))
{
if ((p->data[0] & hdr_daq_mask) != hdr_daq_active)
{
// skip
shm_cfg_ptr[CFG_FIL_EVT_SKIPPED]++;
}
else
{
// process
shm_cfg_ptr[CFG_FIL_EVT_PROCESSED]++;
tube = (p->data[1] & LWL_TUBE_MASK) >> LWL_TUBE_SHIFT;
data = (p->data[1] & LWL_DATA_MASK) >> LWL_DATA_SHIFT;
if (tube != LWL_TUBE_ERROR)
{
}
#if 0
{
unsigned int adr, bits_set, bit_pos, test_pos, ds;
data = p->data[1] & 0x1ff;
adr = p->data[1] >> 9;
ds = (p->data[0] >> 24) & 0xf;
dbg_printf(DBGMSG_INFO5,"ds=%d adr=%d (0x%02x)\n",ds,adr,adr);
bits_set = 0;
bit_pos = 0;
test_pos = 1;
while(adr)
{
if (adr & 0x01)
{
bits_set++;
bit_pos = test_pos;
}
adr = adr >> 1;
test_pos ++;
}
if (bits_set > 1)
{
// more than one bits set
shm_cfg_ptr[CFG_FIL_TEST_1]++;
dbg_printf(DBGMSG_INFO5,"More than one bit set\n");
return;
}
tube = bit_pos*10 + ds - 1;
}
#endif
dbg_printf(DBGMSG_INFO5,"tube=%d data=%d\n",tube,data);
channel = axis_0.fcn(tube, &axis_0);
// dbg_printf(DBGMSG_INFO5,"channel=%d \n",channel);
if (channel>=0)
{
if(axis_1_lookup)
{
lookupidx = tube*axis_1.array[2] + data;
// dbg_printf(DBGMSG_INFO5,"lookupidx=%d \n",lookupidx);
pos_inc = axis_1.fcn(lookupidx, &axis_1);
// dbg_printf(DBGMSG_INFO5,"pos_inc=%d \n",pos_inc);
pos = pos_inc >> 16;
inc = pos_inc & 0x0ffff;
}
else
{
inc = whole_inc;
pos = axis_1.fcn(data, &axis_1);
if (pos<0) return;
}
// dbg_printf(DBGMSG_INFO5,"pos=%d inc=%d\n",pos,inc);
if (pos>=axis_1.len)
{
// dbg_printf(DBGMSG_INFO5,"process_tofmap_construct(): pos=%d\n",pos);
(*(axis_1.cnt_high_ptr))++;
}
else
{
if (b0_rank<3)
{
// No Tof needed;
binpos = (channel * axis_1.len) + pos;
UINT32_INC_X_CEIL_CNT_OVL(histoDataPtr[binpos], inc, shm_cfg_ptr[CFG_FIL_BIN_OVERFLOWS]);
// dbg_printf(DBGMSG_INFO5,"histoDataPtr[%d]=%d\n",binpos,histoDataPtr[binpos]);
if ((inc<whole_inc) && ((channel+1)<axis_0.len))
{
UINT32_INC_X_CEIL_CNT_OVL(histoDataPtr[binpos+(axis_1.len)], (whole_inc-inc), shm_cfg_ptr[CFG_FIL_BIN_OVERFLOWS]);
}
}
else
{
timestamp = p->data[0] & LWL_HDR_TS_MASK;
// dbg_printf(DBGMSG_INFO5,"timestamp=%d --",timestamp);
tofpos = axis_2.fcn(timestamp, &axis_2);
// dbg_printf(DBGMSG_INFO5,"tofpos=%d\n",tofpos);
if (tofpos>=0)
{
// dbg_printf(DBGMSG_INFO5,"channel=%d tofpos=%d\n",channel,tofpos);
binpos = (channel * axis_2.len * axis_1.len) + (pos * axis_2.len) + tofpos ;
UINT32_INC_X_CEIL_CNT_OVL(histoDataPtr[binpos], inc, shm_cfg_ptr[CFG_FIL_BIN_OVERFLOWS]);
// dbg_printf(DBGMSG_INFO5,"histoDataPtr[%d]=%d\n",binpos,histoDataPtr[binpos]);
if ((inc<whole_inc) && ((channel+1)<axis_0.len))
{
UINT32_INC_X_CEIL_CNT_OVL(histoDataPtr[binpos+(axis_2.len * axis_1.len)], (whole_inc-inc), shm_cfg_ptr[CFG_FIL_BIN_OVERFLOWS]);
}
}
}
}
}
}
}
else if (!process_tsi(p))
{
// unknown packet
UINT32_INC_CEIL(shm_cfg_ptr[CFG_FIL_PKG_UNKNOWN]);
UINT32_INC_CEIL(shm_cfg_ptr[CFG_FIL_SUM_PKG_UNKNOWN]);
}
}
/*******************************************************************************/