1 ;======================================================================
2 ; MAIN PROGRAM AND GLUE
7 ;======================================================================
8 ; COMMON TO MASTER AND SLAVE
10 ;----------------------------------------
26 bs_f RCON, IPEN ; interrupt priorities
31 bt_f_if0 idloc1,idloc1_master
34 bt_f_if1 idloc1,idloc1_master
40 bt_f_if1 idloc1,idloc1_master
41 goto backgroundloop_master
42 bt_f_if1 idloc1,idloc1_boarddet
43 goto backgroundloop_detectors
44 goto backgroundloop_reversers
48 ; called by {master,slave}_init immediately after they've init'd i2c.
52 call points_local_init
53 call polarity_local_init
54 call detect_local_init
57 ;----------------------------------------
64 intrl_handled_routine @
65 mov_ff isr_low_save_stkptr, STKPTR
68 ;======================================================================
71 ;----------------------------------------
73 ; Master-specific initialisation.
78 call polarity_master_init
79 call points_master_init
80 call common_local_init
86 call power_polarising_init
92 ;----------------------------------------
93 master_interrupt_low @
96 call nmra_serialrx_intrl
97 call power_fault_intrl
100 mov_ff IPR1, xdebug+4
101 mov_ff INTCON, xdebug+5
102 call serialtxfc_intrl
104 call points_local_intrl
109 ;----------------------------------------------------------------------
110 serialrx_table_section code 0x2000
112 ;--------------------
113 serialrx_generalmsg @
114 ;command_<something> has same calling convention:
116 ; FSR0 -> start of message undefined
117 ; *FSR0 message undefined
120 bra_n serialrx_if_multibyte
121 bra_z command_crashed
124 bra_z command_power_on
126 bra_z command_power_off
130 serialrx_if_multibyte
131 rr_fw INDF0 ; W = ii MM ww ww ww ww ii ii
132 and_lw 0x3c ; W = zz zz ww ww ww ww zz zz
133 bt_f_if0 PCL, 0 ; always true, but reads PCL
137 goto serialrx_bad ; 1 0000 xxx
138 goto command_ping ; 1 0001 xxx
139 goto command_polarity ; 1 0010 xxx
140 goto serialrx_bad ; 1 0011 xxx
141 goto command_point ; 1 0100 xxx
142 goto serialrx_bad ; 1 0101 xxx
143 goto serialrx_bad ; 1 0110 xxx
144 goto serialrx_bad ; 1 0111 xxx
145 goto serialrx_bad ; 1 1000 xxx
146 goto serialrx_bad ; 1 1001 xxx
147 goto serialrx_bad ; 1 1010 xxx
148 goto serialrx_bad ; 1 1011 xxx
149 goto serialrx_bad ; 1 1100 xxx
150 goto serialrx_bad ; 1 1101 xxx
151 goto serialrx_bad ; 1 1110 xxx
152 goto serialrx_bad ; 1 1111 xxx
160 ;--------------------
166 bra_n command_ping_bad
167 goto serial_addbyte_another
169 command_ping_bad panic morse_HP
171 ;======================================================================
174 ;----------------------------------------
176 ; Slave-specific initialisation.
182 call common_local_init
183 call detect_slave_init
186 ;----------------------------------------
187 slave_interrupt_low @
189 call points_local_intrl
192 ;----------------------------------------
197 ;----------------------------------------
202 bra i2csu_write_if_special
204 bra polarity_local_do
211 i2csu_write_if_special
213 bra i2csu_write_if_bad
214 goto panic_crashread_commanded
217 ;======================================================================
218 ; MASTER/SLAVE deviations
222 ; Either transmits the message to the master, or if we are the master,
223 ; handles it as an incoming message from the notional `slave 0'.
224 ; W message unchanged
226 bt_f_if0 idloc1,idloc1_master
227 goto slave_add_short_message
228 goto loopback_read_byte
230 ;======================================================================