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)
69 dw 0xffff ; silicon errata: B4 issue 4
71 mov_ff TABLAT,panic_morse
73 and_wff panic_morse ; panic_morse now contains # bytes of morse msgs
75 mov_ff TABLAT,panic_regs
78 swap_f panic_regs ; panic_regs now contains # registers to read
89 call morsemsg ; transmit morse in red
95 call registermsg ; transmit contents of registers in
96 ; red(=low) and blue(=high)
99 ;****************************************************************************
103 ; wrapper round morse_readout to flash the per-pic led red for a morse msg
106 clr_f morse_counter ; clear loop counter
110 cmp_fw_ifge morse_counter ; if loop counter >=panic_morse
111 return ; return to panic
114 mov_ff TABLAT,flash_pattern
120 ;--------------------------
123 ; Flashes the per-pic led and black in a specified pattern.
125 ; The pattern is specified as the state for 8 identically-long time
126 ; periods each as long as a morse `dot', encoded into a byte with
127 ; most significant bit first.
130 ; flash_pattern flash pattern preserved
131 ; bit_counter any undefined
138 dec_f_ifz bit_counter ; done all the bits yet ?
142 rl_f flash_pattern ; top bit goes into N,
144 bra_n morse_readout_if_led_1
146 morse_readout_if_led_0
148 bra morse_readout_endif_led
150 morse_readout_if_led_1
153 morse_readout_endif_led
155 bra morse_readout_loop
157 ;--------------------------
158 ;--------------------------
162 clr_f register_counter ; clear loop counter
166 cmp_fw_ifge register_counter ; if loop counter >=panic_regs
167 return ; return to panic
171 mov_fw TABLAT ; TABLAT has the 8-bit version
172 mov_wf FSR0L ; of the address. So, 8 bits
173 ; go straight into FSR0L.
175 mov_lw 0x0f ; For FSR0H, we see if the
176 mov_fw FSR0H ; address XX is >=0x60.
177 ; If it is then we meant 0xfXX;
178 mov_lw 0x5f ; if not then we meant 0x0XX.
179 cmp_fw_ifle FSR0L ; (This is just like PIC does
180 clr_f FSR0H ; for insns using Access Bank)
182 mov_ff INDF0,flash_pattern
183 call register_readout
185 inc_f register_counter ;increment loop counter
191 ;--------------------------
195 ; Flashes the per-pic led red(0) and green(1) in a specified pattern.
196 ; (black gap between each bit)
198 ; The pattern is specified as the state for 8 identically-long time
199 ; periods each as long as a morse `dot', encoded into a byte with
200 ; most significant bit first.
203 ; flash_pattern flash pattern preserved
204 ; bit_counter any undefined
206 clr_f bit_counter ; clear loop counter
210 register_readout_loop
212 cmp_fw_ifge bit_counter ; if loop counter >=8 (register
217 cmp_fw_ifne bit_counter ; if loop counter !=4 (nybble length),
218 ; skip insertion of extra black space
219 goto not_nybble_boundary
223 rl_f flash_pattern ; top bit goes into N flag,
225 bra_n register_readout_if_led_1
227 register_readout_if_led_0
229 bra register_readout_endif_led
231 register_readout_if_led_1
234 register_readout_endif_led
235 inc_f bit_counter ; increment loop counter
239 bra register_readout_loop
242 ;****************************************************************************
243 ; GENERAL SUBROUTINES
245 ;----------------------------------------
247 ; waits for a fixed interval, depending on the configuration of TMR0
249 bc_f INTCON,2 ; clear timer0 interrupt bit (p109)
250 clr_f TMR0H ; p107 set high byte of timer0 to 0 (buffered,
251 ; only actually set when write to tmr0l occurs)
252 clr_f TMR0L ; set timer0 low byte - timer now set to 0000h
254 bt_f_if0 INTCON,TMR0IF
255 bra waiting_loop ; wait for timer0 interrupt
259 ;****************************************************************************