avr: t03 can now send and receive messages!
will change other nodes from com2 interface to new network interface.
This commit is contained in:
@@ -170,7 +170,9 @@ main_loop:
|
||||
|
||||
rcall BaseTimer_Run
|
||||
rcall TtyOnUart1_Run
|
||||
|
||||
|
||||
; check incoming msg
|
||||
rcall checkRecvdMsg
|
||||
rjmp main_loop
|
||||
|
||||
|
||||
@@ -258,18 +260,16 @@ initModules:
|
||||
.include "common/m_ringbuffer_y.asm"
|
||||
.include "common/ringbuffer_y.asm"
|
||||
.include "common/m_fixedbuffers.asm"
|
||||
;.include "common/crc8.asm"
|
||||
.include "modules/flash/wait.asm"
|
||||
.include "modules/basetimer/main.asm"
|
||||
.include "modules/led_simple/main.asm"
|
||||
.include "modules/com2/defs.asm"
|
||||
.include "modules/com2/crc.asm"
|
||||
.include "modules/comproto/defs.asm"
|
||||
.include "modules/network/defs.asm"
|
||||
.include "modules/network/buffer.asm"
|
||||
.include "modules/network/data.asm"
|
||||
.include "modules/network/main.asm"
|
||||
.include "modules/network/iface.asm"
|
||||
.include "modules/network/msg/defs.asm"
|
||||
.include "modules/network/msg/common.asm"
|
||||
.include "modules/network/msg/device-w.asm"
|
||||
|
||||
.include "modules/uart_hw/defs.asm"
|
||||
.include "modules/uart_hw/lowlevel.asm"
|
||||
@@ -291,18 +291,18 @@ maybeSendDeviceMsg:
|
||||
sbiw r25:r24, 1
|
||||
brne maybeSendDeviceMsg_storeCounter
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc maybeSendDeviceMsg_resetCounter
|
||||
push r16
|
||||
adiw xh:xl, 1
|
||||
rcall writeDeviceMsg
|
||||
rcall NETMSG_Device_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
push r16
|
||||
rcall TtyOnUart1_SendBuffer
|
||||
rcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
|
||||
pop r16
|
||||
brcs maybeSendDeviceMsg_resetCounter
|
||||
rcall NET_Buffer_ReleaseByNum ; (R16, X)
|
||||
rcall NET_Buffer_ReleaseByNum ; (R16, X)
|
||||
rjmp maybeSendDeviceMsg_end
|
||||
; reset counter
|
||||
maybeSendDeviceMsg_resetCounter:
|
||||
@@ -316,36 +316,16 @@ maybeSendDeviceMsg_end:
|
||||
|
||||
|
||||
|
||||
writeDeviceMsg:
|
||||
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, CPRO_CMD_DEVICE
|
||||
st X+, r16 ; msg code
|
||||
clr r16
|
||||
st X+, r16 ; src address
|
||||
rcall 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, Y)
|
||||
sbiw xh:xl, 20 ; go back to beginning of message (1 byte dst addr, 1 byte length, 18 bytes payload)
|
||||
rcall com2CalcAndAddChecksumByte ; (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
|
||||
checkRecvdMsg:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
|
||||
|
||||
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
|
||||
rcall NET_PeekNextIncomingMsgNum ; check read queue
|
||||
brcc checkRecvdMsg_end ; no msg, jmp
|
||||
rcall NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
brcc checkRecvdMsg_end ; could not add, jmp
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
checkRecvdMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user