#include #include #include #ifdef BASE_HAS_NO_NTP_PATCH #include #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* for DEBUGPRINT */ #include #include #include "devWfPadBpm.h" /* twisted 4/14/8, but DevWfPadDpvt_tps needed */ #include "drvPadBpm.h" #undef DEBUG #ifdef DEBUG_PRINT int drvPadBpmFlag = 4; /*4/14/8*/ #endif void padUdpThread(void *arg); extern IpBscIf lanIpIf; /*4/16/8 was static */ epicsThreadId drvPadStreamInit(); /*4/16/8 was static */ void * getdata(void *packBuffer, int idx, int nsamples, int endianLittle, int colMajor, void *uarg) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("getdata: nsamples is %d\n", nsamples)); #endif assert ( 0 == ( nsamples & 1 ) ); if ( colMajor ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("getdata: reading %d*4 samples in column major order into 0x%0x\n", nsamples, (unsigned int) LAN9118_FIFO_HACK)); #endif drvPadReadFifosColMajor( LAN9118_FIFO_HACK, nsamples * 4, endianLittle ); } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("getdata: reading %d*4 samples in row major order into 0x%0x\n", nsamples, (unsigned int) LAN9118_FIFO_HACK)); #endif drvPadReadFifosRowMajor( LAN9118_FIFO_HACK, nsamples * 4, endianLittle ); } return 0; } static long drvPadStreamReport(int level) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("PAD Stream Support for Communication with BPM Processor\n")); DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("over 2nd Ethernet Interface\n")); #endif if ( level > 1 ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("Dumping Interface Statistics\n"); #endif drvLan9118DumpStats(lanIpBscIfGetDrv(lanIpIf), 0)); } return 0; } static int start_stop_cb(int start, void *uarg) { return devPadWfSetRarm(start ? 2 : 0); } /*4/16/8 was static*/ epicsThreadId drvPadStreamInit() { char *padslot; int channel; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("drvPadStreamInit:\n")); #endif if ( padStreamInitialize(lanIpIf, start_stop_cb, 0) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvPadBpmFlag, ("drvPadStreamInit: error calling padStreamInitialize\n")); #endif return 0; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("drvPadStreamInit: padStreamInitialize successful\n")); #endif if ( !(padslot = getenv("PADSLOT")) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvPadBpmFlag, ("drvPadStreamInit: enviroment variable PADSLOT not set\n")); #endif return 0; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("drvPadStreamInit: padslot set to enviroment variable PADSLOT: %s\n",padslot)); #endif channel = atoi(padslot); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("drvPadStreamInit: Starting UDP listener for PAD channel %i\n", channel)); #endif return epicsThreadCreate( "padUdpListener", epicsThreadPriorityScanHigh, epicsThreadGetStackSize(epicsThreadStackMedium), padUdpThread, (void*)channel); } /*4/16/8 was static*/ void padThread(void *arg) { waveformRecord *waveform_ps = arg; DevWfPadDpvt_tps dpvt_ps = waveform_ps->dpvt; PadDataKind kind; int isCal, status; while (1) { epicsEventWait( dpvt_ps->sync ); kind = PadDataBpm; #ifdef AFE /* A CAL event ? */ if ( (isCal = gotCalt) ) { switch ( AFE_REG_CSR_CALM_GET(drvPadAfeRegCache[AFE_REG_CSR]) ) { case AFE_REG_CSR_CALM_RED: kind = PadDataCalRed; break; case AFE_REG_CSR_CALM_GRN: kind = PadDataCalGrn; break; case AFE_REG_CSR_CALM_BOTH: /* TODO -- handle this case */ break; case AFE_REG_CSR_CALM_NONE: default: break; } } #endif if ( waveform_ps->rarm == 10 ) { if ( PadDataBpm == kind ) status = padStreamSim(0); else status = 0; /* ignore cal data -- otherwise we * might be unable to keep up if they * are triggering fast */ } else { status = padStreamSend(getdata, kind, 0, 0); } /* Toggle CAL mode; if we're not in 'soft toggle' mode * then nothing happens. */ drvPadCalToggle(AFE_CS); /* If we can't send streaming data then * 'ordinary' record support is engaged. */ if ( status ) { dpvt_ps->irq = 1; /* signal IRQ */ if ( epicsTimeEventDeviceTime == waveform_ps->tse ) { #ifdef BASE_HAS_NO_NTP_PATCH struct ntptimeval ntv; if ( 0 == ntp_gettime(&ntv) ) { #ifdef NTP_NANO epicsTimeFromTimespec(&waveform_ps->time, &ntv.time); #else epicsTimeFromTimeval(&waveform_ps->time, &ntv.time); #endif } else #endif epicsTimeGetEvent(&waveform_ps->time, epicsTimeEventCurrentTime); } /* stream not active; process record */ callbackRequestProcessCallback(&dpvt_ps->cb_s, priorityHigh, dpvt_ps->rec_p); } else { /* Clear interrupt here so we can detect a trigger overrun */ coldfEportFlagClr(dpvt_ps->irq_pin); /* release trigger pin */ coldfEportEpdrSet(dpvt_ps->trig_pin, 0); coldfEportIntEnable(dpvt_ps->irq_pin); } } } void padUdpThread(void *arg) { int err; /* use default port and channel number passed as arg */ if ( (err = padUdpHandler(0, (int)arg)) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvPadBpmFlag, ("ERROR: padUdpHandler() aborted: %s\n", strerror(-err))); #endif } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvPadBpmFlag, ("padUdpThread: padUdpHandler started successfully\n")); #endif }