-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracelib.h
304 lines (229 loc) · 10.1 KB
/
tracelib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*************************************************************************
*
* Copyright (c) 2022 Rajit Manohar
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
**************************************************************************
*/
#ifndef __ACT_TRACEIF_H__
#define __ACT_TRACEIF_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef enum act_bool_val {
ACT_SIG_BOOL_FALSE = 0,
ACT_SIG_BOOL_TRUE = 1,
ACT_SIG_BOOL_X = 2,
ACT_SIG_BOOL_Z = 3
} act_bool_val_t;
typedef enum act_chan_state {
ACT_CHAN_SEND_BLOCKED = 0, /* this encoding matches atrace.h */
ACT_CHAN_RECV_BLOCKED = 1,
ACT_CHAN_IDLE = 2,
ACT_CHAN_VALUE = 3
} act_chan_state_t;
typedef enum act_signal_type {
ACT_SIG_BOOL = 0,
ACT_SIG_INT = 1,
ACT_SIG_CHAN = 2, /* channels: unused by various formats */
ACT_SIG_ANALOG = 3 /* real number: voltages and currents */
} act_signal_type_t;
typedef union act_signal_val {
float v; /* for analog values */
unsigned long val; /* for small digital values up to 63 bits */
unsigned long *valp; /* for >63 bit values */
} act_signal_val_t;
#define ACT_TRACE_WIDE_NUM(w) (((w)+8*sizeof (unsigned long)-1)/(8*sizeof(unsigned long)))
typedef struct {
unsigned int has_reader:1;
unsigned int has_writer:1;
/*--- writer API ---*/
/* return a handle to the trace file for subsequent calls */
void *(*create_tracefile) (const char *base, float stop_time, float ts);
/* create tracefile, integer timesteps of arbitrary size, with ts
as the conversion between int and real time */
void *(*create_tracefile_alt) (const char *base, float stop_time, float ts);
/* start adding signal names */
int (*add_signal_start) (void *handle);
/* add different signal types */
void *(*add_analog_signal) (void *handle, const char *s);
void *(*add_digital_signal) (void *handle, const char *s);
void *(*add_int_signal) (void *handle, const char *s, int width);
void *(*add_chan_signal) (void *handle, const char *s, int width);
/* finish adding signal names */
int (*add_signal_end) (void *handle);
/* start adding initial values */
int (*init_start) (void *handle);
/*
use the general signal change functions below to provide
initial values for all variables here
*/
/* finished with initial value */
int (*init_end) (void *handle);
struct {
/* use this for BOOL, INT */
int (*signal_change_digital) (void *handle, void *node, float t,
unsigned long v);
/* for > 64-bit values for INT */
int (*signal_change_wide_digital) (void *handle, void *node, float t,
int len,
unsigned long *v);
/* use this for CHAN */
int (*signal_change_chan) (void *handle, void *node, float t,
act_chan_state_t s, unsigned long v);
/* for > 64-bit CHAN */
int (*signal_change_wide_chan) (void *handle, void *node, float t,
act_chan_state_t s, int len,
unsigned long *v);
/* for analog signals */
int (*signal_change_analog) (void *handle, void *node, float t, float v);
} std;
struct {
int (*signal_change_digital) (void *handle, void *node, int len,
unsigned long *tm, unsigned long v);
int (*signal_change_wide_digital) (void *handle, void *node, int len,
unsigned long *tm,
int len2,
unsigned long *v);
int (*signal_change_chan) (void *handle, void *node, int len,
unsigned long *tm,
act_chan_state_t s, unsigned long v);
int (*signal_change_wide_chan) (void *handle, void *node, int len,
unsigned long *tm,
act_chan_state_t s, int len2,
unsigned long *v);
int (*signal_change_analog) (void *handle, void *node, int len,
unsigned long *tm, float v);
} alt;
/*--- reader API ---*/
/* open file for reading */
void *(*open_tracefile) (const char *base);
void *(*open_tracefile_alt) (const char *base);
/* read metadata */
void (*read_header) (void *handle, float *stop_time, float *dt);
/* return signal, NULL if missing */
void *(*signal_lookup) (void *handle, const char *name);
/* return signal type */
act_signal_type_t (*signal_type) (void *handle, void *node);
void (*advance_time) (void *handle, int nsteps);
void (*advance_time_by) (void *handle, float delta);
act_signal_val_t (*get_signal) (void *nandle, void *node);
int (*has_more_data) (void *handle);
/* close trace file */
int (*close_tracefile) (void *handle);
/* use this to close the library */
void *dlib;
} act_extern_trace_func_t;
typedef struct {
unsigned int mode:1; /* float t = 0, int t = 1 */
unsigned int readonly:1; /* 1 = reader, 0 = create */
int state;
/* 0 = open, ready for signal creation
1 = in-signal-creation
2 = signal create done, ready for init
3 = in-init
4 = init-done, ready for signal changes
5 = in signal change or ready to read
*/
void *handle;
act_extern_trace_func_t *t;
} act_trace_t;
/* Load trace file library.
Function names are prefixed by "prefix_", and must be:
create - mapped to create_tracefile (mode=0)
create_alt - mapped to create tracefile for alt format (mode=1)
signal_start - mapped to add_signal_start
add_analog_signal - mapped to ...
add_digital_signal - ...
add_int_signal - ...
add_chan_signal - ...
signal_end - finish creating signal names, mapped to add_signal_end
init_start - mapped to ...
init_end - mapped to ...
change_digital - ...
change_analog - ...
change_wide_digital - ...
change_chan - ...
change_wide_chan - ...
change_digital_alt - ...
change_analog_alt - ...
change_wide_digital_alt - ...
change_chan_alt - ...
change_wide_chan_alt - ...
close - close_tracefile
If your file format ooes not support a signal type, you can omit
the funcftions from the library. Those signals will be skipped.
*/
act_extern_trace_func_t *act_trace_load_format (const char *prefix, const char *dl);
void act_trace_close_format (act_extern_trace_func_t *fmt);
/* return 1 if the format files have a reader API, 0 otherwise */
int act_trace_fmt_has_reader (act_extern_trace_func_t *);
/* return 1 if the format files have a writer API, 0 otherwise */
int act_trace_fmt_has_writer (act_extern_trace_func_t *);
/* return a handle to the trace file for subsequent calls
mode = 0 : use functions that have floating-point times
mode = 1 : use functions that have integer times
*/
act_trace_t *act_trace_create (act_extern_trace_func_t *,
const char *name, float stop_time, float ts,
int mode);
void *act_trace_add_signal (act_trace_t *, act_signal_type_t type,
const char *s, int width);
int act_trace_init_start (act_trace_t *);
int act_trace_init_end (act_trace_t *);
int act_trace_analog_change (act_trace_t *, void *node, float t, float v);
int act_trace_digital_change (act_trace_t *, void *node, float t, unsigned long v);
int act_trace_wide_digital_change (act_trace_t *, void *node, float t,
int len, unsigned long *v);
int act_trace_chan_change (act_trace_t *, void *node, float t,
act_chan_state_t s, unsigned long v);
int act_trace_wide_chan_change (act_trace_t *, void *node, float t,
act_chan_state_t s, int len, unsigned long *v);
int act_trace_analog_change_alt (act_trace_t *, void *node, int len, unsigned long *tm, float v);
int act_trace_digital_change_alt (act_trace_t *, void *node, int len, unsigned long *tm, unsigned long v);
int act_trace_wide_digital_change_alt (act_trace_t *, void *node, int len, unsigned long *tm, int lenv, unsigned long *v);
int act_trace_chan_change_alt (act_trace_t *, void *node, int len, unsigned long *tm, act_chan_state_t s, unsigned long v);
int act_trace_wide_chan_change_alt (act_trace_t *, void *node, int len, unsigned long *tm, act_chan_state_t s, int lenv, unsigned long *v);
int act_trace_close (act_trace_t *);
int act_trace_has_alt (act_extern_trace_func_t *);
/*-- API for reading --*/
/* mode = 0/1 : same as the .._create() function */
act_trace_t *act_trace_open (act_extern_trace_func_t *,
const char *name, int mode);
/* get parameters from the header: if info is missing from the file
format, a -1 is returned in stop_time/dt */
void act_trace_header (act_trace_t *, float *stop_time, float *dt);
/* get a signal pointer given the signal name */
void *act_trace_lookup (act_trace_t *, const char *name);
/* return the signal type: bool, int, channel, analog */
act_signal_type_t act_trace_sigtype (act_trace_t *, void *sig);
/* advance time by steps (in units of deltaT) or by an actual amount
in SI units. */
void act_trace_advance_steps (act_trace_t *, int steps);
void act_trace_advance_time (act_trace_t *, float dt);
/* returns 1 if there are future timesteps in the trace file, 0
otherwise */
int act_trace_has_more_data (act_trace_t *);
/* get the value of the specified signal */
act_signal_val_t act_trace_get_signal (act_trace_t *, void *sig);
/* get value, shortcuts optimized for specific signal types */
unsigned long act_trace_get_smallval (act_trace_t *, void *sig);
float act_trace_get_analog (act_trace_t *, void *sig);
#ifdef __cplusplus
}
#endif
#endif /* __ACT_TRACEIF_H__ */