aboutsummaryrefslogtreecommitdiff
path: root/src/twi.ts
diff options
context:
space:
mode:
authorUri Shaked2020-01-31 15:08:53 +0200
committerUri Shaked2020-01-31 15:08:53 +0200
commitf95a33c4bd6310f69bc24ee2f4c05157c532e25d (patch)
treec25add972dc4e9c4f92de6a6309bc72e440ed0fb /src/twi.ts
parentfix(assembler): BRBC/BRBS forward labels fail (diff)
downloadavr8js-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.ts14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/twi.ts b/src/twi.ts
index e2cfe24..027061f 100644
--- a/src/twi.ts
+++ b/src/twi.ts
@@ -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: