Files
aqhomecontrol/avr/modules/comproto/msg_device.asm
2024-09-05 03:18:22 +02:00

48 lines
1.5 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
; ---------------------------------------------------------------------------
; Enqueue a DEVICE packet.
;
; IN:
; - R16: destination address
; OUT:
; - nothing
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
CPRO_WriteDevice:
ldi r17, COM2_PAYLOAD_FLAGS_UID | (8<<COM2_PAYLOAD_FLAGS_SHIFT_NUM)
ldi r18, CPRO_CMD_DEVICE
rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
push yh
push yl
ldi zh, HIGH(devInfoBlock*2) ; 6-13: devInfoBlock
ldi zl, LOW(devInfoBlock*2)
ldi r18, 8
rcall Utils_CopyFromFlash ; (R17, R18, X, Y)
pop yl
pop yh
sbiw xh:xl, 16 ; go back to beginning of message (1 byte dst addr, 1 byte length, 14 bytes payload)
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 17 ; go back to beginning of message (1 byte dst addr, 1 byte length, 14 bytes payload, 1 byte crc)
ret