#include #include #include "ti_dsp.h" /* ---------------------------------------------------------------------- Load the DP RAM with nevts events taken from file "testbeam2.data" mode=0: Set the DP RAM event counter after the last event. mode=1: Set the DP RAM event counter after each event ---------------------------------------------------------------------- */ void ti_feedevt(ti_dsp_p dsp, int nevts, int mode) { /* --- These must match the format of the input binary file */ const int nsamp=5, nwords=4*(1+8*nsamp); static FILE *fd; /* testbeam.data file */ static unsigned int *data; /* Local event buffer */ static unsigned int Nevt; /* Total number of events sent */ unsigned int dp_addr; /* --- Initialization */ if (fd == NULL){ fd = fopen("testbeam2.data", "rb"); if (fd == NULL){ perror("ti_feedevt: Cannot open file testbeam2.data"); exit(1); } data = malloc(nwords*sizeof(int)); if (data == NULL){ perror("ti_feedevt: malloc()"); exit(1); } } /* --- Send events */ while(nevts--){ /* -- User routine called every trigger */ ti_utrig(dsp, 0x0123, 0x0a01, 0xab); /* -- Read next event from file */ fread(data, sizeof(int), nwords, fd); if (feof(fd)){ free(data); fclose(fd); fd = NULL; break; } #ifdef __i386 fswibm(data, nwords); #endif /* -- Copy event to dual-port memory */ dp_addr = (Nevt & 127) << 8; ti_dpcpy(dsp, dp_addr, data, nwords); Nevt++; /* -- Set both TTC and FEB event counters */ if (mode) ti_dpset(dsp, 0x7fff, Nevt | (Nevt << 16), 1); } /* -- Set both TTC and FEB event counters */ ti_dpset(dsp, 0x7fff, Nevt | (Nevt << 16), 1); ti_dpset(dsp, 0x7fff, Nevt | (Nevt << 16), 1); ti_dpset(dsp, 0x7fff, Nevt | (Nevt << 16), 1); ti_dpset(dsp, 0x7fff, Nevt | (Nevt << 16), 1); vme_check(); }