simplified message handling, switch from XOR checksum to CRC8 with polynomial 0x97.

0x97 allows for detection of all 1-3 bit errors in a message of up to
119 bytes
(see https://www.faa.gov/aircraft/air_cert/design_approvals/air_software/media/TC-14-49.pdf)
This commit is contained in:
Martin Preuss
2023-04-07 23:22:40 +02:00
parent 4e1f08b567
commit 7eb462173c
33 changed files with 281 additions and 367 deletions

View File

@@ -1,4 +1,10 @@
#define COM_USE_CRC8 1
#define COM_CRC_POLYNOMIAL 0x97
; ***************************************************************************
; code
@@ -14,15 +20,20 @@
; - X : pointer to packet buffer
; OUT:
; - CFLAG: set if okay, clear otherwise
; MODIFIED REGS: R16, R17, R18, X
; MODIFIED REGS: R16, R17, R18, R19, X
comCalcAndAddChecksumByte:
adiw xh:xl, COM_MSG_OFFS_MSGLEN
ld r18, X ; read msg len
inc r18 ; account for dest address
inc r18 ; account for msg len bytes
inc r18 ; account for msg len byte
sbiw xh:xl, COM_MSG_OFFS_MSGLEN
#ifdef COM_USE_CRC8
ldi r19, COM_CRC_POLYNOMIAL
rcall cproCalcCrc8 ; (R16, R17, R18, R20, X)
#else
rcall cproCalcXor ; (R16, R17, R18, X)
#endif
st X, r16 ; add checksum byte
sec
ret
@@ -36,15 +47,20 @@ comCalcAndAddChecksumByte:
; - X : pointer to packet buffer
; OUT:
; - CFLAG: set if okay, clear otherwise
; MODIFIED REGS: R16, R17, R18, X
; MODIFIED REGS: R16, R17, R18, R19, R20, X
cproCheckMessageInBuffer:
adiw xh:xl, COM_MSG_OFFS_MSGLEN
ld r18, X ; read msg len
inc r18 ; account for dest address
inc r18 ; account for msg len bytes
inc r18 ; account for msg len byte
sbiw xh:xl, COM_MSG_OFFS_MSGLEN
#ifdef COM_USE_CRC8
ldi r19, COM_CRC_POLYNOMIAL
rcall cproCalcCrc8 ; (R16, R17, R18, R20, X)
#else
rcall cproCalcXor ; (R16, R17, R18, X)
#endif
ld r17, X
cp r16,r17 ; should be equal
brne cproCheckMessageInBuffer_error