Exemplo n.º 1
0
/*
 * plc_LoopWait()
 *
 * Description:
 *  Returns FALSE if a slip is detected.
 */ 
pwr_tBoolean plc_LoopWait (
    int		*WaitResult,     /* Set to 1 when Event */
    pwr_tVaxTime	*DeltaTime,
    pwr_tVaxTime	*NextTime,
    unsigned long Event
)
{
    pwr_tStatus sts;
    pwr_tVaxTime NextLoop, UpTime, DiffTime;
    pwr_tBoolean Result;

    sts = lib$add_times(NextTime, DeltaTime, &NextLoop);
    *NextTime = NextLoop;
    ker$get_uptime(&sts, &UpTime);
    
    sts = lib$sub_times(NextTime, &UpTime, &DiffTime);
    if (sts == LIB$_NEGTIM) 
	Result = FALSE; /* Slip */
    else  if (NextTime->high == UpTime.high && NextTime->low == UpTime.low)
	Result = TRUE; /* Equal Times */
    else {
	if (Event)
	    ker$wait_any(&sts, WaitResult, &DiffTime, Event);
	else
	    ker$wait_any(&sts, WaitResult, &DiffTime);
	Result = TRUE;
    }	

    return Result;
}
Exemplo n.º 2
0
static void
waitTime (
  pwr_tTime		*t
)
{
  pwr_tStatus		sts;
  pwr_tTime		now;
  pwr_tTime		then = *t;
  char tims[24];
  short len;
  struct dsc$descriptor_s tims_desc = {
    sizeof(tims)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S,};

#if 0
  subTime(&then, nowTime(&now));
#endif

  if ((int)then.tv_sec > 0 || ((int)then.tv_sec == 0 && then.tv_nsec > 0)) {
#if defined OS_VMS || defined OS_ELN
    int			tv_nsec;
    int			vmstime[2];
    int			multiplier = -10000000;	      /* Used to convert 1 s to 100 ns, delta time.  */
    static pwr_tTime	tick = {0, 10000000};

    addTime(&then, &tick);
    tv_nsec = -then.tv_nsec/100;   /* Convert to 100 ns.  */
    sts = lib$emul(&then.tv_sec, &multiplier, &tv_nsec, vmstime);

#if defined OS_VMS
    tims_desc.dsc$a_pointer = tims;
    sys$asctim( &len, &tims_desc, vmstime, 0);
    tims[len] = '\0';
    printf("  %s\n", tims);
#if 0
    sts = sys$clref(timerFlag);
    sts = sys$setimr(timerFlag, vmstime, 0, 0, 0);
    sts = sys$waitfr(timerFlag);
#endif
#elif defined OS_ELN
    eln$time_string(tims, vmstime);
    tims[23] = '\0';
    printf("  %s\n", tims);
#if 0
    ker$wait_any(&sts, NULL, vmstime);
#endif
#endif

#elif defined OS_LYNX
    pwr_tTime rmt;

    nanosleep(&then, &rmt);
#endif
  }
}
Exemplo n.º 3
0
void time_Sleep( float time)
{
#ifdef OS_VMS
	int sts;
        sts = lib$wait(&time);
#elif OS_ELN
	LARGE_INTEGER	l_time;

	l_time.high = -1;	
	l_time.low = - time * 10000000;	
	ker$wait_any( NULL, NULL, &l_time);
#elif defined OS_POSIX
	pwr_tDeltaTime	p_time;
	struct timespec ts;

	time_FloatToD( &p_time, time);
	ts.tv_sec = p_time.tv_sec;
	ts.tv_nsec = p_time.tv_nsec;
	nanosleep( &ts, NULL);
#endif
}
Exemplo n.º 4
0
static void
waitClock (
  time_tClock		diff,
  int			*tmo_ms
)
{
#if defined OS_VMS || defined OS_ELN
    pwr_tStatus		sts;
    int			sec;
    int			nsec;
    int			vmstime[2];
    int			multiplier = -10000000;	      /* Used to convert 1 s to 100 ns, delta time.  */

    sec = diff / CLK_TCK;
    nsec = - (diff % CLK_TCK * 10000000 / CLK_TCK);   /* Convert to 100 ns.  */
    sts = lib$emul(&sec, &multiplier, &nsec, vmstime);

# if defined OS_VMS
    sts = sys$clref(timer_flag);
    sts = sys$setimr(timer_flag, vmstime, 0, 0, 0);
    sts = sys$waitfr(timer_flag);
# elif defined OS_ELN
    ker$wait_any(&sts, NULL, vmstime);
# endif

#elif defined OS_POSIX
//    pwr_tTime  rmt;
//    pwr_tTime  wait;
    static int tics_per_sec = 0;

    if (tics_per_sec == 0) {
      tics_per_sec = sysconf(_SC_CLK_TCK);
    }
//    printf("waitClock: %d\n", diff);
//    time_ClockToD(NULL, (pwr_tDeltaTime *)&wait, diff);
    *tmo_ms = diff * 1000 / tics_per_sec;
//    *tmo_ms = wait.tv_sec * 1000 + wait.tv_nsec / 1000000;
//    nanosleep(&wait, &rmt);
#endif
}
Exemplo n.º 5
0
pwr_tStatus sutl_sleep( float time)
{
#ifdef OS_VMS
        int sts;
        sts = lib$wait(&time);
#elif OS_ELN
        LARGE_INTEGER   l_time;

        l_time.high = -1;
        l_time.low = - time * 10000000;
        ker$wait_any( NULL, NULL, &l_time);
#elif defined(OS_LYNX) || defined (OS_LINUX)
        pwr_tDeltaTime  p_time;
	struct timespec p_time_ts;

        time_FloatToD( &p_time, time);

	p_time_ts.tv_sec = p_time.tv_sec;
	p_time_ts.tv_nsec = p_time.tv_nsec;
        nanosleep( &p_time_ts, NULL);
#endif

        return 1;
}
Exemplo n.º 6
0
pwr_tUInt32 bck_WaitBackup (
		void *context,
		pwr_tBoolean timeout)
{
  pwr_tUInt32 sts;
  pwr_tObjid objid;
  pwr_tInt32 c;
  pwr_tTime t;
  pwr_tVaxTime tmo;
  pwr_tVaxTime tmptime;
  pwr_sClass_Backup_Conf *backup_confp;	/* Backup_Conf object pointer */
  $DESCRIPTOR (timeunitdsc, "0 0:0:0.1");	/* 0.1 second units */
  int cycletime;

#ifdef OS_ELN
  pwr_tInt32 res;
  pwr_tVaxTime *tmop;
#endif

#ifdef OS_VMS
  $DESCRIPTOR (efcname, BCK_EFC_NAME);
#endif

/*
 * Initialize
 */

#ifdef OS_ELN
  if (!areas_mapped) {
    BCK_MAP_AREAS;
    areas_mapped = TRUE;
  }
#endif

/*
 * Find the local Backup_Conf object
 */

  sts = gdh_GetClassList (pwr_cClass_Backup_Conf, &objid);
  while (ODD (sts)) {
    sts = gdh_ObjidToPointer (objid, (pwr_tAddress *)&backup_confp);
    if (ODD (sts)) break;
    sts = gdh_GetNextObject (objid, &objid);
  }
  if (EVEN (sts)) return sts;		/* Something wrong, quit */

/*
 * Pick up argument information
 */

  if (context == NULL) time_GetTime(&t);
  else {
    t = *(pwr_tTime *)context;
    free (context);
  }

#ifdef OS_ELN
  tmop = NULL;
#else
  timed_out = FALSE;  
  sts = sys$ascefc (BCK_EFC, &efcname, 0, 0);
  if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif

  if (timeout) {
    cycletime = backup_confp->CycleSlow * 2;
    if (cycletime == 0) cycletime = BCK_DEFAULT_SLOW * 2;

#ifdef OS_ELN
    tmo = eln$time_value (&timeunitdsc);
#else
    sts = sys$bintim (&timeunitdsc, &tmo);
    if (EVEN (sts)) lib$signal (sts);		/* BUG, should not happen */
#endif

    lib$mult_delta_time (
		&cycletime,		/* multiplier */
		&tmo);			/* delta_time (modified) */
    sys$gettim (&tmptime);
    lib$add_times (&tmo, &tmptime, &tmo); /* Make absolute time */

#ifdef OS_ELN
    tmop = &tmo;
#else
    sts = sys$setimr (BCK_WRITE_DONE, &tmo, &astrtn, 4711, 0);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
#endif
  }

/*
 * Loop, and wait for things to happen
 */

  while (TRUE) {
#ifdef OS_ELN
    ker$clear_event (NULL, bck_write_done);
    ker$wait_any (NULL, &res, tmop, bck_write_done);

    /* Check for timeout */

    if (res == 0) return SS$_TIMEOUT;
#else

    sts = sys$clref (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */
    sts = sys$waitfr (BCK_WRITE_DONE);
    if (EVEN (sts)) lib$signal (sts);			/* BUG */

    /* Check for timeout */

    if (timed_out) return SS$_TIMEOUT;

#endif

    /* Check if both cycles done */

    if (time_Acomp(&backup_confp->ObjTimeSlow, &t) < 0) 
        continue;
    if (time_Acomp(&backup_confp->ObjTimeFast, &t) < 0) 
        continue;

    break;

  } /* Loop */

#ifdef OS_VMS
  sys$cantim (4711, 0);
#endif

  return 1;	/* Done. */

} /* bck_WaitBackup */