From 89e372ba921c4f5a6aaa291c19c3d2b40af52ad3 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 22 Nov 2016 01:24:26 -0800 Subject: [PATCH] TIMER: Restore functionality for clocks devices that don't use sim_activate_after Clock devices which call sim_register_clock_unit or sim_register_clock_unit_tmr are best behaved if they use sim_activate_after to schedule their tick events. --- scp.c | 2 ++ sim_defs.h | 3 ++- sim_timer.c | 7 +++++++ sim_timer.h | 1 + sim_tmxr.c | 2 ++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/scp.c b/scp.c index c2a5ba93..464ee6a7 100644 --- a/scp.c +++ b/scp.c @@ -8899,6 +8899,8 @@ return reason; t_stat sim_activate (UNIT *uptr, int32 event_time) { +if (uptr->dynflags & UNIT_TMR_UNIT) + return sim_timer_activate (uptr, event_time); return _sim_activate (uptr, event_time); } diff --git a/sim_defs.h b/sim_defs.h index 35408340..28692405 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -595,7 +595,8 @@ struct UNIT { #define UNIT_TM_POLL 0000002 /* TMXR Polling unit */ #define UNIT_NO_FIO 0000004 /* fileref is NOT a FILE * */ #define UNIT_DISK_CHK 0000010 /* disk data debug checking (sim_disk) */ -#define UNIT_V_DF_TAPE 4 /* Bit offset for Tape Density reservation */ +#define UNIT_TMR_UNIT 0000020 /* Unit registered as a calibrated timer */ +#define UNIT_V_DF_TAPE 5 /* Bit offset for Tape Density reservation */ #define UNIT_S_DF_TAPE 3 /* Bits Reserved for Tape Density */ struct BITFIELD { diff --git a/sim_timer.c b/sim_timer.c index b31cc91f..8271039b 100644 --- a/sim_timer.c +++ b/sim_timer.c @@ -2033,6 +2033,12 @@ if (0 == inst_per_sec) return inst_per_sec; } +t_stat sim_timer_activate (UNIT *uptr, int32 interval) +{ +AIO_VALIDATE; +return sim_timer_activate_after (uptr, (uint32)((interval * 1000000.0) / sim_timer_inst_per_sec ())); +} + t_stat sim_timer_activate_after (UNIT *uptr, uint32 usec_delay) { int inst_delay, tmr; @@ -2109,6 +2115,7 @@ t_stat sim_register_clock_unit_tmr (UNIT *uptr, int32 tmr) if (NULL == sim_clock_unit[tmr]) sim_clock_cosched_queue[tmr] = QUEUE_LIST_END; sim_clock_unit[tmr] = uptr; +uptr->dynflags |= UNIT_TMR_UNIT; sim_timer_units[tmr].flags = (sim_clock_unit[tmr] ? 0 : UNIT_DIS | UNIT_IDLE); sim_tick_units[tmr].flags = (sim_clock_unit[tmr] ? 0 : UNIT_DIS); return SCPE_OK; diff --git a/sim_timer.h b/sim_timer.h index 35d6e503..d4b247b6 100644 --- a/sim_timer.h +++ b/sim_timer.h @@ -128,6 +128,7 @@ uint32 sim_os_ms_sleep_init (void); void sim_start_timer_services (void); void sim_stop_timer_services (void); t_stat sim_timer_change_asynch (void); +t_stat sim_timer_activate (UNIT *uptr, int32 interval); t_stat sim_timer_activate_after (UNIT *uptr, uint32 usec_delay); int32 sim_timer_activate_time (UNIT *uptr); t_stat sim_register_clock_unit (UNIT *uptr); diff --git a/sim_tmxr.c b/sim_tmxr.c index 80e2c8ac..21b2c04b 100644 --- a/sim_tmxr.c +++ b/sim_tmxr.c @@ -3849,6 +3849,8 @@ return SCPE_OK; t_stat tmxr_activate (UNIT *uptr, int32 interval) { +if (uptr->dynflags & UNIT_TMR_UNIT) + return sim_timer_activate (uptr, interval); #if defined(SIM_ASYNCH_MUX) if ((!(uptr->dynflags & UNIT_TM_POLL)) || (!sim_asynch_enabled)) {