avr: fixed crc code.

This commit is contained in:
Martin Preuss
2024-09-12 13:03:45 +02:00
parent 0107330c32
commit ec033cfd10
2 changed files with 46 additions and 11 deletions

View File

@@ -20,20 +20,23 @@
; @param X pointer to data to calc crc8 for
; @param r18 number of bytes to calc crc8 for
; @param r19 polynomial to use
; @clobbers: R16, R17, R18, R20, X
; @clobbers: R16, R17, R18, R20, R21, X
crc8Calc:
ldi r16, 0xff ; start crc
clr r16 ; start crc
crc8Calc_loop1:
ld r17, X+ ; running var
eor r16, r17
ldi r20, 8 ; counter for loop2
crc8Calc_loop2:
lsl r16
brcc crc8Calc_l1
crc8Calc_loop2: ; r16=crc so far, r17=current inbyte
mov r21, r16
lsr r16
eor r21, r17
lsr r17
andi r21, 1
breq crc8Calc_withoutPoly
eor r16, r19
crc8Calc_l1:
crc8Calc_withoutPoly:
dec r20
brne crc8Calc_loop2
dec r18
@@ -41,5 +44,3 @@ crc8Calc_l1:
ret
; @end