avr: refactor ctc calculation code.
This commit is contained in:
@@ -14,19 +14,15 @@
|
||||
; add checksum byte to buffer
|
||||
;
|
||||
; IN:
|
||||
; - X : pointer to packet buffer
|
||||
; - X : pointer to packet buffer (points behind checksum upon return)
|
||||
; OUT:
|
||||
; - CFLAG: set if okay, clear otherwise
|
||||
; - X : points behind checksum byte pos upon return
|
||||
; MODIFIED REGS: R16, R17, R18, R19, X
|
||||
|
||||
com2CalcAndAddChecksumByte:
|
||||
adiw xh:xl, COM2_MSG_OFFS_MSGLEN
|
||||
ld r18, X ; read msg len
|
||||
sbiw xh:xl, COM2_MSG_OFFS_MSGLEN
|
||||
inc r18 ; account for dest address
|
||||
inc r18 ; account for msg len byte
|
||||
rcall crc8Calc ; (R16, R17, R18, R20, X)
|
||||
st X, r16 ; add checksum byte
|
||||
rcall com2CalcMsgChecksum
|
||||
st X+, r16 ; add checksum byte
|
||||
sec
|
||||
ret
|
||||
|
||||
@@ -39,15 +35,10 @@ com2CalcAndAddChecksumByte:
|
||||
; - X : pointer to packet buffer
|
||||
; OUT:
|
||||
; - CFLAG: set if okay, clear otherwise
|
||||
; MODIFIED REGS: R16, R17, R18, R19, R20, X
|
||||
; MODIFIED REGS: R16, R17 (R18, R20, X)
|
||||
|
||||
com2CheckMessageInBuffer:
|
||||
adiw xh:xl, COM2_MSG_OFFS_MSGLEN
|
||||
ld r18, X ; read msg len
|
||||
sbiw xh:xl, COM2_MSG_OFFS_MSGLEN
|
||||
inc r18 ; account for dest address
|
||||
inc r18 ; account for msg len byte
|
||||
rcall crc8Calc ; (R16, R17, R18, R20, X)
|
||||
rcall com2CalcMsgChecksum ; R16, R18, (R17, R20, X)
|
||||
ld r17, X
|
||||
cp r16, r17 ; should be equal
|
||||
brne com2CheckMessageInBuffer_error
|
||||
@@ -58,3 +49,25 @@ com2CheckMessageInBuffer_error:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; com2CalcMsgChecksum
|
||||
;
|
||||
; calc checksum from msg buffer (except crc byte)
|
||||
;
|
||||
; IN:
|
||||
; - X : pointer to packet buffer (points to checksum byte upon return)
|
||||
; OUT:
|
||||
; - r16: crc8 checksum
|
||||
; - X : points to position of checksum byte
|
||||
; MODIFIED REGS: R16, R18, (R17, R20, X)
|
||||
|
||||
com2CalcMsgChecksum:
|
||||
adiw xh:xl, COM2_MSG_OFFS_MSGLEN
|
||||
ld r18, X ; read msg len
|
||||
sbiw xh:xl, COM2_MSG_OFFS_MSGLEN
|
||||
inc r18 ; account for dest address
|
||||
inc r18 ; account for msg len byte
|
||||
rjmp crc8Calc ; (R16, R17, R18, R20, X)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user