From 89838678b8618055776dbea9ce7e8d8150dbe6cb Mon Sep 17 00:00:00 2001 From: Werner Johansson Date: Sat, 22 Feb 2003 00:34:51 -0800 Subject: [PATCH] v0.1 - Receives Unilink data OK, relays it to serial Signed-off-by: Werner Johansson --- wj-uni.asm | 29 ++++++++++++++++++++++++----- 1 files changed, 24 insertions(+), 5 deletions(-) diff --git a/wj-uni.asm b/wj-uni.asm index ecb6d6a..5f47338 100644 --- a/wj-uni.asm +++ b/wj-uni.asm @@ -14,6 +14,7 @@ ;---------------------------------------------------------------- ; Version ; +; 0.1 Receives Unilink data OK, relays it to serial ; 0.0 Very first "Fucking No Work!" version ; ;---------------------------------------------------------------- @@ -88,25 +89,30 @@ IRQPCLATH equ 7dh btfss INTCON,INTF ; Check if it's INT (CLK) goto IRQNotINT ; Nope +; If there's activity on the clock line (the clock goes high) we stay in here until we have clocked eight bits +; - this saves us a lot of context switching (and it's just a few hundred cpu cycles after all (20us*8 bits= +; 160us=800 instruction cycles (5 MIPS @ 20MHz), not even a problem for serial input if we're not getting more than +; 6250 bytes per second from the UART, and the 2-byte FIFO somehow fills up (this should be impossible even @ 115200 +; as we're only calling this blocking INT handler a maximum of 1000 times per second, halting INT's for 1/6250 of a second, +; this gives the CPU ample of time to deal with all bytes from the USART. I'm checking the OERR (Serial Overrun) bit +; to catch this though.. + movlw 8 ; Loop this many times movwf DataCount CLKWaitHigh - btfsc PORTA,4 ; Check for RST - goto IRQAfterINT btfss PORTC,2 ; Check for BUSON goto IRQAfterINT btfss PORTB,0 ; Wait for clock to go high goto CLKWaitHigh + CLKWaitLow - btfsc PORTA,4 ; Check for RST - goto IRQAfterINT btfss PORTC,2 ; Check for BUSON goto IRQAfterINT btfsc PORTB,0 ; Wait for clock to go low goto CLKWaitLow - clrc ; Clear carry + clrc ; Clear carry (this way the DataStore byte doesn't have to be cleared before) btfss PORTC,3 ; Test DATA setc ; Set carry if data is LOW (data is inverted!) rlf DataStore,f ; Shift it into our accumulator @@ -114,6 +120,19 @@ CLKWaitLow decfsz DataCount,f ; Loop once more perhaps? goto CLKWaitHigh +; Successfully received a byte here, run it through a state machine to figure out what to do +; (several possibilites exists here: +; If more than 1.1ms has passed since last receive, reset receive counter to zero +; If receive counter is zero and the received byte is a zero byte, discard it +; Otherwise store the byte in our receive buffer and increment receive counter +; If the receive counter is 3 check the two upper bits of recv'd byte (CMD1) - this tells us the length of the packet +; 00 = short 6 byte packet +; 10 = medium 11 byte packet +; 11 = long 16 byte packet +; Update the receive length byte accordingly +; Check whether receive length and receive count are equal, that means that we're finished, flag this by setting +; the high bit of receive length + IRQAfterINT bcf INTCON,INTF ; Clear our IRQ -- 1.7.3