Skip to content

Commit

Permalink
Don't reload watchdog counter on enable, don't use scheduler when dis…
Browse files Browse the repository at this point in the history
…abled
  • Loading branch information
calc84maniac committed Jul 11, 2024
1 parent b40193c commit a508764
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions core/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "interrupt.h"
#include "debug/debug.h"

#include <assert.h>
#include <string.h>
#include <stdio.h>

Expand All @@ -16,18 +17,17 @@ cxxx_state_t cxxx; /* Global CXXX state */
fxxx_state_t fxxx; /* Global FXXX state */

static void watchdog_event(enum sched_item_id id) {
assert(watchdog.control & 1);

if (watchdog.control & 1) {
watchdog.status = 1;
if (watchdog.control & 2) {
cpu_crash("[CEmu] Reset triggered by watchdog timer.\n");
}
if (watchdog.control & 4) {
gui_console_printf("[CEmu] Watchdog NMI triggered.\n");
cpu_nmi();
}
sched_repeat(id, watchdog.load);
watchdog.status = 1;
if (watchdog.control & 2) {
cpu_crash("[CEmu] Reset triggered by watchdog timer.\n");
}
if (watchdog.control & 4) {
gui_console_printf("[CEmu] Watchdog NMI triggered.\n");
cpu_nmi();
}
sched_repeat(id, watchdog.load);
}

/* Watchdog read routine */
Expand Down Expand Up @@ -83,8 +83,11 @@ static void watchdog_write(const uint16_t pio, const uint8_t byte, bool poke) {
case 0x008: case 0x009:
write8(watchdog.restart, bit_offset, byte);
if (watchdog.restart == 0x5AB9) {
sched_set(SCHED_WATCHDOG, watchdog.load);
watchdog.count = watchdog.load;
if (watchdog.control & 1) {
sched_set(SCHED_WATCHDOG, watchdog.load);
} else {
watchdog.count = watchdog.load;
}
watchdog.restart = 0;
}
break;
Expand All @@ -98,7 +101,7 @@ static void watchdog_write(const uint16_t pio, const uint8_t byte, bool poke) {
}
if ((watchdog.control ^ old) & 1) {
if (watchdog.control & 1) {
sched_set(SCHED_WATCHDOG, watchdog.load);
sched_set(SCHED_WATCHDOG, watchdog.count);
} else {
watchdog.count = sched_ticks_remaining(SCHED_WATCHDOG);
sched_clear(SCHED_WATCHDOG);
Expand Down

0 comments on commit a508764

Please sign in to comment.