bzr branch
http://suren.me/webbzr/alps/pcitool
315
by Suren A. Chilingaryan
Support properties of arbitrary type |
1 |
#define _PCILIB_VIEW_ENUM_C
|
2 |
||
3 |
#include <stdio.h> |
|
4 |
#include <unistd.h> |
|
5 |
#include <stdlib.h> |
|
6 |
#include <string.h> |
|
7 |
#include <strings.h> |
|
8 |
||
9 |
#include <uthash.h> |
|
10 |
||
11 |
#include "error.h" |
|
12 |
#include "version.h" |
|
13 |
#include "model.h" |
|
14 |
#include "enum.h" |
|
15 |
#include "view.h" |
|
16 |
#include "value.h" |
|
17 |
#include "register.h" |
|
18 |
||
19 |
||
20 |
static void pcilib_register_view_free(pcilib_t *ctx, pcilib_view_description_t *view) { |
|
21 |
if (view->name) |
|
22 |
free((void*)view->name); |
|
23 |
free(view); |
|
24 |
}
|
|
25 |
||
26 |
static int pcilib_register_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t dummy, pcilib_value_t *val) { |
|
27 |
int err; |
|
28 |
||
29 |
const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); |
|
30 |
pcilib_register_view_description_t *v = (pcilib_register_view_description_t*)(model_info->views[view_ctx->view]); |
|
31 |
||
32 |
if (v->view) { |
|
33 |
return pcilib_read_register_view(ctx, v->bank, v->reg, v->view, val); |
|
34 |
} else { |
|
35 |
pcilib_register_value_t regval; |
|
36 |
||
37 |
err = pcilib_read_register(ctx, v->bank, v->reg, ®val); |
|
38 |
if (err) return err; |
|
39 |
||
40 |
return pcilib_set_value_from_register_value(ctx, val, regval); |
|
41 |
}
|
|
42 |
}
|
|
43 |
||
44 |
static int pcilib_register_view_write(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t *dummy, const pcilib_value_t *val) { |
|
45 |
int err; |
|
46 |
||
47 |
const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); |
|
48 |
pcilib_register_view_description_t *v = (pcilib_register_view_description_t*)(model_info->views[view_ctx->view]); |
|
49 |
||
50 |
if (v->view) { |
|
51 |
return pcilib_write_register_view(ctx, v->bank, v->reg, v->view, val); |
|
52 |
} else { |
|
53 |
pcilib_register_value_t regval; |
|
54 |
||
55 |
regval = pcilib_get_value_as_register_value(ctx, val, &err); |
|
56 |
if (err) return err; |
|
57 |
||
58 |
return pcilib_write_register(ctx, v->bank, v->reg, regval); |
|
59 |
}
|
|
60 |
||
61 |
return err; |
|
62 |
}
|
|
63 |
||
64 |
const pcilib_view_api_description_t pcilib_register_view_api = |
|
65 |
{ PCILIB_VERSION, sizeof(pcilib_register_view_description_t), NULL, NULL, pcilib_register_view_free, pcilib_register_view_read, pcilib_register_view_write }; |