Fix broken timer fix bug fixes
This commit is contained in:
parent
4449acada0
commit
b4feff41f0
10
core/timer.c
10
core/timer.c
|
@ -7,11 +7,11 @@
|
||||||
|
|
||||||
/* Compute clocks until the next decrement to zero */
|
/* Compute clocks until the next decrement to zero */
|
||||||
static uint32_t tmrGetUntil(VB *sim) {
|
static uint32_t tmrGetUntil(VB *sim) {
|
||||||
uint32_t full = (sim->tmr.reload + 1) * (sim->tmr.t_clk_sel ? 400 : 2000);
|
uint32_t fullTick = sim->tmr.t_clk_sel ? 400 : 2000;
|
||||||
uint32_t cur = sim->tmr.clocks +
|
uint32_t thisTick = sim->tmr.clocks +
|
||||||
(sim->tmr.t_clk_sel ? 0 : 400 * (4 - sim->tmr.tick20));
|
(sim->tmr.t_clk_sel ? 0 : 400 * (4 - sim->tmr.tick20));
|
||||||
return sim->tmr.counter == 0 ?
|
return thisTick + fullTick *
|
||||||
sim->tmr.reload * full : (sim->tmr.counter - 1) * full + cur;
|
(sim->tmr.counter == 0 ? sim->tmr.reload : sim->tmr.counter - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update the counter to a new value */
|
/* Update the counter to a new value */
|
||||||
|
@ -142,12 +142,14 @@ static void tmrWriteControl(VB *sim, uint8_t value) {
|
||||||
static void tmrWriteHigh(VB *sim, uint8_t value) {
|
static void tmrWriteHigh(VB *sim, uint8_t value) {
|
||||||
sim->tmr.reload = (uint16_t) value << 8 | (sim->tmr.reload & 0x00FF);
|
sim->tmr.reload = (uint16_t) value << 8 | (sim->tmr.reload & 0x00FF);
|
||||||
tmrUpdate(sim, sim->tmr.reload);
|
tmrUpdate(sim, sim->tmr.reload);
|
||||||
|
sim->tmr.until = tmrGetUntil(sim);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write to the low data register */
|
/* Write to the low data register */
|
||||||
static void tmrWriteLow(VB *sim, uint8_t value) {
|
static void tmrWriteLow(VB *sim, uint8_t value) {
|
||||||
sim->tmr.reload = (sim->tmr.reload & 0xFF00) | value;
|
sim->tmr.reload = (sim->tmr.reload & 0xFF00) | value;
|
||||||
tmrUpdate(sim, sim->tmr.reload);
|
tmrUpdate(sim, sim->tmr.reload);
|
||||||
|
sim->tmr.until = tmrGetUntil(sim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue