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 ;----------------------------------------
62 mov_ff isr_low_save_stkptr, STKPTR
65 ;======================================================================
68 ;----------------------------------------
70 ; Master-specific initialisation.
73 call polarity_master_init
74 call points_master_init
75 call common_local_init
83 ;----------------------------------------
87 call nmra_serialrx_intrl
89 call points_local_intrl
94 master_interrupt_high_notnmra
97 ;----------------------------------------------------------------------
98 serialrx_table_section code 0x2000
100 ;--------------------
102 ;command_<something> has same calling convention:
104 ; FSR0 -> start of message undefined
105 ; *FSR0 message undefined
107 ; ; INDF0=MM ww ww ww ww ii ii ii
108 rlc_fw INDF0 ; W = ww ww ww ww ii ii ii ?? C=MM Z=00
109 bra_c serialrx_if_multibyte
110 bra_z command_crashed
111 ; single-byte non-0 command, has to be ON or OFF
112 ; ie supposedly ; INDF0=zz zz II zz zz zz zz PP C=zz
113 rrc_fw INDF0 ; W = zz zz zz II zz zz zz zz C=PP
114 xor_lw 0x10 ; W = zz zz zz zz zz zz zz zz C=PP Z=OK
119 serialrx_if_multibyte
120 rr_fw INDF0 ; W = ii MM ww ww ww ww ii ii
121 and_lw 0x3c ; W = zz zz ww ww ww ww zz zz
122 bt_f_if0 PCL, 0 ; always true, but reads PCL
126 goto serialrx_bad ; 1 0000 xxx
127 goto command_ping ; 1 0001 xxx
128 goto command_polarity ; 1 0010 xxx
129 goto serialrx_bad ; 1 0011 xxx
130 goto command_point ; 1 0100 xxx
131 goto serialrx_bad ; 1 0101 xxx
132 goto serialrx_bad ; 1 0110 xxx
133 goto serialrx_bad ; 1 0111 xxx
134 goto serialrx_bad ; 1 1000 xxx
135 goto serialrx_bad ; 1 1001 xxx
136 goto serialrx_bad ; 1 1010 xxx
137 goto serialrx_bad ; 1 1011 xxx
138 goto serialrx_bad ; 1 1100 xxx
139 goto serialrx_bad ; 1 1101 xxx
140 goto serialrx_bad ; 1 1110 xxx
141 goto serialrx_bad ; 1 1111 xxx
143 goto serialrx_bad ; 0 0000 xxx
144 goto serialrx_bad ; 0 0001 xxx
145 goto serialrx_bad ; 0 0000 xxx
152 ;--------------------
158 bra_n command_ping_bad
159 goto serial_addbyte_another
161 command_ping_bad panic morse_HP
163 ;--------------------
167 ;======================================================================
170 ;----------------------------------------
172 ; Slave-specific initialisation.
178 call common_local_init
179 call detect_slave_init
182 ;----------------------------------------
185 call points_local_intrl
188 ;----------------------------------------
193 ;----------------------------------------
198 bra i2csu_write_if_special
200 bra polarity_local_do
207 i2csu_write_if_special
209 bra i2csu_write_if_bad
210 goto panic_crashread_commanded
213 ;======================================================================
214 ; MASTER/SLAVE deviations
218 ; Either transmits the message to the master, or if we are the master,
219 ; handles it as an incoming message from the notional `slave 0'.
220 ; W message unchanged
222 bt_f_if0 idloc1,idloc1_master
223 goto slave_add_short_message
224 goto loopback_read_byte
226 ;======================================================================