Files
aqhomecontrol/avr/modules/comproto/msg_value.asm
2024-09-05 18:52:25 +02:00

97 lines
2.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 CPRO_WriteReportValue
; Write a REPORT_VALUE packet.
;
; @return nothing
; @param R16 destination address
; @param R17 value id
; @param R19:R18 value
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100)
; @param R22 value type
; @param X buffer to write to
; @clobbers R6, R7, R8, R9, R10, R11, R12, R16, R17, X, Y (R3, R4, R15, R16, R17, R18, R19, R20, R21)
CPRO_WriteReportValue:
st X+, r16 ; dest address
ldi r16, 10 ; msg code+src address+8 payload bytes
st X+, r16 ; msg len
ldi r16, CPRO_CMD_VALUE_REPORT
st X+, r16 ; msg code
ldi r16, com2Address
st X+, r16 ; src address
clr r16
st X+, r16 ; msg id/ref id, low
st X+, r16 ; msg id/ref id, high
st X+, r17 ; value id
st X+, r22 ; value type
st X+, r18 ; value (low)
st X+, r19 ; value (high)
st X+, r20 ; denom (low)
st X+, r21 ; denom (high)
sbiw xh:xl, 12 ; go back to beginning of message
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
sbiw xh:xl, 13 ; go back to beginning of message
ret
; @end
; ---------------------------------------------------------------------------
; @routine CPRO_WriteSetValueResponse
; Write response to a SET_VALUE request.
;
; @return nothing
; @param R16 message code (CPRO_CMD_VALUE_SET_ACK or CPRO_CMD_VALUE_SET_NACK)
; @param X buffer to write to
; @param Y buffer with received setValueRequest message
; @clobbers R16, R17, R18, R19, (Y)
CPRO_WriteSetValueResponse:
; copy received message into new message
mov r19, r16
ldi r18, 12 ; message size without checksum byte
rcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
sbiw xh:xl, 12 ; go back to beginning of message
; exchange src and dest address
adiw xh:xl, 3 ; src address
ld r16, X
lds r17, com2Address
st X, r16 ; set our src address
sbiw xh:xl, 3
st X, r16 ; set old src address as destination address
; replace msg code
adiw xh:xl, 2 ; msg code
st X, r19
sbiw xh:xl, 2
; add checksum byte
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
sbiw xh:xl, 13 ; go back to beginning of message
ret
; @end