avr: more work on com2wn module.

This commit is contained in:
Martin Preuss
2025-09-01 23:25:02 +02:00
parent 81669a5442
commit b95a4fa872
6 changed files with 38 additions and 83 deletions

View File

@@ -17,6 +17,7 @@
com2wnIoRingBuffer: .byte RINGBUFFERY_SIZE+COM2WN_IO_RINGBUFFER_SIZE
com2wnIoCurrentClockStates: .byte 1
com2wnIoLastClockStates: .byte 1
com2wnIoDisabledClockMask: .byte 1
com2wnIoFlags: .byte 1

View File

@@ -51,6 +51,7 @@ COM2WN_Init:
clr r16
sts com2wnIoFlags, r16
sts com2wnIoDisabledClockMask, r16
ldi yl, LOW(com2wnIoRingBuffer)
ldi yh, HIGH(com2wnIoRingBuffer)
@@ -85,6 +86,8 @@ COM2WN_Init:
mCOM2WN_INIT 7
.endif
rcall com2wnSetupIrq
ret
; @end
@@ -100,8 +103,7 @@ com2wnInit:
rcall com2wSetMode ; (R17)
rcall com2wSetupLines
rcall com2wnSetupIrq
rcall com2wnEnableClkIrq
ret
; @end

View File

@@ -46,6 +46,13 @@ com2wnSetupIrq:
com2wnEnableClkIrq:
push r16
push r17
; clear this interfaces CLK bit in com2wnIoDisabledClockMask
ldd r16, Y+COM2W_IFACE_OFFS_PINMASK_CLK
com r16
lds r17, com2wnIoDisabledClockMask
and r17, r16
sts com2wnIoDisabledClockMask, r17
; enable pin change irq
ldd r16, Y+COM2W_IFACE_OFFS_PINMASK_IRQ
inr r17, COM_IRQ_ADDR_CLK
or r17, r16
@@ -70,6 +77,13 @@ com2wnDisableClkIrq:
inr r17, COM_IRQ_ADDR_CLK
and r17, r16 ; clear bit for clock line
outr COM_IRQ_ADDR_CLK, r17
; set this interfaces CLK bit in com2wnIoDisabledClockMask
ldd r16, Y+COM2W_IFACE_OFFS_PINMASK_CLK
lds r17, com2wnIoDisabledClockMask
or r17, r16
sts com2wnIoDisabledClockMask, r17
pop r17
pop r16
ret
@@ -93,6 +107,8 @@ COM2WN_ClkChangeIsr:
push r16
inr r16, COM_CLK_INPUT ; read clk state early
push r17
lds r17, com2wnIoDisabledClockMask ; mask disabled interfaces
or r16, r17
push r18
push xl
push xh
@@ -125,6 +141,8 @@ COM2WN_ClkChangeIsr_popRet:
inr r16, COM_CLK_INPUT ; read clk state early
inr r17, COM_DATA_INPUT ; read data state early
push r18
lds r18, com2wnIoDisabledClockMask ; mask disabled interfaces
or r16, r18
push xl
push xh
push yl

View File

@@ -120,6 +120,9 @@ com2wnReadNextBit_end:
; @clobbers r16, r17, r18, X
com2wnByteRecvd:
push r16
rcall LedActivity_Trigger
pop r16
ldd xl, Y+COM2W_IFACE_OFFS_BUFPOS_LOW
ldd xh, Y+COM2W_IFACE_OFFS_BUFPOS_HIGH
ldd r17, Y+COM2W_IFACE_OFFS_BUFLEFT
@@ -165,7 +168,6 @@ com2wnByteRecvd_overflow:
ldi r16, NET_IFACE_OFFS_ERR_MISSED_LOW
rjmp com2wnByteRecvd_error
com2wnByteRecvd_eMsgSize:
ldi r16, NET_IFACE_OFFS_ERR_MSGSIZE_LOW
com2wnByteRecvd_error:
push r24

View File

@@ -170,11 +170,16 @@ com2wnLowLevelRun_loop: ; loop through all interfaces
and r21, r18 ; CLK for interface changed?
breq com2wnLowLevelRun_nextIface
push r16
push r17
push r18
push r19
and r16, r20 ; only keep CLK mask for current interface
ldd r20, Y+COM2W_IFACE_OFFS_PINMASK_DATA
and r17, r20 ; only keep DATA mask for current interface
rcall com2wnActOnClock ; (r16, r17, r18, X)
pop r19
pop r18
pop r17
pop r16
com2wnLowLevelRun_nextIface:
ldi r20, COM2W_IFACE_SIZE
@@ -265,6 +270,8 @@ com2wnStartReading:
std Y+COM2W_IFACE_OFFS_BUFLEFT, r16
clr r16
std Y+COM2W_IFACE_OFFS_BUFUSED, r16
std Y+COM2W_IFACE_OFFS_BITCOUNTER, r16
std Y+COM2W_IFACE_OFFS_CURRBYTE, r16
ldi r16, COM2W_MODE_READING
rcall com2wSetMode ; (R17)
ret

View File

@@ -163,81 +163,6 @@ com2wWaitForClockLowMulti10Us_stateReached:
.if clock > 1000000
; begin version for > 1000000 Hz
ldi r20, LOW(clock/1000000)
ldd r22, Y+COM2W_IFACE_OFFS_PINMASK_CLK ; +2
com2wWaitForClockLowMulti10Us_loop0:
push r20 ; +2
com2wWaitForClockLowMulti10Us_loop: ; 10 cycles per loop
inr r16, COM_CLK_INPUT ; +1 (if low port, +2 if high port)
and r16, r22 ; +1
breq com2wWaitForClockLowMulti10Us_stateReached ; +1 if FALSE, +2 if TRUE
inr r16, COM_CLK_INPUT ; +1 (if low port, +2 if high port)
and r16, r22 ; +1
breq com2wWaitForClockLowMulti10Us_stateReached ; +1 if FALSE, +2 if TRUE
nop ; +1
dec r20 ; +1
brne com2wWaitForClockLowMulti10Us_loop ; +2 if TRUE, +1 if FALSE
pop r20 ; +2
dec r20 ; +1
brne com2wWaitForClockLowMulti10Us_loop0 ; +1 if FALSE, +2 if TRUE
clc ; +1
ret ; +4
com2wWaitForClockLowMulti10Us_stateReached:
pop r20
sec ; +1
ret ; +4
; end version for > 1000000 Hz
.elif clock < 1000000
.error "Clock speed too low"
.else
; begin version for 1000000 Hz
ldd r22, Y+COM2W_IFACE_OFFS_PINMASK_CLK ; +2
com2wWaitForClockLowMulti10Us_loop: ; 10 cycles per loop
inr r16, COM_CLK_INPUT ; +1 (if low port, +2 if high port)
and r16, r22 ; +1
breq com2wWaitForClockLowMulti10Us_stateReached ; +1 if FALSE, +2 if TRUE
inr r16, COM_CLK_INPUT ; +1 (if low port, +2 if high port)
and r16, r22 ; +1
breq com2wWaitForClockLowMulti10Us_stateReached ; +1 if FALSE, +2 if TRUE
nop ; +1
dec r20 ; +1
brne com2wWaitForClockLowMulti10Us_loop ; +2 if TRUE, +1 if FALSE
clc ; +1
ret ; +4
com2wWaitForClockLowMulti10Us_stateReached:
sec ; +1
ret ; +4
; end version for 1000000 Hz
.endif
; @end
#endif ; AVR_MODULES_COM2W_COM2WN_WAIT_H