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
15 ; used in panic routine for temporary storage:
19 register_counter res 1
22 panic_address res 1 ; condensed form of message start addr.
23 panic_morse res 1 ; # bytes of morse msg in panic readout
24 panic_regs res 1 ; # registers in panic readout
27 ;****************************************************************************
31 ;****************************************************************************
34 ; switch off interrupts and power
35 ; reconfigure timer0 for writing diagnostic msg to the LED
37 clr_f INTCON ; disable all interrupts EVER
38 bc_f PORTC,1 ; switch off booster
40 ; now we have time to copy the panic message address out of WREG
41 ; (turning off interrupts is urgent (we might get interrupted while
42 ; panicing which would be bad because we might forget to panic).
47 ; re-initialise timer0 config
48 bc_f T0CON,6 ; p107 Timer0 -> 16bit mode
49 bc_f T0CON,5 ; timer0 use internal clock
50 bc_f T0CON,3 ; use prescaler
52 bs_f T0CON,1 ; } prescale value 1:8 (13ms x 8)
55 ; get # bytes of morse msg, # registers in panic readout, message start addr.
56 ; back from condensed message start addr. stored in panic_address
59 mov_lw 4 ; size of each message's details
63 add_lw (morse_messages_start)/256
67 tblrd *+ ; read 1st byte of error message
68 ; (gives # bytes morse, # bytes registers)
70 mov_ff TABLAT,panic_morse
72 and_wff panic_morse ; panic_morse now contains # bytes of morse msgs
74 mov_ff TABLAT,panic_regs
77 swap_f panic_regs ; panic_regs now contains # registers to read
84 call morsemsg ; transmit morse in red
90 call registermsg ; transmit contents of registers in
91 ; red(=low) and blue(=high)
94 ;****************************************************************************
98 ; wrapper round morse_readout to flash the per-pic led red for a morse msg
101 clr_f morse_counter ; clear loop counter
105 cmp_fw_ifge morse_counter ; if loop counter >=panic_morse
106 return ; return to panic
109 mov_ff TABLAT,flash_pattern
115 ;--------------------------
118 ; Flashes the per-pic led and black in a specified pattern.
120 ; The pattern is specified as the state for 8 identically-long time
121 ; periods each as long as a morse `dot', encoded into a byte with
122 ; most significant bit first.
125 ; flash_pattern flash pattern preserved
126 ; bit_counter any undefined
133 dec_f_ifz bit_counter ; done all the bits yet ?
137 rl_f flash_pattern ; top bit goes into N,
139 bra_n morse_readout_if_led_1
141 morse_readout_if_led_0
143 bra morse_readout_endif_led
145 morse_readout_if_led_1
148 morse_readout_endif_led
150 bra morse_readout_loop
152 ;--------------------------
153 ;--------------------------
157 clr_f register_counter ; clear loop counter
161 cmp_fw_ifge register_counter ; if loop counter >=panic_regs
162 return ; return to panic
166 mov_fw TABLAT ; TABLAT has the 8-bit version
167 mov_wf FSR0L ; of the address. So, 8 bits
168 ; go straight into FSR0L.
170 mov_lw 0x0f ; For FSR0H, we see if the
171 mov_fw FSR0H ; address XX is >=0x60.
172 ; If it is then we meant 0xfXX;
173 mov_lw 0x5f ; if not then we meant 0x0XX.
174 cmp_fw_ifle FSR0L ; (This is just like PIC does
175 clr_f FSR0H ; for insns using Access Bank)
177 mov_ff INDF0,flash_pattern
178 call register_readout
180 inc_f register_counter ;increment loop counter
186 ;--------------------------
190 ; Flashes the per-pic led red(0) and green(1) in a specified pattern.
191 ; (black gap between each bit)
193 ; The pattern is specified as the state for 8 identically-long time
194 ; periods each as long as a morse `dot', encoded into a byte with
195 ; most significant bit first.
198 ; flash_pattern flash pattern preserved
199 ; bit_counter any undefined
201 clr_f bit_counter ; clear loop counter
205 register_readout_loop
207 cmp_fw_ifge bit_counter ; if loop counter >=8 (register
212 cmp_fw_ifne bit_counter ; if loop counter !=4 (nybble length),
213 ; skip insertion of extra black space
214 goto not_nybble_boundary
218 rl_f flash_pattern ; top bit goes into N flag,
220 bra_n register_readout_if_led_1
222 register_readout_if_led_0
224 bra register_readout_endif_led
226 register_readout_if_led_1
229 register_readout_endif_led
230 inc_f bit_counter ; increment loop counter
234 bra register_readout_loop
237 ;****************************************************************************
238 ; GENERAL SUBROUTINES
240 ;----------------------------------------
242 ; waits for a fixed interval, depending on the configuration of TMR0
244 bc_f INTCON,2 ; clear timer0 interrupt bit (p109)
245 clr_f TMR0H ; p107 set high byte of timer0 to 0 (buffered,
246 ; only actually set when write to tmr0l occurs)
247 clr_f TMR0L ; set timer0 low byte - timer now set to 0000h
249 bt_f_if0 INTCON,TMR0IF
250 bra waiting_loop ; wait for timer0 interrupt
254 ;****************************************************************************