;----------------------------------------------------------------\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
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
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