diff --git a/avr/modules/flash/io_uart_attn_small.asm b/avr/modules/flash/io_uart_attn_small.asm new file mode 100644 index 0000000..a7b0efa --- /dev/null +++ b/avr/modules/flash/io_uart_attn_small.asm @@ -0,0 +1,592 @@ +; *************************************************************************** +; copyright : (C) 2025 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. * +; *************************************************************************** + + +; *************************************************************************** +; code + + +.cseg + + +; --------------------------------------------------------------------------- +; @routine ioRawInit +; Send a message +; +; @clobbers r16, r17 + +ioRawInit: + ; set baudrate +.if clock == 8000000 + ldi r16, 25 ; (19.2Kb/s at 8MHz) + ldi r17, 0 +.endif + +.if clock == 1000000 + ldi r16, 3 ; (19.2Kb/s at 1MHz) + ldi r17, 0 +.endif + + outr UART_REG_UBRRH, r17 + outr UART_REG_UBRRL, r16 + + ; set character format (asynchronous USART, 8-bit, one stop bit, no parity) +.ifdef URSEL + ldi r16, (1< 7 per loop, max about 1000 + clc ; 1 + ret ; 4 +ioRawWaitForData_gotit: + sec ; 1 + ret ; 4 +; @end + + + +; --------------------------------------------------------------------------- +; @routine ioRawWaitForAttnSeconds +; +; Wait for ATTN state max given seconds +; +; @return CFLAG set if okay (data available), cleared on error +; @param R16 expected state (0xff for high, 0 for low) +; @param r20 maximum number of seconds to wait +; @clobbers: r20, r22 + +ioRawWaitForAttnSeconds: +ioRawWaitForAttnSeconds_loop: + push r20 + rcall ioRawWaitForAttn1s ; (r20, r22) + pop r20 + brcs ioRawWaitForAttnSeconds_gotit + sbi LED_PIN, LED_PINNUM ; toggle (doen't work on AtMega8515) + dec r20 + brne ioRawWaitForAttnSeconds_loop + clc +ioRawWaitForAttnSeconds_gotit: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ioRawWaitForAttn1s +; +; Wait for ATTN state for max 1s +; +; @param R16 expected state (0xff for high, 0 for low) +; @return CFLAG set if okay (ATTN state reached), cleared on error +; @clobbers: r20, r22 + +ioRawWaitForAttn1s: + ldi r20, 100 +ioRawWaitForAttn1s_loop: + push r20 + rcall ioRawWaitForAttn10ms ; (R20, R22) + pop r20 + brcs ioRawWaitForAttn1s_gotit + dec r20 + brne ioRawWaitForAttn1s_loop + clc +ioRawWaitForAttn1s_gotit: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ioRawWaitForAttn10ms +; +; Wait for ATTN state for max 10 milliseconds. +; +; @param R16 expected state (0xff for high, 0 for low) +; @return CFLAG set if okay (ATTN state reached), cleared on error +; @clobbers: r20, r22 + +ioRawWaitForAttn10ms: +.if clock == 8000000 + ldi r20, 80 +.endif +.if clock == 1000000 + ldi r20, 10 +.endif +ioRawWaitForAttn10ms_loop: + push r20 + rcall ioRawWaitForAttn1000Cycles ; (r20, r22) + pop r20 + brcs ioRawWaitForAttn10ms_gotit + dec r20 + brne ioRawWaitForAttn10ms_loop + clc +ioRawWaitForAttn10ms_gotit: + ret +; @end + + + +; --------------------------------------------------------------------------- +; @routine ioRawWaitForAttnState1000Cycles +; +; Wait for ATTN state for max 1000 clock cycles +; (about 1ms at 1MHz, 0.125ms at 8MHz) +; +; @param R16 expected state (0xff for high, 0 for low) +; @return CFLAG set if okay (packet received), cleared on error +; @clobbers: r20, r22 + +ioRawWaitForAttn1000Cycles: + ldi r20, 90 ; 1 +ioRawWaitForAttn1000Cycles_loop: + push r17 ; +2 + in r17, COM_ATTN_INPUT ; +1 + eor r17, r16 ; +1 + andi r17, (1<