Files
aqhomecontrol/avr/modules/uart_hw/lowlevel.asm
Martin Preuss a7990db831 avr: t03 can now send and receive messages!
will change other nodes from com2 interface to new network interface.
2025-02-13 18:56:13 +01:00

84 lines
2.4 KiB
NASM

; ***************************************************************************
; 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. *
; ***************************************************************************
.cseg
; ---------------------------------------------------------------------------
; @routine UART_HW_Interface_Init @global
;
; @param Y pointer to interface data in SRAM
; @clobbers R16 (R17, X)
UART_HW_Interface_Init:
rcall NET_Interface_Init ; (R16, R17, X)
ldi r16, 0xff
std Y+UART_HW_IFACE_OFFS_READBUFNUM, r16
std Y+UART_HW_IFACE_OFFS_WRITEBUFNUM, r16
ldi r16, UART_HW_READMODE_IDLE
std Y+UART_HW_IFACE_OFFS_READMODE, r16
ldi r16, UART_HW_WRITEMODE_IDLE
std Y+UART_HW_IFACE_OFFS_WRITEMODE, r16
ret
; @end
; ---------------------------------------------------------------------------
; @routine UART_HW_Interface_SetReadBuffer @global
;
; @param Y pointer to interface data in SRAM
; @param r16 read buffer number
; @param X pointer to read buffer
; @clobbers R17
UART_HW_Interface_SetReadBuffer:
std Y+UART_HW_IFACE_OFFS_READBUFNUM, r16
adiw xh:xl, 1
std Y+UART_HW_IFACE_OFFS_READBUFPOS_LOW, xl
std Y+UART_HW_IFACE_OFFS_READBUFPOS_HIGH, xh
sbiw xh:xl, 1
clr r17
std Y+UART_HW_IFACE_OFFS_READBUFUSED, r17
ldi r17, NET_BUFFERS_SIZE-1
std Y+UART_HW_IFACE_OFFS_READBUFLEFT, r17
ret
; @end
; ---------------------------------------------------------------------------
; @routine UART_HW_Interface_SetWriteBuffer @global
;
; @param Y pointer to interface data in SRAM
; @param r16 write buffer number
; @param X pointer to write buffer
; @clobbers r17
UART_HW_Interface_SetWriteBuffer:
std Y+UART_HW_IFACE_OFFS_WRITEBUFNUM, r16
adiw xh:xl, 1
std Y+UART_HW_IFACE_OFFS_WRITEBUFPOS_LOW, xl ; begin of msg (dest addr byte)
std Y+UART_HW_IFACE_OFFS_WRITEBUFPOS_HIGH, xh
adiw xh:xl, 1
ld r17, X ; payload length byte
sbiw xh:xl, 2 ; back to start of buffer
inc r17
inc r17
inc r17
std Y+UART_HW_IFACE_OFFS_WRITEBUFUSED, r17
std Y+UART_HW_IFACE_OFFS_WRITEBUFLEFT, r17
ret
; @end