From: ian Date: Sun, 4 Dec 2005 19:56:18 +0000 (+0000) Subject: new bit-twiddling and pindata arrangements build X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=ed024161cc12114f40e03c56c21a0cb3aba58af8;p=trains.git new bit-twiddling and pindata arrangements build --- diff --git a/cebpic/.cvsignore b/cebpic/.cvsignore index 13f1d62..1b610ec 100644 --- a/cebpic/.cvsignore +++ b/cebpic/.cvsignore @@ -8,5 +8,5 @@ blank[0246].asm gpsim.log idlocs*.asm morse+auto.inc -ours-pindata.asm +ours+pindata.asm routines.lib diff --git a/cebpic/Makefile b/cebpic/Makefile index 55d481a..e576b23 100644 --- a/cebpic/Makefile +++ b/cebpic/Makefile @@ -12,7 +12,7 @@ PROGRAMS= led-flash send-serial panic reply-serial \ ROUTINES= routines-led LIBS= routines.lib -INCLUDES= common.inc pindata.inc ../iwjpictest/clockvaries.inc +INCLUDES= common.inc ../iwjpictest/clockvaries.inc include manypics.make diff --git a/cebpic/common.inc b/cebpic/common.inc index 8df4108..844920c 100644 --- a/cebpic/common.inc +++ b/cebpic/common.inc @@ -30,26 +30,6 @@ TESTFLASH equ 04h ; test LED flash pattern morse_messages_start equ 0x4000 morse_messages_end equ 0x4400 -;-------------------- -; Areas filled in by ../layout/ours-pindata.asm -; (see pindata.inc for details) -pt_pic_data equ 0x6000 -pt_port_data equ 0x6100 -pt_bit_data equ 0x6200 - -sense_pic_data equ 0x6400 -sense_port_data equ 0x6500 -sense_bit_data equ 0x6600 - -reverse_pic_data equ 0x6800 -reverse_port_data equ 0x6900 -reverse_bit_data equ 0x6a00 - -pt_num_max equ 256 -sense_num_max equ 256 -reverse_num_max equ 256 - - ;---------------------------------------- ; ifbit1(REGISTER,BITNUMBER) ; executes the next instruction but only if bit BITNUMBER diff --git a/cebpic/manypics.make b/cebpic/manypics.make index eda53a2..6ad265a 100644 --- a/cebpic/manypics.make +++ b/cebpic/manypics.make @@ -32,7 +32,8 @@ define makesubmakefile set -e; d=.submakefile.new; rm -f $$d; for f in "$$@";do echo "$$f" >>$$d; done -- $(foreach prog, $(PROGRAMS), $(call define_prog,$(prog))) -$(foreach da, idlocs% config %+morse blank%, $(call define_directasm,$(da))) +$(foreach da, idlocs% config %+morse %+pindata blank%, + $(call define_directasm,$(da))) endef .submakefile: $(CEBPIC)manypics.make Makefile @@ -79,11 +80,11 @@ morse+auto.inc: $(CEBPIC)morse-generator morse.messages ' <$< $o %+vars.fin: %.asm $(CEBPIC)manypics.make - perl -ne ' \ + perl -ne ' \ BEGIN { print "; autogenerated - do not edit\n"; } \ - next unless m/^(\w+)\s/; \ - next if m/^\w+\s+equ\s+/; \ - print " extern $$1\n" or die $$!; \ + next unless m/^(\w+)\s/; \ + next if m/^\w+\s+(?:equ|udata|udata_acs)\s+/; \ + print " extern $$1\n" or die $$!; \ ' <$< $o %+morse.asm: $(CEBPIC)morse-generator morse.messages %+program.map @@ -95,7 +96,7 @@ morse+auto.inc: $(CEBPIC)morse-generator morse.messages idlocs%.asm: $(CEBPIC)make-idlocs ../layout/ours.wiring ./$^ $* >$@.new && mv -f $@.new $@ -ours-pindata.asm: ../layout/ours-pindata.asm +ours+pindata.asm: ../layout/ours+pindata.asm cp $< $@ manypic-clean: pic-clean diff --git a/cebpic/pindata.inc b/cebpic/pindata.inc deleted file mode 100644 index 8a59d20..0000000 --- a/cebpic/pindata.inc +++ /dev/null @@ -1,43 +0,0 @@ -; This .inc file is included by the autogenerated ours-pindata.asm -; and should define the things that ours-pindata.asm needs. - -; ours-pindata.asm contains data specifying which PIC pins correspond -; to which points (`pt'), section reversers (`reverse') and section -; detections (`sense'). -; -; Objects are numbered starting at 1; object number 0 is always -; unused/undefined. -; -; For each object kind KIND there are three data areas in -; to the flash program memory, starting at -; KIND_pic_data -; KIND_port_data -; KIND_pin_data -; (all of which must be defined by this file, pindata.inc, -; or something it includes - they're in common.inc at the moment). -; -; Each of these data areas is an array of bytes, one per object. The -; first byte (at KIND_pic_data) is for object no.0, the next (at -; KIND_pic_data+1) is for object no.1, etc. (Object no.0 is never -; used.) -; -; The byte values in each section are as follows: -; -; KIND_pic_data PIC number which controls this object (0 for the -; master PIC, etc.). 0xff if this object number is -; undefined/unused. The KIND_pic_data array is -; filled up to but not including KIND_pic_data + -; KIND_num_max. (KIND_num_max must be defined by -; pindata.inc ie in common.inc). -; -; KIND_port_data Low byte of address of the relevant LATx for the -; object. If the object number is unused, the -; value in flash is undefined (ie it may be -; anything). -; -; KIND_pin_data Byte with exactly one bit, being the relevant -; bit of the LATx/PORTx/TRISx. If the object -; number is unused, the value in flash is undefined -; (ie it may be anything). - - include common.inc diff --git a/detpic/.cvsignore b/detpic/.cvsignore index f13daf9..1c969ff 100644 --- a/detpic/.cvsignore +++ b/detpic/.cvsignore @@ -10,5 +10,5 @@ blank[0246].asm gpsim.log idlocs*.asm morse+auto.inc -ours-pindata.asm +ours+pindata.asm syncwrite.asm diff --git a/detpic/Makefile b/detpic/Makefile index 0679bc2..e3c731d 100644 --- a/detpic/Makefile +++ b/detpic/Makefile @@ -7,7 +7,7 @@ OBJS_test-sofar= vectors.o panic.o routines-led.o i2clib.o \ misc.o slave.o detect.o variables.o \ syncwrite.o XCODEN_test-sofar= morse -XCODE1_test-sofar= blank2 blank6 +XCODE1_test-sofar= blank2 ours+pindata INCLUDES= common.inc \ final.inc \ diff --git a/detpic/detect.asm b/detpic/detect.asm index 0326ff1..72cdad1 100644 --- a/detpic/detect.asm +++ b/detpic/detect.asm @@ -99,7 +99,7 @@ message_buffer_end ; will be read). outmsg_end points to the first byte after the ; message, and is used for read overrun detection. ; -; During i2csu_read_start (High ISR), the actual first byte of the +; During i2csu_read_begin (High ISR), the actual first byte of the ; message to be sent is calculated from buf0, and transmitted; the ; extra detection bytes (if any) are stored in outbuf, and any extra ; messages (from message_buffer) are also appended to outbuf. @@ -109,15 +109,15 @@ message_buffer_end ;---------- det_common_init - mov_lw 0b111 ; turn off comparator, or we can't use pins + mov_lw b'111' ; turn off comparator, or we can't use pins mov_wf CMCON ; RD0-RD4 as digital inputs - mov_lw 0b0110 ; turn off A/D except perhaps for pin - or_wff ADCON1 ; AN0 ie SPARE ie RA0 (same reason as above) + 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 - bsr det_common_init + rcall det_common_init set_f scana set_f scanb set_f scanc @@ -150,8 +150,8 @@ slave_add_short_message i2csu_read_begin ; called from High ISR, see i2clib.inc bt_f_if1 idloc1,idloc1_boarddet - bra det_slave_read_start_detectors - bra det_slave_read_start_reversers + bra i2csu_read_begin_detectors + bra i2csu_read_begin_reversers ;---------- i2csu_read_another @@ -282,7 +282,7 @@ i2csu_read_begin_detectors ;---------------------------------------------------------------------- ; both detectors and reversers ; -i2csu_read_start_either_tail +i2csu_read_begin_either_tail set_f scana set_f scand @@ -295,7 +295,7 @@ msg_copy_loop mov_wf POSTINC2 bra_n msg_copy_loop - mov_ff FSR2L, outmsg_lastbyte + mov_ff FSR2L, outmsg_end reset_message_buffer ; FSR1/buf0/message_buffer any set to empty @@ -307,7 +307,7 @@ reset_message_buffer ;---------- new_i2c_outmsg -; Called from i2csu_read_start ISR to check that the whole of +; Called from i2csu_read_begin ISR to check that the whole of ; the previous message was read, and to reset the FSR2 pointer ; to point to the start of outbuf so that we can fill the outbuf. mov_fw FSR2L ; W -> byte after the one we last sent @@ -349,7 +349,7 @@ i2csu_read_begin_reversers rcall new_i2c_outmsg - bra both_startread_tail + bra i2csu_read_begin_either_tail ;====================================================================== include final.inc diff --git a/detpic/detect.inc b/detpic/detect.inc index db1511b..70f580d 100644 --- a/detpic/detect.inc +++ b/detpic/detect.inc @@ -1,5 +1,3 @@ - extern det_slave_setup - extern det_scanloop_reversers - extern det_scanloop_detectors - extern det_read_start_reversers - extern det_read_start_detectors + extern det_slave_init + extern backgroundloop_reversers + extern backgroundloop_detectors diff --git a/detpic/morse.messages b/detpic/morse.messages index b6848c9..8f5cd89 100644 --- a/detpic/morse.messages +++ b/detpic/morse.messages @@ -46,8 +46,8 @@ SD i2clib:st ; impr. i2cm_read_done/i2cs_read_data # Messages for slave detection/i2c DW ; slave write (nyi) -DQ FSR2L,outmsg_end ; previous slave read incomplete -DR FSR2L,outmsg_end ; slave read overrun +DQ FSR2L,:outmsg_end ; previous slave read incomplete +DR FSR2L,:outmsg_end ; slave read overrun # Messages for specific peripherals PS FSR0L ; POLARITY message too short diff --git a/detpic/pindata.inc b/detpic/pindata.inc index cba20d7..2ffce54 100644 --- a/detpic/pindata.inc +++ b/detpic/pindata.inc @@ -1,19 +1,9 @@ ;====================================================================== -pt_pic_data equ 0x5000 -pt_port_data equ 0x5100 -pt_bit_data equ 0x5200 +picno2ptmap equ 0x6000 +bkptix2portnumbitnum equ 0x6100 +pic2detinfo equ 0x6200 +picno2revbits equ 0x6300 -pt_num_max equ 255 - -sense_pic_data equ 0x5400 -sense_port_data equ 0x5500 -sense_bit_data equ 0x5600 - -sense_num_max equ 255 - -reverse_pic_data equ 0x5800 -reverse_port_data equ 0x5900 -reverse_bit_data equ 0x5a00 - -reverse_num_max equ 255 +maxpic_ln2 equ 5 +maxpic equ 1 << maxpic_ln2 diff --git a/detpic/slave.asm b/detpic/slave.asm index a69174b..662797e 100644 --- a/detpic/slave.asm +++ b/detpic/slave.asm @@ -13,7 +13,7 @@ ; picno, idloc1 containing correct values read from flash slave - call det_slave_setup + call det_slave_init mov_fw picno call i2cs_init @@ -21,8 +21,8 @@ slave mov_wf INTCON bt_f_if1 idloc1,idloc1_boarddet - goto det_scanloop_detectors - goto det_scanloop_reversers + goto backgroundloop_detectors + goto backgroundloop_reversers ;---------- i2csu_write_begin diff --git a/detpic/test-sofar.asm b/detpic/test-sofar.asm index 41b2362..de5c553 100644 --- a/detpic/test-sofar.asm +++ b/detpic/test-sofar.asm @@ -72,7 +72,6 @@ udata_acs -t res 1 ch res 1 mode res 1 mode_readhex equ 0 diff --git a/detpic/variables.asm b/detpic/variables.asm index 1fbbd45..f9f16ce 100644 --- a/detpic/variables.asm +++ b/detpic/variables.asm @@ -8,12 +8,12 @@ idloc1_boarddet equ 6 t res 1 ; general temporary outmsg_end res 1 ; first empty byte in outbuf - udata 0x200 +outbuf_section udata 0x200 outbuf_szln2 equ 7 outbuf_size equ (1<= $nreverses; } } +sub line_boards_detectors { } sub mistake ($) { my ($m) = @_; @@ -230,16 +235,18 @@ sub pa_boob ($) { return [ $1,$2 ]; } -# so_boob_KIND($boardnum,$objnum,$boardtype,$pininfo) -> global object number +# boob2objnum_KIND($boardnum,$objnum,$boardtype,$mkused +# -> global object number -sub so_boob_pt { +sub boob2objnum_pt { my ($boardnum,$obj)=@_; - mistake("point encoding out of range") if $boardnum>31; - die if $obj > 31; - return ($boardnum << 5) | $obj; + mistake("point encoding out of range") if + $boardnum >= (1 << (10 - $maxptixln2)); + die if $obj >= (1 << $maxptixln2); + return ($boardnum << $maxptixln2) | $obj; } -sub so_boob_reverse { +sub boob2objnum_reverse { my ($boardnum,$obj,$boardtype)=@_; # Converts board and object number (in canonical pic number plus @@ -260,7 +267,7 @@ sub so_boob_reverse { my ($cycle,$boardincycle,$cyclebasebyte,$byte,$bit); die unless $boardtype eq 'reversers'; - die if $obj > 5; + die $obj if $obj > 5; $obj = sprintf '%d', $obj; $obj =~ y/302154/543210/; # mapping due to polarity_do_here $cycle= int(($boardnum+3) / 7); @@ -281,7 +288,7 @@ sub so_boob_reverse { return $byte*7 + 3 - $bit; } -sub so_boob_sense($$$) { +sub boob2objnum_sense { my ($boardnum,$obj)=@_; my ($inpage); $inpage= $obj + $sensesbase[$boardnum]; @@ -289,8 +296,23 @@ sub so_boob_sense($$$) { return ($boardnum << 7) | $inpage; } -sub so_boob ($$) { - my ($kind,$bo) = @_; +sub boob2objnum ($$$$) { + my ($boardnum,$obj,$kind,$mkused) = @_; + my ($type); + $type= $boardtype[$boardnum]; + return &{"boob2objnum_$kind"}($boardnum,$obj,$type,$mkused); +} + +sub boob_used_bit ($$$) { + my ($boardnum,$obj,$kind) = @_; + my ($objnum); + $objnum= boob2objnum($boardnum, $obj, $kind, 0); + return defined $pin_used{$kind}[$objnum] ? 1 : 0; +} + +sub so_boob ($$$) { + my ($kind,$mkused,$bo) = @_; + my ($type,$pi); if (defined $bo) { my ($board,$obj)= @$bo; my ($objnum,$type,$pi); @@ -301,17 +323,18 @@ sub so_boob ($$) { mistake("object reference $kind $board.$obj out of range for". " board type $type") unless defined $pi->[$obj]; - $objnum= &{"so_boob_$kind"}($board,$obj,$type,$pi); - $pin_used{$kind}[$objnum]= [ $board, $pi->[$obj], $obj ]; + $objnum= boob2objnum($board,$obj,$kind,$mkused); + $pin_used{$kind}[$objnum]= [ $board, $pi->[$obj], $obj ] + if $mkused; return sprintf("%4d /* %d.%-2d*/", $objnum, $board, $obj); } else { return " 0 /*none*/ "; } } -sub so_oboob ($$) { - my ($kind,$obj) = @_; - return so_boob($kind, defined $obj ? $obj->{BoOb} : undef); +sub so_objboob ($$$) { + my ($kind,$mkused,$obj) = @_; + return so_boob($kind,$mkused, defined $obj ? $obj->{BoOb} : undef); } sub mainread () { @@ -406,7 +429,7 @@ sub writeout () { $delim=' '; foreach $boob (@{ $ptv->{BoOb} }) { o($delim); - o(so_boob('pt',$boob)); + o(so_boob('pt',1, $boob)); $delim= ', '; } o(" };\n"); @@ -434,8 +457,8 @@ sub writeout () { "\"$seg\",", $segr->{Inv}, $segr->{FeatCount}, ($segr->{FeatCount} ? "mfi_$seg," : '0,'), $segr->{Posns}, "spci_$seg,", - so_oboob('sense',$segr), - so_oboob('reverse', $segr->{Inv} ? $segr : undef)); + so_objboob('sense',1, $segr), + so_objboob('reverse',1, $segr->{Inv} ? $segr : undef)); $delim= ','; } o("\n};\n"); @@ -443,79 +466,144 @@ sub writeout () { # writeasm_KIND() -sub o_section ($) { - my ($sec) = @_; - o("$sec code ${sec}_start"); +sub o_section ($$) { + my ($sec,$docstring) = @_; + o("\n;----------\n". + " org $sec\n"); + o($docstring); +} +sub o_section_end_fill ($$$) { + my ($lastnumdone, $fillvalue, $entrysize) = @_; + if ($entrysize == 1 and $lastnumdone & 1) { + o(", $fillvalue & 0xff\n"); + $lastnumdone++; + } else { + o("\n"); + } + o(sprintf " fill %s, %d*(maxpic-%d)\n\n", + $fillvalue, $entrysize, $lastnumdone); +} + +sub o_db ($;$) { + my ($ix,$every) = @_; + $every=16 unless defined $every; + o(($every ? $ix % $every : $ix) ? ',' : "\n db "); } sub writeasm_sense { - o_section("pindata_pic2detinfo"); - o("Exists equ 0x8000\n". - "Detectors equ 0x0080\n". - "Reversers equ 0x0000\n"); + my ($num, $base); + o_section('pic2detinfo',<<'END'); +; Table indexed by pic no., giving information about sensing +; Each element is two bytes: +; 1st byte bit 7 Set iff this board exists for the purposes of sensing +; bits 6-3 Not used, set to zero +; bits 2-0 Top 3 bits of sense segment numbers on this board +; 2nd byte bit 7 Set iff this board is a Detectors board +; bits 6-0 Base for bottom 7 bits of segment number +; (per-board segment no. is added to this; carry +; to upper 3 bits is not permitted) +END + o("SenseExists equ 0x80\n". + "Detectors equ 0x80\n". + "Reversers equ 0x00\n\n"); for ($num=0; $num<@boardtype; $num++) { - if (!defined $boardtype[$num]) { o(" dw 0\n"); next; } + if (!defined $boardtype[$num]) { o(" dw 0\t\t\t\t; $num\n"); next; } $base= $sensesbase[$num]; - o(sprintf " dw Exists | %-10s | 0x%02x%02x\n", - ucfirst($boardtype[$num]), $base >> 7, $base & 0x7f); + o(sprintf " db SenseExists | 0x%02x, %12s | 0x%02x\t; %d\n", + $base >> 7, ucfirst($boardtype[$num]), $base & 0x7f, $num); + } + o_section_end_fill($num, 0, 2); +} + +sub writeasm_pt { + my ($num, $elemsize, $byte, $bit, $objnum); + o_section('picno2ptmap',<<'END'); +; Bitmap indexed first by pic no, and then by point no. on that board, +; saying whether the point is present or not. Each pic has 4 bytes, +; ie 32 bits. First byte is points 0 to 7, in bits 0 to 7 respectively +; so that MSbit of byte 3 (4th byte) is point no.31. Unused boards +; or boards with no points are all-bits-0. +END + for ($num=0; $num<@boardtype; $num++) { + if (!defined $boardtype[$num]) { o(" dw 0\t\t\t\t; $num"); next; } + die if $maxptixln2 < 4; # must be whole no. of 16-bit words + $elemsize= 1 << ($maxptixln2-3); + for ($byte=0; $byte < $elemsize; $byte++) { + o_db($byte, 0); + o("b'"); + for ($bit=7; $bit>=0; $bit--) { + o(boob_used_bit($num, $byte*8 + $bit, 'pt')); + } + o("'"); + } + o(" ; $num"); } - o(sprintf " fill 0, maxboards_count-%d\n", $num); o("\n"); + o_section_end_fill($num, 0, $elemsize); + + my($typeix,$type,$pt,$pi); + o_section('bkptix2portnumbitnum',<<"END"); +; Table giving physical ports and pins for points for each +; kind of board. Index is point number (for reversers boards) +; or point number + 2^$maxptixln2 (for detectors boards). +; Value is one byte, either 0xff meaning that board type has +; no such point, or top nybble being port number (0 for A, 1 for B, +; etc.) and bottom nybble being bit number. Ie, +; Index: 00Dppppp where D is 1 iff detectors board and p is pt ix +; Value: 0ppp0bbb where p is port num and b is bit num; or 0xff +END + o(" radix hex\n"); + for ($typeix=0; $typeix<2; $typeix++) { + $type= qw(reversers detectors)[$typeix]; + die $type unless $pin_info{$type}; + o("; $type:"); + for ($pt=0; $pt < (1 << $maxptixln2); $pt++) { + o_db($pt); + $pi= $pin_info{$type}{'pt'}[$pt]; + if (defined $pi) { + $pi =~ m/^(\d)\,(\d)\,/ or die; + o($1.$2); + } else { + o('ff'); + } + } + o("\n"); + } + o(" radix dec\n\n"); +} + +sub writeasm_reverse { + my ($num,$kc,$bit); + o_section('picno2revbits',< 7; + o("b'"); + for ($bit= $kc-1; $bit>=0; $bit--) { + o(boob_used_bit($num, $bit, 'reverse')); + } + o("'"); + } else { + o('0xff'); + } + } + o_section_end_fill($num, '0xffff', 1); } -# for $w (qw(pic port bit)) { -# @d=(); -# o("\n"); -# o("${k}_${w}_data_section org ${k}_${w}_data\n"); -# for ($i=0; $i<@{ $pin_used{$k} }; $i++) { -# $or= $pin_used{$k}[$i]; -# if (defined $or) { -# $or->[1] =~ m/^(\d+)\,\d+,(\w+)$/; -# ($portnum,$bit)= ($1,$2); -# $portnum= sprintf "%02x", $portnum + 0x89; # 89=LATA -# $bit= sprintf "%02x", hex $bit; -# } else { -# $portnum=$bit='00'; -# } -# if ($w eq 'pic') { -# if (defined $or) { -# push @d, $or->[0]; -# } else { -# push @d, 'X', -# } -# } elsif ($w eq 'port') { -# push @d, $portnum; -# } elsif ($w eq 'bit') { -# push @d, $bit; -# } else { -# die; -# } -# } -# push @d, 'X' if @d^1; -# @d= map { s/^[a-f]/0$&/; sprintf "%3s", $_ } @d; -# for (;;) { -# $d[$each/2] = " $d[$each/2]" if $#d >= $each/2; -# last if @d <= $each; -# o(" db ". join(',',@d[0..($each-1)]). "\n"); -# @d= @d[$each..$#d]; -# } -# o(" db ".join(',',@d)."\n"); -# if ($w eq 'pic') { -# o(" if \$ > ${k}_pic_data + ${k}_num_max\n". -# " error \"too much ${k}_picdata\"\n". -# " endif\n". -# " fill 0xffff, ${k}_pic_data + ${k}_num_max - \$\n"); -# } -# } -# } sub writeasm () { my ($k,$w,$i,@d,$or,$p,$portnum,$bit,$each); close STDOUT or die $!; - open STDOUT, ">$basename-pindata.asm" or die $!; + open STDOUT, ">$basename+pindata.asm" or die $!; o("; autogenerated - do not edit\n"); o(" include pindata.inc\n". " radix dec\n". - "X equ 0xff\n"); + "ff equ 0xff\n"); $each= 10; for $k (@objkinds) { &{"writeasm_$k"}();