summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
Diffstat (limited to 'views')
-rw-r--r--views/transform.c128
-rw-r--r--views/transform.h3
2 files changed, 59 insertions, 72 deletions
diff --git a/views/transform.c b/views/transform.c
index 02edddf..7906743 100644
--- a/views/transform.c
+++ b/views/transform.c
@@ -10,92 +10,80 @@
#include "transform.h"
#include "py.h"
#include "error.h"
+#include "pci.h"
-static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t regval, pcilib_value_t *val) {
- const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
- pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(model_info->views[view_ctx->view]);
+static pcilib_view_context_t * pcilib_transform_view_init(pcilib_t *ctx, pcilib_view_t view) {
+ int err;
- int err;
+ pcilib_view_context_t *view_ctx;
+ pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(ctx->views[view]);
- err = pcilib_set_value_from_register_value(ctx, val, regval);
- if (err) return err;
+ if(v->script) {
+ pcilib_access_mode_t mode = 0;
+
+ err = pcilib_py_load_script(ctx, v->script);
+ if(err) {
+ pcilib_error("Error (%i), loading script %s", err, v->script);
+ return NULL;
+ }
+
+ err = pcilib_py_get_transform_script_properties(ctx, v->script, &mode);
+ if(err) {
+ pcilib_error("Error (%i) obtaining properties of transform script %s", err, v->script);
+ return NULL;
+ }
- if(v->module)
- return err = pcilib_script_run_func(ctx, v->module,
- "read_from_register", val);
- else
- return pcilib_py_eval_string(ctx, v->read_from_reg, val);
-}
+ if ((v->base.mode&PCILIB_REGISTER_RW) == 0)
+ v->base.mode |= PCILIB_REGISTER_RW;
+ v->base.mode &= (~PCILIB_REGISTER_RW)|mode;
-static int pcilib_transform_view_write(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t *regval, const pcilib_value_t *val) {
+ if (!v->read_from_reg) v->read_from_reg = "read_from_register";
+ if (!v->write_to_reg) v->write_to_reg = "write_to_register";
+ }
+ view_ctx = (pcilib_view_context_t*)malloc(sizeof(pcilib_view_context_t));
+ if (view_ctx) memset(view_ctx, 0, sizeof(pcilib_view_context_t));
+
+ return view_ctx;
+}
+
+static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t regval, pcilib_value_t *val) {
+ int err;
+
const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(model_info->views[view_ctx->view]);
- int err = 0;
-
- pcilib_value_t val_copy = {0};
- err = pcilib_copy_value(ctx, &val_copy, val);
- if (err) return err;
+ err = pcilib_set_value_from_register_value(ctx, val, regval);
+ if (err) return err;
+ if (v->script)
+ err = pcilib_py_eval_func(ctx, v->script, v->read_from_reg, val);
+ else
+ err = pcilib_py_eval_string(ctx, v->read_from_reg, val);
- if(v->module)
- err = pcilib_script_run_func(ctx, v->module,
- "write_to_register", &val_copy);
- else
- err = pcilib_py_eval_string(ctx, v->write_to_reg, &val_copy);
-
- if (err) return err;
-
- *regval = pcilib_get_value_as_register_value(ctx, &val_copy, &err);
- return err;
+ return err;
}
-void pcilib_transform_view_free_description (pcilib_t *ctx, pcilib_view_description_t *view)
-{
- pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(view);
-
- if(v->module)
- pcilib_py_free_script(ctx, v->module);
-
- free(v);
-}
+static int pcilib_transform_view_write(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t *regval, const pcilib_value_t *val) {
+ int err = 0;
+ pcilib_value_t val_copy = {0};
-pcilib_view_context_t * pcilib_transform_view_init(pcilib_t *ctx, const pcilib_view_description_t *desc)
-{
- pcilib_transform_view_description_t *v_desc = (pcilib_transform_view_description_t*)desc;
-
- if(v_desc->module)
- {
- pcilib_access_mode_t mode = 0;
-
- int err = pcilib_py_init_script(ctx, v_desc->module);
- if(err)
- {
- pcilib_error("Failed init script module (%s) - error %i",
- v_desc->module, err);
- return NULL;
- }
- err = pcilib_py_get_transform_script_properties(ctx, v_desc->module,
- &mode);
- if(err)
- {
- pcilib_error("Failed get transform script properties (%s) - error %i",
- v_desc->module, err);
- return NULL;
- }
+ const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
+ pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(model_info->views[view_ctx->view]);
+
+ err = pcilib_copy_value(ctx, &val_copy, val);
+ if (err) return err;
+
+ if (v->script)
+ err = pcilib_py_eval_func(ctx, v->script, v->write_to_reg, &val_copy);
+ else
+ err = pcilib_py_eval_string(ctx, v->write_to_reg, &val_copy);
- v_desc->base.mode |= PCILIB_REGISTER_RW;
- mode |= PCILIB_REGISTER_INCONSISTENT;
- v_desc->base.mode &= mode;
- }
+ if (err) return err;
- pcilib_view_context_t *view_ctx;
- view_ctx = (pcilib_view_context_t*)malloc(sizeof(pcilib_view_context_t));
- if (view_ctx) memset(view_ctx, 0, sizeof(pcilib_view_context_t));
-
- return view_ctx;
+ *regval = pcilib_get_value_as_register_value(ctx, &val_copy, &err);
+ return err;
}
const pcilib_view_api_description_t pcilib_transform_view_api =
- { PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), pcilib_transform_view_init, NULL, pcilib_transform_view_free_description, pcilib_transform_view_read, pcilib_transform_view_write };
+ { PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), pcilib_transform_view_init, NULL, NULL, pcilib_transform_view_read, pcilib_transform_view_write };
diff --git a/views/transform.h b/views/transform.h
index 8c9321d..774a019 100644
--- a/views/transform.h
+++ b/views/transform.h
@@ -3,13 +3,12 @@
#include <pcilib.h>
#include <pcilib/view.h>
-#include <py.h>
typedef struct {
pcilib_view_description_t base;
+ const char *script; /**< Python script module name */
const char *read_from_reg; /**< Formula explaining how to convert the register value to the view value */
const char *write_to_reg; /**< Formula explaining how to convert from the view value to the register value */
- const char *module; /**< Python script module name (without extension) */
} pcilib_transform_view_description_t;
#ifndef _PCILIB_VIEW_TRANSFORM_C