> 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
< 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
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))
include i2clib+panic.inc
include variables+vars.fin
include program+externs.fin
+ extern bufferw
end
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
;
; 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
;
buffer1 res 16
buffer2 res 16
buffer3 res 16
+bufferw res 16
code
;****************************************************************************
+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
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
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
; 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
; oops:
panic morse_HM
-
+advance_read_buffer_ifwatchdog
+ ; just loop round the buffer
+ mov_lw 0x40
+ mov_wf totrack
+ return
;****************************************************************************
call cdu_init
call power_polarising_init
call power_fault_init
+ call watchdog_init
clr_f xdebug+0
return
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
--- /dev/null
+;======================================================================
+; 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