t03: send memory stats.

This commit is contained in:
Martin Preuss
2025-02-14 22:45:49 +01:00
parent d5d6217c5e
commit f1f24168e5
2 changed files with 115 additions and 15 deletions

View File

@@ -25,7 +25,7 @@
.equ clock=8000000 ; Define the clock frequency
;.equ SEND_DEVICE_EVERY = 3000
.equ SEND_DEVICE_EVERY = 350 ; every 30s
.equ SEND_DEVICE_EVERY = 100 ; every 10s
.equ SEND_STATS_EVERY = 600 ; every minute
.nolist
@@ -206,6 +206,7 @@ onSystemTimerTick:
rcall maybeSendDeviceMsg
rcall maybeSendTStatsMsg
rcall maybeSendRStatsMsg
rcall maybeSendMStatsMsg
rcall TtyOnUart1_Periodically
ret
@@ -250,11 +251,16 @@ initModules:
ldi r16, HIGH(SEND_STATS_EVERY)
sts sendTStatsCounter+1, r16
ldi r16, LOW(SEND_STATS_EVERY)
ldi r16, LOW(SEND_STATS_EVERY+10)
sts sendRStatsCounter, r16
ldi r16, HIGH(SEND_STATS_EVERY)
ldi r16, HIGH(SEND_STATS_EVERY+10)
sts sendRStatsCounter+1, r16
ldi r16, LOW(SEND_STATS_EVERY+20)
sts sendMStatsCounter, r16
ldi r16, HIGH(SEND_STATS_EVERY+20)
sts sendMStatsCounter+1, r16
ret
; @end
@@ -285,6 +291,7 @@ initModules:
.include "modules/network/msg/device-w.asm"
.include "modules/network/msg/sendstats-w.asm"
.include "modules/network/msg/recvstats-w.asm"
.include "modules/network/msg/memstats-w.asm"
.include "modules/uart_hw/defs.asm"
.include "modules/uart_hw/lowlevel.asm"
@@ -348,12 +355,8 @@ maybeSendTStatsMsg:
rcall NETMSG_SendStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
sbiw xh:xl, 1
pop r16
push r16
rcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
pop r16
brcs maybeSendTStatsMsg_resetCounter
rcall NET_Buffer_ReleaseByNum ; (R16, X)
rjmp maybeSendTStatsMsg_end
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
brcc maybeSendTStatsMsg_end
; reset counter
maybeSendTStatsMsg_resetCounter:
ldi r24, LOW(SEND_STATS_EVERY)
@@ -383,12 +386,8 @@ maybeSendRStatsMsg:
rcall NETMSG_RecvStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
sbiw xh:xl, 1
pop r16
push r16
rcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
pop r16
brcs maybeSendRStatsMsg_resetCounter
rcall NET_Buffer_ReleaseByNum ; (R16, X)
rjmp maybeSendRStatsMsg_end
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
brcc maybeSendRStatsMsg_end
; reset counter
maybeSendRStatsMsg_resetCounter:
ldi r24, LOW(SEND_STATS_EVERY)
@@ -401,6 +400,37 @@ maybeSendRStatsMsg_end:
maybeSendMStatsMsg:
ldi yl, LOW(ttyOnUart1_iface)
ldi yh, HIGH(ttyOnUart1_iface)
lds r24, sendMStatsCounter
lds r25, sendMStatsCounter+1
sbiw r25:r24, 1
brne maybeSendMStatsMsg_storeCounter
; send device msg
rcall NET_Buffer_Alloc ; (R16, R17, X)
; brcc maybeSendTStatsMsg_resetCounter
brcc maybeSendMStatsMsg_end
push r16
adiw xh:xl, 1
rcall NETMSG_MemStats_Write ; (R16, R17, R18, R19, R20, R21)
sbiw xh:xl, 1
pop r16
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
brcc maybeSendMStatsMsg_end
; reset counter
maybeSendMStatsMsg_resetCounter:
ldi r24, LOW(SEND_STATS_EVERY)
ldi r25, HIGH(SEND_STATS_EVERY)
maybeSendMStatsMsg_storeCounter:
sts sendMStatsCounter, r24
sts sendMStatsCounter+1, r25
maybeSendMStatsMsg_end:
ret
checkRecvdMsg:
ldi yl, LOW(ttyOnUart1_iface)
ldi yh, HIGH(ttyOnUart1_iface)
@@ -503,6 +533,7 @@ programRamBegin:
deviceCounter: .byte 2
sendTStatsCounter: .byte 2
sendRStatsCounter: .byte 2
sendMStatsCounter: .byte 2
programRamEnd:

View File

@@ -0,0 +1,69 @@
; ***************************************************************************
; copyright : (C) 2025 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. *
; ***************************************************************************
; ---------------------------------------------------------------------------
; @routine NETMSG_MemStats_Write @global
;
; @param Y pointer to device to write msg for
; @param X pointer to buffer to write to
; @clobbers R16, R17, R18, R19, R20, R21
NETMSG_MemStats_Write:
ldi r16, 0xff
st X+, r16 ; dest address
ldi r16, 16 ; msg code+src address+14 payload bytes
st X+, r16 ; msg len
ldi r16, NETMSG_CMD_MEMSTATS
st X+, r16 ; msg code
ldd r16, Y+NET_IFACE_OFFS_ADDRESS
st X+, r16 ; src address
; uid
rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
; timestamp (0 for now)
clr r16
st X+, r16
st X+, r16
st X+, r16
st X+, r16
; stack used
ldi r20, LOW(RAMEND)
ldi r21, HIGH(RAMEND)
in r17, SPL
sub r20, r17
st X+, r20
in r17, SPH
sbc r21, r17
st X+, r21
; current buffers used
push xl
push xh
rcall NET_Buffer_CountUsed ; (r16, r17, r18, X)
pop xh
pop xl
st X+, r16
; max buffers used
clr r16
st X+, r16
; no buffer errors
ldd r16, Y+NET_IFACE_OFFS_ERR_NOBUF_LOW
st X+, r16
ldd r16, Y+NET_IFACE_OFFS_ERR_NOBUF_HIGH
st X+, r16
sbiw xh:xl, 18 ; go back to beginning of message (1 byte dst addr, 1 byte length, 16 bytes payload)
rcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 19 ; go back to beginning of message (1 byte dst addr, 1 byte length, 16 bytes payload, 1 byte crc)
ret
; @end