aboutsummaryrefslogtreecommitdiff
path: root/src/peripherals/usart.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/peripherals/usart.ts20
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() {