158 lines
3.9 KiB
NASM
158 lines
3.9 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_Init @global
|
|
;
|
|
; Initializes buffers.
|
|
;
|
|
; @clobbers R16, R17, X, Y
|
|
|
|
UART_HW_Init:
|
|
ldi xh, HIGH(uartHwDataBegin)
|
|
ldi xl, LOW(uartHwDataBegin)
|
|
clr r16
|
|
ldi r17, (uartHwDataEnd-uartHwDataBegin)
|
|
rcall Utils_FillSram
|
|
|
|
rcall UART_HW_FixedBuffers_Init
|
|
|
|
ldi r16, UART_HW_MSGNUMINBUF_SIZE
|
|
ldi yl, LOW(uartHw_ringBufferMsgNumIn)
|
|
ldi yh, HIGH(uartHw_ringBufferMsgNumIn)
|
|
rcall RingBufferY_Init
|
|
|
|
ldi r16, UART_HW_MSGNUMOUTBUF_SIZE
|
|
ldi yl, LOW(uartHw_ringBufferMsgNumOut)
|
|
ldi yh, HIGH(uartHw_ringBufferMsgNumOut)
|
|
rcall RingBufferY_Init
|
|
|
|
sec
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine UART_HW_InterfaceInit @global
|
|
;
|
|
; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_STATE)
|
|
; @clobbers R16, R17, X
|
|
|
|
UART_HW_InterfaceInit:
|
|
mov xl, yl
|
|
mov xh, yh
|
|
ldi r17, UART_HW_IFACE_SIZE
|
|
clr r16
|
|
rcall Utils_FillSram ; (R17, X)
|
|
m_ringbuffer_y_reset UART_HW_IFACE_READBUF_SIZE, \
|
|
UART_HW_IFACE_OFFS_READBUF_USED, \
|
|
UART_HW_IFACE_OFFS_READBUF_RDPOS, \
|
|
UART_HW_IFACE_OFFS_READBUF_WRPOS, \
|
|
UART_HW_IFACE_OFFS_READBUF_DATA
|
|
|
|
m_ringbuffer_y_reset UART_HW_IFACE_WRITEBUF_SIZE, \
|
|
UART_HW_IFACE_OFFS_WRITEBUF_USED, \
|
|
UART_HW_IFACE_OFFS_WRITEBUF_RDPOS, \
|
|
UART_HW_IFACE_OFFS_WRITEBUF_WRPOS, \
|
|
UART_HW_IFACE_OFFS_WRITEBUF_DATA
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine UART_HW_InterfaceWriteToReadBuffer @global
|
|
;
|
|
; @return CFLAG on success, cleared on error
|
|
; @param r16 byte to write
|
|
; @param Y pointer to start of interface data
|
|
; @clobbers R17, R18, X
|
|
|
|
UART_HW_InterfaceWriteToReadBuffer:
|
|
push yl
|
|
push yh
|
|
adiw yh:yl, UART_HW_IFACE_OFFS_READBUF
|
|
rcall RingBufferY_WriteByte ; R17, R18, X
|
|
pop yh
|
|
pop yl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine UART_HW_InterfaceReadFromReadBuffer @global
|
|
;
|
|
; @return CFLAG on success, cleared on error
|
|
; @return R16 byte read
|
|
; @param Y pointer to start of interface data
|
|
; @clobbers R17, R18, X
|
|
|
|
UART_HW_InterfaceReadFromReadBuffer:
|
|
push yl
|
|
push yh
|
|
adiw yh:yl, UART_HW_IFACE_OFFS_READBUF
|
|
rcall RingBufferY_ReadByte ; R17, R18, X
|
|
pop yh
|
|
pop yl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine UART_HW_InterfaceWriteToWriteBuffer @global
|
|
;
|
|
; @return CFLAG on success, cleared on error
|
|
; @param r16 byte to write
|
|
; @param Y pointer to start of interface data
|
|
; @clobbers R17, R18, X
|
|
|
|
UART_HW_InterfaceWriteToWriteBuffer:
|
|
push yl
|
|
push yh
|
|
adiw yh:yl, UART_HW_IFACE_OFFS_WRITEBUF
|
|
rcall RingBufferY_WriteByte ; R17, R18, X
|
|
pop yh
|
|
pop yl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine UART_HW_InterfaceReadFromWriteBuffer @global
|
|
;
|
|
; @return CFLAG on success, cleared on error
|
|
; @return R16 byte read
|
|
; @param Y pointer to start of interface data
|
|
; @clobbers R17, R18, X
|
|
|
|
UART_HW_InterfaceReadFromWriteBuffer:
|
|
push yl
|
|
push yh
|
|
adiw yh:yl, UART_HW_IFACE_OFFS_WRITEBUF
|
|
rcall RingBufferY_ReadByte ; R17, R18, X
|
|
pop yh
|
|
pop yl
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
|
|
|
|
|