avr: reuse code (saves a few more bytes).

This commit is contained in:
Martin Preuss
2024-09-01 20:12:02 +02:00
parent 892d9f5c5a
commit 45cae14f6a

View File

@@ -34,8 +34,7 @@ com2ReceivePacketRaw:
cpi r16, 0xff
breq com2ReceivePacketRaw_acceptAddr
ldi r16, COM2_ERROR_NOTFORME
clc ; not for me
ret
rjmp com2ReceivePacketRaw_error ; clc/ret
com2ReceivePacketRaw_acceptAddr:
st X+, r16 ; store dest address, lock buffer
; read msg length
@@ -54,16 +53,14 @@ com2ReceivePacketRaw_loop:
st X+, r16
dec r17
brne com2ReceivePacketRaw_loop
sec
ret
rjmp com2PacketsSecRet
com2ReceivePacketRaw_ioError:
ldi r16, COM2_ERROR_IOERROR
rjmp com2ReceivePacketRaw_error
rjmp com2PacketsClcRet
com2ReceivePacketRaw_contentError:
ldi r16, COM2_ERROR_DATAERROR
com2ReceivePacketRaw_error:
clc
ret
rjmp com2PacketsClcRet
@@ -105,8 +102,7 @@ COM2_SendPacketWithAttn:
; packet successfully sent
out SREG, r15
pop r15
sec
ret
rjmp com2PacketsSecRet
COM2_SendPacketWithAttn_ioError:
ldi r16,COM2_ERROR_COLLISION
@@ -117,8 +113,7 @@ COM2_SendPacketWithAttn_lineBusyError:
COM2_SendPacketWithAttn_retNc:
pop r15
out SREG, r15
clc
ret
rjmp com2PacketsClcRet
@@ -132,7 +127,7 @@ COM2_SendPacketWithAttn_retNc:
; REGS: r22
com2WaitForOneBitLength:
Utils_WaitNanoSecs COM_BIT_LENGTH, 3+4, r22 ; wait for one bit duration (minus RCALL/RET)
Utils_WaitNanoSecs COM_BIT_LENGTH, 7, r22 ; wait for one bit duration (minus RCALL/RET)
ret
@@ -151,14 +146,18 @@ com2SendPacketRaw:
com2SendPacket_loop:
ld r16, X+
rcall com2SendByte ; send byte (R16, R21, R22)
brcc com2SendPacket_ioError
brcc com2PacketsClcRet
dec r17
brne com2SendPacket_loop
sec
ret
com2SendPacket_ioError:
com2PacketsClcRet:
clc
ret
com2PacketsSecRet:
sec
ret