Esempio n. 1
0
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);
	}
     }
  }
}
Esempio n. 2
0
/*
 *   The tune decoder where the proper
 *   operation for this controller is performed.
 *
 *     Author:  Greg Brissey 12/20/04
 */
tuneDecode(TUNE_MSG *msge)
{
   int result,cmpltCode;
   char msgstr[COMM_MAX_STR_SIZE+2];

   cmpltCode = CNTLR_TUNE_ACTION_CMPLT;
   DPRINT3( 1,"tuneDecode: cmd: %d, channel: %d, atten: %d \n",msge->cmd,msge->channel,msge->arg2);
    switch(msge->cmd)
    {
       case CNTLR_CMD_TUNE_QUIET:
       {
            cntlrTuneQuiet(msge);
            send2Master(CNTLR_CMD_STATE_UPDATE,cmpltCode,0,0,NULL);
       }
       break;

       case CNTLR_CMD_TUNE_ENABLE:
       {
            cntlrTuneEnable(msge);
            send2Master(CNTLR_CMD_STATE_UPDATE,cmpltCode,0,0,NULL);
       }
       break;

       case CNTLR_CMD_TUNE_FINI:
       {
            DPRINT( 1," -- CNTLR_CMD_TUNE_FINI --\n");
            cntlrTuneQuiet(msge);
            send2Master(CNTLR_CMD_STATE_UPDATE,cmpltCode,0,0,NULL);
       }
       break;

       default:
          break;
    }
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
static int
updtapbus( ushort apreg, ushort apval )
{
	int	fifoIsEmpty, fifoIsRunning;

#ifdef FIFOBUFOBJ
	fifoIsEmpty = ( ( fifoEmpty( pTheFifoObject ) == 1 ) && 
		        ( fifoBufWkEntries(pTheFifoObject->pFifoWordBufs) == 0L ) );
#else
	fifoIsEmpty = fifoEmpty( pTheFifoObject );
#endif
	fifoIsRunning = fifoRunning( pTheFifoObject );

	if (fifoIsEmpty && fifoIsRunning) {
		errLogRet( LOGIT, debugInfo, "FIFO empty but running in update APBUS\n" );
		return( -1 );
	}

	if (fifoIsEmpty)
	  writeapwordStandAlone( apreg, apval, 50 );
	else
	  writeapword( apreg, apval, 50 );

    DPRINT3( DEBUG_APBUS, "updateapbus: fifo empty: %d, apregister: 0x%x, value: 0x%x\n",
                 fifoIsEmpty, apreg, apval );

	return( 0 );
} 
Esempio n. 5
0
/**************************************************************
*
* 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);
      }
     }

   }

}
Esempio n. 6
0
/**************************************************************
*
*  maxBufSize - determine the maximum system buffering that can be 
*  tolerated.  
*
*
* RETURNS:
* maxBufSIze  - if no error,
*
*/ 
static long maxBufSize(long fidSize,long totalFidBlks,unsigned long dspMemSize)
{
   long maxLimit;
   long maxFidBlksInSTM;
   long bytesPerStatBlk,  bytesPerMsgQ,  bytesPerRng; 
   long maxMallocSize, maxStructSize;

   /* - What is the maximum number of FID blocks that can  buffered */
   maxFidBlksInSTM = dspMemSize / fidSize;
   DPRINT3(-2,"maxBufSize: maxFidBlksInSTM = %ld, == %lu / %lu\n",maxFidBlksInSTM,dspMemSize,fidSize);

   /* 
      What is the maximum number of FID block stuctures 
      (i.e. FID_BLOCK_ARRAY, MSG_Qs, RINGXBLKs)
      that can be malloced with the self imposed malloc limit
      of the structures.
     Note: 1 MSG_Qs, 1 RINGs, 1 malloc buffer
   */

   maxStructSize = MAX_BUFFER_ALLOCATION / 
		   ( sizeof(FID_STAT_BLOCK) + sizeof(ITR_MSG) + sizeof(long));
  
   DPRINT1(-2,"maxBufSize:  maxStructSize: %ld\n",maxStructSize);

   /* --- who's the limiting size maxStructSize or maxFidBlksInSTM ? --- */
   maxLimit = (maxStructSize < maxFidBlksInSTM) ? maxStructSize : maxFidBlksInSTM;

   /* --- who's the limiting size maxLimit or totalFidBlks ? --- */
   return( (maxLimit < totalFidBlks) ? maxLimit : totalFidBlks );
}
Esempio n. 7
0
/*---------------------------------------------------------------------
| hardware_get  -  Set the appropriate event op for proper external
|		    syncing
|                       Author: Greg Brissey  11/14/88
+---------------------------------------------------------------------*/
hardware_get(Object dev_obj, ...)
{
   char		   msge[128];
   va_list         vargs;
   int             error = 0;
   Msg_Set_Param   param;
   Msg_Set_Result  result;

   va_start(vargs, dev_obj);
   if (dev_obj->dispatch == NULL)
   {
      abort_message("hardware_get: Uninitialized Device...\n");
   }

   /* Options allways follow the format 'Option,(value),Option,(value),etc' */
   while ((param.setwhat = va_arg(vargs, int)) != 0)
   {
      switch (param.setwhat)
      {
	 case GET_RTVALUE:
	    param.value = (c68int) va_arg(vargs, int);
	    DPRINT3(DPRTLEVEL,"hardware_get: Cmd: '%s' to %d, for device: '%s'\n",
		      ObjCmd(param.setwhat),param.value,dev_obj->objname);
	    error = Send(dev_obj, MSG_GET_EVENT_VAL_pr, &param, &result);
	    break;
	 default:
            sprintf(msge,"%s : Unknown Command '%s'.\n",
		dev_obj->objname,ObjCmd(param.setwhat));
            abort_message(msge);
	    break;
      }
   }
   va_end(vargs);
   return (error);
}
Esempio n. 8
0
/* shimType is QSPI_SHIMS, 14-channel shim box */
void qspiShimInterface(int *paramvec, int *index, int count, int fifoFlag)
{
int cs, dacNo, dacInPack, readValue;
int token1, token2;
long fWord[10];
   DPRINT1( -5,"qspiShims(): shimDelay = %d \n", shimDelay);
//   DPRINT2( 1,"index=%d, count=%d\n",*index, count);
   if (shimDelay < 1360) shimDelay = 1360;
   while (*index < count)
   { 
      (*index)++;     // skip over the SHIMDAC token
      token1 = paramvec[*index]; (*index)++;
      token2 = paramvec[*index]; (*index)++;
      DPRINT3(2,"token1=%d, token2=%d index=%d\n",token1,token2,*index);
      pCurrentStatBlock->AcqShimValues[token1] = token2;

      dacNo = qspi_dac_addr[ token1 ];
      if (dacNo == -1) continue;
      cs = (dacNo/4) + 3;		// which DAC package
      dacInPack = (dacNo % 4) << 14;	// which DAC in package

      if (token2 > 2047)
         token2 = 4095;
      else if (token2 < -2048)
         token2 = 0;
      else				// this 'else' is not right
         token2 += 2048;		// 0=-5 V, 2048=0V, 4095=+5V

      DPRINT3(2,"cs=%d dacInPack=%x  value = %d\n",cs,dacInPack,token2);
      readValue = (unsigned int)((cs<<24) | dacInPack | token2);
      DPRINT1(2,"outValue=%x\n",readValue);
      if (fifoFlag)
      {
         /* 17 usec/shim, this is hardcoded in psg's	   */
         /* MasterController::loadshim() 		   */
         /* if you change it here, change it there as well */
         /* 1280 is 16 usec, for 16 bits, 1usec to load    */
         fWord[0] = (DURATIONKEY | shimDelay);   
         // use port << 28, but port = 0 here
         fWord[1] = (LATCHKEY    | SPIKEY | readValue);
         writeCntrlFifoBuf(fWord,2); 
      }
      else
         readValue = hsspi(0, readValue );
      DPRINT1(2,"hsspi read: %x\n",readValue);
   }
}
Esempio n. 9
0
static int
setLockFreqAPfromBytes( ushort *apvals, int startfifo )
{

/*  Although the AP bus register values have been broken down
    into bytes at this point, this program receives them as ushort,
    because the high-order byte has been set to AP_LATCH4LOCK.	*/

	ushort	  apregs[ NUM_LKFREQ_APREGS ];
	int	  iter, tindex, tval;
	int	(*storevalue)();

	tindex = xcode2index( LKFREQ );
	if (tindex < 0) {
    		DPRINT(0, "error getting index to set lock frequency\n");
		return( -1 );
	}

	apregs[ 0 ] = index2apreg( tindex );
	for (iter = 1; iter < NUM_LKFREQ_APREGS; iter++)
	  apregs[ iter ] = apregs[ iter-1 ] + 1;

	DPRINT3( 1, "lock frequency AP registers: 0x%4x 0x%4x 0x%4x\n",
		      apregs[ 0 ], apregs[ 1 ], apregs[ 2 ] );
	DPRINT3( 1, "lock frequency AP values:    0x%4x 0x%4x 0x%4x\n",
		      apvals[ 0 ], apvals[ 1 ], apvals[ 2 ] );

        if (startfifo)
	  for (iter = 0; iter < NUM_LKFREQ_APREGS; iter++)
	    writeapwordStandAlone( apregs[ iter ], apvals[ iter ], AP_LOCKDELAY );
        else
	  for (iter = 0; iter < NUM_LKFREQ_APREGS; iter++)
	    writeapword( apregs[ iter ], apvals[ iter ], AP_LOCKDELAY );

	storevalue = index2valuestore( tindex );
	if (storevalue != NULL) {
		int	lockfreq_value;

		lockfreq_value = ( (apvals[ 0 ] & 0xff) |
				  ((apvals[ 1 ] & 0xff) << 8) |
				  ((apvals[ 2 ] & 0xff) << 16) );

		(*storevalue)( lockfreq_value );
	}

	return( 0 );
}
Esempio n. 10
0
/*
 * DDRs will call this so they can participate in the barrier
 *
 *                                      Author Greg Brissey  8/18/05
 *
 */
void initialDDRSyncComm()
{
    char pubtopic[128];
    DDRBarrierPubPatternSub((void *) NULL);
    sprintf(pubtopic,DDRBARRIER_PUB_COMM_TOPIC_FORMAT_STR,hostName);
    DPRINT3(-1,"format: '%s', cntrlL '%s', topic: '%s'\n",DDRBARRIER_PUB_COMM_TOPIC_FORMAT_STR,hostName,pubtopic);
    pUploadSyncPub = createDDRSyncCommPub(NDDS_Domain,pubtopic, hostName );
}
Esempio n. 11
0
int dataDataBufsAllFree(DATAOBJ_ID pStmId)
/* pStmId 	- stm Object Id */
{
   int used,ready;
   used = rngXBlkNElem(pStmId->pTagFreeList);
   ready = (used == pStmId->maxFidBlkBuffered) ? 1 : 0;
   DPRINT3(2,"stmBufsAllFree: used: %d, Exp total: %d, ready: %d\n",
	used,pStmId->maxFidBlkBuffered ,ready);
   return(ready);
}
Esempio n. 12
0
int assignReal(double d, varInfo *v, int i)
{   Rval *q;

    DPRINT3(3,"assignReal: 0x%08x[%d] <== %lf",v,i,d);
    if (v)
    {   if (v->T.basicType == T_STRING)
	{   WerrprintfWithPos("Can't assign REAL value to STRING variable");
#ifdef VNMRJ
	    jExpressionError();
#endif 
	    return(0);
	}
	else
	{   if (v->T.basicType == T_UNDEF)
	    {
		DPRINT0(3,", newly defined as REAL");
		v->T.basicType = T_REAL;
	    }
	    if (i)
	    {
		DPRINT1(3,", just to element %d\n",i);
		if (i <= v->T.size+1)
		{   if ((q=selectRval(v,i)) == NULL)
		       q = addNewRval(v);
		    q->v.r = d;
		    /* v->active = ACT_ON; */
		    return(1);
		}
		else
		{   WerrprintfWithPos("Assignment to non-existent element (=%d)",i);
#ifdef VNMRJ
		    jExpressionError();
#endif 
		    return(0);
		}
	    }
	    else
	    {
		DPRINT0(3,", to whole thing\n");
		disposeRealRvals(v->R);
		v->T.size = 0;
		v->R      = NULL;
		q         = addNewRval(v);
		q->v.r    = d;
		/* v->active = ACT_ON; */
	    }
	    return(1);
	}
    }
    else
    {
	DPRINT0(3,", NULL var ptr\n");
	return(0);
    }
}
Esempio n. 13
0
/*
 *   The NDDS callback routine, the routine is call when an issue of the subscribed topic
 *   is delivered.
 *   called with the context of the NDDS task n_rtu7400
 *
 *
 *                                      Author Greg Brissey  8/18/05
 *
 */
RTIBool DDRSync_CommCallback(const NDDSRecvInfo *issue, NDDSInstance *instance,
                             void *callBackRtnParam)
{
    Cntlr_Comm *recvIssue;
 
    if (issue->status == NDDS_FRESH_DATA)
    {
        recvIssue = (Cntlr_Comm *) instance;
        DPRINT6(+1," DDRSync_Comm CallBack:  nddsTopic: '%s', cmd: %d, arg1: %d, arg2: %d, arg3: %d, crc: 0x%lx\n",
        issue->nddsTopic,recvIssue->cmd,recvIssue->arg1, recvIssue->arg2, recvIssue->arg3, recvIssue->crc32chksum);
        /* (*callbackFunc)(recvIssue); */
        switch(recvIssue->cmd)
        {
          case CNTLR_CMD_DDR_AT_BARRIER:
                numAtBarrier++;
                DPRINT3(-1," '%s: SyncBarrierParser:  numAtBarrier: %d , numActiveDDRs: %d\n",recvIssue->cntlrId,numAtBarrier,numActiveDDRs);
                if (numAtBarrier >= numActiveDDRs)
                {
                   numAtBarrier = 0;
                   DPRINT1(-1," '%s': SyncBarrierParser:  give Semaphore\n",recvIssue->cntlrId);
                   semGive(pBarrierWaitSem);
                }
                break;

           case CNTLR_CMD_SET_NUM_ACTIVE_DDRS:
                numActiveDDRs = recvIssue->errorcode;
                numAtBarrier = 0;
                uploadSyncCntDown = uploadSyncCount;
                while (semTake(pBarrierWaitSem,NO_WAIT) != ERROR);
                DPRINT3(-1,"'%s': SyncBarrierParser: setActive ddrs to: %d, clear numAtBarrier: %d\n",
                     recvIssue->cntlrId,numActiveDDRs,numAtBarrier);
                break;

           case CNTLR_CMD_SET_UPLINK_CNTDWN:
                uploadSyncCntDown = uploadSyncCount = recvIssue->errorcode;;
                DPRINT2(-1,"'%s': SyncBarrierParser: set uploadSyncCount to: %d\n", recvIssue->cntlrId,uploadSyncCount);
                break;
        }

    }
   return RTI_TRUE;
}
Esempio n. 14
0
/*
 * The Barrier involved nodes via NDDS uses this callback function to create Subscriptions to the
 * DDRs/Master *
 *
 *                                      Author Greg Brissey  8/18/05
 *
 */
NDDSSubscription DDRBarrier_CmdPatternSubCreate( const char *nddsTopic, const char *nddsType, 
                  void *callBackRtnParam) 
{ 
     NDDSSubscription pSub;
     DPRINT3(-1,"DDRBarrier_CmdPatternSubCreate(): Topic: '%s', Type: '%s', arg: 0x%lx\n",
		nddsTopic, nddsType, callBackRtnParam);
     pUploadSyncSub[numSubs] =  createDDRSyncCommSub(NDDS_Domain, (char*) nddsTopic, 
			DDRSYNC_COMM_MULTICAST_IP, (void *) callBackRtnParam );
     pSub = pUploadSyncSub[numSubs++]->subscription;
     return pSub;
}
Esempio n. 15
0
/*
 * The Master via NDDS uses this callback function to create Subscriptions to the
 * FIdCT_StatusBlock BE Publications aimed at the MAster for updating the Stat block
 *
 *					Author Greg Brissey 10-26-04
 */
NDDSSubscription FidCt_StatPatternSubCreate( const char *nddsTopic, const char *nddsType, 
                  void *callBackRtnParam) 
{ 
     NDDSSubscription pSub;
     NDDS_ID pNddsSub;
     DPRINT3(-1,"FidCT_StatPatternSubCreate(): Topic: '%s', Type: '%s', arg: 0x%lx\n",
		nddsTopic, nddsType, callBackRtnParam);
     pNddsSub = createMasterFidSub((char*) nddsTopic );
     pSub = pNddsSub->subscription;
     return pSub;
}
Esempio n. 16
0
/*
 * 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;
}
Esempio n. 17
0
int assignEString(char *s, varInfo *v, int i)
{   Rval *q;

    DPRINT3(3,"assignEString: 0x%08x[%d] <== \"%s\"",v,i,s);
    if (v)
    {   if (v->ET.basicType == T_REAL)
	{   WerrprintfWithPos("Can't assign STRING value to REAL variable");
#ifdef VNMRJ
	    jExpressionError();
#endif 
	    return(0);
	}
	else
	{   if (v->ET.basicType == T_UNDEF)
	    {
		DPRINT0(3,", newly defined as STRING");
		v->ET.basicType = T_STRING;
	    }
	    if (i)
	    {
		DPRINT1(3,", just to element %d\n",i);
		if (i <= v->ET.size+1)
		{   if ((q=selectERval(v,i)) == NULL)
		       q = addNewERval(v);
		    else
		       release(q->v.s);
		    q->v.s = newString(s);
		    return(1);
		}
		else
		{   WerrprintfWithPos("Can't assign to non-existent element (%d)\n",i);
#ifdef VNMRJ
		    jExpressionError();
#endif 
		    return(0);
		}
	    }
	    else
	    {
		DPRINT0(3,", to whole thing\n");
		disposeStringRvals(v->E);
		v->ET.size = 0;
		v->E      = NULL;
		q         = addNewERval(v);
		q->v.s    = newString(s);
	    }
	    return(1);
	}
    }
    else
	return(0);
}
Esempio n. 18
0
/**************************************************************
*
* hashPut - put entry into a hash table 
*
*
*  This routine places an entry into the hash table based on the
*  key.
*
* RETURNS:
*  OK, ERROR .
*
*	Author Greg Brissey 8/5/93
*/
int hashPut (HASH_ID hashid, char* key, char* refaddr)
/* HASH_ID    hashid;	hash table to put entry into */
/* char*      key;   	the key to base the index in table */
/* char*      refaddr;  reference address of info hashed */
{
   long index;
   register HASH_ENTRY *hashlist;

   index = (*hashid->pHashFunc)((char *) key, hashid->maxEntries);
   if (index < 0 || index > hashid->maxEntries)
   {
      errLogRet(ErrLogOp,debugInfo,"hashPut: computed index out-of-bounds: %ld\n",index);
      return(ERROR);
   }
   hashlist = hashid->pHashEntries;

   while (hashlist[index].hashKey)     /* look for next free slot */
   {
      hashid->collisions++;
         DPRINT3(4,"hash:collision with 0x%lx  and 0x%lx , total: %ld\n",
                key, hashlist[index].hashKey, hashid->collisions);
      ++index;   /* increment key */
      index %= hashid->maxEntries;
   }

   hashlist[index].hashKey = key;
   hashlist[index].refAddr = refaddr;

   if ( ++(hashid->numEntries) > hashid->maxEntries)
   {
      errLogRet(ErrLogOp,debugInfo,"hash: ERROR Number of identifiers exceeds hash table\n");
   }

   DPRINT3(4,"hash: table[%ld] -  key 0x%lx, refadr: 0x%lx \n", index, 
	 hashlist[index].hashKey,hashlist[index].refAddr);

   return( OK );
}
Esempio n. 19
0
static int
updtLockphase( ushort apval )
{
	int	fifoIsEmpty, fifoIsRunning;
	int	tmp1,tmp2;

	fifoIsEmpty = ( ( fifoEmpty( pTheFifoObject ) == 1 ) && 
		        ( fifoBufWkEntries(pTheFifoObject->pFifoWordBufs) == 0L ) );
	fifoIsRunning = fifoRunning( pTheFifoObject );

	if (fifoIsEmpty && fifoIsRunning) {
		errLogRet( LOGIT, debugInfo, "FIFO empty but running in update APBUS\n" );
		return( -1 );
	}

	if (fifoIsEmpty)
           init_fifo( NULL, 0, 0 );

        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_SLCT, 0x0A30); /* lk xmtr */
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_WRT,  0x0A17); /* PIRB2 24-31*/
        tmp1 = (int)(- (currentStatBlock.stb.AcqLockPhase * 32.0 / 45.0))&0xFF;
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_INCWR,0x0A00|tmp1);/* zeroing */
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_SLCT, 0x0A30); /* lk xmtr */
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_WRT,  0x0A18); /* SMC2 */
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_INCWR,0x0A08);
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_SLCT, 0x0A30); /* lk xmtr */
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_WRT,  0x0A1E); /* HOP CLK2 */
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_INCWR,0x0A00); /* strobe*/
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_SLCT, 0x0A30); /* lk xmtr */
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_WRT,  0x0A17); /* PIRB2 24-31*/
        tmp2 = (int)(apval * 32.0 / 45.0)&0xFF;
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_INCWR,0x0A00|tmp2);
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_SLCT, 0x0A30); /* lk xmtr */
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_WRT,  0x0A1E); /* HOP CLK2*/
        fifoStuffCmd(pTheFifoObject,CL_AP_BUS_INCWR,0x0A00); /* strobe */

	if (fifoIsEmpty)
        {  fifoStuffCmd(pTheFifoObject,HALTOP,0);
           fifoStart( pTheFifoObject );
           fifoWait4Stop( pTheFifoObject );
        }

    DPRINT3( DEBUG_APBUS, "updtLockphase: fifo empty: %d, value: %d [0x%x]\n",
                 fifoIsEmpty, apval, apval );
	currentStatBlock.stb.AcqLockPhase = apval;

	return( 0 );
}
Esempio n. 20
0
/*
 * set the controller into the quiet mode for tune
 * action depends on type of controller (BrdType)
 *
 *     Author:  Frits Vosman 12/27/04
 */
cntlrTuneEnable(TUNE_MSG *msge)
{
   int activeChannel;
   activeChannel = msge->channel - 1;
   DPRINT1( 1," -- CNTLR_CMD_TUNE_ENABLE --  chan: %d\n",activeChannel);
   switch(BrdType)
   {
      case MASTER_BRD_TYPE_ID:
         DPRINT(1,"cntlrTuneEnable: Master, should not get here");
         break;
      case RF_BRD_TYPE_ID:
         if (BrdNum ==  activeChannel)
         {
            DPRINT3(-1,"cntlrTuneEnable: RF chan=%d, activate=%d, yes, attn=%d",
                                              BrdNum, activeChannel,msge->arg2);
            /* TuneON(frequency,power); */
            /* TuneON(msge->arg2*5); */
            execFunc("TuneON",(void*)(msge->arg2*5), NULL, NULL, NULL, NULL, NULL,NULL,NULL);
         }
         else
         {
            DPRINT2(1,"cntlrTuneEnable: RF chan=%d, activate=%d, no",
                                              BrdNum, activeChannel);
         }
         break;
      case LPFG_BRD_TYPE_ID:
      case PFG_BRD_TYPE_ID:
         DPRINT(1,"cntlrTuneEnable: PFG ignores");
         break;
      case GRAD_BRD_TYPE_ID:
         DPRINT(1,"cntlrTuneEnable: Grad ignores");
         break;
      case LOCK_BRD_TYPE_ID:
         DPRINT(1,"cntlrTuneEnable: Lock ignores");
         break;
      case DDR_BRD_TYPE_ID:
         *pDDR_FIFOOutputSelect = 0;
         *pDDR_SoftwareGates |= 0x8;
         DPRINT(1,"cntlrTuneEnable: DDR RG Off");
         break;
      default:
         DPRINT(-1,"cntlrTuneEnable: Unknown cntlr, ignored");
         break;
   }
}
Esempio n. 21
0
/************************************************
*
*  fFidSeek - Set offsetAddr to the beginning of the
*	      blockheader for the requested FID.
*
*  md         - pointer to the file information.
*  fidNum     - requested FID number
*  headerSize - size, in bytes of the FID file header.
*               will be sizeof(struct datafilehead)
*  bbytes     - size, in bytes, of a FID and its block
*               header.
*
*  RETURNS:
*  0 for success, -1 for failure.
*/
long long fFidSeek(FILE_ID md, int fidNum, int headerSize, unsigned long bbytes)
{
    uint64_t fidoffset;
 
    if (fidNum < 1L)
    {
      errLogRet(ErrLogOp,debugInfo, "mFidSeek: Fid number < 1.\n");
      return(-1);
    }
    fidoffset = headerSize + ((uint64_t) bbytes * ((uint64_t) (fidNum - 1L)));

    md->offsetAddr = fidoffset;

    DPRINT3(2,"fFidSeek(): fid# = %lu, offset = %llu, 0x%llx\n",
		fidNum, fidoffset, fidoffset);

    return(fidoffset);
}
Esempio n. 22
0
/*************************************************************
*
*  probHandler - Wait for Messages that indecate some problem
*    with the system. Then perform appropriate recovery.
*
*					Author Greg Brissey 12-7-94
*/
pHandler(MSG_Q_ID msges)
{
   EXCEPTION_MSGE msge;
   int *val;
   int bytes;
   void recovery(EXCEPTION_MSGE *);

   DPRINT(1,"pHandler :Server LOOP Ready & Waiting.\n");
   FOREVER
   {
     markReady(PHANDLER_FLAGBIT);
     memset( &msge, 0, sizeof( EXCEPTION_MSGE ) );
     bytes = msgQReceive(pMsgesToPHandlr, (char*) &msge, 
			  sizeof( EXCEPTION_MSGE ), WAIT_FOREVER);
     markBusy(PHANDLER_FLAGBIT);
     DPRINT3(1,"pHandler: recv: %d bytes, Exception Type: %d, Event: %d \n",
			bytes, msge.exceptionType, msge.reportEvent);

      
     recovery( &msge );
   } 
}
Esempio n. 23
0
int assignPair(pair *p, varInfo *v, int i)
{   Rval *r;

    DPRINT3(3,"assignPair: pair 0x%08x to var 0x%08x[%d]...\n",p,v,i);
    DSHOWPAIR(3,"assignPair: ",p);
    DSHOWVAR(3,"assignPair: ",v);
    if (v)
    {	switch (p->T.basicType)
	{ case T_UNDEF:     return(0);
	  case T_REAL:	    r = p->R;
		            if (v->prot & P_ARR)
		            { if ((r = r->next) || (i > 1))
		              {
				 WerrprintfWithPos("cannot array parameter");
				 return(0);
		              }
			      r = p->R;
		            }
			    while (r)
			    {
			    	if (assignReal(r->v.r,v,i))
				{   r  = r->next;
				    if (i == 0)
					i++; /* bump index to 2 */
				    i += 1;
				}
				else
				{
				    return(0);
				}
			    }
			    DPRINT0(3,"assignPair: ...after\n");
			    DSHOWVAR(3,"assignPair: ",v);
			    return(1);
	  case T_STRING:    r = p->R;
		            if (v->prot & P_ARR)
		            { if ((r = r->next) || (i > 1))
		              {
				 WerrprintfWithPos("cannot array parameter");
				 return(0);
		              }
			      r = p->R;
			    }
			    while (r)
			    	if (assignString(r->v.s,v,i))
				{   r  = r->next;
				    if (i == 0)
					i++; /* bump index to 2 */
				    i += 1;
				}
				else
				    return(0);
			    DPRINT0(3,"assignPair: ...after\n");
			    DSHOWVAR(3,"assignPair: ",v);
			    return(1);
	  default:	    WerrprintfWithPos("unknown parameter assignment with basictype %d",p->T.basicType);
			    return(0);

	}
    }
    return(0);
}
Esempio n. 24
0
int
setLockDecPower( int apaddr, int lkdecpower, int apdelay, int startfifo )
{
   ushort  lkpreampregvalue, lockapreg, apvalue;

   DPRINT2( 1, "setLockDecPower power = %d, equiv. lk power: %d\n", lkdecpower,lkdecpower-15 );


   lkdecpower -= 15;	/* 63 - 15 = 48 i.e. max atten of lock/dec */

   if (lkdecpower <= 0) 
   {
         lkdecpower = 0;
   }
   else if (lkdecpower > 48) 
   {
         lkdecpower = 48;
   }

   apvalue = cvtLkDbLinear( lkdecpower );
   DPRINT3(1, "setLockDecPower: lock/dec power, AP register: 0x%x, AP value: %d, 0x%x\n", 
		   apaddr, apvalue, apvalue );
   if (startfifo)
      writeapwordStandAlone( apaddr, (apvalue & 0xff) | AP_LATCH4LOCK, apdelay );
   else
      writeapword( apaddr, (apvalue & 0xff) | AP_LATCH4LOCK, apdelay );
   DPRINT3(1,"setLockDecPower: apadr: 0x%x,   val: 0x%x, delay: %d\n",
	   apaddr,(apvalue & 0xff) | AP_LATCH4LOCK,apdelay);


#ifdef XXXX
   if (startfifo > 1)   /* just store the values for future setting */
   {
	lkdecPwrAddr = apaddr;
	lkdecPwr = lkdecpower;
	lkdecApDelay = apdelay; 
   }
   else
   {
     apaddr = lkdecPwrAddr;
     lkdecpower = lkdecPwr;
     apdelay = lkdecApDelay; 

      if ((lkdecPwrAddr == 0) || (lkdecApDelay == 0))
      {
	DPRINT(-1,"setLockDecPower: Can't set Dec. Power, Values are not Initialized\n");
	return(-1);
      }

      lkdecpower -= 15;	/* 63 - 15 = 48 i.e. max atten of lock/dec */

      if (lkdecpower <= 0) 
      {
         lkdecpower = 0;
      }
      else if (lkdecpower > 48) 
      {
         lkdecpower = 48;
      }

      apvalue = cvtLkDbLinear( lkdecpower );
      DPRINT2(0, "setLockDecPower: lock/dec power, AP register: 0x%x, AP value: 0x%x\n", 
		   apaddr, apvalue );
      if (startfifo)
         writeapwordStandAlone( apaddr, (apvalue & 0xff) | AP_LATCH4LOCK, apdelay );
      else
         writeapword( apaddr, (apvalue & 0xff) | AP_LATCH4LOCK, apdelay );
      DPRINT3(0,"setLockDecPower: apadr: 0x%x,   val: 0x%x, delay: %d\n",
	   apaddr,(apvalue & 0xff) | AP_LATCH4LOCK,apdelay);
   }
#endif
   return(0);
}
Esempio n. 25
0
/*****************************************************************************
 * rack file
 *
 * rack_type rack_pathname injector_port/rack_index X-center Y-center Z-bottom
 *
 * e.g.:
 *  injector /vnmr/asm/racks/m215_inj.grk 1 Center X, Center Y (5576 38)
 *  rack /vnmr/asm/racks/code_205.grk  1 546 1872
 *  rack /vnmr/asm/racks/code_201.grk  2 546+(1*1196) 1872
 *  rack /vnmr/asm/racks/code_204.grk  3 546+(2*1196) 1872
 *  rack /vnmr/asm/racks/code_202.grk  4 546+(3*1196) 1872
 *  rack /vnmr/asm/racks/code_209.grk  5 546+(4*1196) 1872
 *
 ****************************************************************************/
int readRacks(char *rackpath)
{
    FILE *stream;
    struct stat s;
    char eolch;
    char textline[256],buffer[256],path[256];
    char *rackstype,*racktype,*filepath,*port_rack,*X,*Y,*Z;
    char *rackIdStr,*chrptr;
    int status,line,j,t,typefound,len;
    int portnum, xcenter, ycenter, bot;
    int xAxis,yAxis;
    int rackType,rackIndex;
    int sampType,sampIndex;
    int numSRacks;
    

    j=0;
    line = 0;
    numSRacks = 0;

    stat(rackpath, &s);
    DPRINT3(1,"'%s': MDate: %ld, File: %ld \n",rackpath,MDate,s.st_mtime);
    if (s.st_mtime <= MDate) {
        DPRINT(1,"File has not changed.\n");
        return(0);
    }
    DPRINT(1,"File has Changed.\n");

    stream = fopen(rackpath,"r");

    /* does file exist? */
    if (stream == NULL) {
        errLogSysRet(LOGOPT,debugInfo,
           "initRacks: setup file '%s' could not be opened.", rackpath);
        return(ERROR);
    }
 
    while ( ( chrptr = fgets(textline, 256, stream) )  != NULL) {

        /* note: the CR is included in textline */
        j++;

        if ( (len = strlen(textline)) < 15)
            continue;

        if (textline[0] == '#')  /* # then it's a comment */
            continue;

        /* extract the string tokens, Prompt and Text */
        rackstype = (char*) strtok(textline," \n");
        if ( rackstype == NULL )
            continue;

        racktype = (char*) strtok(NULL," \n");
        if ( racktype == NULL )
            continue;

        filepath = (char*) strtok(NULL," \n");
        if ( filepath == NULL )
            continue;

        DPRINT4(1,"\n\n Nracks: %d, Rack: '%s', Type: '%s', filepath: '%s'\n",
                g215Bed.NumRacks,rackstype,racktype,filepath);

        X = (char*) strtok(NULL," \n");
        Y = (char*) strtok(NULL," \n");
        Z = (char*) strtok(NULL," \n");
        port_rack = (char*) strtok(NULL," \n");

        rackType = atoi(racktype);
        if ((rackType < 0) || (rackType > 37)) {
            errLogRet(LOGOPT, debugInfo, "initRacks: Rack Type of "
                                         "Range(0-37): %d \n", rackType);
            fclose(stream);
            return(ERROR);
        }

        strcpy(buffer, filepath);
        rackIdStr = strtok(buffer,"_");
        /* DPRINT1(1,"Id prefix: '%s'\n",rackIdStr); */
        rackIdStr = strtok(NULL,".");
        /* DPRINT1(1,"Id string: '%s'\n",rackIdStr); */
   
        for (typefound=rackIndex=0; rackIndex<g215Bed.NumRacks; rackIndex++) {

            DPRINT4(1,"Index: %d, Type: %d, Defined Type: %d, '%s'\n",
                    rackIndex, rackType, g215Bed.DefinedRacks[rackIndex].type,
                    g215Bed.DefinedRacks[rackIndex].IdStr);

            if (g215Bed.DefinedRacks[rackIndex].type == rackType) {
                typefound = 1;
                break;
            }
        } 

        /* Centers depths etc. for Injector or rack */
        if (rackType == 0)  /* Injector */ {

            portnum = atoi(port_rack);
            xcenter = atoi(X);
            ycenter = atoi(Y);
            bot = atoi(Z);

            DPRINT4(1,"Port: %d, center: X=%d, Y=%d, Bottom: %d\n",
                    portnum, xcenter, ycenter, bot);

            g215Bed.InjectorCenter[0] = xcenter; /* Center of Injector */
            g215Bed.InjectorCenter[1] = ycenter; /* Center of Injector */
            g215Bed.InjectorBot = bot;           /* Bottom of Injector */

            if (typefound) {
                rackCenter(g215Bed.DefinedRacks[rackIndex].pRackObj,
                           xcenter, ycenter); /* 5565 */
                xAxis = rackGetX(g215Bed.DefinedRacks[rackIndex].pRackObj,
                                 1, portnum);
                yAxis = rackGetY(g215Bed.DefinedRacks[rackIndex].pRackObj,
                                 1, portnum);
                DPRINT3(1,"Inject Loc: X=%d, Y=%d, Bottom: %d\n",
                        xAxis,yAxis,bot);

                gilInitInjLoc(pGilObjId,xAxis, yAxis, bot);
            }
        }
        else {
            numSRacks++;

            if ( X != NULL )
                xcenter = atoi(X);
            else
                xcenter = -1;
   
            if ( Y != NULL )
                ycenter = atoi(Y);
            else
                ycenter = -1;

            DPRINT4(1,"NumRacksRead: %d, rackIndex: %d, Center: X=%d, Y=%d\n",
                    numSRacks, rackIndex, xcenter, ycenter);

            if ((xcenter != -1) && (ycenter != -1)) {
                g215Bed.Rack1Center[0] = xcenter; /* Center of Well */
                g215Bed.Rack1Center[1] = ycenter; /* Center of Well */
            }
        }

        if (typefound != 1) {
            /* rack IdStr e.g. 205, 205h, adpt2, etc. */
            strncpy(g215Bed.DefinedRacks[g215Bed.NumRacks].IdStr,
                    rackIdStr, 80);
            g215Bed.DefinedRacks[g215Bed.NumRacks].type = rackType;

            DPRINT4(1, "Adding racktype: '%s', Idstr: '%s', type: %d, "
                       "path: '%s'\n", rackstype, 
                    g215Bed.DefinedRacks[g215Bed.NumRacks].IdStr, 
                    g215Bed.DefinedRacks[g215Bed.NumRacks].type, filepath);

            DPRINT1(1,"rack definition file: '%s'\n", filepath);
         
            if ( (g215Bed.DefinedRacks[g215Bed.NumRacks].pRackObj =
                  rackCreate(filepath)) == NULL) {

                DPRINT1(1, "initRacks: Unable to Initialize Rack: '%s'\n",
                          filepath);
                fclose(stream);
                return(-1);
            }

            if (rackType == 0)  /* Injector */ {

                rackCenter(g215Bed.DefinedRacks[g215Bed.NumRacks].pRackObj,
                           xcenter, ycenter);
                xAxis = rackGetX(
                            g215Bed.DefinedRacks[g215Bed.NumRacks].pRackObj,
                            1, portnum);
                yAxis = rackGetY(
                            g215Bed.DefinedRacks[g215Bed.NumRacks].pRackObj,
                            1, portnum);
                DPRINT3(1,"Inject Loc: X=%d, Y=%d, Bottom: %d\n",
                        xAxis, yAxis, bot);

                gilInitInjLoc(pGilObjId, xAxis, yAxis, bot);
            }

            g215Bed.NumRacks++;
        }
    }

    fclose(stream);
    /* gilShow(0); */
    MDate = s.st_mtime;

    /*------------ HERMES - READ RACK DELTAS FROM CONFIG FILE -------------*/
    sprintf(path, "%s/asm/info/liqhandlerInfo", systemdir);
    stream = fopen(path, "r");
    if (stream != NULL) {
        int x1,y1,x2,y2,x3,y3,x4,y4;
        if ((fscanf(stream, "%[^\n]\n", textline) != 1) ||
            (fscanf(stream, "X1Delta:  %d\r\n", &x1) != 1) ||
            (fscanf(stream, "Y1Delta:  %d\r\n", &y1) != 1) ||
            (fscanf(stream, "X2Delta:  %d\r\n", &x2) != 1) ||
            (fscanf(stream, "Y2Delta:  %d\r\n", &y2) != 1) ||
            (fscanf(stream, "X3Delta:  %d\r\n", &x3) != 1) ||
            (fscanf(stream, "Y3Delta:  %d\r\n", &y3) != 1) ||
            (fscanf(stream, "X4Delta:  %d\r\n", &x4) != 1) ||
            (fscanf(stream, "Y4Delta:  %d\r\n", &y4) != 1)) {
            DPRINT3(0, "\r\nError reading 768AS liquid handler "
                    "setup file %s %d %s\r\n", path, errno,
                    strerror(errno));
        }
        else {
            rackDelta[0][0] = x1; rackDelta[0][1] = y1;
            rackDelta[1][0] = x2; rackDelta[1][1] = y2;
            rackDelta[2][0] = x3; rackDelta[2][1] = y3;
            rackDelta[3][0] = x4; rackDelta[3][1] = y4;
        }

        fclose(stream);
    }

    return (0);
}
Esempio n. 26
0
/*
 * The thread start routine for crew threads. Waits in the rngBlkGet()
 * call  where address of workQEntries are received, then processes work items until requested to shut down.
 *
 * For none active Receivers/DDRs their cmd will set to -1 , thus they will
 *  pend immediately.
 *
 *     Author:  Greg Brissey
 */
void *worker_routine (void *arg)
{
   int status;
   WORKQ_ENTRY_ID  pWrkQentry;
   RCVR_DESC_ID pRcvrDesc;
   WORKQINVARIENT_ID pWrkqInvar;
   int inQueue;
   int processThreadFlag;
   char *CntlrId;

   RCVR_DESC_ID pAccessWrkDesc = (RCVR_DESC_ID) arg; 
   if (pAccessWrkDesc == &ProcessThread)
      processThreadFlag = 1;
   else
      processThreadFlag = 0;

   CntlrId = pAccessWrkDesc->cntlrId;
   DPRINT3(+2,"'%s':  threadId: 0x%lx, RCVR_DESC_ID: 0x%lx,  starting\n", 
         CntlrId,pAccessWrkDesc->threadID,pAccessWrkDesc);

    pThreadBlockAllSigs();   /* block most signals here */

    pthread_detach(pAccessWrkDesc->threadID);   /* if thread terminates no need to join it to recover resources */

    while (1) {

	/* obtain work from the pipe line Q, if non the thread blocks */
        rngBlkGet(pAccessWrkDesc->pInputQ, &pWrkQentry,1);

        if (!processThreadFlag)
           incrActiveCntlrStatus(CntlrId);
             
        pRcvrDesc = (RCVR_DESC_ID) pWrkQentry->pInvar->pRcvrDesc;


        DPRINT2(+2,"'%s': Got workQ: 0x%lx\n", pRcvrDesc->cntlrId, pWrkQentry);
        inQueue = rngBlkNElem(pRcvrDesc->pInputQ);
        DPRINT2(+2,"'%s': work still in Q: %d\n", pRcvrDesc->cntlrId, inQueue);

#define INSTRUMENT
#ifdef INSTRUMENT
        if (inQueue >  pRcvrDesc->p4Diagnostics->pipeHighWaterMark)
             pRcvrDesc->p4Diagnostics->pipeHighWaterMark = inQueue;
#endif

        DPRINT2(+2,"'%s': Got workQ: 0x%lx\n", pAccessWrkDesc->cntlrId, pAccessWrkDesc);
        DPRINT2(+2,"'%s': work still in Q: %d\n", pAccessWrkDesc->cntlrId, rngBlkNElem(pAccessWrkDesc->pInputQ));

        status = (pAccessWrkDesc->pCallbackFunc)(pWrkQentry);

        /* if status is not < 0 then send workQ on to next stage
         * if status < 0 then there is an error or the function call already
         * handled the passing to the next stage and this routine does not need to
         */
        DPRINT2(+2,"'%s': CallBack Returned: %d\n", pRcvrDesc->cntlrId, status);
        if (status  >= 0)
        {
           DPRINT2(+2,"'%s': Done,  Send WorkQ onto Processing Thread: 0x%lx\n", 
		pRcvrDesc->cntlrId, pRcvrDesc);
           rngBlkPut(pAccessWrkDesc->pOutputQ, &pWrkQentry,1);
        }
        if (!processThreadFlag)
           decActiveCntlrStatus(CntlrId);
    }
}
Esempio n. 27
0
/*------------------------------------------------------------------------
|
|       BeginProcessing()/1
|       Fork & Exec a child for BackGround vnmr processing
|       Send commands to Vnmr for ForeGround processing
|
|                               Author Greg Brissey 9/7/94
|
+-----------------------------------------------------------------------*/
void BeginProcessing(ExpInfoEntry* pProcExpInfo, int proctype, long fid, long ct,
                     int dCode, int eCode)
{
    char cmdstring[1024];
    char procmsge[1024];
    char msgestring[1024];
    int process2do;
    MSG_Q_ID pAutoMsgQ;

    /* we no longer pass the actual command string to Vnmr but just it's
       type, and Vnmr will read it's procpar to get the command string 
       This means for Wexp, Wnt & Wexp will need tobe concatenated
    */
    process2do =  pProcExpInfo->ExpInfo->ProcMask;
    DPRINT3(1,"BeginProcessing(): type = %d dcode: %d ecode: %d \n",
               proctype,dCode,eCode);
    switch(proctype)
    {
       case WEXP_WAIT:
       case WEXP:
	    if (pProcExpInfo->ExpInfo->GoFlag != EXEC_GO)
            {
	       process2do &= WHEN_SU_PROC;
               eCode = pProcExpInfo->ExpInfo->GoFlag;  /* type of su done */
            }
	    else
            {
	       process2do &= WHEN_GA_PROC | WHEN_EXP_PROC | WHEN_NT_PROC;
            }
	break;
       case WERR:
               if (dCode == EXP_STARTED)
	          process2do = 0;
               else
	          process2do &= WHEN_ERR_PROC;
	break;
       case WFID:
	       process2do &= (WHEN_NT_PROC | WHEN_GA_PROC);
	break;
       case WBS:
	       process2do &= WHEN_BS_PROC;
	break;
       default:
	       process2do = 0;	/* don't do any */
	break;
    }

    if (++FGkey > 1024)
	FGkey = 1L;
    DPRINT2(1,"BeginProcessing(): flags: automode= %d vpmode= %d\n",
               pProcExpInfo->ExpInfo->ExpFlags & AUTOMODE_BIT,pProcExpInfo->ExpInfo->ExpFlags & VPMODE_BIT);
/*
    sprintf(msgestring,"acqcp('exp%d','%s',%d,%d,%d,%d,%lu,%lu,%lu)\n",
			pProcExpInfo->ExpInfo->ExpNum,
			pProcExpInfo->ExpId,0,0,process2do,(int)FGkey, fid, ct);
 */
    if ( (pProcExpInfo->ExpInfo->ExpFlags & VPMODE_BIT) &&
         (pProcExpInfo->ExpInfo->ExpFlags & AUTOMODE_BIT) )
       sprintf(msgestring,"acqsend(5,'%d',0,%d,'vpa',%d,%d,%lu,%lu,'%s')\n",
                        (int)FGkey, process2do,dCode,eCode, fid, ct,
                        pProcExpInfo->ExpInfo->DataFile);
    else if (pProcExpInfo->ExpInfo->ExpFlags & VPMODE_BIT)
       sprintf(msgestring,"acqsend(5,'%d',0,%d,'vp',%d,%d,%lu,%lu,'%s')\n",
                        (int)FGkey, process2do,dCode,eCode, fid, ct,
                        pProcExpInfo->ExpInfo->DataFile);
    else
       sprintf(msgestring,"acqsend(5,'%d',%d,%d,'exp%d',%d,%d,%lu,%lu)\n",
                        (int)FGkey,pProcExpInfo->ExpInfo->ExpNum,
			process2do,pProcExpInfo->ExpInfo->ExpNum,dCode,eCode, fid, ct);
    /* ---  If FG Vnmr is in Process Exp#  & Wexp Not Processing in FG, --- */
    /*       And not in automation mode                             */
    /* ---  Then do FG processing else do it in BG                      --- */
    /*  FG is Never done for automation Experiments!  */

    if ( (strlen(pProcExpInfo->ExpInfo->MachineID) > (size_t) 1) &&
	  (verifyInterface( pProcExpInfo->ExpInfo->MachineID )) &&
         ( !(pProcExpInfo->ExpInfo->ExpFlags & AUTOMODE_BIT) ||
            ( ((pProcExpInfo->ExpInfo->ExpFlags & VPMODE_BIT) && (pProcExpInfo->ExpInfo->ExpFlags & AUTOMODE_BIT)) ) ) )
    {
 
         /* acqcp('exp#','ExpInfo',donecode,errorcode,WprocType,fid,ct) */

         DPRINT(1,"Send Vnmr(MachineId): acqsend(5,FGkey,Exp#,Process2Do,'exp#',dcode,ecode,fid,ct)\n");
         DPRINT2(1,"Send Vnmr(%s): '%s'\n",
         		pProcExpInfo->ExpInfo->MachineID,
         		msgestring);
         deliverMessage( pProcExpInfo->ExpInfo->MachineID, msgestring );

         DPRINT(1,"BeginProcessing: FG calling activeQadd\n");
	 activeQadd(pProcExpInfo->ExpId, proctype, fid, ct, FG, (int) FGkey, dCode, eCode );
	 procQdelete(proctype, 1);

    }
    else	/* ----- process in BackGround ----- */
    {

        char vnmrmode[20];
        char expnum[16];
        char fidpath[128];
        char userpath[128];
        char host[128];
        char vnmr_acqid[16];
        int ret;
        int len;
        int uid;
        int gid;

        /* Be Absolutely sure there is a Vnmr out there to RUN */
        if ( access(Vnmrpath,R_OK | X_OK) != 0)
        {
           errLogRet(ErrLogOp,debugInfo,
                 "WARNING: BG '%s' Processing for '%s' was NOT performed, \n",
                   procmsge, pProcExpInfo->ExpId);
           errLogRet(ErrLogOp,debugInfo,
                 "         '%s' not found or can not run.\n",
                   Vnmrpath);
           return;   /* don't do any more */
        }

        /*
	    Common Arguments for NORMAL or AUTOMATION Vnmr Arguments
        */
	/* below we first copy the string "acqsend('5',..." to 
	   cmdstring (why? I don't know, msgestring isn't used anymore)
	   and then set the 8th character to '6'. So the cmdstring then
	   reads as "acqsend('6',...". By the way, in acqproc the digits
	   5 and 6 are defines as FGREPLY and FGNOREPLY respectively.
	   For those that need to maintain software this may be of help.
	*/
        strcpy(cmdstring,msgestring);
        cmdstring[8] = '6';
        sprintf(userpath,"-u%s",pProcExpInfo->ExpInfo->UsrDirFile);
        sprintf(host,"-h%s",pProcExpInfo->ExpInfo->MachineID);
        sprintf(vnmr_acqid,"-i%d",pProcExpInfo->ExpInfo->ExpNum);
	sprintf(fidpath,"-d%s",pProcExpInfo->ExpInfo->DataFile);

        /* Are we in Automation Mode ? */
        if ( !(pProcExpInfo->ExpInfo->ExpFlags & AUTOMODE_BIT) )
        {
          /* back mode is used because the experiment will need to be
           * locked by the background Vnmr. The acq mode expects the
           * experiment to already be locked.
           */
          sprintf(vnmrmode,"-mback");
          sprintf(expnum,"-n%d",pProcExpInfo->ExpInfo->ExpNum);
        }
        else     /* Automation Mode */
        {
	    /* Use Exp2 & Exp3 in automation mode */
           if (proctype == WEXP)
              sprintf(expnum,"-n2");
           else
              sprintf(expnum,"-n3");

           sprintf(vnmrmode,"-mauto");

           len = strlen(fidpath);
            /* Test Auto_Pid ? */
           /* if acquisition in automode and go neither a go(nowait)  */
           /*  or Werror issue a resume to autoproc prior to processing */
           if ( (pProcExpInfo->ExpInfo->ProcWait == AU_NOWAIT) && 
		(proctype != WERR) )
           {
	     DPRINT(1,"BeginProcessing: Prior to vfork - Send Resume\n");
    	     pAutoMsgQ = openMsgQ("Autoproc");
	     if (pAutoMsgQ != NULL)
	     {
	       sendMsgQ(pAutoMsgQ, "resume", strlen("resume"), MSGQ_NORMAL,
 			WAIT_FOREVER); /* NO_WAIT */
	       closeMsgQ(pAutoMsgQ);
	     }
           }

        }
 
 
        /* save User is a static location for forked child */
	strcpy(User,pProcExpInfo->ExpInfo->UserName);
	umask4Vnmr = pProcExpInfo->ExpInfo->UserUmask;
        childpid = fork();  /* fork a child */
        DPRINT1(1,"Start BG process ----  childpid = %d\n",childpid);
        /* -----  Parent vs Child ---- */
        if (childpid == 0)
        {
	    sigset_t signalmask;

	    /* set signal mask for child ti zip */
	    sigemptyset( &signalmask );
    	    sigprocmask( SIG_SETMASK, &signalmask, NULL );

            /* change the user and group ID of the child so that VNMR
               will run with those ID's */
	    getUserUid(User, &uid, &gid);
 
            seteuid(getuid());
            freopen("/dev/null","r",stdin);
            freopen("/dev/console","a",stdout);
            freopen("/dev/console","a",stderr);
            if ( setgid(gid) )
            {
                  DPRINT(1,"BGprocess:  cannot set group ID\n");
            }
 
            if ( setuid(uid) )
            {
                  DPRINT(1,"BGprocess:  cannot set user ID\n");
            }

            /* set umask to be that requested by PSG */
            umask( umask4Vnmr );
              
            ret=execl(Vnmrpath,"Vnmr",vnmrmode,host,vnmr_acqid,expnum,userpath,fidpath,cmdstring,NULL);
            if (ret == -1)
            {
               errLogRet(ErrLogOp,debugInfo,
                 "WARNING: BG '%s' for Exp%d was NOT performed, \n",
                   proctype,pProcExpInfo->ExpInfo->ExpNum);
               errLogRet(ErrLogOp,debugInfo, "         execl on '%s' failed.\n",
                   Vnmrpath);
               return;   /* don't do any more */
            }
        }
        else     /* if (childpid != 0)  Child */
        {
            DPRINT(1,"BeginProcessing: BG calling activeQadd()\n");
	    activeQadd(pProcExpInfo->ExpId, proctype, fid, ct, BG, childpid, dCode, eCode);
	    procQdelete(proctype, 1);
        }
    }
}
Esempio n. 28
0
/* ------------------------------------------------------------------- run -- */
int SPECTACLE_BASE :: run()
{
   if (first_time) {
      /* create segmented input buffer */
      int num_segments = (window_len / RTBUFSAMPS) + 2;
      int extrasamps = RTBUFSAMPS - framesToRun();
      if (extrasamps)
         num_segments++;
      int inbuf_samps = num_segments * RTBUFSAMPS * inputChannels();
      inbuf = new float [inbuf_samps];
      for (int i = 0; i < inbuf_samps; i++)
         inbuf[i] = 0.0;

      /* Read ptr chases write ptr by <window_len>.  Set read ptr to a position
         <window_len> frames from right end of input buffer.  Set write ptr to
         beginning of buffer, or, if framesToRun() is not the same as the RTcmix
         buffer size, set it so that the next run invocation after this one
         will find the write ptr at the start of the second buffer segment.
      */
      inbuf_readptr = inbuf + (inbuf_samps - (window_len * inputChannels()));
      inbuf_startptr = inbuf + (extrasamps * inputChannels());
      inbuf_writeptr = inbuf_startptr;
      inbuf_endptr = inbuf + inbuf_samps;

      int outbuf_samps = num_segments * RTBUFSAMPS * outputChannels();
      outbuf = new float [outbuf_samps];
      for (int i = 0; i < outbuf_samps; i++)
         outbuf[i] = 0.0;

      outbuf_readptr = outbuf + (outbuf_samps
                                       - (framesToRun() * outputChannels()));
      outbuf_writeptr = outbuf_readptr;
      outbuf_endptr = outbuf + outbuf_samps;
      first_time = 0;

      DPRINT3("framesToRun()=%d, extrasamps=%d, num_segments=%d\n",
                                 framesToRun(), extrasamps, num_segments);
      DPRINT3("inbuf_samps=%d, inbuf_readptr=%p, inbuf_writeptr=%p\n",
                                 inbuf_samps, inbuf_readptr, inbuf_writeptr);
      DPRINT3("outbuf_samps=%d, outbuf_readptr=%p, outbuf_writeptr=%p\n",
                                 outbuf_samps, outbuf_readptr, outbuf_writeptr);
   }

   const int insamps = framesToRun() * inputChannels();
   if (currentFrame() < total_insamps)
      rtgetin(inbuf_writeptr, this, insamps);

   int iterations = framesToRun() / decimation;
   if (framesToRun() < RTBUFSAMPS)
      iterations++;

   DPRINT1("iterations=%d\n", iterations);

   for (int i = 0; i < iterations; i++) {
      if (currentFrame() < input_end_frame) {
         DPRINT1("taking input...cursamp=%d\n", currentFrame());
         shiftin();
         fold(currentFrame());
         JGrfft(fft_buf, half_fft_len, FORWARD);
         leanconvert();
      }
      else
         flush_dry_delay();
      modify_analysis();
      leanunconvert();
      JGrfft(fft_buf, half_fft_len, INVERSE);
      overlapadd(currentFrame());
      shiftout();

      increment(decimation);
   }

   if (currentFrame() < input_end_frame) {
      inbuf_writeptr += insamps;
      if (inbuf_writeptr >= inbuf_endptr)
         inbuf_writeptr = inbuf;
   }

   rtbaddout(outbuf_readptr, framesToRun());
   outbuf_readptr += framesToRun() * outputChannels();
   if (outbuf_readptr >= outbuf_endptr)
      outbuf_readptr = outbuf;

   return framesToRun();
}
Esempio n. 29
0
/* -------------------------------------------------------------- pre_init -- */
int TVSPECTACLE :: pre_init(double p[], int n_args)
{
   wetdry = n_args > 9 ? p[9] : 1.0;            /* default is 1 */
   inchan = n_args > 10 ? (int) p[10] : 0;      /* default is chan 0 */
   pctleft = n_args > 11 ? p[11] : 0.5;         /* default is center */

   if (wetdry < 0.0 || wetdry > 1.0)
      return die(instname(), "Wet/dry must be between 0 and 1.");

   eqtableA = floc(3);
   if (eqtableA) {
      int len = fsize(3);
      eqtableA = resample_functable(eqtableA, len, half_fft_len);
   }
   else
      return die(instname(), "You haven't made EQ function A (table 3).");

   eqtableB = floc(6);
   if (eqtableB) {
      int len = fsize(6);
      eqtableB = resample_functable(eqtableB, len, half_fft_len);
   }
   else
      return die(instname(), "You haven't made EQ function B (table 6).");

   deltimetableA = floc(4);
   if (deltimetableA) {
      int len = fsize(4);
      deltimetableA = resample_functable(deltimetableA, len, half_fft_len);
   }
   else
      return die(instname(),
                        "You haven't made delay time function A (table 4).");

   deltimetableB = floc(7);
   if (deltimetableB) {
      int len = fsize(7);
      deltimetableB = resample_functable(deltimetableB, len, half_fft_len);
   }
   else
      return die(instname(),
                        "You haven't made delay time function B (table 7).");

   /* Compute maximum delay lag and create delay lines for FFT magnitude
      and phase values.  Make ringdur at least as long as the longest
      delay time.  Remember that these delays function at the decimation
      rate, not at audio rate.
   */
   maxdelsamps = (long) (MAXDELTIME * SR / decimation + 0.5);
   float maxtime = 0.0;
   for (int i = 0; i < half_fft_len; i++) {

      /* Check delay time table A. */
      float deltime = deltimetableA[i];
      if (deltime < 0.0 || deltime > MAXDELTIME)
         return die(instname(),
                    "Delay times must be >= 0 and <= %g. (The value in "
                    "table A at %d is %g.)", MAXDELTIME, i, deltime);
      float samps = deltime * SR / (float) decimation;
      assert(samps <= maxdelsamps);
      if (deltime > maxtime)
         maxtime = deltime;

      /* Check delay time table B. */
      deltime = deltimetableB[i];
      if (deltime < 0.0 || deltime > MAXDELTIME)
         return die(instname(),
                    "Delay times must be >= 0 and <= %g. (The value in "
                    "table B at %d is %g.)", MAXDELTIME, i, deltime);
      samps = deltime * SR / (float) decimation;
      assert(samps <= maxdelsamps);
      if (deltime > maxtime)
         maxtime = deltime;

      mag_delay[i] = new DLineN(maxdelsamps);
      phase_delay[i] = new DLineN(maxdelsamps);
   }
   if (ringdur < maxtime)
      ringdur = maxtime;   /* but will still cut off any trailing feedback */

   DPRINT3("decimation=%d, maxdelsamps=%ld, ringdur=%g\n",
                                 decimation, maxdelsamps, ringdur);

   feedbacktableA = floc(5);
   if (feedbacktableA) {
      int len = fsize(5);
      feedbacktableA = resample_functable(feedbacktableA, len, half_fft_len);
   }
   else
      return die(instname(),
                     "You haven't made delay feedback function A (table 5).");

   feedbacktableB = floc(8);
   if (feedbacktableB) {
      int len = fsize(8);
      feedbacktableB = resample_functable(feedbacktableB, len, half_fft_len);
   }
   else
      return die(instname(),
                     "You haven't made delay feedback function B (table 8).");

   eqcurve = floc(9);
   if (eqcurve) {
      int len = fsize(9);
      if (check_curve(eqcurve, len, 0.0, 1.0))
         rtcmix_warn(instname(), "EQ curve values must be between 0 and 1.\n"
                          "Fixing...");
      tableset(SR, inputdur + ringdur, len, eqcurvetabs);
      eq_curve_weight = eqcurve[0];
   }
   else {
      rtcmix_advise(instname(), "Setting EQ table curve to all 0's (no table 9).");
      eq_curve_weight = 0.0;
   }

   deltimecurve = floc(10);
   if (deltimecurve) {
      int len = fsize(10);
      if (check_curve(deltimecurve, len, 0.0, 1.0))
         rtcmix_warn(instname(), "Delay time curve values must be between 0 and 1.\n"
                          "Fixing...");
      tableset(SR, inputdur + ringdur, len, deltimecurvetabs);
      deltime_curve_weight = deltimecurve[0];
   }
   else {
      rtcmix_advise(instname(), "Setting EQ table curve to all 0's (no table 10).");
      deltime_curve_weight = 0.0;
   }

   feedbackcurve = floc(11);
   if (feedbackcurve) {
      int len = fsize(11);
      if (check_curve(feedbackcurve, len, 0.0, 1.0))
         rtcmix_warn(instname(), "Feedback curve values must be between 0 and 1.\n"
                          "Fixing...");
      tableset(SR, inputdur + ringdur, len, feedbackcurvetabs);
      feedback_curve_weight = feedbackcurve[0];
   }
   else {
      rtcmix_advise(instname(), "Setting EQ table curve to all 0's (no table 11).");
      feedback_curve_weight = 0.0;
   }

//printf("deltimecurvetabs: %f, %f\n", deltimecurvetabs[0], deltimecurvetabs[1]);
   return 0;
}
Esempio n. 30
0
/*
 * This routine is called only for RRI shims.  It first decides if
 * the old shimmer software or the new mxserver software is present
 * in the RRI. It does this by testing whether or not the PC (prepare
 * coarse) command is present.  It is not present in old software.
 * If the new software is present, we use the PC command to disable
 * DACs which are not present. Finally, if the z7 dac is not present,
 * we assume the ULTRA18 shims are present.
 */
initGradTest()
{
   int index;
   int stat;
  
   /* Set all dacs to present */
   for (index = 0; index < sizeof(rriShimTable)/sizeof(rriShimTable[0]);
        index++)
   {
      gradOK[index] = 1;
   }
   if (pShimMutex != NULL)
   {
      semTake(pShimMutex,WAIT_FOREVER); /* protect shim serial comm */
   }
   else
   {
      return(ULTRA);
   }
   clearport(shimPort);
   pputchr(shimPort, 'P');
   cmdecho(shimPort, ECHO);
   pputchr(shimPort, 'C');
   stat = cmddone(shimPort, 100);
   if (stat == 200)
   {
/*
 * The PC command is not recognized. This must be old RRI SHIMMER software
 */
      semGive(pShimMutex);
      return(ULTRA);
   }
   pputchr(shimPort, '\r');

/*
 * At this point an error should occur for the MXSERVER RRI software.
 * There are two cases.
 * 1. MxServer with no error handling should not give an error number
 *    but it will give an error message about "Incorrect number of
 *    arguments".
 * 2. MxServer with error handling should give error 201 ""Incorrect number of
 *    argument".
 */

   stat = cmddone(shimPort, 500);
        
   semGive(pShimMutex);
   if (stat != 201)
      return(ULTRA);
   RRIcmd = 'P';
   for (index = 0; index < sizeof(rriShimTable)/sizeof(rriShimTable[0]);
        index++)
   {
      setRRIShim(index, 0, 0);
/*
 * A return value of 202 is given by RRI's mxserver if a gradient is
 * not present
 */
      if (shimstat == 202)
      {
         DPRINT1(1,"turn off dac %d\n",index);
         gradOK[index] = 0;
      }
      else if (shimstat != 0)
      {
        DPRINT3(1,"dac %d (%s) status= %d\n",
                index,rriShimTable[index],shimstat);
      }
   }
   RRIcmd = 'S';
   /* test if z7 (dac 10) is present */
   return( (gradOK[10] == 0) ? ULTRA18 : ULTRA);
}