int32 todr_rd (void) { TOY *toy = (TOY *)clk_unit.filebuf; struct timespec base, now, val; if ((fault_PC&0xFFFE0000) == 0x20040000) { /* running from ROM? */ sim_debug (DBG_REG, &clk_dev, "todr_rd(ROM) - TODR=0x%X\n", todr_reg); return todr_reg; /* return counted value for ROM diags */ } if (0 == todr_reg) { /* clock running? */ sim_debug (DBG_REG, &clk_dev, "todr_rd(Not Running) - TODR=0x%X\n", todr_reg); return todr_reg; } /* Maximum number of seconds which can be represented as 10ms ticks in the 32bit TODR. This is the 33bit value 0x100000000/100 to get seconds */ #define TOY_MAX_SECS (0x40000000/25) sim_rtcn_get_time(&now, TMR_CLK); /* get curr time */ base.tv_sec = toy->toy_gmtbase; base.tv_nsec = toy->toy_gmtbasemsec * 1000000; sim_timespec_diff (&val, &now, &base); if (val.tv_sec >= TOY_MAX_SECS) { /* todr overflowed? */ sim_debug (DBG_REG, &clk_dev, "todr_rd(Overflowed) - TODR=0x%X\n", 0); return todr_reg = 0; /* stop counting */ } sim_debug (DBG_REG, &clk_dev, "todr_rd() - TODR=0x%X\n", (int32)(val.tv_sec*100 + val.tv_nsec/10000000)); return (int32)(val.tv_sec*100 + val.tv_nsec/10000000); /* 100hz Clock Ticks */ }
int32 todr_rd (void) { TOY *toy = (TOY *)clk_unit.filebuf; struct timespec base, now, val; if ((fault_PC&0xFFFE0000) == 0x20040000) /* running from ROM? */ return todr_reg; /* return counted value for ROM diags */ if (0 == todr_reg) /* clock running? */ return todr_reg; /* Maximum number of seconds which can be represented as 10ms ticks in the 32bit TODR. This is the 33bit value 0x100000000/100 to get seconds */ #define TOY_MAX_SECS (0x40000000/25) clock_gettime(CLOCK_REALTIME, &now); /* get curr time */ base.tv_sec = toy->toy_gmtbase; base.tv_nsec = toy->toy_gmtbasemsec * 1000000; sim_timespec_diff (&val, &now, &base); if (val.tv_sec >= TOY_MAX_SECS) /* todr overflowed? */ return todr_reg = 0; /* stop counting */ return (int32)(val.tv_sec*100 + val.tv_nsec/10000000); /* 100hz Clock Ticks */ }
int32 todr_rd (void) { TOY *toy = (TOY *)clk_unit.filebuf; struct timespec base, now, val; clock_gettime(CLOCK_REALTIME, &now); /* get curr time */ base.tv_sec = toy->toy_gmtbase; base.tv_nsec = toy->toy_gmtbasemsec * 1000000; sim_timespec_diff (&val, &now, &base); return (int32)(val.tv_sec*100 + val.tv_nsec/10000000); /* 100hz Clock Ticks */ }
int32 todr_rd (void) { TOY *toy = (TOY *)clk_unit.filebuf; struct timespec base, now, val; sim_rtcn_get_time(&now, TMR_CLK); /* get curr time */ base.tv_sec = toy->toy_gmtbase; base.tv_nsec = toy->toy_gmtbasemsec * 1000000; sim_timespec_diff (&val, &now, &base); sim_debug (TMR_DB_TODR, &clk_dev, "todr_rd() - TODR=0x%X - %s\n", (int32)(val.tv_sec*100 + val.tv_nsec/10000000), todr_fmt_vms_todr ((int32)(val.tv_sec*100 + val.tv_nsec/10000000))); return (int32)(val.tv_sec*100 + val.tv_nsec/10000000); /* 100hz Clock Ticks */ }
void todr_wr (int32 data) { TOY *toy = (TOY *)clk_unit.filebuf; struct timespec now, val, base; /* Save the GMT time when set value was 0 to record the base for future read operations in "battery backed-up" state */ if (-1 == clock_gettime(CLOCK_REALTIME, &now)) /* get curr time */ return; /* error? */ val.tv_sec = ((uint32)data) / 100; val.tv_nsec = (((uint32)data) % 100) * 10000000; sim_timespec_diff (&base, &now, &val); /* base = now - data */ toy->toy_gmtbase = (uint32)base.tv_sec; toy->toy_gmtbasemsec = base.tv_nsec/1000000; }
void todr_wr (int32 data) { TOY *toy = (TOY *)clk_unit.filebuf; struct timespec now, val, base; /* Save the GMT time when set value was 0 to record the base for future read operations in "battery backed-up" state */ sim_rtcn_get_time(&now, TMR_CLK); /* get curr time */ val.tv_sec = ((uint32)data) / 100; val.tv_nsec = (((uint32)data) % 100) * 10000000; sim_timespec_diff (&base, &now, &val); /* base = now - data */ toy->toy_gmtbase = (uint32)base.tv_sec; toy->toy_gmtbasemsec = base.tv_nsec/1000000; sim_debug (TMR_DB_TODR, &tmr_dev, "todr_wr(0x%X)\n", data); }
void todr_wr (int32 data) { TOY *toy = (TOY *)clk_unit.filebuf; struct timespec now, val, base; if (data) { todr_blow = 0; /* Save the GMT time when set value is not 0 to record the base for future read operations in "battery backed-up" state */ sim_rtcn_get_time(&now, TMR_CLK); /* get curr time */ val.tv_sec = ((uint32)data) / 100; val.tv_nsec = (((uint32)data) % 100) * 10000000; sim_timespec_diff (&base, &now, &val); /* base = now - data */ toy->toy_gmtbase = (uint32)base.tv_sec; toy->toy_gmtbasemsec = base.tv_nsec/1000000; } else { /* stop the clock */ toy->toy_gmtbase = 0; toy->toy_gmtbasemsec = 0; } todr_reg = data; sim_debug (DBG_REG, &clk_dev, "todr_wr(0x%X) - TODR=0x%X blow=%d\n", data, todr_reg, todr_blow); }