Files
aqhomecontrol/avr/modules/flash/io.asm
Martin Preuss eecb022a0c avr/modules/flash: make protocol more robust
- wait for ATTN high after error receiving a packet
- use different wait times when waiting for FLASH_START and FLASH_DATA
2025-05-05 21:05:07 +02:00

58 lines
1.7 KiB
NASM

; ***************************************************************************
; copyright : (C) 2025 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine ioWaitForGivenMsg
; Wait for incoming msg with given command
;
; @return CFLAG set if okay (packet received), cleared on error
; @return r16 code of received msg
; @param r16 command to wait for
; @param r20 number of tries (low number when waiting for FLASH_START, higher when waiting for FLASH_DATA)
; @clobbers: r16, r17, r20, X (r18, r19, r22)
ioWaitForGivenMsg:
ioWaitForGivenMsg_loop:
push r16
push r20
rcall ioRawWaitForValidMsg ; (r16, r17, r18, r19, r20, r21, r22, X)
pop r20
pop r17 ; pop expected code to r17!
brcc ioWaitForGivenMsg_loopEnd
ldi xl, LOW(flashRecvBuffer)
ldi xh, HIGH(flashRecvBuffer)
adiw xh:xl, COM2_MSG_OFFS_CMD
ld r16, X
sbiw xh:xl, COM2_MSG_OFFS_CMD
cp r16, r17
breq ioWaitForGivenMsg_gotIt
cpi r16, CPRO_CMD_FLASH_END
breq ioWaitForGivenMsg_gotIt
ioWaitForGivenMsg_loopEnd:
mov r17, r16 ; move expected code back to r16
dec r20
brne ioWaitForGivenMsg_loop
clc
ret
ioWaitForGivenMsg_gotIt:
sec
ioWaitForGivenMsg_end:
ret
; @end