avr: share code.

This commit is contained in:
Martin Preuss
2025-03-23 01:08:33 +01:00
parent 595f983071
commit ebce002614
6 changed files with 51 additions and 49 deletions

View File

@@ -110,3 +110,43 @@ UART_HW_Interface_EnsureReadBuffer_noBuf:
; ---------------------------------------------------------------------------
; @routine UART_HW_Interface_HandleMsgReceived
;
; @param Y pointer to interface data in SRAM
; @clobbers R16 (R17, R18, R24, R25)
UART_HW_Interface_HandleMsgReceived:
; unset buffer
ldi r17, 0xff
ldd r16, Y+UART_HW_IFACE_OFFS_READBUFNUM
std Y+UART_HW_IFACE_OFFS_READBUFNUM, r17
cp r16, r17
breq UART_HW_Interface_HandleMsgReceived_enterIdle ; SNH!
; check checksum
rcall NET_Buffer_Locate ; (R17)
push r16
adiw xh:xl, 1
rcall NETMSG_CheckMessageInBuffer ; (R16, R17, R18, R19, R20, X)
pop r16
brcs UART_HW_Interface_HandleMsgReceived_addMsg
; invalid msg
rcall NET_Buffer_ReleaseByNum ; (R16, X)
ldi r16, NET_IFACE_OFFS_ERR_CONTENT_LOW
rjmp UART_HW_Interface_HandleMsgReceived_incCounterGoIdle
UART_HW_Interface_HandleMsgReceived_addMsg:
rcall NET_AddIncomingMsgNum ; (R17, R18, X)
brcs UART_HW_Interface_HandleMsgReceived_enterIdle
; could not add msg
rcall NET_Buffer_ReleaseByNum ; (R16, X)
ldi r16, NET_IFACE_OFFS_ERR_MISSED_LOW
UART_HW_Interface_HandleMsgReceived_incCounterGoIdle:
rcall NET_Interface_IncCounter16 ; (R24, R25)
UART_HW_Interface_HandleMsgReceived_enterIdle:
ldi r17, UART_HW_READMODE_IDLE
std Y+UART_HW_IFACE_OFFS_READMODE, r17 ; set read mode
ret
; @end