v0.1 - Receives Unilink data OK, relays it to serial
authorWerner Johansson <wj@xnk.nu>
Sat, 22 Feb 2003 08:34:51 +0000 (00:34 -0800)
committerWerner Johansson <wj@xnk.nu>
Sun, 17 Oct 2010 00:30:23 +0000 (17:30 -0700)
Signed-off-by: Werner Johansson <wj@xnk.nu>

wj-uni.asm

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