chiark / gitweb /
isr register use fixes (particularly for <foo>_local_do, which have strange calling...
authorian <ian>
Mon, 19 Dec 2005 19:04:51 +0000 (19:04 +0000)
committerian <ian>
Mon, 19 Dec 2005 19:04:51 +0000 (19:04 +0000)
detpic/common.inc
detpic/detect.asm
detpic/points.asm
detpic/reverse.asm
detpic/variables.asm

index 4807c88fec3088f8301f12c8e55fa83a232048d9..9e2dc310470f751dd7c35fc646794e285bb5344b 100644 (file)
@@ -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:
 ;
 ; <periph>_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!
 ;
 ; <periph>_local_init  Initialises RAM tables for local peripheral
 ;                      and arranges for pins to be set in appropriate
@@ -94,7 +96,7 @@ clock equ -1
 ;
 ; <periph>_local_intrl Low ISR service routine for peripheral (see below).
 ;                              
-; <periph>_master_do   Called when an appropriate message has been
+; command_<periph>     Called when an appropriate message has been
 ;                      received from the host.
 ;
 ; <something>_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
 
index 62263a2deecb272b45a217c712aec019af7e6ef3..7560b968c4bdfbf02c1b022bee7ad21219e47428 100644 (file)
@@ -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
 
index e5dfe1611b2847d4d5086534e6f95c564ffdfa35..df003b292721572d9deab6a57648ce7feb5e473d 100644 (file)
@@ -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
index 34892fa2d0ba2b4a8ced2fbe64aa70b8c688c990..b49454da91f1d78d344e36d5d1578ec843ed2d1e 100644 (file)
@@ -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<num> is the reversal bits for point <num>
 ;
-       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
 
index e338b6bc1e599a0aefc5ad80841362f477bbbada..884d4ecc426c698d6ded9622d8b9345885685575 100644 (file)
@@ -9,12 +9,15 @@ idloc1_master equ     7
 idloc1_boarddet        equ     6
 
 t              res     1       ; general temporary
+t_dolocal      res     1       ; temporary for <foo>_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