From 5b3c813981c62a6038b12dba7a5115bb30a3e33e Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 18 Sep 2024 00:12:56 +0200 Subject: [PATCH] avr: beautifications. --- avr/modules/com2/lowlevel.asm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/avr/modules/com2/lowlevel.asm b/avr/modules/com2/lowlevel.asm index 14a1522..cfe44e2 100644 --- a/avr/modules/com2/lowlevel.asm +++ b/avr/modules/com2/lowlevel.asm @@ -27,32 +27,32 @@ ; MODIFIED REGS: R16, R21, R22 com2SendByte: - ldi r21, 8 ; +1 bits left + ldi r21, 8 ; +1 bits left ; 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 + 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 ; send data bits 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 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 rjmp com2SendByte_loopEnd ; +2 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 - sbis COM_PIN_DATA, COM_PINNUM_DATA ; +1 if no skip, +2 if skipped + 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 + 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 com2SendByte_loopEnd: - dec r21 ; +1 + 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 + 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 rjmp com2LowLevelSecRet com2SendByte_error: