avr: use common code.

This commit is contained in:
Martin Preuss
2024-09-05 03:18:22 +02:00
parent ea2cd6e58e
commit 817ff958b9
3 changed files with 46 additions and 74 deletions

View File

@@ -21,32 +21,26 @@
;
; IN:
; - R16: destination address
; - X : buffer to write to
; OUT:
; - nothing
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
CPRO_WriteDevice:
ldi r17, COM2_PAYLOAD_FLAGS_UID | (6<<COM2_PAYLOAD_FLAGS_SHIFT_NUM)
ldi r17, COM2_PAYLOAD_FLAGS_UID | (8<<COM2_PAYLOAD_FLAGS_SHIFT_NUM)
ldi r18, CPRO_CMD_DEVICE
push xh
push xl
rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
lds r17, firmwareType
st X+, r17 ; 6: firmware type low
lds r17, firmwareType+1
st X+, r17 ; 7: firmware type high
lds r17, firmwareVersion
st X+, r17 ; 8: version low
lds r17, firmwareVersion+1
st X+, r17 ; 9: version high
lds r17, firmwareModules
st X+, r17 ; 10: modules mask low
lds r17, firmwareModules+1
st X+, r17 ; 11: modules mask low
pop xl
pop xh
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
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