From 601559ca6e14723466152cd61f0abf4fbbb1de2c Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 9 Feb 2025 21:05:48 +0100 Subject: [PATCH] avr: added RingBufferY_PeekByte --- avr/common/m_ringbuffer_y.asm | 37 +++++++++++++++++++++++++++++++++++ avr/common/ringbuffer_y.asm | 29 +++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/avr/common/m_ringbuffer_y.asm b/avr/common/m_ringbuffer_y.asm index 7a8fa1d..31ca3c3 100644 --- a/avr/common/m_ringbuffer_y.asm +++ b/avr/common/m_ringbuffer_y.asm @@ -92,6 +92,43 @@ l_end: +; --------------------------------------------------------------------------- +; @macro m_ringbuffer_y_peekbyte +; +; @param Y base address (for "LDD Y+nn" and "STD Y+nn") +; @param %0 offset to Y to access maxBytes variable (for "LDD Y+nn" and "STD Y+nn") +; @param %1 offset to Y to access usedBytes +; @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, R18, X + +.macro m_ringbuffer_y_peekbyte + ldd r18, Y+@0 ; maxBytes + 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 + std Y+@2, r17 ; readPos + sec +l_end: +.endmacro +; @end + + + ; --------------------------------------------------------------------------- ; @macro m_ringbuffer_y_reset ; diff --git a/avr/common/ringbuffer_y.asm b/avr/common/ringbuffer_y.asm index ac56ddc..76c618d 100644 --- a/avr/common/ringbuffer_y.asm +++ b/avr/common/ringbuffer_y.asm @@ -52,9 +52,9 @@ RingBufferY_WriteByte: ; --------------------------------------------------------------------------- -; @macro m_ringbuffer_y_readbyte +; @routine RingBufferY_ReadByte ; -; @param Y base address of ringbuffer struct +; @param Y base address of ringbuffer struct ; @return CFLAG set if okay, cleared on error (i.e. buffer empty) ; @return R16 byte read ; @clobbers R17, R18, X @@ -71,6 +71,31 @@ RingBufferY_ReadByte: +; --------------------------------------------------------------------------- +; @routine RingBufferY_PeekByte +; +; @param Y base address (for "LDD Y+nn" and "STD Y+nn") +; @param %0 offset to Y to access maxBytes variable (for "LDD Y+nn" and "STD Y+nn") +; @param %1 offset to Y to access usedBytes +; @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 empty) +; @return R16 byte read +; @clobbers R17, R18, X + +RingBufferY_PeekByte: + m_ringbuffer_y_peekbyte \ + RINGBUFFERY_OFFS_MAXSIZE, \ + RINGBUFFERY_OFFS_USED, \ + RINGBUFFERY_OFFS_READPOS, \ + RINGBUFFERY_OFFS_WRITEPOS, \ + RINGBUFFERY_OFFS_DATA + ret +; @end + + + ; --------------------------------------------------------------------------- ; @macro m_ringbuffer_y_reset ;