; *************************************************************************** ; 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. * ; *************************************************************************** .dseg uartHwDataBegin: ; fixed buffers for incoming and outgoing messages uartHw_buffers: .byte UART_HW_FIXEDBUFFERS_NUM*UART_HW_FIXEDBUFFERS_SIZE uartHwDataEnd: .cseg ; --------------------------------------------------------------------------- ; @routine UART_HW_FixedBuffers_Init @global ; ; @clobbers R16, R17, X UART_HW_FixedBuffers_Init: ldi xl, LOW(uartHw_buffers) ldi xh, HIGH(uartHw_buffers) m_fixedbuf_init UART_HW_FIXEDBUFFERS_SIZE, UART_HW_FIXEDBUFFERS_NUM ret ; @end ; --------------------------------------------------------------------------- ; @routine UART_HW_FixedBuffers_Alloc @global ; ; @return CFLAG set if buffer available, cleared otherwise ; @return r16 buffer num ; @return X pointer to start of buffer ; @clobbers R16, R17, X UART_HW_FixedBuffers_Alloc: ldi xl, LOW(uartHw_buffers) ldi xh, HIGH(uartHw_buffers) m_fixedbuf_reserve UART_HW_FIXEDBUFFERS_SIZE, UART_HW_FIXEDBUFFERS_NUM ret ; @end ; --------------------------------------------------------------------------- ; @routine UART_HW_FixedBuffers_Release @global ; ; @param X pointer to start of buffers ; @clobbers R16 UART_HW_FixedBuffers_Release: m_fixedbuf_release ret ; @end ; --------------------------------------------------------------------------- ; @routine UART_HW_FixedBuffers_Locate ; ; Get position of a given buffer. ; ; CAVE: need to change this routine if UART_HW_FIXEDBUFFERS_SIZE is changed! ; ; @return CFLAG set if okay, cleared on error ; @return X points to start of buffer with the given num ; @param r16 buffer num (0-max) ; @clobbers r16 UART_HW_FixedBuffers_Locate: cpi r16, UART_HW_FIXEDBUFFERS_NUM brcc UART_HW_FixedBuffers_Locate_end ; out of range mov xh, r16 ; * 256 clr xl lsr xh ; *128 ror xl lsr xh ; *64 ror xl lsr xh ; *32 ror xl ldi r16, LOW(uartHw_buffers) add xl, r16 ldi r16, HIGH(uartHw_buffers) adc xh, r16 sec UART_HW_FixedBuffers_Locate_end: ret ; @end