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_relaxed_queue(RetransmitRelaxedNode *rn, Nmra *n);
59 void retransmit_relaxed_requeue(RetransmitRelaxedNode *rn, Nmra *n);
60 void retransmit_relaxed_cancel(RetransmitRelaxedNode *rn);
62 void retransmit_urgent_queue(RetransmitUrgentNode *rn, Nmra *n);
63 void retransmit_urgent_queue_relaxed(RetransmitUrgentNode *urg, Nmra *n);
64 void retransmit_urgent_requeue(RetransmitUrgentNode *rn, Nmra *n);
65 void retransmit_urgent_cancel(RetransmitUrgentNode *rn);
67 /* ... NB: these are NOT idempotent. Use _requeue it's queued;
68 * _requeue is just _cancel followed by queue. */
70 /*---------- features, filled in by record, used by features.c ----------*/
72 #define FEATURESADDR_TRANSMITS 4
73 /* 0..2 are func0to4 func5to8 func9to12 and speed cmd
74 * pi.l is 0 if not applicable */
76 typedef struct FeaturesAddr {
77 struct FeaturesAddr *next;
79 unsigned current, permitted; /* nmra features */
80 RetransmitRelaxedNode rn[FEATURESADDR_TRANSMITS];
85 extern Segment *segments;
87 extern FeaturesAddr *feataddrs;
89 /*---------- global variables, in realtime.c ----------*/
91 extern CommandInput cmdi;
92 extern int picio_send_noise;
94 #define CIXF_U 0x0000ffffu
95 #define CIXF_FORCE 0x00010000u
96 #define CIXF_ANYSTA 0x00020000u
98 /*---------- from/for startup.c ----------*/
100 #include "stastate.h"
102 void sta_startup(void);
103 void sta_finalising_done(void);
104 void serial_moredata(PicInsn *buf);
106 extern StartupState sta_state;
107 extern const char *const stastatelist[];
109 void resolve_begin(void); /* from resolve.c */
110 int resolve_complete(void);
111 void resolve_motioncheck(void);
113 void waggle_settle(void); /* from movpos.c */
114 void waggle_startup_manual(void);
116 /*---------- from/for record.c and persist.c ----------*/
118 void records_parse(const char **argv);
119 void persist_entrails_interpret(void);
120 void persist_entrails_run_converter(void);
121 void persist_install(void);
123 extern const char *persist_fn;
124 extern char *persist_record_converted;
126 void persist_map_veryearly(void);
128 /*---------- from/for realtime.c ----------*/
130 void oupicio(const char *dirn, const PicInsnInfo *pii, int obj, int v,
131 void (*qprintf)(const char *fmt, ...));
132 void ouhex(const char *word, const Byte *command, int length);
133 void ouhex_nosim(const char *word, const Byte *command, int length);
135 void serial_transmit(const PicInsn *pi);
136 void command_doline(ParseState *ps, CommandInput *cmdi_arg);
137 const CmdInfo *current_cmd;
139 /*---------- for/from simulate.c ----------*/
141 void serial_indata_process(int buf_used);
143 void sim_initialise(const char *logduplicate);
146 void simlog_ccb(char *m, size_t l, void *u);
147 void simlogv(const char *fmt, va_list al);
148 void simlog(const char *fmt, ...);
149 void simlog_serial(const Byte *data, int length);
150 void simlog_flush(void);
151 void simlog_open(const char *fn);
153 void mgettimeofday(struct timeval *tv); /* contains magic for simulation */
154 void *toev_callback(oop_source *source, struct timeval tv, void *t_v);
156 void sim_toev_start(TimeoutEvent *toev);
157 void sim_toev_stop(TimeoutEvent *toev);
158 void sim_mgettimeofday(struct timeval *tv);
160 extern int simlog_full;
161 extern const char *simulate;
163 extern PicInsn serial_buf;
165 /*---------- from actual.c ----------*/
167 int picinsn_polarity_testbit(const PicInsn *pi, const SegmentInfo *segi);
168 /* this belongs in {au,skel}proto-pic.[ch] really but it's
169 * more convenient here. */
171 /*---------- from movpos.c ----------*/
173 void points_turning_on(void);
174 void motions_all_abandon(void);
176 /*---------- from eventhelp.c ----------*/
178 extern const char toev_fast_pclass[];
180 typedef void TimeoutEventFn(TimeoutEvent*);
181 struct TimeoutEvent { /* Undefined Idle Running set by */
182 int running; /* any 0 1 toev_ */
183 int duration; /*ms*/ /* any any[1] any[1] caller */
184 TimeoutEventFn *callback; /* any any valid[2] caller */
185 struct timeval abs; /* any any valid toev_ */
186 const char *pclass, *pinst; /* any any valid caller */
187 }; /* [1] duration must be >=0 or -1 when toev_start is called;
188 * [2] callback may be modified while timeout is running;
189 * value used is that prevailing when timeout happens
190 * when the timeout happens, TimeoutEvent's state goes from R to I
191 * and then callback member is read and the function called
194 void toev_init(TimeoutEvent*); /* U -> I */
195 void toev_start(TimeoutEvent*); /* IR -> R; reads duration */
196 /* if duration is -1 then is same as toev_stop */
197 void toev_stop(TimeoutEvent*); /* IR -> I */
199 /*---------- from rtprio.c ----------*/
201 void realtime_priority(void);
203 #define RTFEAT_DEFAULTS 0100u /* turns on MLOCK and SCHEDPRIO iff not sim */
204 #define RTFEAT_MEM 0001u /* mlock */
205 #define RTFEAT_CPU 0002u /* hard CPU scheduling priority */
207 #define RTFEAT_ALL_SHIFT 16
208 #define RTFEAT_ALL(x) (RTFEAT_##x << RTFEAT_ALL_SHIFT)
209 /* RTFEAT_ALL(FOO) is relevant only if RTFEAT_FOO selected, and means
210 * not to apply the normal limit to the grabbing of FOO */
212 extern unsigned rtfeats_use;
214 void ouvprintf(const char *fmt, va_list al);
215 void ouprintf(const char *fmt, ...);
217 void ouvprintf_only(const char *fmt, va_list al);
218 void ouprintf_only(const char *fmt, ...);
220 void debug_count_event(const char *what);
222 #define DEBUGP(a,k) (dflags_##a & DBIT_##a##_##k)
224 #define COND_DPRINTF(cond, a,k, fmt, ...) \
225 ((cond) ? ouprintf_only("debug " #a "/" #k " : " fmt,##__VA_ARGS__) : (void)0)
227 #define DPRINTF(a,k,f,...) COND_DPRINTF(DEBUGP(a,k),a,k,f,##__VA_ARGS__)
228 #define DPRINTF1(a,k,f,...) COND_DPRINTF((DP)=DEBUGP(a,k), a,k,f,##__VA_ARGS__)
229 #define DPRINTF2(f,...) ((DP) ? ouprintf_only(f,##__VA_ARGS__) : (void)0)
231 /*---------- tbi ----------*/
233 void choreographers_all_abandon(void);
237 #define PERSIST_CONVERT_OPTION "--persist-convert-entrails"
242 #endif /*REALTIME_H*/