Skip to content

Commit

Permalink
feat(usart): add immediate parameter to writeByte()
Browse files Browse the repository at this point in the history
The value will be available immediately to the user program instead of waiting one symbol time before making it available.
  • Loading branch information
urish committed Jul 17, 2021
1 parent ba80f53 commit 7f0a89c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/peripherals/usart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 7f0a89c

Please sign in to comment.