1 ;======================================================================
4 ; This file implements panic_routine, which is called by the
5 ; `panic' macro in panic.inc. See panic.inc for the functionality
10 ;---------------------------------------------------------------------------
11 ; reserved access bank locations
29 panic_vars_section udata 0x060 ; not available via access bank
31 ; used in panic routine for temporary storage:
35 register_counter res 1
38 panic_address res 1 ; condensed form of message start addr.
39 panic_morse res 1 ; # bytes of morse msg in panic readout
40 panic_regs res 1 ; # registers in panic readout
45 ;****************************************************************************
49 ;****************************************************************************
52 ; switch off interrupts and power
53 ; reconfigure timer0 for writing diagnostic msg to the LED
55 mov_ff INTCON, psave_intcon
56 clr_f INTCON ; disable all interrupts EVER
61 mov_ff LATC, psave_latc
65 ; now we have time to copy the panic message address out of WREG
66 ; (turning off interrupts is urgent (we might get interrupted while
67 ; panicing which would be bad because we might forget to panic).
70 clr_f STKPTR ; avoids stack overruns
73 mov_ff TABLAT, psave_tablat
74 mov_ff TBLPTRL, psave_tblptr
75 mov_ff TBLPTRH, psave_tblptr+1
76 mov_ff TBLPTRU, psave_tblptr+2
77 mov_ff FSR0L, psave_fsr0
78 mov_ff FSR0H, psave_fsr0+1
79 mov_ff FSR1L, psave_fsr1
80 mov_ff FSR1H, psave_fsr1+1
81 mov_ff PRODL, psave_prod
82 mov_ff PRODH, psave_prod+1
88 ; re-initialise timer0 config
90 bra_z panic_setup_if_master
92 morse_t0setup sclock, (1<<TMR0ON), t0l_count, t0h_count
93 bra panic_setup_endif_masterslave
95 morse_t0setup mclock, (1<<TMR0ON), t0l_count, t0h_count
96 panic_setup_endif_masterslave
98 ; get # bytes of morse msg, # registers in panic readout, message start addr.
99 ; back from condensed message start addr. stored in panic_address
102 mov_lw 4 ; size of each message's details
106 add_lw (morse_messages_start)/256
110 tblrd *+ ; read 1st byte of error message
111 ; (gives # bytes morse, # bytes registers)
112 dw 0xffff ; silicon errata: B4 issue 4
114 mov_ff TABLAT,panic_morse
116 and_wff panic_morse ; panic_morse now contains # bytes of morse msgs
118 mov_ff TABLAT,panic_regs
121 swap_f panic_regs ; panic_regs now contains # registers to read
125 rcall morsemsg ; transmit morse in red
129 rcall registermsg ; transmit contents of registers in
130 ; red(=low) and blue(=high)
134 ;****************************************************************************
138 ; wrapper round morse_readout to flash the per-pic led red for a morse msg
141 clr_f morse_counter ; clear loop counter
145 cmp_fw_ifge morse_counter ; if loop counter >=panic_morse
146 return ; return to panic
149 mov_ff TABLAT,flash_pattern
155 ;--------------------------
158 ; Flashes the per-pic led and black in a specified pattern.
160 ; The pattern is specified as the state for 8 identically-long time
161 ; periods each as long as a morse `dot', encoded into a byte with
162 ; most significant bit first.
165 ; flash_pattern flash pattern preserved
166 ; bit_counter any undefined
173 dec_f_ifz bit_counter ; done all the bits yet ?
177 rl_f flash_pattern ; top bit goes into N,
179 bra_n morse_readout_if_led_1
181 morse_readout_if_led_0
183 bra morse_readout_endif_led
185 morse_readout_if_led_1
188 morse_readout_endif_led
190 bra morse_readout_loop
192 ;--------------------------
193 ;--------------------------
197 clr_f register_counter ; clear loop counter
201 cmp_fw_ifge register_counter ; if loop counter >=panic_regs
202 return ; return to panic
206 mov_fw TABLAT ; TABLAT has the 8-bit version
207 mov_wf FSR0L ; of the address. So, 8 bits
208 ; go straight into FSR0L.
210 mov_lw 0x0f ; For FSR0H, we see if the
211 mov_fw FSR0H ; address XX is >=0x60.
212 ; If it is then we meant 0xfXX;
213 mov_lw 0x5f ; if not then we meant 0x0XX.
214 cmp_fw_ifle FSR0L ; (This is just like PIC does
215 clr_f FSR0H ; for insns using Access Bank)
217 mov_ff INDF0,flash_pattern
218 rcall register_readout
220 inc_f register_counter ;increment loop counter
225 ;--------------------------
229 ; Flashes the per-pic led red(0) and green(1) in a specified pattern.
230 ; (black gap between each bit)
232 ; The pattern is specified as the state for 8 identically-long time
233 ; periods each as long as a morse `dot', encoded into a byte with
234 ; most significant bit first.
237 ; flash_pattern flash pattern preserved
238 ; bit_counter any undefined
240 clr_f bit_counter ; clear loop counter
244 register_readout_loop
246 cmp_fw_ifge bit_counter ; if loop counter >=8 (register
251 cmp_fw_ifne bit_counter ; if loop counter !=4 (nybble length),
252 ; skip insertion of extra black space
253 bra not_nybble_boundary
257 rl_f flash_pattern ; top bit goes into N flag,
259 bra_n register_readout_if_led_1
261 register_readout_if_led_0
263 bra register_readout_endif_led
265 register_readout_if_led_1
268 register_readout_endif_led
269 inc_f bit_counter ; increment loop counter
273 bra register_readout_loop
276 ;****************************************************************************
277 ; GENERAL SUBROUTINES
279 ;----------------------------------------
280 waiting16 rcall waiting8
281 waiting8 rcall waiting4
282 waiting4 rcall waiting2
283 waiting2 rcall waiting
285 ; waits for a fixed interval, depending on the configuration of TMR0
287 bc_f INTCON,2 ; clear timer0 interrupt bit (p109)
288 ; Interrupt happens on overflow. So start at 65535-morse_t0cycles:
290 mov_wf TMR0H ; p107 set high byte of timer0 (buffered,
291 ; only actually set when write to tmr0l occurs)
293 mov_wf TMR0L ; set timer0 low byte - timer now set
294 waiting_loop ; wait for timer0 interrupt, or some other interrupt
295 bt_f_if1 INTCON,TMR0IF
298 bt_f_if0 SSPCON1, SSPEN
299 bra waiting_loop ; no readouts if i2c is disabled
301 bt_f_if1 idloc1, idloc1_master
302 bra waiting_loop ; no readouts on master yet
304 call i2cs_interrupt ; check for i2c interrupt
309 ;****************************************************************************
314 panicd_process_input_byte
315 ; W instruction from host or master
318 ; we've received 0x00:
321 bs_f panicst, panicst_acked
326 bt_f_if0 panicst, panicst_acked ; well, ignore that !
328 ; OK, we have an instruction:
333 bra write_if_setpointer
334 bt_f_if0 idloc1,idloc1_master
335 return ; all the remaining options are for master only
337 ;nyi bra write_if_selectslave
339 ;nyi bra write_if_readout
355 i2csu_read_begin_panicd
356 mov_lw 0x80 ; M0000000
357 bt_f_if0 panicst, panicst_acked
365 i2csu_read_another_panicd
366 bt_f_if1 panicst, panicst_acked
367 bra i2csu_read_panicd_ok
372 ;***************************************************************************