int gilShow(int level) { int location, type; int i,j; DPRINT(0,"Defined Racks: \n"); for(j=0;j<g215Bed.NumRacks;j++) { DPRINT4(0,"Rack[%d]: 0x%lx, Id: '%s', Type: %d\n", j, g215Bed.DefinedRacks[j].pRackObj, g215Bed.DefinedRacks[j].IdStr, g215Bed.DefinedRacks[j].type); } DPRINT(0,"\n\nCenters: \n"); DPRINT3(0,"Injector: X: %d, Y: %d, Z: %d\n", g215Bed.InjectorCenter[0], g215Bed.InjectorCenter[1], g215Bed.InjectorBot); DPRINT2(0,"1st Rack: X: %d, Y: %d\n", g215Bed.Rack1Center[0], g215Bed.Rack1Center[1]); DPRINT(0,"Loaded Racks: \n"); for(j=0;j<GIL_MAX_RACKS;j++) { if (g215Bed.LoadedRacks[j] != NULL) DPRINT2(0,"Rack[%d]: 0x%lx \n", j, g215Bed.LoadedRacks[j]); } return 0; }
Rval *selectERval(varInfo *v, int i) { int j; Rval *p; DPRINT2(3,"selectERval: find %dth ERval of var 0x%08x...\n",i,v); if (0 < i) { p = v->E; j = 1; while ((j < i) && p) { DPRINT2(3,"selectERval: ...not %dth (was 0x%08x)\n",j,p); p = p->next; j += 1; } #ifdef DEBUG if (p) DPRINT2(3,"selectERval: SUCCEEDED, %dth is 0x%08x\n",i,p); else DPRINT0(3,"selectERval: FAILED, ran out of ERval packets!\n"); #endif return(p); } else { DPRINT0(3,"selectERval: FAILED, can't select 0th value\n"); return(NULL); } }
/* * Task waits for the semaphore to be given then publishes the Status * This is done to avoid doing the publishing from within a ISR routines. * * Author: Greg Brissey 9/29/04 */ pubFidCtStatus() { int arg,bytes; FidCt_Stat fstat; int timeoutnticks; timeoutnticks = calcSysClkTicks(5000); /* 5 sec timeout */ FOREVER { /* semTake(pFidCtPubSem, WAIT_FOREVER); see bugzilla bug #150 WSR TSR# 421424 */ /* bytes = msgQReceive(pFidCtPubMsgQ, (char*)&fstat,sizeof(FidCt_Stat), WAIT_FOREVER); */ bytes = msgQReceive(pFidCtPubMsgQ, (char*)&fstat,sizeof(FidCt_Stat), timeoutnticks); /* DPRINT1(-1,"pubFidCtStatus: CT: %d\n",arg); */ if (pFidCtStatusPub != NULL) { if (bytes != ERROR) { pFidCtStat->FidCt=fstat.FidCt; pFidCtStat->Ct=fstat.Ct; DPRINT2(1,"pubFidCtStatus: QRECV: fid:%d ct:%d\n", (int)fstat.FidCt,(int)fstat.Ct); } else /* timed out, allows console to go idle if time Procs running before comlink is set up */ { pFidCtStat->FidCt=fid_count; pFidCtStat->Ct=fid_ct; DPRINT2(5,"pubFidCtStatus: Timed out: fid:%d ct:%d\n", (int)fid_count,(int)fid_ct); } #ifndef RTI_NDDS_4x nddsPublishData(pFidCtStatusPub); #else /* RTI_NDDS_4x */ publishFidCtStat(pFidCtStatusPub); #endif /* RTI_NDDS_4x */ } } }
int setLockPar( int acode, int value, int startfifo ) { unsigned short apvalue, latch, lockapreg; int tindex; int (*converter)(); int (*storevalue)(); DPRINT2( 9, "do lock A-code starts with acode = %d and value = %d\n", acode, value ); tindex = acode2index( acode ); if (tindex < 0) { DPRINT1(0, "error getting index for lock A-code %d\n",acode); return( -1 ); } latch = AP_LATCH4LOCK; lockapreg = index2apreg( tindex ); converter = index2converter( tindex ); if (converter != NULL) apvalue = (*converter)( value ); else apvalue = value; DPRINT2( 9, "do lock A-code, AP register: 0x%x, AP value: 0x%x\n", lockapreg, apvalue ); if (startfifo) writeapwordStandAlone( lockapreg, (apvalue & 0xff) | latch, AP_LOCKDELAY ); else writeapword( lockapreg, (apvalue & 0xff) | latch, AP_LOCKDELAY ); storevalue = index2valuestore( tindex ); if (storevalue != NULL) (*storevalue)( value ); return(0); }
RTIBool App_NodeCallback(const NDDSRecvInfo *issue, NDDSInstance *instance, void *callBackRtnParam) { App_HB *recvIssue; int cntlrType; /* possible status values: NDDS_FRESH_DATA, NDDS_DESERIALIZATION_ERROR, NDDS_UPDATE_OF_OLD_DATA, NDDS_NO_NEW_DATA, NDDS_NEVER_RECEIVED_DATA */ /* cntlrType = *((int*)callBackRtnParam); */ if (issue->status == NDDS_FRESH_DATA) { recvIssue = (App_HB *) instance; DPRINT6(+3, "'%s': App_NodeCallback: '%s': received AppStr: '%s', HB cnt: %lu, ThreadId: %d, AppID: %d\n", ProcName,issue->nddsTopic,recvIssue->AppIdStr, recvIssue->HBcnt, recvIssue->ThreadId,recvIssue->AppId); if (DDR_HB < 1) { DDR_HB = 1; DPRINT2(+1,"'%s': App_NodeCallback: Issue: '%s', Is Back.\n", ProcName, issue->nddsTopic); } } else if (issue->status == NDDS_NO_NEW_DATA) { DPRINT2(+1,"'%s': App_NodeCallback: Issue: '%s', Missed Deadline, Node must be gone.\n", ProcName, issue->nddsTopic); DDR_HB = -1; } return RTI_TRUE; }
/************************************************************** * * hashShow - show hash table information * * * This routine display that state and optionally the * hash table contents. * * RETURNS: * * Author Greg Brissey 8/5/93 */ void hashShow (HASH_ID hashid, int level) /* HASH_ID hashid; hash table to show */ /* int level; level of information output */ { DPRINT2(3,"Hash Table ID: '%s', 0x%lx\n",hashid->pHashIdStr,hashid); DPRINT(3,"Hash Stats:\n"); DPRINT2(3,"Hash Table Address: %ld, 0x%lx\n", hashid->pHashEntries,hashid->pHashEntries); DPRINT2(3,"Entries: %ld, Max Entries: %ld\n", hashid->numEntries, hashid->maxEntries); DPRINT1(3,"Number of Hashing Collisions: %ld\n",hashid->collisions); DPRINT2(3,"Hash Func: 0x%lx, Comparison Func: 0x%lx\n",hashid->pHashFunc, hashid->pCmpFunc); if (level > 0) { long i; register HASH_ENTRY *hashlist; hashlist = hashid->pHashEntries; DPRINT(3,"\n\nHash Table Entries:\n"); for(i=0;i<hashid->maxEntries;i++) { if (hashlist[i].hashKey) { DPRINT3(3,"Hash Index[%ld]: Key: 0x%lx, Reference Addr: 0x%lx\n", i,hashlist[i].hashKey,hashlist[i].refAddr); } } } }
/* * Used by processFID() thread, to wait for the recvFID() threads to reach the non-active state * then it can safely proceed to close up experimenr files, etc. * I tried setting time out less than 1 second via getimeofday() * gettimeofday(&tp,NULL); * timeout.tv_sec = tp.tv_sec; This never worked properly * timeout.tv_nsec = (tp.tv_usec * 1000) + 500000000; .50 sec * But this never worked. */ wait4DoneCntlrStatus() { int status, cancel, temp; cntlr_status_t *pCntlrStatus; struct timespec timeout; pCntlrStatus = &CntlrStatus; status = pthread_mutex_lock( &pCntlrStatus->mutex ); if (status != 0) return status; pCntlrStatus->waiting4Done = 1; /* thread waiting for done */ if (pCntlrStatus->cntlrsActive == 0) { DPRINT(+2,"wait4DoneCntlrStatus: count is Zero, Just return\n"); status = 0; } else { /* not a cancellation point, disable it */ pthread_setcancelstate( PTHREAD_CANCEL_DISABLE, &cancel); /* * Wait until wrkdone == 1 which means that it * has been boradcast to continue */ DPRINT2(+2,"wait4DoneCntlrStatus: active: %d, workdone: %d, wait on conditional\n", pCntlrStatus->cntlrsActive,pCntlrStatus->wrkdone); while( pCntlrStatus->wrkdone != 1 ) { barrierWaitAbort(&TheBarrier); /* free any struck threads */ time(&timeout.tv_sec); timeout.tv_sec += 1; /* one second timeout */ timeout.tv_nsec = 0; status = pthread_cond_timedwait( &pCntlrStatus->done, &pCntlrStatus->mutex,&timeout); /* status = pthread_cond_wait( &pCntlrStatus->done, &pCntlrStatus->mutex); */ DPRINT2(+2,"pthread_cond_timedwait: status return: %d, ETIMEDOUT: %d\n",status,ETIMEDOUT); if (status == ETIMEDOUT ) { DPRINT(+2,"wait4DoneCntlrStatus: timeout, retry\n"); } /* if (status != ETIMEDOUT ) { DPRINT(-4,"wait4DoneCntlrStatus: Error return\n"); break; } */ } pthread_setcancelstate( cancel, &temp); } pCntlrStatus->waiting4Done = 0; /* thread waiting for done */ pthread_mutex_unlock( &pCntlrStatus->mutex); return status; /* error, -1 for waker, or 0 */ }
int main( int argc, char * argv[] ) { int i; int x = 100; int y = 2; int name1 = 100; printf( "hello, Cruel World! \n" ); dprint( x/y ); dprint( x+y ); dprint( x+y+2 ); //return 0; printf( "name1 = %d \n", name1 ); paste( name, 1 ) = 123; printf( "name1 = %d \n", name1 ); #if 0 dprint( a ); dprint( b ); DPRINT( "a = %d b=%d ", 100, 200 ); DPRINT2( "a = %d b=%d ", 100, 200 ); #endif // paste2( name, 2 ); return 0; }
/* Lookup <str> and install if necessary; return pointer. */ char * strsave(char *str) { int h; struct str *p; h = hash(str); for (p = stab[h]; p != NULL; p = p->next) if (strcmp(str, p->str) == 0) return (p->str); p = (struct str *) emalloc(sizeof(struct str)); if (p == NULL) return NULL; p->str = (char *) emalloc(strlen(str) + 1); if (p->str == NULL) { efree(p); return NULL; } strcpy(p->str, str); p->next = stab[h]; stab[h] = p; DPRINT2("strsave ('%s') => %p\n", str, p); return p->str; }
/* * Create a Publication Topic to communicate with the Lock * * Author Greg Brissey 5-06-04 */ NDDS_ID createLockCmdPub(NDDS_ID nddsId, char *topic, char *cntlrName) { int result; NDDS_ID pPubObj; char pubtopic[128]; Lock_Cmd *issue; /* Build Data type Object for both publication and subscription to Expproc */ /* ------- malloc space for data type object --------- */ if ( (pPubObj = (NDDS_ID) malloc( sizeof(NDDS_OBJ)) ) == NULL ) { return(NULL); } /* zero out structure */ memset(pPubObj,0,sizeof(NDDS_OBJ)); memcpy(pPubObj,nddsId,sizeof(NDDS_OBJ)); strcpy(pPubObj->topicName,topic); pPubObj->pubThreadId = 89; /* DEFAULT_PUB_THREADID; */ /* fills in dataTypeName, TypeRegisterFunc, TypeAllocFunc, TypeSizeFunc */ getLock_CmdInfo(pPubObj); DPRINT2(-1,"Create Pub topic: '%s' for Cntlr: '%s'\n",pPubObj->topicName,cntlrName); createPublication(pPubObj); issue = (Lock_Cmd *) pPubObj->instance; return(pPubObj); }
/* * AcceptConnection() is a posix thread which waits on Accept, * when accept returns the newly created accept socket is placed on a queue * and a SIGIO signal is sent to the main thread to perform the read and processing * the socket message * * Author greg Brissey 3/21/2006 */ void *AcceptConnection( void *arg) { int result; Socket *pAcceptSocket; Socket *pListenSocket; pListenSocket = (Socket *) arg; pthread_detach(AcceptThreadId); /* if thread terminates no need to join it to recover resources */ for ( ;; ) { pAcceptSocket = (Socket *) malloc( sizeof( Socket ) ); if (pAcceptSocket == NULL) { return( NULL ); } pListenSocket = (Socket *) arg; memset( pAcceptSocket, 0, sizeof( Socket ) ); result = acceptSocket_r( pListenSocket, pAcceptSocket ); if (result < 0) { errLogSysRet(ErrLogOp,debugInfo,"acceptSocket_r" ); } else { DPRINT2(+3,"AcceptConnection: 0x%lx, fd: %d\n", pAcceptSocket,pAcceptSocket->sd); rngBlkPut(pAcceptQueue, &pAcceptSocket, 1); pthread_kill(main_threadId,SIGIO); /* signal console socket msg arrival to main thread */ /* kill(getpid(), SIGIO); */ } } }
/* WARNING this function will changed the calling task priority if it is lower than the Stuffer, to greater than the stuffer while putting fifo words into the fifo buffer */ void set2ExpEndState() /* reprogram HSlines, ap registers to safe state, Normal end */ { int callTaskId; int callTaskPrior; DPRINT(0,"set2ExpEndState"); #ifdef INOVA /* Keep the MTS gradient amp disabled whenever possible! */ gpaTuneSet(pTheAutoObject, SET_GPAENABLE, GPA_DISABLE_DELAY); DPRINT(0,"Stuff FIFO through Normal channels with Safe State & Run fifo"); fifoResetStufferFlagNSem(pTheFifoObject); callTaskId = taskIdSelf(); taskPriorityGet(callTaskId,&callTaskPrior); /* Lower priority to allow stuffer in, if needed */ /* if priority <= to that of the stuffer then lower the priority of this task */ /* thus allowing the stuffer to stuff the fifo */ DPRINT2(0,"set2ExpEndState: tid: 0x%lx, priority: %d\n",callTaskId,callTaskPrior); setlksample(); set2khz(); activate_ssha(); /* reset priority back if changed */ if (callTaskPrior <= FIFO_STUFFER_PRIORITY) { DPRINT(0,"Set priority Back \n"); taskPrioritySet(callTaskId,callTaskPrior); } #endif return; }
/* * As each thread recvFid() finishs it's work it decrements the number threads active */ decActiveCntlrStatus(char *cntlrId) { int status; cntlr_status_t *pCntlrStatus; pCntlrStatus = &CntlrStatus; status = pthread_mutex_lock( &pCntlrStatus->mutex ); if (status != 0) return status; pCntlrStatus->cntlrsActive--; DPRINT2(+2,"'%s': decActiveCntlrStatus: active: %d\n", cntlrId,pCntlrStatus->cntlrsActive); if (pCntlrStatus->cntlrsActive == 0) { DPRINT1(+2,"decActiveCntlrStatus: wait4done: %d\n",pCntlrStatus->waiting4Done); /* the usage of waiting4Done never worked properly occassional ending up never * broadcasting the conditiona variable */ /* if ( pCntlrStatus->waiting4Done == 1) /* thread waiting for done */ /* { */ DPRINT(+2,"decActiveCntlrStatus: count Zero, and someone waiting broadcast to show all done\n"); pCntlrStatus->wrkdone = 1; status = pthread_cond_broadcast( &pCntlrStatus->done ); /* } */ } pthread_mutex_unlock( &pCntlrStatus->mutex); return 0; /* error, -1 for waker, or 0 */ }
static int doUpdtNoAcodes( char *startarg ) { unsigned int offset; int cmd, num; int paramvec[ MAXNUMARGS ]; char *currentarg, *paramptr; currentarg = startarg; paramptr = strtok_r(currentarg,",",¤targ); cmd = atoi(paramptr); switch (cmd) { case FIX_APREG: num = getintargs(¤targ, paramvec, 3); DPRINT2( 1, "FIX APREG: APBUS: 0x%x, value: %d\n", paramvec[ 0 ], paramvec[ 2 ] ); updtapbus( paramvec[ 0 ], paramvec[ 2 ] ); break; case LKPHASE: num = getintargs(¤targ, paramvec, 1); updtLockphase ( paramvec[ 0 ] ); break; default: errLogRet( LOGIT, debugInfo, "Command not found or not supported unless A-codes are active.\n" ); DPRINT1(0, "A_updt: Command not found or not supported unless A-codes are active - cmd: %d\n", cmd ); break; } }
void killEmDead(int first2Die,int last2Die) { int i; struct timeval tv; for( i = first2Die; i <= last2Die; i++) { DPRINT2(1,"SIGTERM kill: %s pid: %d\n", taskList[i].procName,taskList[i].taskPid); if ( taskList[i].taskPid != (pid_t) -1 ) { kill(taskList[i].taskPid,SIGTERM); } } /* wait for a little while. can not sleep() in here. Apparently. kill(pid,0) does not work * until the process is reaped. */ tv.tv_sec = 2; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); /* let's make sure, if SIGTERM was not good enough we'll use something stronger SIGKILL */ for( i = first2Die; i <= last2Die; i++) { if (taskList[i].taskPid != (pid_t) -1) { kill(taskList[i].taskPid,SIGKILL); taskList[i].taskPid = (pid_t) -1; } } }
RTIBool FidCt_StatCallback(const NDDSRecvInfo *issue, NDDSInstance *instance, void *callBackRtnParam) { FidCt_Stat *FidCtIssue; if (issue->status == NDDS_FRESH_DATA) { FidCtIssue = (FidCt_Stat *) instance; DPRINT2(3,"FidCt_StatCallback(): FID=%d, Ct=%d\n", FidCtIssue->FidCt, FidCtIssue->Ct); if (pCurrentStatBlock != NULL) { if ( (pCurrentStatBlock->Acqstate == ACQ_INACTIVE) && (FidCtIssue->FidCt == 0) && (FidCtIssue->Ct == 0) ) { /* DPRINT(-5,"Set IDLE\n"); */ pCurrentStatBlock->Acqstate = ACQ_IDLE; } else if ( (pCurrentStatBlock->Acqstate == ACQ_IDLE) && (FidCtIssue->FidCt == -1) && (FidCtIssue->Ct == -1) ) { pCurrentStatBlock->Acqstate = ACQ_INACTIVE; /* DPRINT(-5,"Set INACTIVE\n"); */ } if ( (pCurrentStatBlock->Acqstate != ACQ_ACQUIRE) || FidCtIssue->FidCt || FidCtIssue->Ct ) { pCurrentStatBlock->AcqFidCnt = FidCtIssue->FidCt; pCurrentStatBlock->AcqCtCnt = FidCtIssue->Ct; sendConsoleStatus(); } } } return RTI_TRUE; }
/* * Create a Exception Publication to communicate with the Cntrollers/Master * * * Author Greg Brissey 8/18/05 * */ NDDS_ID createDDRSyncCommPub(NDDS_ID nddsId, char *topic, char *cntlrName) { int result; NDDS_ID pPubObj; char pubtopic[128]; Cntlr_Comm *issue; /* Build Data type Object for both publication and subscription to Expproc */ /* ------- malloc space for data type object --------- */ if ( (pPubObj = (NDDS_ID) malloc( sizeof(NDDS_OBJ)) ) == NULL ) { return(NULL); } /* create the pub issue Mutual Exclusion semaphore */ pDDRSyncPubMutex = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE); /* zero out structure */ memset(pPubObj,0,sizeof(NDDS_OBJ)); memcpy(pPubObj,nddsId,sizeof(NDDS_OBJ)); strcpy(pPubObj->topicName,topic); pPubObj->pubThreadId = 0xbadc0de; /* DEFAULT_PUB_THREADID; taskIdSelf(); */ /* fills in dataTypeName, TypeRegisterFunc, TypeAllocFunc, TypeSizeFunc */ getCntlr_CommInfo(pPubObj); DPRINT2(+1,"Create Pub topic: '%s' for Cntlr: '%s'\n",pPubObj->topicName,cntlrName); createPublication(pPubObj); issue = (Cntlr_Comm *) pPubObj->instance; strcpy(issue->cntlrId,cntlrName); /* fill in the constant cntlrId string */ return(pPubObj); }
void waitOrWerrResume(char *expIdStr, int proctype) { MSG_Q_ID pAutoMsgQ; int sendResume; DPRINT2(1,"waitOrWerrResume: Proc ID: '%s', Active ID: '%s'\n", ProcExpInfo.ExpId,expIdStr); if ( strcmp(expIdStr,ProcExpInfo.ExpId) == 0 ) { DPRINT3(1,"waitOrWerrResume: ProcWait: %d(0=nowait), proctype: %d(%d=WERR)\n", ProcExpInfo.ExpInfo->ProcWait,proctype,proctype); if ( (ProcExpInfo.ExpInfo->ProcWait == AU_NOWAIT) && (proctype != WERR) ) { sendResume = 0; } else { sendResume = 1; } } else { strncpy(ActiveExpInfo.ExpId,expIdStr,EXPID_LEN); ActiveExpInfo.ExpId[EXPID_LEN-1] = '\0'; DPRINT1(1,"waitOrWerrResume: Mapin ActiveExpInfo: '%s'\n",expIdStr); if (mapInExp(&ActiveExpInfo) == -1) { errLogRet(ErrLogOp,debugInfo, "waitOrWerrResume: Could not MapIn: '%s' \n",expIdStr); sendResume = 0; } else { DPRINT3(1,"waitOrWerrResume: ActiveWait: %d(0=nowait), proctype: %d(%d=WERR)\n", ActiveExpInfo.ExpInfo->ProcWait,proctype,proctype); if ( (ActiveExpInfo.ExpInfo->ProcWait == AU_NOWAIT) && (proctype != WERR) ) { sendResume = 0; } else { sendResume = 1; } mapOutExp(&ActiveExpInfo); } if (sendResume) { DPRINT(1,"waitOrWerrResume: Send Resume\n"); pAutoMsgQ = openMsgQ("Autoproc"); if (pAutoMsgQ != NULL) { sendMsgQ(pAutoMsgQ, "resume", strlen("resume"), MSGQ_NORMAL, WAIT_FOREVER); /* NO_WAIT */ closeMsgQ(pAutoMsgQ); } } } }
/************************************************************** * * dataInitial - Initializes the Data Object, based on the experiment * * * This routine initializes the DATA Object base on the experimental *parameters. The parameters: * <fidSize> is the smallest FID size (bytes) for the experiment * <totalFidBlks> is the total number of fid blocks to acquire. * Note: <totalFidBlks> is NOT the number of FID Elements but instead *the number of FID elements times the number of blocksizes (nt/bs). *E.G. arraydim=10,nt=32 & bs=8 then <totalFidBlks> = 10 * (32/8) = 40 * * * RETURNS: * OK or ERROR * * Author Greg Brissey 8/5/93 */ int dataInitial(DATAOBJ_ID pStmId, ulong_t totalFidBlks, ulong_t fidSize) /* DATAOBJ_ID pStmId - data Object identifier */ /* totalFidBlks Number of FID BLocks to be acquired */ /* fidSize Size of FID in bytes */ { char *addr; long maxNumFidBlkToAlloc; long i; FID_STAT_BLOCK *pStatBlk; /* pointer to FID Entry */ extern long maxBufSize(); if (pStmId == NULL) return(ERROR); DPRINT2(-1,"dataInitial: nFids: %lu, size: %lu\n", totalFidBlks, fidSize); /* The msg Q That the ISR use to pass on Info is Passed as an Argument it is Owned by the Uplinker e.g. interrupt type, CT or NT, Tag value */ maxNumFidBlkToAlloc = maxBufSize(fidSize, totalFidBlks,pStmId->dspMemSize); DPRINT4(-1,"maxBufSize: fidsize: %lu, fidblks: %lu, stm memsize: %lu, maxNumFidBlkToAlloc: %ld\n", fidSize,totalFidBlks,pStmId->dspMemSize,maxNumFidBlkToAlloc); /* if requested number is greater than already exist will need to realloc */ if (maxNumFidBlkToAlloc > pStmId->maxFreeList) { if (reAllocateResources(pStmId,maxNumFidBlkToAlloc)) { dataFreeAllRes(pStmId); errLogSysRet(LOGIT,debugInfo, "stmInitial: A resource could not be Allocated"); return(ERROR); } } /* Fill Free List with the list of Tag Values (0 to maxNumFidBlk...) */ pStmId->maxFidBlkBuffered = maxNumFidBlkToAlloc; rngXBlkFlush(pStmId->pTagFreeList); for (i=0; i<maxNumFidBlkToAlloc; i++) { rngXBlkPut(pStmId->pTagFreeList, &i, 1); } /* Mark all StatBlocks as Not Allocated */ for (i=0; i<maxNumFidBlkToAlloc; i++) { pStatBlk = &((pStmId->pStatBlkArray)[i]); pStatBlk->doneCode = NOT_ALLOCATED; pStatBlk->errorCode = 0; pStatBlk->fidAddr = NULL; pStatBlk->dataSize = fidSize; /* FID size in bytes */ pStatBlk += sizeof(FID_STAT_BLOCK); } return( OK ); }
int setLockPower( int lockpower_value, int startfifo ) { ushort lkpreampregvalue, lockpower, apvalue, latch, lockapreg; int tindex; int (*converter)(); int (*storevalue)(); DPRINT1( 9, "lockpower starts with value = %d\n", lockpower_value ); lockpower = lockpower_value; tindex = acode2index( LOCKPOWER_I ); if (tindex < 0) { DPRINT(0, "error getting index for lockpower A-code\n"); return( -1 ); } latch = AP_LATCH4LOCK; if (lockpower <= 0) { lockpower = 0; } else if (lockpower > 68) { lockpower = 68; } /* set preamp atten using lock backing store */ lkpreampregvalue = getlkpreampgainvalue(); if (lockpower > 48) { lockpower = lockpower-20; lkpreampregvalue |= LKPREAMPBIT; } else lkpreampregvalue &= (~LKPREAMPBIT); if (startfifo) writeapwordStandAlone( getlkpreampgainapaddr(), lkpreampregvalue | latch, AP_LOCKDELAY ); else writeapword( getlkpreampgainapaddr(), lkpreampregvalue | latch, AP_LOCKDELAY ); storelkpreampgainvalue( lkpreampregvalue ); lockapreg = index2apreg( tindex ); converter = index2converter( tindex ); if (converter != NULL) apvalue = (*converter)( lockpower ); else apvalue = lockpower; DPRINT2( 9, "lock power, AP register: 0x%x, AP value: 0x%x\n", lockapreg, apvalue ); if (startfifo) writeapwordStandAlone( lockapreg, (apvalue & 0xff) | latch, AP_LOCKDELAY ); else writeapword( lockapreg, (apvalue & 0xff) | latch, AP_LOCKDELAY ); storevalue = index2valuestore( tindex ); if (storevalue != NULL) (*storevalue)( lockpower_value ); }
char *registerDeath(pid_t pid) { int i; for( i = EXPPROC; i <= SPULPROC; i++) { DPRINT2(1,"registerDeath: died: %d, who: %d\n", pid,taskList[i].taskPid); /* Autoproc death is handled in msgehandler.c by a request to die to avoid race conditions with the SIGCHLD signal */ if ( (taskList[i].taskPid == pid) && ( i != AUTOPROC ) ) { taskList[i].taskPid = (pid_t) -1; DPRINT2(1,"Process: '%s' pid: %d, Died.\n",taskList[i].procName,pid); return(taskList[i].procName); } } return(NULL); }
/* Reliable Publication Status call back routine. At present we use this to indicate if a subscriber has come or gone */ void MyThreadPubStatusRtn(NDDSPublicationReliableStatus *status, void *callBackRtnParam) { cntlr_t *mine = (cntlr_t*) callBackRtnParam; switch(status->event) { case NDDS_QUEUE_EMPTY: DPRINT1(1,"'%s': Queue empty\n",mine->cntlrId); break; case NDDS_LOW_WATER_MARK: DPRINT1(1,"'%s': Below low water mark - ",mine->cntlrId); DPRINT2(1,"Topic: '%s', UnAck Issues: %d\n",status->nddsTopic, status->unacknowledgedIssues); break; case NDDS_HIGH_WATER_MARK: DPRINT1(1,"'%s': Above high water mark - ",mine->cntlrId); DPRINT2(1,"Topic: '%s', UnAck Issues: %d\n",status->nddsTopic, status->unacknowledgedIssues); break; case NDDS_QUEUE_FULL: DPRINT1(1,"'%s': Queue full - ",mine->cntlrId); DPRINT2(1,"Topic: '%s', UnAck Issues: %d\n",status->nddsTopic, status->unacknowledgedIssues); break; case NDDS_SUBSCRIPTION_NEW: DPRINT2(+1,"'%s': A new reliable subscription Appeared for '%s'.\n",mine->cntlrId, status->nddsTopic); /* mine->numSubcriber4Pub++; */ break; case NDDS_SUBSCRIPTION_DELETE: DPRINT2(+1,"'%s': A reliable subscription disappeared for '%s'.\n",mine->cntlrId, status->nddsTopic); /* mine->numSubcriber4Pub--; */ #ifdef TEST_THREAD_DELETION /* not used, not safe!! */ if (mine->numSubcriber4Pub == 0) { mine->numSubcriber4Pub = -1; /* -1 remoe thread */ /* rmCntrlThread(mine->crew, mine->cntlrId); */ } #endif break; default: /* NDDS_BEFORERTN_VETOED NDDS_RELIABLE_STATUS */ break; } }
/* * The Lock via NDDS uses this callback function to create Subscriptions to the * Host/MAster Lock Command Publications aimed at the Lock Controller * * Author Greg Brissey 5-05-04 */ NDDSSubscription Lock_CmdPatternSubCreate( const char *nddsTopic, const char *nddsType, void *callBackRtnParam) { NDDSSubscription pSub; DPRINT3(-1,"Lock_CmdPatternSubCreate(): Topic: '%s', Type: '%s', arg: 0x%lx\n", nddsTopic, nddsType, callBackRtnParam); DPRINT2(-1,"callbackParam: 0x%lx, callBackRtnParam: 0x%lx\n",&callbackParam,callBackRtnParam); pLockCmdSubs[numLockCmdSubs] = createLockCmdSub(NDDS_Domain, (char*) nddsTopic, (void *) &callbackParam ); pSub = pLockCmdSubs[numLockCmdSubs++]->subscription; return pSub; }
NDDS_ID createMonitorCmdsSub(char *subName) { void processChanMsge(); NDDS_ID pSubObj; /* Build Data type Object for both publication and subscription to Expproc */ /* ------- malloc space for data type object --------- */ if ( (pSubObj = (NDDS_ID) malloc( sizeof(NDDS_OBJ)) ) == NULL ) { return(NULL); } /* create pipe for messages from NDDS signal handler Console to Expproc */ if ( pipe(MonCmdPipe) != 0) { errLogSysQuit(ErrLogOp,debugInfo,"Expproc: createMonitorCmdsSub(): could not create Message Pipe\n" ); } pMonitor_CmdBufMngr = nddsBufMngrCreate(50,(sizeof(Monitor_Cmd) + CMD_MAX_STR_SIZE + 4)); /* set the callback routine to processMonitorCmd() and mark as direct this avoid the ssocket related setting which are not whated for the pipe set for the reading fd of the pipe */ DPRINT2(1,"---> pipe fd[0]: %d, fd[1]: %d\n",MonCmdPipe[0],MonCmdPipe[1]); /* zero out structure */ memset(pSubObj,0,sizeof(NDDS_OBJ)); memcpy(pSubObj,NDDS_Domain,sizeof(NDDS_OBJ)); strcpy(pSubObj->topicName,subName); /* fills in dataTypeName, TypeRegisterFunc, TypeAllocFunc, TypeSizeFunc */ getMonitor_CmdInfo(pSubObj); /* NDDS issue callback routine */ #ifndef RTI_NDDS_4x pSubObj->callBkRtn = Monitor_CmdCallback; pSubObj->callBkRtnParam = pMonitor_CmdBufMngr; /* MonCmdPipe; /* pCntlrThr->SubPipeFd; write end of pipe */ #endif /* RTI_NDDS_4x */ pSubObj->MulticastSubIP[0] = 0; /* use UNICAST */ #ifdef RTI_NDDS_4x initSubscription(pSubObj); attachOnDataAvailableCallback(pSubObj, Monitor_CmdCallback, pMonitor_CmdBufMngr); #endif /* RTI_NDDS_4x */ createSubscription(pSubObj); return(pSubObj); }
/* WARNING: it can only find symbol if name is a ptr returned by strsave */ struct symbol * lookup(char *name) { struct symbol *p = NULL; for (p = htab[hash(name)]; p != NULL; p = p->next) if (name == p->name) break; DPRINT2("lookup ('%s') => %p\n", name, p); return p; }
strtit() { long long duration; cntrlFifoStart(); cntrlFifoWait4Stop(); cntrlFifoCumulativeDurationGet(&duration); DPRINT2(-1,"testGate1dma: initial duration: %llu, %lf us \n",duration, (((double) duration) * .0125)); DPRINT1(-1,"testGate1dma: gate changes: %llu\n",duration / 800L ); }
/*------------------------------------------------------------------------- | | Setup the timer interval alarm | +--------------------------------------------------------------------------*/ int setRtimer(double timsec, double interval) { long sec,frac; struct itimerval timeval,oldtime; sec = (long) timsec; frac = (long) ( (timsec - (double)sec) * 1.0e6 ); /* usecs */ DPRINT2(3,"setRtimer(): sec = %ld, frac = %ld\n",sec,frac); timeval.it_value.tv_sec = sec; timeval.it_value.tv_usec = frac; sec = (long) interval; frac = (long) ( (interval - (double)sec) * 1.0e6 ); /* usecs */ DPRINT2(3,"setRtimer(): sec = %ld, frac = %ld\n",sec,frac); timeval.it_interval.tv_sec = sec; timeval.it_interval.tv_usec = frac; if (setitimer(ITIMER_REAL,&timeval,&oldtime) == -1) { perror("setitimer error"); return(-1); } return(0); }
int processExpSock() { int nfound; fd_set readfd; Socket *pAcceptSocket; void readAcceptSocket( Socket *pSocket ); int rngBlkIsEmpty (register RINGBLK_ID ringId); int sockInQ; /* Start by building a mask of possible active file descriptors */ /* while queue is not empty keep reading sockets */ /* while (rngBlkIsEmpty(pAcceptQueue) != Q_EMPTY) */ while ((sockInQ = rngBlkNElem(pAcceptQueue)) > 0 ) { DPRINT1(1,"Accepted Sockets in Queue: %d\n",sockInQ); rngBlkGet(pAcceptQueue, &pAcceptSocket, 1); DPRINT2(+3,"processExpSock: 0x%lx, fd: %d\n", pAcceptSocket,pAcceptSocket->sd); FD_ZERO( &readfd ); FD_SET( pAcceptSocket->sd, &readfd); DPRINT1(+3,"readfd mask: 0x%lx\n",readfd); /* who's got input ? */ try_again: if ( (nfound = select( pAcceptSocket->sd+1, &readfd, 0, 0, 0 ) ) < 0) { if (errno == EINTR) goto try_again; else errLogSysRet(ErrLogOp,debugInfo, "select Error:\n" ); } DPRINT1(+3,"select: readfd mask: 0x%lx\n",readfd); if (nfound < 1) /* Nobody */ { /*fprintf( stderr, "SIGIO received, but nothing active was found\n" );*/ free(pAcceptSocket); return(0); } if (FD_ISSET(pAcceptSocket->sd, &readfd) ) readAcceptSocket( pAcceptSocket ); free(pAcceptSocket); } return 0; }
int chkTaskActive(int task) { DPRINT2(1,"chkTaskActive %d: PID= %d\n",task,taskList[task].taskPid); if (taskList[task].taskPid != -1) { TheGrimReaper(NULL); } if (taskList[task].taskPid > 0) { if (kill(taskList[task].taskPid,0)) /* are you out there */ taskList[task].taskPid = (pid_t) -1; } return( (taskList[task].taskPid != -1) ); }
/* Has error-checking for malloc built in. */ char * emalloc(long nbytes) { char *s; s = (char *) malloc(nbytes); if (s == NULL) sys_error("system out of memory"); #ifndef NO_EMALLOC_DEBUG DPRINT2("emalloc: nbytes=%d, ptr=%p\n", nbytes, s); #endif return s; }