;====================================================================== ; TRACK POWER AND SHORT CIRCUIT include common.inc settling_timeout equ 10000 ; us udata_acs settling 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 ; ; NMRA is paused by disabling timer 0 intr; when we restart, ; we restart the current message. ; ;---------------------------------------------------------------------- ;-------------------- power_polarising_init clr_f settling return ;-------------------- power_polarising_begin pin_l p0_booster_pwm bc_f INTCON, TMR0IE bs_f flags, flags_polarising clr_f settling return ;-------------------- power_polarising_settling ; idempotent tst_f_ifnz settling return mov_lw settling_timeout / tick_us mov_wf settling return ;-------------------- power_polarising_tick tst_f_ifnz settling dec_f_ifnz settling ; decrement if not zero return ; return if not dec'd, or if decrement didn't make zero ; settle timeout complete: bc_f flags, flags_polarising intr_mask call nmra_restartmessage intr_unmask 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 ; * = when host instructs ; + = lost race, only command_power ; C 1 iff command is ON undefined tell on or off on on: start nmra with empty buffers turn booster on turn cdu on panic morse_UEC ;power_on ??? ; from cebpic/nmra-stream.asm's setup bcf PORTB,2,0 ; booster shutdown L bcf TRISB,2,0 ; booster shutdown not-Z bcf PORTB,0,0 ; user fault L or Z pause nmra panic morse_UER power_panichook panic morse_UEP ;====================================================================== include final.inc