2 * declarations for realtime daemon
9 #include "auproto-pic.h"
31 #include "../layout/layout-data.h"
33 typedef struct Segment Segment;
34 typedef struct Train Train;
35 typedef struct TimeoutEvent TimeoutEvent;
37 /*---------- from retransmit.c ----------*/
39 typedef struct RetransmitRelaxedNode RetransmitRelaxedNode;
40 typedef union RetransmitUrgentNode RetransmitUrgentNode;
41 typedef unsigned Retransmit__Time;
43 /* Contents of the retransmission nodes is generally all for use by
44 * retransmit.c only; as a special exception, caller may edit pi
45 * directly. Normally, though, pi is set by supplying an NMRA
46 * command to one of the _queue functions; iff the Nmra* is
47 * non-null, _queue will add an NMRA checksum and update pi.
49 struct RetransmitRelaxedNode {
51 DLIST_NODE(RetransmitRelaxedNode) rr;
53 union RetransmitUrgentNode {
56 RetransmitRelaxedNode relaxed;
58 Retransmit__Time when;
59 DLIST_NODE(RetransmitUrgentNode) queue;
63 void retransmit_start(void);
64 void retransmit_something(void);
66 void retransmit_relaxed_queue(RetransmitRelaxedNode *rn, Nmra *n);
67 void retransmit_relaxed_requeue(RetransmitRelaxedNode *rn, Nmra *n);
68 void retransmit_relaxed_cancel(RetransmitRelaxedNode *rn);
70 void retransmit_urgent_queue(RetransmitUrgentNode *rn, Nmra *n);
71 void retransmit_urgent_queue_relaxed(RetransmitUrgentNode *urg, Nmra *n);
72 void retransmit_urgent_requeue(RetransmitUrgentNode *rn, Nmra *n);
73 void retransmit_urgent_cancel(RetransmitUrgentNode *rn);
75 /* ... NB: these are NOT idempotent. Use _requeue it's queued;
76 * _requeue is just _cancel followed by queue. */
78 /*---------- features, filled in by record, used by features.c ----------*/
80 #define FEATURESADDR_TRANSMITS 4
81 /* 0..2 are func0to4 func5to8 func9to12 and speed cmd
82 * pi.l is 0 if not transmitting */
84 typedef struct FeaturesAddr {
85 struct FeaturesAddr *next;
87 RetransmitRelaxedNode rn[FEATURESADDR_TRANSMITS];
92 int bitval; /* may have no or several bits set */
93 int speedstep; /* -ve means backwards; 0 means not to use motor for feat */
96 typedef struct FeaturesTarget {
97 struct FeaturesTarget *next;
99 char *featchs; /* null-terminated */
100 FeaturesFeature **feats; /* same order as featchs */
104 extern Train *trains;
105 extern Segment *segments;
107 extern FeaturesTarget *feattargs;
108 extern FeaturesAddr *feataddrs;
110 /*---------- global variables, in realtime.c ----------*/
112 extern CommandInput cmdi;
113 extern int picio_send_noise;
115 #define UPO (&(cmdi.out))
117 #define CIXF_U 0x0000ffffu
118 #define CIXF_FORCE 0x00010000u
119 #define CIXF_ANYSTA 0x00020000u
121 /*---------- from/for startup.c ----------*/
123 #include "stastate.h"
125 void sta_startup(void);
126 void sta_finalising_done(void);
127 void serial_moredata(PicInsn *buf);
129 extern StartupState sta_state;
130 extern const char *const stastatelist[];
132 void resolve_begin(void); /* from resolve.c */
133 int resolve_complete(void);
134 void resolve_motioncheck(void);
136 void waggle_settle(void); /* from movpos.c */
137 void waggle_startup_manual(void);
139 /*---------- from/for record.c and persist.c ----------*/
141 void records_parse(const char **argv);
142 void persist_entrails_interpret(void);
143 void persist_entrails_run_converter(void);
144 void persist_install(void);
146 extern const char *persist_fn;
147 extern char *persist_record_converted;
149 void persist_map_veryearly(void);
151 /*---------- from/for realtime.c ----------*/
153 void oupicio(const char *dirn, const PicInsnInfo *pii, int obj, int v);
154 void ouhexi(const char *word, const Byte *command, int length);
155 void ouhexo(const char *word, const Byte *command, int length);
157 void serial_transmit(const PicInsn *pi);
158 void command_doline(ParseState *ps, CommandInput *cmdi_arg);
159 const CmdInfo *current_cmd;
161 /*---------- for/from simulate.c ----------*/
163 void serial_indata_process(int buf_used);
165 void sim_initialise(const char *logduplicate);
168 void simlogv(const char *fmt, va_list al);
169 void simlog(const char *fmt, ...);
170 void simlog_serial(const Byte *data, int length);
171 void simlog_flush(void);
172 void simlog_open(const char *fn);
174 void mgettimeofday(struct timeval *tv); /* contains magic for simulation */
175 void *toev_callback(oop_source *source, struct timeval tv, void *t_v);
177 void sim_toev_start(TimeoutEvent *toev);
178 void sim_toev_stop(TimeoutEvent *toev);
179 void sim_mgettimeofday(struct timeval *tv);
181 extern int simlog_full;
182 extern const char *simulate;
184 extern PicInsn serial_buf;
186 /*---------- from actual.c ----------*/
188 int picinsn_polarity_testbit(const PicInsn *pi, const SegmentInfo *segi);
189 /* this belongs in {au,skel}proto-pic.[ch] really but it's
190 * more convenient here. */
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 /*---------- tbi ----------*/
237 void choreographers_all_abandon(void);
239 #define DUPO(ctx) UPO, "debug " ctx " : "
243 #define PERSIST_CONVERT_OPTION "--persist-convert-entrails"
247 #define CTYPE(isfoobar,ch) (isfoobar((unsigned char)(ch)))
249 #endif /*REALTIME_H*/