aqhome-nodes: send heartbeat message to interface every 2mins.

e02 now expects this message. If for at least 10mins no such msg is
received the USB interface is reset.
This commit is contained in:
Martin Preuss
2026-04-27 16:01:12 +02:00
parent a0360d5373
commit 0ac20ba82c
12 changed files with 217 additions and 26 deletions

View File

@@ -108,3 +108,13 @@
.equ USART0_DATAREG = UDR0
.equ USART1_DATAREG = UDR1
; ---------------------------------------------------------------------------
; MCP2221
.equ MCP2221_RESET_DDR = DDRB
.equ MCP2221_RESET_PORT = PORTB
.equ MCP2221_RESET_PINNUM = PORTB0

View File

@@ -72,30 +72,12 @@
#define APP_ROUTER_NO_ADDR_MGR
#define MODULES_CLOCK
;#define MODULES_COM
;#define MODULES_COM_WITH_ADDR_PROTO
;#define MODULES_LED
#define MODULES_LED_SIMPLE
;#define MODULES_LED_SIGNAL
;#define MODULES_LED_ACTIVITY
;#define MODULES_TWI_MASTER
;#define MODULES_LCD
;#define LCD_MINIMAL_FONT
;#define MODULES_SI7021
;#define MODULES_STATS
;#define MODULES_CNY70
;#define MODULES_REED
;#define MODULES_OWI_MASTER
;#define MODULES_DS18B20
;#define MODULES_MOTION
#define MODULES_NETWORK
#define MODULES_COM2W
;#define MODULES_COMONUART0
;#define MODULES_TTYONUART1
#define MODULES_UARTFD0
#define APPS_STATS
;#define APPS_NETWORK
;#define APPS_ROUTER
#define APPS_FORWARDER
@@ -106,14 +88,17 @@
.equ HEARTBEAT_MAXTIME_IN_MINS = 10 ; 10 minutes
.equ LEDMCPRESET_ONTIME = 2
.equ LEDMCPRESET_OFFTIME = 2
.equ LEDMCPRESET_REPEATS = 50 ; 50*0.4=20s
; ---------------------------------------------------------------------------
; defines for values
.equ VALUE_ID_DS18B20_TEMP = 0x06
.equ VALUE_ID_LEDSIMPLE_TIMING = 0x88
;.equ VALUE_ID_ROUTER_SETRANGE = 0x89
; none
@@ -187,6 +172,30 @@ onSystemStart:
ldi r16, 0xf0
sts netInterfaceData+NET_IFACE_OFFS_ADDRESS, r16
sts netInterfaceData2+NET_IFACE_OFFS_ADDRESS, r16
ldi r16, HEARTBEAT_MAXTIME_IN_MINS
sts heartbeatTimer, r16
rcall resetMcp2221
ret
; @end
onEveryMinute:
lds r16, heartbeatTimer
tst r16
breq onEverySecond_ret
dec r16
sts heartbeatTimer, r16
brne onEverySecond_ret
rcall resetMcp2221
ldi r16, HEARTBEAT_MAXTIME_IN_MINS
sts heartbeatTimer, r16
onEverySecond_ret:
ret
; @end
@@ -194,7 +203,6 @@ onSystemStart:
onEvery100ms:
onEverySecond:
onEveryMinute:
onEveryHour:
onEveryDay:
ret
@@ -218,12 +226,48 @@ onEveryLoop:
; Called on every message received
onMessageReceived:
adiw xh:xl, NETMSG_OFFS_CMD
ld r16, X
sbiw xh:xl, NETMSG_OFFS_CMD
cpi r16, NETMSG_CMD_HEARTBEAT
brne onMessageReceived_ret
ldi r16, HEARTBEAT_MAXTIME_IN_MINS
sts heartbeatTimer, r16
onMessageReceived_ret:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine resetMcp2221
;
; Reset MCP2221 by pulling /RST low for 10us.
resetMcp2221:
push r15
inr r15, SREG
cli
sbi MCP2221_RESET_DDR, MCP2221_RESET_PINNUM ; out
cbi MCP2221_RESET_PORT, MCP2221_RESET_PINNUM ; set RST low
Utils_WaitNanoSecs 10000, 0, r22 ; minimum is 2us, use 10us to be safe
sbi MCP2221_RESET_PORT, MCP2221_RESET_PINNUM ; set RST high
outr SREG, r15
pop r15
#ifdef MODULES_LED_SIMPLE
ldi r18, LEDMCPRESET_ONTIME
ldi r19, LEDMCPRESET_OFFTIME
ldi r20, LEDMCPRESET_REPEATS
bigcall LedSimple_SetTiming
#endif
ret
; @end
@@ -249,3 +293,16 @@ deviceCodeEnd:
.warning "Code reaches into boot loader!"
.endif
; ***************************************************************************
; data segment
.dseg
heartbeatTimer: .byte 1

View File

@@ -17,6 +17,7 @@
.equ NETMSG_CMD_PING = 10
.equ NETMSG_CMD_PONG = 11
.equ NETMSG_CMD_HEARTBEAT = 12
.equ NETMSG_CMD_SENDSTATS = 22
.equ NETMSG_CMD_RECVSTATS = 23
.equ NETMSG_CMD_TWIBUSMEMBER = 30