avr: improved protocol timing for COM2.
- increased waiting time after lowering ATTN line - lengthten stop bit for cleaner frames (now recognized by PulseView) - count "NOTFORME" conditions - introduce definition COM_HALFBIT_LENGTH (I dont' trust value calculations in avrasm)
This commit is contained in:
@@ -31,7 +31,7 @@ com2SendByte:
|
||||
; send startbit
|
||||
cbi COM_PORT_DATA, COM_PINNUM_DATA ; +2 set DATA low
|
||||
sbi COM_DDR_DATA, COM_PINNUM_DATA ; +2 set DATA as output
|
||||
Utils_WaitNanoSecs COM_BIT_LENGTH, 5, r22 ; wait for one bit duration
|
||||
Utils_WaitNanoSecs COM_BIT_LENGTH, 1, r22 ; wait for one bit duration
|
||||
; send data bits
|
||||
com2SendByte_loop: ; 9 for low bit
|
||||
lsr r16 ; 1+ bit to send -> CARRY
|
||||
@@ -43,16 +43,16 @@ com2SendByte_setLow:
|
||||
com2SendByte_setHigh:
|
||||
cbi COM_DDR_DATA, COM_PINNUM_DATA ; +2 set DATA as input, pullup R makes it ONE
|
||||
nop ; +1 (to make pin change available)
|
||||
Utils_WaitNanoSecs COM_BIT_LENGTH/2, 11, r22 ; wait for half a bit length for line to safely settle
|
||||
Utils_WaitNanoSecs COM_HALFBIT_LENGTH, 0, r22 ; wait for half a bit length for line to safely settle
|
||||
sbis COM_PIN_DATA, COM_PINNUM_DATA ; +1 if no skip, +2 if skipped
|
||||
rjmp com2SendByte_error ; +2 if error (collision: we wanted line to be high but it is low)
|
||||
Utils_WaitNanoSecs COM_BIT_LENGTH/2, 0, r22
|
||||
Utils_WaitNanoSecs COM_HALFBIT_LENGTH, 11, r22
|
||||
com2SendByte_loopEnd:
|
||||
dec r21 ; +1
|
||||
brne com2SendByte_loop ; +2, sum per loop: 10 cycles
|
||||
; send stopbit
|
||||
cbi COM_DDR_DATA, COM_PINNUM_DATA ; +2 set DATA as input, pullup R makes it ONE
|
||||
Utils_WaitNanoSecs COM_BIT_LENGTH, 4, r22 ; wait for one bit length
|
||||
Utils_WaitNanoSecs COM_BIT_LENGTH, 0, r22 ; wait for one bit length
|
||||
rjmp com2LowLevelSecRet
|
||||
|
||||
com2SendByte_error:
|
||||
@@ -81,7 +81,7 @@ com2ReceiveByte:
|
||||
; wait for startbit
|
||||
rcall com2WaitForDataLow ; (R16, R17, R22)
|
||||
brcc com2ReceiveByte_error
|
||||
Utils_WaitNanoSecs COM_BIT_LENGTH/2, 5, r22 ; goto middle of startbit to maximize sync stability
|
||||
Utils_WaitNanoSecs COM_HALFBIT_LENGTH, 10, r22 ; goto middle of startbit to maximize sync stability
|
||||
com2ReceiveByte_loop:
|
||||
Utils_WaitNanoSecs COM_BIT_LENGTH, 8, r22 ; 8 cycles used in the complete loop between waits
|
||||
sec ; +1
|
||||
@@ -149,7 +149,7 @@ com2WaitForAttnHigh:
|
||||
; ---------------------------------------------------------------------------
|
||||
; com2WaitForDataState1ms
|
||||
;
|
||||
; Waits up to 1ms for high DATA line
|
||||
; Waits up to 500us for high DATA line
|
||||
; IN:
|
||||
; - R16: state to wait for (00 for low, 0xff for high)
|
||||
; OUT:
|
||||
@@ -163,12 +163,14 @@ com2WaitForDataState1ms_loop:
|
||||
eor r22, r16
|
||||
andi r22, (1<<COM_PINNUM_DATA)
|
||||
breq com2WaitForDataState1ms_stateReached
|
||||
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
|
||||
; rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
|
||||
Utils_WaitNanoSecs 5000, 0, r22
|
||||
dec r17
|
||||
brne com2WaitForDataState1ms_loop
|
||||
rjmp com2LowLevelClcRet
|
||||
com2WaitForDataState1ms_stateReached:
|
||||
rjmp com2LowLevelSecRet
|
||||
sec
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user