-static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/Attic/hwtrig.c,v 6.12 2001-04-11 10:56:05 hades Exp $";
+static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/Attic/hwtrig.c,v 6.13 2001-04-11 13:13:54 hades Exp $";
#define _POSIX_C_SOURCE 199309L
#include <unistd.h>
+#include <assert.h>
+#include <errno.h>
#include <sys/time.h>
+#include <allParam.h>
#include <lvme.h>
#include "subevt.h"
-#include <allParam.h>
+#include "hwtip.h"
+
+#define NCRATES 3 /* Number of TOF crates */
#define MU_EVT_COUNT 0x0e8014UL
#define MU_FIFO 0x0000UL
LVme *lvme6;
LVme_L evtCount;
LVme_L old_evtCount;
+ HwTip *tip;
size_t maxSubEvtSize;
};
Param *param;
my = allocMem(sizeof(Hardware));
- my->maxSubEvtSize = 3 * SubEvt_hdrSize() + 10 * sizeof(UInt4);
+ my->maxSubEvtSize = (SubEvt_hdrSize() + 2 * 500 * sizeof(UInt4)) /* MU */
+ + (SubEvt_hdrSize() + (NCRATES * 620 * sizeof(UInt4))); /* CONC */
my->evtCount = 0;
my->old_evtCount = 0;
cardBase = 0;
}
- desParam(param);
-
my->lvme0 = allocMem(sizeof(LVme));
if (0 > conLVme(my->lvme0, cardBase, 0x100000UL, 0x09UL, 0, 0)) {
msglog(LOG_ERR, "MU on %p not found\n", cardBase);
return NULL;
}
+ my->tip = allocMem(sizeof(HwTip));
+ if (0 > conHwTip(my->tip, "conc", param)) {
+ msglog(LOG_ERR, "%s:%d:%s\n", __FILE__, __LINE__, strerror(errno));
+ return NULL;
+ }
+
+ desParam(param);
+
return my;
}
void deleteHardware(Hardware *my)
{
+ desHwTip(my->tip);
+ freeMem(my->tip);
+
desLVme(my->lvme6);
freeMem(my->lvme6);
desLVme(my->lvme4);
void Hardware_waitForTrigger(Hardware *my, void *partEvt)
{
+/*
+* check if CONC is ready
+*/
+
+ if (HwTip_isEmpty(my->tip)) {
+ HwTip_requestBuffer(my->tip);
+ while (HwTip_isBusy(my->tip)) {
+ /* wait for some time for not disturbing the DSP */
+ struct timespec tS, *t = &tS;
+ t->tv_sec = 0;
+ t->tv_nsec = 100000000;
+ nanosleep(t, NULL);
+ }
+ }
+
+/*
+* check if MU is ready
+*/
+
/*
only read the Matching Unit Count register, when all pending
events are processed. This is recommended, because it is very
my->old_evtCount=LVme_getL(my->lvme0, MU_EVT_COUNT);
while (my->evtCount == my->old_evtCount) {
-#if 1
+ /* wait for some time for not disturbing the DSP */
struct timespec tS, *t = &tS;
-
t->tv_sec = 0;
- t->tv_nsec = 400000000UL;
+ t->tv_nsec = 100000000UL;
nanosleep(t, NULL);
my->old_evtCount=LVme_getL(my->lvme0, MU_EVT_COUNT);
-#endif
}
my->evtCount++;
{
UInt4 *data;
size_t size;
- int i;
data = SubEvt_begin(subEvt);
*data++ = LVme_getW(my->lvme4, MU_FIFO) & 0xffff;
SubEvt_setDecoding(subEvt, SubEvtDecoding_32bitData);
- while (data < SubEvt_end(subEvt)) {
+ while ((void *)data < SubEvt_end(subEvt)) {
*data++ = LVme_getW(my->lvme4, MU_FIFO) & 0xffff;
}
static unsigned long trigNr = 0;
UInt1 trigTag;
UInt1 trigCode;
+ int i;
SubEvt_setDecoding(partEvt, SubEvtDecoding_SubEvts);
+/*
+* read out CONC
+*/
+
+ for (i = 0; i < NCRATES; i++) {
+ HwTip_readSubEvt(my->tip, subEvt);
+ if (i == 0) {
+ trigTag = SubEvt_trigNr(subEvt);
+ } else {
+ if (trigTag != SubEvt_trigNr(subEvt)) {
+ msglog(LOG_ERR, "(%s)Trigger tag mismatch: 0x%08x != 0x%08x\n",
+ my->tip->name, trigTag, SubEvt_trigNr(subEvt));
+ }
+ }
+ subEvt = SubEvt_next(partEvt, subEvt);
+ }
+
+/*
+* read out MU
+*/
+
readoutTrig(my, subEvt);
- trigTag = SubEvt_trigNr(subEvt);
+ if (trigTag != SubEvt_trigNr(subEvt)) {
+ msglog(LOG_ERR, "(MU)Trigger tag mismatch: 0x%08x != 0x%08x\n",
+ trigTag, SubEvt_trigNr(subEvt));
+ }
trigCode = SubEvt_dataValue(subEvt, 0);
subEvt = SubEvt_next(partEvt, subEvt);
SubEvt_setId(partEvt, trigCode);
SubEvt_setTrigNr(partEvt, (trigNr << 8) | trigTag);
trigNr++;
+
+ assert(SubEvt_size(partEvt) <= my->maxSubEvtSize);
#ifndef NDEBUG
msglog(LOG_DEBUG, "partEvt: %s\n", SubEvt_2charP(partEvt));
#endif