From 6ecc1721b09a86e74bce3c350d60b8f9202e2471 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 6 Jul 2025 20:21:51 +0200 Subject: [PATCH] r05: no longer use APPS_NETWORK. Implemented some of those features in APP_ROUTER like PING, REBOOT. --- avr/apps/router/main.asm | 122 ++++++++++++++++++++++++++++++++++ avr/devices/all/apps.asm | 4 ++ avr/devices/all/includes.asm | 3 + avr/devices/all/main.asm | 4 ++ avr/devices/r05/main/main.asm | 10 +-- 5 files changed, 136 insertions(+), 7 deletions(-) diff --git a/avr/apps/router/main.asm b/avr/apps/router/main.asm index 5350c27..4df9bf2 100644 --- a/avr/apps/router/main.asm +++ b/avr/apps/router/main.asm @@ -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 ; diff --git a/avr/devices/all/apps.asm b/avr/devices/all/apps.asm index 0c17385..1489a59 100644 --- a/avr/devices/all/apps.asm +++ b/avr/devices/all/apps.asm @@ -89,6 +89,10 @@ mainAppsOnPacketReceived: bigcall AppNetwork_HandleMsg #endif +#ifdef APPS_ROUTER + bigcall AppRouter_HandleMsg +#endif + #ifdef APPS_MA_LIGHT bigcall AppMotionLight_OnPacketReceived #endif diff --git a/avr/devices/all/includes.asm b/avr/devices/all/includes.asm index 172803d..7a8b6ae 100644 --- a/avr/devices/all/includes.asm +++ b/avr/devices/all/includes.asm @@ -244,6 +244,9 @@ #ifdef APPS_ROUTER .include "apps/router/main.asm" +.include "modules/network/msg/reboot-d.asm" +.include "modules/network/msg/reboot-r.asm" +.include "modules/network/msg/pong-w.asm" #endif diff --git a/avr/devices/all/main.asm b/avr/devices/all/main.asm index 98f5f17..d752723 100644 --- a/avr/devices/all/main.asm +++ b/avr/devices/all/main.asm @@ -186,6 +186,10 @@ sysOnEveryDay: bigcall AppNetwork_EveryDay #endif +#ifdef APPS_ROUTER + bigcall AppRouter_EveryDay +#endif + bigjmp onEveryDay ; @end diff --git a/avr/devices/r05/main/main.asm b/avr/devices/r05/main/main.asm index a94b187..b777a22 100644 --- a/avr/devices/r05/main/main.asm +++ b/avr/devices/r05/main/main.asm @@ -55,6 +55,7 @@ #define MAIN_WITHOUT_MSG_HANDLING ; message handling in AppRouter! +#define APP_STATS_NETDEV2 ; send stats for 2nd device #define MODULES_CLOCK #define MODULES_LED_SIMPLE @@ -70,7 +71,7 @@ #define MODULES_NETWORK #define MODULES_COMONUART0 #define MODULES_COMONUART1 -#define APPS_NETWORK +;#define APPS_NETWORK #define APPS_ROUTER @@ -168,18 +169,13 @@ onSystemStart: onEvery100ms: onEverySecond: +onEveryMinute: onEveryHour: onEveryDay: ret -onEveryMinute: - ret -; @end - - - ; --------------------------------------------------------------------------- ; @routine onEveryLoop ;