make router functionality of r05 an app.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
network
|
||||
reportsensors
|
||||
stats
|
||||
router
|
||||
</subdirs>
|
||||
|
||||
<extradist>
|
||||
|
||||
15
avr/apps/router/0BUILD
Normal file
15
avr/apps/router/0BUILD
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<subdirs>
|
||||
</subdirs>
|
||||
|
||||
<extradist>
|
||||
main.asm
|
||||
</extradist>
|
||||
|
||||
|
||||
</gwbuild>
|
||||
|
||||
|
||||
158
avr/apps/router/main.asm
Normal file
158
avr/apps/router/main.asm
Normal file
@@ -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<<NET_IFACE_BUFFER_IFACENUM1_BIT) | (1<<NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
rcall appRouterReverseInterfaceNum ; (R16, R17)
|
||||
rcall appRouterAddMsgToInterface
|
||||
brcc appRouterCheckRecvdMsg_end ; could not add, jmp
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
rjmp appRouterCheckRecvdMsg
|
||||
appRouterCheckRecvdMsg_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appRouterLetSysHandleMsg
|
||||
;
|
||||
; @param X pointer to msg to handle (point behind the buffer header!)
|
||||
; @clobbers any, !X
|
||||
|
||||
appRouterLetSysHandleMsg:
|
||||
ld r16, X
|
||||
cpi r16, 0xff
|
||||
breq appRouterLetSysHandleMsg_forMe
|
||||
lds r17, netInterfaceData+NET_IFACE_OFFS_ADDRESS
|
||||
cp r16, r17
|
||||
brne appRouterLetSysHandleMsg_end
|
||||
appRouterLetSysHandleMsg_forMe:
|
||||
push xl
|
||||
push xh
|
||||
rcall onMessageReceived
|
||||
pop xh
|
||||
pop xl
|
||||
push xl
|
||||
push xh
|
||||
rcall mainModulesOnPacketReceived
|
||||
pop xh
|
||||
pop xl
|
||||
push xl
|
||||
push xh
|
||||
rcall mainAppsOnPacketReceived
|
||||
pop xh
|
||||
pop xl
|
||||
appRouterLetSysHandleMsg_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appRouterReverseInterfaceNum
|
||||
;
|
||||
; @param r17 buffer num
|
||||
; @return r17 reversed interface number
|
||||
; @clobbers r16, r17
|
||||
|
||||
appRouterReverseInterfaceNum:
|
||||
ldi r16, (1<<NET_IFACE_BUFFER_IFACENUM1_BIT) | (1<<NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
eor r17, r16
|
||||
and r17, r16
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appRouterAddMsgToInterface
|
||||
; @param r16 buffer num
|
||||
; @param r17 interface num
|
||||
|
||||
appRouterAddMsgToInterface:
|
||||
cpi r17, NETDEV0_IFACENUM
|
||||
brne appRouterAddMsgToInterface_notNetDev0
|
||||
ldi yl, LOW(netInterfaceData)
|
||||
ldi yh, HIGH(netInterfaceData)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
appRouterAddMsgToInterface_notNetDev0:
|
||||
ldi yl, LOW(netInterfaceData2)
|
||||
ldi yh, HIGH(netInterfaceData2)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
appRouterAddMsgToInterface_end:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,10 @@ initApps:
|
||||
bigcall AppNetwork_Init
|
||||
#endif
|
||||
|
||||
#ifdef APPS_ROUTER
|
||||
bigcall AppRouter_Init
|
||||
#endif
|
||||
|
||||
#ifdef APPS_MOTION
|
||||
bigcall AppMotion_Init
|
||||
#endif
|
||||
@@ -62,9 +66,13 @@ initApps:
|
||||
;
|
||||
|
||||
runApps:
|
||||
#ifdef APPS_ROUTER
|
||||
bigcall AppRouter_Run
|
||||
#endif
|
||||
|
||||
; add more modules here
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -242,6 +242,11 @@
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef APPS_ROUTER
|
||||
.include "apps/router/main.asm"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef APPS_REPORTSENSORS
|
||||
.include "apps/reportsensors/data.asm"
|
||||
.include "apps/reportsensors/main.asm"
|
||||
|
||||
@@ -7,18 +7,27 @@
|
||||
<values>
|
||||
<value name="DS18B20_TEMP" id="0x06" type="sensor" dataType="rational" modality="temperature" units="C" denom="16" />
|
||||
|
||||
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_packets_in" id="0xe0" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_packets_out" id="0xe1" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_content_errors" id="0xe2" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_io_errors" id="0xe3" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_nobuf_errors" id="0xe4" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_collision_errors" id="0xe5" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_busy_errors" id="0xe6" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_msgsize_errors" id="0xe7" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_missed_errors" id="0xe8" type="sensor" dataType="uint16" denom="1" />
|
||||
|
||||
<value name="stats_packets2_in" id="0xe9" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_packets2_out" id="0xe9" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_packets_in2" id="0xe9" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_packets_out2" id="0xea" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_content_errors2" id="0xeb" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_io_errors2" id="0xec" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_nobuf_errors2" id="0xed" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_collision_errors2" id="0xee" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_busy_errors2" id="0xef" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_msgsize_errors2" id="0xf0" type="sensor" dataType="uint16" denom="1" />
|
||||
<value name="stats_missed_errors2" id="0xf1" type="sensor" dataType="uint16" denom="1" />
|
||||
|
||||
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
|
||||
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
|
||||
</values>
|
||||
|
||||
</device>
|
||||
|
||||
@@ -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<<NET_IFACE_BUFFER_IFACENUM1_BIT) | (1<<NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
rcall reverseInterfaceNum ; (R16, R17)
|
||||
; ldi r17, COMONUART0_IFACENUM ; DEBUG: send everything to uart0 to test that code first
|
||||
rcall addMsgToInterface
|
||||
brcc checkRecvdMsg_end ; could not add, jmp
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
rjmp checkRecvdMsg
|
||||
checkRecvdMsg_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine letSysHandleMsg
|
||||
;
|
||||
; @param X pointer to msg to handle (point behind the buffer header!)
|
||||
; @clobbers any, !X
|
||||
|
||||
letSysHandleMsg:
|
||||
ld r16, X
|
||||
cpi r16, 0xff
|
||||
breq letSysHandleMsg_forMe
|
||||
lds r17, comOnUart0_iface+NET_IFACE_OFFS_ADDRESS
|
||||
cp r16, r17
|
||||
brne letSysHandleMsg_end
|
||||
letSysHandleMsg_forMe:
|
||||
push xl
|
||||
push xh
|
||||
rcall onMessageReceived
|
||||
pop xh
|
||||
pop xl
|
||||
push xl
|
||||
push xh
|
||||
rcall mainModulesOnPacketReceived
|
||||
pop xh
|
||||
pop xl
|
||||
push xl
|
||||
push xh
|
||||
rcall mainAppsOnPacketReceived
|
||||
pop xh
|
||||
pop xl
|
||||
letSysHandleMsg_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine reverseInterfaceNum
|
||||
;
|
||||
; @param r17 buffer num
|
||||
; @return r17 reversed interface number
|
||||
; @clobbers r16, r17
|
||||
|
||||
reverseInterfaceNum:
|
||||
ldi r16, (1<<NET_IFACE_BUFFER_IFACENUM1_BIT) | (1<<NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
eor r17, r16
|
||||
and r17, r16
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine addMsgToInterface
|
||||
; @param r16 buffer num
|
||||
; @param r17 interface num
|
||||
|
||||
addMsgToInterface:
|
||||
cpi r17, COMONUART0_IFACENUM
|
||||
brne addMsgToInterface_notUart0
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
addMsgToInterface_notUart0:
|
||||
ldi yl, LOW(comOnUart1_iface)
|
||||
ldi yh, HIGH(comOnUart1_iface)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
addMsgToInterface_end:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
#ifdef APPS_STATS
|
||||
sendPacketsIface2In:
|
||||
ldi yl, LOW(netInterfaceData)
|
||||
ldi yh, HIGH(netInterfaceData)
|
||||
; ldi yl, LOW(comOnUart1_iface)
|
||||
; ldi yh, HIGH(comOnUart1_iface)
|
||||
|
||||
ldi r17, AQHOME_VALUEID_STATS_PACKETS_IN2
|
||||
lds r18, comOnUart1_iface+NET_IFACE_OFFS_PACKETSIN_LOW
|
||||
lds r19, comOnUart1_iface+NET_IFACE_OFFS_PACKETSIN_HIGH
|
||||
rjmp appStatsSend16BitValue
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; includes
|
||||
@@ -353,6 +217,7 @@ sendPacketsIface2In:
|
||||
; defines for network interface
|
||||
|
||||
.equ netInterfaceData = comOnUart0_iface
|
||||
.equ netInterfaceData2 = comOnUart1_iface
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user