From: ian Date: Wed, 28 Dec 2005 02:57:59 +0000 (+0000) Subject: Finished faults and power in energy.asm (but not yet really compiled); Fault interrup... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=79c8ebff524d926298be7f494542851e61768471;p=trains.git Finished faults and power in energy.asm (but not yet really compiled); Fault interrupt is now low-priority (which should be fine, since circuitry will handle it for 10ms or so); Document interrupt priorities in common.inc; New pin_znz macro in common.inc --- diff --git a/detpic/common.inc b/detpic/common.inc index 3d5cedd..b512906 100644 --- a/detpic/common.inc +++ b/detpic/common.inc @@ -35,7 +35,11 @@ tickdiv_us equ tick_us * tickdiv ; PCLATH Low ISR Not used ; t_dolocal Low ISR High ISR ; FSR1 Low ISR High ISR (detect[1]) -; FSR2 High ISR (nmra) High ISR (detect[1]) +; FSR2 High ISR (nmra[1]) High ISR (detect[1]) +; +; Main loop detection scan detection scan +; High ISR NMRA output I2C service +; Low ISRs everything else everything else ; ; Trashed May be trashed by any routine anywhere. Saved ; during every ISR entry/exit. @@ -275,6 +279,10 @@ pin_nz macro pinspec bc_f TRISA + (TRISB-TRISA)*((pinspec-0xa) & 15), pinspec >> 4 endm +pin_znz macro pinspec + btg_f TRISA + (TRISB-TRISA)*((pinspec-0xa) & 15), pinspec >> 4 + endm + pin_vh macro pinspec bs_f LATA + (LATB-LATA)*((pinspec-0xa) & 15), pinspec >> 4 endm diff --git a/detpic/energy.asm b/detpic/energy.asm index dd82672..78c2ea3 100644 --- a/detpic/energy.asm +++ b/detpic/energy.asm @@ -3,21 +3,29 @@ include common.inc -settling_timeout equ 10000 ; us +settling_timeout equ 10000 ; us + +stop_timeout equ 500000 ; us +stopflash_timeout equ 25000 ; us +retry_timeout equ 50000 ; us +persist_timeout equ 90000 ; us udata_acs -settling res 1 +settling res 1 ; all counters are 0 if stopped +stop_wait res 1 ; or otherwise count down +retry_wait res 1 code ;====================================================================== +; ; POLARISING/SETTLING: ; ; NMRA flag_p. settling Booster PWM ; -; Normal running 0 0x00 mark -; Polarising paused 1 0x00 space -; Settling paused 1 >0, count down space +; Normal running 0 stopped mark +; Polarising paused 1 stopped space +; Settling paused 1 running space ; ; NMRA is paused by disabling timer 0 intr; when we restart, ; we restart the current message. @@ -32,7 +40,7 @@ power_polarising_init ;-------------------- power_polarising_begin pin_l p0_booster_pwm - bc_f INTCON, TMR0IE + bc_f INTCON, TMR0IE ; disables NMRA interrupt bs_f flags, flags_polarising clr_f settling return @@ -54,53 +62,155 @@ power_polarising_tick ; settle timeout complete: bc_f flags, flags_polarising - intr_mask call nmra_restartmessage - intr_unmask + bs_f INTCON, TMR0IE ; reenables NMRA interrupt goto i2c_consider_restartread ;====================================================================== ; ; FAULTS AND POWER: ; -; Shutdown CDU Fault timeout User Fault Next states -; Off shutdown off stopped off On*, Fault+ -; On power-up on stopped off Fault, Off* -; Fault shutdown off 500ms 1/2x50ms Retry -; Retry power-up off 50ms on Persists, Off -; Persists shutdown off 50ms on Retry +; Shutdown CDU Timeout User Fault Next states +; +; Off shutdown off none off *On (or +Fault) +; On power-up on none off Fault, or *Off +; Stopping shutdown off 500ms 50% 1/50ms ->Retry +; Retry power-up off 50ms off ->Off, or Persists +; Persists shutdown off 90ms on ->Retry ; * = when host instructs ; + = lost race, only +; -> = after timeout +; +; shutdown LAT stop_wait retry_wait +; +; Off H (shutdown) stopped stopped +; On L (power-up) stopped stopped +; Stopping H (shutdown) before Retry for LED flash +; Retry L (power-up) stopped before Off +; Persists H (shutdown) stopped before retry +; +; (uses tickdiv) (uses tick) -command_power - - -; C 1 iff command is ON undefined - tell on or off +;-------------------- +power_fault_init + bs_f INTCON2, INTEDG1 ; rising edge + bc_f INTCON3, INT1IP + bc_f INTCON3, INT1IF + bs_f INTCON3, INT1IE + clr_f stop_wait + clr_f retry_wait + pin_h booster_shutdown + pin_vl p0_booster_userfault + pin_z p0_booster_userfault + ; now we are Off + return -on on: - start nmra with empty buffers - turn booster on - turn cdu on +;-------------------- +command_power + bra_nc command_power_off + ; command is ON: + +; Off -> On; noop in other states + pinlat_ifh p0_booster_shutdown + return ; On or Retry + ; might be Off, Stopping or Persists: + + tst_f_ifnz retry_wait + return ; that deals with Stopping or Persists + ; must be Off: + + pin_l p0_booster_shutdown + goto cdu_on + +;---------- +command_power_off +; On -> Off; noop in other states + pinlat_ifl p0_booster_shutdown + return ; Off, Stopping or Persists + ; might be On or Retry: + + tst_f_ifnz retry_wait + return ; that deals with Retry + ; must be On: +power_off_now + pin_h p0_booster_shutdown + goto cdu_off +;-------------------- +power_fault_intrl + bt_f_if1 INTCON3, INT1IF + return + ; we have a fault: + tst_f_ifz retry_wait + bra power_stop ; we were Off or On, goto Stopping + ; must be Stopping, Retry or Persists: + tst_f_ifnz stop_wait + bra power_stop ; we were already Stopping; restart timer + ; might be Retry or Persists, goto Persists (restarting any timer): - panic morse_UEC + rcall power_off_now + mov_lw persist_timeout / tick_us + mov_wf retry_wait + return -;power_on ??? -; from cebpic/nmra-stream.asm's setup - bcf PORTB,2,0 ; booster shutdown L - bcf TRISB,2,0 ; booster shutdown not-Z +;-------------------- +power_fault_tick + tst_f_ifnz retry_wait + dec_f_ifnz retry_wait + return + ; retry_wait was running but has just reached zero; + ; we were in Stopping, Retry or Persists: + + tst_f_ifnz stop_wait + bra power_stop_doflash ; that was Stopping, just flash the LED + ; must be Retry or Persists: + + pinlat_ifl p0_booster_shutdown + bra power_retry ; we were in Persists, now we can try again + ; we were in Retry but it didn't work: +; go to Persists: + pin_h p0_booster_shutdown + mov_lw persist_timeout / tickdiv_us + mov_wf retry_wait + pin_nz p0_booster_userfault + return - bcf PORTB,0,0 ; user fault L or Z +;---------- +power_stop + rcall power_off_now + mov_lw stop_timeout / tickdiv_us + mov_wf stop_wait + pin_z p0_booster_userfault + mov_lw b'00000111' + call serial_addbyte +power_stop_doflash + pin_znz p0_booster_userfault + mov_lw stopflash_timeout / tickdiv_us + mov_wf retry_wait + return - pause nmra - - panic morse_UER +;-------------------- +power_fault_tickdiv + tst_f_ifnz stop_wait + dec_f_ifnz stop_wait + return + ; stop_wait was running but has just reached zero; + ; we were in Stopping, now we can Retry: +power_retry + mov_lw retry_timeout / tickdiv_us + mov_wf retry_wait + pin_l p0_booster_shutdown + pin_z p0_booster_userfault + return +;-------------------- power_panichook - panic morse_UEP + pin_h p0_booster_shutdown + pin_l p0_booster_pwm + pin_z p0_booster_userfault + return ;====================================================================== include final.inc diff --git a/detpic/energy.fin b/detpic/energy.fin index 5fd3c0d..3a1c020 100644 --- a/detpic/energy.fin +++ b/detpic/energy.fin @@ -1,3 +1,9 @@ extern command_power extern power_polarising + extern power_polarising_init + extern power_polarising_tick + extern power_fault_init + extern power_fault_intrl + extern power_fault_tick + extern power_fault_tickdiv extern power_panichook diff --git a/detpic/nmra-stream.asm b/detpic/nmra-stream.asm index e827791..9688c35 100644 --- a/detpic/nmra-stream.asm +++ b/detpic/nmra-stream.asm @@ -287,6 +287,10 @@ not_nmra_message ;**************************************************************************** near_interrupt_high code + +master_interrupt_high_notnmra + panic morse_IH + master_interrupt_high bt_f_if0 INTCON,TMR0IF ; check whether timer0 interrupt set bra master_interrupt_high_notnmra diff --git a/detpic/points.asm b/detpic/points.asm index 0e10676..4ca3908 100644 --- a/detpic/points.asm +++ b/detpic/points.asm @@ -353,7 +353,7 @@ cdu_init clr_f pointmsg ;... ;----- -cdu_offp +cdu_off cdu_panichook pin_l p0_cdu_enable ;... diff --git a/detpic/program.asm b/detpic/program.asm index 73b1d12..d51fa53 100644 --- a/detpic/program.asm +++ b/detpic/program.asm @@ -82,6 +82,7 @@ master_init call mascan_init call tick_init call power_polarising_init + call power_fault_init return ;---------------------------------------- @@ -89,16 +90,12 @@ master_interrupt_low enter_interrupt_low call tick_intrl call nmra_serialrx_intrl + call power_fault_intrl call serialtx_intrl call points_local_intrl call i2cm_intrl panic morse_IL -;---------- -near_interrupt_high code -master_interrupt_high_notnmra - panic morse_IH - ;---------------------------------------------------------------------- serialrx_table_section code 0x2000 diff --git a/detpic/serout.asm b/detpic/serout.asm index 6bf7cde..b7925bc 100644 --- a/detpic/serout.asm +++ b/detpic/serout.asm @@ -100,8 +100,8 @@ tx_fcdisable ;---------------------------------------------------------------------- serialtxfc_init - bs_f INTCON, RBIE bc_f INTCON2, RBIP + bs_f INTCON, RBIE rcall portb_read return diff --git a/detpic/tick.asm b/detpic/tick.asm index 9ef474b..f2ba9e6 100644 --- a/detpic/tick.asm +++ b/detpic/tick.asm @@ -34,8 +34,8 @@ tick_intrl bc_f PIR1, TMR2IF ; add calls to _tick here: - call power_polarising_tick call power_fault_tick + call power_polarising_tick ; end of list of calls to _tick dec_f_ifz tickdivcount @@ -46,6 +46,7 @@ tick_intrl ;---------------------------------------- tickdiv_do ; add calls to _tickdiv here: + call power_fault_tickdiv call cdu_tickdiv ; end of list of calls to _tickdiv