avr: beautifications.

This commit is contained in:
Martin Preuss
2024-09-18 00:12:56 +02:00
parent b490646799
commit 5b3c813981

View File

@@ -27,32 +27,32 @@
; MODIFIED REGS: R16, R21, R22 ; MODIFIED REGS: R16, R21, R22
com2SendByte: com2SendByte:
ldi r21, 8 ; +1 bits left ldi r21, 8 ; +1 bits left
; send startbit ; send startbit
cbi COM_PORT_DATA, COM_PINNUM_DATA ; +2 set DATA low cbi COM_PORT_DATA, COM_PINNUM_DATA ; +2 set DATA low
sbi COM_DDR_DATA, COM_PINNUM_DATA ; +2 set DATA as output 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, 5, r22 ; wait for one bit duration
; send data bits ; send data bits
com2SendByte_loop: ; 9 for low bit com2SendByte_loop: ; 9 for low bit
lsr r16 ; 1+ bit to send -> CARRY lsr r16 ; 1+ bit to send -> CARRY
brcs com2SendByte_setHigh ; HI: +2, LO: +1 brcs com2SendByte_setHigh ; HI: +2, LO: +1
com2SendByte_setLow: com2SendByte_setLow:
sbi COM_DDR_DATA, COM_PINNUM_DATA ; +2 set DATA as output sbi COM_DDR_DATA, COM_PINNUM_DATA ; +2 set DATA as output
Utils_WaitNanoSecs COM_BIT_LENGTH, 9, r22 Utils_WaitNanoSecs COM_BIT_LENGTH, 9, r22
rjmp com2SendByte_loopEnd ; +2 rjmp com2SendByte_loopEnd ; +2
com2SendByte_setHigh: com2SendByte_setHigh:
cbi COM_DDR_DATA, COM_PINNUM_DATA ; +2 set DATA as input, pullup R makes it ONE cbi COM_DDR_DATA, COM_PINNUM_DATA ; +2 set DATA as input, pullup R makes it ONE
nop ; +1 (to make pin change available) 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_BIT_LENGTH/2, 11, 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 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) 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_BIT_LENGTH/2, 0, r22
com2SendByte_loopEnd: com2SendByte_loopEnd:
dec r21 ; +1 dec r21 ; +1
brne com2SendByte_loop ; +2, sum per loop: 10 cycles brne com2SendByte_loop ; +2, sum per loop: 10 cycles
; send stopbit ; send stopbit
cbi COM_DDR_DATA, COM_PINNUM_DATA ; +2 set DATA as input, pullup R makes it ONE 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, 4, r22 ; wait for one bit length
rjmp com2LowLevelSecRet rjmp com2LowLevelSecRet
com2SendByte_error: com2SendByte_error: