avr: removed unneeded code.

This commit is contained in:
Martin Preuss
2024-10-20 23:09:38 +02:00
parent efc91241d9
commit 89019f1e60
2 changed files with 0 additions and 375 deletions

View File

@@ -1,212 +0,0 @@
; ***************************************************************************
; copyright : (C) 2023 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; ---------------------------------------------------------------------------
; com2SendByte
;
; Send a byte.
; We only set the data pin to low at the beginning for the startbit. After that
; we only change the pin direction (e.g. input vs output):
; - for 0 bit: set DDR to output, forcing the data line low
; - for 1 bit: set DDR to input, letting the external pullup R pull the data line to HIGH
; since the output pin is still set to 0 the internal pullup is disabled
; IN:
; - R16: byte to send
; OUT:
; - CFLAG: set if okay, clear otherwise
; MODIFIED REGS: R16, R21, R22
com2SendByte:
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, 1, r22 ; wait for one bit duration
; send data bits
com2SendByte_loop: ; 9 for low bit
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
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_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_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, 0, r22 ; wait for one bit length
rjmp com2LowLevelSecRet
com2SendByte_error:
rjmp com2LowLevelClcRet
; ---------------------------------------------------------------------------
; com2ReceiveByte
;
; Receive a byte.
;
; IN:
; - nothing
; OUT:
; - CFLAG: set if okay, clear otherwise
; - R16: byte read (if CFLAG set)
; MODIFIED REGS: R16, R20, R21, R22 (R17)
com2ReceiveByte:
cbi COM_DDR_DATA, COM_PINNUM_DATA ; set DATA port as input
cbi COM_PORT_DATA, COM_PINNUM_DATA ; disable internal pullup for DATA
ldi r21, 8 ; bits left
clr r20 ; byte currently receiving
; wait for startbit
rcall com2WaitForDataLow ; (R16, R17, R22)
brcc com2ReceiveByte_error
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
sbic COM_PIN_DATA, COM_PINNUM_DATA ; LOW: +2, HIGH: +1
rjmp com2ReceiveByte_shiftIn ; HIGH: +2, rjmp, use set CFLAG
clc ; LOW: +1
com2ReceiveByte_shiftIn:
ror r20 ; +1
dec r21 ; +1
brne com2ReceiveByte_loop ; +2, sum per loop: 8 cycles
rcall com2WaitForDataHigh ; wait for start of stopbit
brcc com2ReceiveByte_error
mov r16, r20
rjmp com2LowLevelSecRet
com2ReceiveByte_error:
rjmp com2LowLevelClcRet
; ---------------------------------------------------------------------------
; com2WaitForDataLow
;
; Waits up to 1ms for low data line
; IN:
; OUT:
; - CFLAG: set if okay, clear otherwise
; MODIFIED REGISTERS: r16 (r17, r22)
com2WaitForDataLow:
clr r16
rjmp com2WaitForDataState1ms
; ---------------------------------------------------------------------------
; com2WaitForDataHigh
;
; Waits up to 1ms for high data line
; IN:
; OUT:
; - CFLAG: set if okay, clear otherwise
; MODIFIED REGISTERS: r16 (r17, r22)
com2WaitForDataHigh:
ldi r16, 0xff
rjmp com2WaitForDataState1ms
; ---------------------------------------------------------------------------
; com2WaitForAttnHigh
;
; Waits up to 1ms for high ATTN line
; IN:
; OUT:
; - CFLAG: set if okay, clear otherwise
; REGS: r16 (r17, r22)
com2WaitForAttnHigh:
ldi r16, 0xff
rjmp com2WaitForAttnState1ms
; ---------------------------------------------------------------------------
; com2WaitForDataState1ms
;
; Waits up to 500us for high DATA line
; IN:
; - R16: state to wait for (00 for low, 0xff for high)
; OUT:
; - CFLAG: set if state reached, cleared otherwise
; REGS: R17, R22
com2WaitForDataState1ms:
ldi r17, 100
com2WaitForDataState1ms_loop:
in r22, COM_PIN_DATA
eor r22, r16
andi r22, (1<<COM_PINNUM_DATA)
breq com2WaitForDataState1ms_stateReached
; rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
Utils_WaitNanoSecs 5000, 0, r22
dec r17
brne com2WaitForDataState1ms_loop
rjmp com2LowLevelClcRet
com2WaitForDataState1ms_stateReached:
sec
ret
; ---------------------------------------------------------------------------
; com2WaitForAttnState1ms
;
; Waits up to 1ms for high DATA line
; IN:
; - R16: state to wait for (00 for low, 0xff for high)
; OUT:
; - CFLAG: set if state reached, cleared otherwise
; REGS: R17, R22
com2WaitForAttnState1ms:
ldi r17, 100
com2WaitForAttnState1ms_loop:
in r22, COM_PIN_ATTN
eor r22, r16
andi r22, (1<<COM_PINNUM_ATTN)
breq com2WaitForAttnState1ms_stateReached
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)
dec r17
brne com2WaitForAttnState1ms_loop
rjmp com2LowLevelClcRet
com2WaitForAttnState1ms_stateReached:
rjmp com2LowLevelSecRet
com2LowLevelClcRet:
clc
ret
com2LowLevelSecRet:
sec
ret

View File

@@ -1,163 +0,0 @@
; ***************************************************************************
; copyright : (C) 2023 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; ---------------------------------------------------------------------------
; receive packet into buffer pointed to by X.
;
; IN:
; - R16: COM address to listen to
; - R17: maximum value for accepted msg data (i.e. buffersize minus 3)
; - X : buffer to receive to
; OUT:
; - CFLAG: set if okay (packet received), cleared on error
; - R16: error code if CFLAG is cleared
; REGS: r16, r17, r18, X (r19, r20, r21, r22)
com2ReceivePacketRaw:
mov r18, r17
push r16
; read destination address
rcall com2ReceiveByte ; read byte (R16, R17, R20, R21, R22)
pop r17 ; pop from R16 to R17
brcc com2ReceivePacketRaw_ioError
; compare destination address (accept "FF" and own address)
cp r16, r17
breq com2ReceivePacketRaw_acceptAddr
cpi r16, 0xff
breq com2ReceivePacketRaw_acceptAddr
ldi r16, COM2_ERROR_NOTFORME
rjmp com2ReceivePacketRaw_error ; clc/ret
com2ReceivePacketRaw_acceptAddr:
st X+, r16 ; store dest address, lock buffer
; read msg length
rcall com2ReceiveByte ; read packet length (R16, R17, R20, R21, R22)
brcc com2ReceivePacketRaw_ioError
st X+, r16
cp r16, r18 ; (COM2_BUFFER_SIZE-3)
brcc com2ReceivePacketRaw_contentError ; packet too long
inc r16 ; account for checksum byte
mov r17, r16
com2ReceivePacketRaw_loop:
push r17
rcall com2ReceiveByte ; read byte (R16, R17, R20, R21, R22)
pop r17
brcc com2ReceivePacketRaw_ioError
st X+, r16
dec r17
brne com2ReceivePacketRaw_loop
rjmp com2PacketsSecRet
com2ReceivePacketRaw_ioError:
ldi r16, COM2_ERROR_IOERROR
rjmp com2PacketsClcRet
com2ReceivePacketRaw_contentError:
ldi r16, COM2_ERROR_DATAERROR
com2ReceivePacketRaw_error:
rjmp com2PacketsClcRet
; ---------------------------------------------------------------------------
; send packet over wire, handle ATTN line.
;
; IN:
; - x : ptr to buffer to send
; OUT:
; - CFLAGS: set if okay, cleared otherwise (errorcode in R16)
; REGS: R16, R22 (R17, R21, X)
COM2_SendPacketWithAttn:
push r15
in r15, SREG
cli
; check for ATTN line: busy?
cbi COM_PORT_ATTN, COM_PINNUM_ATTN ; disable pullup on ATTN
cbi COM_DDR_ATTN, COM_PINNUM_ATTN ; set ATTN as input
nop ; needed to sample current input
sbis COM_PIN_ATTN, COM_PINNUM_ATTN ; ATTN low?
rjmp COM2_SendPacketWithAttn_lineBusyError ; jump if it is
cbi COM_PORT_ATTN, COM_PINNUM_ATTN ; set ATTN low
sbi COM_DDR_ATTN, COM_PINNUM_ATTN ; set ATTN as output
rcall com2WaitForOneBitLength ; wait for one bit duration (R22)
rcall com2WaitForOneBitLength ; wait for another bit duration (R22)
adiw xh:xl, COM2_MSG_OFFS_MSGLEN
ld r16, X
sbiw xh:xl, COM2_MSG_OFFS_MSGLEN
inc r16 ; account for dest addr
inc r16 ; account for msglen byte
inc r16 ; account for crc byte
rcall com2SendPacketRaw ; (r16, r17, r21, r22, X)
cbi COM_DDR_ATTN, COM_PINNUM_ATTN ; release ATTN line (by setting direction to IN)
brcc COM2_SendPacketWithAttn_ioError
; packet successfully sent
out SREG, r15
pop r15
rjmp com2PacketsSecRet
COM2_SendPacketWithAttn_ioError:
ldi r16,COM2_ERROR_COLLISION
rjmp COM2_SendPacketWithAttn_retNc
COM2_SendPacketWithAttn_lineBusyError:
ldi r16,COM2_ERROR_BUSY
COM2_SendPacketWithAttn_retNc:
pop r15
out SREG, r15
rjmp com2PacketsClcRet
; ---------------------------------------------------------------------------
; wait for one bit length (minus cycles for call and ret).
;
; IN:
; - nothing
; OUT:
; - nothing
; REGS: r22
com2WaitForOneBitLength:
Utils_WaitNanoSecs COM_BIT_LENGTH, 7, r22 ; wait for one bit duration (minus RCALL/RET)
ret
; ---------------------------------------------------------------------------
; send packet over wire, expects ATTN to be low.
;
; IN:
; - r16: number of bytes to send
; - x : ptr to buffer to send
; OUT:
; - nothing
; REGS: r16, r17, x (r21, r22)
com2SendPacketRaw:
mov r17, r16
com2SendPacket_loop:
ld r16, X+
rcall com2SendByte ; send byte (R16, R21, R22)
brcc com2PacketsClcRet
dec r17
brne com2SendPacket_loop
sec
ret
com2PacketsClcRet:
clc
ret
com2PacketsSecRet:
sec
ret