From: ian Date: Mon, 19 Dec 2005 19:04:51 +0000 (+0000) Subject: isr register use fixes (particularly for _local_do, which have strange calling... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=2c573da294ef20c191d4e7e8d91d17f32f6b4de0;p=trains.git isr register use fixes (particularly for _local_do, which have strange calling convention; fixed points so we think they might work --- diff --git a/detpic/common.inc b/detpic/common.inc index 4807c88..9e2dc31 100644 --- a/detpic/common.inc +++ b/detpic/common.inc @@ -30,6 +30,7 @@ clock equ -1 ; FSR0 Low ISR Low ISR ; PCLATU Always set to 0 Not used ; PCLATH Low ISR Not used +; t_dolocal Low ISR High ISR ; FSR1 Low ISR High ISR (detect[1]) ; FSR2 Low ISR High ISR (detect[1]) ; @@ -40,7 +41,7 @@ clock equ -1 ; interrupt, or any routine run during initialisation. ; May therefore not be used in background loop with ; interrupts enabled. May not be used by high-priority -; ISR (unless explicitly saved). +; ISR (unless explicitly saved, eg isrh_fsr0_{save,restore}). ; ; High ISR May be used/trashed by any routine run in high-priority ; interrupt, or any routine run during initialisation. @@ -84,8 +85,9 @@ clock equ -1 ; Conventional routine names: ; ; _local_do Process a master-to-slave command to activate -; a local peripheral (also called on master to -; activate its own local peripherals) +; a local peripheral, in High ISR. Also called +; on master in Low ISR to activate its own +; local peripherals. NB strange calling convention! ; ; _local_init Initialises RAM tables for local peripheral ; and arranges for pins to be set in appropriate @@ -94,7 +96,7 @@ clock equ -1 ; ; _local_intrl Low ISR service routine for peripheral (see below). ; -; _master_do Called when an appropriate message has been +; command_ Called when an appropriate message has been ; received from the host. ; ; _intrl Low ISR service routine. @@ -118,6 +120,16 @@ enter_interrupt_low macro mov_ff STKPTR, isr_low_save_stkptr endm +intrh_fsr0_save macro + mov_ff FSR0L, isr_high_save_fsr0 + mov_ff FSR0H, isr_high_save_fsr0+1 + endm + +intrh_fsr0_restore macro + mov_ff isr_high_save_fsr0, FSR0L + mov_ff isr_high_save_fsr0+1, FSR0H + endm + intrl_handled_core macro ; for internal use only mov_fw isr_low_save_w mov_ff isr_low_save_status, STATUS @@ -140,11 +152,11 @@ intrl_handled macro ; GIEH modified appropriately ; everything else preserved -mask_int_high macro +intrh_mask macro bc_f INTCON,GIEH endm -unmask_int_high macro +intrh_unmask macro bs_f INTCON,GIEH endm diff --git a/detpic/detect.asm b/detpic/detect.asm index 62263a2..7560b96 100644 --- a/detpic/detect.asm +++ b/detpic/detect.asm @@ -147,10 +147,10 @@ slave_add_short_message ; It will be transmitted as an extra message byte, when we are polled. ; W message unchanged ; GIEH set set - mask_int_high - bs_f POSTINC1,7 - mov_wf INDF1 - unmask_int_high + intrh_mask + bs_f INDF1,7 + mov_wf PREINC1 + intrh_unmask return ;---------- @@ -317,8 +317,7 @@ reset_detectread ; unattended* any reset ; Per-PIC LED any black ; may be called from High ISR or during init - mov_lfsr message_buffer, 1 - clr_f INDF1 + mov_lfsr buf0, 1 call led_black diff --git a/detpic/points.asm b/detpic/points.asm index e5dfe16..df003b2 100644 --- a/detpic/points.asm +++ b/detpic/points.asm @@ -10,9 +10,9 @@ ; Timer 3 Off On, counting up ; pointmsg undefined message from master -ptix2bitlat equ 0x300 -ptix2bitlat_section udata ptix2bitlat - res maxpoints * 2 ; bit and LAT* +ptix2latbit equ 0x300 ; has to be a multiple of 0x100 +ptix2latbit_section udata ptix2latbit + res maxpoints * 2 ; LAT* and bit ; for unused point, 0x00 and 0x00 udata_acs @@ -37,11 +37,13 @@ point_local_do bra point_clash mov_wf pointmsg ; pointmsg = SS zz zz pp pp pp pp pp + + intrh_fsr0_save ; point_set_pin uses FSR0, see below rcall point_set_pin + intrh_fsr0_restore clr_f TMR3L ; also copies TMR3H into actual timer register bs_f T3CON, TMR3ON - panic morse_UP return ;---------------------------------------- @@ -54,10 +56,10 @@ points_local_intrl bra point_spurious_intr rcall point_set_pin - mask_int_high + intrh_mask bc_f T3CON, TMR3ON bc_f PIR2, TMR3IF - unmask_int_high + intrh_unmask mov_lw b'00100000' call message_for_master @@ -71,8 +73,17 @@ point_spurious_intr point_set_pin ; Sets the pin appropriately: ; If we were idle, sets it H (to fire) unless pt0 in which case L -; If we were firing, sets it L (to stop) unless pt0 in which case H - mov_lw ptix2bitlat >> 8 +; If we were firing, sets it L (to stop) unless pt0 in which case +; +; Called in various contexts, including both High and Low ISR. +; +; pointmsg point to start or stop firing preserved +; Timer 3 enabled iff should stop now not interfered with +; W,STATUS any undefined +; FSR0 any undefined +; all other any not interfered with +; + mov_lw ptix2latbit >> 8 mov_wf FSR0H ; FSR0H -> table rl_fw pointmsg ; W = point addr, Z iff pt0 mov_wf FSR0L ; FSR0 -> &bit [Z still iff pt0] @@ -81,7 +92,7 @@ point_set_pin bra_z point_set_pin_l point_set_pin_h - mov_fw POSTINC0 ; W = bit, FSR0 -> &LAT* + mov_fw POSTDEC0 ; W = bit, FSR0 -> &LAT* bra_z point_nonexistent mov_ff INDF0, FSR0L ; W = bit, FSR0L -> LAT* set_f FSR0H ; FSR0 -> LAT*, W = bit (still) @@ -91,11 +102,11 @@ point_set_pin_h ;---------- point_set_pin_l - com_fw POSTINC0 ; W = ~bit, FSR0 -> &LAT* + com_fw POSTDEC0 ; W = ~bit, FSR0 -> &LAT* mov_ff INDF0, FSR0L ; W = ~bit, FSR0L -> LAT* set_f FSR0H ; FSR0 -> LAT*, W = bit (still) mov_ff BSR,FSR0H;qq - ior_wff INDF0 ; pin = H + and_wff INDF0 ; pin = H point_set_pin_hl tst_f_ifnz FSR0L ; err, did we just write to 0xf00 ? return ; no; good. @@ -130,14 +141,14 @@ points_local_init ; We do this in two stages. ; Firstly, we scan the bitmap for this pic, setting -; ptix2bitlat to 0xff,0x00 for used points and 0x00,0x00 +; ptix2latbit to 0xff,0x00 for used points and 0x00,0x00 ; to unused ones. ; Secondly, we scan the bkptix2portnumbitnum, adjusting -; ptix2bitlat to have actually correct data. +; ptix2latbit to have actually correct data. ; Doing it like this avoids having to constantly recompute ; individual TBLPTR*'s. - mov_lfsr ptix2bitlat-1, 0 ; FSR0 -> this bit and LAT* + mov_lfsr ptix2latbit-1, 0 ; FSR0 -> this bit and LAT* ; points just at last thing we've filled in load_perpic_tblptr picno2ptmap, maxpoints/8 @@ -150,12 +161,13 @@ points_init_byte_loop tblrd_postinc_fixup ; TABLAT = bitmap data being processed ;... points_init_bit_loop - clr_f PREINC0 ; FSR0 -> bit[current] := 0 + clr_f PREINC0 ; FSR0 -> LAT*[current] := 0 rrc_f TABLAT bt_f_if1 STATUS,C - set_f INDF0 ; FSR0 -still-> bit[current] := 0xff + set_f INDF0 ; FSR0 -still-> LAT*[current] := 0xff + + clr_f PREINC0 ; FSR0 -> bit[current] := 0 - clr_f PREINC0 ; FSR0 -> LAT*[current] := 0 dec_w_ifnz bra points_init_bit_loop dec_f_ifnz t @@ -176,7 +188,7 @@ points_init_bit_loop set_f FSR2H ; FSR2 -> some SFR, will point to LAT/TRIS mov_ff BSR,FSR2H;qq mov_lfsr bitnum2bit+7, 1 ; FSR1 -> bitnum2bit+7 - mov_lfsr ptix2bitlat, 0 ; FSR0 -> this bit (and LAT*) + mov_lfsr ptix2latbit-1, 0 ; FSR0 -> last bit (and previous LAT*) mov_lw maxpoints mov_wf t ; t = loop counter @@ -184,24 +196,24 @@ points_init_bit_loop points_init_portbit_loop tblrd_postinc_fixup ; TABLAT = portnum4 || bitnum4 - bt_f_if0 POSTINC0,7 ; zero?, FSR0 -> LAT*[this] + bt_f_if0 PREINC0,7 ; zero?, FSR0 -> LAT*[this] bra points_init_portbit_endif_used ;... points_init_portbit_if_used mov_fw TABLAT bra_n point_initing_bad_point - + ior_lw 0xf8 ; W -> bit value for bit mov_wf FSR1L ; FSR1 -> bit value for bit swap_fw TABLAT ; W = bitnum4 || portnum4 and_lw 0x0f ; W = portnum4 add_lw qqLATA & 0xff ; W = LAT* - mov_wf POSTDEC0 ; LAT*[this] := LAT, FSR0 -> bit[this] + mov_wf POSTINC0 ; LAT*[this] := LAT, FSR0 -> bit[this] mov_wf FSR2L ; FSR2 -> LAT* mov_fw INDF1 ; W = bit - mov_wf POSTINC0 ; bit[this] = bit, FSR0 -> LAT*[this] + mov_wf POSTDEC0 ; bit[this] = bit, FSR0 -> LAT*[this] com_w ; W = ~bit and_wff INDF2 ; LAT* &= ~bit, ie pin set to L (still Z) pin_vh pall_pt0reverse ; but pt0 pin is backwards, set to H @@ -214,7 +226,7 @@ points_init_portbit_if_used set_f FSR1L ; FSR1 -> bitnum2bit+7, again points_init_portbit_endif_used ; so now we move on to the next one - mov_fw POSTINC0 ; FSR0 -> bit[this+1] + mov_fw POSTINC0 ; FSR0 -> bit[this] dec_f_ifnz t bra points_init_portbit_loop diff --git a/detpic/reverse.asm b/detpic/reverse.asm index 34892fa..b49454d 100644 --- a/detpic/reverse.asm +++ b/detpic/reverse.asm @@ -28,24 +28,35 @@ polarities_commanded_buffer res maxpics+1 ;---------- polarity_local_do -; W here polarity msg PP PP v3 v0 v2 v1 v5 v4 +; On slave, called during i2c receive, ie High ISR +; On master, called during serial receive, ie Low ISR +; See common.inc ! +; +; W here polarity msg (see below) undefined +; STATUS any undefined +; t_dolocal any undefined +; maska,maske set up correctly preserved +; LATA,LATE any modified appropriately +; all others any preserved +; +; on entry: ; W = PP PP v3 v0 v2 v1 v5 v4 ; ; where PP bits are those specifying that this is a polarity message ; v is the reversal bits for point ; - mov_wf t ; t = PP PP v3 v0 v2 v1 v5 v4 + mov_wf t_dolocal ; t = PP PP v3 v0 v2 v1 v5 v4 mov_fw LATE ; W = kk kk kk kk kk kk o5 o4 - xor_wfw t ; W = ?? ?? ?? ?? ?? ?? d5 d4 + xor_wfw t_dolocal ; W = ?? ?? ?? ?? ?? ?? d5 d4 and_wfw maske ; W = zz zz zz zz zz zz d5 d4 xor_wff LATE ; LATE = kk kk kk kk kk kk v5 v4 - bc_f t,1 ; t = SS SS v3 v0 v2 v1 zz v4 - bt_f_if1 t,4 ; t : .. .. .. v0 .. .. .. .. - bs_f t,1 ; t = SS SS v3 v0 v2 v1 v0 v4 + bc_f t_dolocal, 1 ; t = SS SS v3 v0 v2 v1 zz v4 + bt_f_if1 t_dolocal, 4 ; t : .. .. .. v0 .. .. .. .. + bs_f t_dolocal, 1 ; t = SS SS v3 v0 v2 v1 v0 v4 mov_fw LATA ; W = kk kk o3 kk o2 o1 o0 kk - xor_wfw t ; W = ?? ?? d3 ?? d2 d1 d0 ?? + xor_wfw t_dolocal ; W = ?? ?? d3 ?? d2 d1 d0 ?? and_wfw maska ; W = zz zz d3 zz d2 d1 d0 zz xor_wff LATA ; LATA = kk kk v3 kk v2 v1 v0 kk diff --git a/detpic/variables.asm b/detpic/variables.asm index e338b6b..884d4ec 100644 --- a/detpic/variables.asm +++ b/detpic/variables.asm @@ -9,12 +9,15 @@ idloc1_master equ 7 idloc1_boarddet equ 6 t res 1 ; general temporary +t_dolocal res 1 ; temporary for _local_do outmsg_end res 1 ; first empty byte in outbuf isr_low_save_w res 1 ; see {enter,return}_interrupt_low isr_low_save_status res 1 ; in common.inc isr_low_save_stkptr res 1 ; +isr_high_save_fsr0 res 2 ; for isrh_fsr0_{save,restore} + xdebug res 8 polarities_waiting res 1