diff --git a/avr/modules/network/msg/0BUILD b/avr/modules/network/msg/0BUILD index ac00b60..a40d0c1 100644 --- a/avr/modules/network/msg/0BUILD +++ b/avr/modules/network/msg/0BUILD @@ -12,8 +12,11 @@ debug-w.asm device-w.asm memstats-w.asm + reboot-d.asm + reboot-r.asm recvstats-w.asm sendstats-w.asm + simplemsg-w.asm value-d.asm value-r.asm value-w.asm diff --git a/avr/modules/network/msg/addr-d.asm b/avr/modules/network/msg/addr-d.asm index bbdc920..3e5cbdc 100644 --- a/avr/modules/network/msg/addr-d.asm +++ b/avr/modules/network/msg/addr-d.asm @@ -8,7 +8,7 @@ ; *************************************************************************** -#define NETMSG_ADDRESS_OFFS_UID = 4 -#define NETMSG_ADDRESS_OFFS_ADDRESS = 8 +.equ NETMSG_ADDRESS_OFFS_UID = 4 +.equ NETMSG_ADDRESS_OFFS_ADDRESS = 8 diff --git a/avr/modules/network/msg/common.asm b/avr/modules/network/msg/common.asm index 7b39be6..c240472 100644 --- a/avr/modules/network/msg/common.asm +++ b/avr/modules/network/msg/common.asm @@ -56,3 +56,39 @@ NETMSG_AddNextMsgIdToBuffer: +; --------------------------------------------------------------------------- +; @routine NETMSG_CheckUidInMsg +; +; Compare the UID from a message against our own UID. +; +; @param X pointer to UID in a message to compare against out own uid +; @return CFLAG set if matches, cleared otherwise +; @clobbers r16, r18, r19, r20, r21, X + +NETMSG_CheckUidInMsg: + push xl + push xh + rcall Utils_ReadUid + pop xh + pop xl + ld r16, X+ + cp r16, r18 + brne NETMSG_CheckUidInMsg_notMe + ld r16, X+ + cp r16, r19 + brne NETMSG_CheckUidInMsg_notMe + ld r16, X+ + cp r16, r20 + brne NETMSG_CheckUidInMsg_notMe + ld r16, X+ + cp r16, r21 + brne NETMSG_CheckUidInMsg_notMe + sec + ret +NETMSG_CheckUidInMsg_notMe: + clc + ret +; @end + + + diff --git a/avr/modules/network/msg/reboot-d.asm b/avr/modules/network/msg/reboot-d.asm new file mode 100644 index 0000000..b605ebd --- /dev/null +++ b/avr/modules/network/msg/reboot-d.asm @@ -0,0 +1,14 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +.equ NETMSG_REBOOTREQ_OFFS_UID = 4 + + + diff --git a/avr/modules/network/msg/reboot-r.asm b/avr/modules/network/msg/reboot-r.asm new file mode 100644 index 0000000..a99bcf9 --- /dev/null +++ b/avr/modules/network/msg/reboot-r.asm @@ -0,0 +1,41 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; code + +.cseg + + +; --------------------------------------------------------------------------- +; @routine NETMSG_RebootRequestRead @global +; Read a VALUE message. +; +; @return CFLAG set if the UID from the message matches the uid of this node +; @return R16 source address +; @param X buffer to read from +; @clobbers r16, r18, r19, r20, r21 + +NETMSG_RebootRequestRead: + adiw xh:xl, NETMSG_OFFS_SRCADDR + ld r16, X + sbiw xh:xl, NETMSG_OFFS_SRCADDR + push r16 + push xl + push xh + adiw xh:xl, NETMSG_REBOOTREQ_OFFS_UID + rcall NETMSG_CheckUidInMsg ; (r16, r18, r19, r20, r21, X) + pop xh + pop xl + pop r16 + ret +; @end + + diff --git a/avr/modules/network/msg/simplemsg-w.asm b/avr/modules/network/msg/simplemsg-w.asm new file mode 100644 index 0000000..16d1738 --- /dev/null +++ b/avr/modules/network/msg/simplemsg-w.asm @@ -0,0 +1,42 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; *************************************************************************** +; code + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine NETMSG_SimpleMsgWrite +; Write a simple msg (only code and src address). +; +; @param R16 dest addr +; @param R18 msg code +; @param X buffer to write to +; @param Y pointer to network interface data +; @clobbers R18 (R16, R17, R19, R20, X) + +NETMSG_SimpleMsgWrite: + st X+, r16 ; dest address + ldi r16, 2 ; msg code+src address+0 payload bytes + st X+, r16 ; msg len + st X+, r18 ; msg code + ldd r16, Y+NET_IFACE_OFFS_ADDRESS + st X+, r16 ; src address + + sbiw xh:xl, 4 ; go back to beginning of message (1 byte dst addr, 1 byte length, 2 bytes payload) + rcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X) + sbiw xh:xl, 5 ; go back to beginning of message (1 byte dst addr, 1 byte length, 2 bytes payload, 1 byte crc) + ret +; @end + + diff --git a/avr/modules/network/msg/value-d.asm b/avr/modules/network/msg/value-d.asm index c3c1bfa..c1459f2 100644 --- a/avr/modules/network/msg/value-d.asm +++ b/avr/modules/network/msg/value-d.asm @@ -8,9 +8,9 @@ ; *************************************************************************** -#define NETMSG_VALUE_OFFS_UID = 4 -#define NETMSG_VALUE_OFFS_MSGID = 8 -#define NETMSG_VALUE_OFFS_VALUEID = 10 -#define NETMSG_VALUE_OFFS_VALUE = 12 -#define NETMSG_VALUE_OFFS_DENOM = 14 +.equ NETMSG_VALUE_OFFS_UID = 4 +.equ NETMSG_VALUE_OFFS_MSGID = 8 +.equ NETMSG_VALUE_OFFS_VALUEID = 10 +.equ NETMSG_VALUE_OFFS_VALUE = 12 +.equ NETMSG_VALUE_OFFS_DENOM = 14