Files
aqhomecontrol/avr/modules/flash/hdl_flash_start.asm
2025-01-19 15:44:46 +01:00

74 lines
1.8 KiB
NASM

; ***************************************************************************
; copyright : (C) 2023 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 flashHandleFlashStart
; Handle FLASH START packet.
;
; @return CFLAG set if message is for us, cleared otherwise
; @param X buffer containing the message
; @clobbers r16, (R15, R17, R18, R19, R20, R21, R22, X)
flashHandleFlashStart:
rcall flashCheckFlashStart
brcc flashHandleFlashStart_notMe
; okay, flash start message is for us
rcall flashWaitFor100ms
clr r16
rcall flashSendFlashResponse ; (R15, R16, R17, R18, R19, R20, R21, R22, X)
sec
ret
flashHandleFlashStart_notMe:
ret
; @end
; ---------------------------------------------------------------------------
; @routine flashCheckFlashStart
;
; Check whether the UID in the given msg matches our UID.
;
; @return CFLAG set if message is for us, cleared otherwise
; @param X buffer containing the message
; @clobbers r16, r17, r18, X, Y
flashCheckFlashStart:
ldi yh, HIGH(flashUid)
ldi yl, LOW(flashUid)
adiw xh:xl, FLASH_PACKET_START_OFFS_UID
ldi r18, 4
flashCheckFlashStart_loop:
ld r16, X+
ld r17, Y+
cp r16, r17
brne flashCheckFlashStart_notMe
dec r18
brne flashCheckFlashStart_loop
sec
ret
flashCheckFlashStart_notMe:
clc
ret
; @end