avr: consolidated uart_hw module
This commit is contained in:
@@ -30,10 +30,10 @@ comOnUart0_iface: .byte UART_HW_IFACE_SIZE
|
||||
ComOnUart0_Init:
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
rcall UART_HW_Uart0_SetAttnInput ; (none)
|
||||
rcall comOnUart0SetAttnInput ; (none)
|
||||
|
||||
rcall UART_HW_Interface_Init ; (R16, R17, X)
|
||||
rcall UART_HW_Uart0_Init ; (R16, R17, X)
|
||||
rcall comOnUart0Init ; (R16, R17, X)
|
||||
ldi r16, COMONUART0_IFACENUM
|
||||
std Y+NET_IFACE_OFFS_IFACENUM, r16
|
||||
|
||||
@@ -92,7 +92,7 @@ ComOnUart0_RxCharIsr:
|
||||
push yh
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
rcall UART_HW_Uart0_RxCharIsr ; (R16, R17, R18, R24, R25, X)
|
||||
rcall comOnUart0RxCharIsr ; (R16, R17, R18, R24, R25, X)
|
||||
pop yh
|
||||
pop yl
|
||||
pop xh
|
||||
@@ -125,7 +125,7 @@ ComOnUart0_TxUdreIsr:
|
||||
push yh
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
rcall UART_HW_Uart0_TxUdreIsr ; (R16, R17, X)
|
||||
rcall comOnUart0TxUdreIsr ; (R16, R17, X)
|
||||
pop yh
|
||||
pop yl
|
||||
pop xh
|
||||
@@ -156,7 +156,7 @@ ComOnUart0_TxCharIsr:
|
||||
push yh
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
rcall UART_HW_Uart0_TxCharIsr ; (R16, R17, R18, X)
|
||||
rcall comOnUart0TxCharIsr ; (R16, R17, R18, X)
|
||||
pop yh
|
||||
pop yl
|
||||
pop xh
|
||||
@@ -249,34 +249,34 @@ comOnUart0EnterReading_okay:
|
||||
std Y+UART_HW_IFACE_OFFS_READMODE, r16
|
||||
clr r16
|
||||
std Y+NET_IFACE_OFFS_READTIMER, r16
|
||||
rcall UART_HW_Uart0_StartRx ; R16
|
||||
rcall comOnUart0StartRx ; R16
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ComOnUart0_SendBuffer @global
|
||||
; @routine comOnUart0SendBuffer @global
|
||||
;
|
||||
; @param Y pointer to interface data in SRAM
|
||||
; @clobbers R16, R17
|
||||
|
||||
ComOnUart0_SendBuffer:
|
||||
comOnUart0SendBuffer:
|
||||
push r15
|
||||
in r15, SREG
|
||||
cli
|
||||
ldd r17, Y+UART_HW_IFACE_OFFS_WRITEMODE
|
||||
cpi r17, UART_HW_WRITEMODE_IDLE
|
||||
breq ComOnUart0_SendBuffer_setBuffer
|
||||
breq comOnUart0SendBuffer_setBuffer
|
||||
out SREG, r15
|
||||
pop r15
|
||||
clc
|
||||
ret
|
||||
ComOnUart0_SendBuffer_setBuffer:
|
||||
comOnUart0SendBuffer_setBuffer:
|
||||
rcall UART_HW_Interface_SetWriteBuffer ; (R17)
|
||||
ldi r17, UART_HW_WRITEMODE_WRITING
|
||||
std Y+UART_HW_IFACE_OFFS_WRITEMODE, r17
|
||||
rcall UART_HW_Uart0_StartTx ; (R16)
|
||||
rcall comOnUart0StartTx ; (R16)
|
||||
pop r15
|
||||
out SREG, r15
|
||||
sec
|
||||
@@ -363,12 +363,12 @@ comOnUart0RunWriteIdle:
|
||||
sbis COM_ATTN_INPUT, COM_ATTN_PIN ; ATTN low?
|
||||
rjmp comOnUart0RunWriteIdle_end ; yes, line busy, jmp
|
||||
|
||||
rcall UART_HW_Uart0_SetAttnLow ; reserve bus as soon as possible
|
||||
rcall comOnUart0SetAttnLow ; reserve bus as soon as possible
|
||||
Utils_WaitNanoSecs COM_BIT_LENGTH, 0, r22 ; wait for one bit duration
|
||||
Utils_WaitNanoSecs COM_BIT_LENGTH, 0, r22 ; wait for one bit duration
|
||||
|
||||
rcall NET_Buffer_Locate ; (R17)
|
||||
rcall ComOnUart0_SendBuffer ; (R16, R17)
|
||||
rcall comOnUart0SendBuffer ; (R16, R17)
|
||||
rcall NET_Interface_GetNextOutgoingMsgNum ; take msg from queue (R17, R18, X)
|
||||
comOnUart0RunWriteIdle_end:
|
||||
ret
|
||||
@@ -411,9 +411,9 @@ comOnUart0RunWriteBufferEmpty:
|
||||
std Y+UART_HW_IFACE_OFFS_WRITEBUFNUM, r17
|
||||
rcall NET_Buffer_ReleaseByNum ; (R16, X)
|
||||
comOnUart0RunWriteBufferEmpty_setIdle:
|
||||
rcall UART_HW_Uart0_StopTx ; disable transceiver and interrupts (R16)
|
||||
rcall comOnUart0StopTx ; disable transceiver and interrupts (R16)
|
||||
|
||||
rcall UART_HW_Uart0_SetAttnInput ; set ATTN as input
|
||||
rcall comOnUart0SetAttnInput ; set ATTN as input
|
||||
|
||||
ldi r16, UART_HW_WRITEMODE_IDLE
|
||||
std Y+UART_HW_IFACE_OFFS_WRITEMODE, r16
|
||||
@@ -466,7 +466,7 @@ comOnUart0RunReading:
|
||||
ldd r16, Y+NET_IFACE_OFFS_READTIMER
|
||||
cpi r16, COMONUART0_READ_TIMEOUT
|
||||
brcs comOnUart0RunReading_end
|
||||
rcall UART_HW_Uart0_StopRx ; (R16)
|
||||
rcall comOnUart0StopRx ; (R16)
|
||||
ldd r16, Y+UART_HW_IFACE_OFFS_READBUFNUM
|
||||
ldi r17, 0xff
|
||||
std Y+UART_HW_IFACE_OFFS_READBUFNUM, r17
|
||||
@@ -517,14 +517,150 @@ comOnUart0RunMsgReceived:
|
||||
|
||||
|
||||
|
||||
; DEBUG begin
|
||||
ldi r16, NET_IFACE_OFFS_HANDLED_LOW
|
||||
rcall NET_Interface_IncCounter16 ; (R24, R25)
|
||||
; DEBUG end
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine comOnUart0Init @global
|
||||
;
|
||||
; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_STATE)
|
||||
; @clobbers R16, R17, X
|
||||
|
||||
comOnUart0Init:
|
||||
.ifdef COM_ATTN_PUE
|
||||
lds r16, COM_ATTN_PUE
|
||||
cbr r16, COM_ATTN_PIN ; disable pullup on ATTN
|
||||
sts COM_ATTN_PUE, r16
|
||||
.endif
|
||||
rcall comOnUart0SetAttnInput
|
||||
M_UART_HW_Uart_Init 0
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine comOnUart0StartRx @global
|
||||
;
|
||||
; @clobbers R16
|
||||
|
||||
comOnUart0StartRx:
|
||||
M_UART_HW_Uart_StartRx 0
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine comOnUart0StopRx @global
|
||||
;
|
||||
; @clobbers R16
|
||||
|
||||
comOnUart0StopRx:
|
||||
M_UART_HW_Uart_StopRx 0
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine comOnUart0StartTx @global
|
||||
;
|
||||
; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_STATE)
|
||||
; @clobbers R16
|
||||
|
||||
comOnUart0StartTx:
|
||||
M_UART_HW_Uart_StartTx 0
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine comOnUart0StopTx @global
|
||||
;
|
||||
; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_STATE)
|
||||
; @clobbers R16
|
||||
|
||||
comOnUart0StopTx:
|
||||
M_UART_HW_Uart_StopTx 0
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine comOnUart0RxCharIsr @global
|
||||
;
|
||||
; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_MODE)
|
||||
; @clobbers R16 (R17, R18, R24, R25, X)
|
||||
|
||||
comOnUart0RxCharIsr:
|
||||
M_UART_HW_Uart_RxCharHalfDuplexIsr 0
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine comOnUart0TxUdreIsr @global
|
||||
;
|
||||
; Handler for UDRE1 interrupt called when TX data register is empty.
|
||||
;
|
||||
; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_MODE)
|
||||
; @clobbers R16, R17, X
|
||||
|
||||
comOnUart0TxUdreIsr:
|
||||
M_UART_HW_Uart_TxUdreIsr 0
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine comOnUart0TxCharIsr @global
|
||||
;
|
||||
; Handler for TXC1 interrupt called when a last byte has been completely sent and
|
||||
; the data register is empty.
|
||||
;
|
||||
; @param Y pointer to interface data in SRAM (see @ref UART_HW_IFACE_OFFS_MODE)
|
||||
; @clobbers R16
|
||||
|
||||
comOnUart0TxCharIsr:
|
||||
M_UART_HW_Uart_TxCharIsr 0
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine comOnUart0SetAttnInput @global
|
||||
;
|
||||
; Set ATTN line as input (making it effectively HIGH due to pull-up resistor on
|
||||
; the line)
|
||||
;
|
||||
; @clobbers none
|
||||
|
||||
comOnUart0SetAttnInput:
|
||||
cbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN as input
|
||||
.ifdef COM_ATTN_PUE
|
||||
; cbi COM_ATTN_PUE, COM_ATTN_PIN ; disable pullup on ATTN
|
||||
.else
|
||||
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; disable pullup on ATTN
|
||||
.endif
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine comOnUart0SetAttnLow @global
|
||||
;
|
||||
; Set ATTN line low.
|
||||
;
|
||||
; @clobbers none
|
||||
|
||||
comOnUart0SetAttnLow:
|
||||
sbi COM_ATTN_DDR, COM_ATTN_PIN ; set ATTN as output
|
||||
cbi COM_ATTN_OUTPUT, COM_ATTN_PIN ; set ATTN low
|
||||
ret
|
||||
; @end
|
||||
|
||||
; DEBUG begin
|
||||
ldi r16, NET_IFACE_OFFS_ERR_MISSED_LOW
|
||||
rcall NET_Interface_IncCounter16 ; (R24, R25)
|
||||
; DEBUG end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user