/*============================================================================= Name: mpsEvrProc.c mpsEvrStart - MPS EVR Initialization mpsEvrProcInit - MPS EVR Pattern Processing Initialization mpsEvrProc - MPS EVR Pattern Processing mpsTask - MPS EVR Task for testing mpsTaskPrint - MPS EVR Task printout Abs: This file contains all subroutine support for mps evr pattern processing records. 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: Rev: -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) =============================================================================*/ #include /* for struct subRecord */ #include "subRecord.h" /* for struct subRecord */ #include "registryFunction.h" /* for epicsExport */ #include "iocsh.h" /* for iocshRegister */ #include "epicsExport.h" /* for epicsRegisterFunction */ #include "epicsMutex.h" /* epicsMutexId and protos */ #include "epicsEvent.h" /* for epicsEvent* */ #include "epicsThread.h" /* for epicsThreadCreate */ #include "evrTime.h" /* MAX_EVR_TIME,evrTimeNext3 */ #include "evrPattern.h" /* MOD5_BEAMFULL_MASK */ typedef struct { epicsTimeStamp timestamp; epicsUInt32 timeslot; epicsUInt32 timeslotmask; epicsUInt32 pulseid; epicsUInt32 beam; epicsUInt32 spare; } mpsPulse_ts; #define MAX_MPS_TIME (MAX_EVR_TIME) static mpsPulse_ts mpsPulse_as[MAX_MPS_TIME]; static epicsMutexId mpsPulseRWMutex_ps = 0; static epicsEventId mpsTaskEventSem = 0; int mpsTaskCounter = 0; /* Testing */ void mpsTaskPrint() { int idx; mpsPulse_ts mpsPrint_as[MAX_MPS_TIME]; if (mpsPulseRWMutex_ps && (!epicsMutexLock(mpsPulseRWMutex_ps))) { for (idx=0;idx Side: ? Sub Inputs/ Outputs: Inputs: None Outputs: None Ret: 0 = OK, -1 = Error. ==============================================================================*/ static int mpsEvrProcInit(subRecord *psub) { /* Start the MPS task if it isn't already started */ if (mpsEvrStart(0)) return -1; /* do whatever initialization is needed here */ return 0; } /*============================================================================= Name: mpsEvrProc Abs: 360Hz MPS EVR Processing. Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read point to subroutine record Rem: Subroutine for Side: Mutex lock/unlock, event signal. Sub Inputs/ Outputs: Inputs: A - Time Slot N B - PULSEID N C - Modifier5 N (has beam request bit) D - Spare N E - Time Slot N-1 F - PULSEID N-1 G - Modifier5 N-1 H - Spare N-1 I - Time Slot N-2 J - PULSEID N-2 K - Modifier5 N-2 L - Spare N-2 Outputs: VAL - Status Ret: 0 = OK, -1 = Error. =============================================================================*/ static long mpsEvrProc(subRecord *psub) { double *doubleValue_p; epicsUInt32 modifier5; int idx; long status; if (mpsPulseRWMutex_ps && (!epicsMutexLock(mpsPulseRWMutex_ps))) { for (idx = 0, doubleValue_p = &psub->a; idx < evrTimeNext3; idx++) { evrTimeGetFromPipeline(&mpsPulse_as[idx].timestamp, idx, 0,0,0,0,0); mpsPulse_as[idx].timeslot = (epicsUInt32)(*doubleValue_p); doubleValue_p++; mpsPulse_as[idx].pulseid = (epicsUInt32)(*doubleValue_p); doubleValue_p++; modifier5 = (epicsUInt32)(*doubleValue_p); mpsPulse_as[idx].beam = (modifier5 & MOD5_BEAMFULL_MASK)?1:0; doubleValue_p++; mpsPulse_as[idx].spare = (epicsUInt32)(*doubleValue_p); doubleValue_p++; } epicsMutexUnlock(mpsPulseRWMutex_ps); if (mpsTaskEventSem) epicsEventSignal(mpsTaskEventSem); status = 0; } else { status = -1; } psub->val = status; return status; } epicsRegisterFunction(mpsEvrProcInit); epicsRegisterFunction(mpsEvrProc); static const iocshArg mpsEvrStartArg0 = {"Fiducial Registry Flag", iocshArgInt}; static const iocshArg *const mpsEvrStartArgs[1] = {&mpsEvrStartArg0}; static const iocshFuncDef mpsEvrStartDef = {"mpsEvrStart", 1, mpsEvrStartArgs}; static void mpsEvrStartCall(const iocshArgBuf * args) { mpsEvrStart(args[0].ival); } static const iocshFuncDef mpsTaskPrintDef = {"mpsTaskPrint", 0, 0}; static void mpsTaskPrintCall(const iocshArgBuf * args) { mpsTaskPrint(); } static void mpsEvrRegister() { iocshRegister(&mpsEvrStartDef , mpsEvrStartCall ); iocshRegister(&mpsTaskPrintDef , mpsTaskPrintCall ); } epicsExportRegistrar(mpsEvrRegister);