--- /dev/null
+#include <assert.h>
+#include <string.h>
+
+#include <sys/time.h>
+#include <hadesstd.h>
+#include <lvme.h>
+
+#if 1
+#include "subevt.h"
+#endif
+#include "param.h"
+
+#include "tof_defs.h"
+#include "hwtip.h"
+
+
+static int bankRequested(HwTip *my) {
+ UInt2 val;
+
+ val = my->bankRequested;
+ return val;
+}
+
+#if 0
+static int bankConfirmed(HwTip *my) {
+ UInt2 val;
+
+ val = -1;
+ return val;
+}
+#endif
+
+static int endOfData(HwTip *my) {
+ return LVme_getL(my->lvme, my->fifo) + my->fifo;
+}
+
+int conHwTip(HwTip * my, const char *name, const Param *param)
+{
+ unsigned long cardBase;
+ int i;
+
+ assert(my != NULL);
+
+ strcpy(my->name, name);
+
+ cardBase = Param_getVal(param, my->name, "cardbase");
+ my->lvme = allocMem(sizeof(LVme));
+ if (0 > conLVme(my->lvme, cardBase, 0x10000000UL, 0x09UL, 0, 0)) {
+ msglog(LOG_ERR, "HwTip on %p not found\n", cardBase);
+ return -1;
+ }
+ my->currAddr = 0xffffffff; /* start at the end */
+ my->bankRequested = 1; /* of the empty bank */
+ my->pipeFull = 1;
+ my->daqRq = 0;
+ my->daqGr = 2;
+ my->fifo = 0x01000000;
+
+ return 0;
+}
+
+void desHwTip(HwTip * my)
+{
+ desLVme(my->lvme);
+}
+
+void HwTip_requestBuffer(HwTip *my) {
+ LVme_clrBitL(my->lvme, EXT_DAQ, my->daqRq);
+ while (LVme_tstBitL(my->lvme, EXT_DAQ, my->daqGr)) {
+#if 1
+ struct timespec tS, *t = &tS;
+ t->tv_sec = 0;
+ t->tv_nsec = 020000000;
+ nanosleep(t, NULL);
+#endif
+ }
+ if (my->bankRequested == 0) {
+ my->bankRequested = 1;
+ my->pipeFull = 2;
+ my->daqRq = 1;
+ my->daqGr = 3;
+ my->fifo = 0x01000800;
+ } else {
+ my->bankRequested = 0;
+ my->pipeFull = 1;
+ my->daqRq = 0;
+ my->daqGr = 2;
+ my->fifo = 0x01000000;
+ }
+ msglog(LOG_DEBUG, "wait for data\n");
+ while (!LVme_tstBitL(my->lvme, EXT_STATUS, my->pipeFull)) {
+#if 1
+ struct timespec tS, *t = &tS;
+ t->tv_sec = 0;
+ t->tv_nsec = 020000000;
+ nanosleep(t, NULL);
+#endif
+ }
+ msglog(LOG_DEBUG, "data available\n");
+ LVme_setBitL(my->lvme, EXT_DAQ, my->daqRq);
+
+ my->currAddr = my->fifo + 0x4;
+}
+
+int HwTip_isBusy(HwTip *my) {
+ return !LVme_tstBitL(my->lvme, EXT_DAQ, my->daqGr);
+}
+
+int HwTip_isEmpty(HwTip *my) {
+ return my->currAddr >= endOfData(my);
+}
+
+int HwTip_readSubEvt(HwTip *my, void *subEvt) {
+ UInt4 *data = (UInt4 *)subEvt;
+ int firstAddr;
+ size_t size;
+ UInt1 trigTag;
+
+#if 0
+ size = LVme_getL(my->lvme, my->currAddr);
+
+ /* copy one sub evt from RC to memory */
+ for (firstAddr = my->currAddr; my->currAddr - firstAddr < size; my->currAddr += 4) {
+ *data++ = LVme_getL(my->lvme, my->currAddr);
+ }
+
+ trigTag = SubEvt_trigNr(subEvt) & 0xff;
+#else
+ my->currAddr = 0xffffffff;
+ SubEvt_setDecoding(subEvt, 0x00020001);
+ SubEvt_setSize(subEvt, 16);
+ SubEvt_setId(subEvt, 1);
+#endif
+
+ /* normal extension of trigger tag */
+ SubEvt_setTrigNr(subEvt, my->trigNr << 8 | trigTag);
+ my->trigNr++;
+
+ return 0;
+}