From 7f0a89cc4a4e079c4c5889d45f28d6d84864c8b3 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Sat, 17 Jul 2021 17:55:24 +0300 Subject: feat(usart): add `immediate` parameter to writeByte() The value will be available immediately to the user program instead of waiting one symbol time before making it available. --- src/peripherals/usart.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/peripherals/usart.ts') diff --git a/src/peripherals/usart.ts b/src/peripherals/usart.ts index 81451ba..1b7546b 100644 --- a/src/peripherals/usart.ts +++ b/src/peripherals/usart.ts @@ -193,19 +193,23 @@ export class AVRUSART { return this.rxBusyValue; } - writeByte(value: number) { - const { cpu, config } = this; - if (this.rxBusyValue || !(cpu.data[config.UCSRB] & UCSRB_RXEN)) { + writeByte(value: number, immediate = false) { + const { cpu } = this; + if (this.rxBusyValue || !this.rxEnable) { return false; } - this.rxBusyValue = true; - cpu.addClockEvent(() => { + if (immediate) { this.rxByte = value; - this.rxBusyValue = false; cpu.setInterruptFlag(this.RXC); this.onRxComplete?.(); - }, this.cyclesPerChar); - return true; + } else { + this.rxBusyValue = true; + cpu.addClockEvent(() => { + this.rxBusyValue = false; + this.writeByte(value, true); + }, this.cyclesPerChar); + return true; + } } private get cyclesPerChar() { -- cgit v1.2.3