2 * declarations for realtime daemon
9 #include "auproto-pic.h"
22 #include <sys/types.h>
32 #include "../layout/layout-data.h"
34 typedef struct Segment Segment;
35 typedef struct Train Train;
36 typedef struct TimeoutEvent TimeoutEvent;
38 /*---------- from retransmit.c ----------*/
40 typedef struct RetransmitRelaxedNode RetransmitRelaxedNode;
41 typedef union RetransmitUrgentNode RetransmitUrgentNode;
42 typedef unsigned Retransmit__Time;
44 /* Contents of the retransmission nodes is generally all for use by
45 * retransmit.c only; as a special exception, caller may edit pi
46 * directly. Normally, though, pi is set by supplying an NMRA
47 * command to one of the _queue functions; iff the Nmra* is
48 * non-null, _queue will add an NMRA checksum and update pi.
50 struct RetransmitRelaxedNode {
52 DLIST_NODE(RetransmitRelaxedNode) rr;
54 union RetransmitUrgentNode {
57 RetransmitRelaxedNode relaxed;
59 Retransmit__Time when;
60 DLIST_NODE(RetransmitUrgentNode) queue;
64 void retransmit_start(void);
65 void retransmit_something(void);
67 void retransmit_relaxed_queue(RetransmitRelaxedNode *rn, Nmra *n);
68 void retransmit_relaxed_requeue(RetransmitRelaxedNode *rn, Nmra *n);
69 void retransmit_relaxed_cancel(RetransmitRelaxedNode *rn);
71 void retransmit_urgent_queue(RetransmitUrgentNode *rn, Nmra *n);
72 void retransmit_urgent_queue_relaxed(RetransmitUrgentNode *urg, Nmra *n);
73 void retransmit_urgent_requeue(RetransmitUrgentNode *rn, Nmra *n);
74 void retransmit_urgent_cancel(RetransmitUrgentNode *rn);
76 /* ... NB: these are NOT idempotent. Use _requeue it's queued;
77 * _requeue is just _cancel followed by queue. */
79 /*---------- features, filled in by record, used by features.c ----------*/
81 #define FEATURESADDR_TRANSMITS 4
82 /* 0..2 are func0to4 func5to8 func9to12 and speed cmd
83 * pi.l is 0 if not transmitting */
85 typedef struct FeaturesAddr {
86 struct FeaturesAddr *next;
88 RetransmitRelaxedNode rn[FEATURESADDR_TRANSMITS];
93 int bitval; /* may have no or several bits set */
94 int speedstep; /* -ve means backwards; 0 means not to use motor for feat */
97 typedef struct FeaturesTarget {
98 struct FeaturesTarget *next;
100 char *featchs; /* null-terminated */
101 FeaturesFeature **feats; /* same order as featchs */
105 extern Train *trains;
106 extern Segment *segments;
108 extern FeaturesTarget *feattargs;
109 extern FeaturesAddr *feataddrs;
111 /*---------- global variables, in realtime.c ----------*/
113 extern CommandInput cmdi;
114 extern int picio_send_noise;
116 #define UPO (&(cmdi.out))
118 #define CIXF_ANYSTA 1u
119 #define CIXF_FORCE 2u
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);
159 /*---------- for/from simulate.c ----------*/
161 void serial_indata_process(int buf_used);
163 void sim_initialise(const char *logduplicate);
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 /*---------- from movpos.c ----------*/
192 void points_turning_on(void);
193 void motions_all_abandon(void);
195 /*---------- from eventhelp.c ----------*/
197 extern const char toev_fast_pclass[];
199 typedef void TimeoutEventFn(TimeoutEvent*);
200 struct TimeoutEvent { /* Undefined Idle Running set by */
201 int running; /* any 0 1 toev_ */
202 int duration; /*ms*/ /* any any[1] any[1] caller */
203 TimeoutEventFn *callback; /* any any valid[2] caller */
204 struct timeval abs; /* any any valid toev_ */
205 const char *pclass, *pinst; /* any any valid caller */
206 }; /* [1] duration must be >=0 or -1 when toev_start is called;
207 * [2] callback may be modified while timeout is running;
208 * value used is that prevailing when timeout happens
209 * when the timeout happens, TimeoutEvent's state goes from R to I
210 * and then callback member is read and the function called
213 void toev_init(TimeoutEvent*); /* U -> I */
214 void toev_start(TimeoutEvent*); /* IR -> R; reads duration */
215 /* if duration is -1 then is same as toev_stop */
216 void toev_stop(TimeoutEvent*); /* IR -> I */
218 /*---------- from rtprio.c ----------*/
220 void realtime_priority(void);
222 #define RTFEAT_DEFAULTS 0100u /* turns on MLOCK and SCHEDPRIO iff not sim */
223 #define RTFEAT_MEM 0001u /* mlock */
224 #define RTFEAT_CPU 0002u /* hard CPU scheduling priority */
226 #define RTFEAT_ALL_SHIFT 16
227 #define RTFEAT_ALL(x) (RTFEAT_##x << RTFEAT_ALL_SHIFT)
228 /* RTFEAT_ALL(FOO) is relevant only if RTFEAT_FOO selected, and means
229 * not to apply the normal limit to the grabbing of FOO */
231 extern unsigned rtfeats_use;
233 /*---------- tbi ----------*/
235 void choreographers_all_abandon(void);
237 #define DUPO(ctx) UPO, "debug " ctx " : "
241 #define PERSIST_CONVERT_OPTION "--persist-convert-entrails"
245 #define CTYPE(isfoobar,ch) (isfoobar((unsigned char)(ch)))
247 #endif /*REALTIME_H*/