1 ;======================================================================
2 ; MAIN PROGRAM AND GLUE
7 ;======================================================================
8 ; COMMON TO MASTER AND SLAVE
10 ;----------------------------------------
26 bs_f RCON, IPEN ; interrupt priorities
30 bt_f_if0 idloc1,idloc1_master
33 bt_f_if1 idloc1,idloc1_master
39 bt_f_if1 idloc1,idloc1_boarddet
40 goto backgroundloop_detectors
41 goto backgroundloop_reversers
45 ; called by {master,slave}_init immediately after they've init'd i2c.
49 call points_local_init
50 call polarity_local_init
51 call detect_local_init
54 ;----------------------------------------
59 mov_ff isr_low_save_stkptr, STKPTR
62 ;======================================================================
65 ;----------------------------------------
67 ; Master-specific initialisation.
69 call common_local_init
74 ;----------------------------------------
78 call nmra_serialrx_intrl
80 ;call points_local_intrl
85 master_interrupt_high_notnmra
88 ;----------------------------------------------------------------------
89 serialrx_table_section code 0x2000
93 ;command_<something> has same calling convention:
95 ; FSR0 -> start of message undefined
96 ; *FSR0 message undefined
98 ; ; INDF0=MM ww ww ww ww ii ii ii
99 rlc_fw INDF0 ; W = ww ww ww ww ii ii ii ?? C=MM Z=00
100 bra_c serialrx_if_multibyte
101 bra_z command_crashed
102 ; single-byte non-0 command, has to be ON or OFF
103 ; ie supposedly ; INDF0=zz zz II zz zz zz zz PP C=zz
104 rrc_fw INDF0 ; W = zz zz zz II zz zz zz zz C=PP
105 xor_lw 0x10 ; W = zz zz zz zz zz zz zz zz C=PP Z=OK
110 serialrx_if_multibyte
111 rr_fw INDF0 ; W = ii MM ww ww ww ww ii ii
112 and_lw 0x3c ; W = zz zz ww ww ww ww zz zz
113 bt_f_if0 PCL, 0 ; always true, but reads PCL
117 goto serialrx_bad ; 1 0000 xxx
118 goto command_ping ; 1 0001 xxx
119 goto command_polarity ; 1 0010 xxx
120 goto serialrx_bad ; 1 0011 xxx
121 goto command_point ; 1 0100 xxx
122 goto serialrx_bad ; 1 0101 xxx
123 goto serialrx_bad ; 1 0110 xxx
124 goto serialrx_bad ; 1 0111 xxx
125 goto serialrx_bad ; 1 1000 xxx
126 goto serialrx_bad ; 1 1001 xxx
127 goto serialrx_bad ; 1 1010 xxx
128 goto serialrx_bad ; 1 1011 xxx
129 goto serialrx_bad ; 1 1100 xxx
130 goto serialrx_bad ; 1 1101 xxx
131 goto serialrx_bad ; 1 1110 xxx
132 goto serialrx_bad ; 1 1111 xxx
134 goto serialrx_bad ; 0 0000 xxx
135 goto serialrx_bad ; 0 0001 xxx
136 goto serialrx_bad ; 0 0000 xxx
143 ; bra_z crashed_master_do
145 ; bra_z crashed_master_do
147 ; serialrx_check 0x00, 0x21, command_power_on
148 ; serialrx_check 0x21, 0x20, command_power_off
150 ; and_lw 0xf8 ; W^0x20 = MM ww ww ww ww zz zz zz
152 ; serialrx_check 0x00, 0xa0, point_master_do
153 ; serialrx_check 0xa0, 0x88, ping_master_do
154 ; serialrx_check 0x88, 0x90, polarity_master_do
156 ; serialrx_check 0x90, 0x90, polarity_master_do
158 ; mov_wf t ; t = MM ww ww ww ww zz zz zz
164 ;--------------------
170 ;======================================================================
173 ;----------------------------------------
175 ; Slave-specific initialisation.
181 call common_local_init
182 call detect_slave_init
185 ;----------------------------------------
188 call points_local_intrl
191 ;----------------------------------------
196 ;----------------------------------------
200 bt_f_if1 picno,picno_panicd
201 goto i2csu_write_panicd
204 bra i2csu_write_if_special
206 bra polarity_local_do
213 i2csu_write_if_special
215 bra i2csu_write_if_bad
216 goto panic_crashread_commanded
219 ;======================================================================
220 ; MASTER/SLAVE deviations
224 ; Either transmits the message to the master, or if we are the master,
225 ; handles it as an incoming message from the notional `slave 0'.
226 ; W message unchanged
228 bt_f_if0 idloc1,idloc1_master
229 goto slave_add_short_message
230 goto loopback_read_byte
232 ;======================================================================