2 * declarations for realtime daemon
9 #include "auproto-pic.h"
30 #include "../layout/layout-data.h"
32 typedef struct Segment Segment;
33 typedef struct Train Train;
34 typedef struct TimeoutEvent TimeoutEvent;
36 /*---------- from retransmit.c ----------*/
38 typedef struct RetransmitRelaxedNode RetransmitRelaxedNode;
39 typedef union RetransmitUrgentNode RetransmitUrgentNode;
40 typedef unsigned Retransmit__Time;
42 /* Contents of the retransmission nodes is generally all for use by
43 * retransmit.c only; as a special exception, caller may edit pi
44 * directly. Normally, though, pi is set by supplying an NMRA
45 * command to one of the _queue functions; iff the Nmra* is
46 * non-null, _queue will add an NMRA checksum and update pi.
48 struct RetransmitRelaxedNode {
50 DLIST_NODE(RetransmitRelaxedNode) rr;
52 union RetransmitUrgentNode {
55 RetransmitRelaxedNode relaxed;
57 Retransmit__Time when;
58 DLIST_NODE(RetransmitUrgentNode) queue;
62 void retransmit_start(void);
63 void retransmit_something(void);
65 void retransmit_relaxed_queue(RetransmitRelaxedNode *rn, Nmra *n);
66 void retransmit_relaxed_requeue(RetransmitRelaxedNode *rn, Nmra *n);
67 void retransmit_relaxed_cancel(RetransmitRelaxedNode *rn);
69 void retransmit_urgent_queue(RetransmitUrgentNode *rn, Nmra *n);
70 void retransmit_urgent_queue_relaxed(RetransmitUrgentNode *urg, Nmra *n);
71 void retransmit_urgent_requeue(RetransmitUrgentNode *rn, Nmra *n);
72 void retransmit_urgent_cancel(RetransmitUrgentNode *rn);
74 /* ... NB: these are NOT idempotent. Use _requeue it's queued;
75 * _requeue is just _cancel followed by queue. */
77 /*---------- features, filled in by record, used by features.c ----------*/
79 #define FEATURESADDR_TRANSMITS 4
80 /* 0..2 are func0to4 func5to8 func9to12 and speed cmd
81 * pi.l is 0 if not transmitting */
83 typedef struct FeaturesAddr {
84 struct FeaturesAddr *next;
86 RetransmitRelaxedNode rn[FEATURESADDR_TRANSMITS];
91 int bitval; /* may have no or several bits set */
92 int speedstep; /* -ve means backwards; 0 means not to use motor for feat */
95 typedef struct FeaturesTarget {
96 struct FeaturesTarget *next;
98 char *featchs; /* null-terminated */
99 FeaturesFeature **feats; /* same order as featchs */
103 extern Train *trains;
104 extern Segment *segments;
106 extern FeaturesTarget *feattargs;
107 extern FeaturesAddr *feataddrs;
109 /*---------- global variables, in realtime.c ----------*/
111 extern CommandInput cmdi;
112 extern int picio_send_noise;
114 #define UPO (&(cmdi.out))
116 #define CIXF_U 0x0000ffffu
117 #define CIXF_FORCE 0x00010000u
118 #define CIXF_ANYSTA 0x00020000u
120 /*---------- from/for startup.c ----------*/
122 #include "stastate.h"
124 void sta_startup(void);
125 void sta_finalising_done(void);
126 void serial_moredata(PicInsn *buf);
128 extern StartupState sta_state;
129 extern const char *const stastatelist[];
131 void resolve_begin(void); /* from resolve.c */
132 int resolve_complete(void);
133 void resolve_motioncheck(void);
135 void waggle_settle(void); /* from movpos.c */
136 void waggle_startup_manual(void);
138 /*---------- from/for record.c and persist.c ----------*/
140 void records_parse(const char **argv);
141 void persist_entrails_interpret(void);
142 void persist_entrails_run_converter(void);
143 void persist_install(void);
145 extern const char *persist_fn;
146 extern char *persist_record_converted;
148 void persist_map_veryearly(void);
150 /*---------- from/for realtime.c ----------*/
152 void oupicio(const char *dirn, const PicInsnInfo *pii, int obj, int v);
153 void ouhexi(const char *word, const Byte *command, int length);
154 void ouhexo(const char *word, const Byte *command, int length);
156 void serial_transmit(const PicInsn *pi);
157 void command_doline(ParseState *ps, CommandInput *cmdi_arg);
158 const CmdInfo *current_cmd;
160 /*---------- for/from simulate.c ----------*/
162 void serial_indata_process(int buf_used);
164 void sim_initialise(const char *logduplicate);
167 void simlogv(const char *fmt, va_list al);
168 void simlog(const char *fmt, ...);
169 void simlog_serial(const Byte *data, int length);
170 void simlog_flush(void);
171 void simlog_open(const char *fn);
173 void mgettimeofday(struct timeval *tv); /* contains magic for simulation */
174 void *toev_callback(oop_source *source, struct timeval tv, void *t_v);
176 void sim_toev_start(TimeoutEvent *toev);
177 void sim_toev_stop(TimeoutEvent *toev);
178 void sim_mgettimeofday(struct timeval *tv);
180 extern int simlog_full;
181 extern const char *simulate;
183 extern PicInsn serial_buf;
185 /*---------- from actual.c ----------*/
187 int picinsn_polarity_testbit(const PicInsn *pi, const SegmentInfo *segi);
188 /* this belongs in {au,skel}proto-pic.[ch] really but it's
189 * more convenient here. */
191 /*---------- from movpos.c ----------*/
193 void points_turning_on(void);
194 void motions_all_abandon(void);
196 /*---------- from eventhelp.c ----------*/
198 extern const char toev_fast_pclass[];
200 typedef void TimeoutEventFn(TimeoutEvent*);
201 struct TimeoutEvent { /* Undefined Idle Running set by */
202 int running; /* any 0 1 toev_ */
203 int duration; /*ms*/ /* any any[1] any[1] caller */
204 TimeoutEventFn *callback; /* any any valid[2] caller */
205 struct timeval abs; /* any any valid toev_ */
206 const char *pclass, *pinst; /* any any valid caller */
207 }; /* [1] duration must be >=0 or -1 when toev_start is called;
208 * [2] callback may be modified while timeout is running;
209 * value used is that prevailing when timeout happens
210 * when the timeout happens, TimeoutEvent's state goes from R to I
211 * and then callback member is read and the function called
214 void toev_init(TimeoutEvent*); /* U -> I */
215 void toev_start(TimeoutEvent*); /* IR -> R; reads duration */
216 /* if duration is -1 then is same as toev_stop */
217 void toev_stop(TimeoutEvent*); /* IR -> I */
219 /*---------- from rtprio.c ----------*/
221 void realtime_priority(void);
223 #define RTFEAT_DEFAULTS 0100u /* turns on MLOCK and SCHEDPRIO iff not sim */
224 #define RTFEAT_MEM 0001u /* mlock */
225 #define RTFEAT_CPU 0002u /* hard CPU scheduling priority */
227 #define RTFEAT_ALL_SHIFT 16
228 #define RTFEAT_ALL(x) (RTFEAT_##x << RTFEAT_ALL_SHIFT)
229 /* RTFEAT_ALL(FOO) is relevant only if RTFEAT_FOO selected, and means
230 * not to apply the normal limit to the grabbing of FOO */
232 extern unsigned rtfeats_use;
234 /*---------- tbi ----------*/
236 void choreographers_all_abandon(void);
238 #define DUPO(ctx) UPO, "debug " ctx " : "
242 #define PERSIST_CONVERT_OPTION "--persist-convert-entrails"
246 #define CTYPE(isfoobar,ch) (isfoobar((unsigned char)(ch)))
248 #endif /*REALTIME_H*/