summaryrefslogtreecommitdiffstats
path: root/pcilib
diff options
context:
space:
mode:
Diffstat (limited to 'pcilib')
-rw-r--r--pcilib/debug.h10
-rw-r--r--pcilib/env.h1
-rw-r--r--pcilib/py.c2
-rw-r--r--pcilib/value.c16
-rw-r--r--pcilib/view.c15
5 files changed, 34 insertions, 10 deletions
diff --git a/pcilib/debug.h b/pcilib/debug.h
index bc68e1c..3ac0828 100644
--- a/pcilib/debug.h
+++ b/pcilib/debug.h
@@ -3,12 +3,14 @@
#include <stdarg.h>
#include <pcilib/env.h>
+#include <pcilib/error.h>
#define PCILIB_DEBUG
#ifdef PCILIB_DEBUG
# define PCILIB_DEBUG_DMA
# define PCILIB_DEBUG_MISSING_EVENTS
+# define PCILIB_DEBUG_VIEWS
#endif /* PCILIB_DEBUG */
@@ -28,6 +30,14 @@
# define PCILIB_DEBUG_MISSING_EVENTS_BUFFER(function, ...)
#endif /* PCILIB_DEBUG_MISSING_EVENTS */
+#ifdef PCILIB_DEBUG_VIEWS
+# define PCILIB_DEBUG_VIEWS_MESSAGE(function, ...) if (pcilib_getenv(function##_ENV, #function)) { pcilib_debug_message (#function, __FILE__, __LINE__, __VA_ARGS__); }
+# define PCILIB_DEBUG_VIEWS_BUFFER(function, ...) if (pcilib_getenv(function##_ENV #function)) { pcilib_debug_data_buffer (#function, __VA_ARGS__); }
+#else /* PCILIB_DEBUG_VIEWS */
+# define PCILIB_DEBUG_VIEWS_MESSAGE(function, ...)
+# define PCILIB_DEBUG_VIEWS_BUFFER(function, ...)
+#endif /* PCILIB_DEBUG_VIEWS */
+
#define pcilib_debug(function, ...) \
PCILIB_DEBUG_##function##_MESSAGE(PCILIB_DEBUG_##function, PCILIB_LOG_DEFAULT, __VA_ARGS__)
diff --git a/pcilib/env.h b/pcilib/env.h
index 7cf69b9..880e711 100644
--- a/pcilib/env.h
+++ b/pcilib/env.h
@@ -4,6 +4,7 @@
typedef enum {
PCILIB_DEBUG_DMA_ENV,
PCILIB_DEBUG_MISSING_EVENTS_ENV,
+ PCILIB_DEBUG_VIEWS_ENV,
PCILIB_MAX_ENV
} pcilib_env_t;
diff --git a/pcilib/py.c b/pcilib/py.c
index 6aaa22f..3a4fd96 100644
--- a/pcilib/py.c
+++ b/pcilib/py.c
@@ -7,6 +7,7 @@
#include "pci.h"
+#include "debug.h"
#include "pcilib.h"
#include "py.h"
#include "error.h"
@@ -167,5 +168,6 @@ int pcilib_py_eval_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *va
return PCILIB_ERROR_FAILED;
}
+ pcilib_debug(VIEWS, "Evaluating a Python string \'%s\' to %lf=\'%s\'", codestr, PyFloat_AsDouble(obj), code);
return pcilib_set_value_from_float(ctx, value, PyFloat_AsDouble(obj));
}
diff --git a/pcilib/value.c b/pcilib/value.c
index 1a8cc45..42e7993 100644
--- a/pcilib/value.c
+++ b/pcilib/value.c
@@ -8,6 +8,7 @@
#include "value.h"
#include "error.h"
#include "unit.h"
+#include "tools.h"
void pcilib_clean_value(pcilib_t *ctx, pcilib_value_t *val) {
if (!val) return;
@@ -235,11 +236,22 @@ int pcilib_convert_value_type(pcilib_t *ctx, pcilib_value_t *val, pcilib_value_t
case PCILIB_TYPE_LONG:
switch (val->type) {
case PCILIB_TYPE_STRING:
- if (sscanf(val->sval, "%li", &val->ival) != 1) {
+ if (pcilib_isnumber(val->sval)) {
+ if (sscanf(val->sval, "%li", &val->ival) != 1) {
+ pcilib_warning("Can't convert string (%s) to int", val->sval);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ val->format = NULL;
+ } else if (pcilib_isxnumber(val->sval)) {
+ if (sscanf(val->sval, "%lx", &val->ival) != 1) {
+ pcilib_warning("Can't convert string (%s) to int", val->sval);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ val->format = "0x%lx";
+ } else {
pcilib_warning("Can't convert string (%s) to int", val->sval);
return PCILIB_ERROR_INVALID_DATA;
}
- val->format = NULL;
break;
case PCILIB_TYPE_DOUBLE:
val->ival = round(val->fval);
diff --git a/pcilib/view.c b/pcilib/view.c
index c1ad44a..f00e483 100644
--- a/pcilib/view.c
+++ b/pcilib/view.c
@@ -135,7 +135,7 @@ 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
-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) {
+static int pcilib_detect_register_view_and_unit(pcilib_t *ctx, pcilib_register_t reg, const char *name, int write_direction, 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;
@@ -160,7 +160,10 @@ static int pcilib_detect_register_view_and_unit(pcilib_t *ctx, pcilib_register_t
view_desc = ctx->views[view_ctx->view];
if (view_desc->unit) {
- trans = pcilib_find_transform_by_unit_names(ctx, view_desc->unit, name);
+ if (write_direction)
+ trans = pcilib_find_transform_by_unit_names(ctx, name, view_desc->unit);
+ else
+ trans = pcilib_find_transform_by_unit_names(ctx, view_desc->unit, name);
if (trans) {
if (ret_trans) *ret_trans = trans;
if (ret_view) *ret_view = pcilib_find_view_context_by_name(ctx, view_desc->name);
@@ -176,7 +179,7 @@ pcilib_view_context_t *pcilib_find_register_view_context(pcilib_t *ctx, pcilib_r
int err;
pcilib_view_context_t *view;
- err = pcilib_detect_register_view_and_unit(ctx, reg, name, &view, NULL);
+ err = pcilib_detect_register_view_and_unit(ctx, reg, name, 0, &view, NULL);
if (err) return NULL;
return view;
@@ -214,10 +217,8 @@ static int pcilib_detect_view_configuration(pcilib_t *ctx, const char *bank, con
return PCILIB_ERROR_NOTFOUND;
}
- // get value
-
if (unit_name) view_ctx = pcilib_find_register_view_context_by_name(ctx, reg, view_name);
- else err = pcilib_detect_register_view_and_unit(ctx, reg, view_name, &view_ctx, &trans);
+ else err = pcilib_detect_register_view_and_unit(ctx, reg, view_name, write_direction, &view_ctx, &trans);
if ((err)||(!view_ctx)) {
pcilib_error("Can't find the specified view %s for register %s", view_name, regname);
@@ -330,7 +331,6 @@ int pcilib_write_register_view(pcilib_t *ctx, const char *bank, const char *regn
if (err) return err;
}
-
err = v->api->write_to_reg(ctx, cfg.view, &regvalue, &val);
if (err) {
if (regname)
@@ -340,7 +340,6 @@ int pcilib_write_register_view(pcilib_t *ctx, const char *bank, const char *regn
return err;
}
-
if (regname) {
err = pcilib_write_register_by_id(ctx, cfg.reg, regvalue);
if (err) {