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;
111 extern int disable_watchdog;
113 #define CIXF_U 0x0000ffffu
114 #define CIXF_FORCE 0x00010000u
115 #define CIXF_ANYSTA 0x00020000u
117 /*---------- from/for startup.c ----------*/
119 #include "stastate.h"
121 void sta_startup(void);
122 void sta_finalising_done(void);
123 void serial_moredata(PicInsn *buf);
125 extern StartupState sta_state;
126 extern const char *const stastatelist[];
127 void cmdi_output_bufferempty(OutBufferChain *obc);
129 void resolve_begin(void); /* from resolve.c */
130 int resolve_complete(void);
131 void resolve_motioncheck(void);
133 void waggle_settle(void); /* from movpos.c */
134 void waggle_startup_manual(void);
136 /*---------- from/for record.c and persist.c ----------*/
138 void records_parse(const char **argv);
139 void persist_entrails_interpret(void);
140 void persist_entrails_run_converter(void);
141 void persist_install(void);
143 extern const char *persist_fn;
144 extern char *persist_record_converted;
146 void persist_map_veryearly(void);
148 /*---------- from/for realtime.c ----------*/
150 void oupicio(const char *dirn, const PicInsnInfo *pii, int obj, int v,
151 void (*qprintf)(const char *fmt, ...));
152 void ouhex(const char *word, const Byte *command, int length);
153 void ouhex_nosim(const char *word, const Byte *command, int length);
155 void serial_transmit(const PicInsn *pi);
156 void command_doline(ParseState *ps, CommandInput *cmdi_arg);
157 const CmdInfo *current_cmd;
159 /*---------- for/from simulate.c ----------*/
161 void serial_indata_process(int buf_used);
163 void sim_initialise(const char *logduplicate);
166 void simlog_ccb(char *m, size_t l, void *u);
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 void adjuncts_start_xmit(void);
192 void adjuncts_updated(AdjunctsAddr *a);
194 /*---------- from movpos.c ----------*/
196 void points_turning_on(void);
197 void motions_all_abandon(void);
199 /*---------- from eventhelp.c ----------*/
201 extern const char toev_fast_pclass[];
203 typedef void TimeoutEventFn(TimeoutEvent*);
204 struct TimeoutEvent { /* Undefined Idle Running set by */
205 int running; /* any 0 1 toev_ */
206 int duration; /*ms*/ /* any any[1] any[1] caller */
207 TimeoutEventFn *callback; /* any any valid[2] caller */
208 struct timeval abs; /* any any valid toev_ */
209 const char *pclass, *pinst; /* any any valid caller */
210 }; /* [1] duration must be >=0 or -1 when toev_start is called;
211 * [2] callback may be modified while timeout is running;
212 * value used is that prevailing when timeout happens
213 * when the timeout happens, TimeoutEvent's state goes from R to I
214 * and then callback member is read and the function called
217 void toev_init(TimeoutEvent*); /* U -> I */
218 void toev_start(TimeoutEvent*); /* IR -> R; reads duration */
219 /* if duration is -1 then is same as toev_stop */
220 void toev_stop(TimeoutEvent*); /* IR -> I */
222 /*---------- from rtprio.c ----------*/
224 void realtime_priority(void);
226 #define RTFEAT_DEFAULTS 0100u /* turns on MLOCK and SCHEDPRIO iff not sim */
227 #define RTFEAT_MEM 0001u /* mlock */
228 #define RTFEAT_CPU 0002u /* hard CPU scheduling priority */
230 #define RTFEAT_ALL_SHIFT 16
231 #define RTFEAT_ALL(x) (RTFEAT_##x << RTFEAT_ALL_SHIFT)
232 /* RTFEAT_ALL(FOO) is relevant only if RTFEAT_FOO selected, and means
233 * not to apply the normal limit to the grabbing of FOO */
235 extern unsigned rtfeats_use;
237 void ouvprintf(const char *fmt, va_list al)
238 __attribute__((format(printf,1,0)));
239 void ouprintf(const char *fmt, ...)
240 __attribute__((format(printf,1,2)));
242 void ouvprintf_only(const char *fmt, va_list al)
243 __attribute__((format(printf,1,0)));
244 void ouprintf_only(const char *fmt, ...)
245 __attribute__((format(printf,1,2)));
247 extern unsigned long eventcounter; /* for debugging use only ! */
248 void debug_count_event(const char *what);
250 #define DEBUGP(a,k) (dflags_##a & DBIT_##a##_##k)
252 #define DPRINTFA ouprintf_only
254 #define COND_DPRINTF(cond, a,k, fmt, ...) \
255 ((cond) ? DPRINTFA("debug " #a "/" #k " : " fmt,##__VA_ARGS__) : (void)0)
257 #define DPRINTF(a,k,f,...) COND_DPRINTF(DEBUGP(a,k),a,k,f,##__VA_ARGS__)
258 #define DPRINTF1(a,k,f,...) COND_DPRINTF((DP)=DEBUGP(a,k), a,k,f,##__VA_ARGS__)
259 #define DPRINTF2(f,...) ((DP) ? DPRINTFA(f,##__VA_ARGS__) : (void)0)
261 /*---------- tbi ----------*/
263 void choreographers_all_abandon(void);
267 #define PERSIST_CONVERT_OPTION "--persist-convert-entrails"
272 #endif /*REALTIME_H*/