From 6dd9a3ba8f4c89ae87f8959dd6bbbfb4998cbe02 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 16 Jan 2025 17:06:06 +0100 Subject: [PATCH] avr: use ringbuffer macros in uart_irq. --- avr/modules/uart_irq/iface.asm | 88 ++-------------------------------- 1 file changed, 4 insertions(+), 84 deletions(-) diff --git a/avr/modules/uart_irq/iface.asm b/avr/modules/uart_irq/iface.asm index b760062..4c76661 100644 --- a/avr/modules/uart_irq/iface.asm +++ b/avr/modules/uart_irq/iface.asm @@ -75,86 +75,6 @@ _writeAttnBit1: -; --------------------------------------------------------------------------- -; @macro m_ringbuffer_writebyte -; -; @param R16 byte to write -; @param Y base address (for "LDD Y+nn" and "STD Y+nn") -; @param %0 constant maxBytes -; @param %1 offset to Y to access usedBytes variable (for "LDD Y+nn" and "STD Y+nn") -; @param %2 offset to Y to access readPos variable -; @param %3 offset to Y to access writePos variable -; @param %4 offset to Y to access buffer -; @return CFLAG set if okay, cleared on error (i.e. buffer full) -; @clobbers R17, X - -.macro m_ringbuffer_writebyte - ldd r17, Y+@1 ; usedBytes - cpi r17, @0 ; maxBytes - brcc l_end - inc r17 - std Y+@1, r17 ; usedBytes - ldd r17, Y+@3 ; writePos - mov xl, yl - mov xh, yh - adiw xh:xl, @4 - add xl, r17 - adc xh, r17 - sub xh, r17 - st X, r16 - inc r17 - cpi r17, @0 - brcs l_store - clr r17 -l_store: - std Y+@3, r17 ; writePos - sec -l_end: -.endmacro -; @end - - - -; --------------------------------------------------------------------------- -; @macro m_ringbuffer_readbyte -; -; @param Y base address (for "LDD Y+nn" and "STD Y+nn") -; @param %0 constant maxBytes -; @param %1 offset to Y to access usedBytes variable (for "LDD Y+nn" and "STD Y+nn") -; @param %2 offset to Y to access readPos variable -; @param %3 offset to Y to access writePos variable -; @param %4 offset to Y to access buffer -; @return CFLAG set if okay, cleared on error (i.e. buffer full) -; @return R16 byte read -; @clobbers R17, X - -.macro m_ringbuffer_readbyte - ldd r17, Y+@1 ; usedBytes - tst r17 - clc - breq l_end - dec r17 - std Y+@1, r17 ; usedBytes - ldd r17, Y+@2 ; readPos - mov xl, yl - mov xh, yh - adiw xh:xl, @4 - add xl, r17 - adc xh, r17 - sub xh, r17 - ld r16, X - inc r17 - cpi r17, @0 - brcs l_store - clr r17 -l_store: - std Y+@2, r17 ; readPos - sec -l_end: -.endmacro - - - .dseg uartIrqBase: .byte 4 @@ -630,7 +550,7 @@ uart_irq_handle_sendingstopbit_end: ; @clobbers R17, X uart_irq_rdbuf_writebyte: - m_ringbuffer_writebyte \ + m_ringbuffer_y_writebyte \ UART_IRQ_IFACE_READBUF_SIZE, \ UART_IRQ_IFACE_OFFS_READBUF_USED, \ UART_IRQ_IFACE_OFFS_READBUF_RDPOS, \ @@ -650,7 +570,7 @@ uart_irq_rdbuf_writebyte: ; @clobbers R17, X uart_irq_rdbuf_readbyte: - m_ringbuffer_readbyte \ + m_ringbuffer_y_readbyte \ UART_IRQ_IFACE_READBUF_SIZE, \ UART_IRQ_IFACE_OFFS_READBUF_USED, \ UART_IRQ_IFACE_OFFS_READBUF_RDPOS, \ @@ -670,7 +590,7 @@ uart_irq_rdbuf_readbyte: ; @clobbers R17, X uart_irq_wrbuf_writebyte: - m_ringbuffer_writebyte \ + m_ringbuffer_y_writebyte \ UART_IRQ_IFACE_WRITEBUF_SIZE, \ UART_IRQ_IFACE_OFFS_WRITEBUF_USED, \ UART_IRQ_IFACE_OFFS_WRITEBUF_RDPOS, \ @@ -690,7 +610,7 @@ uart_irq_wrbuf_writebyte: ; @clobbers R17, X uart_irq_wrbuf_readbyte: - m_ringbuffer_readbyte \ + m_ringbuffer_y_readbyte \ UART_IRQ_IFACE_WRITEBUF_SIZE, \ UART_IRQ_IFACE_OFFS_WRITEBUF_USED, \ UART_IRQ_IFACE_OFFS_WRITEBUF_RDPOS, \