From: ian Date: Sun, 20 Nov 2005 00:04:21 +0000 (+0000) Subject: fixes and changes from code review X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=1c858ec502540aef1a83f0ae49153d43503be6de;p=trains.git fixes and changes from code review --- diff --git a/detpic/panic.asm b/detpic/panic.asm index 9f30685..29bf2c9 100644 --- a/detpic/panic.asm +++ b/detpic/panic.asm @@ -12,15 +12,16 @@ udata_acs +; used in panic routine for temporary storage: + flash_pattern res 1 morse_counter res 1 register_counter res 1 bit_counter res 1 -; used in panic macro for temporary storage -panic_address res 1 ; stores condensed form of message start addr. -panic_morse res 1 ; stores # bytes of morse msg in panic readout -panic_regs res 1 ; stores # registers in panic readout +panic_address res 1 ; condensed form of message start addr. +panic_morse res 1 ; # bytes of morse msg in panic readout +panic_regs res 1 ; # registers in panic readout ;**************************************************************************** @@ -29,10 +30,6 @@ panic_regs res 1 ; stores # registers in panic readout ;**************************************************************************** -; first, copy the panic message address out of WREG - - mov_wf panic_address - panic_routine ; switch off interrupts and power ; reconfigure timer0 for writing diagnostic msg to the LED @@ -40,6 +37,12 @@ panic_routine clr_f INTCON ; disable all interrupts EVER bc_f PORTC,1 ; switch off booster +; now we have time to copy the panic message address out of WREG +; (turning off interrupts is urgent (we might get interrupted while +; panicing which would be bad because we might forget to panic). + + mov_wf panic_address + ; re-initialise timer0 config bc_f T0CON,6 ; p107 Timer0 -> 16bit mode @@ -53,7 +56,7 @@ panic_routine ; back from condensed message start addr. stored in panic_address panic_loop - mov_lw 4 + mov_lw 4 ; size of each message's details mul_wf panic_address mov_ff PRODL,TBLPTRL mov_ff PRODH,WREG @@ -78,7 +81,7 @@ panic_loop call waiting call waiting call waiting - call morsemsg ; transmit SOS in red + call morsemsg ; transmit morse in red call led_black call waiting call waiting @@ -92,8 +95,7 @@ panic_loop ; PANIC SUBROUTINES morsemsg -; wrapper round readout to flash the per-pic led red for a -; (currently 4-byte) morse msg +; wrapper round morse_readout to flash the per-pic led red for a morse msg morse_msg_start clr_f morse_counter ; clear loop counter @@ -113,7 +115,7 @@ morse_loop ;-------------------------- morse_readout -; Flashes the per-pic led red(0) in a specified pattern. +; Flashes the per-pic led and black in a specified pattern. ; ; The pattern is specified as the state for 8 identically-long time ; periods each as long as a morse `dot', encoded into a byte with @@ -123,13 +125,14 @@ morse_readout ; flash_pattern flash pattern preserved ; bit_counter any undefined - clr_f bit_counter ; clear loop counter + mov_lw 8 + mov_wf bit_counter rr_f flash_pattern morse_readout_loop - mov_fw panic_regs - cmp_fw_ifge bit_counter ; if loop counter >=panic_regs, return + dec_f_ifz bit_counter ; done all the bits yet ? return + ; No: rl_f flash_pattern ; top bit goes into N, ;ie Negative if 1 @@ -143,8 +146,6 @@ morse_readout_if_led_1 call led_red morse_readout_endif_led - inc_f bit_counter ; increment loop counter - call waiting bra morse_readout_loop ;-------------------------- @@ -201,21 +202,21 @@ register_readout register_readout_loop - movlw 8 + mov_lw 8 cmp_fw_ifge bit_counter ; if loop counter >=8 (register ; length), return return - movlw 4 + mov_lw 4 cmp_fw_ifne bit_counter ; if loop counter !=4 (nybble length), ; skip insertion of extra black space goto not_nybble_boundary call waiting not_nybble_boundary - rlncf flash_pattern,1 ; top bit goes into N flag, + rl_f flash_pattern ; top bit goes into N flag, ; ie Negative if 1 - bn register_readout_if_led_1 + bra_n register_readout_if_led_1 register_readout_if_led_0 call led_red @@ -243,9 +244,9 @@ waiting clr_f TMR0H ; p107 set high byte of timer0 to 0 (buffered, ; only actually set when write to tmr0l occurs) clr_f TMR0L ; set timer0 low byte - timer now set to 0000h -loop +waiting_loop bt_f_if0 INTCON,TMR0IF - bra loop ; wait for timer0 interrupt + bra waiting_loop ; wait for timer0 interrupt return