Beispiel #1
0
/* default priority adjustment functions */
void SetTaskPrio(const char* tName, const int tgtPrio)
{
    int tid=0, curPrio=0, newPrio=0;

    if ((tName != NULL) && (strlen(tName) > 0))
    {
        newPrio = tgtPrio;
        if (newPrio < 0)
        {
            newPrio = 0;
        }
        else if (newPrio > 255)
        {
            newPrio = 255;
        }

        tid = taskNameToId(tName);
        if (tid != ERROR)
        {
            if (taskPriorityGet(tid, &curPrio) != ERROR)
            {
                printf("Setting %s priority from %d to %d\n", tName, curPrio, newPrio);
                taskPrioritySet(tid, newPrio);
            }
        }
    }
}
Beispiel #2
0
/* 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;
}
Beispiel #3
0
/* 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");

   /* 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");
   fifoLoadHsl(pTheFifoObject, STD_HS_LINES, pTheFifoObject->SafeHSLines);
   fifoLoadHsl(pTheFifoObject, EXT_HS_LINES, pTheFifoObject->SafeHSLinesExt);
   /* Each SafeState Code is actually two long words */
   
   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);
   if (callTaskPrior <= FIFO_STUFFER_PRIORITY)
   {
      DPRINT(0,"Set priority lower than stuffer\n");
      taskPrioritySet(callTaskId,(FIFO_STUFFER_PRIORITY+1));  
   }
   if (numSafeStatCodes > 0)
   {
      fifoStuffIt(pTheFifoObject, pSafeStateCodes, numSafeStatCodes);/* into Fifo Buffer */
      fifoStuffCode(pTheFifoObject, pTurnOffSshaCodes, numTurnOffSshaCodes);
      fifoStuffCode(pTheFifoObject, pHaltOpCodes, numHaltOpCodes);
	DPRINT(1,"Ready to start FIFO in set to exp end state\n" );
      fifoStart(pTheFifoObject);
      fifoWait4Stop(pTheFifoObject);
   }
   setlksample();
   set2khz();
   activate_ssha();
   /* reset priority back if changed */
   if (callTaskPrior <= FIFO_STUFFER_PRIORITY)
   {
      DPRINT(0,"Set priority Back \n");
      taskPrioritySet(callTaskId,callTaskPrior);  
   }
   return;
}
int vxhGo()
{
  vxhStop();
  tid = taskNameToId("tShell");
  taskPrioritySet(tid,4);
  tid = taskNameToId("tLogTask");
  taskPrioritySet(tid,3);
  tid = taskNameToId("tExcTask");
  taskPrioritySet(tid,3);
  tid = taskNameToId("tTelnetd");
  taskPrioritySet(tid,5);
  tid = taskNameToId("tTelnetOutTask");
  taskPrioritySet(tid,6);
  tid = taskNameToId("tTelnetInTask");
  taskPrioritySet(tid,6);
  tid = taskNameToId("tWdbTask");
  taskPrioritySet(tid,7);

  vxh_stop_flag=0;
  vxh_count=0;
  vxh_id =  taskSpawn(0, //name
		1,		// priority
		VX_FP_TASK,	// options
		0x2000,		// stack size
		(FUNCPTR) vxh_task, // entry point
		      0,0,0,0,0,
		      0,0,0,0,0);
  return(0);
}
Beispiel #5
0
/*----------------------------------------------------------------------*/
static
void resetNameBufs()   /* free all named buffers */
{
   int retrys;
   int callTaskId,DwnLkrTaskId;
   int callTaskPrior;

   /* Since reset2SafeState should have left the downLinker in a ready
      state we now longer need change priority/etc. here to get it to clean
      up.     8/6/97
   */
#ifdef XXX
   callTaskId = taskIdSelf();
   DwnLkrTaskId = taskNameToId("tDownLink");
   taskPriorityGet(callTaskId,&callTaskPrior);
#endif


   retrys=0;

   /* start wdog timeout of 7 seconds */ 
   pHandlerTimeout = 0;
   wdStart(pHandlerWdTimeout,sysClkRateGet() * 7, pHandlerWdISR, 0);

   /* free buffers until all are free or watch-dog timeout has occurred */
   while ( ((dlbUsedBufs(pDlbDynBufs) > 0) || (dlbUsedBufs(pDlbFixBufs) > 0)) &&
		(!pHandlerTimeout) )
   {
        retrys++;
   	DPRINT(0,"dlbFreeAll Dyn");
   	dlbFreeAll(pDlbDynBufs);
   	DPRINT(0,"dlbFreeAll Fix");
   	dlbFreeAll(pDlbFixBufs);
	Tdelay(1);
	DPRINT1(0,"resetNameBufs: retrys: %d\n",retrys);
#ifdef XXX
        /* Lower priority to allow downlinker in */
	if (callTaskPrior <= DOWNLINKER_TASK_PRIORITY)
           taskPrioritySet(callTaskId,(DOWNLINKER_TASK_PRIORITY+1));  
	Tdelay(10);

	DPRINT1(-1,"resetNameBufs: retrys: %d\n",retrys);
        if (retrys > 7)
        {
	   if (taskIsSuspended(DwnLkrTaskId))
	   {
	      DPRINT(-1,"resetNameBufs: clearCurrentNameBuffer()\n");
  	      clearCurrentNameBuffer();
           }
        }
#endif
   }
   wdCancel(pHandlerWdTimeout);
   /* taskPrioritySet(callTaskId,callTaskPrior);   */

  /*    resumeDownLink(); */
}
Beispiel #6
0
int
osip_thread_set_priority (struct osip_thread * _thread, int priority)
{
  osip_thread_t *thread = (osip_thread_t *)_thread;
  if (thread == NULL)
    return -1;
  taskPrioritySet (thread->id, 1);
  return 0;
}
Beispiel #7
0
void zmq::thread_t::
  applySchedulingParameters () // to be called in secondary thread context
{
    int priority = (thread_priority >= 0 ? thread_priority : DEFAULT_PRIORITY);
    priority = (priority < 255 ? priority : DEFAULT_PRIORITY);
    if (descriptor != NULL || descriptor > 0) {
        taskPrioritySet (descriptor, priority);
    }
}
Beispiel #8
0
int main (void)
#endif
{
  int j;
  float *data;

#ifdef VXWORKS
  { int currentPriority;
  /* The producer needs to run at a lower priority, else it swamps
     central and the consumer */
  taskPriorityGet(taskIdSelf(), &currentPriority);
  taskPrioritySet(taskIdSelf(), currentPriority+10);
  }
#endif

  data = (float *)malloc(MAX_DATA_SIZE);
  
  for (j = 0; j<MAX_DATA_SIZE/sizeof(float); j++)
    data[j] = (float) j;

  IPC_connect("sender");
  IPC_defineMsg(NULL_MSG, 0, NULL);
  IPC_defineMsg(FLOAT4_MSG, sizeof(float)*4, NULL);
  IPC_defineMsg(FLOAT16_MSG, sizeof(float)*16, NULL);
  IPC_defineMsg(FLOAT64_MSG, sizeof(float)*64, NULL);
  IPC_defineMsg(FLOAT256_MSG, sizeof(float)*256, NULL);
  IPC_defineMsg(FLOAT1K_MSG, sizeof(float)*1024, NULL);
  IPC_defineMsg(FLOAT4K_MSG, sizeof(float)*4*1024, NULL);
  IPC_defineMsg(FLOAT16K_MSG, sizeof(float)*16*1024, NULL);
  IPC_defineMsg(FLOAT64K_MSG, sizeof(float)*64*1024, NULL);
  IPC_defineMsg(FLOAT256K_MSG, sizeof(float)*256*1024, NULL);

  IPC_subscribe(DONE_MSG, doneHandler, NULL);
  
  sendMessages(NULL_MSG, 0, data);
  sendMessages(FLOAT4_MSG, sizeof(float)*4, data);
  sendMessages(FLOAT16_MSG, sizeof(float)*16, data);
  sendMessages(FLOAT64_MSG, sizeof(float)*64, data);
  sendMessages(FLOAT256_MSG, sizeof(float)*256, data);
  sendMessages(FLOAT1K_MSG, sizeof(float)*1024, data);
  sendMessages(FLOAT4K_MSG, sizeof(float)*4*1024, data);
  sendMessages(FLOAT16K_MSG, sizeof(float)*16*1024, data);
  sendMessages(FLOAT64K_MSG, sizeof(float)*64*1024, data);
  sendMessages(FLOAT256K_MSG, sizeof(float)*256*1024, data);

  /* Wait for everything to settle down before shutting down */
  sleep(2);

  /* shut down */
  printf ("\n");
  fflush(stdout);
  IPC_disconnect();
#if !defined(VXWORKS)
  return 0;
#endif
}
Beispiel #9
0
// Slower updates, lower priority, signals ready.
void readify(Flywheel *flywheel)
{
	flywheel->ready = true;
	flywheel->delay = FLYWHEEL_READY_DELAY;
	if (flywheel->task)
	{
		taskPrioritySet(flywheel->task, FLYWHEEL_READY_PRIORITY);
	}
	// TODO: Signal ready?
}
Beispiel #10
0
// Faster updates, higher priority, signals active.
void activate(Flywheel *flywheel)
{
	flywheel->ready = false;
	flywheel->delay = FLYWHEEL_ACTIVE_DELAY;
	if (flywheel->task)
	{
		taskPrioritySet(flywheel->task, FLYWHEEL_ACTIVE_PRIORITY);
	}
	// TODO: Signal not ready?
}
Beispiel #11
0
void NewPriority(Id* to, PriorityType newPrio)
{
  assert(to);
	// do set a new priority if the one pass to this function is is invalid!
	if (newPrio != INVALID_PRIORITY)
	{
	  if (taskPrioritySet(to->TaskId, GetOSPriority(newPrio)) != OK)
		{
		  ExitFunctionsThreadList().CriticalError(errnoGet(), __FUNCTION__, __LINE__);
		}
	}
}
Beispiel #12
0
void ThreadImpl::setPriorityImpl(int prio)
{
    if (prio != _pData->prio)
    {
        _pData->prio   = prio;
        _pData->osPrio = mapPrio(_pData->prio);
        if (isRunningImpl())
        {
            if (taskPrioritySet(_pData->task, _pData->osPrio) != OK)
                throw SystemException("cannot set task priority");
        }
    }
}
Beispiel #13
0
void ThreadImpl::setOSPriorityImpl(int prio, int /* policy */)
{
    if (prio != _pData->osPrio)
    {
        _pData->prio   = reverseMapPrio(prio);
        _pData->osPrio = prio;
        if (_pData->pRunnableTarget || _pData->pCallbackTarget)
        {
            if (taskPrioritySet(_pData->task, prio) != OK)
                throw SystemException("cannot set task priority");
        }
    }
}
Beispiel #14
0
tstbarrier()
{
    int i;
    int retval;
   int pTmpId, TmpPrior;
    int status;

   pTmpId = taskIdSelf();
   taskPriorityGet(pTmpId,&TmpPrior);
   taskPrioritySet(pTmpId,132);
   status = nddsPublicationIssuesWait(pUploadSyncPub, 5, 0);
   if ( status == -1)
        DPRINT(-1,"sendDDRSync: error in waiting\n");
    for(i=0; i < 100; i++)
    {
       /* DPRINT1(-1," %d: call barrier wait\n",i); */
       retval = barrierWait();
       if (retval == 42)
          DPRINT1(-1,">>>> %d: <<<<<<   returned from barrier wait\n",i);
    }
   taskPrioritySet(pTmpId,TmpPrior);
}
Beispiel #15
0
static
void resetSystem()
{
   DPRINT(0,"AParserAA");
   AParserAA();

   /* PARALLEL_CHANS */
   freeSorter();

   DPRINT(0,"AupdtAA");
   AupdtAA();
   DPRINT(0,"ShandlerAA");
   ShandlerAA();
   DPRINT(0,"fifoStufferAA");
   fifoStufferAA(pTheFifoObject);

   stmAdcOvldClear(pTheStmObject);
   /* stmReset(pTheStmObject); */
   DPRINT(0,"Disable ADC Intrps");
   adcItrpDisable(pTheAdcObject,ADC_ALLITRPS);
   /* adcReset(pTheAdcObject); */

   /* reset fifo Object not to use parallel channels */
   fifoClearPChanId(pTheFifoObject);

   /* Reset Safe State again after tasks restarted */
   /*reset2SafeState();*/  /* reprogram HSlines, ap registers to safe state */
   /* call to reset2SafeState removed; in each case where resetSystem */
   /* is called, reset2SafeState is called immediately previously.    */

/* it maybe safe here, but we have to flip flop priorities with the Stuffer */
   DPRINT2(0,"resetSystem: tid: 0x%lx, priority: %d\n",pHandlerTid,pHandlerPriority);
   taskPrioritySet(pHandlerTid,(FIFO_STUFFER_PRIORITY+1));  
   setlksample();
   set2khz();
   taskPrioritySet(pHandlerTid,pHandlerPriority);  
   return;
}
Beispiel #16
0
static void rootTask(long a0, long a1, long a2, long a3, long a4,
		     long a5, long a6, long a7, long a8, long a9)
{
	TASK_ID tid;
	int ret, n;

	traceobj_enter(&trobj);

	qid = msgQCreate(NMESSAGES, sizeof(int), MSG_Q_PRIORITY);
	traceobj_assert(&trobj, qid != 0);

	traceobj_mark(&trobj, 3);

	ret = taskPrioritySet(taskIdSelf(), 10);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 4);

	tid = taskSpawn("peerTask",
			11,
			0, 0, peerTask, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	traceobj_assert(&trobj, tid != ERROR);

	traceobj_mark(&trobj, 5);

	n = 0;
	do
		ret = msgQSend(qid, (char *)&messages[n], sizeof(int), NO_WAIT, MSG_PRI_URGENT);
	while(n++ < NMESSAGES && ret != ERROR);

	traceobj_assert(&trobj, ret == ERROR && errno == S_objLib_OBJ_UNAVAILABLE && n == NMESSAGES + 1);

	traceobj_mark(&trobj, 6);

	ret = taskDelay(10);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 7);

	ret = msgQNumMsgs(qid);
	traceobj_assert(&trobj, ret == 0);

	traceobj_verify(&trobj, tseq, sizeof(tseq) / sizeof(int));

	traceobj_exit(&trobj);
}
Beispiel #17
0
void BSP_PromptSet()
{
    SHELL_ID    shellId;
    int taskId;

    /* Get the shell context */
    taskId = taskNameToId ("tShell0");
    shellId = shellFirst ();

    while (shellId != (SHELL_ID)0)
    {
        if (((SHELL_CTX *)shellId)->taskId == taskId)
            break;
        shellId = shellNext (shellId);
    }

    shellInterpPromptSet(shellId,"C","[C]->");
    taskPrioritySet(taskId, 9);/*优先级与V9一致*/
}
Beispiel #18
0
static int __wind_task_priorityset(struct pt_regs *regs)
{
	xnhandle_t handle = __xn_reg_arg1(regs);
	int prio = __xn_reg_arg2(regs);
	WIND_TCB *pTcb;

	if (handle)
		pTcb = __wind_lookup_task(handle);
	else
		pTcb = __wind_task_current(current);

	if (!pTcb)
		return S_objLib_OBJ_ID_ERROR;

	if (taskPrioritySet((TASK_ID) pTcb, prio) == ERROR)
		return wind_errnoget();

	return 0;
}
Beispiel #19
0
static void * event_thread_func(void * arg) {
    taskPrioritySet(0, VX_TASK_PRIORITY_MIN);
    for (;;) {
        struct event_info * info = loc_alloc(sizeof(struct event_info));
        semTake(events_signal, WAIT_FOREVER);

        SPIN_LOCK_ISR_TAKE(&events_lock);
        if (events_buf_overflow && events_inp == events_out) {
            SPIN_LOCK_ISR_GIVE(&events_lock);
            loc_free(info);
            break;
        }
        assert(events_inp != events_out);
        *info = events[events_out];
        events_out = (events_out + 1) % MAX_EVENTS;
        SPIN_LOCK_ISR_GIVE(&events_lock);

        post_event(event_handler, info);
    }
    post_event(event_error, NULL);
    return NULL;
}
Beispiel #20
0
/**
 * This routine changes a task's priority to a specified priority.
 * Priorities range from 0, the highest priority, to 255, the lowest priority.
 * Default task priority is 100.
 * @param priority The priority the task should run at.
 * @returns true on success.
 */
bool Task::SetPriority(INT32 priority)
{
    m_priority = priority;
    return HandleError(taskPrioritySet(m_taskID, m_priority));
}
void
CVMthreadSetPriority(CVMThreadID *t, CVMInt32 priority)
{
    taskPrioritySet(t->taskID, JAVAPRIO2VXPRIO(priority));
}
Beispiel #22
0
/*
 * main - parse arguments and handle options
 */
int
ntpdcmain(
	int argc,
	char *argv[]
	)
{
	extern int ntp_optind;

	delay_time.l_ui = 0;
	delay_time.l_uf = DEFDELAY;

#ifdef SYS_VXWORKS
	clear_globals();
	taskPrioritySet(taskIdSelf(), 100 );
#endif

	init_lib();	/* sets up ipv4_works, ipv6_works */
	ssl_applink();

	/* Check to see if we have IPv6. Otherwise default to IPv4 */
	if (!ipv6_works)
		ai_fam_default = AF_INET;

	progname = argv[0];

	{
		int optct = ntpOptionProcess(&ntpdcOptions, argc, argv);
		argc -= optct;
		argv += optct;
	}

	if (HAVE_OPT(IPV4))
		ai_fam_templ = AF_INET;
	else if (HAVE_OPT(IPV6))
		ai_fam_templ = AF_INET6;
	else
		ai_fam_templ = ai_fam_default;

	if (HAVE_OPT(COMMAND)) {
		int		cmdct = STACKCT_OPT( COMMAND );
		const char**	cmds  = STACKLST_OPT( COMMAND );

		while (cmdct-- > 0) {
			ADDCMD(*cmds++);
		}
	}

	debug = DESC(DEBUG_LEVEL).optOccCt;

	if (HAVE_OPT(INTERACTIVE)) {
		interactive = 1;
	}

	if (HAVE_OPT(NUMERIC)) {
		showhostnames = 0;
	}

	if (HAVE_OPT(LISTPEERS)) {
		ADDCMD("listpeers");
	}

	if (HAVE_OPT(PEERS)) {
		ADDCMD("peers");
	}

	if (HAVE_OPT(SHOWPEERS)) {
		ADDCMD("dmpeers");
	}

	if (ntp_optind == argc) {
		ADDHOST(DEFHOST);
	} else {
		for (; ntp_optind < argc; ntp_optind++)
		    ADDHOST(argv[ntp_optind]);
	}

	if (numcmds == 0 && interactive == 0
	    && isatty(fileno(stdin)) && isatty(fileno(stderr))) {
		interactive = 1;
	}

#if 0
	ai_fam_templ = ai_fam_default;
	while ((c = ntp_getopt(argc, argv, "46c:dilnps")) != EOF)
	    switch (c) {
		case '4':
		    ai_fam_templ = AF_INET;
		    break;
		case '6':
		    ai_fam_templ = AF_INET6;
		    break;
		case 'c':
		    ADDCMD(ntp_optarg);
		    break;
		case 'd':
		    ++debug;
		    break;
		case 'i':
		    interactive = 1;
		    break;
		case 'l':
		    ADDCMD("listpeers");
		    break;
		case 'n':
		    showhostnames = 0;
		    break;
		case 'p':
		    ADDCMD("peers");
		    break;
		case 's':
		    ADDCMD("dmpeers");
		    break;
		default:
		    errflg++;
		    break;
	    }

	if (errflg) {
		(void) fprintf(stderr,
			       "usage: %s [-46dilnps] [-c cmd] host ...\n",
			       progname);
		exit(2);
	}

	if (ntp_optind == argc) {
		ADDHOST(DEFHOST);
	} else {
		for (; ntp_optind < argc; ntp_optind++)
		    ADDHOST(argv[ntp_optind]);
	}

	if (numcmds == 0 && interactive == 0
	    && isatty(fileno(stdin)) && isatty(fileno(stderr))) {
		interactive = 1;
	}
#endif

#ifndef SYS_WINNT /* Under NT cannot handle SIGINT, WIN32 spawns a handler */
	if (interactive)
	    (void) signal_no_reset(SIGINT, abortcmd);
#endif /* SYS_WINNT */

	/*
	 * Initialize the packet data buffer
	 */
	pktdatasize = INITDATASIZE;
	pktdata = emalloc(INITDATASIZE);

	if (numcmds == 0) {
		(void) openhost(chosts[0]);
		getcmds();
	} else {
		int ihost;
		int icmd;

		for (ihost = 0; ihost < numhosts; ihost++) {
			if (openhost(chosts[ihost]))
			    for (icmd = 0; icmd < numcmds; icmd++) {
				    if (numhosts > 1) 
					printf ("--- %s ---\n",chosts[ihost]);
				    docmd(ccmds[icmd]);
			    }
		}
	}
#ifdef SYS_WINNT
	WSACleanup();
#endif
	return(0);
} /* main end */
Beispiel #23
0
/*********************************************************************
*
* recovery, based on the cmd code decides what recovery action 
*		to perform.
*
*					Author Greg Brissey 12-7-94
*/
void recovery(CNTLR_COMM_MSG *msge, int externflag)
{
   char *token;
   int len;
   int cmd;
   int i,nMsg2Read;
   int bytes;
   extern int systemConRestart();
   CNTLR_COMM_MSG discardedmsge;

   DPRINT(-1,"Local Exception\n");
   switch( msge->cmd /* exceptionType */ )
   {
      case PANIC:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_PANIC,NULL,NULL);
#endif
    		errLogRet(LOGIT,debugInfo,
       		"phandler: Panic Error: %d", msge->errorcode);
		break;

      case WARNING_MSG:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_WARNMSG,NULL,NULL);
#endif
  	        DPRINT2(-10,"WARNING: doneCode: %d, errorCode: %d\n",
			msge->cmd,msge->errorcode);
    		/* errLogRet(LOGIT,debugInfo,
       		"phandler: Warning Message: %d", msge->reportEvent); */

		/* the send2Expproc is commented out. The msg is send 
		/* via other ways. We got two warning msgs for the 
		/* following numbers:
        	/* PNEU_ERROR + PRESSURE;
         	/* PNEU_ERROR + NB_STACK;
         	/* PNEU_ERROR + VTTHRESH;
         	/* PNEU_ERROR + PS;
		/* VTERROR + NOGAS
                /* Don't send ADC overflows to Expproc */
                /* if ( (msge->errorcode != WARNINGS+ADCOVER) && 
                /*     (msge->errorcode != SFTERROR+LOCKLOST) )
                /*   send2Expproc(CASE,msge->cmd,msge->errorcode,0,NULL,0); 
                 */
		break;

      case SOFT_ERROR:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_SOFTERROR,NULL,NULL);
#endif
		/* update_acqstate( ACQ_IDLE ); INOVA */

  	        DPRINT2(0,"SOFT_ERROR: doneCode: %d, errorCode: %d\n",
			msge->cmd,msge->errorcode);
    		/* errLogRet(LOGIT,debugInfo,
       		"phandler: Soft Error: %d", msge->reportEvent); */
#ifdef INOVA
                statMsg.Status = msge->exceptionType;
                statMsg.Event = msge->reportEvent; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);
#endif
		break;

      case EXP_ABORTED:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_EXPABORTED,NULL,NULL);
#endif
  	        DPRINT(0,"Exp. Aborted");

      case HARD_ERROR:

#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_HARDERROR,NULL,NULL);
#endif
  	        DPRINT2(0,"HARD_ERROR: doneCode: %d, errorCode: %d\n", msge->cmd, msge->errorcode);

		AbortExp(msge,externflag);

		/* fifoCloseLog(pTheFifoObject); */
  	        DPRINT(0,"Done");
		break;
		

      case INTERACTIVE_ABORT:

#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_HARDERROR,NULL,NULL);
#endif
/*
  	        DPRINT1(0,"INTERACTIVE_ABORT: doneCode: %d, errorCode: %d\n", msge->reportEvent);
*/

		AbortExp(msge,externflag);

		/* fifoCloseLog(pTheFifoObject); */
  	        DPRINT(0,"Done");
		break;


      case EXP_HALTED:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_EXPHALTED,NULL,NULL);
#endif
  	        DPRINT2(0,"EXP_HALTED: doneCode: %d, errorCode: %d\n", msge->cmd, msge->errorcode);

		AbortExp(msge,externflag);

		break;


      case STOP_CMPLT:
                /* the monitor set the SA_Criteria value,
		   when the upLinker obtained a FID that meet this
		   Criteria the upLinker sent this msge here and
		   then blocked itself
                  Our job is to
	          1. Foward the Stopped msge to Host
	          2. reset hardware
                  3. put hardware into a safe state
		  4. call stmSA, clears upLinker msgQ, send SA msge
	          5. reset SA_Criteria back to Zero
		  6. give the semaphore to restart upLinker
		  7. reset update task
		  8. reset parser task
	          9. Free the buffers
	         10. Re-enable Interrupts 
		*/

#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_STOPCMPLT,NULL,NULL);
#endif
#ifdef INOVA
                statMsg.Status = msge->exceptionType;
                statMsg.Event = msge->reportEvent; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);

    		errLogRet(LOGIT,debugInfo,
       		"phandler: Exp. Stopped: %d", msge->reportEvent);

                /* reprogram HSlines, ap registers to safe state */
                reset2SafeState( msge->exceptionType );  

                resetSystem();  /* reset fifo, disable intrps, reset tasks & buffers */

  	        DPRINT2(0,"stmHaltCode: doneCode: %d, errorCode: %d\n",
			msge->exceptionType,msge->reportEvent);

                semGive(pSemSAStop);   /* release the UpLinker */
		/* stmHaltCode(pTheStmObject,(int) msge->exceptionType, 
				(int) msge->reportEvent);
		*/
  	        /* DPRINT(0,"stmSA"); stmSA(pTheStmObject); */
   		DPRINT(0,"STOP_CMPLT: lower priority below upLinker\n");
                taskPrioritySet(pHandlerTid,(UPLINKER_TASK_PRIORITY+1));  
   	        taskPrioritySet(pHandlerTid,pHandlerPriority);  

		SA_Criteria = 0;
		SA_Mod = 0L;

  	        DPRINT(0,"wait4DowninkerReady");
		wait4DownLinkerReady();	/* let downlinker become ready, then delete any left over buffers */

                resetNameBufs();   /* free all named buffers */

   		/* stmInitial(pTheStmObject, 1, 1024, pUpLinkMsgQ, 0); */

	        clrDwnLkAbort();

                wait4SystemReady(); /* pend till all activities are complete */

  	        DPRINT(0,"enableInterrupts");
		enableInterrupts();

	        /* now inform Expproc System is Ready */
                statMsg.Status = SYSTEM_READY; /* Console Ready  */
                statMsg.Event = 0; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);

		update_acqstate( ACQ_IDLE );
	        getstatblock();
/*
		if (pTheTuneObject != NULL)
		  semGive( pTheTuneObject->pSemAccessFIFO );
*/

#endif
                sendSysReady();
		break;

      case LOST_CONN:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_LOSTCONN,NULL,NULL);
#endif
#ifdef INOVA
    		errLogRet(LOGIT,debugInfo,
       		"phandler: Host Closed Connection to Console: %d", msge->reportEvent);
		update_acqstate( ACQ_IDLE );
		/* stmItrpDisable(pTheStmObject, STM_ALLITRPS); */
                storeConsoleDebug( SYSTEM_ABORT );
                /* reprogram HSlines, ap registers to safe state */
                reset2SafeState( msge->exceptionType );
                resetSystem();  /* reset fifo, disable intrps, reset tasks & buffers */
		/* stmReset(pTheStmObject); */
                taskDelay(calcSysClkTicks(332));  /* taskDelay(20); */
                resetNameBufs();   /* free all named buffers */
		enableInterrupts();
/*
		if (pTheTuneObject != NULL)
		  semGive( pTheTuneObject->pSemAccessFIFO );
*/
     		taskSpawn("tRestart",50,0,2048,systemConRestart,NULL,
				2,3,4,5,6,7,8,9,10);
	        clrDwnLkAbort();

#endif
	        break;

      case ALLOC_ERROR:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_ALLOCERROR,NULL,NULL);
#endif
#ifdef INOVA
    		errLogRet(LOGIT,debugInfo,
       		"phandler: Memory Allocation Error: %d", msge->reportEvent);

		update_acqstate( ACQ_IDLE );

                statMsg.Status = HARD_ERROR; /* HARD_ERROR */
                statMsg.Event = msge->reportEvent; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_URGENT);
                

		/* report HARD_ERROR to Recvproc */
  	        DPRINT2(0,"stmHaltCode: doneCode: %d, errorCode: %d\n",
			HARD_ERROR,msge->reportEvent);
/*
		stmHaltCode(pTheStmObject,(int) HARD_ERROR, 
				(int) msge->reportEvent);
*/

                /* reprogram HSlines, ap registers to safe state */
                reset2SafeState( msge->exceptionType );

                resetSystem();  /* reset fifo, disable intrps, reset tasks & buffers */

	      
#ifdef XXXX
                statMsg.Status = WARNING_MSG;
                statMsg.Event = WARNINGS + MEM_ALLOC_ERR; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);
#endif

                resetNameBufs();   /* free all named buffers */

   		/* stmInitial(pTheStmObject, 1, 1024, pUpLinkMsgQ, 0); */

	        clrDwnLkAbort();

  	        DPRINT(0,"enableInterrupts");
		enableInterrupts();

	        /* now inform Expproc System is Ready */
                statMsg.Status = SYSTEM_READY; /* Console Ready  */
                statMsg.Event = 0; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);

	        getstatblock();
/*
		if (pTheTuneObject != NULL)
		  semGive( pTheTuneObject->pSemAccessFIFO );
*/

#endif
		break;
      
      case WATCHDOG:
#ifdef INOVA
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_WATCHDOG,NULL,NULL);
#endif
		/* Giv'm a bone */
    		errLogRet(LOGIT,debugInfo,
       		"phandler: Watch Dog: %d", msge->reportEvent);
#endif
		break;

      default:
		/* Who Cares */
    		errLogRet(LOGIT,debugInfo,
       		"phandler: Invalid Exception Type: %d, Event: %d", 
			msge->cmd, msge->errorcode);
		break;
   }
/*
   nMsg2Read = msgQNumMsgs(pMsgesToPHandlr);
   DPRINT1(-1,"Message in Q: %d\n",nMsg2Read);
*/
   if (msge->cmd != WARNING_MSG)
      resumeLedShow(); /* resume LED Idle display */

   while ( (bytes = msgQReceive(pMsgesToPHandlr, (char*) &discardedmsge, sizeof( CNTLR_COMM_MSG ), NO_WAIT)) != ERROR )
   {
     DPRINT(-1,"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n");
     DPRINT1(0,"Read %d bytes from Phandler msgQ, (Bogus Errors at this point)\n",bytes);
     DPRINT4(-1,"'%s': Exception from: -> '%s' <-, Type: %d, ErrorCode: %d \n",
			hostName, discardedmsge.cntlrId, discardedmsge.cmd, discardedmsge.errorcode);
     DPRINT(-1,"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");


   }
}
//---------------------------------------------------------------------------
//
// Function:    openPowerlinkInit
//
// Description:
//    Initialize and start the openPOWERLINK demo application
//
// Parameters:
//    pszEthName = pointer to string with name of network interface to use
//
// Returns: int
//
//---------------------------------------------------------------------------
int openPowerlinkInit (char *pszEthName, unsigned int uiDevNumber)
{
    tEplKernel          EplRet;
    static tEplApiInitParam EplApiInitParam = {0};
    char*               sHostname = HOSTNAME;
    BOOL                fApiInit = FALSE;
    int                 tid;

    // Adjust task priorities of system tasks

    /* shell task is normally set to priority 1 which could disturb
     * openPOWERLINK if long-running commands are entered. Therefore
     * we lower the performance to 20
     */
    tid = taskIdSelf();
    printf ("Task ID: %d\n", tid);
    taskPrioritySet(tid, 20);

    /* The priority of the network stack task has to be increased (default:50)
     * in order to get network packets in time!
     */
    if ((tid = taskNameToId("tNet0")) != -1 )
    {
        taskPrioritySet(tid, 5);
    }

    // Initialize high-resolution timer library
    hrtimer_init(EPL_TASK_PRIORITY_HRTIMER, EPL_TASK_STACK_SIZE);

    // get node ID from insmod command line
    EplApiInitParam.m_uiNodeId = uiNodeId_g;

    if (EplApiInitParam.m_uiNodeId == EPL_C_ADR_INVALID)
    {   // invalid node ID set
        // set default node ID
        EplApiInitParam.m_uiNodeId = NODEID;
    }

    uiNodeId_g = EplApiInitParam.m_uiNodeId;

    // calculate IP address
    EplApiInitParam.m_dwIpAddress = (0xFFFFFF00 & IP_ADDR) |
                                    EplApiInitParam.m_uiNodeId;

    EplApiInitParam.m_fAsyncOnly = FALSE;

    // store the specified device name
    EplApiInitParam.m_HwParam.m_pszDevName = pszEthName;
    EplApiInitParam.m_HwParam.m_uiDevNumber = uiDevNumber;

    EplApiInitParam.m_uiSizeOfStruct = sizeof (EplApiInitParam);
    EPL_MEMCPY(EplApiInitParam.m_abMacAddress, abMacAddr,
               sizeof (EplApiInitParam.m_abMacAddress));
    EplApiInitParam.m_dwFeatureFlags = (DWORD) ~0UL;
    EplApiInitParam.m_dwCycleLen = uiCycleLen_g;  // required for error detection
    EplApiInitParam.m_uiIsochrTxMaxPayload = 100; // const
    EplApiInitParam.m_uiIsochrRxMaxPayload = 100; // const
    EplApiInitParam.m_dwPresMaxLatency = 50000;   // const; only required for IdentRes
    EplApiInitParam.m_uiPreqActPayloadLimit = 36; // required for initialisation (+28 bytes)
    EplApiInitParam.m_uiPresActPayloadLimit = 36; // required for initialisation of Pres frame (+28 bytes)
    EplApiInitParam.m_dwAsndMaxLatency = 150000;  // const; only required for IdentRes
    EplApiInitParam.m_uiMultiplCycleCnt = 0;      // required for error detection
    EplApiInitParam.m_uiAsyncMtu = 1500;          // required to set up max frame size
    EplApiInitParam.m_uiPrescaler = 2;            // required for sync
    EplApiInitParam.m_dwLossOfFrameTolerance = 500000;
    EplApiInitParam.m_dwAsyncSlotTimeout = 3000000;
    EplApiInitParam.m_dwWaitSocPreq = 0;
    EplApiInitParam.m_dwDeviceType = (DWORD) ~0UL;      // NMT_DeviceType_U32
    EplApiInitParam.m_dwVendorId = (DWORD) ~0UL;        // NMT_IdentityObject_REC.VendorId_U32
    EplApiInitParam.m_dwProductCode = (DWORD) ~0UL;     // NMT_IdentityObject_REC.ProductCode_U32
    EplApiInitParam.m_dwRevisionNumber = (DWORD) ~0UL;  // NMT_IdentityObject_REC.RevisionNo_U32
    EplApiInitParam.m_dwSerialNumber = (DWORD) ~0UL;    // NMT_IdentityObject_REC.SerialNo_U32
    EplApiInitParam.m_dwSubnetMask = SUBNET_MASK;
    EplApiInitParam.m_dwDefaultGateway = 0;
    EPL_MEMCPY(EplApiInitParam.m_sHostname, sHostname, sizeof(EplApiInitParam.m_sHostname));
    EplApiInitParam.m_uiSyncNodeId = EPL_C_ADR_SYNC_ON_SOA; // for fSyncOnPrcNode==TRUE, this means last PRC node
    EplApiInitParam.m_fSyncOnPrcNode = TRUE;

    // set callback functions
    EplApiInitParam.m_pfnCbEvent = AppCbEvent;
    EplApiInitParam.m_pfnCbSync  = AppCbSync;
    EplApiInitParam.m_pfnObdInitRam = EplObdInitRam;

    printf("\n\n Hello, I'm a VxWorks POWERLINK node running as %s!\n"
           "(build: %s / %s)\n\n",
            (uiNodeId_g == EPL_C_ADR_MN_DEF_NODE_ID ?
                "Managing Node" : "Controlled Node"),
            __DATE__, __TIME__);

    // initialize POWERLINK stack
    EplRet = EplApiInitialize(&EplApiInitParam);
    if(EplRet != kEplSuccessful)
    {
        goto Exit;
    }
    fApiInit = TRUE;

    // set CDC filename
    EplRet = EplApiSetCdcFilename(pszCdcFilename_g);
    if(EplRet != kEplSuccessful)
    {
    	printf ("Error set cdc filename!\n");
        goto Exit;
    }

    // initialize application
    printf ("Initializing openPOWERLINK application...\n");
    EplRet = AppInit();
    if(EplRet != kEplSuccessful)
    {
        printf("ApiInit() failed!\n");
        goto Exit;
    }

    // initialize process image
    printf("Initializing process image...\n");
    printf("Size of input process image: %ld\n", sizeof(AppProcessImageIn_g));
    printf("Size of output process image: %ld\n", sizeof (AppProcessImageOut_g));
    AppProcessImageCopyJob_g.m_fNonBlocking = FALSE;
    AppProcessImageCopyJob_g.m_uiPriority = 0;
    AppProcessImageCopyJob_g.m_In.m_pPart = &AppProcessImageIn_g;
    AppProcessImageCopyJob_g.m_In.m_uiOffset = 0;
    AppProcessImageCopyJob_g.m_In.m_uiSize = sizeof (AppProcessImageIn_g);
    AppProcessImageCopyJob_g.m_Out.m_pPart = &AppProcessImageOut_g;
    AppProcessImageCopyJob_g.m_Out.m_uiOffset = 0;
    AppProcessImageCopyJob_g.m_Out.m_uiSize = sizeof (AppProcessImageOut_g);

    EplRet = EplApiProcessImageAlloc(sizeof (AppProcessImageIn_g),
                                     sizeof (AppProcessImageOut_g), 2, 2);
    if (EplRet != kEplSuccessful)
    {
        goto Exit;
    }

    EplRet = EplApiProcessImageSetup();
    if (EplRet != kEplSuccessful)
    {
        goto Exit;
    }

    // start the NMT state machine
    EplRet = EplApiExecNmtCommand(kEplNmtEventSwReset);

Exit:
    PRINTF("%s(): returns 0x%X\n", __func__, EplRet);
    if (EplRet != kEplSuccessful)
    {
        if (fApiInit != FALSE)
        {
            EplApiShutdown();
        }

        // Shutdown high-resolution timer library
        hrtimer_shutdown();
        fOpenPowerlinkIsRunning_g = FALSE;
        return -ENODEV;
    }
    else
    {
        fOpenPowerlinkIsRunning_g = TRUE;
        return 0;
    }
}
Beispiel #25
0
static void rootTask(long a0, long a1, long a2, long a3, long a4,
		     long a5, long a6, long a7, long a8, long a9)
{
	int ret;

	traceobj_enter(&trobj);

	traceobj_mark(&trobj, 6);

	ret = taskPrioritySet(taskIdSelf(), 11);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 7);

	sem_id = semMCreate(0xffffffff);
	traceobj_assert(&trobj, sem_id == 0 && errno == S_semLib_INVALID_OPTION);

	traceobj_mark(&trobj, 8);

	sem_id = semMCreate(SEM_Q_PRIORITY|SEM_DELETE_SAFE|SEM_INVERSION_SAFE);
	traceobj_assert(&trobj, sem_id != 0);

	traceobj_mark(&trobj, 9);

	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 10);

	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 11);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 12);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 13);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == ERROR && errno == S_semLib_INVALID_OPERATION);

	traceobj_mark(&trobj, 14);

	ret = semTake(sem_id, WAIT_FOREVER);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 15);

	ret = taskSuspend(taskIdSelf());
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 16);

	ret = semGive(sem_id);
	traceobj_assert(&trobj, ret == OK);

	traceobj_mark(&trobj, 17);

	traceobj_exit(&trobj);
}
Beispiel #26
0
/*********************************************************************
*
* recovery, based on the cmd code decides what recovery action 
*		to perform.
*
*					Author Greg Brissey 12-7-94
*/
void recovery(EXCEPTION_MSGE *msge)
{
   char *token;
   int len;
   int cmd;
   int i,nMsg2Read;
   int bytes;
   EXCEPTION_MSGE discardMsge;
   extern int systemConRestart();
   static void resetSystem();
   static void resetNameBufs();

   /* reset STM & ADC Intrp MsgQ to standard  msgQ, encase they have been switched  */
   stmRestoreMsgQ(pTheStmObject);

   switch( msge->exceptionType )
   {
      case PANIC:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_PANIC,NULL,NULL);
#endif
    		errLogRet(LOGIT,debugInfo,
       		"phandler: Panic Error: %d", msge->reportEvent);
		break;

      case WARNING_MSG:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_WARNMSG,NULL,NULL);
#endif
  	        DPRINT2(0,"WARNING: doneCode: %d, errorCode: %d\n",
			msge->exceptionType,msge->reportEvent);
    		/* errLogRet(LOGIT,debugInfo,
       		"phandler: Warning Message: %d", msge->reportEvent); */
                statMsg.Status = msge->exceptionType;
                statMsg.Event = msge->reportEvent; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);
		break;

      case SOFT_ERROR:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_SOFTERROR,NULL,NULL);
#endif
		update_acqstate( ACQ_IDLE );

  	        DPRINT2(0,"SOFT_ERROR: doneCode: %d, errorCode: %d\n",
			msge->exceptionType,msge->reportEvent);
    		/* errLogRet(LOGIT,debugInfo,
       		"phandler: Soft Error: %d", msge->reportEvent); */
                statMsg.Status = msge->exceptionType;
                statMsg.Event = msge->reportEvent; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);
		break;

      case EXP_ABORTED:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_EXPABORTED,NULL,NULL);
#endif
		stmItrpDisable(pTheStmObject, STM_ALLITRPS);
  	        DPRINT(0,"Exp. Aborted");

      case HARD_ERROR:

#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_HARDERROR,NULL,NULL);
#endif
  	        DPRINT1(0,"HARD_ERROR: doneCode: %d, errorCode: %d\n", msge->reportEvent);

		AbortExp(msge);

		fifoCloseLog(pTheFifoObject);
  	        DPRINT(0,"Done");
		break;
		

      case INTERACTIVE_ABORT:

#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_HARDERROR,NULL,NULL);
#endif
  	        DPRINT1(0,"INTERACTIVE_ABORT: doneCode: %d, errorCode: %d\n", msge->reportEvent);

		AbortExp(msge);

		fifoCloseLog(pTheFifoObject);
  	        DPRINT(0,"Done");
		break;


      case EXP_HALTED:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_EXPHALTED,NULL,NULL);
#endif
		stmItrpDisable(pTheStmObject, STM_ALLITRPS);

                statMsg.Status = msge->exceptionType;
                statMsg.Event = msge->reportEvent; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);

    		errLogRet(LOGIT,debugInfo,
       		"phandler: Exp. Halted: %d", msge->reportEvent);
		/* 
                   Based on the premise the user now has achieve the S/N
	           or whatever from data that has already been obtained
                   therefore there is no need to wait for any data to 
		   be acquired. I.E. Halt Experiment with extreme prejudice!
                */

                /* reprogram HSlines, ap registers to safe state */
                reset2SafeState( msge->exceptionType );

                resetSystem();  /* reset fifo, disable intrps, reset tasks & buffers */

		update_acqstate( ACQ_IDLE );

  	        DPRINT2(0,"stmHaltCode: doneCode: %d, errorCode: %d\n",
			msge->exceptionType,msge->reportEvent);
		stmHaltCode(pTheStmObject,(int) msge->exceptionType, 
				(int) msge->reportEvent);
   		DPRINT(0,"EXP_HALTED: lower priority below upLinker\n");
                taskPrioritySet(pHandlerTid,(UPLINKER_TASK_PRIORITY+1));  
   	        taskPrioritySet(pHandlerTid,pHandlerPriority);  

  	        DPRINT(0,"wait4DowninkerReady");
		wait4DownLinkerReady();	/* let downlinker become ready, then delete any left over buffers */

                resetNameBufs();   /* free all named buffers */

   		stmInitial(pTheStmObject, 1, 1024, pUpLinkMsgQ, 0);

	        clrDwnLkAbort();

                wait4SystemReady(); /* pend till all activities are complete */

  	        DPRINT(0,"enableInterrupts");
		enableInterrupts();

	        /* now inform Expproc System is Ready */
                statMsg.Status = SYSTEM_READY; /* Console Ready  */
                statMsg.Event = 0; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);

		update_acqstate( ACQ_IDLE );
	        getstatblock();
		if (pTheTuneObject != NULL)
		  semGive( pTheTuneObject->pSemAccessFIFO );

		break;


      case STOP_CMPLT:
                /* the monitor set the SA_Criteria value,
		   when the upLinker obtained a FID that meet this
		   Criteria the upLinker sent this msge here and
		   then blocked itself
                  Our job is to
	          1. Foward the Stopped msge to Host
	          2. reset hardware
                  3. put hardware into a safe state
		  4. call stmSA, clears upLinker msgQ, send SA msge
	          5. reset SA_Criteria back to Zero
		  6. give the semaphore to restart upLinker
		  7. reset update task
		  8. reset parser task
	          9. Free the buffers
	         10. Re-enable Interrupts 
		*/

#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_STOPCMPLT,NULL,NULL);
#endif
                statMsg.Status = msge->exceptionType;
                statMsg.Event = msge->reportEvent; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);

    		errLogRet(LOGIT,debugInfo,
       		"phandler: Exp. Stopped: %d", msge->reportEvent);

                /* reprogram HSlines, ap registers to safe state */
                reset2SafeState( msge->exceptionType );  

                resetSystem();  /* reset fifo, disable intrps, reset tasks & buffers */

  	        DPRINT2(0,"stmHaltCode: doneCode: %d, errorCode: %d\n",
			msge->exceptionType,msge->reportEvent);

 		clearIntrpMsgQ(pTheStmObject);
                semGive(pSemSAStop);   /* release the UpLinker */
		stmHaltCode(pTheStmObject,(int) msge->exceptionType, 
				(int) msge->reportEvent);
  	        /* DPRINT(0,"stmSA"); stmSA(pTheStmObject); */
   		DPRINT(0,"STOP_CMPLT: lower priority below upLinker\n");
                taskPrioritySet(pHandlerTid,(UPLINKER_TASK_PRIORITY+1));  
   	        taskPrioritySet(pHandlerTid,pHandlerPriority);  

		SA_Criteria = 0;
		SA_Mod = 0L;

  	        DPRINT(0,"wait4DowninkerReady");
		wait4DownLinkerReady();	/* let downlinker become ready, then delete any left over buffers */

                resetNameBufs();   /* free all named buffers */

   		stmInitial(pTheStmObject, 1, 1024, pUpLinkMsgQ, 0);

	        clrDwnLkAbort();

                wait4SystemReady(); /* pend till all activities are complete */

  	        DPRINT(0,"enableInterrupts");
		enableInterrupts();

	        /* now inform Expproc System is Ready */
                statMsg.Status = SYSTEM_READY; /* Console Ready  */
                statMsg.Event = 0; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);

		update_acqstate( ACQ_IDLE );
	        getstatblock();
		if (pTheTuneObject != NULL)
		  semGive( pTheTuneObject->pSemAccessFIFO );

		break;

      case LOST_CONN:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_LOSTCONN,NULL,NULL);
#endif
    		errLogRet(LOGIT,debugInfo,
       		"phandler: Host Closed Connection to Console: %d", msge->reportEvent);
		update_acqstate( ACQ_IDLE );
		stmItrpDisable(pTheStmObject, STM_ALLITRPS);
                storeConsoleDebug( SYSTEM_ABORT );
                /* reprogram HSlines, ap registers to safe state */
                reset2SafeState( msge->exceptionType );
                resetSystem();  /* reset fifo, disable intrps, reset tasks & buffers */
		stmReset(pTheStmObject);
		taskDelay(sysClkRateGet()/3);
                resetNameBufs();   /* free all named buffers */
		enableInterrupts();
		if (pTheTuneObject != NULL)
		  semGive( pTheTuneObject->pSemAccessFIFO );
     		taskSpawn("tRestart",50,0,2048,systemConRestart,NULL,
				2,3,4,5,6,7,8,9,10);
	        clrDwnLkAbort();

	        break;

      case ALLOC_ERROR:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_ALLOCERROR,NULL,NULL);
#endif
    		errLogRet(LOGIT,debugInfo,
       		"phandler: Memory Allocation Error: %d", msge->reportEvent);

		update_acqstate( ACQ_IDLE );

                statMsg.Status = HARD_ERROR; /* HARD_ERROR */
                statMsg.Event = msge->reportEvent; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_URGENT);
                

		/* report HARD_ERROR to Recvproc */
  	        DPRINT2(0,"stmHaltCode: doneCode: %d, errorCode: %d\n",
			HARD_ERROR,msge->reportEvent);
		stmHaltCode(pTheStmObject,(int) HARD_ERROR, 
				(int) msge->reportEvent);

                /* reprogram HSlines, ap registers to safe state */
                reset2SafeState( msge->exceptionType );

                resetSystem();  /* reset fifo, disable intrps, reset tasks & buffers */

	      
#ifdef XXXX
                statMsg.Status = WARNING_MSG;
                statMsg.Event = WARNINGS + MEM_ALLOC_ERR; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);
#endif

                resetNameBufs();   /* free all named buffers */

   		stmInitial(pTheStmObject, 1, 1024, pUpLinkMsgQ, 0);

	        clrDwnLkAbort();

  	        DPRINT(0,"enableInterrupts");
		enableInterrupts();

	        /* now inform Expproc System is Ready */
                statMsg.Status = SYSTEM_READY; /* Console Ready  */
                statMsg.Event = 0; /* Error Code */
		msgQSend(pMsgesToHost,(char*) &statMsg,sizeof(statMsg),
					WAIT_FOREVER, MSG_PRI_NORMAL);

	        getstatblock();
		if (pTheTuneObject != NULL)
		  semGive( pTheTuneObject->pSemAccessFIFO );

		break;
      
      case WATCHDOG:
#ifdef INSTRUMENT
        wvEvent(EVENT_PHDLR_WATCHDOG,NULL,NULL);
#endif
		/* Giv'm a bone */
    		errLogRet(LOGIT,debugInfo,
       		"phandler: Watch Dog: %d", msge->reportEvent);
		break;

      default:
		/* Who Cares */
    		errLogRet(LOGIT,debugInfo,
       		"phandler: Invalid Exception Type: %d, Event: %d", 
			msge->exceptionType, msge->reportEvent);
		break;
   }
/*
   nMsg2Read = msgQNumMsgs(pMsgesToPHandlr);
   DPRINT1(-1,"Message in Q: %d\n",nMsg2Read);
*/
   while ( (bytes = msgQReceive(pMsgesToPHandlr, (char*) &msge, sizeof( EXCEPTION_MSGE ), NO_WAIT)) != ERROR )
   {
     DPRINT1(0,"Read %d bytes from Phandler msgQ, (Bogus Errors at this point)\n",bytes);
   }
}
Beispiel #27
0
static void
reset2SafeState( int why )  /* argument is the type of exception */
{
   int pTmpId, TmpPrior;
   int tuneactive = 0;

   DPRINT(1,"reset2SafeState");
   DPRINT(1,"stopAPint");
   pcsAbortSort();     /* parallel channel sort to stop and return to APint() */
   abortAPint();   /* like stopAPint() but also cause the Parser to suspend itself */
   /* stopAPint(); */
   DPRINT(1,"stop downLinker");
   setDwnLkAbort();   /* like stop downLinker and set to dump further download to bit bucket */
   DPRINT(1,"reset2SafeState");
   DPRINT(0,"fifoSetNoStuff\n");
   fifoSetNoStuff(pTheFifoObject);    /* stop the stuffer in it's tracks */
   DPRINT(0,"Disable STM Intrps");
   stmItrpDisable(pTheStmObject, STM_ALLITRPS);
   /* reset fifo Object not to use parallel channels */
   fifoClearPChanId(pTheFifoObject);
   DPRINT(0,"fifoReset");

   /* Keep the MTS gradient amp disabled whenever possible! */
   gpaTuneSet(pTheAutoObject, SET_GPAENABLE, GPA_DISABLE_DELAY);

   /* if an interactive abort do not reset the apbus, thus preventing the 
      all amplifier from going to Pulse Mode, thus amps that are in CW 
      will stay that way. This is/was a lockdisplay/shimming issue.
      Where exiting lock display set all the amps to Pulse Mode or blanked!, 
      then one shimmed and obtain a certain lock level. After su command 
      then amps would go back to CW thus injecting noise and lowing the
      lock level, If use wht directly to shimming they could neer re-attain 
      the lock level they had before.  But when enter and exit lock display 
      the level would jump back up. Thus causing no end of
      confusion....
      Thus for INTERACTIVE_ABORT the reset apbus bit is left out when reseting the FIFO.

      Oooops, but wait, we found an exception (of course), when exiting qtune the 
      reset of the apbus reset all the tune relays back to noraml, now of course 
      this does not happen thus leaving the console in tuning mode. Thus we added the 
      following test isTuneActive() and if it is then a full reset including the apbus
      is done.
   */
   tuneactive = isTuneActive();
   /* DPRINT1(-3,"Is Tune active: %d\n",tuneactive); */
   if ((why != INTERACTIVE_ABORT) || (tuneactive == 1))
      fifoReset(pTheFifoObject, RESETFIFOBRD);  /* this now also clear the Fifo Buffer & restart the Stuffer */
   else
      fifoReset(pTheFifoObject, RESETFIFO | RESETSTATEMACH | RESETTAGFIFO | RESETAPRDBKFIFO ); /* no apbus reset */

   /* set initial value of parallel channel free buffer pointer to null */
   clearParallelFreeBufs();

   DPRINT(0,"Stuff FIFO DIRECTLY with Safe State & Run fifo");
   fifoLoadHsl(pTheFifoObject, STD_HS_LINES, pTheFifoObject->SafeHSLines);
   fifoLoadHsl(pTheFifoObject, EXT_HS_LINES, pTheFifoObject->SafeHSLinesExt);
   /* Each SafeState Code is actually two long words */
   if (numSafeStatCodes > 0)
   {
      /*   WARNING: Does not pend for FF Almost Full, BEWARE !! */
      /*   Should only be used in phandler's reset2SafeState() */
      fifoStuffCode(pTheFifoObject, pSafeStateCodes, numSafeStatCodes);
      fifoStuffCode(pTheFifoObject, pTurnOffSshaCodes, numTurnOffSshaCodes);
      fifoStuffCode(pTheFifoObject, pHaltOpCodes, numHaltOpCodes);
	DPRINT(1,"Ready to start FIFO in reset to safe state\n" );
      fifoStart(pTheFifoObject);
      /* fifoWait4Stop(pTheFifoObject);  /* use BusyWait don't what any other lower priority tasks to run ! */
      fifoBusyWait4Stop(pTheFifoObject);  /* use BusyWait don't what any other lower priority tasks to run ! */
	DPRINT(1,"FIFO wait for stop completes in reset to safe state\n" );
   }
   activate_ssha();
   DPRINT(0,"getnGiveShimMutex\n");  
   /* allow any pending serial Shim commands to finish */
   getnGiveShimMutex();
   DPRINT(0,"getnGiveVTMutex\n");
   /* allow any pending serial VT commands to finish */
   getnGiveVTMutex();

/* Now Bump Priority of DownLiner so that it can Dump
   the remaining Data that SendProc wants to send it */

/* If we lost the connection to the host computer, the downlinker is
   is not going to get any more data; nor should this task (problem
   handler) wait for the downlinker to become ready.    April 1997  */

   DPRINT(0,"dlbFreeAllNotLoading Dyn");
   dlbFreeAllNotLoading(pDlbDynBufs);
   DPRINT(0,"dlbFreeAllNotLoading Fix");
   dlbFreeAllNotLoading(pDlbFixBufs);
   if (why != LOST_CONN)
   {
      pTmpId = taskNameToId("tDownLink");
      taskPriorityGet(pTmpId,&TmpPrior);
      taskPrioritySet(pTmpId,(pHandlerPriority-1));  

      /* downLinker has now A. ran and is suspended, 
			    B. Done and in READY state or
	 		    C. still waiting in a read of a socket
      */

      /* start wdog timeout of 20 seconds */ 
      wdStart(pHandlerWdTimeout,sysClkRateGet() * 20, pHandlerWdISR, 0);

      /* if it is busy and not suspend then wait till 
      /* it is Ready or Suspended, or Time-Out */
      while (downLinkerIsActive() &&  !taskIsSuspended(pTmpId) && !pHandlerTimeout)
            taskDelay(1);  /* wait one tick , 16msec */

      wdCancel(pHandlerWdTimeout);

      if (taskIsSuspended(pTmpId))
      {
        taskResume(pTmpId);
        wait4DownLinkerReady();
      }
      taskPrioritySet(pTmpId,TmpPrior);
      DPRINT(0,"downlinker resynchronized\n");
   }
   DPRINT(0,"dlbFreeAll Dyn");
   dlbFreeAll(pDlbDynBufs);
   DPRINT(0,"dlbFreeAll Fix");
   dlbFreeAll(pDlbFixBufs);

   /* 
     Now Bump Priority of Parser so that it can Finish Up  
     We don't have to worry as much about the state of the parser
     since it will completely restarted very soon. 
   */

   pTmpId = taskNameToId("tParser");
   taskPriorityGet(pTmpId,&TmpPrior);
   taskPrioritySet(pTmpId,(pHandlerPriority-1));  
   if (taskIsSuspended(pTmpId))
   {
     taskResume(pTmpId);
     wait4ParserReady();
   }
   taskPrioritySet(pTmpId,TmpPrior);
   resetAPint();
   DPRINT(0,"A-code parser resynchronized\n");

   /* Parser might of made a buffer ready to stuff, so better clear it just incase */
   if (why != INTERACTIVE_ABORT)
      fifoReset(pTheFifoObject, RESETFIFOBRD);  /* this now also clear the Fifo Buffer & restart the Stuffer */
   else
      fifoReset(pTheFifoObject, RESETFIFO | RESETSTATEMACH | RESETTAGFIFO | RESETAPRDBKFIFO ); /* no apbus reset */
   
   return;
}