chiark / gitweb /
new arrangements for cross-directory: ours.safety => ours.layout-data, and automatic...
authorian <ian>
Sun, 27 Mar 2005 22:14:20 +0000 (22:14 +0000)
committerian <ian>
Sun, 27 Mar 2005 22:14:20 +0000 (22:14 +0000)
common.make [new file with mode: 0644]
cprogs.make
hostside/.cvsignore
hostside/Makefile
hostside/safety.c
hostside/safety.h
layout/.cvsignore
layout/Makefile
layout/data2safety
layout/layout-data.h [new file with mode: 0644]
pic.make

diff --git a/common.make b/common.make
new file mode 100644 (file)
index 0000000..a15cbed
--- /dev/null
@@ -0,0 +1 @@
+o=>$@.new && mv -f $@.new $@
index 06f15fc4ba6d2a300068a025696618c2442a14b8..132c373b7cd8990acf361ea7796d21bf6416addd 100644 (file)
@@ -1,6 +1,13 @@
 OPTIMISE= -O2
 WERROR= -Werror
-CFLAGS=        -Wall -Wwrite-strings -Wpointer-arith \
+CFLAGS=        $(CPPFLAGS) \
+       -Wall -Wwrite-strings -Wpointer-arith -Wmissing-declarations \
        -Wnested-externs -Wmissing-prototypes -Wstrict-prototypes \
        $(WERROR) \
        -g $(OPTIMISE)
+CPPFLAGS=      -D_GNU_SOURCE
+LINK=          $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS)
+
+%.o:   %.c
+       $(CC) $(CFLAGS) -MM $< >$*.d
+       $(CC) $(CFLAGS) -o $@ -c $<
index 92602c04b022abb7a633c3e7c8bbcc1f1dec9567..52a5ddffe5c12720384fbc95cf1d2cef9c3207ec 100644 (file)
@@ -1,3 +1,5 @@
 hostside
 safety
 t
+layoutinfo.h
+*.d
index 3de430e3ba8aafefe0e8e90df8285d568a67f72d..e24856a22bb844b1eaf7518485207ed48177ddcc 100644 (file)
@@ -1,5 +1,8 @@
 #
 
+include ../common.make
+include ../cprogs.make
+
 TARGETS=       hostside safety
 CFLAGS=                -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes \
                -Wpointer-arith -Wwrite-strings -g $(OPTIMISE)
@@ -8,19 +11,21 @@ OPTIMISE=    -O2
 all:           $(TARGETS)
 
 hostside:      serialio.o nmra.o main.o encode.o
-               $(CC) $(CFLAGS) -o $@ $+
+               $(LINK)
+
+layoutinfo.h:  ../layout/ours.layout-data.c Makefile
+               sed -e '/^#include/,$$d' $< $o
 
-ours.safety.o: ../layout/ours.safety.c safety.h
-               $(CC) $(CFLAGS) -I. -o $@ -c $<
+%.c:           layoutinfo.h
 
-layoutinfo.h:  ../layout/ours.safety.c Makefile
-               sed -e '/^#include/,$d' $< $o
+safety:                safety.o ../layout/ours.layout-data.o
+               $(LINK)
 
 encode.o:      nmra-packets.h
 main.o:                nmra-packets.h
 %.c:           hostside.h
 
-safety.o:      safety.h layoutinfo.h
-
 clean:
-               rm -f *.o $(TARGETS)
+               rm -f *.o *.d $(TARGETS)
+
+include $(wildcard *.d)
index b982becc6ffb403a67020ed0a167f54fe52c5748..544da3b709e4e1688f7152c661deac5fe2edf1c7 100644 (file)
@@ -3,12 +3,13 @@
 
 #include <stdio.h>
 
+#include "layoutinfo.h"
 #include "safety.h"
 
 static void seg_clear_stale(SegmentState *seg) {
   if (!seg->tr_updated) {
     seg->owned= 0;
-    seg->until_here= seg->until_detect= NOTA(TimeInterval);
+    seg->until_here= seg->until_detect= 0;
   }
 }
 
@@ -25,14 +26,16 @@ typedef struct {
   SegmentNum invert_forcer; /* the unswitchable which forces */
 } LayTrainState;
 
-static void lay_train_pass(LayTrainState l,
+static void lay_train_pass(LayTrainState *l,
                           TrackLocation tloc, long advance,
                           unsigned backwards, long speed,
                           unsigned check_clash) {
+  SegmentNum segn;
   SegmentState *seg;
   const SegmentInfo *segi;
   long overall, remain;
   int *invert_likehere, *invert_unlikehere;
+  TrainState *tra= s->trains[l->tran];
 
   if (l->ec) return;
 
index be00b05201da7bb968036f762defcf3f76164c6b..3b375b03a81b901020a3b9aa8816ff80b388d9bd 100644 (file)
@@ -3,16 +3,13 @@
 #ifndef SAFETY_H
 #define SAFETY_H
 
-/*========== basic types etc. ==========*/
+#include "../layout/layout-data.h"
+#include "layoutinfo.h"
+
+/*========== more basic types etc. ==========*/
 
-typedef unsigned short TrainNum;
-typedef unsigned short SegmentNum;
-typedef unsigned short LocationNum;
-typedef unsigned short MovPosComb;
-typedef unsigned char Small;
 typedef short TimeInterval;
-typedef short Distance;
-typedef char Speed; /* non-negative, units of 4mm/s */
+typedef int ErrorCode;
 
 /*========== state of the layout ==========*/
 
@@ -39,42 +36,6 @@ typedef struct {
   /*polarity?*/
 } SegmentState;
 
-typedef struct {
-  unsigned next_backwards:1;
-  SegmentNum next;
-} SegmentLinkInfo;
-
-typedef struct {
-  const char *pname;
-  Small posns;
-  MovPosComb weight;
-} MovFeatInfo;
-
-typedef struct {
-  const char *pname;
-  SegmentLinkInfo backwards, forwards;
-  Distance dist;
-} SegPosCombInfo;
-
-typedef struct {
-  const char *pname;
-  unsigned invertible:1;
-  Small n_movfeats;
-  const MovFeatInfo *movfeats;
-  MovPosComb n_poscombs;
-  const SegPosCombInfo *poscombs;
-  Small board, object;
-} SegmentInfo;
-
-typedef struct {
-  Speed maxspeed;
-  Distance tail, detectable, head;
-  const char *pname;
-} TrainInfo;
-
-extern const TrainInfo info_trains[NUM_TRAINS];
-extern const SegmentInfo info_segments[NUM_SEGMENTS];
-
 typedef struct {
   TrainState trains[NUM_TRAINS];
   SegmentState segments[NUM_SEGMENTS];
@@ -89,7 +50,7 @@ extern State s;
  * etc.).
  */
 
-void safety_emergencystop(TranNum);
+void safety_emergencystop(TrainNum);
   /* Callable directly in response to application command. */
 
 void safety_requestspeed(TrainNum tran, long newspeed);
@@ -132,11 +93,10 @@ void actual_inversions_done(void);
    */
   
 /*
- *
  * Entrypoints are:                  Called from, and as a result of:
  *   actual_setspeed                    safety.c
  *   actual_emergencystop               safety.c
-
+ */
 
 /*========== utils.c ==========*/
 
index 50dd4921b65b5d25e3b27fe0c0f97689dc859a62..721a4c0f99e6e993ab4fc1933f72817e974dae7a 100644 (file)
@@ -22,4 +22,5 @@ ours.raw.neato
 ours.redacted.neato.ps
 ours.redacted.neato
 ours.redacted.forsafety
-ours.safety.c
+ours.layout-data.c
+*.d
index 7677eb94fc6fdf5a54cbfe8e89d532ff442a7a8f..0e5d036a4bdf4dcaeec208842dd0b483d6c1528b 100644 (file)
@@ -1,4 +1,5 @@
-#include ../cprogs.make
+include ../cprogs.make
+include ../common.make
 
 M4INCS=                parts.i4
 
@@ -23,7 +24,7 @@ CPROGS=               subseg2display compose-segenco
 default:       $(CPROGS) for-test-ui
 all:           default lpages layers extras
 for-test-ui:   ours.graph.c ours.redactgraph ours.raw.neato.ps \
-               ours.redacted.neato.ps ours.safety.c \
+               ours.redacted.neato.ps ours.layout-data.o \
                ours.dgram-bot.segcmap subseg2display ui-plan-bot.ppm
 
 layers:                $(LAYERS)
@@ -33,14 +34,6 @@ extras:              dualjn-a.ps parts.ps
 include ours.dgram.m
 include segencolayers.m
 
-o=>$@.new && mv -f $@.new $@
-
-CFLAGS=                -Wall -Wwrite-strings -Wpointer-arith \
-               -Wstrict-prototypes -Wmissing-prototypes \
-               -Wmissing-declarations -Werror $(OPTIMISE)
-OPTIMISE=      -O2 -g
-CPPFLAGS=      -D_GNU_SOURCE
-LINK=          $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS)
 NETPBM=                -lnetpbm
 # -lppm
 
@@ -68,7 +61,7 @@ compose-segenco: compose-segenco.o
 %.redacted.forsafety: %.redactgraph
                ./$< $(REDACT) consistency printforforsafety $o
 
-%.safety.c:    data2safety %.wiring %.redacted.forsafety
+%.layout-data.c: data2safety %.wiring %.redacted.forsafety
                ./$^ $o
 
 %.redactgraph: %.graph.o redactgraph.o
@@ -139,8 +132,11 @@ clean:
                -rm -f *.oprint-*.ps *.run-layout
                -rm -f *.segcmap *.segcmapreq
                -rm -f *.dgram-*.p*.segenco.ps *.dgram-*.p*.segenco.ppm
-               -rm -f $(CPROGS) *.o
+               -rm -f $(CPROGS) *.o *.d
 
 .PRECIOUS:     $(OPRINTS)
 .PRECIOUS:     %.segcmap %.segcmapreq %.segenco.ppm %.d4 %.neato %.raw.neato
 .PRECIOUS:     %.redactgraph %.redacted.forsafety %.redacted.neato
+.PRECIOUS:     %.layout-data.c
+
+include $(wildcard *.d)
index 03f88c061ba14aa5de13af59982382b8848927ad..c7cefc24ba6db212e6c38bab031134514d075901 100755 (executable)
@@ -208,13 +208,17 @@ sub writeout () {
     my (@segs,$segn,$seg,$segr,$pt,$ptv, $delim);
     my ($comb,$pi,$feat,$featr,$end);
     my ($node,$side,$otherend,$nodeotherside,$otherseg,$otherbackrelus);
-    o("/* autogenerated - do not edit */\n\n".
-      "#include \"safety.h\"\n\n");
+    o("/* autogenerated - do not edit */\n\n");
     @segs=();
     for $seg (sort { nummap($a) cmp nummap($b) } keys %segs) {
        $segs{$seg}{Num}= @segs;
        push @segs, $seg;
     }
+    o(sprintf
+      "#define NUM_TRAINS 1000000\n".
+      "#define NUM_SEGMENTS %s\n\n".
+      "#include \"layout-data.h\"\n\n",
+      scalar @segs);
     foreach $seg (@segs) {
        $segr= $segs{$seg};
 
@@ -229,10 +233,11 @@ sub writeout () {
                              ($comb / $featr->{Weight}) % $featr->{Posns});
            }
            o("$delim\n");
-           o(sprintf "  %-10s {", length $pi ? "/*$pi*/" : '');
+           o(sprintf "  { %-8s %4d",
+             '"'.$seg.(length $pi ? '/' : '').$pi.'",',
+             $segr->{Dist}[$comb]);
            for ($end=0; $end<2; $end++) {
-               o(',') if $end;
-               o(" { ");
+               o(", { ");
                $otherend= $segr->{Ends}[$comb][$end];
                defined $otherend or die "$seg $comb $end ?";
                ($node,$side) = @$otherend;
@@ -240,7 +245,7 @@ sub writeout () {
                if (defined $nodeotherside) {
                    $otherseg= $nodeotherside->{Seg};
                    $otherbackrelus= $nodeotherside->{End} ^ $end ^ 1;
-                   o(sprintf "/*%5s.%d %-6s*/ %d,%3d",
+                   o(sprintf "/*%5s.%d %-5s*/ %d,%3d",
                      $node,$side,
                      ($otherbackrelus?'-':' ').$otherseg,
                      $otherbackrelus,
diff --git a/layout/layout-data.h b/layout/layout-data.h
new file mode 100644 (file)
index 0000000..2d1eed3
--- /dev/null
@@ -0,0 +1,55 @@
+/**/
+
+#ifndef LAYOUT_DATA_H
+#define LAYOUT_DATA_H
+
+/*========== basic types etc. ==========*/
+
+typedef unsigned short TrainNum;
+typedef unsigned short SegmentNum;
+typedef unsigned short MovPosComb;
+typedef short Distance;
+typedef unsigned char Small;
+typedef char Speed; /* non-negative, units of 4mm/s */
+
+/*========== data from config files and layout cad/cam ==========*/
+
+typedef struct {
+  unsigned next_backwards:1;
+  SegmentNum next;
+} SegmentLinkInfo;
+
+typedef struct {
+  const char *pname;
+  Small posns;
+  MovPosComb weight;
+} MovFeatInfo;
+
+typedef struct {
+  const char *pname;
+  Distance dist;
+  SegmentLinkInfo backwards, forwards;
+} SegPosCombInfo;
+
+typedef struct {
+  const char *pname;
+  unsigned invertible:1;
+  Small n_movfeats;
+  const MovFeatInfo *movfeats;
+  MovPosComb n_poscombs;
+  const SegPosCombInfo *poscombs;
+  Small board, object;
+} SegmentInfo;
+
+typedef struct {
+  Speed maxspeed;
+  Distance tail, detectable, head;
+  const char *pname;
+} TrainInfo;
+
+extern const SegmentInfo info_segments[];
+extern const TrainInfo info_trains[];
+
+#define NOTA(x) (~(x##Num)0)
+
+#endif /*LAYOUT_DATA_H*/
index 46899b12f3432381657c2808f2b2f1a91bf324bd..be16054cb384103e09f0b787f91f3a5b6f3aa896 100644 (file)
--- a/pic.make
+++ b/pic.make
@@ -19,8 +19,6 @@ PROGRAM_HEXES=        $(addsuffix .hex, $(PROGRAMS)) \
 
 all:           $(TARGETS) $(PROGRAM_HEXES)
 
-o=>$@.new && mv -f $@.new $@
-
 LINK=          gplink -o $@ $^
 ASSEMBLE=      gpasm -p 18f458