From: ian Date: Tue, 6 Dec 2005 23:31:06 +0000 (+0000) Subject: new arrangements including points; about to hack for qq test X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=3b30282ecbe203acb1a1898275436adfd76d430d;p=trains.git new arrangements including points; about to hack for qq test --- diff --git a/detpic/Makefile b/detpic/Makefile index 2690136..e33439c 100644 --- a/detpic/Makefile +++ b/detpic/Makefile @@ -2,12 +2,12 @@ CEBPIC= ../cebpic/ PICNOS= 0 1 2 -PROGRAMS= test-sofar -OBJS_test-sofar= vectors.o panic.o routines-led.o i2clib.o \ +PROGRAMS= program +OBJS_program= vectors.o panic.o routines-led.o i2clib.o \ misc.o slave.o detect.o variables.o points.o \ - syncwrite.o -XCODEN_test-sofar= morse -XCODE1_test-sofar= blank2 ours+pindata + syncwrite.o reverse.o test-sofar.o +XCODEN_program= morse +XCODE1_program= blank2 ours+pindata INCLUDES= common.inc \ final.inc \ @@ -20,7 +20,9 @@ INCLUDES= common.inc \ vectors.fin \ pindata.inc \ detect.inc \ - points.fin + points.fin \ + program.fin \ + reverse.fin VARSFILES= variables diff --git a/detpic/common.inc b/detpic/common.inc index 10cfe0a..5850b91 100644 --- a/detpic/common.inc +++ b/detpic/common.inc @@ -25,6 +25,7 @@ clock equ -1 ; BSR Not used Not used ; t Low ISR Low ISR ; TBLPTR*,TABLAT Low ISR Low ISR +; PROD* Low ISR Low ISR ; FSR0 Low ISR Low ISR ; FSR1 Low ISR High ISR (detect[1]) ; FSR2 Low ISR High ISR (detect[1]) @@ -113,6 +114,9 @@ return_interrupt_low macro ;---------------------------------------- ; For disabling all interrupts, to make a critical section: ; (for use from main program and Low ISR only) +; +; GIEH modified appropriately +; everything else preserved mask_int_high macro bc_f INTCON,GIEH @@ -125,6 +129,11 @@ unmask_int_high macro ;---------------------------------------- ; For the fix specified in the silicon errata: ; silicon revision B4 issue 4 +; +; Before After +; TABLAT any data from flash +; TBLPTR* correct incremented/decremented +; everything else any preserved tblrd_postinc_fixup macro tblrd *+ @@ -140,7 +149,13 @@ tblrd_postdec_fixup macro ; For setting up TBLPTR according to the picno load_perpic_tblptr macro flash_map_base, perpic_entry_size - movlw perpic_entry_size +; +; Before After +; TBLPTR* any set +; W, STATUS, PROD* any undefined +; everything else any preserved +; + mov_lw perpic_entry_size mul_wf picno mov_lw flash_map_base & 0xff @@ -177,6 +192,22 @@ p0_booster_dirn equ 0c p0_booster_pwm equ 1c radix dec +; +; LAT* may be subject to read-modify-write, see below +; TRIS* may be subject to read-modify-write, see below +; PORT* may be read, see below +; everything else untouched +; +; LAT* TRIS* PORT* +; pin_z untouched set untouched +; pin_h set cleared untouched +; pin_l cleared cleared untouched +; pin_nz untouched cleared untouched +; pin_vh set untouched untouched +; pin_vl cleared untouched untouched +; pin_ifh untouched untouched read +; pin_ifl untouched untouched read + pin_z macro pinspec bs_f TRISA + (TRISB-TRISA)*((pinspec-0xa) & 15), pinspec >> 4 endm diff --git a/detpic/detect.asm b/detpic/detect.asm index b9d9bcf..3c77ed5 100644 --- a/detpic/detect.asm +++ b/detpic/detect.asm @@ -109,46 +109,38 @@ message_buffer_end code ;---------- -det_common_init +detect_local_init mov_lw b'111' ; turn off comparator, or we can't use pins mov_wf CMCON ; RD0-RD4 as digital inputs mov_lw b'0110' ; turn off A/D except perhaps for pin ior_wff ADCON1 ; AN0 ie SPARE ie RA0 (same reason as above) - return -;---------- -det_slave_init - rcall det_common_init + ; compute buf0_startval + clr_w + bt_f_if0 idloc1,idloc1_boarddet + mov_lw 0x14 ; see under reversers, below + mov_wf buf0_startval + set_f scana set_f scanb set_f scanc set_f scand set_f scane + mov_ff buf0_startval, buf0 - clr_w - - bt_f_if0 idloc1,idloc1_boarddet - mov_lw 0x14 ; see under reversers, below - - mov_wf buf0_startval + return +;---------- +detect_slave_init mov_lfsr outbuf, 2 clr_f outmsg_end 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 +; Queues a message byte for transmission to the master. +; It will be transmitted as an extra message byte, when we are polled. ; W message unchanged ; GIEH set set mask_int_high @@ -307,12 +299,12 @@ msg_copy_loop bra_n msg_copy_loop mov_ff FSR2L, outmsg_end + mov_ff buf0_startval, buf0 reset_message_buffer ; FSR1/buf0/message_buffer any set to empty ; may be called from High ISR or during init mov_lfsr message_buffer, 1 - mov_ff buf0_startval, buf0 clr_f INDF1 return diff --git a/detpic/detect.inc b/detpic/detect.inc index fc56c0d..0b84d60 100644 --- a/detpic/detect.inc +++ b/detpic/detect.inc @@ -1,4 +1,5 @@ - extern det_slave_init - extern message_for_master + extern detect_local_init + extern detect_slave_init + extern slave_add_short_message extern backgroundloop_reversers extern backgroundloop_detectors diff --git a/detpic/final.inc b/detpic/final.inc index 325852d..66e74ec 100644 --- a/detpic/final.inc +++ b/detpic/final.inc @@ -1,5 +1,6 @@ - extern slave - extern loopback_read_byte + extern test_sofar_slave_startup_hook + extern trackpower_decide + extern serial_interrupt include vectors.fin include i2clib.inc @@ -10,5 +11,7 @@ include variables+vars.fin include detect.inc include ../iwjpictest/syncwrite.inc + include reverse.fin + include program.fin end diff --git a/detpic/misc.asm b/detpic/misc.asm index fededfc..255f7db 100644 --- a/detpic/misc.asm +++ b/detpic/misc.asm @@ -49,7 +49,4 @@ init_bitnum2bit_loop bra_nn init_bitnum2bit_loop return -;====================================================================== -; MASTER/SLAVE deviations - include final.inc diff --git a/detpic/morse.messages b/detpic/morse.messages index 256494d..43c499e 100644 --- a/detpic/morse.messages +++ b/detpic/morse.messages @@ -31,8 +31,10 @@ TI5 ; for iwj X test-sofar:ch ; bad character received from host # Unimplemented things -UP ; unimplemented point timer setting -UL ; unimplemented master loopback read +UP +UL +UM +UE ZM i2clib:st,:sspstat,:sspcon1,:sspcon2 ; for testing ZS i2clib:st,:sspstat,:sspcon1,:st_orig ; for testing diff --git a/detpic/points.asm b/detpic/points.asm index 1e0e78f..1514b6a 100644 --- a/detpic/points.asm +++ b/detpic/points.asm @@ -11,7 +11,7 @@ ; pointmsg undefined message from master ptix2bitlat equ 0x300 - udata ptix2bitlat +ptix2bitlat_section udata ptix2bitlat res maxpoint * 2 ; bit and LAT* ; for unused point, 0x00 and 0x00 diff --git a/detpic/program.asm b/detpic/program.asm new file mode 100644 index 0000000..44b7037 --- /dev/null +++ b/detpic/program.asm @@ -0,0 +1,45 @@ +;====================================================================== +; MAIN PROGRAM AND GLUE + + include common.inc + code + +;---------- +vector_reset + clr_f INTCON + bs_f RCON, IPEN ; interrupt priorities + + call idlocs_init + + tst_f_ifnz picno + goto slave + bra master + +;---------- +master_interrupt_low + enter_interrupt_low + call i2cm_interrupt + call serial_interrupt + return_interrupt_low + +;====================================================================== +; MASTER/SLAVE deviations + +;---------- +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 + goto slave_add_short_message + +;====================================================================== +; UNIMPLEMENTED STUFF + +;---------- +loopback_read_byte + panic morse_UL + + include final.inc diff --git a/detpic/program.fin b/detpic/program.fin new file mode 100644 index 0000000..a45ed10 --- /dev/null +++ b/detpic/program.fin @@ -0,0 +1,3 @@ + extern slave + extern master + extern message_for_master diff --git a/detpic/reverse.asm b/detpic/reverse.asm index 4f055eb..894b36b 100644 --- a/detpic/reverse.asm +++ b/detpic/reverse.asm @@ -1,6 +1,8 @@ ;====================================================================== ; REVERSERS + include common.inc + ;---------------------------------------- ; LOCAL REVERSERS - Variables @@ -11,12 +13,6 @@ maske res 1 ;---------------------------------------- ; MASTER - Access bank variables and other sections -board0 res 1 -gather res 1 - -polarities_waiting res 1 - ; no of 11... entries in reversers_commanded_buffer - udata polarities_commanded_buffer res maxpic+1 ; Each byte is: @@ -75,10 +71,10 @@ polarity_local_init rcall polarity_local_do com_fw maska - and_wf TRISA + and_wff TRISA com_fw maske - and_wf TRISE + and_wff TRISE return @@ -106,28 +102,35 @@ polarity_master_do ; is a for LSb in message to PIC, b for next bit, ; and so on until f for bit 5. (See polarity_do_here, below.) ; - mov_lfsr message_buffer_start,0 - mov_lfsr reversers_commanded_buffer,1 +; we accumulate (`gather') the `g' bits in t. +; + + panic morse_UM +;; mov_lfsr message_buffer_start,0 + + + mov_lfsr polarities_commanded_buffer,1 mov_fw POSTINC0 ; W = 10010RRR - mov_wf gather ; gather = 10010ggg - xor_lw 0b10001000 ; gather = 00011ggg -loop ; exit from this loop is done by board popping and returning + mov_wf t ; t = 10010ggg + xor_lw b'10001000' ; t = 00011ggg +loop ; Exit from this loop is done by board popping, doing some + ; final stuff, and returning. See board_next_none, below. rrc_fw INDF0 ; W = ?Mhhhhhh C = g - rlc_f gather ; gather = 0*11g+ C = ? + rlc_f t ; t = 0*11g+ C = ? bra_nn if_not_gathered - ; ; gather = 11gggggg - mov_fw gather + ; ; t = 11gggggg + mov_fw t rcall board - mov_lw 0b00000011 ; W = 00000011 - mov_wf gather ; gather = 00000011 + mov_lw b'000000011' ; W = 00000011 + mov_wf t ; t = 00000011 if_not_gathered ; *INDF0 = Mhhhhhhg rr_fw INDF0 ; W = gMhhhhhh - or_lw 0b11000000 ; W = 11hhhhhh + ior_lw b'011000000' ; W = 11hhhhhh rcall board bt_f_if1 POSTINC0,7 ; *POSTINC0 : M....... bra loop ; otherwise: - panic morse_PS + panic morse_RS ;---------- board @@ -154,6 +157,18 @@ board_next_none bra board_next_none_more_message ;... ; now we're exiting from the loop in when_reverse_message_found - pop - return + pop ; that disposes of the call to `board' + + goto trackpower_decide + ; that will turn it off, since polarities_waiting is nonzero + +;---------- +board_next_none_more_message + panic morse_RL +;---------- +trackpower_decide + panic morse_UE + +;====================================================================== + include final.inc diff --git a/detpic/reverse.fin b/detpic/reverse.fin new file mode 100644 index 0000000..0ad7380 --- /dev/null +++ b/detpic/reverse.fin @@ -0,0 +1 @@ + extern polarity_local_init diff --git a/detpic/slave.asm b/detpic/slave.asm index 3b7d6c8..c356cd0 100644 --- a/detpic/slave.asm +++ b/detpic/slave.asm @@ -15,9 +15,12 @@ slave mov_fw picno call i2cs_init + call test_sofar_slave_startup_hook call bitnum2bit_init call points_local_init - call det_slave_init + call polarity_local_init + call detect_local_init + call detect_slave_init mov_lw (1<