chiark / gitweb /
new tickdiv for two speeds of tick; working on energy - polarising finished but not...
[trains.git] / detpic / energy.asm
1 ;======================================================================
2 ; TRACK POWER AND SHORT CIRCUIT
3
4  include common.inc
5
6 settling_timeout equ 10000 ; us
7
8  udata_acs
9 settling        res     1
10
11  code
12
13 ;======================================================================
14 ; POLARISING/SETTLING:
15 ;
16 ;               NMRA            flag_p. settling        Booster PWM
17 ;
18 ; Normal        running         0       0x00            mark
19 ; Polarising    paused          1       0x00            space
20 ; Settling      paused          1       >0, count down  space
21 ;
22 ; NMRA is paused by disabling timer 0 intr; when we restart,
23 ; we restart the current message.
24 ;
25 ;----------------------------------------------------------------------
26
27 ;--------------------
28 power_polarising_init
29         clr_f   settling
30         return
31
32 ;--------------------
33 power_polarising_begin
34         pin_l   p0_booster_pwm
35         bc_f    INTCON, TMR0IE
36         bs_f    flags, flags_polarising
37         clr_f   settling
38         return
39
40 ;--------------------
41 power_polarising_settling
42 ; idempotent
43         tst_f_ifnz settling
44         return
45         mov_lw  settling_timeout / tick_us
46         mov_wf  settling
47         return
48
49 ;--------------------
50 power_polarising_tick
51         tst_f_ifnz settling
52         dec_f_ifnz settling ; decrement if not zero
53         return ; return if not dec'd, or if decrement didn't make zero
54         ; settle timeout complete:
55
56         bc_f    flags, flags_polarising
57         intr_mask
58         call    nmra_restartmessage
59         intr_unmask
60         goto    i2c_consider_restartread
61
62 ;======================================================================
63 ;
64 ; FAULTS AND POWER:
65 ;
66 ;               Shutdown CDU    Fault timeout   User Fault      Next states
67 ; Off           shutdown off    stopped         off             On*, Fault+
68 ; On            power-up on     stopped         off             Fault, Off*
69 ; Fault         shutdown off    500ms           1/2x50ms        Retry
70 ; Retry         power-up off    50ms            on              Persists, Off
71 ; Persists      shutdown off    50ms            on              Retry
72 ;                                                       * = when host instructs
73 ;                                                       + = lost race, only
74
75 command_power
76
77
78 ;  C            1 iff command is ON             undefined
79  tell on or off
80
81 on on:
82  start nmra with empty buffers
83  turn booster on
84  turn cdu on
85
86
87
88
89         panic   morse_UEC
90
91 ;power_on ???
92 ; from cebpic/nmra-stream.asm's setup
93         bcf     PORTB,2,0       ; booster shutdown L
94         bcf     TRISB,2,0       ; booster shutdown not-Z
95
96         bcf     PORTB,0,0       ; user fault L or Z
97
98  pause nmra
99  
100         panic   morse_UER
101
102 power_panichook
103         panic   morse_UEP
104
105 ;======================================================================
106  include final.inc