From: ian Date: Sun, 27 Mar 2005 22:14:20 +0000 (+0000) Subject: new arrangements for cross-directory: ours.safety => ours.layout-data, and automatic... X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=3243c78062a57c1ecb808fda75d7067a85e78a6a;p=trains.git new arrangements for cross-directory: ours.safety => ours.layout-data, and automatic dependency stuff for cprogs, etc. --- diff --git a/common.make b/common.make new file mode 100644 index 0000000..a15cbed --- /dev/null +++ b/common.make @@ -0,0 +1 @@ +o=>$@.new && mv -f $@.new $@ diff --git a/cprogs.make b/cprogs.make index 06f15fc..132c373 100644 --- a/cprogs.make +++ b/cprogs.make @@ -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 $< diff --git a/hostside/.cvsignore b/hostside/.cvsignore index 92602c0..52a5ddf 100644 --- a/hostside/.cvsignore +++ b/hostside/.cvsignore @@ -1,3 +1,5 @@ hostside safety t +layoutinfo.h +*.d diff --git a/hostside/Makefile b/hostside/Makefile index 3de430e..e24856a 100644 --- a/hostside/Makefile +++ b/hostside/Makefile @@ -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) diff --git a/hostside/safety.c b/hostside/safety.c index b982bec..544da3b 100644 --- a/hostside/safety.c +++ b/hostside/safety.c @@ -3,12 +3,13 @@ #include +#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; diff --git a/hostside/safety.h b/hostside/safety.h index be00b05..3b375b0 100644 --- a/hostside/safety.h +++ b/hostside/safety.h @@ -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 ==========*/ diff --git a/layout/.cvsignore b/layout/.cvsignore index 50dd492..721a4c0 100644 --- a/layout/.cvsignore +++ b/layout/.cvsignore @@ -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 diff --git a/layout/Makefile b/layout/Makefile index 7677eb9..0e5d036 100644 --- a/layout/Makefile +++ b/layout/Makefile @@ -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) diff --git a/layout/data2safety b/layout/data2safety index 03f88c0..c7cefc2 100755 --- a/layout/data2safety +++ b/layout/data2safety @@ -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 index 0000000..2d1eed3 --- /dev/null +++ b/layout/layout-data.h @@ -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*/ diff --git a/pic.make b/pic.make index 46899b1..be16054 100644 --- 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