diff options
| author | Uri Shaked | 2021-07-17 17:55:24 +0300 |
|---|---|---|
| committer | Uri Shaked | 2021-07-17 17:55:24 +0300 |
| commit | 7f0a89cc4a4e079c4c5889d45f28d6d84864c8b3 (patch) | |
| tree | 072be48635ceec3713f123db1b4274afac16a547 /src | |
| parent | 0.16.3 (diff) | |
| download | avr8js-7f0a89cc4a4e079c4c5889d45f28d6d84864c8b3.tar.gz avr8js-7f0a89cc4a4e079c4c5889d45f28d6d84864c8b3.tar.bz2 avr8js-7f0a89cc4a4e079c4c5889d45f28d6d84864c8b3.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/peripherals/usart.ts | 20 |
1 files changed, 12 insertions, 8 deletions
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() { |
