diff --git a/avr/apps/router/main.asm b/avr/apps/router/main.asm index 76e1d0d..047a126 100644 --- a/avr/apps/router/main.asm +++ b/avr/apps/router/main.asm @@ -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<