Index: ChangeLog =================================================================== RCS file: /afs/slac/g/lcls/cvs/epics/site/src/udpComm/ChangeLog,v retrieving revision 1.54 retrieving revision 1.57 diff -c -r1.54 -r1.57 *** ChangeLog 6 Mar 2012 10:52:52 -0000 1.54 --- ChangeLog 24 May 2012 23:08:59 -0000 1.57 *************** *** 1,3 **** --- 1,35 ---- + 20120524 (T.S.) + - BUGFIX: src/drvPadAdcStream.c - when reading the FIFOS the first + couple of samples must be skipped as they generate initial + clock cycles. Until now we used the stream packet index == 0 + condition to detect the first samples. With multi-packet + streams this is no longer correct. E.g., in row-major format + a new row is started at a non-zero index. + As a result, the second argument to 'drvPadReadFifosXXXMajor()' + was changed (but is backwards compatible for streams with + only single packets). + - API CHANGE: src/padStream.h, src/drvPadAdcStream.h, + src/drvPadAdcStream.c: + PadStreamGetdataProc() received a new, additional + argument: the total number of samples per channel (= 'row dimension'). + This helps the low-level driver with formatting the data. + CAVEAT: 'getdata' routines on PADs need to be updated to respect + the new API. + - src/drvPadUdpComm.c UDP listener thread priority increased + from epicsThreadPriorityHigh -> epicsThreadPriorityMax. + - src/padStream.c: FIXED maximum number of samples accepted into + a packet. It turns out that the previous value of 1440 would not + fit (adding all the headers) into a typical MTU of 1500. + Rounded down to the next multiple of 16 (be vector-aligned to + help SIMD on the master side) which are 1424 bytes. + + Updated 'getdata' variants to respect new API (see above). + + 20120514 (T.S.) + - src/fidProcess.c, src/fidProcess.h: Added fidProcessGeneric(). + 20120514 (T.S.) + - src/fidProcess.c, src/fidProcess.h: made global variables + 'fidProcessHasBeam', 'fidHeartbeat' volatile. 20120304 (T.S.) - src/drvPadUdpComm.c: if 'cook' returns a debug code then still post with ordinary 'kind'. Index: RELEASE_SITE =================================================================== RCS file: /afs/slac/g/lcls/cvs/epics/site/src/udpComm/RELEASE_SITE,v retrieving revision 1.11 diff -c -r1.11 RELEASE_SITE *** RELEASE_SITE 2 Mar 2012 20:38:38 -0000 1.11 --- RELEASE_SITE 14 May 2012 18:24:34 -0000 *************** *** 8,16 **** # We will build some tools/scripts that allow us to # change this easily when relocating software. #============================================================================== ! EPICS_SITE_TOP=/afs/slac/g/acctest/epics ! BASE_SITE_TOP=/afs/slac/g/acctest/epics/base ! MODULES_SITE_TOP=/afs/slac/g/acctest/epics/modules/R3-14-12 ! IOC_SITE_TOP=/afs/slac/g/acctest/epics/iocTop/R3-14-12 EPICS_BASE_VER=base-R3-14-12 #============================================================================== --- 8,16 ---- # We will build some tools/scripts that allow us to # change this easily when relocating software. #============================================================================== ! EPICS_SITE_TOP=/afs/slac/g/lcls/epics ! BASE_SITE_TOP=/afs/slac/g/lcls/epics/base ! MODULES_SITE_TOP=/afs/slac/g/lcls/epics/modules/R3-14-12 ! IOC_SITE_TOP=/afs/slac/g/lcls/epics/iocTop EPICS_BASE_VER=base-R3-14-12 #============================================================================== Index: src/drvPadAdcStream.c =================================================================== RCS file: /afs/slac/g/lcls/cvs/epics/site/src/udpComm/src/drvPadAdcStream.c,v retrieving revision 1.2 retrieving revision 1.3 diff -c -r1.2 -r1.3 *** src/drvPadAdcStream.c 9 Jan 2012 21:27:13 -0000 1.2 --- src/drvPadAdcStream.c 24 May 2012 23:07:13 -0000 1.3 *************** *** 1,4 **** ! /* $Id: drvPadAdcStream.c,v 1.2 2012/01/09 21:27:13 strauman Exp $ */ #include #include --- 1,4 ---- ! /* $Id: drvPadAdcStream.c,v 1.3 2012/05/24 23:07:13 strauman Exp $ */ #include #include *************** *** 93,99 **** #define CPY4WS do { CPYWS(0); CPYWS(2); CPYWS(4); CPYWS(6); } while (0) void ! drvPadReadFifosColMajor(volatile void *dst_p_v, int idx, int channels, int n, int do_bswap) { volatile int16_t_a *dst_p = dst_p_v; volatile int16_t_a *src_p = (volatile int16_t_a *)CS1_BASE_ADDR; --- 93,99 ---- #define CPY4WS do { CPYWS(0); CPYWS(2); CPYWS(4); CPYWS(6); } while (0) void ! drvPadReadFifosColMajor(volatile void *dst_p_v, int notFirst, int channels, int n, int do_bswap) { volatile int16_t_a *dst_p = dst_p_v; volatile int16_t_a *src_p = (volatile int16_t_a *)CS1_BASE_ADDR; *************** *** 105,111 **** n *= PADRPLY_STRM_NCHANNELS; ! if ( 0 == idx ) { /* Every channel needs 3 initial clock cycles (Ron uses /CS for the clock also) */ *(volatile uint32_t_a*)(src_p + 0); src_p[0]; *(volatile uint32_t_a*)(src_p + 2); src_p[2]; --- 105,112 ---- n *= PADRPLY_STRM_NCHANNELS; ! /* Weird double negation for sake of bwds compatibility */ ! if ( ! notFirst ) { /* Every channel needs 3 initial clock cycles (Ron uses /CS for the clock also) */ *(volatile uint32_t_a*)(src_p + 0); src_p[0]; *(volatile uint32_t_a*)(src_p + 2); src_p[2]; *************** *** 195,201 **** } void ! drvPadReadFifosRowMajor(volatile void *dst_pv, int idx, int ch, int n, int do_bswap) { volatile int16_t_a *dst_p = dst_pv; volatile int16_t_a *src_p = (volatile int16_t_a *)CS1_BASE_ADDR; --- 196,202 ---- } void ! drvPadReadFifosRowMajor(volatile void *dst_pv, int notFirst, int ch, int n, int do_bswap) { volatile int16_t_a *dst_p = dst_pv; volatile int16_t_a *src_p = (volatile int16_t_a *)CS1_BASE_ADDR; *************** *** 203,209 **** /* Every channel needs 3 initial clock cycles (Ron uses /CS for the clock also) */ ! if ( 0 == idx ) { if ( ch & 1 ) *(volatile uint32_t_a*)(src_p + 0); src_p[0]; if ( ch & 2 ) --- 204,211 ---- /* Every channel needs 3 initial clock cycles (Ron uses /CS for the clock also) */ ! /* Weird double negation for sake of bwds compatibility */ ! if ( ! notFirst ) { if ( ch & 1 ) *(volatile uint32_t_a*)(src_p + 0); src_p[0]; if ( ch & 2 ) *************** *** 242,257 **** } void * ! drvPadAdcStream_getdata(void *packBuffer, int idx, int channels, int nsamples, int d32, int endianLittle, int colMajor, void *uarg) { ! assert ( 0 == ( nsamples & 1 ) ); if ( PADRPLY_STRM_NCHANNELS == channels ) { if ( colMajor ) ! drvPadReadFifosColMajor( LAN9118_FIFO_HACK, idx, PADCMD_STRM_CHANNELS_ALL, nsamples, endianLittle ); else ! drvPadReadFifosRowMajor( LAN9118_FIFO_HACK, idx, PADCMD_STRM_CHANNELS_ALL, nsamples, endianLittle ); } else { ! drvPadReadFifosRowMajor( LAN9118_FIFO_HACK, idx, (1<xid != ((PadReply)((uintptr_t)pb->segs.data[pb->segs.nsegs-1] - (uintptr_t)((PadReply)0)->data))->xid ) { /* fragment already part of a new stream packet */ wavBufFree( pb ); pb = wbStaged[chan][kind] = 0; } } --- 536,551 ---- epicsPrintf("drvPadUdpCommPostRaw: inconsistent segment size, dropping\n"); goto bail; } ! ! oxid = ((PadReply)((uintptr_t)pb->segs.data[pb->segs.nsegs-1] - (uintptr_t)((PadReply)0)->data))->xid; ! if ( rply->xid != oxid ) { /* fragment already part of a new stream packet */ wavBufFree( pb ); pb = wbStaged[chan][kind] = 0; + + if ( ( drvPadUdpCommDebug & 2 ) ) { + errlogPrintf("postRaw[%i][%i]: XID overrun, dropping (old: 0x%08"PRIx32", new: 0x%08"PRIx32"\n", chan, kind, rply->xid, oxid); + } } } *************** *** 562,567 **** --- 569,578 ---- pb->usrData = (void*)FRAG_MAX; pb->ts.secPastEpoch = ntohl(rply->timestampHi); pb->ts.nsec = ntohl(rply->timestampLo); + + if ( ( drvPadUdpCommDebug & 2 ) ) { + errlogPrintf("postRaw[%i][%i]: new buffer: m %u, segs.m %u, segs.n %u\n", chan, kind, pb->m, pb->segs.m, pb->segs.n); + } } idx = PADRPLY_STRM_CMD_IDX_GET( rply->strm_cmd_idx ); *************** *** 571,581 **** --- 582,600 ---- goto bail; } + if ( ( drvPadUdpCommDebug & 2 ) ) { + errlogPrintf("postRaw[%i][%i]: idx %i, usrData: %"PRIiPTR"\n", chan, kind, idx, (intptr_t)pb->usrData); + } + if ( idx + 1 > pb->segs.nsegs ) pb->segs.nsegs = idx + 1; pb->segs.data[idx] = rply->data; pkt = 0; + if ( ( drvPadUdpCommDebug & 2 ) ) { + errlogPrintf("postRaw[%i][%i]: idx %i\n", chan, kind, idx); + } + if ( ! (PADRPLY_STRM_CMD_IDX_MF & rply->strm_cmd_idx) ) { /* found the last fragment */ pb->usrData = (void*)( (uintptr_t)pb->usrData - FRAG_MAX + idx + 1 - 1 ); *************** *** 584,589 **** --- 603,612 ---- pb->usrData = (void*)( (uintptr_t)pb->usrData - 1 ); } + if ( ( drvPadUdpCommDebug & 2 ) ) { + errlogPrintf("postRaw[%i][%i]: new usrData: %"PRIiPTR"\n", chan, kind, (intptr_t)pb->usrData); + } + if ( 0 == (uintptr_t)pb->usrData ) { /* All fragments assembled */ *************** *** 732,737 **** --- 755,764 ---- cook_stat = -1; } + if ( drvPadUdpCommDebug & 1 ) { + errlogPrintf("STRM: cook_stat %i\n", cook_stat); + } + posted = 0; if ( cook_stat >= 0 ) { *************** *** 1004,1010 **** epicsThreadCreate( "drvPadUdpCommListener", ! epicsThreadPriorityHigh, 4*epicsThreadGetStackSize(epicsThreadStackBig), drvPadUdpCommListener, 0); --- 1031,1037 ---- epicsThreadCreate( "drvPadUdpCommListener", ! epicsThreadPriorityMax, 4*epicsThreadGetStackSize(epicsThreadStackBig), drvPadUdpCommListener, 0); Index: src/fidProcess.c =================================================================== RCS file: /afs/slac/g/lcls/cvs/epics/site/src/udpComm/src/fidProcess.c,v retrieving revision 1.4 retrieving revision 1.6 diff -c -r1.4 -r1.6 *** src/fidProcess.c 7 Jun 2011 03:24:33 -0000 1.4 --- src/fidProcess.c 14 May 2012 17:56:50 -0000 1.6 *************** *** 10,17 **** #include volatile DrvPadUdpCommHWTime fidTimeBaseline = 0; ! int fidProcessHasBeam = 0; ! unsigned fidHeartbeat = 0; void fidTestProcess(void) __attribute__((weak, alias("fidTestProcess_default"))); --- 10,17 ---- #include volatile DrvPadUdpCommHWTime fidTimeBaseline = 0; ! volatile int fidProcessHasBeam = 0; ! volatile unsigned fidHeartbeat = 0; void fidTestProcess(void) __attribute__((weak, alias("fidTestProcess_default"))); *************** *** 27,67 **** #define E_MOD2 1 #define E_MOD5 4 ! void ! fidTimeGetBaseline_generic(void *unused) { #ifndef TEST_ONLY /* This is actually an array type */ evrModifier_ta modifier_a; - epicsTimeStamp time_s; unsigned long patternStatus; int st; ! DrvPadUdpCommHWTime now, diff; fidProcessHasBeam = 1; /* only interested in 120Hz... */ ! st = evrTimeGetFromPipeline( &time_s, evrTimeCurrent, modifier_a, &patternStatus, 0, 0, 0); if ( st ) { epicsPrintf("drvPadUdpComm: (fidTimeGetBaseline_generic()) epicsTimeGetFromPipeline failed (status %i)\n", st); ! return; } ! if ( (TIMESLOT1_MASK | TIMESLOT4_MASK) & modifier_a[E_MOD2] ) { /* This is it! */ ! now = drvPadUdpCommHWTime(); ! diff = now - fidTimeBaseline; ! fidTimeBaseline = now; fidHeartbeat++; ! drvPadUdpCommSendStartAll(&time_s); } #endif } void fidTimeInstall_generic(void) { fidProcessHasBeam = 1; --- 27,81 ---- #define E_MOD2 1 #define E_MOD5 4 ! unsigned ! fidProcessGeneric(epicsTimeStamp *time_s_p, unsigned time_slot_mask) { + epicsTimeStamp time_s; #ifndef TEST_ONLY /* This is actually an array type */ evrModifier_ta modifier_a; unsigned long patternStatus; int st; ! #endif ! ! if ( !time_s_p ) ! time_s_p = &time_s; fidProcessHasBeam = 1; + #ifndef TEST_ONLY /* only interested in 120Hz... */ ! st = evrTimeGetFromPipeline( time_s_p, evrTimeCurrent, modifier_a, &patternStatus, 0, 0, 0); if ( st ) { epicsPrintf("drvPadUdpComm: (fidTimeGetBaseline_generic()) epicsTimeGetFromPipeline failed (status %i)\n", st); ! return 0; } ! if ( (time_slot_mask & modifier_a[E_MOD2]) ) { /* This is it! */ ! fidTimeBaseline = drvPadUdpCommHWTime(); fidHeartbeat++; ! drvPadUdpCommSendStartAll( time_s_p ); } + + return (modifier_a[E_MOD2] & TIMESLOT_MASK); + #else + epicsTimeGetCurrent( time_s_p ); + drvPadUdpCommSendStartAll( time_s_p ); + return 1; #endif } void + fidTimeGetBaseline_generic(void *unused) + { + fidProcessGeneric(0, TIMESLOT1_MASK | TIMESLOT4_MASK); + } + + void fidTimeInstall_generic(void) { fidProcessHasBeam = 1; Index: src/fidProcess.h =================================================================== RCS file: /afs/slac/g/lcls/cvs/epics/site/src/udpComm/src/fidProcess.h,v retrieving revision 1.1 retrieving revision 1.3 diff -c -r1.1 -r1.3 *** src/fidProcess.h 19 Jan 2010 02:52:27 -0000 1.1 --- src/fidProcess.h 14 May 2012 17:56:50 -0000 1.3 *************** *** 1,4 **** ! /* $Id: fidProcess.h,v 1.1 2010/01/19 02:52:27 strauman Exp $ */ #ifndef GENERIC_FID_PROCESS_H #define GENERIC_FID_PROCESS_H --- 1,4 ---- ! /* $Id: fidProcess.h,v 1.3 2012/05/14 17:56:50 strauman Exp $ */ #ifndef GENERIC_FID_PROCESS_H #define GENERIC_FID_PROCESS_H *************** *** 6,14 **** extern "C" { #endif ! extern int fidProcessHasBeam; ! extern unsigned fidHeartbeat; /* find out if there should be beam during this cycle */ static __inline__ int --- 6,14 ---- extern "C" { #endif ! extern volatile int fidProcessHasBeam; ! extern volatile unsigned fidHeartbeat; /* find out if there should be beam during this cycle */ static __inline__ int *************** *** 24,29 **** --- 24,31 ---- * This callback runs in the context of the evrTask. * The callback also determines whether (at least part of the * machine) carries beam for 'this' 120Hz pulse). + * + * The generic callback executes fidProcessGeneric for timeslots 1 & 4. */ void fidTimeInstall_generic(void); *************** *** 31,36 **** --- 33,59 ---- void fidTestProcess(void); + /* + * Obtain a time-stamp and pattern info for this fiducial. + * If the bit corresponding to the current time-slot is set + * in 'time_slot_mask' then + * - fidHeartBeat is incremented + * - fidTimeBaseline is set to the current DrvPadUdpCommHWTime. + * - drvPadUdpCommSendStartAll() is executed, passing the time-stamp. + * + * time_s_p: pointer to an epicsTimeStamp; may be NULL if the timestamp + * is not of interest to the caller. + * + * active_timeslots: bitmask selecting time-slots considered 'active', + * i.e., when the above actions are to be performed. + * + * RETURNS: current timeslot bit (MOD2 & TIMESLOT_MASK) or zero if + * no valid pattern could be obtained. + */ + + unsigned + fidProcessGeneric(epicsTimeStamp *time_s_p, unsigned active_timeslots); + #ifdef __cplusplus }; #endif Index: src/padStream.c =================================================================== RCS file: /afs/slac/g/lcls/cvs/epics/site/src/udpComm/src/padStream.c,v retrieving revision 1.19 retrieving revision 1.22 diff -c -r1.19 -r1.22 *** src/padStream.c 9 May 2012 23:56:45 -0000 1.19 --- src/padStream.c 24 May 2012 23:08:45 -0000 1.22 *************** *** 1,4 **** ! /* $Id: padStream.c,v 1.19 2012/05/09 23:56:45 strauman Exp $ */ #include #include --- 1,4 ---- ! /* $Id: padStream.c,v 1.22 2012/05/24 23:08:45 strauman Exp $ */ #include #include *************** *** 8,14 **** #include #include #include ! #include #include #include #include --- 8,14 ---- #include #include #include ! #include #include #include #include *************** *** 209,215 **** padStreamXid = rand_r( &padStreamRand ); ! if ( nbytes > 1440 ) { /* doesn't fit in one packet */ --- 209,218 ---- padStreamXid = rand_r( &padStreamRand ); ! /* common MTU is 1500; subtract ethernet (14), IP (20), UDP (8), padProto (20) = 1438; round ! * down to next multiple of 16. -> 1424 ! */ ! if ( nbytes > 1424 ) { /* doesn't fit in one packet */ *************** *** 447,473 **** streamTest(void *packetBuffer, int idx, int channels, ! int nsamples, int d32, int little_endian, int column_major, void *uarg) { return d32 ? ! streamTest32(packetBuffer, idx, channels, nsamples, little_endian, column_major, uarg) : ! streamTest16(packetBuffer, idx, channels, nsamples, little_endian, column_major, uarg); } static PadStripSimValRec strips; PadStreamGetdataProc padStreamSim_getdata = padStreamSim_iir2_getdata; void * padStreamSim_iir2_getdata(void *packetBuffer, int idx, int nchannels, ! int nsamples, int d32, int little_endian, int column_major, --- 450,487 ---- streamTest(void *packetBuffer, int idx, int channels, ! int nsamples_tot, ! int nsamples_frag, int d32, int little_endian, int column_major, void *uarg) { return d32 ? ! streamTest32(packetBuffer, idx, channels, nsamples_frag, little_endian, column_major, uarg) : ! streamTest16(packetBuffer, idx, channels, nsamples_frag, little_endian, column_major, uarg); } static PadStripSimValRec strips; + void + padStreamDumpSimVals(void) + { + printf("Current simulation values:\n"); + printf("0x%08"PRIx32" 0x%08"PRIx32" 0x%08"PRIx32" 0x%08"PRIx32"\n", strips.val[0], strips.val[1], strips.val[2], strips.val[3]); + printf("%10"PRIi32" %10"PRIi32" %10"PRIi32" %10"PRIi32"\n", strips.val[0], strips.val[1], strips.val[2], strips.val[3]); + } + PadStreamGetdataProc padStreamSim_getdata = padStreamSim_iir2_getdata; + /* This does not yet support fragmented streams! */ void * padStreamSim_iir2_getdata(void *packetBuffer, int idx, int nchannels, ! int nsamples_tot, ! int nsamples_frag, int d32, int little_endian, int column_major, *************** *** 502,528 **** } } if ( column_major ) { ! for ( i=0; ival[ch], 0, &noise, swp, nchannels); } } else { for ( j=0; jval[ch], 0, &noise, swp, 1); ! buf += nsamples; } } } --- 516,542 ---- } } if ( column_major ) { ! for ( i=0; ival[ch], 0, &noise, swp, nchannels); } } else { for ( j=0; jval[ch], 0, &noise, swp, 1); ! buf += nsamples_frag; } } } *************** *** 614,620 **** drvLan9118FifoWr(plan, &replyPacket, UDPPKTSZ(sizeof(PadReplyRec))); if ( (padStreamDebug & 0x1) ) { ! printf("padStream: idx %i, nchannels %i, npkts %i\n", idx, nchannels, npkts); } if ( ! (rply->strm_cmd_flags & PADCMD_STRM_FLAG_C1) ) { --- 628,634 ---- drvLan9118FifoWr(plan, &replyPacket, UDPPKTSZ(sizeof(PadReplyRec))); if ( (padStreamDebug & 0x1) ) { ! printf("padStream: idx %i, type %i, nchannels %i, npkts %i\n", idx, type, nchannels, npkts); } if ( ! (rply->strm_cmd_flags & PADCMD_STRM_FLAG_C1) ) { *************** *** 633,638 **** --- 647,653 ---- &rply->data, idx, ch, + nsamples, nsamples_frag, rply->strm_cmd_flags & PADCMD_STRM_FLAG_32, rply->strm_cmd_flags & PADCMD_STRM_FLAG_LE, Index: src/padStream.h =================================================================== RCS file: /afs/slac/g/lcls/cvs/epics/site/src/udpComm/src/padStream.h,v retrieving revision 1.8 retrieving revision 1.9 diff -c -r1.8 -r1.9 *** src/padStream.h 27 Apr 2011 22:18:34 -0000 1.8 --- src/padStream.h 24 May 2012 23:07:55 -0000 1.9 *************** *** 1,6 **** #ifndef PAD_STREAM_H #define PAD_STREAM_H ! /* $Id: padStream.h,v 1.8 2011/04/27 22:18:34 strauman Exp $ */ #include #include --- 1,6 ---- #ifndef PAD_STREAM_H #define PAD_STREAM_H ! /* $Id: padStream.h,v 1.9 2012/05/24 23:07:55 strauman Exp $ */ #include #include *************** *** 50,56 **** #define PADSTRM_GETDATA_F_CM (1<<1) #define PADSTRM_GETDATA_F_32 (1<<2) ! typedef void * (*PadStreamGetdataProc)(void *packBuffer, int idx, int channels, int nsamples, int d32, int endianLittle, int colMajor, void *uarg); int padStreamSend(PadStreamGetdataProc getdata, int type, void *uarg); --- 50,56 ---- #define PADSTRM_GETDATA_F_CM (1<<1) #define PADSTRM_GETDATA_F_32 (1<<2) ! typedef void * (*PadStreamGetdataProc)(void *packBuffer, int idx, int channels, int nsamples_tot, int nsamples_frag, int d32, int endianLittle, int colMajor, void *uarg); int padStreamSend(PadStreamGetdataProc getdata, int type, void *uarg); *************** *** 86,92 **** padStreamSim_iir2_getdata(void *packetBuffer, int idx, int channels, ! int nsamples, int d32, int little_endian, int column_major, --- 86,93 ---- padStreamSim_iir2_getdata(void *packetBuffer, int idx, int channels, ! int nsamples_tot, ! int nsamples_frag, int d32, int little_endian, int column_major, *************** *** 116,121 **** --- 117,126 ---- PadDataCavity } PadDataKind; + /* Dump simulation values to stdout */ + void + padStreamDumpSimVals(void); + #ifdef __cplusplus } #endif