ringbuffer: Fixed a few bugs.
This commit is contained in:
@@ -68,15 +68,12 @@ RingBuffer_Alloc_l1:
|
|||||||
mov r16, r20
|
mov r16, r20
|
||||||
|
|
||||||
; preset first byte (this is the length byte in COM module) with 0
|
; preset first byte (this is the length byte in COM module) with 0
|
||||||
push yl
|
push r16
|
||||||
push yh
|
mov r18, r16
|
||||||
clr r17
|
clr r16
|
||||||
add yl, r16
|
rcall RingBuffer_Write
|
||||||
adc yh, r17
|
rcall RingBuffer_Write
|
||||||
std y+RINGBUFFER_OFFS_DATA, r17 ; (length byte in COM module)
|
pop r16
|
||||||
std y+RINGBUFFER_OFFS_DATA+1, r17 ; (flags byte in COM module)
|
|
||||||
pop yh
|
|
||||||
pop yl
|
|
||||||
|
|
||||||
out SREG, r21 ; restore global interrupt enable bit in SREG
|
out SREG, r21 ; restore global interrupt enable bit in SREG
|
||||||
sec
|
sec
|
||||||
@@ -113,7 +110,7 @@ RingBuffer_DeallocRead:
|
|||||||
mov r20, r19 ; readpos
|
mov r20, r19 ; readpos
|
||||||
add r20, r16 ; readpos + to_dealloc
|
add r20, r16 ; readpos + to_dealloc
|
||||||
cp r20, r17 ; new readpos > max?
|
cp r20, r17 ; new readpos > max?
|
||||||
brcc RingBuffer_DeallocRead_l1 ; no, rjmp
|
brcs RingBuffer_DeallocRead_l1 ; no, rjmp
|
||||||
sub r20, r17 ; wrap around
|
sub r20, r17 ; wrap around
|
||||||
RingBuffer_DeallocRead_l1:
|
RingBuffer_DeallocRead_l1:
|
||||||
std y+RINGBUFFER_OFFS_READPOS, r20
|
std y+RINGBUFFER_OFFS_READPOS, r20
|
||||||
@@ -193,8 +190,8 @@ RingBuffer_Write:
|
|||||||
pop yl
|
pop yl
|
||||||
pop yh
|
pop yh
|
||||||
inc r18
|
inc r18
|
||||||
cp r18, r19
|
cp r18, r19 ; r19 > r18; yes: CF set
|
||||||
brcc RingBuffer_Write_end
|
brcs RingBuffer_Write_end
|
||||||
sub r18, r19
|
sub r18, r19
|
||||||
|
|
||||||
RingBuffer_Write_end:
|
RingBuffer_Write_end:
|
||||||
@@ -230,7 +227,7 @@ RingBuffer_Read:
|
|||||||
pop yh
|
pop yh
|
||||||
inc r18
|
inc r18
|
||||||
cp r18, r19
|
cp r18, r19
|
||||||
brcc RingBuffer_Read_end
|
brcs RingBuffer_Read_end
|
||||||
sub r18, r19
|
sub r18, r19
|
||||||
|
|
||||||
RingBuffer_Read_end:
|
RingBuffer_Read_end:
|
||||||
|
|||||||
Reference in New Issue
Block a user