improved "run" code.
This commit is contained in:
@@ -64,6 +64,10 @@ AppRouter_Init:
|
||||
; set interface number for NETDEV1
|
||||
ldi r16, NETDEV1_IFACENUM
|
||||
sts netInterfaceData2+NET_IFACE_OFFS_IFACENUM, r16
|
||||
|
||||
ldi r18, NETMSG_CMD_ADDRESS_RANGE
|
||||
rcall appRouterSendRangeMsgToDev1
|
||||
|
||||
ret
|
||||
; @end
|
||||
|
||||
@@ -128,6 +132,7 @@ appRouterHandleMsgAnyDev_handleRebootMsg:
|
||||
ret
|
||||
appRouterHandleMsgAnyDev_handlePingMsg:
|
||||
rcall appRouterHandlePingRequest
|
||||
clc
|
||||
ret
|
||||
appRouterHandleMsgAnyDev_handleSetValue:
|
||||
rcall NETMSG_ValueRead ; (none)
|
||||
@@ -174,7 +179,7 @@ appRouterHandleDev1Msg:
|
||||
pop xl
|
||||
rjmp appRouterHandleDev1Msg_end
|
||||
appRouterHandleDev1Msg_savedX:
|
||||
adiw xh:xl, NETMSG_OFFS_CMD ; maybe move ping/reboot handling to all/main.asm?
|
||||
adiw xh:xl, NETMSG_OFFS_CMD
|
||||
ld r16, X
|
||||
sbiw xh:xl, NETMSG_OFFS_CMD
|
||||
cpi r16, NETMSG_CMD_NEED_ADDRESS
|
||||
@@ -182,6 +187,7 @@ appRouterHandleDev1Msg_savedX:
|
||||
cpi r16, NETMSG_CMD_CLAIM_ADDRESS
|
||||
breq appRouterHandleDev1Msg_handleClaimAddr
|
||||
; add more here
|
||||
ldi r16, 0
|
||||
rjmp appRouterHandleDev1Msg_clcRet
|
||||
appRouterHandleDev1Msg_handleNeedAddr:
|
||||
ldi r18, NETMSG_CMD_ADDRESS_RANGE
|
||||
@@ -255,7 +261,7 @@ appRouterSendAddrMsgToDev1:
|
||||
bigcall NETMSG_Address_Write ; (R16, R17, R18, R19, R20, R21)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
rcall appRouterSendMsgToDev1 ; (R16, R17, R18, X, Y)
|
||||
rcall appRouterSendMsgToDev1 ; (R16, R17, R18, R24, R25, X, Y)
|
||||
appRouterSendAddrMsgToDev1_end:
|
||||
ret
|
||||
; @end
|
||||
@@ -266,7 +272,8 @@ appRouterSendAddrMsgToDev1_end:
|
||||
; @routine appRouterSendRangeMsgToDev1
|
||||
;
|
||||
; @param R18 msg code
|
||||
; @clobbers (R16, R17, R18, R19, R20, R21, X, Y)
|
||||
; @return CFLAG set if message enqueued, cleared on error
|
||||
; @clobbers (R16, R17, R18, R19, R20, R21, R24, R25, X, Y)
|
||||
|
||||
appRouterSendRangeMsgToDev1:
|
||||
bigcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
@@ -278,7 +285,7 @@ appRouterSendRangeMsgToDev1:
|
||||
bigcall NETMSG_Range_Write ; (R16, R17, R18, R19, R20, R21)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
rcall appRouterSendMsgToDev1 ; (R16, R17, R18, X, Y)
|
||||
rcall appRouterSendMsgToDev1 ; (R16, R17, R18, R24, R25, X, Y)
|
||||
appRouterSendRangeMsgToDev1_end:
|
||||
ret
|
||||
; @end
|
||||
@@ -290,7 +297,8 @@ appRouterSendRangeMsgToDev1_end:
|
||||
;
|
||||
; @param R16 num of allocated buffer
|
||||
; @param X msg to send (points to start of allocated buffer, e.g. buffer header)
|
||||
; @clobbers Y (R16, R17, R18, X)
|
||||
; @return CFLAG set if message enqueued, cleared on error
|
||||
; @clobbers Y (R16, R17, R18, R24, R25, X)
|
||||
|
||||
appRouterSendMsgToDev1:
|
||||
ldi yl, LOW(netInterfaceData2)
|
||||
@@ -298,6 +306,8 @@ appRouterSendMsgToDev1:
|
||||
bigcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
|
||||
brcs appRouterSendMsgToDev1_end
|
||||
bigcall NET_Buffer_ReleaseByNum ; (R16, X)
|
||||
ldi r16, NET_IFACE_OFFS_ERR_NOBUF_LOW
|
||||
rcall NET_Interface_IncCounter16 ; (R24, R25)
|
||||
clc
|
||||
appRouterSendMsgToDev1_end:
|
||||
ret
|
||||
@@ -354,27 +364,29 @@ appRouterHandlePingRequest_end:
|
||||
; @routine appRouterCheckRecvdMsg
|
||||
;
|
||||
; Read messages from either interface and forward to the other one.
|
||||
;
|
||||
; @return CFLAG set if something done, cleared otherwise
|
||||
|
||||
appRouterCheckRecvdMsg:
|
||||
rcall NET_PeekNextIncomingMsgNum ; check read queue (bufNum->r16)
|
||||
brcc appRouterCheckRecvdMsg_end ; no msg, jmp
|
||||
rcall NET_Buffer_Locate ; (R17)
|
||||
rcall appRouterHandleRouterMsgWithHdr ; filter out router msgs
|
||||
brcs appRouterCheckRecvdMsg_removeMsg ; handled by router code, don't forward
|
||||
; let system handle incoming messages
|
||||
adiw xh:xl, 1
|
||||
rcall appRouterLetSysHandleMsg
|
||||
sbiw xh:xl, 1
|
||||
rcall NET_PeekNextIncomingMsgNum ; check read queue (bufNum->r16)
|
||||
brcc appRouterCheckRecvdMsg_end ; no msg, jmp
|
||||
rcall NET_Buffer_Locate ; (R17)
|
||||
rcall appRouterHandleRouterMsgWithHdr ; filter out router msgs
|
||||
brcs appRouterCheckRecvdMsg_removeMsg ; handled by router code, don't forward
|
||||
; let system handle incoming messages
|
||||
adiw xh:xl, 1
|
||||
rcall appRouterLetSysHandleMsg
|
||||
sbiw xh:xl, 1
|
||||
|
||||
; 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
|
||||
|
||||
; 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
|
||||
sec
|
||||
ret
|
||||
appRouterCheckRecvdMsg_removeMsg:
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
rcall NET_Buffer_ReleaseByNum ; (R16, X)
|
||||
@@ -392,8 +404,8 @@ appRouterCheckRecvdMsg_end:
|
||||
|
||||
appRouterHandleRouterMsgWithHdr:
|
||||
ld r17, X
|
||||
andi r17, (1<<NET_IFACE_BUFFER_IFACENUM1_BIT) | (1<<NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
adiw xh:xl, 1
|
||||
andi r17, (1<<NET_IFACE_BUFFER_IFACENUM1_BIT) | (1<<NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
cpi r17, NETDEV1_IFACENUM
|
||||
brne appRouterHandleRouterMsgWithHdr_any
|
||||
rcall appRouterHandleDev1Msg ; handle messages from controlled subnet
|
||||
|
||||
@@ -66,11 +66,21 @@ initApps:
|
||||
;
|
||||
|
||||
runApps:
|
||||
clr r16
|
||||
#ifdef APPS_ROUTER
|
||||
bigcall AppRouter_Run
|
||||
push r16
|
||||
bigcall AppRouter_Run
|
||||
pop r16
|
||||
sbci r16, 0 ; decrease r16 only if CFLAG set
|
||||
#endif
|
||||
|
||||
; add more modules here
|
||||
|
||||
tst r16
|
||||
clc
|
||||
breq runApps_end
|
||||
sec
|
||||
runApps_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
@@ -241,6 +241,8 @@
|
||||
.include "modules/network/msg/pong-w.asm"
|
||||
.include "modules/network/msg/range-d.asm"
|
||||
.include "modules/network/msg/range-r.asm"
|
||||
.include "common/eeprom-r.asm"
|
||||
.include "common/eeprom-w.asm"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -55,10 +55,26 @@ main:
|
||||
|
||||
main_loop:
|
||||
bigcall systemSleep ; system-dependant
|
||||
bigcall runModules
|
||||
bigcall runApps
|
||||
|
||||
; run loop as long as some run function returns with CFLAG set
|
||||
main_runLoop:
|
||||
clr r16
|
||||
push r16
|
||||
bigcall runModules
|
||||
pop r16
|
||||
sbci r16, 0
|
||||
|
||||
push r16
|
||||
bigcall runApps
|
||||
pop r16
|
||||
sbci r16, 0
|
||||
|
||||
bigcall onEveryLoop ; call into main app
|
||||
push r16
|
||||
bigcall onEveryLoop ; call into main app
|
||||
pop r16
|
||||
|
||||
tst r16
|
||||
brne main_runLoop
|
||||
|
||||
#ifdef MODULES_NETWORK
|
||||
#ifndef MAIN_WITHOUT_MSG_HANDLING
|
||||
|
||||
@@ -175,56 +175,46 @@ initModules:
|
||||
; USED: depending on called routines
|
||||
|
||||
runModules:
|
||||
bigcall BaseTimer_Run
|
||||
clr r16
|
||||
|
||||
push r16
|
||||
bigcall BaseTimer_Run
|
||||
pop r16
|
||||
|
||||
#ifdef MODULES_COM
|
||||
; COM module (call until carry flag cleared but at most 10 times to not starve other modules)
|
||||
ldi r16, 10
|
||||
runModules_Com:
|
||||
push r16
|
||||
bigcall Com2_Run
|
||||
pop r16
|
||||
brcc runModules_ComEnd
|
||||
dec r16
|
||||
brne runModules_Com
|
||||
runModules_ComEnd:
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TTYONUART1
|
||||
bigcall TtyOnUart1_Run
|
||||
push r16
|
||||
bigcall TtyOnUart1_Run
|
||||
pop r16
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_COMONUART0
|
||||
bigcall ComOnUart0_Run
|
||||
push r16
|
||||
bigcall ComOnUart0_Run
|
||||
pop r16
|
||||
sbci r16, 0
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_COMONUART1
|
||||
bigcall ComOnUart1_Run
|
||||
push r16
|
||||
bigcall ComOnUart1_Run
|
||||
pop r16
|
||||
sbci r16, 0
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_STATS
|
||||
bigcall Stats_Run
|
||||
push r16
|
||||
bigcall Stats_Run
|
||||
pop r16
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_REED
|
||||
bigcall REED_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_CNY70
|
||||
bigcall CNY70_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION_LIGHT
|
||||
; rcall MotionLight_Run
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MODULES_TCRT1000
|
||||
; rcall TCRT1K_Run
|
||||
#endif
|
||||
|
||||
|
||||
; add more modules here
|
||||
|
||||
; check for repeat request
|
||||
tst r16
|
||||
clc
|
||||
breq runModules_end
|
||||
sec
|
||||
runModules_end:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -147,20 +147,32 @@ comOnUart0StartReading:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ComOnUart0_Run @global
|
||||
;
|
||||
; @return CFLAG set if something done, cleared otherwise
|
||||
; @clobbers all
|
||||
|
||||
ComOnUart0_Run:
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
ldd r16, Y+UART_HW2_IFACE_OFFS_MODE
|
||||
clr r18
|
||||
ComOnUart0_Run_loop:
|
||||
push r16 ; current state
|
||||
rcall comOnUart0RunMode ; (all but Y)
|
||||
pop r17 ; previous state (pop from r16 into r17)
|
||||
push r18
|
||||
push r16 ; current state
|
||||
rcall comOnUart0RunMode ; (all but Y)
|
||||
pop r17 ; previous state (pop from r16 into r17)
|
||||
pop r18
|
||||
; read new state
|
||||
ldd r16, Y+UART_HW2_IFACE_OFFS_MODE
|
||||
cp r16, r17
|
||||
brne ComOnUart0_Run_loop ; state changed, run again
|
||||
breq ComOnUart0_Run_loopEnd
|
||||
ldi r18, 1
|
||||
rjmp ComOnUart0_Run_loop ; state changed, run again
|
||||
ComOnUart0_Run_loopEnd:
|
||||
tst r18
|
||||
clc
|
||||
breq ComOnUart0_Run_end
|
||||
sec
|
||||
ComOnUart0_Run_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
@@ -147,20 +147,32 @@ comOnUart1StartReading:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ComOnUart1_Run @global
|
||||
;
|
||||
; @return CFLAG set if something done, cleared otherwise
|
||||
; @clobbers all
|
||||
|
||||
ComOnUart1_Run:
|
||||
ldi yl, LOW(comOnUart1_iface)
|
||||
ldi yh, HIGH(comOnUart1_iface)
|
||||
ldd r16, Y+UART_HW2_IFACE_OFFS_MODE
|
||||
clr r18
|
||||
ComOnUart1_Run_loop:
|
||||
push r16 ; current state
|
||||
rcall comOnUart1RunMode ; (all but Y)
|
||||
pop r17 ; previous state (pop from r16 into r17)
|
||||
push r18
|
||||
push r16 ; current state
|
||||
rcall comOnUart1RunMode ; (all but Y)
|
||||
pop r17 ; previous state (pop from r16 into r17)
|
||||
pop r18
|
||||
; read new state
|
||||
ldd r16, Y+UART_HW2_IFACE_OFFS_MODE
|
||||
cp r16, r17
|
||||
brne ComOnUart1_Run_loop ; state changed, run again
|
||||
breq ComOnUart1_Run_loopEnd
|
||||
ldi r18, 1
|
||||
rjmp ComOnUart1_Run_loop ; state changed, run again
|
||||
ComOnUart1_Run_loopEnd:
|
||||
tst r18
|
||||
clc
|
||||
breq ComOnUart1_Run_end
|
||||
sec
|
||||
ComOnUart1_Run_end:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user