avr: added code for fixed buffers.
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
<extradist>
|
<extradist>
|
||||||
crc8.asm
|
crc8.asm
|
||||||
|
fixedbuffers.asm
|
||||||
m_ringbuffer.asm
|
m_ringbuffer.asm
|
||||||
m_ringbuffer_y.asm
|
m_ringbuffer_y.asm
|
||||||
ringbuffer.asm
|
ringbuffer.asm
|
||||||
|
|||||||
112
avr/common/fixedbuffers.asm
Normal file
112
avr/common/fixedbuffers.asm
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @macro m_fixedbuf_init
|
||||||
|
;
|
||||||
|
; @param X pointer to start of buffers
|
||||||
|
; @param %0 constant maxBytes per buffer (including statusbyte in front)
|
||||||
|
; @param %1 constant maxBuffers
|
||||||
|
; @clobbers r16, r17, X
|
||||||
|
|
||||||
|
.macro m_fixedbuf_init
|
||||||
|
ldi r17, @1
|
||||||
|
clr r16
|
||||||
|
l_loop:
|
||||||
|
st X, r16 ; unused
|
||||||
|
adiw xh:xl,@0
|
||||||
|
dec r17
|
||||||
|
brne l_loop
|
||||||
|
.endmacro
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @macro m_fixedbuf_reserve
|
||||||
|
;
|
||||||
|
; @return CFLAG set if buffer available, cleared otherwise
|
||||||
|
; @return r16 buffer num
|
||||||
|
; @return X pointer to start of buffer
|
||||||
|
; @param X pointer to start of buffers
|
||||||
|
; @param %0 constant maxBytes per buffer (including statusbyte in front)
|
||||||
|
; @param %1 constant maxBuffers
|
||||||
|
; @clobbers r16, r17, X
|
||||||
|
|
||||||
|
.macro m_fixedbuf_reserve
|
||||||
|
clr r17 ; loop var: current buffer num
|
||||||
|
l_loop:
|
||||||
|
ld r16, X
|
||||||
|
tst r16
|
||||||
|
breq l_foundfree
|
||||||
|
adiw xh:xl, @0
|
||||||
|
inc r17
|
||||||
|
cpi r17, @1
|
||||||
|
brcs l_loop
|
||||||
|
rjmp l_end ; use cleared CFLAG
|
||||||
|
l_foundfree:
|
||||||
|
ldi r16, 0x80 ; mark as used
|
||||||
|
st X, r16
|
||||||
|
mov r16, r17
|
||||||
|
sec ; set CFLAG, return bufnum in r16, pointre in X
|
||||||
|
l_end:
|
||||||
|
.endmacro
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @macro m_fixedbuf_release
|
||||||
|
;
|
||||||
|
; @param X pointer to start of buffers
|
||||||
|
; @param %0 constant maxBytes per buffer (including statusbyte in front)
|
||||||
|
; @param %1 constant maxBuffers
|
||||||
|
; @clobbers r16
|
||||||
|
|
||||||
|
.macro m_fixedbuf_release
|
||||||
|
clr r16
|
||||||
|
st X, r16
|
||||||
|
.endmacro
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @macro m_fixedbuf_locate
|
||||||
|
;
|
||||||
|
; use this routine only if you can't easily calculate the offset of the buffer
|
||||||
|
; (e.g. by using shift operations for calculation)
|
||||||
|
;
|
||||||
|
; @return CFLAG set if buffer found, cleared otherwise
|
||||||
|
; @return X pointer to start of located buffer (points to the statusbyte in front)
|
||||||
|
; @param r16 buffer num
|
||||||
|
; @param X pointer to start of buffers
|
||||||
|
; @param %0 constant maxBytes per buffer
|
||||||
|
; @param %1 constant maxBuffers
|
||||||
|
; @clobbers r16, X
|
||||||
|
|
||||||
|
.macro m_fixedbuf_locate:
|
||||||
|
cpi r16, @1
|
||||||
|
brcc l_end ; idx out of range, use cleared CFLAG
|
||||||
|
tst r16 ; doesn't change CFLAG which is set from CPI above
|
||||||
|
breq l_end ; buffer 0, return start of buffers
|
||||||
|
l_loop:
|
||||||
|
adiw xh:xl, @0
|
||||||
|
dec r16
|
||||||
|
brne l_loop
|
||||||
|
sec
|
||||||
|
l_end:
|
||||||
|
.endmacro
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user