avr: started work on com2w_router for S03.
This commit is contained in:
0
avr/modules/com2w_router/WIP
Normal file
0
avr/modules/com2w_router/WIP
Normal file
33
avr/modules/com2w_router/data.asm
Normal file
33
avr/modules/com2w_router/data.asm
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2026 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
#ifndef AVR_MOD_COM2WROUTER_DATA_ASM
|
||||||
|
#define AVR_MOD_COM2WROUTER_DATA_ASM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; SDRAM data
|
||||||
|
|
||||||
|
.dseg
|
||||||
|
|
||||||
|
com2wAllBegin:
|
||||||
|
com2wAllCurrentPinMask: .byte 1
|
||||||
|
com2wAllLastClock: .byte 1
|
||||||
|
com2wAllEnd:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif ; AVR_MOD_COM2WROUTER_DATA_ASM
|
||||||
|
|
||||||
175
avr/modules/com2w_router/iface.asm
Normal file
175
avr/modules/com2w_router/iface.asm
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2026 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
#ifndef AVR_MOD_COM2WROUTER_IFACE_ASM
|
||||||
|
#define AVR_MOD_COM2WROUTER_IFACE_ASM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
.equ COM2WR_BUFFERSIZE = NET_BUFFERS_SIZE-1
|
||||||
|
|
||||||
|
|
||||||
|
.equ COM2WR_MODE_IDLE = 0
|
||||||
|
.equ COM2WR_MODE_SKIPPING = 1
|
||||||
|
.equ COM2WR_MODE_READING = 2
|
||||||
|
.equ COM2WR_MODE_WRITING = 3
|
||||||
|
.equ COM2WR_MODE_NUM = 4
|
||||||
|
|
||||||
|
|
||||||
|
.equ COM2WR_IFACE_OFFS_BEGIN = NET_IFACE_SIZE
|
||||||
|
.equ COM2WR_IFACE_OFFS_MODE = COM2WR_IFACE_OFFS_BEGIN+0
|
||||||
|
.equ COM2WR_IFACE_OFFS_MODECOUNTER = COM2WR_IFACE_OFFS_BEGIN+1
|
||||||
|
.equ COM2WR_IFACE_OFFS_CURRBYTE = COM2WR_IFACE_OFFS_BEGIN+2
|
||||||
|
.equ COM2WR_IFACE_OFFS_BITCOUNTER = COM2WR_IFACE_OFFS_BEGIN+3
|
||||||
|
.equ COM2WR_IFACE_OFFS_BUFPOS_LO = COM2WR_IFACE_OFFS_BEGIN+4
|
||||||
|
.equ COM2WR_IFACE_OFFS_BUFPOS_HI = COM2WR_IFACE_OFFS_BEGIN+5
|
||||||
|
.equ COM2WR_IFACE_OFFS_BUFUSED = COM2WR_IFACE_OFFS_BEGIN+6
|
||||||
|
.equ COM2WR_IFACE_OFFS_BUFLEFT = COM2WR_IFACE_OFFS_BEGIN+7
|
||||||
|
.equ COM2WR_IFACE_OFFS_BUFFER = COM2WR_IFACE_OFFS_BEGIN+8
|
||||||
|
|
||||||
|
.equ COM2WR_IFACE_SIZE = COM2WR_IFACE_OFFS_BUFFER+COM2WR_BUFFERSIZE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2WR_Iface_StartReading
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SDRAM
|
||||||
|
; @clobbers r16, X
|
||||||
|
|
||||||
|
COM2WR_Iface_StartReading:
|
||||||
|
rcall com2wrResetReadBuffer
|
||||||
|
ldi r16, COM2WR_MODE_READING
|
||||||
|
std Y+COM2WR_IFACE_OFFS_MODE, r16
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2WR_Iface_StartSkipping
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SDRAM
|
||||||
|
; @clobbers r16, X
|
||||||
|
|
||||||
|
COM2WR_Iface_StartSkipping:
|
||||||
|
ldi r16, COM2WR_MODE_SKIPPING
|
||||||
|
std Y+COM2WR_IFACE_OFFS_MODE, r16
|
||||||
|
rcall com2wrResetReadBuffer
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2WR_Iface_RecvHandleBit
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SDRAM
|
||||||
|
; @param R18 current CLK bit
|
||||||
|
; @param R19 current DATA bit
|
||||||
|
; @clobbers
|
||||||
|
|
||||||
|
COM2WR_Iface_RecvHandleBit:
|
||||||
|
ldd r16, Y+COM2WR_IFACE_OFFS_MODE
|
||||||
|
cpi r16, COM2WR_MODE_READING
|
||||||
|
breq COM2WR_Iface_RecvHandleBit_reading
|
||||||
|
cpi r16, COM2WR_MODE_IDLE
|
||||||
|
breq COM2WR_Iface_RecvHandleBit_idle
|
||||||
|
rjmp COM2WR_Iface_RecvHandleBit_ret
|
||||||
|
COM2WR_Iface_RecvHandleBit_reading:
|
||||||
|
tst r18 ; CLK now HIGH?
|
||||||
|
breq COM2WR_Iface_RecvHandleBit_ret ; nope, ignore
|
||||||
|
; TODO: read bit
|
||||||
|
rjmp COM2WR_Iface_RecvHandleBit_ret
|
||||||
|
COM2WR_Iface_RecvHandleBit_idle:
|
||||||
|
tst r18 ; CLK became LOW?
|
||||||
|
brne COM2WR_Iface_RecvHandleBit_ret ; nope, ignore
|
||||||
|
rcall COM2WR_Iface_StartReading ; (R16, X)
|
||||||
|
COM2WR_Iface_RecvHandleBit_ret:
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
com2wrRecvBit:
|
||||||
|
ldd r16, Y+COM2WR_IFACE_OFFS_CURRBYTE
|
||||||
|
lsr r19 ; databit to carryflag
|
||||||
|
ror r16 ; carryflag to current byte
|
||||||
|
std Y+COM2WR_IFACE_OFFS_CURRBYTE, r16
|
||||||
|
ldd r17, Y+COM2WR_IFACE_OFFS_BITCOUNTER
|
||||||
|
dec r17
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BITCOUNTER, r17
|
||||||
|
brne com2wrRecvBit_ret
|
||||||
|
; byte complete, test counter for remaining bytes
|
||||||
|
ldd r17, Y+COM2WR_IFACE_OFFS_BUFLEFT
|
||||||
|
tst r17
|
||||||
|
breq com2wrRecvBit_overrun
|
||||||
|
dec r17
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BUFLEFT, r17
|
||||||
|
; store current byte
|
||||||
|
ldd xl, Y+COM2WR_IFACE_OFFS_BUFPOS_LO
|
||||||
|
ldd xh, Y+COM2WR_IFACE_OFFS_BUFPOS_HI
|
||||||
|
st X+, r16
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BUFPOS_LO, xl
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BUFPOS_HI, xh
|
||||||
|
; increment byte counter, check for size, adjust remaining byte counter if msgsize received
|
||||||
|
ldd r18, Y+COM2WR_IFACE_OFFS_BUFUSED
|
||||||
|
inc r18
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BUFUSED, r18
|
||||||
|
cpi r18, 2 ; two bytes (DESTADDR, MSGLEN)?
|
||||||
|
brne com2wrRecvBit_ret ; no, jmp
|
||||||
|
inc r16 ; last recvd byte contains remaining msg size, add CRC byte
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BUFLEFT, r16 ; set remaining bytes counter (TODO: check size!)
|
||||||
|
rjmp com2wrRecvBit_ret
|
||||||
|
com2wrRecvBit_overrun:
|
||||||
|
; TODO
|
||||||
|
|
||||||
|
com2wrRecvBit_ret:
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine com2wrResetReadBuffer
|
||||||
|
;
|
||||||
|
; @param Y pointer to interface data in SDRAM
|
||||||
|
; @clobbers r16, X
|
||||||
|
|
||||||
|
com2wrResetReadBuffer:
|
||||||
|
ldi r16, 8
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BITCOUNTER, r16
|
||||||
|
clr r16
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BUFUSED, r16
|
||||||
|
std Y+COM2WR_IFACE_OFFS_MODECOUNTER, r16
|
||||||
|
ldi xl, COM2WR_IFACE_OFFS_BUFFER
|
||||||
|
clr xh
|
||||||
|
add xl, yl
|
||||||
|
adc xh, yh
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BUFPOS_LO, xl
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BUFPOS_HI, xh
|
||||||
|
ldi r16, COM2WR_BUFFERSIZE
|
||||||
|
std Y+COM2WR_IFACE_OFFS_BUFLEFT, r16
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif ; AVR_MOD_COM2WROUTER_IFACE_ASM
|
||||||
|
|
||||||
76
avr/modules/com2w_router/init.asm
Normal file
76
avr/modules/com2w_router/init.asm
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2026 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
#ifndef AVR_MOD_COM2WROUTER_INIT_ASM
|
||||||
|
#define AVR_MOD_COM2WROUTER_INIT_ASM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2WR_Router_Init @global
|
||||||
|
;
|
||||||
|
; @clobbers r16
|
||||||
|
|
||||||
|
COM2WR_Router_Init:
|
||||||
|
; setup data
|
||||||
|
clr r16
|
||||||
|
sts com2wAllCurrentPinMask, r16
|
||||||
|
dec r16
|
||||||
|
sts com2wAllLastClock, r16 ; preset last clock with 1
|
||||||
|
|
||||||
|
bigcall COM2WR_Ringbuffer_Init
|
||||||
|
|
||||||
|
; TODO: setup all sub-interfaces
|
||||||
|
|
||||||
|
; setup lines
|
||||||
|
clr r16
|
||||||
|
outr COM_CLK_DDR, r16 ; make all CLK pins inputs
|
||||||
|
outr COM_DATA_DDR, r16 ; make all DATA pins inputs
|
||||||
|
|
||||||
|
.ifdef COM_CLK_PUE
|
||||||
|
outr COM_CLK_PUE, r16 ; disable pullup resistors on CLK lines
|
||||||
|
.endif
|
||||||
|
|
||||||
|
.ifdef COM_DATA_PUE
|
||||||
|
outr COM_DATA_PUE, r16 ; disable pullup resistors on DATA lines
|
||||||
|
.endif
|
||||||
|
|
||||||
|
; enable pin change irqs for all pins of given port
|
||||||
|
ldi r16, 0xff
|
||||||
|
outr COM_IRQ_ADDR_CLK, r16
|
||||||
|
|
||||||
|
; enable PCIEn irq
|
||||||
|
inr r16, COM_IRQ_ADDR_M_CLK ; enable pin change irq PCIEn
|
||||||
|
sbr r16, (1<<COM_IRQ_BIT_M_CLK)
|
||||||
|
outr COM_IRQ_ADDR_M_CLK, r16
|
||||||
|
|
||||||
|
; clear PCIEn interrupt flag
|
||||||
|
inr r16, COM_IRQ_ADDR_F_CLK ; enable pin change irq PCIEn
|
||||||
|
sbr r16, (1<<COM_IRQ_BIT_F_CLK)
|
||||||
|
outr COM_IRQ_ADDR_F_CLK, r16
|
||||||
|
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif ; AVR_MOD_COM2WROUTER_INIT_ASM
|
||||||
|
|
||||||
64
avr/modules/com2w_router/isr.asm
Normal file
64
avr/modules/com2w_router/isr.asm
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2026 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
#ifndef AVR_MOD_COM2WROUTER_ISR_ASM
|
||||||
|
#define AVR_MOD_COM2WROUTER_ISR_ASM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2WR_Router_PinChangeISR @global @isr
|
||||||
|
;
|
||||||
|
; @clobbers none
|
||||||
|
|
||||||
|
COM2WR_Router_PinChangeISR:
|
||||||
|
push r15
|
||||||
|
inr r15, SREG
|
||||||
|
push r16
|
||||||
|
push r17
|
||||||
|
push r18
|
||||||
|
inr r16, COM_CLK_INPUT
|
||||||
|
inr r17, COM_DATA_INPUT
|
||||||
|
lds r18, com2wAllCurrentPinMask
|
||||||
|
or r16, r18 ; preset ports marked as sending with ones
|
||||||
|
lds r18, com2wAllLastClock
|
||||||
|
sts com2wAllLastClock, r16
|
||||||
|
eor r18, r16 ; check for clock changes
|
||||||
|
breq COM2WR_Router_PinChangeISR_done
|
||||||
|
push r19
|
||||||
|
push xl
|
||||||
|
push xh
|
||||||
|
bigcall COM2WR_Ringbuffer_WriteWord ; (xl, xh, r18, r19)
|
||||||
|
pop xh
|
||||||
|
pop xl
|
||||||
|
pop r19
|
||||||
|
COM2WR_Router_PinChangeISR_done:
|
||||||
|
pop r18
|
||||||
|
pop r17
|
||||||
|
pop r16
|
||||||
|
outr SREG, r15
|
||||||
|
pop r15
|
||||||
|
reti
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif ; AVR_MOD_COM2WROUTER_ISR_ASM
|
||||||
|
|
||||||
30
avr/modules/com2w_router/main.asm
Normal file
30
avr/modules/com2w_router/main.asm
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2026 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
#ifndef AVR_MOD_COM2WROUTER_MAIN_ASM
|
||||||
|
#define AVR_MOD_COM2WROUTER_MAIN_ASM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif ; AVR_MOD_COM2WROUTER_MAIN_ASM
|
||||||
|
|
||||||
32
avr/modules/com2w_router/recv.asm
Normal file
32
avr/modules/com2w_router/recv.asm
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2026 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
#ifndef AVR_MOD_COM2WROUTER_RECV_ASM
|
||||||
|
#define AVR_MOD_COM2WROUTER_RECV_ASM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif ; AVR_MOD_COM2WROUTER_RECV_ASM
|
||||||
|
|
||||||
158
avr/modules/com2w_router/ringbuffer.asm
Normal file
158
avr/modules/com2w_router/ringbuffer.asm
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; copyright : (C) 2026 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. *
|
||||||
|
; ***************************************************************************
|
||||||
|
|
||||||
|
#ifndef AVR_MOD_COM2WROUTER_RINGBUFFER_ASM
|
||||||
|
#define AVR_MOD_COM2WROUTER_RINGBUFFER_ASM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; defines
|
||||||
|
|
||||||
|
.equ COM2WR_RINGBUFFER_MAX_WORDS = 512
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; SDRAM data
|
||||||
|
|
||||||
|
.dseg
|
||||||
|
|
||||||
|
|
||||||
|
com2wRingbufferBegin:
|
||||||
|
com2wRingbufferReadPos: .byte 2
|
||||||
|
com2wRingbufferWritePos: .byte 2
|
||||||
|
com2wRingbufferWordsInBuffer: .byte 2
|
||||||
|
com2wRingbufferData: .byte (2*COM2WR_RINGBUFFER_MAX_WORDS)
|
||||||
|
com2wRingbufferEnd:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ***************************************************************************
|
||||||
|
; code
|
||||||
|
|
||||||
|
.cseg
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2WR_Ringbuffer_Reset @global
|
||||||
|
;
|
||||||
|
; @clobbers r16
|
||||||
|
|
||||||
|
COM2WR_Ringbuffer_Init:
|
||||||
|
rjmp COM2WR_Ringbuffer_Reset
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2WR_Ringbuffer_Reset @global
|
||||||
|
;
|
||||||
|
; @clobbers r16
|
||||||
|
|
||||||
|
COM2WR_Ringbuffer_Reset:
|
||||||
|
clr r16
|
||||||
|
sts com2wRingbufferReadPos, r16
|
||||||
|
sts com2wRingbufferReadPos+1, r16
|
||||||
|
|
||||||
|
sts com2wRingbufferWritePos, r16
|
||||||
|
sts com2wRingbufferWritePos+1, r16
|
||||||
|
|
||||||
|
sts com2wRingbufferWordsInBuffer, r16
|
||||||
|
sts com2wRingbufferWordsInBuffer+1, r16
|
||||||
|
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2WR_Ringbuffer_WriteWord @global
|
||||||
|
;
|
||||||
|
; @return CFLAG set if data stored, cleared otherwise
|
||||||
|
; @param r16 low byte to add
|
||||||
|
; @param r17 high byte to add
|
||||||
|
; @clobbers xl, xh, r18, r19
|
||||||
|
|
||||||
|
COM2WR_Ringbuffer_WriteWord:
|
||||||
|
lds xl, com2wRingbufferWordsInBuffer ; +2
|
||||||
|
lds xh, com2wRingbufferWordsInBuffer+1 ; +2
|
||||||
|
ldi r18, LOW(COM2WR_RINGBUFFER_MAX_WORDS) ; +1
|
||||||
|
ldi r19, HIGH(COM2WR_RINGBUFFER_MAX_WORDS) ; +1
|
||||||
|
cp xl, r18 ; +1
|
||||||
|
cpc xh, r19 ; +1
|
||||||
|
brcc COM2WR_Ringbuffer_WriteWord_ret ; +1 (+2 if jump)
|
||||||
|
adiw xh:xl, 1 ; +1
|
||||||
|
sts com2wRingbufferWordsInBuffer, xl ; +2
|
||||||
|
sts com2wRingbufferWordsInBuffer+1, xh ; +2
|
||||||
|
lds xl, com2wRingbufferWritePos ; +2
|
||||||
|
lds xh, com2wRingbufferWritePos+1 ; +2
|
||||||
|
ldi r18, LOW(com2wRingbufferData) ; +1
|
||||||
|
ldi r19, HIGH(com2wRingbufferData) ; +1
|
||||||
|
add xl, r18 ; +1
|
||||||
|
adc xh, r19 ; +1
|
||||||
|
st X+, r16 ; +2
|
||||||
|
st X+, r17 ; +2
|
||||||
|
sub xl, r18 ; +1
|
||||||
|
sbc xh, r19 ; +1
|
||||||
|
andi xl, LOW((2*COM2WR_RINGBUFFER_MAX_WORDS)-1) ; +1
|
||||||
|
andi xh, HIGH((2*COM2WR_RINGBUFFER_MAX_WORDS)-1) ; +1
|
||||||
|
sts com2wRingbufferWritePos, xl ; +2
|
||||||
|
sts com2wRingbufferWritePos+1, xh ; +2
|
||||||
|
sec ; +1
|
||||||
|
COM2WR_Ringbuffer_WriteWord_ret:
|
||||||
|
ret ; +4 = +41 = <3us at 16MHz
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; @routine COM2WR_Ringbuffer_ReadWord @global
|
||||||
|
;
|
||||||
|
; @return CFLAG set if data available, cleared otherwise
|
||||||
|
; @return r16 low byte from buffer
|
||||||
|
; @return r17 high byte from buffer
|
||||||
|
; @clobbers xl, xh, r18
|
||||||
|
|
||||||
|
COM2WR_Ringbuffer_ReadWord:
|
||||||
|
lds xl, com2wRingbufferWordsInBuffer
|
||||||
|
lds xh, com2wRingbufferWordsInBuffer+1
|
||||||
|
mov r18, xl
|
||||||
|
or r18, xh
|
||||||
|
clc
|
||||||
|
breq COM2WR_Ringbuffer_ReadWord_ret
|
||||||
|
sbiw xh:xl, 1
|
||||||
|
sts com2wRingbufferWordsInBuffer, xl
|
||||||
|
sts com2wRingbufferWordsInBuffer+1, xh
|
||||||
|
lds xl, com2wRingbufferReadPos
|
||||||
|
lds xh, com2wRingbufferReadPos+1
|
||||||
|
ldi r18, LOW(com2wRingbufferData) ; +1
|
||||||
|
ldi r19, HIGH(com2wRingbufferData) ; +1
|
||||||
|
add xl, r18 ; +1
|
||||||
|
adc xh, r19 ; +1
|
||||||
|
ld r16, X+
|
||||||
|
ld r17, X+
|
||||||
|
sub xl, r18
|
||||||
|
sbc xh, r19
|
||||||
|
andi xl, LOW((2*COM2WR_RINGBUFFER_MAX_WORDS)-1)
|
||||||
|
andi xh, HIGH((2*COM2WR_RINGBUFFER_MAX_WORDS)-1)
|
||||||
|
sts com2wRingbufferReadPos, xl
|
||||||
|
sts com2wRingbufferReadPos+1, xh
|
||||||
|
sec
|
||||||
|
COM2WR_Ringbuffer_ReadWord_ret:
|
||||||
|
ret
|
||||||
|
; @end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif ; AVR_MOD_COM2WROUTER_RINGBUFFER_ASM
|
||||||
|
|
||||||
Reference in New Issue
Block a user