COM: Enabled packet-in counter.

This commit is contained in:
Martin Preuss
2023-01-29 18:51:15 +01:00
parent 857e358836
commit 8a395cf9c3

View File

@@ -43,6 +43,10 @@
.equ COM_CMD_I2CBUSMEMBER = 4 .equ COM_CMD_I2CBUSMEMBER = 4
.equ COM_CMD_DEBUG = 5 .equ COM_CMD_DEBUG = 5
.equ COM_ERR_NOTFORME = 1
.equ COM_ERR_CHECKSUM = 2
.equ COM_ERR_IO = 3
; *************************************************************************** ; ***************************************************************************
; data ; data
@@ -89,21 +93,25 @@ comIsrPcint0:
push r1 push r1
push r16 push r16
push r17 push r17
push r20 push r18
push r21 push r19
push r22 push r20
push xh push r21
push xl push r22
push yh push xh
push yl push xl
rcall comReceivePacketHandleBuffer ; (R1, R16, R17, R20, R21, R22, X, Y) push yh
pop yl push yl
pop yh rcall comReceivePacketHandleBuffer ; (R1, R16, R17, R18, R19, R20, R21, R22, X, Y
pop xl pop yl
pop xh pop yh
pop r22 pop xl
pop r21 pop xh
pop r20 pop r22
pop r21
pop r20
pop r19
pop r18
pop r17 pop r17
pop r16 pop r16
pop r1 pop r1
@@ -130,7 +138,7 @@ Com_Init:
ldi r17, (comDataEnd-comDataBegin) ldi r17, (comDataEnd-comDataBegin)
rcall Utils_FillSram rcall Utils_FillSram
ldi r16, 2 ; debug: set fixed address "2" ldi r16, 1 ; debug: set fixed address "1"
sts comAddress, r16 sts comAddress, r16
; setup pins and interrupts ; setup pins and interrupts
@@ -732,7 +740,7 @@ comSendPacketFromSram_error:
; - nothing ; - nothing
; OUT: ; OUT:
; - CFLAG: set if okay, cleared otherwise ; - CFLAG: set if okay, cleared otherwise
; MODIFIED REGISTERS: R16, R17, X, Y (R1, R20, R21, R22) ; MODIFIED REGISTERS: R16, R17, X, Y (R1, R18, R19, R20, R21, R22)
comReceivePacketHandleBuffer: comReceivePacketHandleBuffer:
rcall COM_BufferAlloc rcall COM_BufferAlloc
@@ -744,20 +752,32 @@ comReceivePacketHandleBuffer:
clr r17 clr r17
add xl, r16 add xl, r16
adc xh, r17 adc xh, r17
rcall comReceivePacketToSram ; (r1, r16, r17, R20, R21, R22, X) rcall comReceivePacketToSram ; (r1, r16, r17, R20, R21, R22, X)
brcc comReceivePacketHandleBuffer_dealloc brcc comReceivePacketHandleBuffer_dealloc
; handle buffer flags ; handle buffer flags
ldi r16, COM_BUFFER_FLAGS_RECEIVED ldi r16, COM_BUFFER_FLAGS_RECEIVED
std y+COM_BUFFER_OFFS_FLAGS, r16 std y+COM_BUFFER_OFFS_FLAGS, r16
ldi xl, LOW(comStatsPacketsIn)
ldi xh, HIGH(comStatsPacketsIn)
rcall Utils_IncrementCounter16 ; (r18, r19, 22)
sec sec
ret ret
comReceivePacketHandleBuffer_dealloc: comReceivePacketHandleBuffer_dealloc:
rcall COM_BufferDeallocBack ; (r16, r17, r21) push r16
rcall COM_BufferDeallocBack ; (r16, r17, r21)
pop r16
cpi r16, COM_ERR_NOTFORME ; packet just not for me?
breq comReceivePacketHandleBuffer_notforme ; correct, don't count as error
ldi xl, LOW(comStatsRecvErrs)
ldi xh, HIGH(comStatsRecvErrs)
rcall Utils_IncrementCounter16 ; (r18, r19, 22)
comReceivePacketHandleBuffer_error: comReceivePacketHandleBuffer_error:
clc clc
ret ret
comReceivePacketHandleBuffer_notforme: ; TODO: may count packets not for me?
clc
ret
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
@@ -782,6 +802,7 @@ comReceivePacketToSram:
lds r17, comAddress lds r17, comAddress
cp r16, r17 cp r16, r17
breq comReceivePacketToSram_acceptAddr breq comReceivePacketToSram_acceptAddr
ldi r16, COM_ERR_NOTFORME
clc ; not for me clc ; not for me
ret ret
comReceivePacketToSram_acceptAddr: comReceivePacketToSram_acceptAddr:
@@ -813,8 +834,13 @@ comReceivePacketToSram_readXOR:
brne comReceivePacketToSram_error brne comReceivePacketToSram_error
sec sec
ret ret
comReceivePacketToSram_crcError:
ldi r16, COM_ERR_CHECKSUM
clc
ret
comReceivePacketToSram_error: comReceivePacketToSram_error:
ldi r16, COM_ERR_IO
clc clc
ret ret