/*============================================================================= Name: ffGlob.c ffInitGlobals ffThreadGetTid ffThreadGetMqId ffGlobCpyIOCName - copy the IOC name from env var into ffIOCName_a global ffGetIOCName - return a ptr to the ffIOCName string Abs: general purpose utilities for the ff-aware threads reference document: LCLS Controls | Facilities | FF-Aware IOC | General Purpose Utilities Auth: 09-SEP-2004, diane fairley (DFAIRLEY): created Rev: 02 feb 2005, Debbie Rogind -----------------------------------------------------------------------------*/ #include "copyright_SLAC.h" /* SLAC copyright comments */ /*----------------------------------------------------------------------------- Mod: (newest to oldest) 27-apr-2007, dfairley added LOCA2 fixes 25-apr-2006 added ffGetLOCA2Name, ffGlobCpyLOCA2Name (dfairley) 07-APR-2005, Ron MacKenzie (ronm) Removed asyncExists at Steph's behest. It's in ffAsync.c now. Remove setting of ffJobs_as[].async_e because we don't have async jobs. Initialize 2 new elements of ffJob_ts which are new for async jobs. 09-DEC-2004, diane fairley: added header, changed a lot to meet new coding standards =============================================================================*/ #include "debugPrint.h" #ifdef DEBUG_PRINT #include int ffGlobFlag = DP_DEBUG; #endif /* c includes */ #include /* getenv */ #include /* memcpy */ #include /* clock_gettime, struct timespec */ /* epics includes */ #include /* epicsEventId */ #include /* callocMustSucceed */ #include /* freeListInitPvt */ #ifdef __rtems__ #include #endif /* ffIOC includes */ #include "ffStructs.h" /* ffThread_ts, ffSocket_ts, etc. */ #include "ffTimer.h" /* ffTimer_ts */ #include "msgTypes.h" /* MAX_SMALL_MSG_SIZE, MAX_LARGE_MSG_SIZE, etc */ /* function prototypes */ #include "ffGlob.h" #include "devFbckData.h" /* global variables */ /* array of thread structures */ ffThread_ts ffThreads_as[MAX_THREADS]; /* global runtime data per feedback loop iteration */ loopRT_ts loopRT_as[MAX_LOOPS]; /* list of POIs for the fiducial funtion to match against */ ffPOIs_ts ffPOIs_s; /* each entry is initialized by the loop thread */ /*list of events that must be fired for this fiducial */ ffWakupEvents_ts ffWakeupEvents_s; /* the global timer structure */ ffTimer_ts ffTimer_s; /* the global timer delay, PV value monitored and updated */ unsigned long volatile ffDelay_in_usec = 4000; char ffIocName_a[5]; char ffLocaName_a[5]; char ffLoca2Name_a[5]; char ffSpareStartLoop_a[5]; char ffSpareStopLoop_a[5]; char ffProxyIPAddr_a[16]; epicsEventId dbDownloadEvent_ps = NULL; epicsBoolean dbExists; epicsBoolean ffIocIsLittleEndian; void * ffSmMsgPvt_p = NULL; /* pointer to small-message pool */ void * ffLrgMsgPvt_p = NULL;/* pointer to large-message pool */ execDiags_ts execDiagnostics_s = {{0,0}, 0, 0}; static epicsBoolean ffNotify = epicsFalse; LOCAL void ffGlobInitDevSupportMeas(int cnt, char * loopStr); LOCAL void ffGlobInitDevSupportAct(int cnt, char * loopStr); LOCAL void ffGlobInitDevSupportState(int cnt, char * loopStr); /*============================================================================= Name: ffGlobInitGlobals Abs: initialize the global variables and structures. Called before IOCINIT!!! Args: none Rem: this function initializes all the global vars Side: Ret: none ==============================================================================*/ /**procedure**/ void ffGlobInitGlobals(void) { int cnt; /* initialize the threads structure */ for (cnt=0; cnt1000000000) { temp.secPastEpoch = time1.secPastEpoch+time2.secPastEpoch+1; temp.nsec = time1.nsec+time2.nsec-1000000000; } else { temp.secPastEpoch = time1.secPastEpoch+time2.secPastEpoch; temp.nsec = time1.nsec+time2.nsec; } return temp; } /*=========================================================== Name: ffGlobCpyIOCName Abs: set the ff microname from the environment var Args: none Rem: copy the IOC_NAME environment variable into the global character array Side: none Ret: none ===========================================================*/ void ffGlobCpyIOCName(void) { char * tmpIoc; memset( &ffIocName_a, 0, 5); tmpIoc = getenv("IOC_NAME"); DEBUGPRINT(DP_DEBUG, ffGlobFlag, ("ffGlob: ffGlobCpyIOCName\n")); if (tmpIoc != NULL) { memcpy(&ffIocName_a, tmpIoc, 5); } else memset (&ffIocName_a,63,2); DEBUGPRINT(DP_DEBUG, ffGlobFlag, ("ffGlob: ffGlobCpyLOCAName : IOC_NAME = %s\n", (char *)&ffIocName_a)); } /*=========================================================== Name: ffGetFfIocName Abs: get the ff-aware Ioc name Args: none Rem: get a pointer to the IOC_NAME string Side: none Ret: char * str ===========================================================*/ char * ffGetIOCName(void) { return (char *)&ffIocName_a; } /*=========================================================== Name: ffThreadGetTid Abs: return the epicsThreadId for the given thread enumeration Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- ffThread_te thrd_e read only thread enumeration Rem: checks for a valid thrd_e, returns the assigned tid_ps or NULL Side: Ret: epicsThreadId or NULL if thrd_e is invalid ===========================================================*/ epicsThreadId ffThreadGetTid(const ffThread_te thrd_e) { if (thrd_e < ffEnd) return ffThreads_as[thrd_e].tid_ps; else return NULL; } /*=========================================================== Name: ffThreadGetMqId Abs: return the epicsMessageQueueId assigned to the given thread Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- ffThread_te thrd_e read only thread enumeration Rem: checks for a valid thrd_e, returns the assigned mqId_ps or NULL Side: Ret: epicsMessageQueueId or NULL if thrd_e is invalid ===========================================================*/ epicsMessageQueueId ffThreadGetMqId(const ffThread_te thrd_e) { if (thrd_e < ffEnd) return ffThreads_as[thrd_e].mqId_ps; else return NULL; } /*=========================================================== Name: ffGlobCpyLOCAName Abs: set the ffIOC location name from the environment var Args: none Rem: copy the LOCA_NAME environment variable into the global character array Side: none Ret: none ===========================================================*/ void ffGlobCpyLOCAName(void) { char * tmpLoca; memset( &ffLocaName_a, 0, 5); tmpLoca = getenv("LOCA_NAME"); if (tmpLoca != NULL) { memcpy(&ffLocaName_a, tmpLoca, 5); } else memset (&ffLocaName_a,63,2); DEBUGPRINT(DP_DEBUG, ffGlobFlag, ("ffGlob: ffGlobCpyLOCAName : LOCA_NAME = %s\n", (char *)&ffLocaName_a)); } /*=========================================================== Name: ffGlobCpySpareStartLoop Abs: set the ffIOC spare loop name from reading environment var Args: none Rem: copy the SPARE_START_LOOP environment variable into the global character array Side: none Ret: none ===========================================================*/ void ffGlobCpySpareStartLoop(void) { char * tmpSpare_a; memset( &ffSpareStartLoop_a, 0, 5); tmpSpare_a = getenv("SPARE_LOOP_START"); if (tmpSpare_a != NULL){ memcpy(&ffSpareStartLoop_a, tmpSpare_a, 5); } else memset (&ffSpareStartLoop_a,63,2); DEBUGPRINT(DP_DEBUG, ffGlobFlag, ("ffGlob: ffGlobCpySpareStartLoop : SPARE_LOOP_START = %s\n", (char *)&ffSpareStartLoop_a)); } /*=========================================================== Name: ffGetSpareStartLoop Abs: get the ff IOC's epics spare start loop nomenclature Args: none Rem: get a pointer to the SPARE_START_LOOP string Side: none Ret: char * str ===========================================================*/ char * ffGetSpareStartLoop(void) { return (char *)&ffSpareStartLoop_a; } /*=========================================================== Name: ffGlobCpySpareStopLoop Abs: set the ffIOC spare loop name from reading environment var Args: none Rem: copy the SPARE_STOP_LOOP environment variable into the global character array Side: none Ret: none ===========================================================*/ void ffGlobCpySpareStopLoop(void) { char * tmpSpare; memset( &ffSpareStopLoop_a, 0, 5); tmpSpare = getenv("SPARE_LOOP_STOP"); if (tmpSpare != NULL){ memcpy(&ffSpareStopLoop_a, tmpSpare, 5); } else memset (&ffSpareStopLoop_a,63,2); DEBUGPRINT(DP_DEBUG, ffGlobFlag, ("ffGlob: ffGlobCpySpareStopLoop : SPARE_LOOP_STOP = %s\n", (char *)&ffSpareStopLoop_a)); } /*=========================================================== Name: ffGetSpareStopLoop Abs: get the ff IOC's epics spare last loop nomenclature Args: none Rem: get a pointer to the SPARE_STOP_LOOP string Side: none Ret: char * str ===========================================================*/ char * ffGetSpareStopLoop(void) { return (char *)&ffSpareStopLoop_a; } /*=========================================================== Name: ffGlobCpyLOCA2Name Abs: set the ffIOC second location name from the environment var Args: none Rem: copy the LOCA2_NAME environment variable into the global character array Side: none Ret: none ===========================================================*/ void ffGlobCpyLOCA2Name(void) { char * tmpLoca; memset( &ffLoca2Name_a, 0, 5); tmpLoca = getenv("LOCA2_NAME"); if (tmpLoca != NULL){ memcpy(&ffLoca2Name_a, tmpLoca, 5); } else memset (&ffLoca2Name_a,63,2); DEBUGPRINT(DP_DEBUG, ffGlobFlag, ("ffGlob: ffGlobCpyLOCA2Name : LOCA2_NAME = %s\n", (char *)&ffLoca2Name_a)); } /*=========================================================== Name: ffGetFfLOCA2Name Abs: get the ff-aware Ioc second location name for epics Args: none Rem: get a pointer to the LOCA2_NAME string Side: none Ret: char * str ===========================================================*/ char * ffGetLOCA2Name(void) { char tmpLoca2_a[5]; memset( &tmpLoca2_a, 0, 5); if (strcmp((const char *)&tmpLoca2_a, (const char *)&ffLoca2Name_a)==0) return NULL; else return (char *)&ffLoca2Name_a; } /*=========================================================== Name: ffGetFfLOCA2Name Abs: get the ff-aware Ioc second location name for epics Args: none Rem: get a pointer to the LOCA2_NAME string Side: none Ret: char * str ===========================================================*/ char * ffGetLOCAName(void) { char tmpLoca_a[5]; memset( &tmpLoca_a, 0, 5); if (strcmp((const char *)&tmpLoca_a, (const char *)&ffLocaName_a)==0) return NULL; else return (char *)&ffLocaName_a; }