avr: cleanup lowlevel com2 routines.
This commit is contained in:
@@ -81,20 +81,20 @@ com2ReceiveByte:
|
|||||||
ldi r21, 8 ; bits left
|
ldi r21, 8 ; bits left
|
||||||
clr r20 ; byte currently receiving
|
clr r20 ; byte currently receiving
|
||||||
; wait for startbit
|
; wait for startbit
|
||||||
rcall com2WaitForDataLow ; (R17)
|
rcall com2WaitForDataLow ; (R16, R17, R22)
|
||||||
brcc com2ReceiveByte_error
|
brcc com2ReceiveByte_error
|
||||||
Utils_WaitNanoSecs COM_BIT_LENGTH/2, 5, r22 ; goto middle of startbit to maximize sync stability
|
Utils_WaitNanoSecs COM_BIT_LENGTH/2, 5, r22 ; goto middle of startbit to maximize sync stability
|
||||||
com2ReceiveByte_loop:
|
com2ReceiveByte_loop:
|
||||||
Utils_WaitNanoSecs COM_BIT_LENGTH, 8, r22 ; 8 cycles used in the complete loop between waits
|
Utils_WaitNanoSecs COM_BIT_LENGTH, 8, r22 ; 8 cycles used in the complete loop between waits
|
||||||
sec ; +1
|
sec ; +1
|
||||||
sbic COM_PIN_DATA, COM_PINNUM_DATA ; LOW: +2, HIGH: +1
|
sbic COM_PIN_DATA, COM_PINNUM_DATA ; LOW: +2, HIGH: +1
|
||||||
rjmp com2ReceiveByte_shiftIn ; HIGH: +2, rjmp, use set CFLAG
|
rjmp com2ReceiveByte_shiftIn ; HIGH: +2, rjmp, use set CFLAG
|
||||||
clc ; LOW: +1
|
clc ; LOW: +1
|
||||||
com2ReceiveByte_shiftIn:
|
com2ReceiveByte_shiftIn:
|
||||||
ror r20 ; +1
|
ror r20 ; +1
|
||||||
dec r21 ; +1
|
dec r21 ; +1
|
||||||
brne com2ReceiveByte_loop ; +2, sum per loop: 8 cycles
|
brne com2ReceiveByte_loop ; +2, sum per loop: 8 cycles
|
||||||
rcall com2WaitForDataHigh ; wait for start of stopbit
|
rcall com2WaitForDataHigh ; wait for start of stopbit
|
||||||
brcc com2ReceiveByte_error
|
brcc com2ReceiveByte_error
|
||||||
mov r16, r20
|
mov r16, r20
|
||||||
sec
|
sec
|
||||||
@@ -112,23 +112,11 @@ com2ReceiveByte_error:
|
|||||||
; IN:
|
; IN:
|
||||||
; OUT:
|
; OUT:
|
||||||
; - CFLAG: set if okay, clear otherwise
|
; - CFLAG: set if okay, clear otherwise
|
||||||
; MODIFIED REGISTERS: r17, r22
|
; MODIFIED REGISTERS: r16 (r17, r22)
|
||||||
|
|
||||||
com2WaitForDataLow:
|
com2WaitForDataLow:
|
||||||
ldi r17, COM2_MAXWAIT_US
|
clr r16
|
||||||
|
rjmp com2WaitForDataState1ms
|
||||||
com2WaitForDataLow_loop:
|
|
||||||
sbis COM_PIN_DATA, COM_PINNUM_DATA
|
|
||||||
rjmp com2WaitForDataLow_done
|
|
||||||
rcall com2WaitFor1000ns
|
|
||||||
dec r17
|
|
||||||
brne com2WaitForDataLow_loop
|
|
||||||
clc ; timeout
|
|
||||||
ret
|
|
||||||
|
|
||||||
com2WaitForDataLow_done:
|
|
||||||
sec ; ok
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -139,23 +127,11 @@ com2WaitForDataLow_done:
|
|||||||
; IN:
|
; IN:
|
||||||
; OUT:
|
; OUT:
|
||||||
; - CFLAG: set if okay, clear otherwise
|
; - CFLAG: set if okay, clear otherwise
|
||||||
; MODIFIED REGISTERS: r17, r22, X
|
; MODIFIED REGISTERS: r16 (r17, r22)
|
||||||
|
|
||||||
com2WaitForDataHigh:
|
com2WaitForDataHigh:
|
||||||
ldi r17, COM2_MAXWAIT_US
|
ldi r16, 0xff
|
||||||
|
rjmp com2WaitForDataState1ms
|
||||||
com2WaitForDataHigh_loop:
|
|
||||||
sbic COM_PIN_DATA, COM_PINNUM_DATA
|
|
||||||
rjmp com2WaitForDataHigh_done
|
|
||||||
rcall com2WaitFor1000ns
|
|
||||||
dec r17
|
|
||||||
brne com2WaitForDataHigh_loop
|
|
||||||
clc ; timeout
|
|
||||||
ret
|
|
||||||
|
|
||||||
com2WaitForDataHigh_done:
|
|
||||||
sec ; ok
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -166,23 +142,11 @@ com2WaitForDataHigh_done:
|
|||||||
; IN:
|
; IN:
|
||||||
; OUT:
|
; OUT:
|
||||||
; - CFLAG: set if okay, clear otherwise
|
; - CFLAG: set if okay, clear otherwise
|
||||||
; MODIFIED REGISTERS: r17, r22, X
|
; REGS: r16 (r17, r22)
|
||||||
|
|
||||||
com2WaitForAttnHigh:
|
com2WaitForAttnHigh:
|
||||||
ldi r17, COM2_MAXWAIT_US
|
ldi r16, 0xff
|
||||||
|
rjmp com2WaitForAttnState1ms
|
||||||
com2WaitForAttnHigh_loop:
|
|
||||||
sbic COM_PIN_ATTN, COM_PINNUM_ATTN
|
|
||||||
rjmp com2WaitForAttnHigh_done
|
|
||||||
rcall com2WaitFor1000ns
|
|
||||||
dec r17
|
|
||||||
brne com2WaitForAttnHigh_loop
|
|
||||||
clc ; timeout
|
|
||||||
ret
|
|
||||||
|
|
||||||
com2WaitForAttnHigh_done:
|
|
||||||
sec ; ok
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -215,18 +179,30 @@ com2WaitForDataState1ms_stateReached:
|
|||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; comWaitFor1000ns
|
; com2WaitForAttnState1ms
|
||||||
;
|
;
|
||||||
; Waits for 1000 nanoseconds.
|
; Waits up to 100ms for high DATA line
|
||||||
; IN:
|
; IN:
|
||||||
|
; - R16: state to wait for (00 for low, 0xff for high)
|
||||||
; OUT:
|
; OUT:
|
||||||
; - CFLAG: set if okay, clear otherwise
|
; - CFLAG: set if state reached, cleared otherwise
|
||||||
; REGS: r22
|
; REGS: R17, R22
|
||||||
|
|
||||||
com2WaitFor1000ns:
|
|
||||||
Utils_WaitNanoSecs 1000, 7, r22 ; wait for 1000 nanosecs (minus 3 cycles for rcall, 4 for ret)
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
com2WaitForAttnState1ms:
|
||||||
|
ldi r17, 100
|
||||||
|
com2WaitForAttnState1ms_loop:
|
||||||
|
in r22, COM_PIN_ATTN
|
||||||
|
eor r22, r16
|
||||||
|
andi r22, (1<<COM_PINNUM_ATTN)
|
||||||
|
breq com2WaitForAttnState1ms_stateReached
|
||||||
|
Utils_WaitNanoSecs 10000, 0, r22 ; wait for 10us
|
||||||
|
dec r17
|
||||||
|
brne com2WaitForAttnState1ms_loop
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
com2WaitForAttnState1ms_stateReached:
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user