avr: implement setvalue for n12.
This commit is contained in:
@@ -51,6 +51,11 @@
|
||||
.equ CPRO_CMD_CONFIG_MODULE_RESPONSE = 101
|
||||
|
||||
|
||||
.equ CPRO_PACKET_SETVALUE_OFFS_VALUEID = 6
|
||||
.equ CPRO_PACKET_SETVALUE_OFFS_VALUE = 8
|
||||
.equ CPRO_PACKET_SETVALUE_OFFS_DENOM = 10
|
||||
|
||||
|
||||
.equ CPRO_PACKET_HAVEADDR_OFFS_ADDRESS = COM2_MSG_OFFS_PAYLOAD+4
|
||||
.equ CPRO_PACKET_CLAIMADDR_OFFS_ADDRESS = COM2_MSG_OFFS_PAYLOAD+4
|
||||
.equ CPRO_PACKET_DENYADDR_OFFS_ADDRESS = COM2_MSG_OFFS_PAYLOAD+4
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine CPRO_WriteReportValue
|
||||
; @routine CPRO_WriteReportValue @global
|
||||
; Write a REPORT_VALUE packet.
|
||||
;
|
||||
; @return nothing
|
||||
@@ -56,16 +56,72 @@ CPRO_WriteReportValue:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine CPRO_WriteSetValueResponse
|
||||
; @routine CPRO_WriteSetValueResponse @global
|
||||
; 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)
|
||||
; @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:
|
||||
rcall cproInvertValueMsg ; (R16, R17, R18, R19, Y)
|
||||
|
||||
; add checksum byte
|
||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
||||
sbiw xh:xl, 13 ; go back to beginning of message
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine CPRO_WriteGetValueResponse @global
|
||||
; 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 R19:R18 value
|
||||
; @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)
|
||||
|
||||
CPRO_WriteGetValueResponse:
|
||||
push r18
|
||||
push r19
|
||||
rcall cproInvertValueMsg ; (R16, R17, R18, R19, Y)
|
||||
pop r19
|
||||
pop r18
|
||||
|
||||
; replace values
|
||||
adiw xh:xl, CPRO_PACKET_SETVALUE_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
|
||||
|
||||
; add checksum byte
|
||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
||||
sbiw xh:xl, 13 ; go back to beginning of message
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine cproInvertValueMsg
|
||||
; 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)
|
||||
|
||||
cproInvertValueMsg:
|
||||
; copy received message into new message
|
||||
mov r19, r16
|
||||
ldi r18, 12 ; message size without checksum byte
|
||||
@@ -84,13 +140,61 @@ CPRO_WriteSetValueResponse:
|
||||
adiw xh:xl, 2 ; msg code
|
||||
st X, r19
|
||||
sbiw xh:xl, 2
|
||||
ret
|
||||
|
||||
; add checksum byte
|
||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
||||
sbiw xh:xl, 13 ; go back to beginning of message
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine CPRO_SendSetValueResponse @global
|
||||
; Write response to a SET_VALUE request.
|
||||
;
|
||||
; @return CFLAG set if okay, cleared on error
|
||||
; @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 Y, (R16, R17, R18, R19, R22)
|
||||
|
||||
CPRO_SendSetValueResponse:
|
||||
push xh
|
||||
push xl
|
||||
mov yh, xh
|
||||
mov yl, xl
|
||||
ldi xl, LOW(com2SendBuffer)
|
||||
ldi xh, HIGH(com2SendBuffer)
|
||||
rcall CPRO_WriteSetValueResponse ; (R16, R17, R18, R19, Y)
|
||||
rcall COM2_SendPacket ; (r18, r19, r22, X)
|
||||
pop xl
|
||||
pop xh
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine CPRO_SendGetValueResponse @global
|
||||
; Write response to a GET_VALUE request.
|
||||
;
|
||||
; @return CFLAG set if okay, cleared on error
|
||||
; @param R16 message code (CPRO_CMD_VALUE_SET_ACK or CPRO_CMD_VALUE_SET_NACK)
|
||||
; @param R19:R18 value
|
||||
; @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 getValueRequest message
|
||||
; @clobbers Y, (R16, R17, R18, R19, R22)
|
||||
|
||||
CPRO_SendGetValueResponse:
|
||||
push xh
|
||||
push xl
|
||||
mov yh, xh
|
||||
mov yl, xl
|
||||
ldi xl, LOW(com2SendBuffer)
|
||||
ldi xh, HIGH(com2SendBuffer)
|
||||
rcall CPRO_WriteGetValueResponse ; (R16, R17, R18, R19, Y)
|
||||
rcall COM2_SendPacket ; (r18, r19, r22, X)
|
||||
pop xl
|
||||
pop xh
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user