chiark / gitweb /
new low-priority interrupt arrangements
authorian <ian>
Sun, 18 Dec 2005 17:32:18 +0000 (17:32 +0000)
committerian <ian>
Sun, 18 Dec 2005 17:32:18 +0000 (17:32 +0000)
detpic/common.inc
detpic/i2clib.asm
detpic/i2clib.inc
detpic/points.asm
detpic/points.fin
detpic/program.asm
detpic/program.fin
detpic/slave.asm
detpic/test-sofar.asm
detpic/variables.asm

index 5850b91b442011a0853462ba46d8e170eea66f85..4dfb2c8352f1a65a3480dd8d26d2c8cb24f900fc 100644 (file)
@@ -70,10 +70,12 @@ clock equ -1
 ;                      Master                  Slave
 ;  Timer 0             nmra                    Disabled
 ;  Timer 2             -                       -
-;  Timer 1             1ms tick, int. low      1ms tick, int. low
-;  CCP1                        1ms tick, int. low      1ms tick, int. low
+;  Timer 1             (1ms tick, int. low)    (1ms tick, int. low)
+;  CCP1                        (1ms tick, int. low)    (1ms tick, int. low)
 ;  Timer 3             point fire timer        point fire timer
 ;  ECCP                        -                       -
+;
+;   (...) indicates that this is a projected use, NYI
 
 ;----------------------------------------------------------------------
 ; Conventional routine names:
@@ -86,31 +88,48 @@ clock equ -1
 ;                      and arranges for pins to be set in appropriate
 ;                      quiescent state.  Configures pic built-in
 ;                      peripherals.
-;                              
-; <periph>_local_intr  Low ISR service routine.
-;                      Checks for, and clears, any relevant interrupt,
-;                      and returns with `return'.
 ;
+; <periph>_local_intrl Low ISR service routine for peripheral (see below).
+;                              
 ; <periph>_master_do   Called when an appropriate message has been
 ;                      received from the host.
 ;
+; <something>_intrl    Low ISR service routine.
+;                      Checks for any relevant interrupt.
+;                      If not, just returns.
+;                      If found, services it and then does either
+;                       intrl_handled or intrl_handled_nostack
+;                       neither of which return; the latter is
+;                       faster but implies a promise 
+;
 ;----------------------------------------------------------------------
 ; MACROS
 
 ;----------------------------------------
 ; For entering and leaving Low ISR, saving and restoring STATUS and W
+; See above under <something>_intrl, and {master,slave}_interrupt_low
 
 enter_interrupt_low macro
        mov_ff  STATUS, isr_low_save_status
        mov_wf  isr_low_save_w
+       mov_ff  STKPTR, isr_low_save_stkptr
        endm
 
-return_interrupt_low macro
+intrl_handled_core macro ; for internal use only
        mov_fw  isr_low_save_w
        mov_ff  isr_low_save_status, STATUS
        retfie
        endm
 
+intrl_handled_nostack macro
+       pop     ; undo the `call' from the original ISR
+       intrl_handled_core
+       endm
+
+intrl_handled macro
+       goto    intrl_handled_routine
+       endm
+
 ;----------------------------------------
 ; For disabling all interrupts, to make a critical section:
 ; (for use from main program and Low ISR only)
index 4277705d96d9fbfddf9ed6cb0a443405e17b4132..f8091de5e8c21f583c5381f3b49840c473a35e71 100644 (file)
@@ -122,7 +122,8 @@ i2cm_interrupt
                bt_f_if0 PIR1, SSPIF
                return
                ; We have an interrupt:
-
+;...
+i2cm_interrupt_definite
                mov_ff  SSPSTAT, sspstat
                mov_ff  SSPCON1, sspcon1
                mov_ff  SSPCON2, sspcon2
index 93da997f76099d9704d9add50c0c4c772985b074..b699626e30ba5bed27d9e9c240a207ee1144666d 100644 (file)
@@ -88,6 +88,7 @@
 
 ;--------------------
  extern i2cm_interrupt
+ extern i2cm_interrupt_definite
  extern i2cs_interrupt
 ;
 ; Must be called by the main program's interrupt handler;
 ;
 ; For i2cm_interrupt, the main program's interrupt handler is
 ; responsible for saving W and the flags register and other
-; interrupt-related administrivia.  For i2cs_interrupt, it must be the
-; only high-priority interrupt source and expects to be called from
-; the interrupt handler (and it will return; the caller must
-; retfie_r).
+; interrupt-related administrivia.  i2cm_interrupt checks for
+; SSPIF and handles any interrupt.  i2cm_interrupt_definite
+; should only be called if SSPIF is set and handles it.  In
+; both cases the ISR returns with `return'.
+;
+; For i2cs_interrupt, it must be the only high-priority interrupt
+; source and expects to be called from the interrupt handler (and it
+; will return; the caller must retfie_r).
 ;
 ; If there is an i2c interrupt, the i2c?_interrupt will service it, taking
 ; any necessary action including calling appropriate
index 3632255353dc0191d3cbfd77c9ccebeff8363656..4e5fa49bda89aede741236d60bc023520430778b 100644 (file)
@@ -48,10 +48,10 @@ point_local_do
        return
 
 ;----------------------------------------
-points_local_intr
+points_local_intrl
        bt_f_if0 PIR2, TMR3IF
        return
-       ; OK, we're done:
+       ; OK, it's us, and we're done changing a point:
 
        bt_f_if0 T3CON, TMR3ON
        bra     point_spurious_intr
@@ -63,7 +63,8 @@ points_local_intr
        unmask_int_high
 
        mov_lw  b'00100000'
-       goto    message_for_master
+       call    message_for_master
+       intrl_handled_nostack
 
 ;----------
 point_spurious_intr
index dddeba6c2153a7851316e788fefc1a719ae37e2f..6786e59de6f6a062f2036b5b384bdfae0fa2ecba 100644 (file)
@@ -1,3 +1,3 @@
  extern point_local_do
- extern points_local_intr
  extern points_local_init
+ extern points_local_intrl
index deadc8adee51a7c51d6f49c5cf02b0704479750f..0d86f9500209448de645b29ec3ac43ed3ed668ed 100644 (file)
@@ -29,11 +29,18 @@ vector_reset
        bra     master
 
 ;----------
-master_interrupt_low
-       enter_interrupt_low
-       call    i2cm_interrupt
-       call    serial_interrupt
-       return_interrupt_low
+i2cm_intrl
+; handles i2c interrupt using i2cm_interrupt[_definite],
+; according to the rules for <something>_intrl.
+       bt_f_if0 PIR1, SSPIF
+       return
+       call    i2cm_interrupt_definite
+       intrl_handled_nostack
+
+;----------
+intrl_handled_routine
+       mov_ff  isr_low_save_stkptr, STKPTR
+       intrl_handled_core
 
 ;======================================================================
 ; MASTER/SLAVE deviations
index a45ed1095a4d2d329eb82103643abebfd57f8c7b..79e92db9192624d3ab13824ba6c85d4426203bfb 100644 (file)
@@ -1,3 +1,4 @@
  extern slave
  extern master
+ extern i2cm_intrl
  extern message_for_master
index 6743360fea95d8c6f128486191b570ad56ddcefd..84c8fb0814513b17294d60d7b867263cf7039caa 100644 (file)
@@ -46,7 +46,7 @@ i2csu_write_done
 ;----------
 slave_interrupt_low
        enter_interrupt_low
-       call    points_local_intr
-       return_interrupt_low
+       call    points_local_intrl
+       panic   morse_IL
 
  include final.inc
index 1827e4b3e4a4bbf2c7437c548d29485443c0411a..2b256f6dbf6770df448a72f32e69b71b7fe7c3f8 100644 (file)
@@ -83,6 +83,13 @@ delay_countslow              res     1
 master_interrupt_high
        panic   morse_IP
 
+;----------
+master_interrupt_low
+       enter_interrupt_low
+       call    i2cm_intrl
+       call    serial_intrl
+       panic   morse_IL
+
 ;----------------------------------------------------------------------
 ; MASTER
 ;
@@ -329,11 +336,14 @@ serial_receive_reset ;from serial_read_if_error
        return
 
 ;----------------------------------------
-serial_interrupt
+serial_intrl
 ; on errors, sets LED red and transmits *
        bt_f_if0        PIR1, RCIF
        return
+       rcall           serial_intr_handle
+       intrl_handled_nostack
 
+serial_intr_handle
        mov_fw          RCSTA
        and_lw          (1<<CREN) | (1<<FERR) | (1<<OERR)
        xor_lw          (1<<CREN)
index fc628c6330faab9cf39da3f559c2be9d014d64cf..a892a97c210cecc6cd95a5c8649660892fe0d3d5 100644 (file)
@@ -13,6 +13,7 @@ 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 ;
 
 polarities_waiting     res     1
  ; no of 11... entries in polarities_commanded_buffer, see reversers.asm