From 0a45e38939cbef6d2c50903d9ca954f27140b645 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 6 Jul 2025 18:21:48 +0200 Subject: [PATCH] make router functionality of r05 an app. --- avr/apps/0BUILD | 1 + avr/apps/router/0BUILD | 15 ++++ avr/apps/router/main.asm | 158 ++++++++++++++++++++++++++++++++++ avr/devices/all/apps.asm | 8 ++ avr/devices/all/includes.asm | 5 ++ avr/devices/r05/aqua_r05.xml | 29 ++++--- avr/devices/r05/main/main.asm | 141 +----------------------------- 7 files changed, 209 insertions(+), 148 deletions(-) create mode 100644 avr/apps/router/0BUILD create mode 100644 avr/apps/router/main.asm diff --git a/avr/apps/0BUILD b/avr/apps/0BUILD index 0e4cf4b..6934125 100644 --- a/avr/apps/0BUILD +++ b/avr/apps/0BUILD @@ -9,6 +9,7 @@ network reportsensors stats + router diff --git a/avr/apps/router/0BUILD b/avr/apps/router/0BUILD new file mode 100644 index 0000000..593fe80 --- /dev/null +++ b/avr/apps/router/0BUILD @@ -0,0 +1,15 @@ + + + + + + + + + main.asm + + + + + + diff --git a/avr/apps/router/main.asm b/avr/apps/router/main.asm new file mode 100644 index 0000000..5350c27 --- /dev/null +++ b/avr/apps/router/main.asm @@ -0,0 +1,158 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + + +; *************************************************************************** +; defines + +; --------------------------------------------------------------------------- +; network interfaces + +.equ NETDEV0_IFACENUM = 1 +.equ NETDEV1_IFACENUM = 2 + + + +; *************************************************************************** +; code + +.cseg + +; --------------------------------------------------------------------------- +; @routine AppRouter_Init @global + +AppRouter_Init: + ; set interface number for NETDEV0 + ldi r16, NETDEV0_IFACENUM + sts netInterfaceData+NET_IFACE_OFFS_IFACENUM, r16 + ; set interface number for NETDEV1 + ldi r16, NETDEV1_IFACENUM + sts netInterfaceData2+NET_IFACE_OFFS_IFACENUM, r16 + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine AppRouter_Run @global +; +; Read messages from either interface and forward to the other one. + +AppRouter_Run: + rjmp appRouterCheckRecvdMsg +; @end + + + +; --------------------------------------------------------------------------- +; @routine appRouterCheckRecvdMsg +; +; Read messages from either interface and forward to the other one. + +appRouterCheckRecvdMsg: + rcall NET_PeekNextIncomingMsgNum ; check read queue (bufNum->r16) + brcc appRouterCheckRecvdMsg_end ; no msg, jmp + rcall NET_Buffer_Locate ; (R17) + ; let system handle incoming messages + push r16 + adiw xh:xl, 1 + rcall appRouterLetSysHandleMsg + sbiw xh:xl, 1 + pop r16 + + ; forward to other interface + ld r17, X + andi r17, (1< - - - - - - - + + + + + + + + + - - + + + + + + + + + - + diff --git a/avr/devices/r05/main/main.asm b/avr/devices/r05/main/main.asm index dc6d041..a94b187 100644 --- a/avr/devices/r05/main/main.asm +++ b/avr/devices/r05/main/main.asm @@ -48,18 +48,13 @@ ; --------------------------------------------------------------------------- ; generic -; --------------------------------------------------------------------------- -; network interfaces - -.equ COMONUART0_IFACENUM = 1 -.equ COMONUART1_IFACENUM = 2 ; --------------------------------------------------------------------------- ; firmware settings including list of modules used -#define MAIN_WITHOUT_MSG_HANDLING ; we do message handling ourselfes +#define MAIN_WITHOUT_MSG_HANDLING ; message handling in AppRouter! #define MODULES_CLOCK #define MODULES_LED_SIMPLE @@ -76,7 +71,7 @@ #define MODULES_COMONUART0 #define MODULES_COMONUART1 #define APPS_NETWORK - +#define APPS_ROUTER .equ NET_BUFFERS_NUM = 8 @@ -162,13 +157,6 @@ firmwareStart: ; @routine onSystemStart onSystemStart: - ; set interface number for UART0 - ldi r16, COMONUART0_IFACENUM - sts comOnUart0_iface+NET_IFACE_OFFS_IFACENUM, r16 - ; set interface number for UART1 - ldi r16, COMONUART1_IFACENUM - sts comOnUart1_iface+NET_IFACE_OFFS_IFACENUM, r16 - ret ; @end @@ -187,9 +175,6 @@ onEveryDay: onEveryMinute: -#ifdef APPS_STATS - rcall sendPacketsIface2In -#endif ret ; @end @@ -201,7 +186,6 @@ onEveryMinute: ; Called on every loop (i.e. after awakening from sleep). onEveryLoop: - rcall checkRecvdMsg ret ; @end @@ -219,126 +203,6 @@ onMessageReceived: -; --------------------------------------------------------------------------- -; @routine checkRecvdMsg -; -; Read messages from either interface and forward to the other one. - -checkRecvdMsg: - rcall NET_PeekNextIncomingMsgNum ; check read queue (bufNum->r16) - brcc checkRecvdMsg_end ; no msg, jmp - rcall NET_Buffer_Locate ; (R17) - ; let system handle incoming messages - push r16 - adiw xh:xl, 1 - rcall letSysHandleMsg - sbiw xh:xl, 1 - pop r16 - - ; forward to other interface - ld r17, X - andi r17, (1<