avr: refactor SEND_VALUE message code.
This commit is contained in:
@@ -174,7 +174,7 @@ CNY70_SendAdc_haveValue:
|
||||
clr r21
|
||||
ldi xl, LOW(com2SendBuffer)
|
||||
ldi xh, HIGH(com2SendBuffer)
|
||||
rcall CPRO_WriteValue
|
||||
rcall CPRO_WriteReportValue
|
||||
rjmp COM2_SendPacket
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
.equ CPRO_CMD_COMRECVSTATS = 21
|
||||
.equ CPRO_CMD_TWIBUSMEMBER = 30
|
||||
.equ CPRO_CMD_DEBUG = 40
|
||||
.equ CPRO_CMD_VALUE = 51 ; was 50 when sending timestamp instead of uid
|
||||
.equ CPRO_CMD_NEED_ADDRESS = 60
|
||||
.equ CPRO_CMD_HAVE_ADDRESS = 61
|
||||
.equ CPRO_CMD_CLAIM_ADDRESS = 62
|
||||
@@ -42,6 +41,12 @@
|
||||
.equ CPRO_CMD_REBOOT_REQUEST = 90
|
||||
.equ CPRO_CMD_REBOOT_RESPONSE = 91
|
||||
|
||||
.equ CPRO_CMD_VALUE_REPORT = 100
|
||||
.equ CPRO_CMD_VALUE_SET = 101
|
||||
.equ CPRO_CMD_VALUE_SET_ACK = 102
|
||||
.equ CPRO_CMD_VALUE_SET_NACK = 103
|
||||
|
||||
|
||||
.equ CPRO_CMD_CONFIG_MODULE_REQUEST = 100
|
||||
.equ CPRO_CMD_CONFIG_MODULE_RESPONSE = 101
|
||||
|
||||
|
||||
@@ -17,42 +17,80 @@
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Write a VALUE packet.
|
||||
; @routine CPRO_WriteReportValue
|
||||
; Write a REPORT_VALUE packet.
|
||||
;
|
||||
; IN:
|
||||
; - R16: destination address
|
||||
; - R17: value id
|
||||
; - R19:R18: value
|
||||
; - R21:R20: denom (e.g. 100, meaning value must be divided by 100)
|
||||
; - R22: value type
|
||||
; - X : buffer to write to
|
||||
; OUT:
|
||||
; - CFLAG: set if okay, clear otherwise
|
||||
; MODIFIED REGS: R6, R7, R8, R9, R10, R11, R12, R16, R17, X, Y (R3, R4, R15, R16, R17, R18, R19, R20, R21)
|
||||
; @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_WriteValue:
|
||||
mov r7, r17
|
||||
mov r8, r18
|
||||
mov r9, r19
|
||||
mov r10, r20
|
||||
mov r11, r21
|
||||
mov r12, r22
|
||||
|
||||
ldi r17, COM2_PAYLOAD_FLAGS_UID | (6<<COM2_PAYLOAD_FLAGS_SHIFT_NUM)
|
||||
ldi r18, CPRO_CMD_VALUE
|
||||
push xh
|
||||
push xl
|
||||
rcall COM2_BeginMsgWithVariablePayload ; R3, R4, R16, R17, R18, R19, R20, R21, X
|
||||
st X+, r7 ; 6: value id
|
||||
st X+, r12 ; 7: value type
|
||||
st X+, r8 ; 8: low value
|
||||
st X+, r9 ; 9: high value
|
||||
st X+, r10 ; 10: low denom
|
||||
st X+, r11 ; 11: high denom
|
||||
pop xl
|
||||
pop xh
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ reedSendValueIfChanged_l1:
|
||||
;
|
||||
; @param r16 value
|
||||
; @param r17 value id
|
||||
; @clobbers r16, r18, r19, r20, r21, r22, X (R3, R4, R6, R7, R8, R9, R10, R11, R12, R15, R16, R17, R18, R19, R20, R21, R22, X, Y)
|
||||
; @clobbers r16, r18, r19, r20, r21, r22, r23, X (R3, R4, R6, R7, R8, R9, R10, R11, R12, R15, R16, R17, R18, R19, R20, R21, R22, X, Y)
|
||||
|
||||
reedSendChange:
|
||||
mov r18, r16 ; value to send in r19:r18
|
||||
@@ -340,7 +340,7 @@ reedSendChange:
|
||||
ldi r22, AQHOME_VALUETYPE_DOOR
|
||||
ldi xl, LOW(com2SendBuffer)
|
||||
ldi xh, HIGH(com2SendBuffer)
|
||||
rcall CPRO_WriteValue ; (R3, R4, R6, R7, R8, R9, R10, R11, R12, R15, R16, R17, R18, R19, R20, R21, X, Y)
|
||||
rcall CPRO_WriteReportValue ; (R3, R4, R6, R7, R8, R9, R10, R11, R12, R15, R16, R17, R18, R19, R20, R21, X, Y)
|
||||
rjmp COM2_SendPacket ; (r18, r19, r22, X)
|
||||
; @end
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ SI7021_SendHumidity_haveValue:
|
||||
SI7021_SendValue:
|
||||
ldi xl, LOW(com2SendBuffer)
|
||||
ldi xh, HIGH(com2SendBuffer)
|
||||
rcall CPRO_WriteValue
|
||||
rcall CPRO_WriteReportValue
|
||||
rjmp COM2_SendPacket
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user