aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUri Shaked2020-02-03 21:23:55 +0200
committerUri Shaked2020-02-03 21:23:55 +0200
commit8c244a233966cce22b8e265cacebdc685b05c066 (patch)
treecb616443b87ad52d960ecb68ca8af1dbfa077ea4
parenttest(twi): assembly code to test master transmit #10 (diff)
downloadavr8js-8c244a233966cce22b8e265cacebdc685b05c066.tar.gz
avr8js-8c244a233966cce22b8e265cacebdc685b05c066.tar.bz2
avr8js-8c244a233966cce22b8e265cacebdc685b05c066.zip
test(twi): refactor assembly code to be shorter
Diffstat (limited to '')
-rw-r--r--src/twi.spec.ts27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/twi.spec.ts b/src/twi.spec.ts
index 871bc41..4f57dc7 100644
--- a/src/twi.spec.ts
+++ b/src/twi.spec.ts
@@ -83,10 +83,7 @@ describe('TWI', () => {
sts TWCR, r16
; Wait for TWINT Flag set. This indicates that the START condition has been transmitted
- wait1:
- lds r16, TWCR
- andi r16, TWINT
- breq wait1
+ call wait_for_twint
; Check value of TWI Status Register. Mask prescaler bits. If status different from START go to ERROR
lds r16, TWSR
@@ -104,10 +101,7 @@ describe('TWI', () => {
sts TWCR, r16
; Wait for TWINT Flag set. This indicates that the SLA+W has been transmitted, and ACK/NACK has been received.
- wait2:
- lds r16, TWCR
- andi r16, TWINT
- breq wait2
+ call wait_for_twint
; Check value of TWI Status Register. Mask prescaler bits. If status different from MT_SLA_ACK go to ERROR
lds r16, TWSR
@@ -124,10 +118,7 @@ describe('TWI', () => {
sts TWCR, r16
; Wait for TWINT Flag set. This indicates that the DATA has been transmitted, and ACK/NACK has been received
- wait3:
- lds r16, TWCR
- andi r16, TWINT
- breq wait3
+ call wait_for_twint
; Check value of TWI Status Register. Mask prescaler bits. If status different from MT_DATA_ACK go to ERROR
lds r16, TWSR
@@ -142,10 +133,7 @@ describe('TWI', () => {
sts TWCR, r16
; Wait for TWINT Flag set. This indicates that the STOP condition has been sent
- wait4:
- lds r16, TWCR
- andi r16, TWINT
- breq wait4
+ call wait_for_twint
; Check value of TWI Status Register. The masked value should be 0xf8 once done
lds r16, TWSR
@@ -159,6 +147,13 @@ describe('TWI', () => {
loop:
jmp loop
+ ; Busy-waits for the TWINT flag to be set
+ wait_for_twint:
+ lds r16, TWCR
+ andi r16, TWINT
+ breq wait_for_twint
+ ret
+
; In case of an error, toggle a breakpoint
error:
break