avr: implement setvalue for n12.
This commit is contained in:
@@ -62,6 +62,8 @@
|
|||||||
.equ VALUE_ID_REED1 = 0x04
|
.equ VALUE_ID_REED1 = 0x04
|
||||||
.equ VALUE_ID_REED2 = 0x05
|
.equ VALUE_ID_REED2 = 0x05
|
||||||
|
|
||||||
|
.equ VALUE_ID_REED_CONF = 0x81
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ***************************************************************************
|
||||||
@@ -193,10 +195,11 @@ sramTimerEnqueueValues: .byte 2
|
|||||||
|
|
||||||
.cseg
|
.cseg
|
||||||
|
|
||||||
|
#ifdef MODULES_LED
|
||||||
ledA3Flash: .db DDRA+0x20, PORTA+0x20, PINA+0x20, (1<<PORTA3)
|
ledA3Flash: .db DDRA+0x20, PORTA+0x20, PINA+0x20, (1<<PORTA3)
|
||||||
blinkPattern: .db 2, 50, 0xff, 0xff ; 1 short blink, 5s pause, restart
|
blinkPattern: .db 2, 50, 0xff, 0xff ; 1 short blink, 5s pause, restart
|
||||||
;blinkPattern2: .db 2, 2, 0xff, 0xff ; 1 short blink, short pause, restart
|
;blinkPattern2: .db 2, 2, 0xff, 0xff ; 1 short blink, short pause, restart
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -325,20 +328,57 @@ onEvery100ms:
|
|||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; onPacketReceived:
|
; @routine onPacketReceived:
|
||||||
;
|
;
|
||||||
; Called after a packet was received via COM module. Add your routine calls here.
|
; Called after a packet was received via COM module. Add your routine calls here.
|
||||||
;
|
;
|
||||||
; The packet will be released in any case after return from this call.
|
; The packet will be released in any case after return from this call.
|
||||||
; IN:
|
;
|
||||||
; - X : pointer to received buffer
|
; @return CFLAG set if message handled, cleared otherwise
|
||||||
; OUT:
|
; @param X pointer to received buffer
|
||||||
; - CFLAG: set if handled, cleared otherwise
|
; @clobbers all
|
||||||
; USED: depending on called routines
|
|
||||||
|
|
||||||
onPacketReceived:
|
onPacketReceived:
|
||||||
rcall CPRO_OnPacketReceived
|
; get msg code
|
||||||
|
adiw xh:xl, COM2_MSG_OFFS_CMD
|
||||||
|
ld r16, x
|
||||||
|
sbiw xh:xl, COM2_MSG_OFFS_CMD
|
||||||
|
|
||||||
|
cpi r16, CPRO_CMD_VALUE_SET
|
||||||
|
brne onPacketReceived_l1
|
||||||
|
; msg code is CPRO_CMD_VALUE_SET
|
||||||
|
; TODO
|
||||||
|
|
||||||
|
onPacketReceived_l1:
|
||||||
|
rjmp CPRO_OnPacketReceived
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
onSetValueReceived:
|
||||||
|
adiw xh:xl, CPRO_PACKET_SETVALUE_OFFS_VALUEID
|
||||||
|
ld r16, X
|
||||||
|
sbiw xh:xl, CPRO_PACKET_SETVALUE_OFFS_VALUEID
|
||||||
|
cpi r16, VALUE_ID_REED_CONF
|
||||||
|
brne onSetValueReceived_l1
|
||||||
|
rjmp onSetReedConf
|
||||||
|
onSetValueReceived_l1:
|
||||||
|
clc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
onSetReedConf:
|
||||||
|
; get new value
|
||||||
|
adiw xh:xl, CPRO_PACKET_SETVALUE_OFFS_VALUE
|
||||||
|
ld r16, X
|
||||||
|
sbiw xh:xl, CPRO_PACKET_SETVALUE_OFFS_VALUE
|
||||||
|
; set config
|
||||||
|
rcall REED_SetConfig
|
||||||
|
; send ACK
|
||||||
|
ldi r16, CPRO_CMD_VALUE_SET_ACK
|
||||||
|
rcall CPRO_SendSetValueResponse
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,11 @@
|
|||||||
.equ CPRO_CMD_CONFIG_MODULE_RESPONSE = 101
|
.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_HAVEADDR_OFFS_ADDRESS = COM2_MSG_OFFS_PAYLOAD+4
|
||||||
.equ CPRO_PACKET_CLAIMADDR_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
|
.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.
|
; Write a REPORT_VALUE packet.
|
||||||
;
|
;
|
||||||
; @return nothing
|
; @return nothing
|
||||||
@@ -56,16 +56,72 @@ CPRO_WriteReportValue:
|
|||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; @routine CPRO_WriteSetValueResponse
|
; @routine CPRO_WriteSetValueResponse @global
|
||||||
; Write response to a SET_VALUE request.
|
; Write response to a SET_VALUE request.
|
||||||
;
|
;
|
||||||
; @return nothing
|
; @return nothing
|
||||||
; @param R16 message code (CPRO_CMD_VALUE_SET_ACK or CPRO_CMD_VALUE_SET_NACK)
|
; @param R16 message code (CPRO_CMD_VALUE_SET_ACK or CPRO_CMD_VALUE_SET_NACK)
|
||||||
; @param X buffer to write to
|
; @param X buffer to write to
|
||||||
; @param Y buffer with received setValueRequest message
|
; @param Y buffer with received setValueRequest message
|
||||||
; @clobbers R16, R17, R18, R19, (Y)
|
; @clobbers R16, R17, R18, R19, (Y)
|
||||||
|
|
||||||
CPRO_WriteSetValueResponse:
|
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
|
; copy received message into new message
|
||||||
mov r19, r16
|
mov r19, r16
|
||||||
ldi r18, 12 ; message size without checksum byte
|
ldi r18, 12 ; message size without checksum byte
|
||||||
@@ -84,13 +140,61 @@ CPRO_WriteSetValueResponse:
|
|||||||
adiw xh:xl, 2 ; msg code
|
adiw xh:xl, 2 ; msg code
|
||||||
st X, r19
|
st X, r19
|
||||||
sbiw xh:xl, 2
|
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
|
ret
|
||||||
; @end
|
; @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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -170,6 +170,25 @@ REED_Every100ms:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine REED_SetConfig
|
||||||
|
;
|
||||||
|
; Set config and write to EEPROM
|
||||||
|
;
|
||||||
|
; @return nothing
|
||||||
|
; @param r16 new configuration
|
||||||
|
; @clobbers r16, X, (R17)
|
||||||
|
|
||||||
|
REED_SetConfig:
|
||||||
|
sts reedConfigFromEeprom, r16
|
||||||
|
ldi xh, HIGH(EEPROM_OFFS_REED_CONF) ; write config to EEPROM
|
||||||
|
ldi xl, LOW(EEPROM_OFFS_REED_CONF) ;
|
||||||
|
rcall Utils_WriteEepromIncr ; (R17)
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; @routine reedSetupConfig
|
; @routine reedSetupConfig
|
||||||
;
|
;
|
||||||
@@ -194,6 +213,7 @@ reedSetupConfig_haveConfig:
|
|||||||
sts reedConfigFromEeprom, r16
|
sts reedConfigFromEeprom, r16
|
||||||
reedSetupConfig_end:
|
reedSetupConfig_end:
|
||||||
ret
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user