avr/uart_hw, t03: cross messaging now works!!
This commit is contained in:
@@ -51,6 +51,8 @@
|
||||
; ---------------------------------------------------------------------------
|
||||
; COM module
|
||||
|
||||
.equ COM_BIT_LENGTH = 52000 ; 104000ns=9600, 52000ns=19200, 26000ns=38400
|
||||
|
||||
.equ COM_ATTN_DDR = DDRA
|
||||
.equ COM_ATTN_INPUT = PINA
|
||||
.equ COM_ATTN_OUTPUT = PORTA
|
||||
|
||||
@@ -212,7 +212,7 @@ onSystemTimerTick:
|
||||
; rcall maybeSendDeviceMsg
|
||||
rcall maybeSendTStatsMsg
|
||||
rcall maybeSendRStatsMsg
|
||||
; rcall maybeSendMStatsMsg
|
||||
rcall maybeSendMStatsMsg
|
||||
ret
|
||||
|
||||
|
||||
@@ -286,6 +286,7 @@ initModules:
|
||||
; includes
|
||||
|
||||
.include "common/utils.asm"
|
||||
.include "common/utils_wait.asm"
|
||||
.include "common/utils_wait_fixed.asm"
|
||||
.include "common/utils_copy_from_flash.asm"
|
||||
.include "common/utils_copy_sdram.asm"
|
||||
@@ -358,17 +359,9 @@ maybeSendTStatsMsg:
|
||||
lds r25, sendTStatsCounter+1
|
||||
sbiw r25:r24, 1
|
||||
brne maybeSendTStatsMsg_storeCounter
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
; brcc maybeSendTStatsMsg_resetCounter
|
||||
brcc maybeSendTStatsMsg_end
|
||||
push r16
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_SendStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
brcc maybeSendTStatsMsg_end
|
||||
|
||||
rcall sendTStatsForUart0ToUart1
|
||||
|
||||
; reset counter
|
||||
maybeSendTStatsMsg_resetCounter:
|
||||
ldi r24, LOW(SEND_STATS_EVERY)
|
||||
@@ -380,6 +373,28 @@ maybeSendTStatsMsg_end:
|
||||
ret
|
||||
|
||||
|
||||
sendTStatsForUart0ToUart1:
|
||||
push yl
|
||||
push yh
|
||||
; send device msg
|
||||
rcall NET_Buffer_Alloc ; (R16, R17, X)
|
||||
brcc sendTStatsForUart0ToUart1_end
|
||||
push r16
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_SendStats_Write ; (R16, R17, R18, R19, R20, R21, Z)
|
||||
sbiw xh:xl, 1
|
||||
pop r16
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
rcall NET_Interface_AddOrReleaseOutMsg ; (R16, R17, R18, X)
|
||||
sendTStatsForUart0ToUart1_end:
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
|
||||
|
||||
|
||||
maybeSendRStatsMsg:
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
@@ -391,7 +406,7 @@ maybeSendRStatsMsg:
|
||||
brne maybeSendRStatsMsg_storeCounter
|
||||
|
||||
rcall sendRStatsForUart0ToUart1
|
||||
rcall sendRStatsForUart1ToUart1
|
||||
; rcall sendRStatsForUart1ToUart1
|
||||
|
||||
; reset counter
|
||||
maybeSendRStatsMsg_resetCounter:
|
||||
@@ -481,29 +496,32 @@ maybeSendMStatsMsg_end:
|
||||
|
||||
|
||||
checkRecvdMsg:
|
||||
rcall NET_PeekNextIncomingMsgNum ; check read queue (bufNum->r16)
|
||||
brcc checkRecvdMsg_end ; no msg, jmp
|
||||
rcall NET_Buffer_Locate ; (R17)
|
||||
adiw xh:xl, 1
|
||||
push r16
|
||||
rcall NETMSG_CheckMessageInBuffer ; (R16, R17, R18, R19, R20, X)
|
||||
pop r16
|
||||
brcs checkRecvdMsg_sendMsg
|
||||
; release buffer
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
rcall NET_Buffer_ReleaseByNum ; delete
|
||||
clc
|
||||
rjmp checkRecvdMsg_end
|
||||
checkRecvdMsg_sendMsg:
|
||||
sbiw xh:xl, 1
|
||||
ld r17, X
|
||||
andi r17, (NET_IFACE_BUFFER_IFACENUM1_BIT | NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
; rcall reverseInterfaceNum
|
||||
ldi r17, TTYONUART1_IFACENUM ; DEBUG: send everything to uart1 to test that code first
|
||||
rcall addMsgToInterface
|
||||
brcc checkRecvdMsg_end ; could not add, jmp
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
sec
|
||||
rcall NET_PeekNextIncomingMsgNum ; check read queue (bufNum->r16)
|
||||
brcc checkRecvdMsg_end ; no msg, jmp
|
||||
rcall NET_Buffer_Locate ; (R17)
|
||||
push r16
|
||||
push xl
|
||||
push xh
|
||||
adiw xh:xl, 1
|
||||
rcall NETMSG_CheckMessageInBuffer ; (R16, R17, R18, R19, R20, X)
|
||||
pop xh
|
||||
pop xl
|
||||
pop r16
|
||||
brcs checkRecvdMsg_sendMsg
|
||||
; release buffer
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
rcall NET_Buffer_ReleaseByNum ; delete
|
||||
clc
|
||||
rjmp checkRecvdMsg_end
|
||||
checkRecvdMsg_sendMsg:
|
||||
ld r17, X
|
||||
andi r17, (NET_IFACE_BUFFER_IFACENUM1_BIT | NET_IFACE_BUFFER_IFACENUM0_BIT)
|
||||
rcall reverseInterfaceNum
|
||||
; ldi r17, TTYONUART1_IFACENUM ; DEBUG: send everything to uart1 to test that code first
|
||||
rcall addMsgToInterface
|
||||
brcc checkRecvdMsg_end ; could not add, jmp
|
||||
rcall NET_GetNextIncomingMsgNum ; take off the queue
|
||||
rjmp checkRecvdMsg
|
||||
checkRecvdMsg_end:
|
||||
ret
|
||||
|
||||
@@ -538,18 +556,19 @@ reverseInterfaceNum_notUart0:
|
||||
; @param r17 interface num
|
||||
|
||||
addMsgToInterface:
|
||||
cpi r16, COMONUART0_IFACENUM
|
||||
cpi r17, COMONUART0_IFACENUM
|
||||
brne addMsgToInterface_notUart0
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
addMsgToInterface_notUart0:
|
||||
cpi r16, TTYONUART1_IFACENUM
|
||||
brne addMsgToInterface_end
|
||||
ldi yl, LOW(comOnUart0_iface)
|
||||
ldi yh, HIGH(comOnUart0_iface)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
addMsgToInterface_notUart0:
|
||||
cpi r17, TTYONUART1_IFACENUM
|
||||
brne addMsgToInterface_end
|
||||
ldi yl, LOW(ttyOnUart1_iface)
|
||||
ldi yh, HIGH(ttyOnUart1_iface)
|
||||
rjmp NET_Interface_AddOutgoingMsgNum ; try to add msg to interface
|
||||
addMsgToInterface_end:
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
@@ -36,11 +36,6 @@ ComOnUart0_Init:
|
||||
rcall UART_HW_Uart0_Init ; (R16, R17, X)
|
||||
ldi r16, COMONUART0_IFACENUM
|
||||
std Y+NET_IFACE_OFFS_IFACENUM, r16
|
||||
|
||||
ldi r16, UART_HW_READMODE_IDLE
|
||||
std Y+UART_HW_IFACE_OFFS_READMODE, r16
|
||||
ldi r16, UART_HW_WRITEMODE_IDLE
|
||||
std Y+UART_HW_IFACE_OFFS_WRITEMODE, r16
|
||||
|
||||
sbi COM_IRQ_ADDR_ATTN, COM_IRQ_BIT_ATTN ; enable pin change irq for ATTN line
|
||||
in r16, GIMSK ; enable pin change irq PCIE0 or PCIE1
|
||||
@@ -369,6 +364,9 @@ comOnUart0RunWriteIdle:
|
||||
rjmp comOnUart0RunWriteIdle_end ; yes, line busy, jmp
|
||||
|
||||
rcall UART_HW_Uart0_SetAttnLow ; 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 NET_Interface_GetNextOutgoingMsgNum ; take msg from queue (R17, R18, X)
|
||||
|
||||
@@ -167,9 +167,11 @@ UART_HW_Uart1_RxCharIsr_econtent:
|
||||
ldi r16, NET_IFACE_OFFS_ERR_CONTENT_LOW
|
||||
rjmp UART_HW_Uart1_RxCharIsr_incCounterAndEnterSkipping
|
||||
UART_HW_Uart1_RxCharIsr_overrun:
|
||||
ldi r16, NET_IFACE_OFFS_ERR_NOBUF_LOW
|
||||
; ldi r16, NET_IFACE_OFFS_ERR_NOBUF_LOW
|
||||
ldi r16, NET_IFACE_OFFS_ERR_MISSED_LOW
|
||||
UART_HW_Uart1_RxCharIsr_incCounterAndEnterSkipping:
|
||||
ldi r17, UART_HW_READMODE_SKIPPING
|
||||
ldi r16, NET_IFACE_OFFS_HANDLED_LOW
|
||||
UART_HW_Uart1_RxCharIsr_incCounterAndEnterMode:
|
||||
rcall NET_Interface_IncCounter16 ; (R24, R25)
|
||||
std Y+UART_HW_IFACE_OFFS_READMODE, r17 ; set read mode
|
||||
|
||||
@@ -369,9 +369,18 @@ ttyOnUart1RunReading:
|
||||
; @clobbers R16
|
||||
|
||||
ttyOnUart1RunSkipping:
|
||||
ldi r17, 0xff
|
||||
ldd r16, Y+UART_HW_IFACE_OFFS_READBUFNUM
|
||||
std Y+UART_HW_IFACE_OFFS_READBUFNUM, r17
|
||||
cp r16, r17
|
||||
breq ttyOnUart1RunSkipping_checkTimer
|
||||
rcall NET_Buffer_ReleaseByNum ; (R16, X)
|
||||
|
||||
ttyOnUart1RunSkipping_checkTimer:
|
||||
ldd r16, Y+NET_IFACE_OFFS_READTIMER
|
||||
cpi r16, TTYONUART1_SKIPTIME
|
||||
brcs ttyOnUart1RunSkipping_end
|
||||
; leave skip mode (enter idle)
|
||||
ldi r16, UART_HW_READMODE_IDLE
|
||||
std Y+UART_HW_IFACE_OFFS_READMODE, r16
|
||||
ttyOnUart1RunSkipping_end:
|
||||
@@ -388,6 +397,8 @@ ttyOnUart1RunSkipping_end:
|
||||
ttyOnUart1RunMsgReceived:
|
||||
ldi r17, 0xff
|
||||
ldd r16, Y+UART_HW_IFACE_OFFS_READBUFNUM
|
||||
cp r16, r17
|
||||
breq comOnUart1RunMsgReceived_enterIdle
|
||||
std Y+UART_HW_IFACE_OFFS_READBUFNUM, r17
|
||||
rcall NET_AddIncomingMsgNum ; (R17, R18, X)
|
||||
brcs comOnUart1RunMsgReceived_enterIdle
|
||||
@@ -396,7 +407,6 @@ ttyOnUart1RunMsgReceived:
|
||||
ldi r16, NET_IFACE_OFFS_ERR_NOBUF_LOW
|
||||
rcall NET_Interface_IncCounter16 ; (R24, R25)
|
||||
comOnUart1RunMsgReceived_enterIdle:
|
||||
rcall UART_HW_Interface_EnsureReadBuffer ; (R16, R17, R24, R25, X)
|
||||
ldi r17, UART_HW_READMODE_IDLE
|
||||
std Y+UART_HW_IFACE_OFFS_READMODE, r17 ; set read mode
|
||||
ret
|
||||
|
||||
Reference in New Issue
Block a user