--- /dev/null
+o=>$@.new && mv -f $@.new $@
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 $<
hostside
safety
t
+layoutinfo.h
+*.d
#
+include ../common.make
+include ../cprogs.make
+
TARGETS= hostside safety
CFLAGS= -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes \
-Wpointer-arith -Wwrite-strings -g $(OPTIMISE)
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)
#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;
}
}
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;
#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 ==========*/
/*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];
* etc.).
*/
-void safety_emergencystop(TranNum);
+void safety_emergencystop(TrainNum);
/* Callable directly in response to application command. */
void safety_requestspeed(TrainNum tran, long newspeed);
*/
/*
- *
* Entrypoints are: Called from, and as a result of:
* actual_setspeed safety.c
* actual_emergencystop safety.c
-
+ */
/*========== utils.c ==========*/
ours.redacted.neato.ps
ours.redacted.neato
ours.redacted.forsafety
-ours.safety.c
+ours.layout-data.c
+*.d
-#include ../cprogs.make
+include ../cprogs.make
+include ../common.make
M4INCS= parts.i4
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)
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
%.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
-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)
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};
($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;
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,
--- /dev/null
+/**/
+
+#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*/
all: $(TARGETS) $(PROGRAM_HEXES)
-o=>$@.new && mv -f $@.new $@
-
LINK= gplink -o $@ $^
ASSEMBLE= gpasm -p 18f458