summaryrefslogtreecommitdiffstats
path: root/pcilib
diff options
context:
space:
mode:
Diffstat (limited to 'pcilib')
-rw-r--r--pcilib/pci.h11
-rw-r--r--pcilib/pcilib.h3
-rw-r--r--pcilib/unit.h8
-rw-r--r--pcilib/value.c16
-rw-r--r--pcilib/view.c6
-rw-r--r--pcilib/view.h10
-rw-r--r--pcilib/xml.c3
7 files changed, 37 insertions, 20 deletions
diff --git a/pcilib/pci.h b/pcilib/pci.h
index ff18e52..caefe44 100644
--- a/pcilib/pci.h
+++ b/pcilib/pci.h
@@ -39,17 +39,6 @@ typedef struct {
uint8_t max_payload, payload;
} pcilib_pcie_link_info_t;
-struct pcilib_view_context_s {
- const char *name;
- pcilib_view_t view;
- UT_hash_handle hh;
-};
-
-struct pcilib_unit_context_s {
- const char *name;
- pcilib_unit_t unit;
- UT_hash_handle hh;
-};
typedef struct {
const char *name; /**< Register name */
diff --git a/pcilib/pcilib.h b/pcilib/pcilib.h
index 3909ab4..6acceb6 100644
--- a/pcilib/pcilib.h
+++ b/pcilib/pcilib.h
@@ -112,7 +112,7 @@ typedef struct {
union {
long ival;
double fval;
- char *sval;
+ const char *sval;
};
// This is a private part
@@ -223,6 +223,7 @@ 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_static_string(pcilib_t *ctx, pcilib_value_t *value, const char *str);
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/unit.h b/pcilib/unit.h
index dad7962..3e49174 100644
--- a/pcilib/unit.h
+++ b/pcilib/unit.h
@@ -1,6 +1,8 @@
#ifndef _PCILIB_UNIT_H
#define _PCILIB_UNIT_H
+#include <uthash.h>
+
#include <pcilib.h>
#define PCILIB_UNIT_INVALID ((pcilib_unit_t)-1)
@@ -23,6 +25,12 @@ typedef struct {
pcilib_unit_transform_t transforms[PCILIB_MAX_TRANSFORMS_PER_UNIT + 1]; /**< Transforms to other units */
} pcilib_unit_description_t;
+struct pcilib_unit_context_s {
+ const char *name;
+ pcilib_unit_t unit;
+ UT_hash_handle hh;
+};
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/pcilib/value.c b/pcilib/value.c
index cbf347b..b039e5f 100644
--- a/pcilib/value.c
+++ b/pcilib/value.c
@@ -57,6 +57,16 @@ int pcilib_set_value_from_int(pcilib_t *ctx, pcilib_value_t *value, long ival) {
return 0;
}
+int pcilib_set_value_from_static_string(pcilib_t *ctx, pcilib_value_t *value, const char *str) {
+ pcilib_clean_value(ctx, value);
+
+ value->type = PCILIB_TYPE_STRING;
+ value->sval = str;
+
+ return 0;
+}
+
+
/*
double pcilib_value_get_float(pcilib_value_t *val) {
pcilib_value_t copy;
@@ -108,7 +118,7 @@ int pcilib_convert_value_type(pcilib_t *ctx, pcilib_value_t *val, pcilib_value_t
case PCILIB_TYPE_STRING:
switch (val->type) {
case PCILIB_TYPE_STRING:
- break;
+ return 0;
case PCILIB_TYPE_DOUBLE:
sprintf(val->str, (val->format?val->format:"%lf"), val->fval);
val->format = NULL;
@@ -132,7 +142,7 @@ int pcilib_convert_value_type(pcilib_t *ctx, pcilib_value_t *val, pcilib_value_t
val->format = NULL;
break;
case PCILIB_TYPE_DOUBLE:
- break;
+ return 0;
case PCILIB_TYPE_LONG:
val->fval = val->ival;
val->format = NULL;
@@ -155,7 +165,7 @@ int pcilib_convert_value_type(pcilib_t *ctx, pcilib_value_t *val, pcilib_value_t
val->format = NULL;
break;
case PCILIB_TYPE_LONG:
- break;
+ return 0;
default:
return PCILIB_ERROR_NOTSUPPORTED;
}
diff --git a/pcilib/view.c b/pcilib/view.c
index bf312e4..e9fdab5 100644
--- a/pcilib/view.c
+++ b/pcilib/view.c
@@ -126,7 +126,7 @@ pcilib_view_context_t *pcilib_find_register_view_context_by_name(pcilib_t *ctx,
if (!regctx->views) return NULL;
for (i = 0; regctx->views[i].name; i++) {
- if (strcasecmp(name, regctx->views[i].name)) {
+ if (!strcasecmp(name, regctx->views[i].name)) {
return pcilib_find_view_context_by_name(ctx, regctx->views[i].view);
}
}
@@ -261,7 +261,7 @@ int pcilib_read_register_view(pcilib_t *ctx, const char *bank, const char *regna
pcilib_clean_value(ctx, val);
- err = v->api->read_from_reg(ctx, cfg.view, &regvalue, val);
+ err = v->api->read_from_reg(ctx, cfg.view, regvalue, val);
if (err) {
if (regname)
pcilib_error("Error (%i) computing view (%s) of register %s", err, view, regname);
@@ -281,7 +281,7 @@ int pcilib_read_register_view(pcilib_t *ctx, const char *bank, const char *regna
int pcilib_write_register_view(pcilib_t *ctx, const char *bank, const char *regname, const char *view, const pcilib_value_t *valarg) {
int err;
- pcilib_value_t val;
+ pcilib_value_t val = {0};
pcilib_view_description_t *v;
pcilib_view_configuration_t cfg;
diff --git a/pcilib/view.h b/pcilib/view.h
index 4af4c00..9d3d32d 100644
--- a/pcilib/view.h
+++ b/pcilib/view.h
@@ -1,6 +1,8 @@
#ifndef _PCILIB_VIEW_H
#define _PCILIB_VIEW_H
+#include <uthash.h>
+
#include <pcilib.h>
#include <pcilib/unit.h>
@@ -19,7 +21,7 @@ typedef struct {
pcilib_view_context_t *(*init)(pcilib_t *ctx);
void (*free)(pcilib_t *ctx, pcilib_view_context_t *view);
void (*free_description)(pcilib_t *ctx, pcilib_view_description_t *view);
- int (*read_from_reg)(pcilib_t *ctx, pcilib_view_context_t *view, const pcilib_register_value_t *regval, pcilib_value_t *val);
+ int (*read_from_reg)(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t regval, pcilib_value_t *val);
int (*write_to_reg)(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t *regval, const pcilib_value_t *val);
} pcilib_view_api_description_t;
@@ -32,6 +34,12 @@ struct pcilib_view_description_s {
const char *description; /**< Short description */
};
+struct pcilib_view_context_s {
+ const char *name;
+ pcilib_view_t view;
+ UT_hash_handle hh;
+};
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/pcilib/xml.c b/pcilib/xml.c
index c431b73..25ffbfe 100644
--- a/pcilib/xml.c
+++ b/pcilib/xml.c
@@ -516,7 +516,7 @@ static int pcilib_xml_create_transform_view(pcilib_t *ctx, xmlXPathContextPtr xp
pcilib_transform_view_description_t desc = {0};
- desc.base.api = &pcilib_enum_view_xml_api;
+ desc.base.api = &pcilib_transform_view_api;
err = pcilib_xml_parse_view(ctx, xpath, doc, node, (pcilib_view_description_t*)&desc);
if (err) return err;
@@ -1037,6 +1037,7 @@ void pcilib_free_xml(pcilib_t *ctx) {
xmlFreeParserCtxt(ctx->xml.parser);
ctx->xml.parser = NULL;
}
+
/*
xmlSchemaCleanupTypes();
xmlCleanupParser();