/*============================================================================= Name: mpgEvent.c mpgEventSeqPutPulseID - MPG 360Hz Seq Ram Pulse ID (Timestamp) Update mpgEventSeqInit - MPG 360Hz Seq Ram Preparation Initialization mpgEventSeq - MPG 360Hz Seq Ram Preparation mpgEventInp - User Input for all Event Codes mpgEventBeamCode - MPG Event Code Pattern Setup mpgEventCode - MPG Event Code Setup mpgEventRate - Return Rate for an Event Code mpgEventState - Get and Reset Diagnostic Counts Abs: This file contains all subroutine support for the MPG IOC processing of 360Hz EVG sequence RAM/event code programming. Rem: All functions called by the subroutine record get passed one argument: psub Pointer to the subroutine record data. Use: pointer Type: struct subRecord * 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: 12-feb-2007, S. Allison (saa) Rev: -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) =============================================================================*/ #include /* for memset */ #include "debugPrint.h" #include "subRecord.h" /* for struct subRecord */ #include "longSubRecord.h" /* for struct longSubRecord */ #include "registryFunction.h" /* for epicsExport */ #include "epicsExport.h" /* for epicsRegisterFunction */ #include "epicsMutex.h" /* EPICS Mutex support library */ #include "ellLib.h" /* EPICS Linked list library */ #include "evrTime.h" /* EVENT* defines */ #include "evrPattern.h" /* Various bit masks */ #include "egRecord.h" /* egMOD1_Off, egMOD1_Single */ #include "drvMrfEg.h" /* MRF_NUM_EVENTS, Eg protos */ #define PATTERNS_PER_EVENT 2 /* # pattern mask per event code */ /* The first 35 ticks in the sequence ram are reserved for: (0) Fiducial (1) Heartbeat (2 to 33) 32 Bit "Seconds" (set to pulse ID) (34) "Seconds" Synchronization */ #define BITS_PER_TIMESTAMP 32 /* # of bits in the "seconds" timestamp */ /* Minimum user-defined event code delay */ #define MINIMUM_EVENT_DELAY (BITS_PER_TIMESTAMP + 3) /* Detail for one pattern check */ typedef struct { /* Inputs */ evrModifier_ta inclusion_a; evrModifier_ta exclusion_a; unsigned long beamCode; unsigned long pipelineID; } mpgEventPattern_ts; /* Detail for one event code */ typedef struct { ELLNODE node_s; unsigned int code; unsigned int count; int enable; int everyCycle; int maxBurstCount; int burstCountSoFar; int delay; unsigned short ramPos_a[MRF_NUM_SEQ_RAM]; MrfEvgSeqStruct ram_as[MRF_NUM_SEQ_RAM]; mpgEventPattern_ts pattern_as[PATTERNS_PER_EVENT]; } mpgEvent_ts; /* Detail for one sequence RAM */ typedef struct { int change; int enable; int busy; } mpgRam_ts; /* Tables and Lists */ static ELLLIST eventList_s; /* Event list in sequence RAM order */ static mpgEvent_ts mpgEvent_as[MRF_NUM_EVENTS]; /* event code table */ MrfEvgSeqStruct mpgPulseIDRam_as[MRF_NUM_SEQ_RAM][BITS_PER_TIMESTAMP]; /* Pulse ID RAM tables */ static mpgRam_ts mpgRam_as[MRF_NUM_SEQ_RAM]; /* ram flags */ /* Modulo36 event code - incremented on every pulse */ static epicsUInt16 mod36EventCode = EVENT_MODULO36_MIN; /* Control Flags */ static epicsMutexId mpgEventMutex_ps = 0; /* Mutex for above information */ static int delayOffset = 0; /* Delay offset */ static int sendSeq = 0; /* Trigger sequence for testing */ #ifdef __rtems__ static EgCardStruct *evgCard_ps = 0; /* EVG card information */ #endif /* Diagnostics Counters */ static unsigned long lockErrCount = 0; /* # times unable to lock data */ static unsigned long busyErrCount = 0; /* # times a seq ram was busy */ static unsigned long modeErrCount = 0; /* # times a seq ram is not in single modes */ static unsigned long enableErrCount = 0; /* # times a seq ram still active*/ static unsigned long patternErrCount = 0; /* # bad patterns */ /*============================================================================= Name: mpgEventSeqPutPulseID Abs: Put the pulse ID into the sequence ram as the "seconds" timestamp. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- unsigned int pulseID read pulse ID int ramIdx read sequence ram index (0 or 1) Rem: None. Side: EVG sequence ram updated.. Ret: 0 = OK. ==============================================================================*/ int mpgEventSeqPutPulseID(unsigned int pulseID, int ramIdx) { int idx, pidx; int ram; int eventcode; /* Set proper event codes in the ram based on if the bit is set or not set in the pulse ID. Start with MSB. Only update the ram if there is an event code change. */ ram = ramIdx + 1; for (pidx = 0, idx = BITS_PER_TIMESTAMP-1; pidx < BITS_PER_TIMESTAMP; pidx++, idx--) { if (pulseID & (1 << idx)) eventcode = EVENT_SECONDS_1; else eventcode = EVENT_SECONDS_0; if (eventcode != mpgPulseIDRam_as[ramIdx][pidx].EventCode) { mpgPulseIDRam_as[ramIdx][pidx].EventCode = eventcode; #ifdef __rtems__ if (evgCard_ps) { EgSeqRamWrite(evgCard_ps, ram, mpgPulseIDRam_as[ramIdx][pidx].Timestamp, &mpgPulseIDRam_as[ramIdx][pidx]); } #endif } } return 0; } /*============================================================================= Name: mpgEventSeqInit Abs: Initialization for 360Hz Sequence RAM Processing Args: None. Rem: None. Side: Static data initialized. EVG sequence ram initialized. EVG sequence mode set to Off. Ret: -1 if mutex already created or cannot be created. 0 otherwise. ==============================================================================*/ int mpgEventSeqInit(void) { int idx, pidx; int eventcode; int ram; int delay = 0; /* For RTEMS, get the EVG card information and enable the distributed bus for timestamp events. */ #ifdef __rtems__ evgCard_ps = (EgCardStruct *)EgGetCardStruct(0); #endif /* Make sure this routine is called only once */ if (mpgEventMutex_ps) return -1; /* Create read/write mutex around shared data */ if (!(mpgEventMutex_ps = epicsMutexCreate())) return -1; /* Initialize event code list used for sequence ram loading */ ellInit(&eventList_s); /* Initialize event code table */ memset(mpgEvent_as, 0, sizeof(mpgEvent_ts) * MRF_NUM_EVENTS); for (eventcode = 0; eventcode < MRF_NUM_EVENTS; eventcode++) { for (pidx = 0; pidx < PATTERNS_PER_EVENT; pidx++) { mpgEvent_as[eventcode].pattern_as[pidx].pipelineID = MAX_EVR_TIME; } } /* Initialize codes that are reserved for post-event, external trigger, and MPG processing so they cannot be used here */ mpgEvent_as[EVENT_EXTERNAL_TRIG].code = EVENT_EXTERNAL_TRIG; mpgEvent_as[EVENT_MODULO720].code = EVENT_MODULO720; mpgEvent_as[EVENT_MPG].code = EVENT_MPG; /* Initialize codes that are reserved for MOD36 event codes, except for the first one which is set up like other event codes. */ for (eventcode = EVENT_MODULO36_MIN+1; eventcode <= EVENT_MODULO36_MAX; eventcode++) { mpgEvent_as[eventcode].code = eventcode; } /* Initialize special event codes - these are NOT included in the linked list since there order is fixed. */ mpgEvent_as[EVENT_FIDUCIAL].code = EVENT_FIDUCIAL; mpgEvent_as[EVENT_FIDUCIAL].enable = 1; mpgEvent_as[EVENT_FIDUCIAL].everyCycle = 1; mpgEvent_as[EVENT_FIDUCIAL].delay = delay++; /* Delays for timestamp are done later. */ mpgEvent_as[EVENT_SECONDS_0].code = EVENT_SECONDS_0; mpgEvent_as[EVENT_SECONDS_0].enable = 1; mpgEvent_as[EVENT_SECONDS_0].everyCycle = 1; mpgEvent_as[EVENT_SECONDS_0].delay = 0; mpgEvent_as[EVENT_SECONDS_1].code = EVENT_SECONDS_1; mpgEvent_as[EVENT_SECONDS_1].enable = 1; mpgEvent_as[EVENT_SECONDS_1].everyCycle = 1; mpgEvent_as[EVENT_SECONDS_1].delay = 0; delay += BITS_PER_TIMESTAMP; mpgEvent_as[EVENT_RESET_TICK].code = EVENT_RESET_TICK; mpgEvent_as[EVENT_RESET_TICK].enable = 1; mpgEvent_as[EVENT_RESET_TICK].everyCycle = 1; mpgEvent_as[EVENT_RESET_TICK].delay = delay++; mpgEvent_as[EVENT_HEARTBEAT].code = EVENT_HEARTBEAT; mpgEvent_as[EVENT_HEARTBEAT].enable = 1; mpgEvent_as[EVENT_HEARTBEAT].everyCycle = 1; mpgEvent_as[EVENT_HEARTBEAT].delay = delay++; /* Initialize the end-of-sequence event - this is NOT included in the linked list since the delay (Timestamp) is unknown until other events are added */ mpgEvent_as[EVENT_END_SEQUENCE].code = EVENT_END_SEQUENCE; mpgEvent_as[EVENT_END_SEQUENCE].enable = 1; mpgEvent_as[EVENT_END_SEQUENCE].everyCycle = 1; mpgEvent_as[EVENT_END_SEQUENCE].delay = delay++; /* Initialize the sequence RAMs with the fiducial, seconds, heartbeat, and end-of-sequence events. The seconds event codes take 32 slots. */ for (idx=0, ram=1; idxEgLock); if (evgLockStatus) { lockErrCount++; eventEnable = 0; } mode = EgGetMode(evgCard_ps, ram, &mpgRam_as[ramNext].busy, &mpgRam_as[ramNext].enable); /* For now, ignore the busy status. */ if (mpgRam_as[ramNext].busy) { busyErrCount++; } /* Make sure we are in single-shot mode and disabled. */ if (mode != egMOD1_Single) { EgSetSingleSeqMode(evgCard_ps, ram); mpgRam_as[ramNext].change = 1; mpgRam_as[ramNext].enable = 0; modeErrCount++; } /* If a RAM is still enabled, this means the fiducial didn't happen or the sequence ram is too long. Disabling doesn't make a difference, we have to let it play out. */ else if (mpgRam_as[ramNext].enable) { eventEnable = 0; enableErrCount++; } } else { evgLockStatus = 1; } #endif /* Set up this sequence RAM only if all events are enabled. Note that the fiducial, heartbeat, timestamp events are always first so start at the next available position in the sequence ram. The fiducial and heartbeat timestamps are always 0 and 1. */ ramPos = MINIMUM_EVENT_DELAY; lastTimestamp = ramPos-1; if (eventEnable) { ELLNODE *node_ps = ellFirst(&eventList_s); /* Go through each event and disable it if it's enabled unless it. goes every cycle and should be enabled or pattern match. If the ram needs an update due to user request (new event, different event code, different delay), rewrite the sequence ram. */ while (node_ps) { mpgEvent_ps = (mpgEvent_ts *)node_ps; ramUpdate = 0; if (mpgRam_as[ramNext].change) { mpgEvent_ps->ramPos_a[ramNext] = ramPos; ramUpdate = 1; } /* Calculate proper delay for this event. Allow for a delay offset that is applied to all event codes except the fiducial and heartbeat. */ delay = mpgEvent_ps->delay + delayOffset; if ((delay < 0) || (delay <= lastTimestamp)) delay = lastTimestamp+1; lastTimestamp = delay; if (lastTimestamp != mpgEvent_ps->ram_as[ramNext].Timestamp) { mpgEvent_ps->ram_as[ramNext].Timestamp = lastTimestamp; ramUpdate = 1; } if (mpgEvent_ps->enable) { if (mpgEvent_ps->everyCycle) { /* Modulo36 event code is actually 36 event codes that share the same delay. Switch to the next event code now. */ if (mpgEvent_ps->code == EVENT_MODULO36_MIN) { mpgEvent_ps->ram_as[ramNext].EventCode = mod36EventCode; ramUpdate = 1; } else if (mpgEvent_ps->ram_as[ramNext].EventCode != mpgEvent_ps->code) { mpgEvent_ps->ram_as[ramNext].EventCode = mpgEvent_ps->code; ramUpdate = 1; } /* Check all patterns (with valid pipeline ID) that have been defined for this event. */ } else { for (pidx = 0; pidx < PATTERNS_PER_EVENT; pidx++) { idx = mpgEvent_ps->pattern_as[pidx].pipelineID; if (idx < MAX_EVR_TIME) { if (evrPatternCheck(mpgEvent_ps->pattern_as[pidx].beamCode, 0, mpgEvent_ps->pattern_as[pidx].inclusion_a, mpgEvent_ps->pattern_as[pidx].exclusion_a, modifier_aa[idx])) { break; } } } if (pidx < PATTERNS_PER_EVENT) { if (mpgEvent_ps->ram_as[ramNext].EventCode != mpgEvent_ps->code) { mpgEvent_ps->ram_as[ramNext].EventCode = mpgEvent_ps->code; ramUpdate = 1; } } else if (mpgEvent_ps->ram_as[ramNext].EventCode) { mpgEvent_ps->ram_as[ramNext].EventCode = 0; ramUpdate = 1; } } } else if (mpgEvent_ps->ram_as[ramNext].EventCode) { mpgEvent_ps->ram_as[ramNext].EventCode = 0; ramUpdate = 1; } /* Update event code and burst counters */ if (mpgEvent_ps->ram_as[ramNext].EventCode) { mpgEvent_ps->count++; /* If event is bursting, check if this is the last one. */ if (mpgEvent_ps->maxBurstCount) { mpgEvent_ps->burstCountSoFar++; if (mpgEvent_ps->burstCountSoFar >= mpgEvent_ps->maxBurstCount) { mpgEvent_ps->burstCountSoFar = 0; mpgEvent_ps->enable = 0; } } } #ifdef __rtems__ if (ramUpdate && evgCard_ps) EgSeqRamWrite(evgCard_ps, ram, ramPos, &(mpgEvent_ps->ram_as[ramNext])); #endif /* set next RAM position */ ramPos++; /* get next record */ node_ps = ellNext(node_ps); } mpgRam_as[ramNext].change = 0; } /* Always add the timestamp and end-of-sequence events - unless the ram is still enabled */ if (!mpgRam_as[ramNext].enable) { mpgEvent_as[EVENT_FIDUCIAL].count++; mpgEvent_as[EVENT_HEARTBEAT].count++; mpgEvent_as[EVENT_SECONDS_0].count++; mpgEvent_as[EVENT_SECONDS_1].count++; mpgEvent_as[EVENT_RESET_TICK].count++; mpgEvent_as[EVENT_END_SEQUENCE].count++; /* When all events disabled - make sure ram is updated next time all events are enabled. Also, set pulseID to invalid. */ if (eventEnable) { pulseID = PULSEID(time_as[evrTimeNext1]); } else { pulseID = PULSEID_INVALID; mpgRam_as[ramNext].change = 1; } /* Add pulse ID. */ mpgEventSeqPutPulseID(pulseID, ramNext); /* Add end-of-sequence event if necessary */ lastTimestamp++; mpgEvent_ps = &mpgEvent_as[EVENT_END_SEQUENCE]; if ((mpgEvent_ps->ram_as[ramNext].Timestamp != lastTimestamp) || (mpgEvent_ps->ramPos_a[ramNext] != ramPos)) { mpgEvent_ps->ramPos_a[ramNext] = ramPos; mpgEvent_ps->ram_as[ramNext].Timestamp = lastTimestamp; #ifdef __rtems__ if (evgCard_ps) EgSeqRamWrite(evgCard_ps, ram, ramPos, &(mpgEvent_ps->ram_as[ramNext])); #endif } } /* Enable the next RAM for the next fiducial */ #ifdef __rtems__ if (evgCard_ps) { if (!mpgRam_as[ramNext].enable) { EgEnableRam(evgCard_ps, ramNext+1); mpgRam_as[ramNext].enable = 1; } /* For testing - when fiducial is not available, make it happen now. */ if (sendSeq) EgSeqTrigger(evgCard_ps, ramNext+1); if (!evgLockStatus) epicsMutexUnlock(evgCard_ps->EgLock); } #endif /* Unlock the static data so user requests can now be serviced. */ epicsMutexUnlock(mpgEventMutex_ps); return 0; } /*============================================================================= Name: mpgEventInp Abs: User Input for all Event Codes Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read point to subroutine record Rem: Subroutine for IOC:::TICKOFFSET Inputs: VAL - Delay Offset for all Event Codes (in Ticks) A - Send sequence when ready - For testing when there is no fiducial 0 = don't send, 1 = send Outputs: None. Sets static data. ==============================================================================*/ static int mpgEventInp(subRecord *psub) { /* Return with error if can't get mutex */ if ((!mpgEventMutex_ps) || epicsMutexLock(mpgEventMutex_ps)) return -1; sendSeq = psub->a; delayOffset = psub->val; epicsMutexUnlock(mpgEventMutex_ps); return 0; } /*============================================================================= Name: mpgEventBeamCode Abs: Process User Requested Changes to an Event Code's Pattern Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- longSubRecord * psub read point to subroutine record Rem: Subroutine for EVNT:SYS0:1:CHCK Inputs: A - Event Code B - Spare C - Beam Code associated with this Event Code (0 = do all beam codes) D - Pipeline Index (0 to MAX_EVR_TIME-1, >= MAX_EVR_TIME - no pattern checking) E - Pattern Check Index (0 to PATTERNS_PER_EVENT-1) I - Modifier2 Inclusion Mask J - Modifier3 Inclusion Mask K - Modifier4 Inclusion Mask L - Modifier5 Inclusion Mask M - Modifier6 Inclusion Mask N - Modifier2 Exclusion Mask O - Modifier3 Exclusion Mask P - Modifier4 Exclusion Mask Q - Modifier5 Exclusion Mask R - Modifier6 Exclusion Mask Outputs: VAL = Event Code ==============================================================================*/ static int mpgEventBeamCode(longSubRecord *psub) { int eidx, pidx, midx; unsigned long *outp; /* Return with error if invalid event code or pattern index. */ psub->val = 0; if ((psub->a <= 0) || (psub->a >= MRF_NUM_EVENTS) || (psub->e >= PATTERNS_PER_EVENT)) return -1; eidx = psub->a; pidx = psub->e; /* Return with error if can't get mutex. */ if ((!mpgEventMutex_ps) || epicsMutexLock(mpgEventMutex_ps)) return -1; /* Add masks for pattern checking. */ mpgEvent_as[eidx].pattern_as[pidx].beamCode = psub->c; mpgEvent_as[eidx].pattern_as[pidx].pipelineID = psub->d; for (midx = 1, outp = &psub->i; midx < MAX_EVR_MODIFIER; midx++, outp++) mpgEvent_as[eidx].pattern_as[pidx].inclusion_a[midx] = *outp; for (midx = 1, outp = &psub->n; midx < MAX_EVR_MODIFIER; midx++, outp++) mpgEvent_as[eidx].pattern_as[pidx].exclusion_a[midx] = *outp; epicsMutexUnlock(mpgEventMutex_ps); psub->val = psub->a; return 0; } /*============================================================================= Name: mpgEventCode Abs: Process User Requested Changes to an Event in the Sequence RAM Not done at 360Hz! Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- longSubRecord * psub read point to subroutine record Rem: Subroutine for EVNT:SYS0:1:CTRL Inputs: A - Event Code B - Desired Delay in the Sequence Ram (clock ticks) C - Minimum Delay (clock ticks) D - Maximum Delay (clock ticks) E - Enable/Disable this event code F - Event code applies to every cycle G - Spare H - Number of Pulses to Send - this event automatically disables after number is sent. 0 = always send Outputs: I - Desired Delay in the Sequence Ram (clock ticks) VAL = Actual Event Code Ret: 0 = OK, -1 = ERROR ==============================================================================*/ static long mpgEventCode(longSubRecord *psub) { mpgEvent_ts *mpgEvent_ps; ELLNODE *node_ps; int newdelay = psub->b; int newcode = psub->a; int prvcode = psub->val; /* Return with error if can't get mutex, outputs remain unchanged */ if ((!mpgEventMutex_ps) || epicsMutexLock(mpgEventMutex_ps)) return -1; /* Override invalid event code with the null event code. An event code is invalid if its already being used by another EVNT record or if the delay is out of bounds. */ if ((newcode <= 0) || (newcode >= MRF_NUM_EVENTS) || ((newcode != mpgEvent_as[prvcode].code) && mpgEvent_as[newcode].code) || (newdelay < psub->c) || (newdelay > psub->d) || (newdelay < MINIMUM_EVENT_DELAY)) { newcode = 0; newdelay = 0; } /* Remove this event from the event list on any change to event code or delay. */ if (mpgEvent_as[prvcode].code && ((newcode != mpgEvent_as[prvcode].code ) || (newdelay != mpgEvent_as[prvcode].delay))) { ellDelete(&eventList_s, &(mpgEvent_as[prvcode].node_s)); mpgEvent_as[prvcode].code = 0; mpgEvent_as[prvcode].enable = 0; mpgEvent_as[prvcode].delay = 0; mpgEvent_as[prvcode].count = 0; mpgEvent_as[prvcode].burstCountSoFar = 0; mpgRam_as[0].change = mpgRam_as[1].change = 1; } /* Add this event to the event list in the proper order based on delay. */ if (newcode && (!mpgEvent_as[newcode].code)) { int addEvent = 1; mpgEvent_as[newcode].ram_as[0].EventCode = 0; mpgEvent_as[newcode].ram_as[1].EventCode = 0; mpgEvent_as[newcode].ram_as[0].Timestamp = 0; mpgEvent_as[newcode].ram_as[1].Timestamp = 0; node_ps = ellFirst(&eventList_s); while(node_ps) { mpgEvent_ps = (mpgEvent_ts *)node_ps; /* Insert it if it's a smaller than or equal to this one's delay. */ if (newdelay < mpgEvent_ps->delay) { ellInsert(&eventList_s, node_ps->previous, &(mpgEvent_as[newcode].node_s)); mpgRam_as[0].change = mpgRam_as[1].change = 1; node_ps = 0; addEvent = 0; } /* Cannot use the same delay as another event. Reject user request. */ else if (newdelay == mpgEvent_ps->delay) { newcode = 0; newdelay = 0; node_ps = 0; addEvent = 0; } else { node_ps = ellNext(node_ps); } } if (addEvent) { ellAdd(&eventList_s, &(mpgEvent_as[newcode].node_s)); mpgRam_as[0].change = mpgRam_as[1].change = 1; } } /* Now set up new attributes for this event - 360Hz processing will change RAM position, update timestamp, and update event code */ mpgEvent_as[newcode].code = newcode; mpgEvent_as[newcode].delay = newdelay; if (newcode) mpgEvent_as[newcode].enable = psub->e; else mpgEvent_as[newcode].enable = 0; mpgEvent_as[newcode].everyCycle = psub->f; mpgEvent_as[newcode].maxBurstCount = psub->h; if (mpgEvent_as[newcode].maxBurstCount == 0) mpgEvent_as[newcode].burstCountSoFar = 0; else if (mpgEvent_as[newcode].maxBurstCount < mpgEvent_as[newcode].burstCountSoFar) { mpgEvent_as[newcode].burstCountSoFar = 0; mpgEvent_as[newcode].enable = 0; } epicsMutexUnlock(mpgEventMutex_ps); psub->i = newdelay; psub->val = newcode; return 0; } /*============================================================================= Name: mpgEventRate Abs: Return Rate of an Event Code for MOD720 diagnostic processing. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read point to subroutine record Rem: Subroutine for EVNT:SYS0:1:RATE Inputs: A - Event Code Outputs: VAL = Event Code Rate Ret: 0 = OK, -1 = ERROR ==============================================================================*/ static long mpgEventRate(subRecord *psub) { int eventcode = psub->a; psub->val = 0; if ((eventcode <= 0) || (eventcode >= MRF_NUM_EVENTS)) return -1; /* Return with error if can't get mutex */ if ((!mpgEventMutex_ps) || epicsMutexLock(mpgEventMutex_ps)) return -1; psub->val = (double)mpgEvent_as[eventcode].count/MODULO720_SECS; mpgEvent_as[eventcode].count = 0; epicsMutexUnlock(mpgEventMutex_ps); return 0; } /*============================================================================= Name: mpgEventState Abs: MPG Event 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:EVENTDIAG Inputs: A - Spare B - Counter Reset Flag Outputs: Q - Number of lock errors in event processing R - Number of times a seq ram was still busy S - Number of times a seq ram was not in single mode T - Number of times a seq ram was still active U - Number of bad patterns in event processing VAL = not used Side: File-scope counters may be reset. Ret: 0 = OK ==============================================================================*/ static long mpgEventState(longSubRecord *psub) { psub->q = lockErrCount; psub->r = busyErrCount; psub->s = modeErrCount; psub->t = enableErrCount; psub->u = patternErrCount; if (psub->b > 0) { psub->b = 0; lockErrCount = 0; busyErrCount = 0; modeErrCount = 0; enableErrCount = 0; patternErrCount = 0; } return 0; } epicsRegisterFunction(mpgEventCode); epicsRegisterFunction(mpgEventBeamCode); epicsRegisterFunction(mpgEventRate); epicsRegisterFunction(mpgEventInp); epicsRegisterFunction(mpgEventState);