avr/modules/network: added messages.

This commit is contained in:
Martin Preuss
2025-04-29 00:36:20 +02:00
parent 1e90682605
commit c1a67a36ef
7 changed files with 143 additions and 7 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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