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
17 register_counter res 1
20 ; used in panic macro for temporary storage
21 panic_address res 1 ; stores condensed form of message start addr.
22 panic_morse res 1 ; stores # bytes of morse msg in panic readout
23 panic_regs res 1 ; stores # registers in panic readout
26 ;****************************************************************************
30 ;****************************************************************************
32 ; first, copy the panic message address out of WREG
37 ; switch off interrupts and power
38 ; reconfigure timer0 for writing diagnostic msg to the LED
40 clr_f INTCON ; disable all interrupts EVER
41 bc_f PORTC,1 ; switch off booster
44 ; re-initialise timer0 config
45 bc_f T0CON,6 ; p107 Timer0 -> 16bit mode
46 bc_f T0CON,5 ; timer0 use internal clock
47 bc_f T0CON,3 ; use prescaler
49 bs_f T0CON,1 ; } prescale value 1:16 (13ms x 16)
52 ; get # bytes of morse msg, # registers in panic readout, message start addr.
53 ; back from condensed message start addr. stored in panic_address
60 add_lw (morse_messages_start)/256
64 tblrd *+ ; read 1st byte of error message
65 ; (gives # bytes morse, # bytes registers)
67 mov_ff TABLAT,panic_morse
69 and_wff panic_morse ; panic_morse now contains # bytes of morse msgs
71 mov_ff TABLAT,panic_regs
74 swap_f panic_regs ; panic_regs now contains # registers to read
81 call morsemsg ; transmit SOS in red
87 call registermsg ; transmit contents of registers in
88 ; red(=low) and blue(=high)
91 ;****************************************************************************
95 ; wrapper round readout to flash the per-pic led red for a
96 ; (currently 4-byte) morse msg
99 clr_f morse_counter ; clear loop counter
103 cmp_fw_ifge morse_counter ; if loop counter >=panic_morse
104 return ; return to panic
107 mov_ff TABLAT,flash_pattern
113 ;--------------------------
116 ; Flashes the per-pic led red(0) in a specified pattern.
118 ; The pattern is specified as the state for 8 identically-long time
119 ; periods each as long as a morse `dot', encoded into a byte with
120 ; most significant bit first.
123 ; flash_pattern flash pattern preserved
124 ; bit_counter any undefined
126 clr_f bit_counter ; clear loop counter
131 cmp_fw_ifge bit_counter ; if loop counter >=panic_regs, return
134 rl_f flash_pattern ; top bit goes into N,
136 bra_n morse_readout_if_led_1
138 morse_readout_if_led_0
140 bra morse_readout_endif_led
142 morse_readout_if_led_1
145 morse_readout_endif_led
146 inc_f bit_counter ; increment loop counter
148 bra morse_readout_loop
150 ;--------------------------
151 ;--------------------------
155 clr_f register_counter ; clear loop counter
159 cmp_fw_ifge register_counter ; if loop counter >=panic_regs
160 return ; return to panic
164 mov_fw TABLAT ; TABLAT has the 8-bit version
165 mov_wf FSR0L ; of the address. So, 8 bits
166 ; go straight into FSR0L.
168 mov_lw 0x0f ; For FSR0H, we see if the
169 mov_fw FSR0H ; address XX is >=0x60.
170 ; If it is then we meant 0xfXX;
171 mov_lw 0x5f ; if not then we meant 0x0XX.
172 cmp_fw_ifle FSR0L ; (This is just like PIC does
173 clr_f FSR0H ; for insns using Access Bank)
175 mov_ff INDF0,flash_pattern
176 call register_readout
178 inc_f register_counter ;increment loop counter
184 ;--------------------------
188 ; Flashes the per-pic led red(0) and green(1) in a specified pattern.
189 ; (black gap between each bit)
191 ; The pattern is specified as the state for 8 identically-long time
192 ; periods each as long as a morse `dot', encoded into a byte with
193 ; most significant bit first.
196 ; flash_pattern flash pattern preserved
197 ; bit_counter any undefined
199 clr_f bit_counter ; clear loop counter
203 register_readout_loop
205 cmp_fw_ifge bit_counter ; if loop counter >=8 (register
210 cmp_fw_ifne bit_counter ; if loop counter !=4 (nybble length),
211 ; skip insertion of extra black space
212 goto not_nybble_boundary
216 rlncf flash_pattern,1 ; top bit goes into N flag,
218 bn register_readout_if_led_1
220 register_readout_if_led_0
222 bra register_readout_endif_led
224 register_readout_if_led_1
227 register_readout_endif_led
228 inc_f bit_counter ; increment loop counter
232 bra register_readout_loop
235 ;****************************************************************************
236 ; GENERAL SUBROUTINES
238 ;----------------------------------------
240 ; waits for a fixed interval, depending on the configuration of TMR0
242 bc_f INTCON,2 ; clear timer0 interrupt bit (p109)
243 clr_f TMR0H ; p107 set high byte of timer0 to 0 (buffered,
244 ; only actually set when write to tmr0l occurs)
245 clr_f TMR0L ; set timer0 low byte - timer now set to 0000h
247 bt_f_if0 INTCON,TMR0IF
248 bra loop ; wait for timer0 interrupt
252 ;****************************************************************************