/*$Id: fcomOutState.h,v 1.2 2010/03/10 10:36:20 strauman Exp $*/ #ifndef BPM_FCOM_OUT_STATE_H #define BPM_FCOM_OUT_STATE_H #include #ifdef __cplusplus extern "C" { #endif /* State variables -- FOR INTERNAL USE ONLY -- */ extern volatile uint32_t fcomOutStateMask; /* bitmask of channels that should be posted */ extern volatile uint32_t fcomOutStateEnbl; /* bitmask of channels currently 'in use' */ extern volatile uint32_t fcomOutStateGood; /* bitmask of currently working channels */ extern volatile uint32_t fcomOutStateMemb; /* bitmask of channels not yet added to group */ /* Public diagnostic variables */ extern volatile uint32_t fcomOutStateTimo; /* counter for timeout occurrences */ extern volatile uint32_t fcomOutStateTost; /* record bitmask of timed-out channels */ /* Check (to be executed at every fiducial) that * all FCOM group members had been added (and the group * thus been sent). * * RETURNS 0 on success, nonzero if a timeout/overrun was * detected. Timed-out channels are disabled until * they come on-line again. */ static __inline__ int fcomOutStateFidCheck(void) { int rval; /* Cache drvPadUdpCommChannelsInUseMask synchronously at FID time */ fcomOutStateEnbl = drvPadUdpCommChannelsInUseMask & fcomOutStateMask; /* Remove disabled channels from group */ fcomOutStateMemb &= fcomOutStateEnbl; /* Make sure disabled channels are always 'good' */ fcomOutStateGood |= ~fcomOutStateEnbl; /* Are there left-over channels (= group not sent!) ? */ if ( fcomOutStateMemb ) { fcomOutStateTimo++; fcomOutStateTost = fcomOutStateMemb; /* Mark as bad */ fcomOutStateGood &= ~fcomOutStateMemb; rval = -1; } else { rval = 0; } /* Compute new set of channels that should be posted */ fcomOutStateMemb = fcomOutStateEnbl & fcomOutStateGood; return rval; } #define FCOS_ADD 1 #define FCOS_POST 2 /* Notify state machine that BPM data for channel 'ch' * is available. * * RETURNS: 0 * if nothing needs to be done (channel is disabled) * FCOS_ADD * if data must be added to group * FCOS_ADD | FCOS_POST * if data must be added to group and the group * must subsequently be posted. */ static __inline__ int fcomOutStatePost(unsigned ch) { uint32_t me = (1<