make router functionality of r05 an app.
This commit is contained in:
@@ -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