74 lines
2.1 KiB
NASM
74 lines
2.1 KiB
NASM
; ***************************************************************************
|
|
; copyright : (C) 2023 by Martin Preuss
|
|
; email : martin@libchipcard.de
|
|
;
|
|
; ***************************************************************************
|
|
; * This file is part of the project "AqHome". *
|
|
; * Please see toplevel file COPYING of that project for license details. *
|
|
; ***************************************************************************
|
|
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; add checksum byte to buffer
|
|
;
|
|
; IN:
|
|
; - 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:
|
|
rcall com2CalcMsgChecksum
|
|
st X+, r16 ; add checksum byte
|
|
sec
|
|
ret
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; check message in buffer
|
|
;
|
|
; IN:
|
|
; - X : pointer to packet buffer
|
|
; OUT:
|
|
; - CFLAG: set if okay, clear otherwise
|
|
; MODIFIED REGS: R16, R17 (R18, R20, X)
|
|
|
|
com2CheckMessageInBuffer:
|
|
rcall com2CalcMsgChecksum ; R16, R18, (R17, R20, X)
|
|
ld r17, X
|
|
cp r16, r17 ; should be equal
|
|
brne com2CheckMessageInBuffer_error
|
|
sec
|
|
ret
|
|
com2CheckMessageInBuffer_error:
|
|
clc
|
|
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)
|
|
|
|
|