avr: echoing messages via tty now basically works.

This commit is contained in:
Martin Preuss
2025-02-13 23:52:55 +01:00
parent a7990db831
commit 6e25647c0a
6 changed files with 163 additions and 18 deletions

View File

@@ -24,9 +24,9 @@
;.equ clock=1000000 ; Define the clock frequency
.equ clock=8000000 ; Define the clock frequency
; .equ SEND_DEVICE_EVERY = 3000
.equ SEND_DEVICE_EVERY = 100 ; every 10s
;.equ SEND_DEVICE_EVERY = 3000
.equ SEND_DEVICE_EVERY = 350 ; every 30s
.equ SEND_STATS_EVERY = 600 ; every minute
.nolist
.include "include/tn841def.inc" ; Define device ATtiny841
@@ -204,6 +204,8 @@ onSystemTimerTick:
rcall LedSimple_Every100ms
#endif
rcall maybeSendDeviceMsg
rcall maybeSendTStatsMsg
rcall maybeSendRStatsMsg
rcall TtyOnUart1_Periodically
ret
@@ -242,6 +244,17 @@ initModules:
sts deviceCounter, r16
ldi r16, HIGH(SEND_DEVICE_EVERY)
sts deviceCounter+1, r16
ldi r16, LOW(SEND_STATS_EVERY)
sts sendTStatsCounter, r16
ldi r16, HIGH(SEND_STATS_EVERY)
sts sendTStatsCounter+1, r16
ldi r16, LOW(SEND_STATS_EVERY)
sts sendRStatsCounter, r16
ldi r16, HIGH(SEND_STATS_EVERY)
sts sendRStatsCounter+1, r16
ret
; @end
@@ -270,6 +283,8 @@ initModules:
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/common.asm"
.include "modules/network/msg/device-w.asm"
.include "modules/network/msg/sendstats-w.asm"
.include "modules/network/msg/recvstats-w.asm"
.include "modules/uart_hw/defs.asm"
.include "modules/uart_hw/lowlevel.asm"
@@ -292,7 +307,7 @@ maybeSendDeviceMsg:
brne maybeSendDeviceMsg_storeCounter
; send device msg
rcall NET_Buffer_Alloc ; (R16, R17, X)
brcc maybeSendDeviceMsg_resetCounter
brcc maybeSendDeviceMsg_end
push r16
adiw xh:xl, 1
rcall NETMSG_Device_Write ; (R16, R17, R18, R19, R20, R21, Z)
@@ -316,12 +331,94 @@ maybeSendDeviceMsg_end:
maybeSendTStatsMsg:
ldi yl, LOW(ttyOnUart1_iface)
ldi yh, HIGH(ttyOnUart1_iface)
lds r24, sendTStatsCounter
lds r25, sendTStatsCounter+1
sbiw r25:r24, 1
brne maybeSendTStatsMsg_storeCounter
; send device msg
rcall NET_Buffer_Alloc ; (R16, R17, X)
; brcc maybeSendTStatsMsg_resetCounter
brcc maybeSendTStatsMsg_end
push r16
adiw xh:xl, 1
rcall NETMSG_SendStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
sbiw xh:xl, 1
pop r16
push r16
rcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
pop r16
brcs maybeSendTStatsMsg_resetCounter
rcall NET_Buffer_ReleaseByNum ; (R16, X)
rjmp maybeSendTStatsMsg_end
; reset counter
maybeSendTStatsMsg_resetCounter:
ldi r24, LOW(SEND_STATS_EVERY)
ldi r25, HIGH(SEND_STATS_EVERY)
maybeSendTStatsMsg_storeCounter:
sts sendTStatsCounter, r24
sts sendTStatsCounter+1, r25
maybeSendTStatsMsg_end:
ret
maybeSendRStatsMsg:
ldi yl, LOW(ttyOnUart1_iface)
ldi yh, HIGH(ttyOnUart1_iface)
lds r24, sendRStatsCounter
lds r25, sendRStatsCounter+1
sbiw r25:r24, 1
brne maybeSendRStatsMsg_storeCounter
; send device msg
rcall NET_Buffer_Alloc ; (R16, R17, X)
; brcc maybeSendTStatsMsg_resetCounter
brcc maybeSendRStatsMsg_end
push r16
adiw xh:xl, 1
rcall NETMSG_RecvStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
sbiw xh:xl, 1
pop r16
push r16
rcall NET_Interface_AddOutgoingMsgNum ; (R17, R18, X)
pop r16
brcs maybeSendRStatsMsg_resetCounter
rcall NET_Buffer_ReleaseByNum ; (R16, X)
rjmp maybeSendRStatsMsg_end
; reset counter
maybeSendRStatsMsg_resetCounter:
ldi r24, LOW(SEND_STATS_EVERY)
ldi r25, HIGH(SEND_STATS_EVERY)
maybeSendRStatsMsg_storeCounter:
sts sendRStatsCounter, r24
sts sendRStatsCounter+1, r25
maybeSendRStatsMsg_end:
ret
checkRecvdMsg:
ldi yl, LOW(ttyOnUart1_iface)
ldi yh, HIGH(ttyOnUart1_iface)
rcall NET_PeekNextIncomingMsgNum ; check read queue
brcc checkRecvdMsg_end ; no msg, jmp
rcall NET_Buffer_Locate ; (R17)
adiw xh:xl, 1
push r16
rcall NETMSG_CheckMessageInBuffer ; (R16, R17, R18, R19, R20, X)
pop r16
brcs checkRecvdMsg_sendMsg
rcall NET_GetNextIncomingMsgNum ; take off the queue
rcall NET_Buffer_ReleaseByNum ; delete
ldi r16, NET_IFACE_OFFS_ERR_CONTENT_LOW
rcall NET_Interface_IncCounter16 ; (R24, R25)
rjmp checkRecvdMsg_end
checkRecvdMsg_sendMsg:
rcall NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
brcc checkRecvdMsg_end ; could not add, jmp
rcall NET_GetNextIncomingMsgNum ; take off the queue
@@ -402,9 +499,10 @@ waitFor10ms_loop:
.dseg
programRamBegin:
; nothing for now
flashUid: .byte 4
deviceCounter: .byte 2
flashUid: .byte 4
deviceCounter: .byte 2
sendTStatsCounter: .byte 2
sendRStatsCounter: .byte 2
programRamEnd: