From: ian Date: Mon, 5 Dec 2005 03:29:57 +0000 (+0000) Subject: new detection and points arrangements; builds X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=72ac2d764d593544ffda7581399c946d74276f23;p=trains.git new detection and points arrangements; builds --- diff --git a/detpic/Makefile b/detpic/Makefile index 6f005e3..2690136 100644 --- a/detpic/Makefile +++ b/detpic/Makefile @@ -4,7 +4,7 @@ PICNOS= 0 1 2 PROGRAMS= test-sofar OBJS_test-sofar= vectors.o panic.o routines-led.o i2clib.o \ - misc.o slave.o detect.o variables.o \ + misc.o slave.o detect.o variables.o points.o \ syncwrite.o XCODEN_test-sofar= morse XCODE1_test-sofar= blank2 ours+pindata @@ -19,7 +19,8 @@ INCLUDES= common.inc \ ../iwjpictest/clockvaries.inc \ vectors.fin \ pindata.inc \ - detect.inc + detect.inc \ + points.fin VARSFILES= variables diff --git a/detpic/common.inc b/detpic/common.inc index ebf3de5..3150e61 100644 --- a/detpic/common.inc +++ b/detpic/common.inc @@ -13,6 +13,7 @@ clock equ -1 include ../iwjpictest/clockvaries.inc include variables+vars.inc + include pindata.inc ;---------------------------------------------------------------------- ; Common conventions for function register notation: @@ -25,8 +26,8 @@ clock equ -1 ; t Low ISR Low ISR ; TBLPTR*,TABLAT Low ISR Low ISR ; FSR0 Low ISR Low ISR -; FSR1 Low ISR High ISR (detect) -; FSR2 Low ISR High ISR (detect) +; FSR1 Low ISR High ISR (detect[1]) +; FSR2 Low ISR High ISR (detect[1]) ; ; Trashed May be trashed by any routine anywhere. Saved ; during every ISR entry/exit. @@ -60,6 +61,9 @@ clock equ -1 ; A routine which is allowed to trash a register may document that it ; saves that register for the benefit of its callers. ; +; [1] FSR1 and FSR2 on slave pics are reserved exclusively for the +; I2C response and detection code (detect.asm), after det_slave_init. +; ; General-purpose hardware allocation: ; ; Master Slave @@ -73,6 +77,35 @@ clock equ -1 ;---------------------------------------------------------------------- ; MACROS +enter_interrupt_low macro + mov_ff STATUS, isr_low_save_status + mov_wf isr_low_save_w + endm + +return_interrupt_low macro + mov_fw isr_low_save_w + mov_ff isr_low_save_status, STATUS + retfie + endm + +mask_int_high macro + bc_f INTCON,GIEH + endm + +unmask_int_high macro + bs_f INTCON,GIEH + endm + +tblrd_postinc_fixup macro + tblrd *+ + dw 0xffff + endm + +tblrd_postdec_fixup macro + tblrd *- + dw 0xffff + endm + ;---------------------------------------------------------------------- ; PINSPECS stuff ; diff --git a/detpic/detect.asm b/detpic/detect.asm index 7abdf25..b9d9bcf 100644 --- a/detpic/detect.asm +++ b/detpic/detect.asm @@ -138,13 +138,23 @@ det_slave_init goto reset_message_buffer ;---------- +message_for_master +; Either transmits the message to the master, or if we are the master, +; handles it as an incoming message from the notional `slave 0'. +; W message unchanged +; GIEH set set + bt_f_if1 idloc1,idloc1_master + goto loopback_read_byte + +;..... +;---------------------------------------- slave_add_short_message ; W message unchanged ; GIEH set set - bc_f INTCON,GIEH + mask_int_high bs_f POSTINC1,7 mov_wf INDF1 - bs_f INTCON,GIEH + unmask_int_high return ;---------- diff --git a/detpic/detect.inc b/detpic/detect.inc index 70f580d..fc56c0d 100644 --- a/detpic/detect.inc +++ b/detpic/detect.inc @@ -1,3 +1,4 @@ extern det_slave_init + extern message_for_master extern backgroundloop_reversers extern backgroundloop_detectors diff --git a/detpic/final.inc b/detpic/final.inc index e7e771a..325852d 100644 --- a/detpic/final.inc +++ b/detpic/final.inc @@ -1,10 +1,12 @@ extern slave + extern loopback_read_byte include vectors.fin include i2clib.inc include panic.fin include routines-led.fin include misc.fin + include points.fin include variables+vars.fin include detect.inc include ../iwjpictest/syncwrite.inc diff --git a/detpic/misc.asm b/detpic/misc.asm index 5eeca03..04cd2d3 100644 --- a/detpic/misc.asm +++ b/detpic/misc.asm @@ -1,9 +1,11 @@ ;====================================================================== -; GENERALLY USEFUL ROUTINES include common.inc code +;====================================================================== +; GENERALLY USEFUL ROUTINES + ;---------- read_pic_no ; read pic no from ID locations and return it @@ -22,7 +24,7 @@ read_pic_no return ;---------- -init_read_idlocs +idlocs_init ; read id locations and store in canonical place ; W undefined undefined ; picno undefined pic number (from 20000) @@ -39,7 +41,7 @@ init_read_idlocs return ;---------- -init_bitnum2bit +bitnum2bit_init ; populate bitnum2bit mov_lw 0x80 mov_lfsr bitnum2bit,0 @@ -49,10 +51,7 @@ init_bitnum2bit_loop bra_nn init_bitnum2bit_loop return -;---------- -common_init - call bitnum2bit_init - call points_init - return +;====================================================================== +; MASTER/SLAVE deviations include final.inc diff --git a/detpic/misc.fin b/detpic/misc.fin index b4da5ee..0679b03 100644 --- a/detpic/misc.fin +++ b/detpic/misc.fin @@ -1,2 +1,3 @@ extern read_pic_no - extern init_read_idlocs + extern idlocs_init + extern bitnum2bit_init diff --git a/detpic/morse.messages b/detpic/morse.messages index e1888f2..256494d 100644 --- a/detpic/morse.messages +++ b/detpic/morse.messages @@ -32,6 +32,7 @@ X test-sofar:ch ; bad character received from host # Unimplemented things UP ; unimplemented point timer setting +UL ; unimplemented master loopback read ZM i2clib:st,:sspstat,:sspcon1,:sspcon2 ; for testing ZS i2clib:st,:sspstat,:sspcon1,:st_orig ; for testing @@ -57,3 +58,6 @@ RS FSR0L ; POLARITY message too short RL FSR0L ; POLARITY message too long PB points:pointmsg ; Firing point when already busy +PI points:pointmsg,T3CON ; Unexpected Timer 3 interrupt +PU points:pointmsg ; Firing nonexistent point +PF points:t ; Flash mentions point not on board diff --git a/detpic/points.asm b/detpic/points.asm index 51b203c..79a7737 100644 --- a/detpic/points.asm +++ b/detpic/points.asm @@ -5,18 +5,26 @@ ; Timer 3 Off On, counting up ; pointmsg undefined message from master + include common.inc + udata_acs pointmsg res 1 - udata 0x300 -ptix2latbit res maxpoint * 2 ; bit and LAT* +ptix2bitlat equ 0x300 + udata ptix2bitlat + res maxpoint * 2 ; bit and LAT* + ; for unused point, 0x00 and 0x00 code pt_timer13_prescale equ 0 pt_timer13_inithigh equ 0 -;---------- +;====================================================================== +; LOCAL POINTS +; Actually doing points (on slave, or master's own) + +;-------------------- point_timer_init mov_lw (1<> 8 + mov_lw ptix2bitlat >> 8 mov_wf FSR0H ; FSR0H -> table - rl_w pointmsg ; W = point addr, Z iff pt0 - mov_wf FSR0L ; FSR0 -> &LAT* [Z still iff pt0] + rl_fw pointmsg ; W = point addr, Z iff pt0 + mov_wf FSR0L ; FSR0 -> &bit [Z still iff pt0] bt_f_if1 T3CON, TMR3ON ; Were we firing ? [Z still iff pt0] btg_f STATUS, Z ; Z iff (pt0 xor were_firing) bra_z point_set_pin_l + point_set_pin_h mov_fw POSTINC0 ; W = bit, FSR0 -> &LAT* + bra_z point_nonexistent mov_ff INDF0, FSR0L ; W = bit, FSR0L -> LAT* set_f FSR0H ; FSR0 -> LAT*, W = bit (still) ior_wff INDF0 ; pin = H return +;---------- point_set_pin_l com_fw POSTINC0 ; W = ~bit, FSR0 -> &LAT* mov_ff INDF0, FSR0L ; W = ~bit, FSR0L -> LAT* set_f FSR0H ; FSR0 -> LAT*, W = bit (still) ior_wff INDF0 ; pin = H - return +point_set_pin_hl + tst_f_ifnz FSR0L ; err, did we just write to 0xf00 ? + return ; no; good. + ; oops, we did: + if 0xf00 == RXF0SIDH + ; This is actually OK; it's a `receive acceptance filter' + ; for the CAN controller, writing to which has no side + ; effects. And anyway the register starts at xxxx xxxx + ; so if we don't care about CAN that's fine, and we're about + ; to panic, of course. + ; See DS p212 (register summary), p228 (description), + ; p48 (location, 0xf00), p53 (POR value). + else + error "must check what 0xf00 is on this processor" + endif +point_nonexistent + panic morse_PU ;---------- point_clash panic morse_PB - - - - bt_f_if0 - - - - - bra_z point_do_if_pt0 -point_do_ifnot_pt0 - rcall point_pin_h -point_do_endif_pt0_set_timer - mov_lw - -point_do_if_pt0 - rcall point_pin_l - - - -point_pin_l - - - rl_w - - bt_f_if0 - - add_lw (ptix2lat >> 8) - 0x80 - - - -; We use FSR1 so we have to save it - mov_ff FSR1L, fsr1l_save ; we assume FSR1H is zero, since on - ; W SS zz zz pp pp pp pp pp - ;---------------------------------------------------------------------- points_init ; Initialises tables for points ; Clears TRIS* bits for all points and sets each pin to `not triggering' -points_init - - -; -; Expected layout of data at data_points in flash: -; 4 bytes for each point number -; byte 0 -; pic number for this point -; ff indicates unassigned point number -; byte 1 -; index number for this point on relevant pic -; byte 2 -; address of relevant LAT* -; byte 3 -; bit in LAT (eg 0x40 for bit 6) -; bytes 1-3 are not defined if number is not assigned -; address of data_points is guaranteed to be multiple of 256 +; 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 +; to unused ones. +; Secondly, we scan the bkptix2portnumbitnum, adjusting +; ptix2bitlat to have actually correct data. +; Doing it like this avoids having to constantly recompute +; individual TBLPTR*'s. + mov_lfsr ptix2bitlat, 0 ; FSR0 -> this bit and LAT* + mov_lw maxpoint/8 + mul_wf picno + mov_lw picno2ptmap & 0xff + add_wfw PRODL + mov_wf TBLPTRL - udata_acs - - udata 0x300 -our_point_table_ctln2 equ 6 -our_point_table_count equ (1 << our_point_table_ctln2) -our_point_table res our_point_table_count * 2 -; 2 bytes for each point, indexed by index number on this pic -; 1st byte: LAT* address, or 0 for unassigned -; 2nd byte: bit in LAT - - code - -;---------------------------------------------------------------------- -points_init -; Clears TRIS* bits for all points and sets the -; pin to `not triggering' - - mov_lfsr our_point_table, 0 ; FSR0 points to point lookup table - mov_lw our_point_table_count * 2 - -points_init_clear_loop - clr_f POSTINC1 - dec_w_ifnz - bra points_init_clear_loop - ; otherwise, done: - - ; During this loop: - clr_wf TBLPTRU - mov_lw (data_points >> 8) + mov_lw picno2ptmap >> 8 + addc_wfw PRODH mov_wf TBLPTRH - clr_f TBLPTRL ; TBLPTR* -> to point data - - set_f FSR1H ; FSR1 -> LAT*, TRIS* - - mov_lfsr our_point_table, 0 ; FSR0 -> point lookup table - -points_init_loop - mov_lw (data_points_end >> 8) - cmp_fw_ifge TBLPTRH - bra points_init_loop_exit - tblrd *+ - dw 0xffff ; TABLAT = pic number + clr_f TBLPTRU ; TBLPTR* -> our point data + + mov_lw maxpoint/8 + mov_wf t ; t = byte counter +;... +points_init_byte_loop + mov_lw 8 ; W = bit counter + clr_f INDF0 ; bit[current] := 0 + tblrd_postinc_fixup ; TABLAT = bitmap data being processed +;... +points_init_bit_loop + rrc_f TABLAT + bra_nc points_init_ifnot_point +points_init_if_point + set_f POSTINC0 ; bit[current] := 0xff, FSR0 -> LAT*[current] +points_init_ifnot_point + clr_f POSTINC0 ; LAT*[current] := 0xff, FSR0 -> bit[current+1] - mov_fw picno - cmp_fw_ifne TABLAT - bra points_init_loop_ifnot_ours - - tblrd *+ - dw 0xffff ; TABLAT = index number - - mov_lw 0xff << our_point_table_ctln2 - and_wfw TABLAT - bra_nz bad_pointtable_index - - rl_fw TABLAT - mov_wf FSR0L ; FSR0 -> our table entry - - tst_f_ifnz INDF0 - bra_nz bad_pointtable_clash - - tblrd *+ - dw 0xffff ; TABLAT = LAT* address - - mov_fw TABLAT - mov_wf POSTINC0 ; store LAT* address; FSR0 -> bit - mov_wf FSR1L ; FSR1 -> LAT* + dec_w_ifnz + bra points_init_bit_loop + dec_f_ifnz t + bra points_init_byte_loop +;... end of loop: + +; We've scanned for points used on this board; +; now find the actual pins. + + mov_lfsr ptix2bitlat, 0 ; FSR0 -> this bit and LAT* + mov_lfsr bitnum2bit+7, 1 ; FSR1 -> bitnum2bit+7 + set_f FSR2 ; FSR2 -> some SFR, will point to LAT/TRIS + + mov_lw bkptix2portnumbitnum & 0xff + bt_f_if0 idloc1,idloc1_boarddet + add_lw maxpoint + mov_wf TBLPTRL + + mov_lw bkptix2portnumbitnum >> 8 + mov_wf TBLPTRH ; TBLPTR* -> point port/bit data + + mov_lw maxpoint + mov_wf t ; t = loop counter +;... +points_init_portbit_loop + tblrd_postinc_fixup ; TABLAT = portnum4 || bitnum4 + + bt_f_if0 POSTINC0,7 ; zero?, FSR0 -> LAT*[this] + bra points_init_portbit_endif_used +;... +points_init_portbit_if_used + mov_wf TABLAT + bra_n point_initing_bad_point - tblrd *+ - dw 0xffff ; TABLAT = bit value - - mov_fw TABLAT - mov_wf INDF0 ; store bit value - - com_w ; W = ~bit - and_wff INDF1 ; clear the LAT* bit (point inactive) - pin_vh pall_pt0reverse ; except pt0 which is backwards - + and_wff FSR1L ; FSR1 -> bit value for bit + + swap_fw TABLAT ; W = bitnum4 || portnum4 + and_lw 0x0f ; W = portnum4 + add_lw LATA & 0xff ; W = LAT* + mov_wf POSTDEC0 ; LAT*[this] := LAT, FSR0 -> bit[this] + mov_wf FSR2L ; FSR2 -> LAT* + + mov_wf INDF1 ; W = bit + mov_fw POSTINC0 ; 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 + ; (still Z, unless we've done this already) mov_lw TRISA-LATA - add_wf FSR1L ; FSR1 -> TRIS* - com_fw TABLAT ; W = ~bit - and_wff INDF1 ; make the pin an output - - bra points_init_loop - -points_init_loop_ifnot_ours - tblrd *+ - tblrd *+ - tblrd *+ - bra points_init_loop - + add_wff FSR2L ; FSR2 -> TRIS* + com_fw INDF1 ; W = ~bit + and_wff INDF2 ; TRIS* &= ~bit, ie pin set to not Z - + 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] + dec_f_ifnz t + bra points_init_portbit_loop - clr_f INDF1 + return - +;---------- +point_initing_bad_point + panic morse_PF ;---------------------------------------------------------------------- -cdu_init +;cdu_init ; For master pic only. Sorts out the CDU's pin. + include final.inc diff --git a/detpic/points.fin b/detpic/points.fin new file mode 100644 index 0000000..51abd71 --- /dev/null +++ b/detpic/points.fin @@ -0,0 +1,3 @@ + extern points_interrupt + extern points_init + extern point_do_here diff --git a/detpic/slave.asm b/detpic/slave.asm index ecfcee3..cad8143 100644 --- a/detpic/slave.asm +++ b/detpic/slave.asm @@ -15,7 +15,8 @@ slave mov_fw picno call i2cs_init - call common_init + call bitnum2bit_init + call points_init call det_slave_init mov_lw (1<