/*============================================================================= Name: mpgPattern.c mpgPattern - 360Hz Pattern Processing mpgPatternInit - 360Hz Pattern Processing Initialization mpgPatternState - Pattern Processing State and Diagnostics mpgPatternSim - Pattern Input Simulation Abs: This file contains all subroutine support for the MPG IOC processing of the incoming Pnet pattern and outgoing MPG pattern. Rem: All functions called by the subroutine record get passed one argument: psub Pointer to the subroutine record data. Use: pointer Type: struct longSubRecord * Acc: read/write Mech: reference All functions return a long integer. 0 = OK, -1 = ERROR. The subroutine record ignores the status returned by the Init routines. For the calculation routines, the record status (STAT) is set to SOFT_ALARM (unless it is already set to LINK_ALARM due to severity maximization) and the severity (SEVR) is set to psub->brsv (BRSV - set by the user in the database though it is expected to be invalid). Auth: 04-dec-2006, S. Allison (saa), some logic taken from D. Kotturi's drvPnet.c Rev: -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) =============================================================================*/ #include /* for memset */ #ifdef __rtems__ #include /* required for timex.h */ #endif #include /* for ntp_adjtime */ #include "debugPrint.h" #include "longSubRecord.h" /* for struct longSubRecord */ #include "registryFunction.h" /* for epicsExport */ #include "epicsExport.h" /* for epicsRegisterFunction */ #include "epicsMutex.h" /* EPICS Mutex support */ #include "epicsTime.h" /* for epicsTimeGetCurrent */ #include "epicsTypes.h" /* for types */ #include "errlog.h" /* errlogPrintf */ #include "evrMessage.h" /* for EVR_MESSAGE_PATTERN* */ #include "evrTime.h" /* for evrTime* prototypes */ #include "evrPattern.h" /* for PATTERN* defines */ #include "pnetSeqCheck.h" /* for pnetSeqCheck* protos */ #include "mpgPattern.h" /* for mpgPatternMod proto */ #include "mpsCommunication.h" /* for mpsCommunicationPut */ #include "drvMrfEg.h" /* for EgDataBufferLoad proto */ #include "patternDbgBuf.h" #include "cantProceed.h" #include "pabig.h" #define EVG_DELTA_TIME 0.008333333333 /* 1/120sec for setting time 3 pulses ahead */ #ifdef DEBUG_PRINT /* ENUM with values: DP_FATAL, DP_ERROR, DP_WARN, DP_INFO, DP_DEBUG Anything less than or equal to mpgPatternFlag gets printed out. Can be set to 0 here and altered via prompt or in st.cmd file */ int mpgPatternFlag = DP_INFO; #endif /* Time Slot Counters - one counter per supported rate */ static int tsCounter_a[TIMESLOT_RATE_MAX]; /* 30hz, 10hz, 5hz, 1hz, 0.5hz */ static int tsCounterMax_a[TIMESLOT_RATE_MAX] = { 1, 5, 11, 59, 119 }; static epicsTimeStamp prevTime_s; #ifdef __rtems__ EgCardStruct *egCard_ps; #endif static unsigned long msgCount = 0; /* # waveforms processed since boot/reset */ static unsigned long msgRolloverCount = 0; /* # time msgCount reached EVR_MAX_INT */ static unsigned long resyncCount = 0; /* # of times 6min 2s rollover happened since boot/reset */ static unsigned long invalidErrCount = 0; /* # bad PNET waveforms */ static unsigned long invalidMPSCount = 0; /* # bad MPS modifiers */ static unsigned long invalidTimeCount = 0; /* # bad NTP status reports */ static unsigned long timeoutCount = 0; /* # timeouts */ static unsigned long timestampErrCount = 0; /* # bad timestamps */ static unsigned long pulseIDSyncErrCount = 0; /* # of pulse ID sync errors */ static unsigned long modulo720SyncErrCount = 0; /* # of modulo720 sync errors */ static unsigned long seqCheck1ErrCount = 0; static unsigned long seqCheck2ErrCount = 0; static unsigned long seqCheck3ErrCount = 0; static unsigned long mpgPatternSync = 1; static unsigned long ntpStatus = 0; /* NTP status, 0 = OK, >0 = error */ /* BYKIK abort values */ static epicsUInt32 bykikAbortActive = epicsFalse; static epicsUInt32 bykikAbortPeriodInBeamShots = (120 * 60 * 60 * 24 * 7 * 1); /* One week at 120 Hz */ static epicsUInt32 beamShotsUntilNextBykikAbort = (120 * 60 * 60 * 24 * 7 * 1); /* One week at 120 Hz */ static epicsMutexId bykikAbortValuesMutex = 0; PatternDbgBuf mpgPatternBuf = 0; /*============================================================================= Name: mpgPatternInit Abs: Initialization for 360Hz Processing to Set up the MPG Pattern Args: None. Rem: None. Ret: -1 if error from epicsTimeGetCurrent. Otherwise, return from mpgPatternModInit. ==============================================================================*/ int mpgPatternInit(void) { bykikAbortValuesMutex = epicsMutexMustCreate(); /* Initialize rate counters for every timeslot and every rate */ memset(tsCounter_a, 0, sizeof(int) * TIMESLOT_RATE_MAX); mpgPatternBuf = patternDbgBufGet( "mpgPatternBuf" ); if ( !mpgPatternBuf ) cantProceed("mpgPatternInit: mpgPatternBuf not found!\n"); pabigStateInit( 0, -1 ); /* * For RTEMS, initialize the EVG data buffer size * and get the pointer to the card structure. */ #ifdef __rtems__ EgDataBufferInit(0, sizeof(evrMessagePattern_ts)); egCard_ps = (EgCardStruct *)EgGetCardStruct(0); #endif /* Initialize previous timestamp to system time */ if (epicsTimeGetCurrent(&prevTime_s)) return -1; return (mpgPatternModInit()); } /*============================================================================= Name: mpgPattern Abs: 360Hz Processing of the Pnet pattern Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- int timeout read timeout flag epicsUInt32 mpsModifier read MPS pattern modifier Rem: None. Side: Output to EVR timestamp/pattern table. Ret: -1 if system time cannot be determined or space for newest pattern is not available. Otherwise, return from evrTimePatternPutEnd. ==============================================================================*/ int mpgPattern(int timeout, epicsUInt32 mpsModifier) { evrMessagePattern_ts *pattern_ps; struct timex ntp_s; unsigned long *timeslot_p; unsigned long *patternStatus_p; evrMessageReadStatus_te evrMessageStatus; epicsTimeStamp *mod720time_ps; epicsTimeStamp currenttime_s; double delta_time; int modulo720Flag; unsigned long modifier5mask; unsigned long pulsid_resync; unsigned int idx; unsigned int pulsidInTime; unsigned char traveling_one; static unsigned int pulseIDSync = 0; /* EVG and SLC MPG pulse ID synced */ static unsigned int modulo720Sync = 0; /* EVG and SLC MPG modulo720 synced */ static unsigned int seqCheckSync = 0; /* sequence checking synced */ static unsigned long modifier5 = 0; /* modifier5 */ static unsigned int pulsid = 0; /* pulse ID */ static unsigned long modulo720Count= 0; /* mod720 counter */ pabigProcess( 0 ); /* Keep a count of messages and reset before overflow */ if (msgCount < EVR_MAX_INT) { msgCount++; } else { msgRolloverCount++; msgCount = 0; } /* Initialize EVR timestamp to system time */ if (epicsTimeGetCurrent(¤ttime_s)) return -1; /* Check NTP status. For now, just update a counter when it's bad. */ memset(&ntp_s, 0, sizeof(ntp_s)); if (ntp_adjtime(&ntp_s)) { ntpStatus = 1; invalidTimeCount++; } else { ntpStatus = 0; } /* Lock the pattern table and get pointer to newest pattern data */ if (evrTimePatternPutStart(&pattern_ps, ×lot_p, &patternStatus_p, &mod720time_ps)) return -1; /* Initialize EVR timestamp to system time. */ pattern_ps->time = currenttime_s; /* Increment internal counters. */ modulo720Count++; pulsid++; /*Check if there is a Pnet Module then process the relative EVR_MESSAGE. */ /* Fill in the pattern. Set header and get 4 PNET modifiers. */ pattern_ps->header_s.type = EVR_MESSAGE_PATTERN; pattern_ps->header_s.version = EVR_MESSAGE_PATTERN_VERSION; /* if we cannot read the message - set record invalid and force a resync */ evrMessageStatus = evrMessageRead(EVR_MESSAGE_PNET, (evrMessage_tu *)pattern_ps->modifier_a); if (timeout || evrMessageStatus) { if (timeout) { *patternStatus_p = PATTERN_TIMEOUT; timeoutCount++; } else if (evrMessageStatus == evrMessageDataNotAvail) { *patternStatus_p = PATTERN_NO_DATA; } else { *patternStatus_p = PATTERN_INVALID_WF; invalidErrCount++; } pulseIDSync = 0; modulo720Sync = 0; seqCheckSync = 0; modifier5 = 0; for (idx = 0; idx < EVR_MODIFIER_MAX; idx++) pattern_ps->modifier_a[idx] = 0; if (epicsTimeDiffInSeconds(&pattern_ps->time, mod720time_ps) > MODULO720_SECS) modulo720Count = MODULO720_COUNT; } else { *patternStatus_p = PATTERN_OK; /* Remove unused high PSK bit of modifier1 until EDM is fixed. */ pattern_ps->modifier_a[MOD1_IDX] &= (~0x80000000); /* Check if SLC MPG is rebooting */ if (pattern_ps->modifier_a[MOD1_IDX] & MPG_IPLING) { *patternStatus_p = PATTERN_MPG_IPLING; pulseIDSync = 0; modulo720Sync = 0; seqCheckSync = 0; modifier5 = 0; /* Do sync checking */ } else { *timeslot_p = TIMESLOT(pattern_ps->modifier_a); if (mpgPatternSync) { traveling_one = (unsigned char)(pattern_ps->modifier_a[MOD2_IDX] & TIMESLOT_MASK); if (pnetSeqCheckData1(traveling_one, seqCheckSync)) { /* "traveling 1" check */ *patternStatus_p = PATTERN_SEQ_CHECK1_ERR; seqCheck1ErrCount++; } else if (pnetSeqCheckData2(*timeslot_p, seqCheckSync)) { /* 0-5 looping counter check */ *patternStatus_p = PATTERN_SEQ_CHECK2_ERR; seqCheck2ErrCount++; } else if (pnetSeqCheckData3(traveling_one, *timeslot_p)) {/* check that two checksum values stay in sync */ *patternStatus_p = PATTERN_SEQ_CHECK3_ERR; seqCheck3ErrCount++; } /* Both pulse ID and modulo 720 will need to be resync'ed too */ if (*patternStatus_p) { pulseIDSync = 0; modulo720Sync = 0; } seqCheckSync = 1; /* Check if modulo-720 can be resynchronized on this pulse. */ if (pattern_ps->modifier_a[MOD1_IDX] & MODULO720_MASK) { /* Synch all time slot counters on MOD720 */ for (idx = 0; idx < TIMESLOT_RATE_MAX; idx++) { tsCounter_a[idx] = tsCounterMax_a[idx]; } /* If we should be sync'ed but are not, update a counter */ if (modulo720Sync && (modulo720Count != MODULO720_COUNT)) { modulo720SyncErrCount++; errlogPrintf("mpgPattern: Modulo 720 not synchronized, modulo720Count = %lu\n", modulo720Count); /* Assume pulse ID is also out-of-sync */ pulseIDSync = 0; } modulo720Count = 0; modulo720Sync = 1; } else if (!modulo720Sync) { *patternStatus_p = PATTERN_MODULO720_NO_SYNC; } else if (modulo720Count >= MODULO720_COUNT) { /* If we should be sync'ed but are not, update a counter */ modulo720SyncErrCount++; errlogPrintf("mpgPattern: Modulo 720 not synchronized, modulo720Count = %lu\n", modulo720Count); modulo720Count = 0; modulo720Sync = 0; *patternStatus_p = PATTERN_MODULO720_NO_SYNC; /* Assume pulse ID is also out-of-sync */ pulseIDSync = 0; } /* Check for a non-zero value in the 4 bit pulsid_resync field of Pnet data. If found, it resets upper 4 bits of the pulse ID (lower bit will be zero). Otherwise, the pulse ID is set to 1 if the last value is the rollover value. Otherwise, the pulse ID is simply incremented.*/ pulsid_resync = (pattern_ps->modifier_a[MOD1_IDX] >> 3) & PULSEID_RESYNC; if (pulsid_resync) { /* If we should be sync'ed but are not, update a counter */ if ((pulseIDSync) && (pulsid != pulsid_resync)) { pulseIDSyncErrCount++; errlogPrintf("mpgPattern: Pulse IDs not synchronized, MPG = %lu, EVG = %d\n", pulsid_resync, pulsid); /* Assume modulo 720 out-of-sync too unless the RESYNC bit is set */ if (!(pattern_ps->modifier_a[MOD1_IDX] & MODULO720_MASK)) { modulo720Sync = 0; *patternStatus_p = PATTERN_MODULO720_NO_SYNC; } } pulseIDSync = 1; pulsid = pulsid_resync; } else if (!pulseIDSync) { *patternStatus_p = PATTERN_PULSEID_NO_SYNC; } else if (pulsid > PULSEID_MAX) { /* Aha. Time to rollover, so THIS pulse will be set back to zero */ DEBUGPRINT(DP_DEBUG, mpgPatternFlag, ("mpgPattern: Rollover, pulsid+1 = %d\n", pulsid)); pulsid = 0; resyncCount++; } } else { pulseIDSync = 1; modulo720Sync = 1; } /* Set modifier 5 rate bits and counters for timeslot 1. */ if (*timeslot_p == 1) { modifier5 = 0; modifier5mask = 1<= tsCounterMax_a[idx]) { tsCounter_a[idx] = 0; if (!*patternStatus_p) modifier5 |= modifier5mask; } else { tsCounter_a[idx]++; } modifier5mask = modifier5mask<<1; } } } } /* Set modifier5 rate bits. */ pattern_ps->modifier_a[MOD5_IDX] = modifier5; /* Clamp internal counters. */ if (pulsid > PULSEID_MAX) pulsid = 0; if (modulo720Count >= MODULO720_COUNT) { pattern_ps->modifier_a[MOD1_IDX] |= MODULO720_MASK; modulo720Count = 0; } /* Set bit in pattern that can be used to determine if pattern is not good. */ if (*patternStatus_p) pattern_ps->modifier_a[MOD1_IDX] |= MPG_IPLING; /* Update MPS information (which is not pipelined) into the pattern. */ pattern_ps->modifier_a[MOD6_IDX] = mpsModifier; if ((!(pattern_ps->modifier_a[MOD6_IDX] & MPS_VALID)) && (!(pattern_ps->modifier_a[MOD1_IDX] & MPG_IPLING))) invalidMPSCount++; /* Set other modifier bits - add EDEF and user bits. */ if (mpgPatternMod(pattern_ps)) *patternStatus_p = PATTERN_ERROR; /* Send pattern on to the EVRs. */ /* The time is for 3 pulses in the future - add 1/120sec */ epicsTimeAddSeconds(&pattern_ps->time, EVG_DELTA_TIME); /* Overlay the pulse ID into the lower 17 bits of the nsec field */ if (pulseIDSync) pulsidInTime = pulsid; else pulsidInTime = PULSEID_INVALID; evrTimePutPulseID(&pattern_ps->time, pulsidInTime); /* The timestamp must ALWAYS be increasing. Check if this time is less than the previous time (due to rollover) and adjust up slightly using bit 17 (the lower-most bit of the top 15 bits). */ delta_time = epicsTimeDiffInSeconds(&pattern_ps->time, &prevTime_s); if (delta_time < 0.0) { epicsTimeAddSeconds(&pattern_ps->time, PULSEID_BIT17/NSEC_PER_SEC); evrTimePutPulseID(&pattern_ps->time, pulsidInTime); /* If the timestamp STILL isn't greater than the past, perhaps system time is not increasing as it should. For now, keep a counter - later we may want to add code to handle this. */ delta_time = epicsTimeDiffInSeconds(&pattern_ps->time, &prevTime_s); if (delta_time < 0.0) timestampErrCount++; } prevTime_s = pattern_ps->time; /* send pattern on to all EVRs */ #ifdef __rtems__ if (egCard_ps) { epicsMutexLock(egCard_ps->EgLock); EgDataBufferLoad(egCard_ps, (epicsUInt32 *)pattern_ps, sizeof(evrMessagePattern_ts)/sizeof(epicsUInt32)); epicsMutexUnlock(egCard_ps->EgLock); } #endif /* modulo720 decoded from modifier 1 */ if (pattern_ps->modifier_a[MOD1_IDX] & MODULO720_MASK) modulo720Flag = 1; else modulo720Flag = 0; /* record the pattern for debugging/diagnostic purposes */ patternDbgBufPutBytes( mpgPatternBuf, pattern_ps->modifier_a, sizeof(pattern_ps->modifier_a)/sizeof(pattern_ps->modifier_a[0]), modulo720Flag ? & pattern_ps->time : 0 ); /* Unlock pattern data and post MOD720 events if needed */ evrTimePatternPutEnd(modulo720Flag); return 0; } /*============================================================================= Abs: Check if BYKIK is included/excluded. Abort beam at BYKIK every bykikAbortPeriodInBeamShots beam shots CATER 105824 Ret: void @aut: Carolina Bianchini ==============================================================================*/ void mpgBykik_check(evrMessagePattern_ts *pattern_ps){ /* * Abort beam at BYKIK every bykikAbortPeriodInBeamShots beam shots */ epicsMutexLock(bykikAbortValuesMutex); if ((bykikAbortActive) && (bykikAbortPeriodInBeamShots > 0)) { if ((pattern_ps->modifier_a[MOD3_IDX] & POCKCEL_PERM) && ((pattern_ps->modifier_a[MOD2_IDX] & TIMESLOT1_MASK) || (pattern_ps->modifier_a[MOD2_IDX] & TIMESLOT4_MASK)) && (beamShotsUntilNextBykikAbort > 0)) /* True if beam */ /* (pattern_ps->modifier_a[MOD5_IDX] & MOD5_10HZ_MASK == 0) && This line may be required... */ /* (pattern_ps->modifier_a[MOD5_IDX] & MOD5_1HZ_MASK == 0) && This line may be required... */ { /* There is beam on this pulse, decrement counter */ beamShotsUntilNextBykikAbort--; } if (beamShotsUntilNextBykikAbort == 0) { /* Counter has expired */ /* Reset counter */ beamShotsUntilNextBykikAbort = bykikAbortPeriodInBeamShots; /* Set BYKIK bit */ pattern_ps->modifier_a[MOD2_IDX] |= KICKER_LTU; } } epicsMutexUnlock(bykikAbortValuesMutex); } /*============================================================================= Abs: Set period (in beam shots) that the timing system should abort beam at BYKIK. Ret: -1 error 0 success ==============================================================================*/ int mpgSetBykikAbortPeriod(epicsUInt32 abortPeriodInBeamShots) { epicsMutexLock(bykikAbortValuesMutex); bykikAbortPeriodInBeamShots = abortPeriodInBeamShots; /* Reset counter */ beamShotsUntilNextBykikAbort = bykikAbortPeriodInBeamShots; epicsMutexUnlock(bykikAbortValuesMutex); return 0; } /*============================================================================= Abs: Get period (in beam shots) that the timing system should abort beam at BYKIK. ==============================================================================*/ epicsUInt32 mpgGetBykikAbortPeriod() { epicsUInt32 abortPeriodInBeamShots; epicsMutexLock(bykikAbortValuesMutex); abortPeriodInBeamShots = bykikAbortPeriodInBeamShots; epicsMutexUnlock(bykikAbortValuesMutex); return abortPeriodInBeamShots; } /*============================================================================= Ret: -1 error 0 success ==============================================================================*/ int mpgSetBykikAbortActiveState(int state) { epicsMutexLock(bykikAbortValuesMutex); bykikAbortActive = state ? epicsTrue : epicsFalse; epicsMutexUnlock(bykikAbortValuesMutex); return 0; } epicsBoolean mpgBykikAbortIsActive() { epicsBoolean status; epicsMutexLock(bykikAbortValuesMutex); status = bykikAbortActive; epicsMutexUnlock(bykikAbortValuesMutex); return status; } epicsUInt32 mpgBykikGetShotsUntilNextAbort() { epicsUInt32 status; epicsMutexLock(bykikAbortValuesMutex); status = beamShotsUntilNextBykikAbort; epicsMutexUnlock(bykikAbortValuesMutex); return status; } /*============================================================================= Name: mpgPatternState Abs: Access to Last MPG Pattern State and Pattern Diagnostics. This subroutine is for status only and must update at a slow rate. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- longSubRecord * psub read point to subroutine record Rem: Subroutine for IOC:LOCA:UNIT:PATTERNDIAG Inputs: A - Error Flag from evrPattern B - Counter Reset Flag Outputs: C - Number of timeout errors D - Number of waveforms processed by mpgPattern E - Number of times D has rolled over F - Number of bad waveforms The following G-J outputs are pop'ed by a call to evrMessageCounts() G - Number of times ISR wrote a message H - Number of times G has rolled over I - Number of times ISR overwrote a message J - Number of backwards time errors K - Number of unexpected unsynchronized pulse IDs L - Number of unexpected unsynchronized modulo720s M - Number of seq check 1 errors N - Number of seq check 2 errors O - Number of seq check 3 errors P - Number of pulse Id 6min 2sec cycles that have transpired since reset Q - Number of invalid MPS modifiers R - NTP status, 0 = OK, 1 = Error S - Number of NTP errors T - U = spare V - Minimum PNET Delta Start Time (us) W - Maximum PNET Delta Start Time (us) X - Average Data Processing Time (us) Y - Number of message write errors Z - Maximum Data Processing Time (us) VAL = Last Error flag (see evrPattern for values) Side: File-scope counters may be reset. Ret: 0 = OK ==============================================================================*/ static long mpgPatternState(longSubRecord *psub) { psub->val = psub->a; psub->d = msgCount; /* # waveforms processed since boot/reset */ psub->e = msgRolloverCount; /* # time msgCount reached EVR_MAX_INT */ psub->f = invalidErrCount; evrMessageCounts(EVR_MESSAGE_PNET, &psub->g,&psub->h,&psub->i,&psub->c,&psub->y, &psub->j,&psub->v,&psub->w,&psub->x,&psub->z); psub->j = timestampErrCount; psub->k = pulseIDSyncErrCount; psub->l = modulo720SyncErrCount; psub->m = seqCheck1ErrCount; psub->n = seqCheck2ErrCount; psub->o = seqCheck3ErrCount; psub->p = resyncCount; /* # of times 6min 2s rollover happened since boot/reset */ psub->q = invalidMPSCount; psub->r = ntpStatus; psub->s = invalidTimeCount; if (psub->b > 0) { psub->b = 0; msgCount = 0; msgRolloverCount = 0; invalidErrCount = 0; invalidMPSCount = 0; invalidTimeCount = 0; timeoutCount = 0; resyncCount = 0; seqCheck1ErrCount = 0; seqCheck2ErrCount = 0; seqCheck3ErrCount = 0; pulseIDSyncErrCount = 0; modulo720SyncErrCount = 0; evrMessageCountReset(EVR_MESSAGE_PNET); } return 0; } /*============================================================================= Name: mpgPatternSim Abs: Simulate PNET data stream. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- longSubRecord * psub read point to subroutine record Rem: Subroutine for IOC:LOCA:UNIT:PATTERNSIM Side: Sends a message to the PNET pattern queue and set MPS modifier. Sub Inputs/ Outputs: Simulated inputs: C - Time Slot (used only if between 1 and 6) D - MODIFIER1 E - MODIFIER2 F - MODIFIER3 G - MODIFIER4 I - MODIFIER6 (MPS modifier) J - BEAMCODE K - YY L - PULSE ID (not used) M - Sync check flag (0 = skip sync check, 1 = do sync check) Ret: Return from evrMessageWrite. ==============================================================================*/ static long mpgPatternSim(longSubRecord *psub) { evrMessage_tu evrMessage_u; int idx; void pnetISR(void *arg); epicsTimeStamp mpsTime_s; /*------------- parse input into sub outputs ----------------------------*/ mpgPatternSync = psub->m; for (idx = 0; idx < EVR_PNET_MODIFIER_MAX; idx++) evrMessage_u.pnet_s.modifier_a[idx] = (&psub->d)[idx]; evrMessage_u.pnet_s.modifier_a[MOD1_IDX] = psub->d & 0xFFFF8000; evrMessage_u.pnet_s.modifier_a[MOD1_IDX] |= ((psub->j << 8) & 0x1F00); evrMessage_u.pnet_s.modifier_a[MOD1_IDX] |= (psub->k & YY_BIT_MASK); if ((psub->c > 0) && (psub->c <= TIMESLOT_MAX)) { unsigned long timeslot_mask = 1 << (psub->c-1); evrMessage_u.pnet_s.modifier_a[MOD2_IDX] = psub->e & ~TIMESLOT_MASK; evrMessage_u.pnet_s.modifier_a[MOD2_IDX] |= timeslot_mask; timeslot_mask = psub->c << 29; evrMessage_u.pnet_s.modifier_a[MOD4_IDX] = psub->g & 0x1FFFFFFF; evrMessage_u.pnet_s.modifier_a[MOD4_IDX] |= timeslot_mask; } /* Set MPS modifier and state and timestamp (for the next pulse). */ evrTimeGetFromPipeline(&mpsTime_s, evrTimeNext1, 0,0,0,0,0); mpsCommunicationPut(psub->i, 0, &mpsTime_s); /* Send the pattern to the PNET pattern queue and wake up PNET task*/ evrMessageWrite(EVR_MESSAGE_PNET, &evrMessage_u); pnetISR(0); return 0; } epicsRegisterFunction(mpgPatternState); epicsRegisterFunction(mpgPatternSim);