From: ian Date: Sat, 17 May 2008 13:59:44 +0000 (+0000) Subject: new watchdog and short circuit arrangements; also add _ to end of p0_booster_userfaul... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=26cf9a7c0be0f371a5db311d8ca94548ecf6b7ce;p=trains.git new watchdog and short circuit arrangements; also add _ to end of p0_booster_userfault_ to indicate inverted polarity --- diff --git a/detpic/energy.asm b/detpic/energy.asm index 9fa4642..2fed6bf 100644 --- a/detpic/energy.asm +++ b/detpic/energy.asm @@ -5,15 +5,14 @@ settling_timeout equ 10000 ; us -stop_timeout equ 500000 ; us -stopflash_timeout equ 50000 ; us -retry_timeout equ 50000 ; us -persist_timeout equ 90000 ; us +stopping_timeout equ 500000 ; us +stopflash_timeout equ 100000 ; us +retriableflash_timeout equ 500000 ; us udata_acs settling res 1 ; all counters are 0 if stopped -stop_wait res 1 ; or otherwise count down -retry_wait res 1 +stopping_wait res 1 ; or otherwise count down +ledflash_wait res 1 fault_spurious_count res 1 @@ -67,7 +66,12 @@ power_polarising_tick @ ; settle timeout complete: bc_f flags, flags_polarising + + tst_f_ifnz stopping_wait + bra power_polarising_done_ifstopping pin_vh p0_booster_pwm +power_polarising_done_ifstopping + call nmra_restartmessage bs_f INTCON, TMR0IE ; reenables NMRA interrupt goto i2c_consider_restartread @@ -76,23 +80,34 @@ power_polarising_tick @ ; ; FAULTS AND POWER: ; -; Shutdown CDU Time User Fault Next states and action when -; fault timeout ON OFF ; -; Off shutdown off none off On -; On power-up on none off Stopping,FAULT Off -; Stopping shutdown on 500ms 50% 1/100ms Retriable -; Retriable shutdown on none on On Off -; (no notation: event ignored) +; Off On Stopping Retriable Watchdogged +; Recognise by +; stopping_wait 0 0 >0 0 0 +; ledflash_wait 0 0 >0 >0 0 +; b._shutdowwn H L H H H +; b._userfault_ H H * * L +; +; Managed here: +; shutdown H L H H H +; Fault LED - - 50% 1/100ms 50% 1/500ms on +; Timeout? - - 500ms - - +; next state Retriable ; -; shutdown LAT stop_wait retry_wait cdu pointstate +; Elsewhere: +; CDU - ON ON ON ON +; booster_pwm !polar !polar OFF !polar !polar[1] +; so power is - ON off! - - ; -; Off H (shutdown) 0 0 off Charging -; On L (power-up) 0 0 on any -; Stopping H (shutdown) before Retry for LED flash on any -; Retriable H (shutdown) 0 0 on any +; Events, results: +; Fault - Stopping - Stopping[2] Stopping +; Watchdog - W'dogged - - - +; ON On (On) - On On +; OFF (Off) Off - Off Off +; (- means event ignored) ; -; (uses tickdiv) (uses tick) +; [1] booster_pwm `!polar' means on if we're not polarising. +; [2] this is not supposed to happen but we don't check for it ;-------------------- power_fault_init @ @@ -100,36 +115,35 @@ power_fault_init @ bc_f INTCON3, INT1IP bc_f INTCON3, INT1IF bs_f INTCON3, INT1IE - clr_f stop_wait - clr_f retry_wait - clr_f fault_spurious_count pin_h p0_booster_shutdown - pin_h p0_booster_userfault + pin_h p0_booster_userfault_ + clr_f ledflash_wait + clr_f stopping_wait + clr_f fault_spurious_count ; now we are Off return command_power_section code 0x2080 ;-------------------- command_power_on @ -; Off, Retriable -> On; noop in other states - tst_f_ifnz stop_wait + tst_f_ifnz stopping_wait return ; that deals with Stopping - ; might be Off, On or Retriable, so safe to just turn On + ; safe to just turn On, even if already On - pin_vh p0_booster_userfault - pin_vh p0_booster_pwm pin_vl p0_booster_shutdown + pin_vh p0_booster_userfault_ + clr_f ledflash_wait goto cdu_on ;---------- command_power_off @ -; On, Retriable -> Off; noop in Off or Stopping - tst_f_ifnz stop_wait + tst_f_ifnz stopping_wait return ; that deals with Stopping - ; must be Off, On or Retriable, so safe to just turn Off + ; safe to just turn Off, even if already Off - pin_vh p0_booster_userfault pin_vh p0_booster_shutdown + pin_vh p0_booster_userfault_ + clr_f ledflash_wait goto cdu_off code2 code @@ -155,33 +169,44 @@ power_fault_intrl @ fault_isactual pin_vl p0_booster_pwm pin_vh p0_booster_shutdown - - tst_f_ifnz stop_wait + tst_f_ifnz stopping_wait bra fault_isactual_ifalreadystopping mov_lw b'00000111' call serial_addbyte -fault_isactual_ifalreadystopping - mov_lw stop_timeout / tickdiv_us - mov_wf stop_wait - pin_vl p0_booster_userfault - rcall power_stop_doflash + mov_lw stopping_timeout / tickdiv_us + mov_wf stopping_wait + pin_vh p0_booster_userfault_ + rcall power_led_start_stoppingflash + +fault_isactual_ifalreadystopping intrl_handled_nostack ;-------------------- power_fault_tick @ - tst_f_ifnz retry_wait - dec_f_ifnz retry_wait + tst_f_ifnz ledflash_wait + dec_f_ifnz ledflash_wait return - ; retry_wait was running but has just reached zero; - ; we were in Stopping. +;... ledflash_wait was running but has just reached zero; flash the LED -;----- -power_stop_doflash - pin_vhl p0_booster_userfault - mov_lw stopflash_timeout / tick_us - mov_wf retry_wait + pin_vhl p0_booster_userfault_ + +power_led_start_retriableflash + mov_lw retriableflash_timeout / 2 / tick_us + tst_f_ifnz stopping_wait +power_led_start_stoppingflash + mov_lw stopflash_timeout / 2 / tick_us + mov_wf ledflash_wait + return + +;-------------------- +power_watchdog_timeout @ + pinlat_ifh p0_booster_shutdown + return +;... must be On, so go to Watchdogged + pin_vh p0_booster_shutdown + pin_vl p0_booster_userfault_ return ;-------------------- @@ -190,13 +215,17 @@ power_fault_tickdiv @ bra fault_spurious_tickdiv ; in any case: fault_tickdiv_rest - tst_f_ifnz stop_wait - dec_f_ifnz stop_wait + tst_f_ifnz stopping_wait + dec_f_ifnz stopping_wait return - ; stop_wait was running but has just reached zero; + ; stopping_wait was running but has just reached zero; ; we were in Stopping, go to Retriable: - clr_f retry_wait - pin_vl p0_booster_userfault + + rcall power_led_start_retriableflash + + bt_f_if0 flags, flags_polarising + pin_vh p0_booster_pwm + mov_lw b'00000110' goto serial_addbyte @@ -222,7 +251,7 @@ fault_spurious_tickdiv_isoverflow power_panichook @ pin_vh p0_booster_shutdown pin_vl p0_booster_pwm - pin_vh p0_booster_userfault + pin_vh p0_booster_userfault_ return ;====================================================================== diff --git a/detpic/watchdog.asm b/detpic/watchdog.asm index 78b9d1a..df1671c 100644 --- a/detpic/watchdog.asm +++ b/detpic/watchdog.asm @@ -16,9 +16,6 @@ command_watchdog @ bra_n command_watchdog_bad mov_wf watchdog ; watchdog = OMMMMMMM - pinlat_ifl p0_booster_shutdown - call cdu_on - goto nmra_sendwatchdog_stop command_watchdog_bad panic morse_WX @@ -30,8 +27,7 @@ watchdog_tickdiv @ return ; oops, we've timed out - call nmra_sendwatchdog_start - call cdu_off + call power_watchdog_timeout mov_lw 0x0d goto serial_addbyte