avr: adapted to latest changes in COM2 module (using uartBitbang)

This commit is contained in:
Martin Preuss
2024-10-25 00:15:24 +02:00
parent e232b4adbf
commit 3546c93d23
20 changed files with 174 additions and 66 deletions

View File

@@ -72,12 +72,11 @@ bootLoader:
; rcall watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot)
; setup pins and interrupts
cbi COM_PORT_DATA, COM_PINNUM_DATA ; disable internal pullup for DATA
cbi COM_DDR_DATA, COM_PINNUM_DATA ; set DATA port as input
cbi COM_PORT_ATTN, COM_PINNUM_ATTN ; disable internal pullup for ATTN
cbi COM_DDR_ATTN, COM_PINNUM_ATTN ; set ATTN port as input
cbi COM_TXD_DATA, COM_TXD_PIN ; disable internal pullup for DATA
cbi COM_TXD_DDR, COM_TXD_PIN ; set DATA port as input
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable internal pullup for ATTN
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN port as input
sbi LED_DDR, LED_PINNUM ; out
cbi LED_PORT, LED_PINNUM ; on

View File

@@ -80,7 +80,7 @@ flashWaitForSpecificMessage_isLow: ; is low, receive message, check for
ldi r17, FLASH_RECVBUFFER_MAXLEN-3
ldi xl, LOW(flashRecvBuffer)
ldi xh, HIGH(flashRecvBuffer)
rcall com2ReceivePacketRaw
rcall uartBitbang_ReceivePacketIntoBuffer
pop r17
brcc flashWaitForSpecificMessage_waitAttnHigh
ldi xl, LOW(flashRecvBuffer)
@@ -125,9 +125,9 @@ flashWaitForAttnState1ms:
ldi r24, 100
flashWaitForAttnState1ms_loop:
push r17
in r17, COM_PIN_ATTN
in r17, COM_ATTN_INPUT
eor r17, r16
andi r17, (1<<COM_PINNUM_ATTN)
andi r17, (1<<COM_ATTN_PIN)
pop r17
breq flashWaitForAttnState1ms_stateReached
rcall Utils_WaitFor10MicroSecs ; wait for 10us (R22)

View File

@@ -29,7 +29,7 @@
flashSendPacketUntilSuccess:
push xl
push xh
rcall COM2_SendPacketWithAttn ; (R16, R17, R21, R22, X)
rcall uartBitbang_SendPacket ; (R16, R17, R21, R22, X)
pop xh
pop xl
brcc flashSendPacket_error
@@ -50,7 +50,7 @@ flashSendPacket_error:
; REGS: (R16, R17, R18, R22, R24, R25)
flashWaitForAttnHigh:
rcall com2WaitForAttnHigh ; (r17, r22)
rcall uartBitbang_WaitForAttnHigh ; (r17, r22)
brcc flashWaitForAttnHigh_stillLow
ret
flashWaitForAttnHigh_stillLow:

View File

@@ -0,0 +1,61 @@
; ***************************************************************************
; copyright : (C) 2024 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. *
; ***************************************************************************
; - check motion
; - motion detected?
; - yes:
; - set motion HW bit
; - reset motion timeout counter
; - SW bit set?
; - no:
; - report motion
; - reset motionReportTimeout (use lower value to repeat motion message once)
; - set motion SW bit
; - yes
; - dec motionReportTimeout
; - 0?
; - report current SW state
; - reset motionReportTimeout (use higher value since motion should already be known)
; - no:
; - clear motion hw bit
; - dec motionTimeout
; - 0?
; - yes:
; - clear SW motion bit
; - report no motion
.equ MOTION_STATE_MOTION_HW_BIT = 0
.equ MOTION_STATE_MOTION_SW_BIT = 1
.dseg
motionDataBegin:
motionState: .byte 1
motionTimeout: .byte 1
motionReportTimeout: .byte 1
motionDataEnd:
.cseg
Motion_Init:
Motion_Fini:
Motion_Run:
Motion_Every100ms:
ret

View File

@@ -184,5 +184,19 @@ uartBitbang_WaitForDataHigh:
; ---------------------------------------------------------------------------
; @routine uartBitbang_WaitForAttnHigh
;
; Wait up to 1ms for data pin to become high
; @return CFLAG set if okay, clear otherwise
; @clobbers R17, R22
uartBitbang_WaitForAttnHigh:
UART_BB_M_WAIT_FOR_PIN_HIGH COM_ATTN_INPUT, COM_ATTN_PIN
ret
; @end