From ed7d27525058f779e63d0d3ac8a51c0f404e0b16 Mon Sep 17 00:00:00 2001 From: ian Date: Fri, 30 Dec 2005 11:47:46 +0000 Subject: [PATCH] new watchdog feature --- cebpic/README.protocol | 2 ++ detpic/Makefile | 2 +- detpic/final.inc | 1 + detpic/morse.messages | 3 +++ detpic/nmra-stream.asm | 52 +++++++++++++++++++++++++++------------- detpic/program.asm | 1 + detpic/tick.asm | 1 + detpic/watchdog.asm | 54 ++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 98 insertions(+), 18 deletions(-) create mode 100644 detpic/watchdog.asm diff --git a/cebpic/README.protocol b/cebpic/README.protocol index 3a922cd..cbe015b 100644 --- a/cebpic/README.protocol +++ b/cebpic/README.protocol @@ -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 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 diff --git a/detpic/Makefile b/detpic/Makefile index 9603e27..b587f71 100644 --- a/detpic/Makefile +++ b/detpic/Makefile @@ -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)) diff --git a/detpic/final.inc b/detpic/final.inc index debcb40..101f657 100644 --- a/detpic/final.inc +++ b/detpic/final.inc @@ -2,5 +2,6 @@ include i2clib+panic.inc include variables+vars.fin include program+externs.fin + extern bufferw end diff --git a/detpic/morse.messages b/detpic/morse.messages index 64df6fc..a1a81e5 100644 --- a/detpic/morse.messages +++ b/detpic/morse.messages @@ -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 diff --git a/detpic/nmra-stream.asm b/detpic/nmra-stream.asm index f2f5f29..6caea1e 100644 --- a/detpic/nmra-stream.asm +++ b/detpic/nmra-stream.asm @@ -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 ;**************************************************************************** diff --git a/detpic/program.asm b/detpic/program.asm index f094581..714269c 100644 --- a/detpic/program.asm +++ b/detpic/program.asm @@ -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 diff --git a/detpic/tick.asm b/detpic/tick.asm index a70ebc6..07d697b 100644 --- a/detpic/tick.asm +++ b/detpic/tick.asm @@ -47,6 +47,7 @@ tick_intrl @ tickdiv_do ; add calls to _tickdiv here: call power_fault_tickdiv + call watchdog_tickdiv call cdu_tickdiv ; end of list of calls to _tickdiv diff --git a/detpic/watchdog.asm b/detpic/watchdog.asm new file mode 100644 index 0000000..f0abe6c --- /dev/null +++ b/detpic/watchdog.asm @@ -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 -- 2.30.2