diff options
| author | Uri Shaked | 2020-01-31 15:08:53 +0200 |
|---|---|---|
| committer | Uri Shaked | 2020-01-31 15:08:53 +0200 |
| commit | f95a33c4bd6310f69bc24ee2f4c05157c532e25d (patch) | |
| tree | c25add972dc4e9c4f92de6a6309bc72e440ed0fb /src/twi.ts | |
| parent | fix(assembler): BRBC/BRBS forward labels fail (diff) | |
| download | avr8js-f95a33c4bd6310f69bc24ee2f4c05157c532e25d.tar.gz avr8js-f95a33c4bd6310f69bc24ee2f4c05157c532e25d.tar.bz2 avr8js-f95a33c4bd6310f69bc24ee2f4c05157c532e25d.zip | |
test(twi): assembly code to test master transmit #10
Diffstat (limited to '')
| -rw-r--r-- | src/twi.ts | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -96,6 +96,8 @@ export class NoopTWIEventHandler implements TWIEventHandler { export class AVRTWI { public eventHandler: TWIEventHandler = new NoopTWIEventHandler(this); + private nextTick: (() => void) | null = null; + constructor(private cpu: CPU, private config: TWIConfig, private freqMHz: number) { this.updateStatus(STATUS_TWI_IDLE); this.cpu.writeHooks[config.TWCR] = (value) => { @@ -106,8 +108,7 @@ export class AVRTWI { const { status } = this; if (clearInt && value & TWCR_TWEN) { const twdrValue = this.cpu.data[this.config.TWDR]; - // TODO: this should be executed after the current instruction completes - setTimeout(() => { + this.nextTick = () => { if (value & TWCR_TWSTA) { this.eventHandler.start(status !== STATUS_TWI_IDLE); } else if (value & TWCR_TWSTO) { @@ -120,13 +121,20 @@ export class AVRTWI { const ack = !!(value & TWCR_TWEA); this.eventHandler.readByte(ack); } - }, 0); + }; this.cpu.data[config.TWCR] = value; return true; } }; } + tick() { + if (this.nextTick) { + this.nextTick(); + this.nextTick = null; + } + } + get prescaler() { switch (this.cpu.data[this.config.TWSR] & TWSR_TWPS_MASK) { case 0: |
