1 ;======================================================================
2 ; MAIN PROGRAM AND GLUE
7 ;======================================================================
8 ; COMMON TO MASTER AND SLAVE
10 ;----------------------------------------
13 bs_f RCON, IPEN ; interrupt priorities
17 bt_f_if0 idloc1,idloc1_master
20 bt_f_if1 idloc1,idloc1_master
26 bt_f_if1 idloc1,idloc1_master
27 goto backgroundloop_master
28 bt_f_if1 idloc1,idloc1_boarddet
29 goto backgroundloop_detectors
30 goto backgroundloop_reversers
34 ; called by {master,slave}_init immediately after they've init'd i2c.
38 call points_local_init
39 call polarity_local_init
40 call detect_local_init
43 ;----------------------------------------
50 intrl_handled_routine @
51 mov_ff isr_low_save_stkptr, STKPTR
54 ;======================================================================
57 ;----------------------------------------
59 ; Master-specific initialisation.
66 call polarity_master_init
67 call points_master_init
68 call common_local_init
74 call power_polarising_init
80 ;----------------------------------------
81 master_interrupt_low @
86 call nmra_serialrx_intrl
88 call power_fault_intrl
94 call points_local_intrl
100 ;----------------------------------------------------------------------
101 serialrx_table_section code 0x2000
103 ;--------------------
104 serialrx_generalmsg @
105 ;command_<something> has same calling convention:
107 ; FSR0 -> start of message undefined
108 ; *FSR0 message undefined
111 bra_n serialrx_if_multibyte
112 bra_z command_crashed
115 bra_z command_power_on
117 bra_z command_power_off
121 serialrx_if_multibyte
122 rr_fw INDF0 ; W = ii MM ww ww ww ww ii ii
123 and_lw 0x3c ; W = zz zz ww ww ww ww zz zz
124 bt_f_if0 PCL, 0 ; always true, but reads PCL
128 goto serialrx_bad ; 1 0000 xxx
129 goto command_ping ; 1 0001 xxx
130 goto command_polarity ; 1 0010 xxx
131 goto command_watchdog ; 1 0011 xxx
132 goto command_point ; 1 0100 xxx
133 goto serialrx_bad ; 1 0101 xxx
134 goto serialrx_bad ; 1 0110 xxx
135 goto serialrx_bad ; 1 0111 xxx
136 goto serialrx_bad ; 1 1000 xxx
137 goto serialrx_bad ; 1 1001 xxx
138 goto serialrx_bad ; 1 1010 xxx
139 goto serialrx_bad ; 1 1011 xxx
140 goto serialrx_bad ; 1 1100 xxx
141 goto serialrx_bad ; 1 1101 xxx
142 goto serialrx_bad ; 1 1110 xxx
143 goto serialrx_bad ; 1 1111 xxx
151 ;--------------------
157 bra_n command_ping_bad
158 goto serial_addbyte_another
160 command_ping_bad panic morse_HP
162 ;======================================================================
165 ;----------------------------------------
167 ; Slave-specific initialisation.
175 call common_local_init
176 call detect_slave_init
179 ;----------------------------------------
180 slave_interrupt_low @
182 call points_local_intrl
185 ;----------------------------------------
190 ;----------------------------------------
195 bra i2csu_write_if_special
197 bra polarity_local_do
204 i2csu_write_if_special
206 bra i2csu_write_if_bad
207 goto panic_crashread_commanded
210 ;======================================================================
211 ; MASTER/SLAVE deviations
215 ; Either transmits the message to the master, or if we are the master,
216 ; handles it as an incoming message from the notional `slave 0'.
217 ; W message unchanged
219 bt_f_if0 idloc1,idloc1_master
220 goto slave_add_short_message
221 goto loopback_read_byte
223 ;======================================================================