diff --git a/avr/modules/network/msg/0BUILD b/avr/modules/network/msg/0BUILD index 926fe04..ac00b60 100644 --- a/avr/modules/network/msg/0BUILD +++ b/avr/modules/network/msg/0BUILD @@ -6,11 +6,17 @@ common.asm crc.asm defs.asm + addr-d.asm + addr-r.asm + addr-w.asm debug-w.asm device-w.asm memstats-w.asm recvstats-w.asm sendstats-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 new file mode 100644 index 0000000..bbdc920 --- /dev/null +++ b/avr/modules/network/msg/addr-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. * +; *************************************************************************** + + +#define NETMSG_ADDRESS_OFFS_UID = 4 +#define NETMSG_ADDRESS_OFFS_ADDRESS = 8 + + diff --git a/avr/modules/network/msg/addr-r.asm b/avr/modules/network/msg/addr-r.asm new file mode 100644 index 0000000..c0f8c29 --- /dev/null +++ b/avr/modules/network/msg/addr-r.asm @@ -0,0 +1,36 @@ +; *************************************************************************** +; 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_ValueRead @global +; Read a VALUE message. +; +; @param X buffer to read from +; @return R18 command +; @return R19 address to send +; @clobbers R18, R19 + +NETMSG_Address_Read: + adiw xh:xl, 2 + ld r18, X+ ; command + adiw xh:xl, 5 ; skip src addr and uid + ld r19, X+ ; addr + sbiw xh:xl, 9 ; back to msg begin + ret +; @end + + + diff --git a/avr/modules/network/msg/addr-w.asm b/avr/modules/network/msg/addr-w.asm new file mode 100644 index 0000000..2092e57 --- /dev/null +++ b/avr/modules/network/msg/addr-w.asm @@ -0,0 +1,39 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +; --------------------------------------------------------------------------- +; @routine NETMSG_Address_Write +; +; @param Y pointer to device to write msg for +; @param X pointer to buffer to write to +; @param R18 command +; @param R19 address to send +; @clobbers R16, R18 (R17, R19, R20, R21, Z) + +NETMSG_Address_Write: + ldi r16, 0xff + st X+, r16 ; dest address + ldi r16, 7 ; msg code+src address+5 payload bytes + st X+, r16 ; msg len + st X+, r18 ; msg code + ldd r16, Y+NET_IFACE_OFFS_ADDRESS + st X+, r16 ; src address + mov r17, r19 + rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21) + st X+, r17 ; address to send + + sbiw xh:xl, 9 ; go back to beginning of message (1 byte dst addr, 1 byte length, 7 bytes payload) + rcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X) + sbiw xh:xl, 10 ; go back to beginning of message (1 byte dst addr, 1 byte length, 7 bytes payload, 1 byte crc) + ret +; @end + + + diff --git a/avr/modules/network/msg/common.asm b/avr/modules/network/msg/common.asm index 23767f3..a14bdf6 100644 --- a/avr/modules/network/msg/common.asm +++ b/avr/modules/network/msg/common.asm @@ -7,7 +7,6 @@ ; * Please see toplevel file COPYING of that project for license details. * ; *************************************************************************** - ; ; --------------------------------------------------------------------------- ; @routine NETMSG_Common_AddUidToBuffer @global @@ -71,6 +70,32 @@ netMsgCheckMessageInBuffer_error: +; --------------------------------------------------------------------------- +; @routine NETMSG_AddNextMsgIdToBuffer @global +; +; Write next message id (2 bytes) into buffer given by X, advance X. +; +; @return X points to behind written message id +; @param X pointer to packet buffer +; @param Y pointer to network interface data +; @clobbers: r16, r17, r18 + +NETMSG_AddNextMsgIdToBuffer: + ldi r18, 1 + ldd r16, Y+NET_IFACE_OFFS_LASTMSGID_LOW + ldd r17, Y+NET_IFACE_OFFS_LASTMSGID_HIGH + add r16, r18 + dec r18 + adc r17, r18 + std Y+NET_IFACE_OFFS_LASTMSGID_LOW, r16 + std Y+NET_IFACE_OFFS_LASTMSGID_HIGH, r17 + st X+, r16 + st X+, r17 + ret +; @end + + + ; --------------------------------------------------------------------------- ; @routine netMsgCalcMsgChecksum ; diff --git a/avr/modules/network/msg/value-d.asm b/avr/modules/network/msg/value-d.asm new file mode 100644 index 0000000..c3c1bfa --- /dev/null +++ b/avr/modules/network/msg/value-d.asm @@ -0,0 +1,16 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + +#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 + diff --git a/avr/modules/network/msg/value-r.asm b/avr/modules/network/msg/value-r.asm new file mode 100644 index 0000000..a186a75 --- /dev/null +++ b/avr/modules/network/msg/value-r.asm @@ -0,0 +1,46 @@ +; *************************************************************************** +; 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_ValueRead @global +; Read a VALUE message. +; +; @param X buffer to read from +; @return R17 value id +; @return R19:R18 value +; @return R21:R20 denom (e.g. 100, meaning value must be divided by 100) +; @return R22 source address +; @return R23 command +; @return R25:R24 message id + +NETMSG_ValueRead: + adiw xh:xl, 2 + ld r23, X+ ; command + ld r22, X+ ; src address + adiw xh:xl, 4 ; skip uid + ld r24, X+ ; msg id (low) + ld r25, X+ ; msg id (high) + ld r17, X+ ; value id + adiw xh:xl, 1 ; skip value type + ld r18, X+ ; value (low) + ld r19, X+ ; value (high) + ld r20, X+ ; denom (low) + ld r21, X+ ; denom (high) + sbiw xh:xl, 16 ; back to msg begin + ret +; @end + + diff --git a/avr/modules/network/msg/value-w.asm b/avr/modules/network/msg/value-w.asm new file mode 100644 index 0000000..92f92e4 --- /dev/null +++ b/avr/modules/network/msg/value-w.asm @@ -0,0 +1,128 @@ +; *************************************************************************** +; 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_ValueWriteReport @global +; Write a REPORT_VALUE packet. +; +; @return nothing +; @param R16 destination address +; @param R17 value id +; @param R19:R18 value +; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100) +; @param R22 value type +; @param X buffer to write to +; @param Y pointer to network interface +; @clobbers R23, R24, R25 (R16, R17, R18, R19, R20, R21) + +NETMSG_ValueWriteReport: + ldi r23, CPRO_CMD_VALUE_REPORT + rcall NET_Interface_GetNextMsgId ; (get msg id to r25:r24) + rjmp netMsgValueWrite ; (R16, R17, R18, R19, R20, R21) +; @end + + + +; --------------------------------------------------------------------------- +; @routine NETMSG_ValueWriteSet @global +; Write a REPORT_VALUE packet. +; +; @return nothing +; @param R16 destination address +; @param R17 value id +; @param R19:R18 value +; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100) +; @param R22 value type +; @param X buffer to write to +; @param Y pointer to network interface +; @clobbers R23, R24, R25 (R16, R17, R18, R19, R20, R21) + +NETMSG_ValueWriteSet: + ldi r23, CPRO_CMD_VALUE_SET + rcall NET_Interface_GetNextMsgId ; (get msg id to r25:r24) + rjmp netMsgValueWrite ; (R16, R17, R18, R19, R20, R21) +; @end + + + +; --------------------------------------------------------------------------- +; @routine NETMSG_ValueWriteResponse @global +; Write a REPORT_VALUE packet. +; +; @return nothing +; @param R16 destination address +; @param R17 value id +; @param R19:R18 value +; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100) +; @param R22 value type +; @param R23 msg code +; @param R25:R24 reference message id +; @param X buffer to write to +; @param Y pointer to network interface +; @clobbers (R16, R17, R18, R19, R20, R21) + +NETMSG_ValueWriteResponse: + rjmp netMsgValueWrite ; (R16, R17, R18, R19, R20, R21) +; @end + + + +; --------------------------------------------------------------------------- +; @routine netMsgValueWrite @global +; Write a packet (except the checksum byte). +; +; @return nothing +; @param R16 destination address +; @param R17 value id +; @param R19:R18 value +; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100) +; @param R22 value type +; @param R23 msg code +; @param R25:R24 message id +; @param X buffer to write to +; @param Y pointer to network interface +; @clobbers R16 (R17, R18, R19, R20, R21) + +netMsgValueWrite: + st X+, r16 ; dest address + ldi r16, 14 ; msg code+src address+12 payload bytes + st X+, r16 ; msg len + st X+, r23 ; msg code + ldd r16, Y+NET_IFACE_OFFS_ADDRESS + st X+, r16 ; src address + adiw xh:xl, 4 ; skip uid (4 bytes), msg/ref id (2 bytes) + st X+, r24 ; msg id (low) + st X+, r25 ; msg id (high) + st X+, r17 ; value id + st X+, r22 ; value type + st X+, r18 ; value (low) + st X+, r19 ; value (high) + st X+, r20 ; denom (low) + st X+, r21 ; denom (high) + + sbiw xh:xl, 12 ; go back to UID (12=16 back, 4 forward) + rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21) + clr r16 + st X+, r16 ; msg id (low) + st X+, r16 ; msg id (high) + sbiw xh:xl, 10 ; go back to beginning of message + ; finish msg + rcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X) + sbiw xh:xl, 17 ; go back to beginning of message + ret +; @end + +