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 and update pi.
41 struct RetransmitRelaxedNode {
43 DLIST_NODE(RetransmitRelaxedNode) rr;
45 union RetransmitUrgentNode {
48 RetransmitRelaxedNode relaxed;
50 Retransmit__Time when;
51 DLIST_NODE(RetransmitUrgentNode) queue;
55 void retransmit_start(void);
56 void retransmit_something(void);
58 void retransmit_urgent_queue(RetransmitUrgentNode *rn, Nmra *n);
59 void retransmit_urgent_queue_relaxed(RetransmitUrgentNode *urg, Nmra *n);
60 void retransmit_urgent_requeue(RetransmitUrgentNode *rn, Nmra *n);
61 void retransmit_urgent_cancel(RetransmitUrgentNode *rn);
63 void retransmit_relaxed_queue(RetransmitRelaxedNode *rn, Nmra *n);
64 void retransmit_relaxed_cancel(RetransmitRelaxedNode *rn);
66 /* ... NB: these are NOT idempotent and NOT interchangeable. Use
67 * urgent_requeue if it's queued and has changed and must get a new
68 * quota of urgency; _requeue is just _cancel followed by queue. */
70 /*---------- adjuncts, filled in by record, used by adjuncts.c ----------*/
72 #define ADJUNCTSADDR_TRANSMITS 4
73 /* 0..2 are func0to4 func5to8 func9to12 and speed cmd
74 * pi.l is 0 if not transmitting */
76 #define ADJS_SPEEDSTEP_BIT 0x4000u /* a->{current,all,permit}, f->bits */
77 #define ADJS_SPEEDSTEP_REVERSE 0x8000u /* in a->all */
79 typedef struct AdjunctsAddr {
80 struct AdjunctsAddr *next;
82 unsigned current, permit, all;
83 RetransmitRelaxedNode rn[ADJUNCTSADDR_TRANSMITS];
87 char *pname; /* first, for pname1st_compar */
89 unsigned bits; /* may have no or several bits set */
92 typedef struct AdjunctsTarget {
93 char *pname; /* first, for pname1st_compar */
95 AdjunctsAdjunct *adjs;
100 extern Segment *segments;
102 extern int n_adjtargs, n_adjaddrs;
103 extern AdjunctsTarget *adjtargs;
104 extern AdjunctsAddr **adjaddrs;
106 /*---------- global variables, in realtime.c ----------*/
108 extern CommandInput cmdi;
109 extern int picio_send_noise;
111 #define CIXF_U 0x0000ffffu
112 #define CIXF_FORCE 0x00010000u
113 #define CIXF_ANYSTA 0x00020000u
115 /*---------- from/for startup.c ----------*/
117 #include "stastate.h"
119 void sta_startup(void);
120 void sta_finalising_done(void);
121 void serial_moredata(PicInsn *buf);
123 extern StartupState sta_state;
124 extern const char *const stastatelist[];
125 void cmdi_output_bufferempty(OutBufferChain *obc);
127 void resolve_begin(void); /* from resolve.c */
128 int resolve_complete(void);
129 void resolve_motioncheck(void);
131 void waggle_settle(void); /* from movpos.c */
132 void waggle_startup_manual(void);
134 /*---------- from/for record.c and persist.c ----------*/
136 void records_parse(const char **argv);
137 void persist_entrails_interpret(void);
138 void persist_entrails_run_converter(void);
139 void persist_install(void);
141 extern const char *persist_fn;
142 extern char *persist_record_converted;
144 void persist_map_veryearly(void);
146 /*---------- from/for realtime.c ----------*/
148 void oupicio(const char *dirn, const PicInsnInfo *pii, int obj, int v,
149 void (*qprintf)(const char *fmt, ...));
150 void ouhex(const char *word, const Byte *command, int length);
151 void ouhex_nosim(const char *word, const Byte *command, int length);
153 void serial_transmit(const PicInsn *pi);
154 void command_doline(ParseState *ps, CommandInput *cmdi_arg);
155 const CmdInfo *current_cmd;
157 /*---------- for/from simulate.c ----------*/
159 void serial_indata_process(int buf_used);
161 void sim_initialise(const char *logduplicate);
164 void simlog_ccb(char *m, size_t l, void *u);
165 void simlogv(const char *fmt, va_list al);
166 void simlog(const char *fmt, ...);
167 void simlog_serial(const Byte *data, int length);
168 void simlog_flush(void);
169 void simlog_open(const char *fn);
171 void mgettimeofday(struct timeval *tv); /* contains magic for simulation */
172 void *toev_callback(oop_source *source, struct timeval tv, void *t_v);
174 void sim_toev_start(TimeoutEvent *toev);
175 void sim_toev_stop(TimeoutEvent *toev);
176 void sim_mgettimeofday(struct timeval *tv);
178 extern int simlog_full;
179 extern const char *simulate;
181 extern PicInsn serial_buf;
183 /*---------- from actual.c ----------*/
185 int picinsn_polarity_testbit(const PicInsn *pi, const SegmentInfo *segi);
186 /* this belongs in {au,skel}proto-pic.[ch] really but it's
187 * more convenient here. */
189 void adjuncts_start_xmit(void);
190 void adjuncts_updated(AdjunctsAddr *a);
192 /*---------- from movpos.c ----------*/
194 void points_turning_on(void);
195 void motions_all_abandon(void);
197 /*---------- from eventhelp.c ----------*/
199 extern const char toev_fast_pclass[];
201 typedef void TimeoutEventFn(TimeoutEvent*);
202 struct TimeoutEvent { /* Undefined Idle Running set by */
203 int running; /* any 0 1 toev_ */
204 int duration; /*ms*/ /* any any[1] any[1] caller */
205 TimeoutEventFn *callback; /* any any valid[2] caller */
206 struct timeval abs; /* any any valid toev_ */
207 const char *pclass, *pinst; /* any any valid caller */
208 }; /* [1] duration must be >=0 or -1 when toev_start is called;
209 * [2] callback may be modified while timeout is running;
210 * value used is that prevailing when timeout happens
211 * when the timeout happens, TimeoutEvent's state goes from R to I
212 * and then callback member is read and the function called
215 void toev_init(TimeoutEvent*); /* U -> I */
216 void toev_start(TimeoutEvent*); /* IR -> R; reads duration */
217 /* if duration is -1 then is same as toev_stop */
218 void toev_stop(TimeoutEvent*); /* IR -> I */
220 /*---------- from rtprio.c ----------*/
222 void realtime_priority(void);
224 #define RTFEAT_DEFAULTS 0100u /* turns on MLOCK and SCHEDPRIO iff not sim */
225 #define RTFEAT_MEM 0001u /* mlock */
226 #define RTFEAT_CPU 0002u /* hard CPU scheduling priority */
228 #define RTFEAT_ALL_SHIFT 16
229 #define RTFEAT_ALL(x) (RTFEAT_##x << RTFEAT_ALL_SHIFT)
230 /* RTFEAT_ALL(FOO) is relevant only if RTFEAT_FOO selected, and means
231 * not to apply the normal limit to the grabbing of FOO */
233 extern unsigned rtfeats_use;
235 void ouvprintf(const char *fmt, va_list al)
236 __attribute__((format(printf,1,0)));
237 void ouprintf(const char *fmt, ...)
238 __attribute__((format(printf,1,2)));
240 void ouvprintf_only(const char *fmt, va_list al)
241 __attribute__((format(printf,1,0)));
242 void ouprintf_only(const char *fmt, ...)
243 __attribute__((format(printf,1,2)));
245 extern unsigned long eventcounter; /* for debugging use only ! */
246 void debug_count_event(const char *what);
248 #define DEBUGP(a,k) (dflags_##a & DBIT_##a##_##k)
250 #define DPRINTFA ouprintf_only
252 #define COND_DPRINTF(cond, a,k, fmt, ...) \
253 ((cond) ? DPRINTFA("debug " #a "/" #k " : " fmt,##__VA_ARGS__) : (void)0)
255 #define DPRINTF(a,k,f,...) COND_DPRINTF(DEBUGP(a,k),a,k,f,##__VA_ARGS__)
256 #define DPRINTF1(a,k,f,...) COND_DPRINTF((DP)=DEBUGP(a,k), a,k,f,##__VA_ARGS__)
257 #define DPRINTF2(f,...) ((DP) ? DPRINTFA(f,##__VA_ARGS__) : (void)0)
259 /*---------- tbi ----------*/
261 void choreographers_all_abandon(void);
265 #define PERSIST_CONVERT_OPTION "--persist-convert-entrails"
270 #endif /*REALTIME_H*/