avr: more work on com2wn module.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
com2wnIoRingBuffer: .byte RINGBUFFERY_SIZE+COM2WN_IO_RINGBUFFER_SIZE
|
com2wnIoRingBuffer: .byte RINGBUFFERY_SIZE+COM2WN_IO_RINGBUFFER_SIZE
|
||||||
com2wnIoCurrentClockStates: .byte 1
|
com2wnIoCurrentClockStates: .byte 1
|
||||||
com2wnIoLastClockStates: .byte 1
|
com2wnIoLastClockStates: .byte 1
|
||||||
|
com2wnIoDisabledClockMask: .byte 1
|
||||||
com2wnIoFlags: .byte 1
|
com2wnIoFlags: .byte 1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ COM2WN_Init:
|
|||||||
|
|
||||||
clr r16
|
clr r16
|
||||||
sts com2wnIoFlags, r16
|
sts com2wnIoFlags, r16
|
||||||
|
sts com2wnIoDisabledClockMask, r16
|
||||||
|
|
||||||
ldi yl, LOW(com2wnIoRingBuffer)
|
ldi yl, LOW(com2wnIoRingBuffer)
|
||||||
ldi yh, HIGH(com2wnIoRingBuffer)
|
ldi yh, HIGH(com2wnIoRingBuffer)
|
||||||
@@ -85,6 +86,8 @@ COM2WN_Init:
|
|||||||
mCOM2WN_INIT 7
|
mCOM2WN_INIT 7
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
|
rcall com2wnSetupIrq
|
||||||
|
|
||||||
ret
|
ret
|
||||||
; @end
|
; @end
|
||||||
|
|
||||||
@@ -100,8 +103,7 @@ com2wnInit:
|
|||||||
rcall com2wSetMode ; (R17)
|
rcall com2wSetMode ; (R17)
|
||||||
|
|
||||||
rcall com2wSetupLines
|
rcall com2wSetupLines
|
||||||
rcall com2wnSetupIrq
|
rcall com2wnEnableClkIrq
|
||||||
|
|
||||||
ret
|
ret
|
||||||
; @end
|
; @end
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,13 @@ com2wnSetupIrq:
|
|||||||
com2wnEnableClkIrq:
|
com2wnEnableClkIrq:
|
||||||
push r16
|
push r16
|
||||||
push r17
|
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
|
ldd r16, Y+COM2W_IFACE_OFFS_PINMASK_IRQ
|
||||||
inr r17, COM_IRQ_ADDR_CLK
|
inr r17, COM_IRQ_ADDR_CLK
|
||||||
or r17, r16
|
or r17, r16
|
||||||
@@ -70,6 +77,13 @@ com2wnDisableClkIrq:
|
|||||||
inr r17, COM_IRQ_ADDR_CLK
|
inr r17, COM_IRQ_ADDR_CLK
|
||||||
and r17, r16 ; clear bit for clock line
|
and r17, r16 ; clear bit for clock line
|
||||||
outr COM_IRQ_ADDR_CLK, r17
|
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 r17
|
||||||
pop r16
|
pop r16
|
||||||
ret
|
ret
|
||||||
@@ -93,6 +107,8 @@ COM2WN_ClkChangeIsr:
|
|||||||
push r16
|
push r16
|
||||||
inr r16, COM_CLK_INPUT ; read clk state early
|
inr r16, COM_CLK_INPUT ; read clk state early
|
||||||
push r17
|
push r17
|
||||||
|
lds r17, com2wnIoDisabledClockMask ; mask disabled interfaces
|
||||||
|
or r16, r17
|
||||||
push r18
|
push r18
|
||||||
push xl
|
push xl
|
||||||
push xh
|
push xh
|
||||||
@@ -125,6 +141,8 @@ COM2WN_ClkChangeIsr_popRet:
|
|||||||
inr r16, COM_CLK_INPUT ; read clk state early
|
inr r16, COM_CLK_INPUT ; read clk state early
|
||||||
inr r17, COM_DATA_INPUT ; read data state early
|
inr r17, COM_DATA_INPUT ; read data state early
|
||||||
push r18
|
push r18
|
||||||
|
lds r18, com2wnIoDisabledClockMask ; mask disabled interfaces
|
||||||
|
or r16, r18
|
||||||
push xl
|
push xl
|
||||||
push xh
|
push xh
|
||||||
push yl
|
push yl
|
||||||
|
|||||||
@@ -120,6 +120,9 @@ com2wnReadNextBit_end:
|
|||||||
; @clobbers r16, r17, r18, X
|
; @clobbers r16, r17, r18, X
|
||||||
|
|
||||||
com2wnByteRecvd:
|
com2wnByteRecvd:
|
||||||
|
push r16
|
||||||
|
rcall LedActivity_Trigger
|
||||||
|
pop r16
|
||||||
ldd xl, Y+COM2W_IFACE_OFFS_BUFPOS_LOW
|
ldd xl, Y+COM2W_IFACE_OFFS_BUFPOS_LOW
|
||||||
ldd xh, Y+COM2W_IFACE_OFFS_BUFPOS_HIGH
|
ldd xh, Y+COM2W_IFACE_OFFS_BUFPOS_HIGH
|
||||||
ldd r17, Y+COM2W_IFACE_OFFS_BUFLEFT
|
ldd r17, Y+COM2W_IFACE_OFFS_BUFLEFT
|
||||||
@@ -165,7 +168,6 @@ com2wnByteRecvd_overflow:
|
|||||||
ldi r16, NET_IFACE_OFFS_ERR_MISSED_LOW
|
ldi r16, NET_IFACE_OFFS_ERR_MISSED_LOW
|
||||||
rjmp com2wnByteRecvd_error
|
rjmp com2wnByteRecvd_error
|
||||||
com2wnByteRecvd_eMsgSize:
|
com2wnByteRecvd_eMsgSize:
|
||||||
|
|
||||||
ldi r16, NET_IFACE_OFFS_ERR_MSGSIZE_LOW
|
ldi r16, NET_IFACE_OFFS_ERR_MSGSIZE_LOW
|
||||||
com2wnByteRecvd_error:
|
com2wnByteRecvd_error:
|
||||||
push r24
|
push r24
|
||||||
|
|||||||
@@ -170,11 +170,16 @@ com2wnLowLevelRun_loop: ; loop through all interfaces
|
|||||||
and r21, r18 ; CLK for interface changed?
|
and r21, r18 ; CLK for interface changed?
|
||||||
breq com2wnLowLevelRun_nextIface
|
breq com2wnLowLevelRun_nextIface
|
||||||
push r16
|
push r16
|
||||||
push r18
|
push r17
|
||||||
push r19
|
push r18
|
||||||
rcall com2wnActOnClock ; (r16, r17, r18, X)
|
push r19
|
||||||
pop r19
|
and r16, r20 ; only keep CLK mask for current interface
|
||||||
pop r18
|
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
|
pop r16
|
||||||
com2wnLowLevelRun_nextIface:
|
com2wnLowLevelRun_nextIface:
|
||||||
ldi r20, COM2W_IFACE_SIZE
|
ldi r20, COM2W_IFACE_SIZE
|
||||||
@@ -265,6 +270,8 @@ com2wnStartReading:
|
|||||||
std Y+COM2W_IFACE_OFFS_BUFLEFT, r16
|
std Y+COM2W_IFACE_OFFS_BUFLEFT, r16
|
||||||
clr r16
|
clr r16
|
||||||
std Y+COM2W_IFACE_OFFS_BUFUSED, 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
|
ldi r16, COM2W_MODE_READING
|
||||||
rcall com2wSetMode ; (R17)
|
rcall com2wSetMode ; (R17)
|
||||||
ret
|
ret
|
||||||
|
|||||||
@@ -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
|
#endif ; AVR_MODULES_COM2W_COM2WN_WAIT_H
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user