From: ian Date: Tue, 6 Dec 2005 21:05:57 +0000 (+0000) Subject: working on reversers X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=5f89a8f4a95aefcf25d6139b064b523dbd10fa19;p=trains.git working on reversers --- diff --git a/detpic/common.inc b/detpic/common.inc index 3150e61..10cfe0a 100644 --- a/detpic/common.inc +++ b/detpic/common.inc @@ -74,9 +74,31 @@ clock equ -1 ; Timer 3 point fire timer point fire timer ; ECCP - - +;---------------------------------------------------------------------- +; 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) +; +; _local_init Initialises RAM tables for local peripheral +; 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'. +; +; _master_do Called when an appropriate message has been +; received from the host. +; ;---------------------------------------------------------------------- ; MACROS +;---------------------------------------- +; For entering and leaving Low ISR, saving and restoring STATUS and W + enter_interrupt_low macro mov_ff STATUS, isr_low_save_status mov_wf isr_low_save_w @@ -88,6 +110,10 @@ return_interrupt_low macro retfie endm +;---------------------------------------- +; For disabling all interrupts, to make a critical section: +; (for use from main program and Low ISR only) + mask_int_high macro bc_f INTCON,GIEH endm @@ -96,6 +122,10 @@ unmask_int_high macro bs_f INTCON,GIEH endm +;---------------------------------------- +; For the fix specified in the silicon errata: +; silicon revision B4 issue 4 + tblrd_postinc_fixup macro tblrd *+ dw 0xffff @@ -106,6 +136,24 @@ tblrd_postdec_fixup macro dw 0xffff endm +;---------------------------------------- +; For setting up TBLPTR according to the picno + +load_perpic_tblptr macro flash_map_base, perpic_entry_size + movlw perpic_entry_size + mul_wf picno + + mov_lw flash_map_base & 0xff + add_wfw PRODL + mov_wf TBLPTRL + + mov_lw flash_map_base >> 8 + addc_wfw PRODH + mov_wf TBLPTRH + + clr_f TBLPTRU ; TBLPTR* -> our point data + endm + ;---------------------------------------------------------------------- ; PINSPECS stuff ; diff --git a/detpic/misc.asm b/detpic/misc.asm index 04cd2d3..fededfc 100644 --- a/detpic/misc.asm +++ b/detpic/misc.asm @@ -18,8 +18,7 @@ read_pic_no clr_f TBLPTRH clr_f TBLPTRL - tblrd *+ - dw 0xffff ; silicon errata: B4 issue 4 + tblrd_postinc_fixup mov_fw TABLAT return @@ -33,8 +32,7 @@ idlocs_init rcall read_pic_no mov_wf picno - tblrd *+ - dw 0xffff + tblrd_postinc_fixup mov_fw TABLAT mov_wf idloc1 diff --git a/detpic/pindata.inc b/detpic/pindata.inc index e8ce55d..e17b8ee 100644 --- a/detpic/pindata.inc +++ b/detpic/pindata.inc @@ -5,7 +5,7 @@ picno2ptmap equ 0x6100 bkptix2portnumbitnum equ 0x6000 pic2detinfo equ 0x6040 -picno2revbits equ 0x6080 +picno2revmasks equ 0x6080 maxpic_ln2 equ 5 maxpic equ 1 << maxpic_ln2 diff --git a/detpic/points.asm b/detpic/points.asm index 545d7c7..1e0e78f 100644 --- a/detpic/points.asm +++ b/detpic/points.asm @@ -1,42 +1,38 @@ ;====================================================================== ; POINTS + include common.inc + +;---------------------------------------- +; LOCAL POINTS - Variables, hardware, etc. +; ; Idle Firing ; Timer 3 Off On, counting up ; pointmsg undefined message from master - include common.inc - - udata_acs -pointmsg res 1 - ptix2bitlat equ 0x300 udata ptix2bitlat res maxpoint * 2 ; bit and LAT* ; for unused point, 0x00 and 0x00 - code + udata_acs +pointmsg res 1 pt_timer13_prescale equ 0 pt_timer13_inithigh equ 0 +;====================================================================== + code + ;====================================================================== ; LOCAL POINTS -; Actually doing points (on slave, or master's own) +; on slave, or master's own -;-------------------- -point_timer_init - mov_lw (1<> 8 mov_wf FSR0H ; FSR0H -> table rl_fw pointmsg ; W = point addr, Z iff pt0 @@ -125,7 +119,10 @@ point_clash panic morse_PB ;---------------------------------------------------------------------- -points_init +; LOCAL POINTS - INITIALISATION + +;---------------------------------------- +points_local_init ; Initialises tables for points ; Clears TRIS* bits for all points and sets each pin to `not triggering' @@ -142,18 +139,7 @@ points_init 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 - - mov_lw picno2ptmap >> 8 - addc_wfw PRODH - mov_wf TBLPTRH - - clr_f TBLPTRU ; TBLPTR* -> our point data + load_perpic_tblptr picno2ptmap, maxpoint/8 mov_lw maxpoint/8 mov_wf t ; t = byte counter @@ -237,7 +223,18 @@ points_init_portbit_endif_used point_initing_bad_point panic morse_PF -;---------------------------------------------------------------------- +;---------- +point_timer_init + mov_lw (1< is the reversal bits for point +; + mov_wf t ; t = PP PP v3 v0 v2 v1 v5 v4 + + mov_wf LATE ; W = kk kk kk kk kk kk o5 o4 + xor_wfw t ; W = ?? ?? ?? ?? ?? ?? d5 d4 + and_wfw maske ; W = zz zz zz zz zz zz d5 d4 + xor_wff LATE ; LATA = kk kk kk kk kk kk v5 v4 + + bc_f t,2 ; t = SS SS v3 v0 v2 v1 zz v4 + bt_f_if1 t,4 ; t : .. .. .. v0 .. .. .. .. + bs_f t,2 ; t = SS SS v3 v0 v2 v1 v0 v4 + + mov_wf LATA ; W = kk kk o3 kk o2 o1 o0 kk + xor_wfw t ; 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 + + ; where kk is a bit we must keep + ; o is old reverse bit + ; d is old (+) new + ; v is new reverse bit + return + +;---------- +polarity_local_init + load_perpic_tblptr picno2revmasks, 2 + + tblrd_postinc_fixup + mov_fw TABLAT + mov_wf maska + + tblrd_postinc_fixup + mov_fw TABLAT + mov_wf maske + + clr_w + rcall polarity_local_do + + com_fw maska + and_wf TRISA + + com_fw maske + and_wf TRISE + + return + +;====================================================================== +; MASTER + ;---------- -polarity_decode_message +polarity_master_do ; message format ; SS zz zz SS ZZ 2f 2e 2d g is board 2 ; MM 2c 0f 0e 0d 0c 0b 0a board 0 @@ -86,23 +157,3 @@ board_next_none pop return - -;---------- -polarity_do_here -; W here polarity msg SS SS v3 v0 v2 v1 v5 v4 - mov_wf input ; input = SS SS v3 v0 v2 v1 v5 v4 - - mov_wf LATE ; W = kk kk kk kk kk kk o5 o4 - xor_wfw input ; W = ?? ?? ?? ?? ?? ?? d5 d4 - and_wfw maske ; W = zz zz zz zz zz zz d5 d4 - xor_wff LATE ; LATA = kk kk kk kk kk kk v5 v4 - - bc_f input,2 ; input = SS SS v3 v0 v2 v1 zz v4 - bt_f_if1 input,4 ; input : .. .. .. v0 .. .. .. .. - bs_f input,2 ; input = SS SS v3 v0 v2 v1 v0 v4 - - mov_wf LATA ; W = kk kk r3 kk r2 r1 r0 kk - xor_wfw input ; W = ?? ?? r3 ?? r2 r1 r0 ?? - and_wfw maska ; W = zz zz r3 zz r2 r1 r0 zz - xor_wff LATA ; LATE = kk kk r3 kk r2 r1 r0 kk - return diff --git a/detpic/slave.asm b/detpic/slave.asm index cad8143..3b7d6c8 100644 --- a/detpic/slave.asm +++ b/detpic/slave.asm @@ -16,7 +16,7 @@ slave mov_fw picno call i2cs_init call bitnum2bit_init - call points_init + call points_local_init call det_slave_init mov_lw (1< 7; - o("b'"); - for ($bit= $kc-1; $bit>=0; $bit--) { - o(boob_used_bit($num, $bit, 'reverse')); - } - o("'"); - } else { - o('0xff'); + for ($bit= $kc-1; $bit>=0; $bit--) { + $pu= boob_used($num, $bit, 'reverse'); + next unless $pu; + $pu->[1] =~ m/^([04])\,\d,(0x\w{2})$/ or die; + push @{ $portae[!!$1] }, $2; } + o(' db '); + o(join(', ', map { @$_ ? join('|',@$_) : '0' } @portae)); + o(sprintf " ; %d\n",$num); } - o_section_end_fill($num, '0xffff', 1); + o_section_end_fill($num, '0xffff', 2); } sub writeasm () {