; ***************************************************************************
; 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




; ---------------------------------------------------------------------------
; Handle FLASH START packet.
;
; IN:
; - X  : buffer containing the message
; OUT:
; - CFLAG: set if message is for us, cleared otherwise
; REGS: r16, r18. r19. r20, r21, X (R15, R17, R22)

flashHandleFlashStart:
  lds r18, flashUid
  lds r19, flashUid+1
  lds r20, flashUid+2
  lds r21, flashUid+3
  adiw xh:xl, FLASH_PACKET_START_OFFS_UID
  ld r16, X+
  cp r16, r18
  brne flashHandleFlashStart_notMe
  ld r16, X+
  cp r16, r19
  brne flashHandleFlashStart_notMe
  ld r16, X+
  cp r16, r20
  brne flashHandleFlashStart_notMe
  ld r16, X
  cp r16, r21
  brne flashHandleFlashStart_notMe
  ; okay, flash start message is for us
  rcall flashWaitFor100ms
  rcall flashSendFlashResponse             ; (R15, R16, R17, R18, R19, R20, R21, R22, X)
  sec
  ret
flashHandleFlashStart_notMe:
  clc
  ret



