chiark / gitweb /
check for receiving too much nmra data
authorian <ian>
Wed, 21 Dec 2005 13:18:46 +0000 (13:18 +0000)
committerian <ian>
Wed, 21 Dec 2005 13:18:46 +0000 (13:18 +0000)
detpic/morse.messages
detpic/nmra-stream.asm

index 8ce7148367e35122968e3172544ed44389f5dc83..234af1d72dfac8f31b1679cf0c28866781a5fe08 100644 (file)
 
 # Miscellaneous
 E                              ; `expected'; we were told to panic
+
+# Regarding communications from the host
 HX     ::t                     ; host sent unknown command
 HW     ::t                     ; host sent message which was too long
 HO                             ; host RS232 read overrun
 HF                             ; host RS232 framing error
+HN                             ; host sent too much NMRA - buffers full
 
 # Problematic interrupts
 IH     INTCON,INTCON3,PIR1,PIR2,PIR3 ; Interrupt source not found (high pri.)
index f88fbf4f2738308648f761bf3eddfa6919acf832..dedc2996bcc1fb07a7338eaa905bf568fbc88d8a 100644 (file)
@@ -221,9 +221,8 @@ fixme need to check both interrupt handlers here and look for refies too
 serial_receive_done
        intrl_handled_nostack
 
-receive_message_too_long
-       panic   morse_HW
- fixme reviewed up to here for inclusion in bigger program
+receive_too_much_nmra          panic   morse_HW
+receive_message_too_long       panic   morse_HW
 
 ; *** I *think* the interrupt bit is cleared by reading out of RCREG
 ; but this may be something to try in debugging if stuff doesn't work
@@ -244,10 +243,24 @@ advance_write_buffer
        debug   '5'
        mov_fw  fromserial              ; W =           00BB0000
        add_lw  0x10                    ; W =           0?CC0000
-       bc_w    6                       ; W =           00CC0000
-       mov_wf  fromserial              ;  where BB is this buffer
+       mov_wf  t                       ; t =           0?CC0000
+                                       ;  where BB is this buffer
                                        ;   and CC is next buffer
- fixme check for overruns ie if we caught up with totrack
+
+       ; we have to check our proposed new value for fromserial
+       ; against totrack before we store it in fromserial;
+       ; otherwise there's the possibility that we will store
+       ; the new value, and then the high-priority ISR will
+       ; interrupt us and advance totrack onto the buffer we've
+       ; just filled, fooling us into thinking we've overrun.
+       xor_wfw totrack                 ; W =           0?DD????
+       and_lw  0x30                    ;               ..DD....
+       bra_z   receive_too_much_nmra   ; where DD is (fromserial buffer)
+                                       ;  xor (totrack buffer)
+
+       mov_wf  t                       ; W =           0?CC0000
+       bc_w    6                       ; W =           00CC0000
+       mov_fw  fromserial
 
        bra     serial_receive_done
 
@@ -258,6 +271,7 @@ not_nmra_message
        bra     serial_receive_done
 
 ;****************************************************************************
+ fixme reviewed up to here for inclusion in bigger program
 
 nmra_interrupt_timer
        bt_f_if0 INTCON,2,0     ; check whether timer0 interrupt set