summaryrefslogtreecommitdiffstats
path: root/pcilib
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2015-10-13 00:40:04 +0200
committerSuren A. Chilingaryan <csa@suren.me>2015-10-13 00:40:04 +0200
commit981a4dafac2d2e7ed237cb31af68c7bf2cee8665 (patch)
tree4491e77b8a441565a084f4b169aa334977f8b0c7 /pcilib
parentf13867f64fcba24ef2cb9d726b5ee1082ac1a8b9 (diff)
downloadpcitool-981a4dafac2d2e7ed237cb31af68c7bf2cee8665.tar.gz
pcitool-981a4dafac2d2e7ed237cb31af68c7bf2cee8665.tar.bz2
pcitool-981a4dafac2d2e7ed237cb31af68c7bf2cee8665.tar.xz
pcitool-981a4dafac2d2e7ed237cb31af68c7bf2cee8665.zip
Support transform views
Diffstat (limited to 'pcilib')
-rw-r--r--pcilib/pcilib.h5
-rw-r--r--pcilib/py.c2
-rw-r--r--pcilib/value.c81
-rw-r--r--pcilib/view.c37
4 files changed, 115 insertions, 10 deletions
diff --git a/pcilib/pcilib.h b/pcilib/pcilib.h
index 6acceb6..5c1ca70 100644
--- a/pcilib/pcilib.h
+++ b/pcilib/pcilib.h
@@ -223,7 +223,12 @@ void pcilib_clean_value(pcilib_t *ctx, pcilib_value_t *val);
int pcilib_copy_value(pcilib_t *ctx, pcilib_value_t *dst, const pcilib_value_t *src);
int pcilib_set_value_from_float(pcilib_t *ctx, pcilib_value_t *val, double fval);
int pcilib_set_value_from_int(pcilib_t *ctx, pcilib_value_t *val, long ival);
+int pcilib_set_value_from_register_value(pcilib_t *ctx, pcilib_value_t *value, pcilib_register_value_t regval);
int pcilib_set_value_from_static_string(pcilib_t *ctx, pcilib_value_t *value, const char *str);
+double pcilib_get_value_as_float(pcilib_t *ctx, const pcilib_value_t *val, int *err);
+long pcilib_get_value_as_int(pcilib_t *ctx, const pcilib_value_t *val, int *err);
+pcilib_register_value_t pcilib_get_value_as_register_value(pcilib_t *ctx, const pcilib_value_t *val, int *err);
+
int pcilib_convert_value_unit(pcilib_t *ctx, pcilib_value_t *val, const char *unit_name);
int pcilib_convert_value_type(pcilib_t *ctx, pcilib_value_t *val, pcilib_value_type_t type);
diff --git a/pcilib/py.c b/pcilib/py.c
index 2248892..6aaa22f 100644
--- a/pcilib/py.c
+++ b/pcilib/py.c
@@ -63,7 +63,7 @@ static int pcilib_py_realloc_string(pcilib_t *ctx, size_t required, size_t *size
static char *pcilib_py_parse_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *value) {
int i;
int err = 0;
- pcilib_value_t val;
+ pcilib_value_t val = {0};
pcilib_register_value_t regval;
char save;
diff --git a/pcilib/value.c b/pcilib/value.c
index b039e5f..1a8cc45 100644
--- a/pcilib/value.c
+++ b/pcilib/value.c
@@ -57,6 +57,10 @@ int pcilib_set_value_from_int(pcilib_t *ctx, pcilib_value_t *value, long ival) {
return 0;
}
+int pcilib_set_value_from_register_value(pcilib_t *ctx, pcilib_value_t *value, pcilib_register_value_t regval) {
+ return pcilib_set_value_from_int(ctx, value, regval);
+}
+
int pcilib_set_value_from_static_string(pcilib_t *ctx, pcilib_value_t *value, const char *str) {
pcilib_clean_value(ctx, value);
@@ -66,6 +70,83 @@ int pcilib_set_value_from_static_string(pcilib_t *ctx, pcilib_value_t *value, co
return 0;
}
+double pcilib_get_value_as_float(pcilib_t *ctx, const pcilib_value_t *val, int *ret) {
+ int err;
+ double res;
+ pcilib_value_t copy = {0};
+
+ err = pcilib_copy_value(ctx, &copy, val);
+ if (err) {
+ if (ret) *ret = err;
+ return 0.;
+ }
+
+ err = pcilib_convert_value_type(ctx, &copy, PCILIB_TYPE_DOUBLE);
+ if (err) {
+ if (ret) *ret = err;
+ return 0.;
+ }
+
+ if (ret) *ret = 0;
+ res = copy.fval;
+
+ pcilib_clean_value(ctx, &copy);
+
+ return res;
+}
+
+long pcilib_get_value_as_int(pcilib_t *ctx, const pcilib_value_t *val, int *ret) {
+ int err;
+ long res;
+ pcilib_value_t copy = {0};
+
+ err = pcilib_copy_value(ctx, &copy, val);
+ if (err) {
+ if (ret) *ret = err;
+ return 0;
+ }
+
+ err = pcilib_convert_value_type(ctx, &copy, PCILIB_TYPE_LONG);
+ if (err) {
+ if (ret) *ret = err;
+ return 0;
+ }
+
+ if (ret) *ret = 0;
+ res = copy.ival;
+
+ pcilib_clean_value(ctx, &copy);
+
+ return res;
+}
+
+pcilib_register_value_t pcilib_get_value_as_register_value(pcilib_t *ctx, const pcilib_value_t *val, int *ret) {
+ int err;
+ pcilib_register_value_t res;
+ pcilib_value_t copy = {0};
+
+ err = pcilib_copy_value(ctx, &copy, val);
+ if (err) {
+ if (ret) *ret = err;
+ return 0.;
+ }
+
+ err = pcilib_convert_value_type(ctx, &copy, PCILIB_TYPE_LONG);
+ if (err) {
+ if (ret) *ret = err;
+ return 0.;
+ }
+
+ if (ret) *ret = 0;
+ res = copy.ival;
+
+ pcilib_clean_value(ctx, &copy);
+
+ return res;
+}
+
+
+
/*
double pcilib_value_get_float(pcilib_value_t *val) {
diff --git a/pcilib/view.c b/pcilib/view.c
index e9fdab5..c1ad44a 100644
--- a/pcilib/view.c
+++ b/pcilib/view.c
@@ -135,17 +135,21 @@ pcilib_view_context_t *pcilib_find_register_view_context_by_name(pcilib_t *ctx,
}
// We expect symmetric units. Therefore, we don't distringuish if we read or write
-pcilib_view_context_t *pcilib_find_register_view_context(pcilib_t *ctx, pcilib_register_t reg, const char *name) {
+static int pcilib_detect_register_view_and_unit(pcilib_t *ctx, pcilib_register_t reg, const char *name, pcilib_view_context_t **ret_view, pcilib_unit_transform_t **ret_trans) {
pcilib_view_t i;
pcilib_view_context_t *view_ctx;
pcilib_view_description_t *view_desc;
pcilib_register_context_t *regctx = &ctx->register_ctx[reg];
- if (!regctx->views) return NULL;
+ if (!regctx->views) return PCILIB_ERROR_NOTFOUND;
// Check if view is just a name of listed view
view_ctx = pcilib_find_register_view_context_by_name(ctx, reg, name);
- if (view_ctx) return view_ctx;
+ if (view_ctx) {
+ if (ret_view) *ret_view = view_ctx;
+ if (ret_trans) *ret_trans = NULL;
+ return 0;
+ }
// Check if view is a unit
for (i = 0; regctx->views[i].name; i++) {
@@ -157,13 +161,26 @@ pcilib_view_context_t *pcilib_find_register_view_context(pcilib_t *ctx, pcilib_r
view_desc = ctx->views[view_ctx->view];
if (view_desc->unit) {
trans = pcilib_find_transform_by_unit_names(ctx, view_desc->unit, name);
- if (trans) return pcilib_find_view_context_by_name(ctx, view_desc->name);
+ if (trans) {
+ if (ret_trans) *ret_trans = trans;
+ if (ret_view) *ret_view = pcilib_find_view_context_by_name(ctx, view_desc->name);
+ return 0;
+ }
}
}
- return NULL;
+ return PCILIB_ERROR_NOTFOUND;
}
+pcilib_view_context_t *pcilib_find_register_view_context(pcilib_t *ctx, pcilib_register_t reg, const char *name) {
+ int err;
+ pcilib_view_context_t *view;
+
+ err = pcilib_detect_register_view_and_unit(ctx, reg, name, &view, NULL);
+ if (err) return NULL;
+
+ return view;
+}
typedef struct {
pcilib_register_t reg;
@@ -172,6 +189,7 @@ typedef struct {
} pcilib_view_configuration_t;
static int pcilib_detect_view_configuration(pcilib_t *ctx, const char *bank, const char *regname, const char *view_cname, int write_direction, pcilib_view_configuration_t *cfg) {
+ int err = 0;
pcilib_view_t view;
pcilib_view_context_t *view_ctx;
pcilib_unit_transform_t *trans = NULL;
@@ -199,9 +217,9 @@ static int pcilib_detect_view_configuration(pcilib_t *ctx, const char *bank, con
// get value
if (unit_name) view_ctx = pcilib_find_register_view_context_by_name(ctx, reg, view_name);
- else view_ctx = pcilib_find_register_view_context(ctx, reg, view_name);
+ else err = pcilib_detect_register_view_and_unit(ctx, reg, view_name, &view_ctx, &trans);
- if (!view_ctx) {
+ if ((err)||(!view_ctx)) {
pcilib_error("Can't find the specified view %s for register %s", view_name, regname);
return PCILIB_ERROR_NOTFOUND;
}
@@ -222,10 +240,11 @@ static int pcilib_detect_view_configuration(pcilib_t *ctx, const char *bank, con
pcilib_error("Don't know how to get the requested unit %s for view %s", unit_name, ctx->views[view]->name);
return PCILIB_ERROR_NOTFOUND;
}
- // No transform is required
- if (!trans->transform) trans = NULL;
}
+ // No transform is required
+ if (!trans->transform) trans = NULL;
+
cfg->reg = reg;
cfg->view = view_ctx;
cfg->trans = trans;