avr: t03 can now send and receive messages!
will change other nodes from com2 interface to new network interface.
This commit is contained in:
@@ -97,7 +97,7 @@ NET_Buffer_ReleaseByNum_end:
|
||||
; @return CFLAG set if okay, cleared on error
|
||||
; @return X points to start of buffer with the given num
|
||||
; @param r16 buffer num (0-max)
|
||||
; @clobbers r16
|
||||
; @clobbers r17
|
||||
|
||||
NET_Buffer_Locate:
|
||||
cpi r16, NET_BUFFERS_NUM
|
||||
@@ -110,10 +110,10 @@ NET_Buffer_Locate:
|
||||
ror xl
|
||||
lsr xh ; *32
|
||||
ror xl
|
||||
ldi r16, LOW(netBuffers)
|
||||
add xl, r16
|
||||
ldi r17, LOW(netBuffers)
|
||||
add xl, r17
|
||||
ldi r16, HIGH(netBuffers)
|
||||
adc xh, r16
|
||||
adc xh, r17
|
||||
sec
|
||||
NET_Buffer_Locate_end:
|
||||
ret
|
||||
|
||||
@@ -80,3 +80,24 @@ NET_GetNextIncomingMsgNum:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine NET_GetPeekIncomingMsgNum @global
|
||||
;
|
||||
; @return CFLAG on success, cleared on error
|
||||
; @return R16 buffer number of the next incoming message
|
||||
; @param Y pointer to start of interface data
|
||||
; @clobbers R17, R18, X
|
||||
|
||||
NET_PeekNextIncomingMsgNum:
|
||||
push yl
|
||||
push yh
|
||||
ldi yl, LOW(netRingBufferMsgNumIn)
|
||||
ldi yh, HIGH(netRingBufferMsgNumIn)
|
||||
rcall RingBufferY_PeekByteGuarded ; R17, R18, X
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
11
avr/modules/network/msg/0BUILD
Normal file
11
avr/modules/network/msg/0BUILD
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<extradist>
|
||||
device-w.asm
|
||||
</extradist>
|
||||
|
||||
</gwbuild>
|
||||
|
||||
|
||||
126
avr/modules/network/msg/common.asm
Normal file
126
avr/modules/network/msg/common.asm
Normal file
@@ -0,0 +1,126 @@
|
||||
; ***************************************************************************
|
||||
; 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_Common_AddUidToBuffer @global
|
||||
;
|
||||
; @return X points directly behind the UID in buffer
|
||||
; @param X current buffer position to write UID to
|
||||
; @clobbers R16, R18, R19, R20, R21
|
||||
|
||||
NETMSG_Common_AddUidToBuffer:
|
||||
push xh
|
||||
push xl
|
||||
rcall Utils_ReadUid ; (R16, X)
|
||||
pop xl
|
||||
pop xh
|
||||
st X+, r18
|
||||
st X+, r19
|
||||
st X+, r20
|
||||
st X+, r21
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine NETMSG_CalcAndAddChecksumByte @global
|
||||
;
|
||||
; @return CFLAG set if okay, clear otherwise
|
||||
; @return X points behind checksum byte pos upon return
|
||||
; @param X pointer to packet buffer (points behind checksum upon return)
|
||||
; @clobbers R16, R17, R18, R19, R20, X
|
||||
|
||||
NETMSG_CalcAndAddChecksumByte:
|
||||
rcall netMsgCalcMsgChecksum ; (R16, R17, R18, R19, R20, X)
|
||||
st X+, r16 ; add checksum byte
|
||||
sec
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine netMsgCheckMessageInBuffer
|
||||
;
|
||||
; check message in buffer
|
||||
;
|
||||
; @return CFLAG set if okay, clear otherwise
|
||||
; @param X pointer to packet buffer
|
||||
; @clobbers R16, R17 (R18, R19, R20, X)
|
||||
|
||||
netMsgCheckMessageInBuffer:
|
||||
rcall netMsgCalcMsgChecksum ; (R16, R17, R18, R19, R20, X)
|
||||
ld r17, X
|
||||
cp r16, r17 ; should be equal
|
||||
brne netMsgCheckMessageInBuffer_error
|
||||
sec
|
||||
ret
|
||||
netMsgCheckMessageInBuffer_error:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine netMsgCalcMsgChecksum
|
||||
;
|
||||
; calc checksum from msg buffer (except crc byte)
|
||||
;
|
||||
; @return r16 crc8 checksum
|
||||
; @return X points to position of checksum byte
|
||||
; @param X pointer to packet buffer (points to checksum byte upon return)
|
||||
; @clobbers R18 (R16, R17, R19, R20, X)
|
||||
|
||||
netMsgCalcMsgChecksum:
|
||||
adiw xh:xl, NETMSG_OFFS_MSGLEN
|
||||
ld r18, X ; read msg len
|
||||
sbiw xh:xl, NETMSG_OFFS_MSGLEN
|
||||
inc r18 ; account for dest address
|
||||
inc r18 ; account for msg len byte
|
||||
rjmp netMsgCrcCalc ; (R16, R17, R18, R19, R20, X)
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine netMsgCrcCalc @global
|
||||
; calc checksum using given polynomial
|
||||
;
|
||||
; @return r16 calculated checksum
|
||||
; @return X points directly after last checked byte
|
||||
; @param X pointer to data to calc crc8 for
|
||||
; @param r18 number of bytes to calc crc8 for
|
||||
; @clobbers R16, R17, R18, R19, R20, X
|
||||
|
||||
netMsgCrcCalc:
|
||||
ldi r16, 0xff ; start crc
|
||||
ldi r19, NETMSG_CRC8_POLYNOMIAL
|
||||
|
||||
netMsgCrcCalc_loop1:
|
||||
ld r17, X+ ; running var
|
||||
eor r16, r17
|
||||
ldi r20, 8 ; counter for loop2
|
||||
netMsgCrcCalc_loop2:
|
||||
lsl r16
|
||||
brcc netMsgCrcCalc_l1
|
||||
eor r16, r19
|
||||
netMsgCrcCalc_l1:
|
||||
dec r20
|
||||
brne netMsgCrcCalc_loop2
|
||||
dec r18
|
||||
brne netMsgCrcCalc_loop1
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
68
avr/modules/network/msg/defs.asm
Normal file
68
avr/modules/network/msg/defs.asm
Normal file
@@ -0,0 +1,68 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; command values
|
||||
|
||||
.equ NETMSG_CMD_PING = 10
|
||||
.equ NETMSG_CMD_PONG = 11
|
||||
.equ NETMSG_CMD_SENDSTATS = 20
|
||||
.equ NETMSG_CMD_RECVSTATS = 21
|
||||
.equ NETMSG_CMD_TWIBUSMEMBER = 30
|
||||
.equ NETMSG_CMD_DEBUG = 40
|
||||
|
||||
.equ NETMSG_CMD_RESULT = 50
|
||||
|
||||
.equ NETMSG_CMD_NEED_ADDRESS = 60
|
||||
.equ NETMSG_CMD_HAVE_ADDRESS = 61
|
||||
.equ NETMSG_CMD_CLAIM_ADDRESS = 62
|
||||
.equ NETMSG_CMD_DENY_ADDRESS = 63
|
||||
.equ NETMSG_CMD_ADDRESS_RANGE = 64
|
||||
|
||||
.equ NETMSG_CMD_FLASH_START = 70
|
||||
.equ NETMSG_CMD_FLASH_END = 71
|
||||
.equ NETMSG_CMD_FLASH_READY = 72
|
||||
.equ NETMSG_CMD_FLASH_DATA = 73
|
||||
.equ NETMSG_CMD_FLASH_RSP = 74
|
||||
|
||||
.equ NETMSG_CMD_DEVICE = 80
|
||||
.equ NETMSG_CMD_MEMSTATS = 81
|
||||
.equ NETMSG_CMD_SYSSTATS = 82
|
||||
|
||||
.equ NETMSG_CMD_REBOOT_REQUEST = 90
|
||||
.equ NETMSG_CMD_REBOOT_RESPONSE = 91
|
||||
|
||||
.equ NETMSG_CMD_VALUE_REPORT = 100
|
||||
.equ NETMSG_CMD_VALUE_SET = 101
|
||||
.equ NETMSG_CMD_VALUE_SET_ACK = 102
|
||||
.equ NETMSG_CMD_VALUE_SET_NACK = 103
|
||||
|
||||
.equ NETMSG_CMD_DATA = 110
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; position definitions for all messages
|
||||
|
||||
.equ NETMSG_OFFS_DESTADDR = 0
|
||||
.equ NETMSG_OFFS_MSGLEN = 1
|
||||
.equ NETMSG_OFFS_MSGDATA = 2
|
||||
.equ NETMSG_OFFS_CMD = 2 ; first at NETMSG_OFFS_MSGDATA
|
||||
.equ NETMSG_OFFS_SRCADDR = 3
|
||||
.equ NETMSG_OFFS_PAYLOAD = 4 ; payload for the cmd follows here
|
||||
|
||||
.equ NETMSG_CRC8_POLYNOMIAL = 0x97 ; HD=4 up to 119 bytes, e.g. detects all 1 to 3 bit errors
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
39
avr/modules/network/msg/device-w.asm
Normal file
39
avr/modules/network/msg/device-w.asm
Normal file
@@ -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_Device_Write
|
||||
;
|
||||
; @param Y pointer to device to write msg for
|
||||
; @clobbers R16, R18 (R17, R19, R20, R21, Z)
|
||||
|
||||
NETMSG_Device_Write:
|
||||
ldi r16, 0xff
|
||||
st X+, r16 ; dest address
|
||||
ldi r16, 18 ; msg code+src address+12 payload bytes
|
||||
st X+, r16 ; msg len
|
||||
ldi r16, NETMSG_CMD_DEVICE
|
||||
st X+, r16 ; msg code
|
||||
ldd r16, Y+NET_IFACE_OFFS_ADDRESS
|
||||
st X+, r16 ; src address
|
||||
rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
|
||||
ldi zh, HIGH(devInfoBlock*2) ; 6-17: devInfoBlock
|
||||
ldi zl, LOW(devInfoBlock*2)
|
||||
ldi r18, 12
|
||||
rcall Utils_CopyFromFlash ; (R17, R18, X, Z)
|
||||
sbiw xh:xl, 20 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload)
|
||||
rcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X)
|
||||
sbiw xh:xl, 21 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload, 1 byte crc)
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
40
avr/modules/network/msg/sendstats-w.asm
Normal file
40
avr/modules/network/msg/sendstats-w.asm
Normal file
@@ -0,0 +1,40 @@
|
||||
; ***************************************************************************
|
||||
; 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_SendStats_Write @global
|
||||
;
|
||||
; @param Y pointer to device to write msg for and to
|
||||
; @clobbers R16, R18 (R17, R19, R20, R21, Z)
|
||||
|
||||
NETMSG_SendStats_Write:
|
||||
ldi r16, 0xff
|
||||
st X+, r16 ; dest address
|
||||
ldi r16, 12 ; msg code+src address+10 payload bytes
|
||||
st X+, r16 ; msg len
|
||||
ldi r16, NETMSG_CMD_SENDSTATS
|
||||
st X+, r16 ; msg code
|
||||
ldd r16, Y+NET_IFACE_OFFS_ADDRESS
|
||||
st X+, r16 ; src address
|
||||
rcall NETMSG_Common_AddUidToBuffer ; (R16, R18, R19, R20, R21)
|
||||
adiw yh:yl, NET_IFACE_OFFS_PACKETSOUT_LOW
|
||||
ldi r18, 6
|
||||
rcall Utils_Copy_SDRAM
|
||||
sbiw yh:yl, NET_IFACE_OFFS_PACKETSOUT_LOW+6
|
||||
|
||||
sbiw xh:xl, 13 ; go back to beginning of message (1 byte dst addr, 1 byte length, 12 bytes payload)
|
||||
rcall NETMSG_CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X)
|
||||
sbiw xh:xl, 14 ; go back to beginning of message (1 byte dst addr, 1 byte length, 12 bytes payload, 1 byte crc)
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user