From: ian Date: Sun, 18 Dec 2005 17:32:18 +0000 (+0000) Subject: new low-priority interrupt arrangements X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=0e134cc62ed1168908643e52b9784f06c633d1a1;p=trains.git new low-priority interrupt arrangements --- diff --git a/detpic/common.inc b/detpic/common.inc index 5850b91..4dfb2c8 100644 --- a/detpic/common.inc +++ b/detpic/common.inc @@ -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. -; -; _local_intr Low ISR service routine. -; Checks for, and clears, any relevant interrupt, -; and returns with `return'. ; +; _local_intrl Low ISR service routine for peripheral (see below). +; ; _master_do Called when an appropriate message has been ; received from the host. ; +; _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 _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) diff --git a/detpic/i2clib.asm b/detpic/i2clib.asm index 4277705..f8091de 100644 --- a/detpic/i2clib.asm +++ b/detpic/i2clib.asm @@ -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 diff --git a/detpic/i2clib.inc b/detpic/i2clib.inc index 93da997..b699626 100644 --- a/detpic/i2clib.inc +++ b/detpic/i2clib.inc @@ -88,6 +88,7 @@ ;-------------------- extern i2cm_interrupt + extern i2cm_interrupt_definite extern i2cs_interrupt ; ; Must be called by the main program's interrupt handler; @@ -95,10 +96,14 @@ ; ; 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 diff --git a/detpic/points.asm b/detpic/points.asm index 3632255..4e5fa49 100644 --- a/detpic/points.asm +++ b/detpic/points.asm @@ -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 diff --git a/detpic/points.fin b/detpic/points.fin index dddeba6..6786e59 100644 --- a/detpic/points.fin +++ b/detpic/points.fin @@ -1,3 +1,3 @@ extern point_local_do - extern points_local_intr extern points_local_init + extern points_local_intrl diff --git a/detpic/program.asm b/detpic/program.asm index deadc8a..0d86f95 100644 --- a/detpic/program.asm +++ b/detpic/program.asm @@ -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 _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 diff --git a/detpic/program.fin b/detpic/program.fin index a45ed10..79e92db 100644 --- a/detpic/program.fin +++ b/detpic/program.fin @@ -1,3 +1,4 @@ extern slave extern master + extern i2cm_intrl extern message_for_master diff --git a/detpic/slave.asm b/detpic/slave.asm index 6743360..84c8fb0 100644 --- a/detpic/slave.asm +++ b/detpic/slave.asm @@ -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 diff --git a/detpic/test-sofar.asm b/detpic/test-sofar.asm index 1827e4b..2b256f6 100644 --- a/detpic/test-sofar.asm +++ b/detpic/test-sofar.asm @@ -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<