diff options
| author | Uri Shaked | 2021-09-10 01:35:06 +0300 |
|---|---|---|
| committer | Uri Shaked | 2021-09-10 01:35:06 +0300 |
| commit | 39fe0472ce7b7f54438e69f47705086bc60d9716 (patch) | |
| tree | b84cd4c3829c87dde6f8ea56fe6342a891fd9525 /src/cpu | |
| parent | 0.17.1 (diff) | |
| download | avr8js-39fe0472ce7b7f54438e69f47705086bc60d9716.tar.gz avr8js-39fe0472ce7b7f54438e69f47705086bc60d9716.tar.bz2 avr8js-39fe0472ce7b7f54438e69f47705086bc60d9716.zip | |
feat(watchdog): implement watchdog timer #106
Diffstat (limited to '')
| -rw-r--r-- | src/cpu/cpu.ts | 11 | ||||
| -rw-r--r-- | src/cpu/instruction.ts | 2 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/cpu/cpu.ts b/src/cpu/cpu.ts index de5b294..7a518b8 100644 --- a/src/cpu/cpu.ts +++ b/src/cpu/cpu.ts @@ -35,6 +35,7 @@ export interface ICPU { readData(addr: u16): u8; writeData(addr: u16, value: u8, mask?: u8): void; + onWatchdogReset(): void; } export type CPUMemoryHook = (value: u8, oldValue: u8, addr: u16, mask: u8) => boolean | void; @@ -80,6 +81,14 @@ export class CPU implements ICPU { readonly gpioPorts = new Set<AVRIOPort>(); readonly gpioByPort: AVRIOPort[] = []; + /** + * This function is called by the WDR instruction. The Watchdog peripheral attaches + * to it to listen for WDR (watchdog reset). + */ + onWatchdogReset = () => { + /* empty by default */ + }; + pc: u32 = 0; cycles: u32 = 0; nextInterrupt: i16 = -1; @@ -91,8 +100,10 @@ export class CPU implements ICPU { reset() { this.data.fill(0); this.SP = this.data.length - 1; + this.pc = 0; this.pendingInterrupts.splice(0, this.pendingInterrupts.length); this.nextInterrupt = -1; + this.nextClockEvent = null; } readData(addr: number) { diff --git a/src/cpu/instruction.ts b/src/cpu/instruction.ts index c3cdb92..9937ec9 100644 --- a/src/cpu/instruction.ts +++ b/src/cpu/instruction.ts @@ -783,7 +783,7 @@ export function avrInstruction(cpu: ICPU) { cpu.data[d] = ((15 & i) << 4) | ((240 & i) >>> 4); } else if (opcode === 0x95a8) { /* WDR, 1001 0101 1010 1000 */ - /* not implemented */ + cpu.onWatchdogReset(); } else if ((opcode & 0xfe0f) === 0x9204) { /* XCH, 1001 001r rrrr 0100 */ const r = (opcode & 0x1f0) >> 4; |
