2 * declarations for realtime daemon
9 #include "auproto-pic.h"
19 #include <sys/types.h>
22 #include "../layout/layout-data.h"
23 #include "realtime+dflags.h"
25 typedef struct Segment Segment;
26 typedef struct Train Train;
27 typedef struct TimeoutEvent TimeoutEvent;
29 /*---------- from retransmit.c ----------*/
31 typedef struct RetransmitRelaxedNode RetransmitRelaxedNode;
32 typedef union RetransmitUrgentNode RetransmitUrgentNode;
33 typedef unsigned Retransmit__Time;
35 /* Contents of the retransmission nodes is generally all for use by
36 * retransmit.c only; as a special exception, caller may edit pi
37 * directly. Normally, though, pi is set by supplying an NMRA
38 * command to one of the _queue functions; iff the Nmra* is
39 * non-null, _queue will add an NMRA checksum (modifying *n)
40 * and update pi (which always results in a nonzero pi.l).
42 struct RetransmitRelaxedNode {
44 DLIST_NODE(RetransmitRelaxedNode) rr;
46 union RetransmitUrgentNode {
49 RetransmitRelaxedNode relaxed;
51 Retransmit__Time when;
52 DLIST_NODE(RetransmitUrgentNode) queue;
56 void retransmit_start(void);
57 void retransmit_something(void);
59 void retransmit_urgent_queue(RetransmitUrgentNode *rn, Nmra *n);
60 void retransmit_urgent_queue_relaxed(RetransmitUrgentNode *urg, Nmra *n);
61 void retransmit_urgent_requeue(RetransmitUrgentNode *rn, Nmra *n);
62 void retransmit_urgent_cancel(RetransmitUrgentNode *rn);
64 void retransmit_relaxed_queue(RetransmitRelaxedNode *rn, Nmra *n);
65 void retransmit_relaxed_cancel(RetransmitRelaxedNode *rn);
67 /* ... NB: these are NOT idempotent and NOT interchangeable. Use
68 * urgent_requeue if it's queued and has changed and must get a new
69 * quota of urgency; _requeue is just _cancel followed by queue. */
71 /*---------- adjuncts, filled in by record, used by adjuncts.c ----------*/
73 #define ADJUNCTSADDR_TRANSMITS 4
74 /* 0..2 are func0to4 func5to8 func9to12 and speed cmd
75 * pi.l is 0 if not transmitting */
77 #define ADJS_SPEEDSTEP_BIT 0x4000u /* a->{current,all,permit}, f->bits */
78 #define ADJS_SPEEDSTEP_REVERSE 0x8000u /* in a->all */
80 typedef struct AdjunctsAddr {
81 struct AdjunctsAddr *next;
83 unsigned current, permit, all;
84 RetransmitRelaxedNode rn[ADJUNCTSADDR_TRANSMITS];
88 char *pname; /* first, for pname1st_compar */
90 unsigned bits; /* may have no or several bits set */
93 typedef struct AdjunctsTarget {
94 char *pname; /* first, for pname1st_compar */
96 AdjunctsAdjunct *adjs;
100 extern Train *trains;
101 extern Segment *segments;
103 extern int n_adjtargs, n_adjaddrs;
104 extern AdjunctsTarget *adjtargs;
105 extern AdjunctsAddr **adjaddrs;
107 /*---------- global variables, in realtime.c ----------*/
109 extern CommandInput cmdi;
110 extern int picio_send_noise;
112 #define CIXF_U 0x0000ffffu
113 #define CIXF_FORCE 0x00010000u
114 #define CIXF_ANYSTA 0x00020000u
116 /*---------- from/for startup.c ----------*/
118 #include "stastate.h"
120 void sta_startup(void);
121 void sta_finalising_done(void);
122 void serial_moredata(PicInsn *buf);
124 extern StartupState sta_state;
125 extern const char *const stastatelist[];
126 void cmdi_output_bufferempty(OutBufferChain *obc);
128 void resolve_begin(void); /* from resolve.c */
129 int resolve_complete(void);
130 void resolve_motioncheck(void);
132 void waggle_settle(void); /* from movpos.c */
133 void waggle_startup_manual(void);
135 /*---------- from/for record.c and persist.c ----------*/
137 void records_parse(const char **argv);
138 void persist_entrails_interpret(void);
139 void persist_entrails_run_converter(void);
140 void persist_install(void);
142 extern const char *persist_fn;
143 extern char *persist_record_converted;
145 void persist_map_veryearly(void);
147 /*---------- from/for realtime.c ----------*/
149 void oupicio(const char *dirn, const PicInsnInfo *pii, int obj, int v,
150 void (*qprintf)(const char *fmt, ...));
151 void ouhex(const char *word, const Byte *command, int length);
152 void ouhex_nosim(const char *word, const Byte *command, int length);
154 void serial_transmit(const PicInsn *pi);
155 void command_doline(ParseState *ps, CommandInput *cmdi_arg);
156 const CmdInfo *current_cmd;
158 /*---------- for/from simulate.c ----------*/
160 void serial_indata_process(int buf_used);
162 void sim_initialise(const char *logduplicate);
165 void simlog_ccb(char *m, size_t l, void *u);
166 void simlogv(const char *fmt, va_list al);
167 void simlog(const char *fmt, ...);
168 void simlog_serial(const Byte *data, int length);
169 void simlog_flush(void);
170 void simlog_open(const char *fn);
172 void mgettimeofday(struct timeval *tv); /* contains magic for simulation */
173 void *toev_callback(oop_source *source, struct timeval tv, void *t_v);
175 void sim_toev_start(TimeoutEvent *toev);
176 void sim_toev_stop(TimeoutEvent *toev);
177 void sim_mgettimeofday(struct timeval *tv);
179 extern int simlog_full;
180 extern const char *simulate;
182 extern PicInsn serial_buf;
184 /*---------- from actual.c ----------*/
186 int picinsn_polarity_testbit(const PicInsn *pi, const SegmentInfo *segi);
187 /* this belongs in {au,skel}proto-pic.[ch] really but it's
188 * more convenient here. */
190 void adjuncts_start_xmit(void);
191 void adjuncts_updated(AdjunctsAddr *a);
193 /*---------- from movpos.c ----------*/
195 void points_turning_on(void);
196 void motions_all_abandon(void);
198 /*---------- from eventhelp.c ----------*/
200 extern const char toev_fast_pclass[];
202 typedef void TimeoutEventFn(TimeoutEvent*);
203 struct TimeoutEvent { /* Undefined Idle Running set by */
204 int running; /* any 0 1 toev_ */
205 int duration; /*ms*/ /* any any[1] any[1] caller */
206 TimeoutEventFn *callback; /* any any valid[2] caller */
207 struct timeval abs; /* any any valid toev_ */
208 const char *pclass, *pinst; /* any any valid caller */
209 }; /* [1] duration must be >=0 or -1 when toev_start is called;
210 * [2] callback may be modified while timeout is running;
211 * value used is that prevailing when timeout happens
212 * when the timeout happens, TimeoutEvent's state goes from R to I
213 * and then callback member is read and the function called
216 void toev_init(TimeoutEvent*); /* U -> I */
217 void toev_start(TimeoutEvent*); /* IR -> R; reads duration */
218 /* if duration is -1 then is same as toev_stop */
219 void toev_stop(TimeoutEvent*); /* IR -> I */
221 /*---------- from rtprio.c ----------*/
223 void realtime_priority(void);
225 #define RTFEAT_DEFAULTS 0100u /* turns on MLOCK and SCHEDPRIO iff not sim */
226 #define RTFEAT_MEM 0001u /* mlock */
227 #define RTFEAT_CPU 0002u /* hard CPU scheduling priority */
229 #define RTFEAT_ALL_SHIFT 16
230 #define RTFEAT_ALL(x) (RTFEAT_##x << RTFEAT_ALL_SHIFT)
231 /* RTFEAT_ALL(FOO) is relevant only if RTFEAT_FOO selected, and means
232 * not to apply the normal limit to the grabbing of FOO */
234 extern unsigned rtfeats_use;
236 void ouvprintf(const char *fmt, va_list al)
237 __attribute__((format(printf,1,0)));
238 void ouprintf(const char *fmt, ...)
239 __attribute__((format(printf,1,2)));
241 void ouvprintf_only(const char *fmt, va_list al)
242 __attribute__((format(printf,1,0)));
243 void ouprintf_only(const char *fmt, ...)
244 __attribute__((format(printf,1,2)));
246 extern unsigned long eventcounter; /* for debugging use only ! */
247 void debug_count_event(const char *what);
249 #define DEBUGP(a,k) (dflags_##a & DBIT_##a##_##k)
251 #define DPRINTFA ouprintf_only
253 #define COND_DPRINTF(cond, a,k, fmt, ...) \
254 ((cond) ? DPRINTFA("debug " #a "/" #k " : " fmt,##__VA_ARGS__) : (void)0)
256 #define DPRINTF(a,k,f,...) COND_DPRINTF(DEBUGP(a,k),a,k,f,##__VA_ARGS__)
257 #define DPRINTF1(a,k,f,...) COND_DPRINTF((DP)=DEBUGP(a,k), a,k,f,##__VA_ARGS__)
258 #define DPRINTF2(f,...) ((DP) ? DPRINTFA(f,##__VA_ARGS__) : (void)0)
260 /*---------- tbi ----------*/
262 void choreographers_all_abandon(void);
266 #define PERSIST_CONVERT_OPTION "--persist-convert-entrails"
271 #endif /*REALTIME_H*/