diff --git a/sim_timer.c b/sim_timer.c index 182a1270..d5d5dc1f 100644 --- a/sim_timer.c +++ b/sim_timer.c @@ -85,7 +85,7 @@ #include #define SIM_INTERNAL_CLK (SIM_NTIMERS+(1<<30)) -#define SIM_INTERNAL_UNIT sim_timer_units[SIM_NTIMERS] +#define SIM_INTERNAL_UNIT sim_internal_timer_unit #ifndef MIN #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif @@ -146,6 +146,8 @@ t_bool sim_idle_enab = FALSE; /* global flag */ volatile t_bool sim_idle_wait = FALSE; /* global flag */ static int32 sim_calb_tmr = -1; /* the system calibrated timer */ +static int32 sim_calb_tmr_last = -1; /* shadow value when at sim> prompt */ +static double sim_inst_per_sec_last = 0; /* shadow value when at sim> prompt */ static uint32 sim_idle_rate_ms = 0; static uint32 sim_os_sleep_min_ms = 0; @@ -745,6 +747,7 @@ static uint32 rtc_clock_calib_backwards[SIM_NTIMERS+1] = { 0 };/* Calibrations s UNIT sim_timer_units[SIM_NTIMERS+1]; /* one for each timer and one for an */ /* internal clock if no clocks are registered */ +UNIT sim_internal_timer_unit; /* Internal calibration timer */ UNIT sim_throttle_unit; /* one for throttle */ t_stat sim_throt_svc (UNIT *uptr); @@ -811,10 +814,8 @@ if (!uptr) uptr = sim_clock_unit[tmr]; sim_debug (DBG_CAL, &sim_timer_dev, "_sim_rtcn_init_unit(unit=%s, time=%d, tmr=%d)\n", sim_uname(uptr), time, tmr); if (uptr) { - if (!sim_clock_unit[tmr]) { - sim_clock_unit[tmr] = uptr; - sim_clock_cosched_queue[tmr] = QUEUE_LIST_END; - } + if (!sim_clock_unit[tmr]) + sim_register_clock_unit_tmr (uptr, tmr); } rtc_clock_start_gtime[tmr] = sim_gtime(); rtc_rtime[tmr] = sim_os_msec (); @@ -995,15 +996,16 @@ int tmr; uint32 clock_start, clock_last, clock_now; sim_debug (DBG_TRC, &sim_timer_dev, "sim_timer_init()\n"); -for (tmr=0; tmr= SIM_NTIMERS))) return FALSE; tnow = sim_timenow_double(); -if (sim_catchup_ticks && - (!rtc_clock_catchup_eligible[tmr])) { +if (!rtc_clock_catchup_eligible[tmr]) { rtc_clock_catchup_base_time[tmr] = tnow; rtc_clock_ticks_tot[tmr] += rtc_clock_ticks[tmr]; rtc_clock_ticks[tmr] = 0; @@ -1975,6 +1976,7 @@ if (tmr == SIM_NTIMERS) { /* None found? */ sim_calb_tmr = SIM_NTIMERS; sim_debug (DBG_CAL, &sim_timer_dev, "_rtcn_configure_calibrated_clock() - Starting Internal Calibrated Timer at %dHz\n", sim_int_clk_tps); SIM_INTERNAL_UNIT.action = &sim_timer_clock_tick_svc; + SIM_INTERNAL_UNIT.flags = UNIT_DIS | UNIT_IDLE; sim_activate_abs (&SIM_INTERNAL_UNIT, 0); sim_rtcn_init_unit (&SIM_INTERNAL_UNIT, (CLK_INIT*CLK_TPS)/sim_int_clk_tps, SIM_INTERNAL_CLK); } @@ -2007,6 +2009,10 @@ static t_stat sim_timer_clock_reset (DEVICE *dptr) { sim_debug (DBG_TRC, &sim_timer_dev, "sim_timer_clock_reset()\n"); _rtcn_configure_calibrated_clock (sim_calb_tmr); +if (sim_switches & SWMASK ('P')) { + sim_cancel (&SIM_INTERNAL_UNIT); + sim_calb_tmr = -1; + } return SCPE_OK; } @@ -2047,7 +2053,7 @@ for (tmr=0; tmr<=SIM_NTIMERS; tmr++) { sim_cancel (&sim_timer_units[tmr]); if (rtc_hz[tmr]) sim_activate (sim_clock_unit[tmr], rtc_currd[tmr]); - /* Move coschedule'd units to the standard event queue */ + /* Move coscheduled units to the standard event queue */ accum = 1; while (sim_clock_cosched_queue[tmr] != QUEUE_LIST_END) { UNIT *cptr = sim_clock_cosched_queue[tmr]; @@ -2061,7 +2067,9 @@ for (tmr=0; tmr<=SIM_NTIMERS; tmr++) { } } } -sim_cancel (&SIM_INTERNAL_UNIT); /* Make sure Internal Timer is stopped */ +sim_cancel (&SIM_INTERNAL_UNIT); /* Make sure Internal Timer is stopped */ +sim_calb_tmr_last = sim_calb_tmr; /* Save calibrated timer value for display */ +sim_inst_per_sec_last = sim_timer_inst_per_sec (); /* Save execution rate for display */ sim_calb_tmr = -1; #if defined(SIM_ASYNCH_CLOCKS) pthread_mutex_lock (&sim_timer_lock); @@ -2135,7 +2143,7 @@ double inst_delay_d, inst_per_sec; AIO_VALIDATE; /* If this is a clock unit, we need to schedule the related timer unit instead */ -for (tmr=0; tmr= SIM_NTIMERS)) + return SCPE_IERR; + } if (NULL == uptr) { /* deregistering? */ while (sim_clock_cosched_queue[tmr] != QUEUE_LIST_END) { UNIT *uptr = sim_clock_cosched_queue[tmr];