From ec78ccf4b194bf99dbf7b97916c2c8b12c6b760b Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 20 Nov 2005 01:17:47 +0000 Subject: [PATCH] new building arrangements for a better morse --- Makefile | 5 +- cebpic/.cvsignore | 1 + cebpic/manypics.make | 19 ++--- cebpic/morse-auto.asm-gen | 44 +++++++++--- detpic/.cvsignore | 2 + detpic/Makefile | 7 +- detpic/i2clib.asm | 138 ++++++++++++++++++------------------- detpic/i2clib.inc | 10 --- detpic/morse-auto.messages | 18 ++--- iwjpictest/.cvsignore | 2 +- iwjpictest/Makefile | 2 + pic.make | 4 +- 12 files changed, 141 insertions(+), 111 deletions(-) diff --git a/Makefile b/Makefile index 8b1db90..52b7afe 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,11 @@ all: picprogs hostprogs PICPROGS_DIRS= iwjpictest cebpic detpic HOSTPROGS_DIRS= layout hostside -picprogs: +pic: set -e; for f in $(PICPROGS_DIRS); do $(MAKE) -C $$f; done +pic_%: + set -e; for f in $(PICPROGS_DIRS); do $(MAKE) -C $$f $*; done + hostprogs: set -e; for f in $(HOSTPROGS_DIRS); do $(MAKE) -C $$f; done diff --git a/cebpic/.cvsignore b/cebpic/.cvsignore index 28b0f22..c0c7dd7 100644 --- a/cebpic/.cvsignore +++ b/cebpic/.cvsignore @@ -1,6 +1,7 @@ *.hex *.cod *.lst +*.map idlocs*.asm gpsim.log routines.lib diff --git a/cebpic/manypics.make b/cebpic/manypics.make index c9d729a..0fe7178 100644 --- a/cebpic/manypics.make +++ b/cebpic/manypics.make @@ -1,17 +1,20 @@ -TARGETS= $(foreach i, $(PICNOS), perpic$i.hex) - include ../common.make include ../pic.make perpic%.hex: config.o idlocs%.o $(LINK) -morse-auto.inc morse-auto.asm: \ - morse-auto.%: $(CEBPIC)morse-auto.asm-gen morse-auto.messages - ./$^ $* $o +morse-auto.inc: $(CEBPIC)morse-auto.asm-gen morse-auto.messages + ./$^ inc $o + +%-automorse.asm: $(CEBPIC)morse-auto.asm-gen morse-auto.messages %-bare.map + ./$^ asm $o + +%-bare.map: %.o $(LIBS) + gplink -m -o $*-bare.hex $^ -%-entire0.hex: %.o config.o idlocs0.o $(LIBS) +%-entire0.hex: %.o config.o idlocs0.o $(LIBS) $(DEFLIBS) $(LINK) idlocs%.asm: $(CEBPIC)make-idlocs @@ -21,6 +24,6 @@ ours-pindata.asm: ../layout/ours-pindata.asm cp $< $@ manypic-clean: pic-clean - rm -f idlocs*.asm + rm -f idlocs*.asm *.map *-automorse.* -.PRECIOUS: idlocs%.asm +.PRECIOUS: idlocs%.asm %-bare.map %-automorse.asm diff --git a/cebpic/morse-auto.asm-gen b/cebpic/morse-auto.asm-gen index 07ae2d7..e30b21e 100755 --- a/cebpic/morse-auto.asm-gen +++ b/cebpic/morse-auto.asm-gen @@ -25,16 +25,20 @@ # # morse_messages_start and morse_messages_end should be defined in # morse-defs.inc, and should also be 4-byte aligned. morse-defs.inc -# and morse-defs.fin should arrange to define any symbolic addresses -# referred to in morse-auto.messages, by saying `extern' (in .fin) or -# including the pXXXX.inc (in .inc). +# should also arrange to define any symbolic addresse referred to +# in morse-auto.messages, eg by including the pXXXX.inc. # # morse-auto.asm contains the actual source and morse-auto.inc # contains `extern' references for the labels morse_XY. +use IO::File; use IO::Handle; -sub badusage () { die "usage: morse-auto.asm-gen ... asm|inc\n"; } +sub badusage () { + die ("usages:\n". + " morse-auto.asm-gen ... asm\n". + " morse-auto.asm-gen ... [.map] inc\n"); +} @ARGV or badusage(); $which= pop @ARGV; @@ -50,6 +54,28 @@ while () { sub oops ($) { die "morse-auto.asm-gen: $ARGV:$.: $_[0]\n"; } +$mapfile= $ARGV[$#ARGV]; + +if ($mapfile =~ m/\.map$/) { + pop @ARGV; + $maph= new IO::File "$mapfile", 'r' or die "$0: $mapfile: $!\n"; + while (<$maph>) { + next unless m/^\s+Symbols\s+$/ .. !/\S/; + next unless m/\S/; + next if m/^\s+Symbols\s+$/; + next if m/^\s+Name\s+Address\s+Location\s+Storage\s+File\s*$/; + next if m/^(?:\s+\-\-+){5}\s*$/; + m/^\s*([0-9a-zA-Z_]+)\s+(0+|0x[0-9a-f]+)\s+(program|data)\s+(static|extern)\s+(\S+)\s*$/ + or die "$0: $mapfile:$.: cannot parse ?!\n"; + ($sym,$val,$progdata,$staticext,$filename) = ($1,$2,$3,$4,$5); + next if $progdata ne 'data'; + $filename =~ s/\.asm$//; + $sym= "$filename:$sym" if $staticext eq 'static'; + $symval{$sym}= $val; + } + die "$0: $mapfile: $!\n" if $maph->error; +} + $"=','; print <<'END' or die $! @@ -69,6 +95,7 @@ END if $which eq 'asm'; $bytes= 0; +$.= 0; while (<>) { chomp; @@ -95,10 +122,12 @@ while (<>) { $morse_bytes= scalar(@data); unshift @data, sprintf "0x%x%x", scalar(@addrs), $morse_bytes; -# push @data, @addrs; push @data, map { - "$_"; -# $_.'&0xff'; + s/^\:/ $filename.':' /e; + $filename= $1 if m/^(.+)\:/; + (exists $symval{$_} ? $symval{$_} : + "$_ - (0xf00 * !(($_ & 0xf00)^0xf00))"); + } @addrs; push @data, ('0') x (3 - (scalar(@data) + 3) % 4); @@ -119,7 +148,6 @@ print <<'END' or die $! error "too much morse - extends beyond morse_messages_end" endif - include morse-auto.fin end END if $which eq 'asm'; diff --git a/detpic/.cvsignore b/detpic/.cvsignore index 51de301..349455e 100644 --- a/detpic/.cvsignore +++ b/detpic/.cvsignore @@ -1,6 +1,8 @@ *.hex *.cod *.lst +*.map +*-automorse.asm idlocs*.asm gpsim.log morse-auto.asm diff --git a/detpic/Makefile b/detpic/Makefile index 4ea37a7..a0bf895 100644 --- a/detpic/Makefile +++ b/detpic/Makefile @@ -1,11 +1,12 @@ PROGRAMS= test-sofar INCLUDES= common.inc final.inc morse-auto.inc \ ../iwjpictest/insn-aliases.inc -LIBS= vectors.o panic.o routines-led.o variables.o \ - i2clib.o morse-auto.o +LIBS= vectors.o panic.o routines-led.o variables.o i2clib.o +DEFLIBS= test-sofar-automorse.o PICNOS= 0 1 2 CEBPIC= ../cebpic/ -TARGETS= $(foreach i, $(PICNOS), perpic$i.hex) +TARGETS= $(addsuffix -bare.map, $(PROGRAMS)) \ + $(foreach i, $(PICNOS), perpic$i.hex) include $(CEBPIC)manypics.make diff --git a/detpic/i2clib.asm b/detpic/i2clib.asm index 49e8b37..d90803f 100644 --- a/detpic/i2clib.asm +++ b/detpic/i2clib.asm @@ -37,12 +37,12 @@ ; ; ;---------- ; m_event_spong -; bt_f_if0 i2c_st, st_something +; bt_f_if0 st, st_something ; bra m_event_bad ; ;... ; ; m_event_several_including_spong -; bs_f i2c_st, st_sponging +; bs_f st, st_sponging ; bra metasyntacticing ; ; ;---------- @@ -53,14 +53,14 @@ udata_acs -i2c_sspstat res 1 -i2c_sspcon1 res 1 -i2c_sspcon2 res 1 ; master only -i2c_slave res 1 ; master only +sspstat res 1 +sspcon1 res 1 +sspcon2 res 1 ; master only +slave res 1 ; master only -i2c_st res 1 +st res 1 -; i2c_st is a bitmask, bit set in visible states: +; st is a bitmask, bit set in visible states: ; master slave st_starting equ 7 ; Writing-Setup?,Reading-Busy? st_addressing equ 6 ; Writing-Setup?,Reading-Busy? @@ -102,41 +102,41 @@ i2cm_interrupt return ; We have an interrupt: - mov_ff SSPSTAT, i2c_sspstat - mov_ff SSPCON1, i2c_sspcon1 - mov_ff SSPCON2, i2c_sspcon2 + mov_ff SSPSTAT, sspstat + mov_ff SSPCON1, sspcon1 + mov_ff SSPCON2, sspcon2 - bt_f_if1 i2c_sspcon1, WCOL + bt_f_if1 sspcon1, WCOL bra_z m_event_bad - bt_f_if1 i2c_sspcon1, SSPOV + bt_f_if1 sspcon1, SSPOV bra_z m_event_bad ; No ? Well, then the I2C should be idle now: - mov_fw i2c_sspcon2 + mov_fw sspcon2 and_lw ~0x60 ; ACKSTAT,ACKDT bra_nz m_event_bad ; OK... - bt_f_if1 i2c_sspstat, R_W + bt_f_if1 sspstat, R_W bra_nz m_event_bad - bt_f_if1 i2c_st, st_stopping + bt_f_if1 st, st_stopping bra m_event_done_stopping - bt_f_if1 i2c_st, st_starting + bt_f_if1 st, st_starting bra m_event_done_starting ; not just done SEN - bt_f_if1 i2c_st, st_addressing + bt_f_if1 st, st_addressing bra m_event_done_addressing - bt_f_if1 i2c_st, st_writing + bt_f_if1 st, st_writing bra m_event_done_writing - bt_f_if1 i2c_st, st_acking + bt_f_if1 st, st_acking bra m_event_done_acking - bt_f_if1 i2c_st, st_reading + bt_f_if1 st, st_reading bra m_event_done_reading m_event_bad @@ -147,40 +147,40 @@ m_event_bad ;---------- m_start -; i2c_st checked for busyness correct +; st checked for busyness correct ; st_reading/writing set unchanged ; st_starting clear set ; W slave number any -; i2c_slave any slave_number +; slave any slave_number ; expects to return directly to main program (caller) - mov_wf i2c_slave + mov_wf slave and_lw 31 bra_nz m_improper_slave - bs_f i2c_st, st_starting + bs_f st, st_starting bs_f SSPCON2, SEN return ;---------- m_event_done_starting - mov_fw i2c_slave + mov_fw slave rcall slave2addr - bt_f_if1 i2c_st, st_reading + bt_f_if1 st, st_reading bs_w 0 ; address bottom bit means read mov_wf SSPBUF - bc_f i2c_st, st_starting - bs_f i2c_st, st_addressing + bc_f st, st_starting + bs_f st, st_addressing return ;---------- m_event_done_addressing - bt_f_if1 i2c_sspcon2, ACKSTAT + bt_f_if1 sspcon2, ACKSTAT bra m_bad_address_ack ; OK, we got ack. - bc_f i2c_st, st_addressing - bt_f_if1 i2c_st, st_reading + bc_f st, st_addressing + bt_f_if1 st, st_reading bra m_event_done_addressing_read bra m_event_done_addressing_write @@ -189,13 +189,13 @@ m_stop ; st_stopping clear set ; st_reading/acking/writing any unchanged ; expects to return directly to main program or to end interrupt handler - bs_f i2c_st, st_stopping + bs_f st, st_stopping bs_f SSPCON2, PEN return ;---------- m_event_done_stopping - clr_f i2c_st + clr_f st goto i2cmu_done ;---------- @@ -204,7 +204,7 @@ m_bad_address_ack ;---------- m_improper_slave -; i2c_slave slave number +; slave slave number panic morse_SN ;======================================== @@ -215,19 +215,19 @@ i2cm_write_start ; At call On return ; State Idle Writing-Setup ; W slave number any - tst_f_ifnz i2c_st + tst_f_ifnz st bra m_improper_write_start - bs_f i2c_st, st_writing + bs_f st, st_writing bra m_start ;---------- m_event_done_writing ; Did slave ack our byte ? It had better have done ! - bt_f_if1 i2c_sspcon2, ACKSTAT + bt_f_if1 sspcon2, ACKSTAT bra m_event_bad - bs_f i2c_st, st_subsequent + bs_f st, st_subsequent ;... m_event_done_addressing_write @@ -242,7 +242,7 @@ m_event_done_addressing_write ;---------- m_event_write_mustfinish - bt_f_if0 i2c_st, st_subsequent + bt_f_if0 st, st_subsequent bra m_improper_write_finish bra m_stop @@ -263,10 +263,10 @@ i2cm_read_start ; At call On return ; State Idle Reading-Busy ; W slave number any - tst_f_ifnz i2c_st + tst_f_ifnz st bra m_improper_read_start - bs_f i2c_st, st_reading + bs_f st, st_reading bra m_start ;---------- @@ -279,18 +279,18 @@ m_event_done_acking_readmore ;---------- m_event_done_reading - bt_f_if0 i2c_sspstat, BF + bt_f_if0 sspstat, BF bra m_event_bad mov_fw SSPBUF - bs_f i2c_st, st_awaiting + bs_f st, st_awaiting goto i2cmu_read_got_byte ;---------- i2cm_read_another ; State Reading-Wait Reading-Busy - bt_f_if0 i2c_st, st_awaiting + bt_f_if0 st, st_awaiting bra m_improper_read_another ; OK, we're fine to read another: ;... @@ -300,8 +300,8 @@ m_read_ack ; st_awaiting still set cleared ; st_acking clear set ; expects to return directly to main program or to end interrupt handler - bc_f i2c_st, st_awaiting - bs_f i2c_st, st_acking + bc_f st, st_awaiting + bs_f st, st_acking bc_f SSPCON2, ACKDT ; ACKDT=0 means to acknowledge bs_f SSPCON2, ACKEN return @@ -309,9 +309,9 @@ m_read_ack ;---------- i2cm_read_done ; State Reading-Wait Stopping - bc_f i2c_st, st_reading + bc_f st, st_reading - bt_f_if0 i2c_st, st_awaiting + bt_f_if0 st, st_awaiting bra m_improper_read_done ; OK: @@ -319,9 +319,9 @@ i2cm_read_done ;---------- m_event_done_acking - bc_f i2c_st, st_acking + bc_f st, st_acking - bt_f_if1 i2c_st, st_reading + bt_f_if1 st, st_reading bra m_event_done_acking_readmore bra m_stop @@ -346,7 +346,7 @@ i2cs_init ; W slave number undefined rcall slave2addr mov_wf SSPADD - clr_f i2c_st + clr_f st mov_lw 0x16 ; !SSPEN, CKP(release), I2C 7-bit slave no-SP-int mov_wf SSPCON1 mov_lw 0x01 ; !GCEN, SEN @@ -364,9 +364,9 @@ init_enable ; SSPIP any configured correctly ; GIEL 0 (disabled) 0 (disabled) ; ssp* shadows any all bits set - set_f i2c_sspstat - set_f i2c_sspcon1 - set_f i2c_sspcon2 + set_f sspstat + set_f sspcon1 + set_f sspcon2 bs_f TRISB, 0 bs_f TRISB, 1 bc_f IPR1, SSPIP @@ -387,7 +387,7 @@ init_enable ; Some macros: chkvals_start_sspstat macro - mov_fw i2c_sspstat + mov_fw sspstat endm chkval macro lastval, value, label @@ -407,22 +407,22 @@ i2cs_interrupt return ; We have an interrupt: - bt_f_if1 i2c_sspcon1, WCOL + bt_f_if1 sspcon1, WCOL bra_z s_event_bad - bt_f_if1 i2c_sspcon1, SSPOV + bt_f_if1 sspcon1, SSPOV bra_z s_event_bad ; Firstly, clear the interrupt flag so that if something else happens ; while we faff, the interrupt will be regenerated: bc_f PIR1, SSPIF - mov_ff SSPSTAT, i2c_sspstat - mov_ff SSPCON1, i2c_sspcon1 + mov_ff SSPSTAT, sspstat + mov_ff SSPCON1, sspcon1 - bt_f_if0 i2c_st, st_reading + bt_f_if0 st, st_reading bra s_event_reading - bt_f_if0 i2c_st, st_writing + bt_f_if0 st, st_writing bra s_event_writing s_event_idle @@ -436,7 +436,7 @@ s_event_bad ;---------- s_event_idle_addrrecvread - bs_f i2c_st, st_reading + bs_f st, st_reading call i2csu_read_begin bra s_events_reading_datasend @@ -446,7 +446,7 @@ s_event_reading chkval 0, 0xac, s_event_reading_datasent ; D,!P, S,R,!BF ; Whatever is happening, we're done reading now ! - clr_f i2c_st + clr_f st call i2csu_read_done chkvals_start_sspstat @@ -471,7 +471,7 @@ s_event_reading_datanack ;---------- s_event_idle_addrrecvwrite bs_f SSPCON1, 3 ; we'll need the Stop interrupt - bs_f i2c_st, st_writing + bs_f st, st_writing ; well, this is all fine so far, so do carry on: s_write_slurpbyte @@ -487,7 +487,7 @@ s_event_writing chkval 0, 0xa9, s_event_writing_datarecv ; D,!P, S,W,BF ; Well, we're done writing now in any case - clr_f i2c_st + clr_f st bc_f SSPCON1, 3 ; no Start and Stop interrupts any more call i2csu_write_done @@ -501,7 +501,7 @@ s_event_writing chkvals_addrrecv 0 ; Then random junk: - mov_fw i2c_sspstat + mov_fw sspstat and_lw 0xc7 ; ?D_A, ?P; ?S xor_lw 0x80 ; SMP, !CKE, !R_W, !UA, !BF bt_f_if1 STATUS, Z @@ -514,11 +514,11 @@ s_event_writing s_event_writing_datarecv rcall s_write_slurpbyte - bt_f_if1 i2c_st, st_subsequent + bt_f_if1 st, st_subsequent goto i2csu_write_another ; not subsequent (yet): - bs_f i2c_st, st_subsequent + bs_f st, st_subsequent goto i2csu_write_begin ;====================================================================== diff --git a/detpic/i2clib.inc b/detpic/i2clib.inc index a8d2b1d..d96cbd6 100644 --- a/detpic/i2clib.inc +++ b/detpic/i2clib.inc @@ -322,13 +322,3 @@ ; ; Beforehand At call On return ; State Transmitting Idle - -;====================================================================== -; INTERNAL VARIABLES -; -; these are `extern'd only so that the morse machinery can display them - extern i2c_sspstat - extern i2c_sspcon1 - extern i2c_sspcon2 - extern i2c_slave - extern i2c_st diff --git a/detpic/morse-auto.messages b/detpic/morse-auto.messages index f8fd2aa..ed079ba 100644 --- a/detpic/morse-auto.messages +++ b/detpic/morse-auto.messages @@ -31,12 +31,12 @@ TI5 ; for iwj X ch ; bad character received from host # Messages for i2clib, S* -SM i2c_st,i2c_sspstat,i2c_sspcon1,i2c_sspcon2 ; m.,i., ctrlr bad state -SS i2c_st,i2c_sspstat,i2c_sspcon1 ; slave, intr, controller bad state -SK i2c_slave ; m. couldn't address slave (no ack) -SN i2c_slave ; improper slave number -SW i2c_st ; improper i2cm_write_start -SF i2c_st ; improper i2cmu_write_next_byte Z -SR i2c_st ; improper i2cm_read_start -SA i2c_st ; improper i2cm_read_another -SD i2c_st ; improper i2cm_read_done +SM i2clib:st,:sspstat,:sspcon1,:sspcon2 ; m.,i., ctrlr bad state +SS i2clib:st,:sspstat,:sspcon1 ; slave, intr, controller bad state +SK i2clib:slave ; m. couldn't address slave (no ack) +SN i2clib:slave ; improper slave number +SW i2clib:st ; improper i2cm_write_start +SF i2clib:st ; improper i2cmu_write_next_byte Z +SR i2clib:st ; improper i2cm_read_start +SA i2clib:st ; improper i2cm_read_another +SD i2clib:st ; improper i2cm_read_done diff --git a/iwjpictest/.cvsignore b/iwjpictest/.cvsignore index 9ddea0c..9b1501a 100644 --- a/iwjpictest/.cvsignore +++ b/iwjpictest/.cvsignore @@ -1,7 +1,7 @@ *.hex *.cod *.lst +*.map insn-*.ps insn-*.txt insn-aliases.inc -*.tmp diff --git a/iwjpictest/Makefile b/iwjpictest/Makefile index 959afef..696a170 100644 --- a/iwjpictest/Makefile +++ b/iwjpictest/Makefile @@ -6,6 +6,8 @@ INSN_TARGETS= insn-aliases.inc \ PROGRAMS= flasher copybits serialloop harness +INCLUDES= insn-aliases.inc onecopybit.inc test.inc + include ../common.make include ../pic.make diff --git a/pic.make b/pic.make index 974b843..8856d93 100644 --- a/pic.make +++ b/pic.make @@ -18,13 +18,13 @@ PROGRAM_HEXES= $(addsuffix .hex, $(PROGRAMS)) \ $(addsuffix -withcfg.hex, $(PROGRAMS)) all: $(TARGETS) $(PROGRAM_HEXES) -LINK= gplink -o $@ $^ +LINK= gplink -m -o $@ $^ ASSEMBLE= gpasm -p 18f458 %-withcfg.hex: %.o config.o $(LIBS) $(LINK) -%.hex: %.o $(LIBS) +%.hex: %.o $(LIBS) $(DEFLIBS) $(LINK) %.o: %.asm $(INCLUDES) -- 2.30.2