avr: re-introduce UID to new VALUE messages, set UID in VALUE response messages.

This commit is contained in:
Martin Preuss
2024-09-06 22:50:32 +02:00
parent 5e4ca45443
commit 2fa3e9d4ab
6 changed files with 77 additions and 44 deletions

View File

@@ -185,15 +185,13 @@ Utils_Fini:
; ---------------------------------------------------------------------------
; Utils_FillSram
; @routine Utils_FillSram @global
;
; IN:
; - x: pointer to SRAM to fill
; - r16: value to fill the SRAM with
; - r17: size of area to fill
; OUT:
; - nothing
; MODIFIED REGISTERS: r17, x
; @return X points directly behind filled memory
; @param X pointer to SRAM to fill
; @param r16 value to fill the SRAM with
; @param r17 size of area to fill
; @clobbers r17
Utils_FillSram:
tst r17
@@ -205,6 +203,7 @@ Utils_FillSram_loop:
brne Utils_FillSram_loop
Utils_FillSram_end:
ret
; @end

View File

@@ -357,9 +357,9 @@ onPacketReceived_l1:
onSetValueReceived:
adiw xh:xl, CPRO_PACKET_SETVALUE_OFFS_VALUEID
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUEID
ld r16, X
sbiw xh:xl, CPRO_PACKET_SETVALUE_OFFS_VALUEID
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUEID
cpi r16, VALUE_ID_REED_CONF
brne onSetValueReceived_l1
rjmp onSetReedConf
@@ -370,9 +370,9 @@ onSetValueReceived_l1:
onSetReedConf:
; get new value
adiw xh:xl, CPRO_PACKET_SETVALUE_OFFS_VALUE
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
ld r16, X
sbiw xh:xl, CPRO_PACKET_SETVALUE_OFFS_VALUE
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
; set config
rcall REED_SetConfig
; send ACK

View File

@@ -220,6 +220,25 @@ COM2_BeginMsgWithVariablePayload_l1:
lsr r3 ; shift out COM2_PAYLOAD_FLAGS_UID
brcc COM2_BeginMsgWithVariablePayload_l2
; write uid
rcall COM2_AddUidToBuffer
COM2_BeginMsgWithVariablePayload_l2:
ret
; ---------------------------------------------------------------------------
; @routine COM2_AddUidToBuffer @global
;
; Write UID into buffer given by X.
;
; @return X points to behind written uid
; @param R16 destination address
; @param R17 flags
; @param R18 command (e.g. CPRO_CMD_PING)
; @param X pointer to packet buffer
; @clobbers: r18, r19, r20, r21 (r16)
COM2_AddUidToBuffer:
push xh
push xl
rcall Utils_ReadUid ; (R16, X)
@@ -229,8 +248,8 @@ COM2_BeginMsgWithVariablePayload_l1:
st X+, r19
st X+, r20
st X+, r21
COM2_BeginMsgWithVariablePayload_l2:
ret
; @end

View File

@@ -100,13 +100,14 @@ Offset Length Meaning
2 1 command code (REPORT_VALUE, REQ_SET_VALUE, RSP_SET_VALUE)
3 1 source address
---------------------------------------------------------
4 2 msg id/ref msg id
6 1 value id
7 1 value type
8 2 value
10 2 denom
4 4 UID of the sending node
8 2 msg id/ref msg id
10 1 value id
11 1 value type
12 2 value
14 2 denom
---------------------------------------------------------
12 1 CRC8 byte
15 1 CRC8 byte

View File

@@ -54,9 +54,11 @@
; ---------------------------------------------------------------------------
; offsets in CPRO_CMD_VALUE_* messages
.equ CPRO_PACKET_SETVALUE_OFFS_VALUEID = 6
.equ CPRO_PACKET_SETVALUE_OFFS_VALUE = 8
.equ CPRO_PACKET_SETVALUE_OFFS_DENOM = 10
.equ CPRO_PACKET_VALUE_OFFS_UID = 4
.equ CPRO_PACKET_VALUE_OFFS_MSGID = 8
.equ CPRO_PACKET_VALUE_OFFS_VALUEID = 10
.equ CPRO_PACKET_VALUE_OFFS_VALUE = 12
.equ CPRO_PACKET_VALUE_OFFS_DENOM = 14
; ---------------------------------------------------------------------------

View File

@@ -27,29 +27,34 @@
; @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)
; @clobbers 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
st X+, r16 ; dest address
ldi r16, 14 ; msg code+src address+12 payload bytes
st X+, r16 ; msg len
ldi r16, CPRO_CMD_VALUE_REPORT
st X+, r16 ; msg code
st X+, r16 ; msg code
ldi r16, com2Address
st X+, r16 ; src address
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)
push r17
ldi r17, 6 ; uid (4 bytes), msg/ref id (2 bytes)
rcall Utils_FillSram ; (R17)
pop r17
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 UID (12=16 back, 4 forward)
rcall COM2_AddUidToBuffer ; (r16, r18, r19, r20, r21)
sbiw xh:xl, 8 ; go back to beginning of message
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
sbiw xh:xl, 16 ; go back to beginning of message
ret
; @end
@@ -70,7 +75,7 @@ CPRO_WriteSetValueResponse:
; add checksum byte
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
sbiw xh:xl, 13 ; go back to beginning of message
sbiw xh:xl, 16 ; go back to beginning of message
ret
; @end
@@ -86,7 +91,7 @@ CPRO_WriteSetValueResponse:
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100, 0=don't change)
; @param X buffer to write to
; @param Y buffer with received setValueRequest message
; @clobbers R16, R17, R18, R19, (Y)
; @clobbers R16, R17, R18, R19, (R20, R21, Y)
CPRO_WriteGetValueResponse:
push r18
@@ -96,12 +101,12 @@ CPRO_WriteGetValueResponse:
pop r18
; replace values
adiw xh:xl, CPRO_PACKET_SETVALUE_OFFS_VALUE
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
st X+, r18 ; value (low)
st X+, r19 ; value (high)
st X+, r20 ; denom (low)
st X+, r21 ; denom (high)
sbiw xh:xl, CPRO_PACKET_SETVALUE_OFFS_VALUE+4
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE+4
; add checksum byte
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
@@ -124,9 +129,9 @@ CPRO_WriteGetValueResponse:
cproInvertValueMsg:
; copy received message into new message
mov r19, r16
ldi r18, 12 ; message size without checksum byte
ldi r18, 16 ; message size without checksum byte
rcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
sbiw xh:xl, 12 ; go back to beginning of message
sbiw xh:xl, 16 ; go back to beginning of message
; exchange src and dest address
adiw xh:xl, 3 ; src address
@@ -140,7 +145,14 @@ cproInvertValueMsg:
adiw xh:xl, 2 ; msg code
st X, r19
sbiw xh:xl, 2
; replace UID
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_UID
rcall COM2_AddUidToBuffer ; (r16, r18, r19, r20, r21)
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_UID+4 ; go back to beginning of message
ret
; @end