chiark / gitweb /
initial cut of morse message generator
authorian <ian>
Mon, 2 May 2005 10:59:45 +0000 (10:59 +0000)
committerian <ian>
Mon, 2 May 2005 10:59:45 +0000 (10:59 +0000)
cebpic/.cvsignore
cebpic/Makefile
cebpic/common.inc
cebpic/morse-auto.asm [new file with mode: 0644]
cebpic/morse-auto.asm-gen [new file with mode: 0755]
cebpic/morse-auto.messages [new file with mode: 0644]
cebpic/morse-defs.inc [new file with mode: 0644]

index ed00119a330e6dc42cf31c7062b3194449a51ccb..d432d530519ea48258dc73df19b9ae8a7c701a04 100644 (file)
@@ -4,3 +4,5 @@
 idlocs*.asm
 gpsim.log
 routines.lib
+morse-auto.asm
+morse-auto.inc
index aff6f641461383310f8d79f8dd02ef75fc721195..386794889888a3698e3c0b069d43b90b4149dca5 100644 (file)
@@ -3,9 +3,9 @@ PROGRAMS=       led-flash send-serial panic reply-serial        \
                i2c-test i2c-test,slow morsepanic
 # booster-output-low  -disabled because you forgot to cvs add it
 
-ROUTINES=      routines-led
+ROUTINES=      routines-led morse-auto
 
-INCLUDES=      common.inc
+INCLUDES=      common.inc morse-auto.inc ../iwjpictest/insn-aliases.inc
 
 PICNOS=                0 1 3
 
@@ -13,6 +13,7 @@ TARGETS=      $(foreach i, $(PICNOS), perpic$i.hex)
 
 LIBS=          routines.lib                            
 
+include ../common.make
 include ../pic.make
 
 clean:         pic-clean
@@ -23,6 +24,10 @@ routines.lib:        $(addsuffix .o, $(ROUTINES))
                gplib -c $@.new $^
                mv -f $@.new $@
 
+morse-auto.inc morse-auto.asm: \
+ morse-auto.%: morse-auto.asm-gen morse-auto.messages
+               ./$^ $* $o
+
 %,slow.o:      %.asm
                $(ASSEMBLE) -D SLOW_VERSION -c -o $@ $<
 
index 1ce0cd41adaea9b1dea6e1fdea3b5c98234686b9..327f5123ddfeffb320a89c12ced3bcbbe053a513 100644 (file)
@@ -9,6 +9,9 @@
        include         /usr/share/gputils/header/p18f458.inc
         radix           dec 
 
+morse_messages_start   equ     0x4000
+morse_messages_end     equ     0x4400
+
 ;----------------------------------------
 ; ifbit1(REGISTER,BITNUMBER)
 ;       executes the next instruction but only if bit BITNUMBER
diff --git a/cebpic/morse-auto.asm b/cebpic/morse-auto.asm
new file mode 100644 (file)
index 0000000..2183e72
--- /dev/null
@@ -0,0 +1,19 @@
+; autogenerated - do not edit
+
+       include morse-defs.inc
+       radix dec
+
+       org     morse_messages_start
+morse_IH db 0x52,10100010b,10101000b,INTCON - (0xf00 * !((INTCON & 0xf00)^0xf00)),INTCON3 - (0xf00 * !((INTCON3 & 0xf00)^0xf00)),PIR1 - (0xf00 * !((PIR1 & 0xf00)^0xf00)),PIR2 - (0xf00 * !((PIR2 & 0xf00)^0xf00)),PIR3 - (0xf00 * !((PIR3 & 0xf00)^0xf00))
+morse_IL db 0x52,10100010b,11101010b,INTCON - (0xf00 * !((INTCON & 0xf00)^0xf00)),INTCON3 - (0xf00 * !((INTCON3 & 0xf00)^0xf00)),PIR1 - (0xf00 * !((PIR1 & 0xf00)^0xf00)),PIR2 - (0xf00 * !((PIR2 & 0xf00)^0xf00)),PIR3 - (0xf00 * !((PIR3 & 0xf00)^0xf00))
+morse_IP db 0x13,10100010b,11101110b,10000000b,INTCON - (0xf00 * !((INTCON & 0xf00)^0xf00)),0,0,0
+morse_SA db 0x12,10101000b,10111000b,SSPCON2 - (0xf00 * !((SSPCON2 & 0xf00)^0xf00))
+morse_SD db 0x12,10101000b,11101010b,SSPCON2 - (0xf00 * !((SSPCON2 & 0xf00)^0xf00))
+morse_TM db 0x42,11100011b,10111000b,PIE1 - (0xf00 * !((PIE1 & 0xf00)^0xf00)),SSPSTAT - (0xf00 * !((SSPSTAT & 0xf00)^0xf00)),SSPCON1 - (0xf00 * !((SSPCON1 & 0xf00)^0xf00)),SSPCON2 - (0xf00 * !((SSPCON2 & 0xf00)^0xf00)),0
+morse_TS db 0x42,11100010b,10100000b,PIE1 - (0xf00 * !((PIE1 & 0xf00)^0xf00)),SSPSTAT - (0xf00 * !((SSPSTAT & 0xf00)^0xf00)),SSPCON1 - (0xf00 * !((SSPCON1 & 0xf00)^0xf00)),SSPCON2 - (0xf00 * !((SSPCON2 & 0xf00)^0xf00)),0
+
+       if $ > morse_messages_end
+        error "too much morse - extends beyond morse_messages_end"
+       endif
+
+       end
diff --git a/cebpic/morse-auto.asm-gen b/cebpic/morse-auto.asm-gen
new file mode 100755 (executable)
index 0000000..56d6df2
--- /dev/null
@@ -0,0 +1,157 @@
+#!/usr/bin/perl
+# Converts morse-auto.messages to morse-auto.asm or morse-auto.inc.
+# morse.asm specifies some flash contents, as follows:
+#
+# Each message XY produces a symbol
+#   morse_XY
+# which is in the flash between morse_messages_start and
+# morse_messages_end, and which is guaranteed to be aligned to a
+# multiple of 4 bytes.
+#
+# At that symbol will be a message in the following format:
+#      RAAAMMMM        header byte, contents as follows:
+#                       M (4 bits) number of bytes of morse pattern
+#                       R reserved bit, always zero
+#                       A (3 bits) number of bytes of addresses
+#      M bytes         morse pattern, as bit string of LED on/off
+#                       values (1=on) for equal-length periods
+#                       (1 period = 1 morse dot), MS bit first
+#                       trailing zeroes in last byte are probably
+#                       best elided
+#      A bytes         zero or more addresses which should be read
+#                       and the corresponding value shown in binary
+#                       addresses are only one byte each, interpreted
+#                       like a zero page reference
+#
+# morse_messages_start and morse_messages_end should be defined in
+# morse-defs.inc, and should also be 4-byte aligned.  morse-defs.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::Handle;
+
+sub badusage () { die "usage: morse-auto.asm-gen <input>... asm|inc\n"; }
+
+@ARGV or badusage();
+$which= pop @ARGV;
+$which eq 'asm' or $which eq 'inc' or badusage();
+
+while (<DATA>) {
+    ($let,$morse) = (m/^([0-9A-Z])\s+([-.]+)$/) or die;
+    $morse =~ s/\./10/g;
+    $morse =~ s/\-/1110/g;
+    $morse =~ s/0$//;
+    $morse{$let}= $morse;
+}
+
+sub oops ($) { die "morse-auto.asm-gen: $ARGV:$.: $_[0]\n"; }
+
+$"=',';
+
+print <<'END' or die $!
+; autogenerated - do not edit
+END
+    ;
+
+print <<'END' or die $!
+
+       include morse-defs.inc
+       radix dec
+
+       org     morse_messages_start
+END
+    if $which eq 'asm';
+
+while (<>) {
+    chomp;
+    s/\#.*//;
+    next unless m/\S/;
+    s/\s+$//;
+    m/^([A-Z0-9]+)(?:\s+([^\t ;]+))?(?:\s+\;\s+(.*))?$/
+       or oops("syntax error");
+    $morse_name= $1;
+    @morse= split //, $morse_name;
+    @addrs= defined($2) ? split /\,/, $2 : ();
+    $comment= $3;
+
+    @addrs < 8 or oops("only up to 7 addrs are supported");
+
+    @data= ();
+
+    $morse= join '000', map { $morse{$_} } @morse;
+    $morse .= '0' x 7; # padding to fill any partial byte
+    while ($morse =~ s/^([01]{8})//) {
+       push @data, "$&b";
+    }
+    $morse =~ m/^0{0,7}$/ or die;
+    $morse_bytes= scalar(@data);
+
+    unshift @data, sprintf "0x%x%x", scalar(@addrs), $morse_bytes;
+#    push @data, @addrs;
+    push @data, map {
+       "$_ - (0xf00 * !(($_ & 0xf00)^0xf00))";
+#      $_.'&0xff';
+    } @addrs;
+
+    push @data, ('0') x (3 - (scalar(@data) + 3) % 4);
+
+    print ("morse_$morse_name db @data\n") or die $!
+       if $which eq 'asm';
+
+    print (" extern morse_$morse_name\n") or die $!
+       if $which eq 'inc';
+}
+
+print <<'END' or die $!
+
+       if $ > morse_messages_end
+        error "too much morse - extends beyond morse_messages_end"
+       endif
+
+       end
+END
+    if $which eq 'asm';
+
+STDIN->error and die $!;
+STDOUT->error and die $!;
+
+__DATA__
+A      .-
+B      -...
+C      -.-.
+D      -..
+E      .
+F      ..-.
+G      --.
+H      ....
+I      ..
+J      .---
+K      -.-
+L      .-..
+M      --
+N      -.
+O      ---
+P      .--.
+Q      --.-
+R      .-.
+S      ...
+T      -
+U      ..-
+V      ...-
+W      .--
+X      -..-
+Y      -.--
+Z      --..
+0      -----
+1      .----
+2      ..---
+3      ...--
+4      ....-
+5      .....
+6      -....
+7      --...
+8      ---..
+9      ----.
diff --git a/cebpic/morse-auto.messages b/cebpic/morse-auto.messages
new file mode 100644 (file)
index 0000000..a5aeca4
--- /dev/null
@@ -0,0 +1,27 @@
+# This is the list of morse panic messages.  Each line consists of:
+#    <morse>  [<address>,<address>...]   [; <description>]
+# This file is converted to morse.asm by the Perl script morse.asm-gen.
+# See morse.asm-gen for information about the format of the data stored
+# in flash.  Only addresses in the Access Bank are supported.
+
+# Suggested output by on the per-pic-led is:
+#    morse (red/black)   contents of one address
+#    morse (red/black)   contents of next address
+#    ...
+#    morse (red/black)   contents of last address
+#    long pause
+#    go back to start
+# Contents of addresses should preferably be read into a temporary
+# buffer space somewhere so that each one is read once and that value
+# remembered.
+
+# Main message listing.  Kept sorted by morse for easy reference.
+IH     INTCON,INTCON3,PIR1,PIR2,PIR3 ; Interrupt source not found (high pri.)
+IL     INTCON,INTCON3,PIR1,PIR2,PIR3 ; Interrupt source not found (low pri.)
+IP     INTCON                  ; Interrupt of priority supposedly disabled
+SA     SSPCON2                 ; Slave didn't I2C ack address
+SD     SSPCON2                 ; Slave didn't I2C ack data
+
+# Messages starting with T are temporary entries for testing and development
+TM     PIE1,SSPSTAT,SSPCON1,SSPCON2 ; Master got I2C interrupt
+TS     PIE1,SSPSTAT,SSPCON1,SSPCON2 ; Slave got I2C interrupt
diff --git a/cebpic/morse-defs.inc b/cebpic/morse-defs.inc
new file mode 100644 (file)
index 0000000..420d28f
--- /dev/null
@@ -0,0 +1 @@
+       include common.inc