r05: no longer use APPS_NETWORK.

Implemented some of those features in APP_ROUTER like PING, REBOOT.
This commit is contained in:
Martin Preuss
2025-07-06 20:21:51 +02:00
parent 1824e8ccdf
commit 6ecc1721b0
5 changed files with 136 additions and 7 deletions

View File

@@ -20,6 +20,19 @@
; ***************************************************************************
; data
.dseg
appRouterDataBegin:
appRouterRangeBegin: .byte 1
appRouterRangeEnd: .byte 1
appRouterDataEnd:
; ***************************************************************************
; code
@@ -29,6 +42,20 @@
; @routine AppRouter_Init @global
AppRouter_Init:
ldi xh, HIGH(appRouterDataBegin)
ldi xl, LOW(appRouterDataBegin)
clr r16
ldi r17, (appRouterDataEnd-appRouterDataBegin)
rcall Utils_FillSram
ldi r16, 0xe0 ; default range from 0xe0-0xef (will be changed later)
sts netInterfaceData+NET_IFACE_OFFS_ADDRESS, r16 ; use first address for router itself
sts netInterfaceData2+NET_IFACE_OFFS_ADDRESS, r16 ; use same address for both interfaces to save on addresses
inc r16
sts appRouterRangeBegin, r16 ; range from router+1
ldi r16, 0xef
sts appRouterRangeEnd, r16
; set interface number for NETDEV0
ldi r16, NETDEV0_IFACENUM
sts netInterfaceData+NET_IFACE_OFFS_IFACENUM, r16
@@ -40,6 +67,24 @@ AppRouter_Init:
; ---------------------------------------------------------------------------
; @routine AppRouter_EveryDay @global
;
; @clobbers R16, R17, X
AppRouter_EveryDay:
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
bigcall NET_Interface_ResetStats ; (R16, R17, X)
ldi yl, LOW(netInterfaceData2)
ldi yh, HIGH(netInterfaceData2)
bigcall NET_Interface_ResetStats ; (R16, R17, X)
ret
; @end
; ---------------------------------------------------------------------------
; @routine AppRouter_Run @global
;
@@ -51,6 +96,83 @@ AppRouter_Run:
; ---------------------------------------------------------------------------
; @routine AppRouter_HandleMsg @global
;
; @param X pointer to received message
AppRouter_HandleMsg:
adiw xh:xl, NETMSG_OFFS_CMD ; maybe move ping/reboot handling to all/main.asm?
ld r16, X
sbiw xh:xl, NETMSG_OFFS_CMD
cpi r16, NETMSG_CMD_REBOOT_REQUEST
breq AppRouter_HandleMsg_handleRebootMsg
cpi r16, NETMSG_CMD_PING
breq AppRouter_HandleMsg_handlePingMsg
rjmp AppRouter_HandleMsg_clcRet
AppRouter_HandleMsg_handleRebootMsg:
push xl
push xh
rcall appRouterHandleRebootRequest
pop xh
pop xl
ret
AppRouter_HandleMsg_handlePingMsg:
push xl
push xh
rcall appRouterHandlePingRequest
pop xh
pop xl
ret
AppRouter_HandleMsg_clcRet:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine appRouterHandleRebootRequest
;
; @param X pointer to received message
appRouterHandleRebootRequest:
ld r16, X ; dest addr
cpi r16, 0xff ; don't reboot for broadcast address
breq appRouterHandleRebootRequest_end
rcall NETMSG_RebootRequestRead
brcc appRouterHandleRebootRequest_end
; reboot
cli
bigjmp BOOTLOADER_ADDR
appRouterHandleRebootRequest_end:
ret
; @end
appRouterHandlePingRequest:
adiw xh:xl, NETMSG_OFFS_SRCADDR
ld r17, X
push r17
bigcall NET_Buffer_Alloc ; (R16, R17, X)
pop r17
brcc appRouterHandlePingRequest_end ; jmp on error
push r16 ; buffer num
mov r16, r17 ; DEST addr
adiw xh:xl, 1
ldi yl, LOW(netInterfaceData)
ldi yh, HIGH(netInterfaceData)
bigcall NETMSG_Pong_Write ; (R16, R17, R18, R19, R20, X)
sbiw xh:xl, 1
pop r16 ; buffer num
bigcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
appRouterHandlePingRequest_end:
ret
; ---------------------------------------------------------------------------
; @routine appRouterCheckRecvdMsg
;