chiark / gitweb /
new watchdog feature
authorian <ian>
Fri, 30 Dec 2005 11:47:46 +0000 (11:47 +0000)
committerian <ian>
Fri, 30 Dec 2005 11:47:46 +0000 (11:47 +0000)
cebpic/README.protocol
detpic/Makefile
detpic/final.inc
detpic/morse.messages
detpic/nmra-stream.asm
detpic/program.asm
detpic/tick.asm
detpic/watchdog.asm [new file with mode: 0644]

index 3a922cd53216562fc471dd0043b4523534fb1aa4..cbe015bc05612c511e4f32a905262e03d06dedd0 100644 (file)
@@ -19,6 +19,7 @@ From host to PIC:
  > 1 1111 111  ....       (ff)  NMRADATA  NMRA data
  > 1 0001 XXX  0 XXXXXXX  (88+)        PING      Ping `X' (please Pong `X')
  > 1 0010 RRR  E RRR...   (90+)        POLARITY  Set polarity
+ > 1 0011 000  0 MMMMMMM  (98+)        WATCHDOG  W'dog reset, t/o <M*16>ms from now
  > 0 0100 001             (21) ON        Power on
  > 0 0100 000             (20) OFF       Power off
 
@@ -57,6 +58,7 @@ From PIC to host:
  < 1 0001 XXX  0 XXXXXXX  (88+)        PONG      Pong `X' (reply to Ping `X')
  < 0 000 1001             (HT)  HELLO    I am booted
  < 0 000 1011             (VT)  AAARGH   Followed by debug chars (only)
+ < 0 000 1101             (CR)  WATCHDOG  Timeout happenedbn
  < 0 000 0111             (BEL) FAULT    Fault exists
  < 0 000 0110             (ACK) FIXED    Fault now fixed
  < 0 0100 PPP             (20+)        POINTED   Point change done using capacitor P
index 9603e279950845564c22533a6788f55759e6cbbc..b587f71c84a5f972720f8cd32d7e1e55e9dae7b8 100644 (file)
@@ -6,7 +6,7 @@ FILES=                  variables vectors                               \
                        panic routines-led i2clib+panic                 \
                        misc detect points serout                       \
                        syncwrite mascan energy                         \
-                       reverse nmra-stream tick
+                       reverse nmra-stream tick watchdog
 
 PROGRAMS=              program
 OBJS_program=          $(addsuffix .o, $(FILES))
index debcb40c4571f81faba052884f9e342a2d747ca5..101f657242ab957cb73e74eb0c8cc77d5f7b49d6 100644 (file)
@@ -2,5 +2,6 @@
   include i2clib+panic.inc
   include variables+vars.fin
   include program+externs.fin
+  extern bufferw
 
        end
index 64df6fc2f3b5ae46c1507953d0fef7b7482bcb83..a1a81e5ea3208199f36d391958302f3a4f6dbb5b 100644 (file)
@@ -49,6 +49,9 @@ MD                            ; i2cmu_done !
 IH     INTCON,INTCON3,PIR1,PIR2,PIR3 ; Interrupt source not found (high pri.)
 IL     INTCON,INTCON3,PIR1,PIR2,PIR3 ; Interrupt source not found (low pri.)
 
+# W - watchdog
+WX                                     ; bad watchdog command
+
 # Messages for i2clib, S*
 SM     i2clib+panic:st,:sspstat,:sspcon1,:sspcon2 ; m.,i., ctrlr bad state
 SS     SSPSTAT,SSPCON1                 ; s.,i., controller bad state
index f2f5f2904bab92c1af4eccf798a891be9474a92d..6caea1ee38292acaea2eb7270b049d141d5846fc 100644 (file)
@@ -32,6 +32,7 @@ totrackbit    res     1       ; bit location of pointer within byte
  ;
  ; buffers are each 16 bytes (this is hardwired)
  ; and there are four of them starting at 0x500, 0x510, 0x520, 0x530.
+ ; plus a copy of the watchdog `stop everything' command at 0x540.
  ;
  ; fromserial and totrack are pointers into the buffer page
  ;
@@ -65,6 +66,7 @@ buffer0 res 16
 buffer1 res 16
 buffer2 res 16
 buffer3 res 16
+bufferw res 16
 
   code
 
@@ -209,6 +211,21 @@ nmra_restartmessage @      ; Entrypoint from power_polarising_tick, at end
 
 ;****************************************************************************
 
+nmra_sendwatchdog_start @
+       mov_lw  0x40
+       mov_wf  totrack
+       return
+
+nmra_sendwatchdog_stop @
+       bt_f_if0 totrack, 6
+       return ; not transmitting watchdog
+       mov_fw  fromserial
+       and_lw  0x30
+       mov_wf  totrack
+       return
+
+;****************************************************************************
+
 nmra_serialrx_intrl @
        bt_f_if0 PIR1,RCIF      ; check whether serial recv interrupt bit set
        return
@@ -265,17 +282,18 @@ advance_write_buffer
        debug   '5'
        mov_fw  fromserial              ; W =           00BB0000
        add_lw  0x10                    ; W =           0?CC0000
-       mov_wf  t                       ; t =           0?CC0000
+       bc_w    6                       ; W =           00CC0000
+       mov_wf  t                       ; t =           00CC0000
                                        ;  where BB is this buffer
                                        ;   and CC is next buffer
 
-       xor_wfw totrack                 ; W =           0?DD????
-       and_lw  0x30                    ;               ..DD....
+       xor_wfw totrack                 ; W =           0WDD????
+       and_lw  0x70                    ;               .WDD....
        bra_z   receive_too_much_nmra   ; where DD is (fromserial buffer)
                                        ;  xor (totrack buffer)
+                                       ; and W is 1 iff xmitting watchog
 
-       mov_fw  t                       ; W =           0?CC0000
-       bc_w    6                       ; W =           00CC0000
+       mov_fw  t                       ; W =           00CC0000
        mov_wf  fromserial
 
        bra     serial_receive_done
@@ -348,7 +366,7 @@ decide_next_bit
 
        mov_fw  fromserial
        xor_wfwa totrack
-       and_lw  0x30
+       and_lw  0x70
        bra_nz  read_from_buffer
        bs_fa   nmractrl,transmitbit
        bs_fa   nmractrl,nextaction
@@ -433,16 +451,12 @@ advance_read_buffer
 ; move pointer to next buffer
 ; clear low 4 bits of totrack and increment top 4 bits
 ; aaaabbbb -> bbbbaaaa -> bbbb(aaaa+1) -> 0000(aaaa+1) -> (aaaa+1)0000
-       debug   '7'     ; write 'v' to serial port
-       swap_fa totrack
-       inc_fa  totrack
-       mov_lw  0xF
-       and_wffa totrack
-       swap_fa totrack
-       debug   '8'     ; write 'v' to serial port
-
-; clear bit 6 (will set back to buffer 0 if has overflowed to 4)
-       bc_fa   totrack,6
+       bt_f_if1 totrack, 6 ; were we doing watchdog broadcasts ?
+       bra     advance_read_buffer_ifwatchdog
+       mov_fw  totrack
+       add_lw  0x10
+       and_lw  0x30
+       mov_wf  totrack
        debug   '9'     ; write 'v' to serial port
 
        inc_f   acknmra
@@ -452,7 +466,11 @@ advance_read_buffer
        ; oops:
        panic   morse_HM
 
-
+advance_read_buffer_ifwatchdog
+       ; just loop round the buffer
+       mov_lw  0x40
+       mov_wf  totrack
+       return
 
 ;****************************************************************************
 
index f09458123ff6b1660bcd0a17f784436010062281..714269c0fc368c09d78545721ce20434579b0533 100644 (file)
@@ -84,6 +84,7 @@ master_init
        call    cdu_init
        call    power_polarising_init
        call    power_fault_init
+       call    watchdog_init
  clr_f xdebug+0
        return
 
index a70ebc6aca124c666b115853f5e073ff315f503b..07d697b9f9ac0f331219a052e3c8bde7697a5035 100644 (file)
@@ -47,6 +47,7 @@ tick_intrl @
 tickdiv_do
        ; add calls to <foo>_tickdiv here:
        call    power_fault_tickdiv
+       call    watchdog_tickdiv
        call    cdu_tickdiv
        ; end of list of calls to <foo>_tickdiv
 
diff --git a/detpic/watchdog.asm b/detpic/watchdog.asm
new file mode 100644 (file)
index 0000000..f0abe6c
--- /dev/null
@@ -0,0 +1,54 @@
+;======================================================================
+; WATCHDOG TIMEOUTS
+
+  include common.inc
+
+  udata_acs
+watchdog       res     1
+
+  code
+;----------------------------------------------------------------------
+command_watchdog @
+       mov_fw  POSTINC0        ; W =           10011OOO
+       and_lw  0x07            ; W =           00000OOO
+       bra_nz  command_watchdog_bad
+       mov_wf  INDF0           ; W =           OMMMMMMM
+       bra_n   command_watchdog_bad
+       mov_fw  watchdog        ; watchdog =    OMMMMMMM
+       goto    nmra_sendwatchdog_stop
+
+command_watchdog_bad panic morse_WX
+
+;----------------------------------------------------------------------
+watchdog_tickdiv @
+       tst_f_ifnz watchdog
+       dec_f_ifnz watchdog
+       ; oops, we've timed out
+
+       call    nmra_sendwatchdog_start
+       mov_lw  0x0d
+       goto    serial_addbyte
+
+;----------------------------------------------------------------------
+watchdog_init @
+       clr_f   watchdog
+       mov_lfsr bufferw, 1
+
+wdog_byte macro v
+       mov_lw  v
+       mov_wf  POSTINC1
+       endm
+
+       ; Baseline Broadcast stop Forwards(I) non-Emergency S9.2 B l.98-
+       ; as computed by ./hostside-old -st bstop
+       set_f   POSTINC1        ; ff
+       set_f   POSTINC1        ; ff
+       wdog_byte               0x80
+       wdog_byte               0x87
+       wdog_byte               0x81
+       wdog_byte               0x61
+
+       return
+
+;======================================================================
+  include final.inc