/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to event.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-12-08 02:47:23 UTC
  • Revision ID: csa@dside.dyndns.org-20111208024723-ym9uf3uoll6ym2a9
new event architecture, first trial

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    pcilib_event_description_t *events = model_info->events;
37
37
    
38
38
    for (i = 0; events[i].name; i++) {
39
 
        if (!strcasecmp(events[i].name, event)) return (1<<i);
 
39
        if (!strcasecmp(events[i].name, event)) return events[i].evid;
40
40
    }
41
41
 
42
42
    return (pcilib_event_t)-1;
43
43
}
44
44
 
 
45
pcilib_event_data_type_t pcilib_find_event_data_type(pcilib_t *ctx, pcilib_event_t event, const char *data_type) {
 
46
    int i;
 
47
    pcilib_register_bank_t res;
 
48
    unsigned long addr;
 
49
    
 
50
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
 
51
    pcilib_event_data_type_description_t *data_types = model_info->data_types;
 
52
    
 
53
    for (i = 0; data_types[i].name; i++) {
 
54
        if ((data_types[i].evid&event)&&(!strcasecmp(data_types[i].name, data_type))) return data_types[i].data_type;
 
55
    }
 
56
 
 
57
    return (pcilib_event_data_type_t)-1;
 
58
}
 
59
 
 
60
int pcilib_init_event_engine(pcilib_t *ctx) {
 
61
    pcilib_event_api_description_t *api;
 
62
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
 
63
 
 
64
    api = model_info->event_api;
 
65
 
 
66
//    api = pcilib_model[model].event_api;
 
67
    if ((api)&&(api->init)) {
 
68
        ctx->event_ctx = api->init(ctx);
 
69
        if (ctx->event_ctx) {
 
70
            ctx->event_ctx->pcilib = ctx;
 
71
        }
 
72
    }
 
73
    
 
74
    return 0;
 
75
}
45
76
 
46
77
int pcilib_reset(pcilib_t *ctx) {
47
78
    pcilib_event_api_description_t *api;
60
91
    return 0;
61
92
}
62
93
 
63
 
int pcilib_start(pcilib_t *ctx, pcilib_event_t event_mask, void *callback, void *user) {
 
94
int pcilib_configure_rawdata_callback(pcilib_t *ctx, pcilib_event_rawdata_callback_t callback, void *user) {
 
95
    pcilib_event_api_description_t *api;
 
96
    
 
97
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
 
98
 
 
99
    api = model_info->event_api;
 
100
    if (!api) {
 
101
        pcilib_error("Event API is not supported by the selected model");
 
102
        return PCILIB_ERROR_NOTSUPPORTED;
 
103
    }
 
104
 
 
105
    ctx->event_ctx->params.rawdata.callback = callback;
 
106
    ctx->event_ctx->params.rawdata.user = user;
 
107
    
 
108
    return 0;    
 
109
}
 
110
 
 
111
int pcilib_configure_autostop(pcilib_t *ctx, size_t max_events, pcilib_timeout_t duration) {
 
112
    pcilib_event_api_description_t *api;
 
113
    
 
114
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
 
115
 
 
116
    api = model_info->event_api;
 
117
    if (!api) {
 
118
        pcilib_error("Event API is not supported by the selected model");
 
119
        return PCILIB_ERROR_NOTSUPPORTED;
 
120
    }
 
121
 
 
122
    ctx->event_ctx->params.autostop.max_events = max_events;
 
123
    ctx->event_ctx->params.autostop.duration = duration;
 
124
    
 
125
    return 0;    
 
126
}
 
127
 
 
128
int pcilib_start(pcilib_t *ctx, pcilib_event_t event_mask, pcilib_event_flags_t flags) {
64
129
    pcilib_event_api_description_t *api;
65
130
    
66
131
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
72
137
    }
73
138
 
74
139
    if (api->start) 
75
 
        return api->start(ctx->event_ctx, event_mask, callback, user);
 
140
        return api->start(ctx->event_ctx, event_mask, flags);
76
141
 
77
142
    return 0;
78
143
}
79
144
 
80
 
int pcilib_stop(pcilib_t *ctx) {
 
145
int pcilib_stop(pcilib_t *ctx, pcilib_event_flags_t flags) {
81
146
    pcilib_event_api_description_t *api;
82
147
    
83
148
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
89
154
    }
90
155
 
91
156
    if (api->stop) 
92
 
        return api->stop(ctx->event_ctx);
 
157
        return api->stop(ctx->event_ctx, flags);
93
158
 
94
159
    return 0;
95
160
}
96
161
 
97
 
pcilib_event_id_t pcilib_get_next_event(pcilib_t *ctx, pcilib_event_t event_mask, pcilib_timeout_t timeout) {
98
 
    pcilib_event_api_description_t *api;
 
162
int pcilib_stream(pcilib_t *ctx, pcilib_event_callback_t callback, void *user) {
 
163
    pcilib_event_api_description_t *api;
 
164
    
 
165
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
 
166
 
 
167
    api = model_info->event_api;
 
168
    if (!api) {
 
169
        pcilib_error("Event API is not supported by the selected model");
 
170
        return PCILIB_ERROR_NOTSUPPORTED;
 
171
    }
 
172
 
 
173
    if (api->stream)
 
174
        return api->stream(ctx->event_ctx, callback, user);
 
175
 
 
176
    if (api->next_event) {
 
177
        pcilib_error("Streaming using next_event API is not implemented yet");
 
178
    }
 
179
 
 
180
    pcilib_error("Event enumeration is not suppored by API");
 
181
    return PCILIB_ERROR_NOTSUPPORTED;
 
182
}
 
183
/*
 
184
typedef struct {
 
185
    pcilib_event_id_t event_id;
 
186
    pcilib_event_info_t *info;
 
187
} pcilib_return_event_callback_context_t;
 
188
 
 
189
static int pcilib_return_event_callback(pcilib_event_id_t event_id, pcilib_event_info_t *info, void *user) {
 
190
    pcilib_return_event_callback_context_t *ctx = (pcilib_return_event_callback_context_t*)user;
 
191
    ctx->event_id = event_id;
 
192
    ctx->info = info;
 
193
}
 
194
*/
 
195
 
 
196
int pcilib_get_next_event(pcilib_t *ctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, pcilib_event_info_t **info) {
 
197
    int err;
 
198
    pcilib_event_api_description_t *api;
 
199
//    pcilib_return_event_callback_context_t user;
99
200
    
100
201
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
101
202
 
106
207
    }
107
208
 
108
209
    if (api->next_event) 
109
 
        return api->next_event(ctx->event_ctx, event_mask, timeout);
 
210
        return api->next_event(ctx->event_ctx, timeout, evid, info);
 
211
 
 
212
/*      
 
213
    if (api->stream) {
 
214
        err = api->stream(ctx->event_ctx, 1, timeout, pcilib_return_event_callback, &user);
 
215
        if (err) return err;
 
216
        
 
217
        if (evid) *evid = user->event_id;
 
218
        if (info) *info = user->info;
 
219
 
 
220
        return 0;
 
221
    }
 
222
*/
110
223
 
111
224
    pcilib_error("Event enumeration is not suppored by API");
112
 
    return PCILIB_EVENT_ID_INVALID;
 
225
    return PCILIB_ERROR_NOTSUPPORTED;
113
226
}
114
227
 
115
228
int pcilib_trigger(pcilib_t *ctx, pcilib_event_t event, size_t trigger_size, void *trigger_data) {
141
254
    }
142
255
 
143
256
    if (api->get_data) 
144
 
        return api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, size);
 
257
        return api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, size, NULL);
145
258
 
146
259
    return NULL;
147
260
}
148
261
 
 
262
int pcilib_copy_data_with_argument(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t size, void *buf, size_t *retsize) {
 
263
    void *res;
 
264
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
 
265
 
 
266
    pcilib_event_api_description_t *api = model_info->event_api;
 
267
    if (!api) {
 
268
        pcilib_error("Event API is not supported by the selected model");
 
269
        return PCILIB_ERROR_NOTSUPPORTED;
 
270
    }
 
271
 
 
272
    if (api->get_data) {
 
273
        res = api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, &size, buf);
 
274
        if (!res) return PCILIB_ERROR_FAILED;
 
275
        
 
276
        if (retsize) *retsize = size;
 
277
        return 0;
 
278
    }   
 
279
 
 
280
    return PCILIB_ERROR_NOTSUPPORTED;
 
281
}
 
282
 
 
283
 
149
284
void *pcilib_get_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t *size) {
150
285
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
151
286
 
156
291
    }
157
292
 
158
293
    if (api->get_data) 
159
 
        return api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, size);
 
294
        return api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, size, NULL);
160
295
 
161
296
    return NULL;
162
297
}
163
298
 
164
 
int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id) {
 
299
int pcilib_copy_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t size, void *buf, size_t *ret_size) {
 
300
    void *res;
 
301
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
 
302
 
 
303
    pcilib_event_api_description_t *api = model_info->event_api;
 
304
    if (!api) {
 
305
        pcilib_error("Event API is not supported by the selected model");
 
306
        return PCILIB_ERROR_NOTSUPPORTED;
 
307
    }
 
308
 
 
309
    if (api->get_data) {
 
310
        res = api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, &size, buf);
 
311
        if (!res) return PCILIB_ERROR_FAILED;
 
312
        
 
313
        if (ret_size) *ret_size = size;
 
314
        return 0;
 
315
    }
 
316
 
 
317
    return PCILIB_ERROR_NOTSUPPORTED;
 
318
}
 
319
 
 
320
int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id, void *data) {
165
321
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
166
322
    
167
323
    pcilib_event_api_description_t *api = model_info->event_api;
171
327
    }
172
328
 
173
329
    if (api->return_data) 
174
 
        return api->return_data(ctx->event_ctx, event_id);
 
330
        return api->return_data(ctx->event_ctx, event_id, data);
175
331
 
176
332
    return 0;
177
333
}
184
340
    void **data;
185
341
} pcilib_grab_callback_user_data_t;
186
342
 
 
343
 
187
344
static int pcilib_grab_callback(pcilib_event_t event, pcilib_event_id_t event_id, void *vuser) {
188
345
    int err;
189
346
    void *data;
217
374
    
218
375
    memcpy(*(user->data), data, size);
219
376
    
220
 
    err = pcilib_return_data(user->ctx, event_id);
 
377
    err = pcilib_return_data(user->ctx, event_id, data);
221
378
    if (err) {
222
379
        if (allocated) {
223
380
            free(*(user->data));
233
390
int pcilib_grab(pcilib_t *ctx, pcilib_event_t event_mask, size_t *size, void **data, pcilib_timeout_t timeout) {
234
391
    int err;
235
392
    struct timespec ts;
 
393
    pcilib_event_id_t eid;
236
394
    
237
395
    pcilib_grab_callback_user_data_t user = {ctx, size, data};
238
396
    
239
 
    err = pcilib_start(ctx, event_mask, pcilib_grab_callback, &user);
 
397
    err = pcilib_start(ctx, event_mask, PCILIB_EVENT_FLAGS_DEFAULT);
 
398
    if (!err) err = pcilib_trigger(ctx, event_mask, 0, NULL);
240
399
    if (!err) {
241
 
        if (timeout) {
242
 
            ts.tv_sec = timeout / 1000000;
243
 
            ts.tv_nsec = 1000 * (timeout % 1000000);
244
 
            nanosleep(&ts, NULL);
245
 
        } else err = pcilib_trigger(ctx, event_mask, 0, NULL);
 
400
        err = pcilib_get_next_event(ctx, timeout, &eid, NULL);
 
401
        if (!err) pcilib_grab_callback(event_mask, eid, &user);
246
402
    }
247
 
    pcilib_stop(ctx);
 
403
    pcilib_stop(ctx, PCILIB_EVENT_FLAGS_DEFAULT);
248
404
    return err;
249
405
}