1 ;======================================================================
6 ;======================================================================
7 ; VARIABLES, HARDWARE, ETC
9 ; Timer 3 pointmsg pointslave cducharging
11 ; S Idle Off undefined undefined undefined
12 ; S Firing Counting up 100PPPPP undefined undefined
13 ; M Idle Off 00000000 0000 0000 0x00
14 ; M Firing Counting up 100PPPPP 0000 0000 0x00
15 ; M Telling Off 100PPPPP 00SS Sss0 0x00
16 ; M Told Off 100PPPPP 0000 0000 0x00
17 ; M Charging Off 00000000 0000 0000 >0
19 ; notes: firing see ie, slave*2 Counts down
20 ; timeout detect.asm in ticks
22 ; cducharging only counts if the cdu is enabled
23 ; (according to CDU Enable LAT bit)
25 cdu_timeout equ 300 ; ms
26 cdu_inittimeout equ 750 ; ms
28 ptix2latbit equ 0x300 ; has to be a multiple of 0x100
29 ptix2latbit_section udata ptix2latbit
30 res maxpoints * 2 ; as produced by outpin_local_init
38 slave2ptinfo res maxpics
39 slave2ptinfo_anypoints equ 0
41 ;======================================================================
43 ; on slave, or master's own
45 ;----------------------------------------------------------------------
46 ; LOCAL POINTS - ACTUALLY DOING
49 ;----------------------------------------
51 ; On slave, called during i2c receive, ie High ISR
52 ; On master, called during serial receive, ie Low ISR
53 ; W fire point msg undefined
54 bt_f_if1 T3CON, TMR3ON
57 mov_wf pointmsg ; pointmsg = SS zz zz pp pp pp pp pp
59 intrlh_fsr0_save ; point_set_pin uses FSR0, see below
63 clr_f TMR3L ; also copies TMR3H into actual timer register
72 ;----------------------------------------
76 ; OK, it's us, and we're done changing a point:
78 bt_f_if0 T3CON, TMR3ON
79 bra point_spurious_intr
88 call message_for_master
97 ; Toggles the pin. The effect is:
98 ; If we were idle, sets it H (to fire) unless pt0 in which case L
99 ; If we were firing, sets it L (to stop) unless pt0 in which case H
101 ; Called in various contexts, including both High and Low ISR.
103 ; pointmsg point to start or stop firing preserved
104 ; W,STATUS any undefined
106 ; all other any not interfered with
108 mov_lw ptix2latbit >> 8
109 mov_wf FSR0H ; FSR0H -> table
110 rl_fw pointmsg ; W = point addr, Z iff pt0
111 mov_wf FSR0L ; FSR0 -> &bit [Z still iff pt0]
112 mov_fw POSTDEC0 ; W = bit, FSR0 -> &LAT*
113 bra_z point_nonexistent
114 mov_ff INDF0, FSR0L ; W = bit, FSR0L -> LAT*
115 set_f FSR0H ; FSR0 -> LAT*, W = bit (still)
116 xor_wff INDF0 ; pin = !pin
123 ;----------------------------------------------------------------------
124 ; LOCAL POINTS - INITIALISATION
126 ;----------------------------------------
128 ; Initialises tables for points
129 ; Clears TRIS* bits for all points and sets each pin to `not triggering'
131 rcall point_timer_init
133 outputs_local_init picno2ptmap, maxpoints, ptix2latbit, bkptix2portnumbitnum
139 bt_f_if1 idloc1,idloc1_master
140 bra point_timer_init_if_master
142 mov_lw (1<<RD16)|(1<<T3ECCP1)| points_slave_t3scale; Fcy;!TMR3ON
144 mov_lw points_slave_t3inith
145 bra point_timer_init_endif_masterslave
146 point_timer_init_if_master
147 mov_lw (1<<RD16)|(1<<T3ECCP1)| points_master_t3scale; Fcy;!TMR3ON
149 mov_lw points_master_t3inith
150 point_timer_init_endif_masterslave
151 mov_wf TMR3H ; We just leave this here.
152 ; Since we never read TMR3L, it is never overwritten
159 ;======================================================================
162 ;----------------------------------------------------------------------
167 load_tblptr picno2ptmap
168 mov_lfsr slave2ptinfo-1, 0
171 points_master_init_board_loop
174 points_master_init_byte_loop
177 bs_f INDF0, slave2ptinfo_anypoints
179 bra points_master_init_byte_loop
181 bra points_master_init_board_loop
185 ;----------------------------------------------------------------------
187 ; FSR0 -> 1 0100 TTT O TTTTTTT
191 bra command_point_busy
193 tst_f_ifnz cducharging
194 bra command_point_cduempty
196 swap_fw POSTINC0 ; W = 0SSS 1010
197 and_lw 0x70 ; W = 0SSS 0000
199 mov_wf pointslave ; pointslave = 00SS S000
201 mov_fw INDF0 ; W = OssT tttt N = O
202 bra_n command_point_badmsg
203 ; OK: ; W = 0ssT tttt
204 and_lw 0x1f ; W = 000T tttt
205 bs_w 7 ; W = 100T tttt
206 mov_wf pointmsg ; pointmsg = 100T tttt
208 swap_fw INDF0 ; W = tttt 0ssT
209 and_lw 0x06 ; W = 0000 0ss0
210 ior_wff pointslave ; pointslave = 00SS Sss0
212 rr_fw pointslave ; W = 000S SSss
213 bra_nz command_point_ifslave
218 command_point_badmsg panic morse_PX
219 command_point_busy panic morse_PB
220 command_point_cduempty panic morse_PC
223 command_point_ifslave
224 mov_lfsr slave2ptinfo, 0
226 bt_f_if1 INDF0, slave2ptinfo_anypoints
233 rr_fw pointslave ; W = 000S SSss
234 bt_f_if1 STATUS, Z ; nothing ?
236 ; we need to write something:
241 points_getwritebyte @
244 bt_f_if0 STATUS, Z ; right slave ?
247 clr_f pointslave ; we're writing now, excellent
249 goto i2c_getwritebyte_yes
251 ;======================================================================
254 ;--------------------
261 mov_lw (cdu_inittimeout * 1000) / tickdiv_us + 1
269 mov_lw (cdu_timeout * 1000) / tickdiv_us + 1
273 ;--------------------
278 ;--------------------
280 pinlat_ifl p0_cdu_enable
283 tst_f_ifnz cducharging
284 dec_f_ifnz cducharging ; so, decrement only if it was nonzero
285 return ; return if we either didn't decrement,
286 ; or didn't reach zero
288 ; cducharging is already zero, from above
289 mov_lw b'00101000' ; CHARGED
293 ;--------------------
295 tst_f_ifnz cducharging
296 return ; presumably we just turned off
299 bra pointed_butnot_firing
303 mov_lw b'00100000' ; POINTED
306 pointed_butnot_firing panic morse_PA
308 ;======================================================================