diff --git a/include/sys/timer.h b/include/sys/timer.h index 45eb95cf39..ea70150cd8 100644 --- a/include/sys/timer.h +++ b/include/sys/timer.h @@ -81,9 +81,6 @@ int tm_stop(timer_t *tm); /*! \brief Used by interrupt filter routine to trigger a callback. */ void tm_trigger(timer_t *tm); -/*! \brief Select timer used as a main time source (for binuptime, etc.) */ -void tm_select(timer_t *tm); - #endif /* !_KERNEL */ #endif /* !_SYS_TIMER_H_ */ diff --git a/sys/aarch64/timer.c b/sys/aarch64/timer.c index 4d1d9202ea..b9b2c17fa2 100644 --- a/sys/aarch64/timer.c +++ b/sys/aarch64/timer.c @@ -86,7 +86,6 @@ static int arm_timer_attach(device_t *dev) { state->irq_res = device_take_irq(dev, 0, RF_ACTIVE); tm_register(&state->timer); - tm_select(&state->timer); bus_intr_setup(dev, state->irq_res, arm_timer_intr, NULL, dev, "ARM CPU timer"); diff --git a/sys/drv/pit.c b/sys/drv/pit.c index 7f127065e5..3fd2833535 100644 --- a/sys/drv/pit.c +++ b/sys/drv/pit.c @@ -103,22 +103,19 @@ static int pit_timer_start(timer_t *tm, unsigned flags, const bintime_t start, /* Maximal counter value which we can store in pit timer */ assert(counter <= 0xFFFF); - pit->sec = 0; - pit->ticks = 0; - pit->prev_ticks16 = 0; pit->period_ticks = counter; - pit->noticed_overflow = false; pit_set_frequency(pit); - bus_intr_setup(dev, pit->irq_res, pit_intr, NULL, pit, "i8254 timer"); return 0; } static int pit_timer_stop(timer_t *tm) { device_t *dev = device_of(tm); pit_state_t *pit = dev->state; - bus_intr_teardown(dev, pit->irq_res); + + outb(TIMER_MODE, TIMER_SEL0 | TIMER_16BIT | TIMER_ONESHOT); + return 0; } @@ -144,6 +141,10 @@ static int pit_attach(device_t *dev) { pit->regs = device_take_ioports(dev, 0, RF_ACTIVE); assert(pit->regs != NULL); + pit->sec = 0; + pit->ticks = 0; + pit->prev_ticks16 = 0; + pit->noticed_overflow = false; pit->irq_res = device_take_irq(dev, 0, RF_ACTIVE); pit->timer = (timer_t){ @@ -159,8 +160,12 @@ static int pit_attach(device_t *dev) { .tm_priv = dev, }; + timer_pit_stop(&pit->timer); + tm_register(&pit->timer); + bus_intr_setup(dev, pit->irq_res, pit_intr, NULL, pit, "i8254 timer"); + return 0; } diff --git a/sys/kern/time.c b/sys/kern/time.c index 5d4a7c10dd..7cb8a06fd8 100644 --- a/sys/kern/time.c +++ b/sys/kern/time.c @@ -128,7 +128,7 @@ time_t tm2sec(tm_t *t) { const int32_t year_scale_s = 31536000, day_scale_s = 86400, hour_scale_s = 3600, min_scale_s = 60; time_t res = 0; - static const int month_in_days[13] = {0, 31, 59, 90, 120, 151, + static const int month_in_days[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; res += (time_t)month_in_days[t->tm_mon] * day_scale_s; diff --git a/sys/kern/timer.c b/sys/kern/timer.c index ec7871c4e7..62b54cf7c3 100644 --- a/sys/kern/timer.c +++ b/sys/kern/timer.c @@ -169,10 +169,6 @@ void tm_trigger(timer_t *tm) { tm->tm_event_cb(tm, tm->tm_arg); } -void tm_select(timer_t *tm) { - time_source = tm; -} - bintime_t binuptime(void) { /* XXX: probably a race condition here */ timer_t *tm = time_source; diff --git a/sys/mips/timer.c b/sys/mips/timer.c index 7689cdbcf9..bf25340f1c 100644 --- a/sys/mips/timer.c +++ b/sys/mips/timer.c @@ -52,7 +52,7 @@ static int set_next_tick(mips_timer_state_t *state) { /* calculate next value of compare register based on timer period */ do { state->compare.val += state->period_cntr; - mips32_set_c0(C0_COMPARE, state->compare.lo); + mips32_setcompare(state->compare.lo); (void)read_count(state); ticks++; } while (state->compare.val <= state->count.val); @@ -74,26 +74,17 @@ static int mips_timer_start(timer_t *tm, unsigned flags, const bintime_t start, assert(flags & TMF_PERIODIC); assert(!(flags & TMF_ONESHOT)); - mips32_setcount(0); - device_t *dev = tm->tm_priv; mips_timer_state_t *state = dev->state; - state->sec = 0; - state->cntr_modulo = 0; - state->last_count_lo = 0; state->period_cntr = bintime_mul(period, tm->tm_frequency).sec; state->compare.val = read_count(state); set_next_tick(state); - bus_intr_setup(dev, state->irq_res, mips_timer_intr, NULL, dev, - "MIPS CPU timer"); return 0; } -static int mips_timer_stop(timer_t *tm) { - device_t *dev = tm->tm_priv; - mips_timer_state_t *state = dev->state; - bus_intr_teardown(dev, state->irq_res); +static inline int mips_timer_stop(timer_t *tm) { + mips32_setcompare(0xffffffff); return 0; } @@ -121,8 +112,15 @@ static int mips_timer_probe(device_t *dev) { static int mips_timer_attach(device_t *dev) { mips_timer_state_t *state = dev->state; + mips32_setcount(0); + + state->sec = 0; + state->cntr_modulo = 0; + state->last_count_lo = 0; state->irq_res = device_take_irq(dev, 0, RF_ACTIVE); + mips_timer_stop(&state->timer); + state->timer = (timer_t){ .tm_name = "mips-cpu-timer", .tm_flags = TMF_PERIODIC, @@ -138,6 +136,9 @@ static int mips_timer_attach(device_t *dev) { tm_register(&state->timer); + bus_intr_setup(dev, state->irq_res, mips_timer_intr, NULL, dev, + "MIPS CPU timer"); + return 0; }