summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pcilib/CMakeLists.txt4
-rw-r--r--pcilib/pci.h2
-rw-r--r--pcilib/unit.c34
-rw-r--r--pcilib/unit.h32
-rw-r--r--pcilib/views.c56
-rw-r--r--pcilib/views.h35
-rw-r--r--pcilib/xml.c24
7 files changed, 88 insertions, 99 deletions
diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt
index 1f3e646..9688065 100644
--- a/pcilib/CMakeLists.txt
+++ b/pcilib/CMakeLists.txt
@@ -9,9 +9,9 @@ include_directories(
set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h
views.h xml.h kmem.h irq.h locking.h lock.h dma.h event.h plugin.h tools.h error.h
-debug.h env.h version.h config.h unit.h)
+debug.h env.h version.h config.h)
add_library(pcilib SHARED pci.c export.c bar.c fifo.c model.c bank.c
-register.c views.c xml.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c unit.c)
+register.c views.c xml.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c)
target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT}
${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${EXTRA_SYSTEM_LIBS}
${LIBXML2_LIBRARIES} ${PYTHON_LIBRARIES})
diff --git a/pcilib/pci.h b/pcilib/pci.h
index 8805fc2..f364890 100644
--- a/pcilib/pci.h
+++ b/pcilib/pci.h
@@ -28,7 +28,7 @@
#include "export.h"
#include "locking.h"
#include "xml.h"
-#include "unit.h"
+#include "views.h"
typedef struct {
uint8_t max_link_speed, link_speed;
diff --git a/pcilib/unit.c b/pcilib/unit.c
deleted file mode 100644
index a9766ed..0000000
--- a/pcilib/unit.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "pcilib.h"
-#include "pci.h"
-#include "stdio.h"
-#include <string.h>
-#include "error.h"
-#include "unit.h"
-
-int pcilib_add_units(pcilib_t *ctx, size_t n, const pcilib_unit_t* units) {
-
- pcilib_unit_t *units2;
- size_t size;
-
- if (!n) {
- for (n = 0; units[n].name[0]; n++);
- }
-
- if ((ctx->num_units + n + 1) > ctx->alloc_units) {
- for (size = ctx->alloc_units; size < 2 * (n + ctx->num_units + 1); size<<=1);
-
- units2 = (pcilib_unit_t*)realloc(ctx->units, size * sizeof(pcilib_unit_t));
- if (!units2) return PCILIB_ERROR_MEMORY;
-
- ctx->units = units2;
- ctx->alloc_units = size;
- }
-
- memcpy(ctx->units + ctx->num_units, units, n * sizeof(pcilib_unit_t));
- memset(ctx->units + ctx->num_units + n, 0, sizeof(pcilib_unit_t));
-
- ctx->num_units += n;
-
- return 0;
-}
-
diff --git a/pcilib/unit.h b/pcilib/unit.h
deleted file mode 100644
index 4a99f5b..0000000
--- a/pcilib/unit.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef _PCILIB_UNITS_H
-#define _PCILIB_UNITS_H
-
-#include "pcilib.h"
-
-#define PCILIB_MAX_TRANSFORMS_PER_UNIT 16
-
-typedef struct pcilib_unit_s pcilib_unit_t;
-typedef struct pcilib_transform_unit_s pcilib_transform_unit_t;
-
-/**
- * type to save a transformation unit in the pcitool program
- */
-struct pcilib_transform_unit_s{
- char *name;
- char *transform_formula;
-};
-
-/**
- * type to save a unit in the pcitool programm
- */
-struct pcilib_unit_s{
- char* name;
- pcilib_transform_unit_t other_units[PCILIB_MAX_TRANSFORMS_PER_UNIT];
-};
-
-/**
- * function to populate the ctx with units
- */
-int pcilib_add_units(pcilib_t* ctx, size_t n, const pcilib_unit_t* units);
-
-#endif
diff --git a/pcilib/views.c b/pcilib/views.c
index d0116db..9fe8810 100644
--- a/pcilib/views.c
+++ b/pcilib/views.c
@@ -6,7 +6,6 @@
#include "error.h"
#include <strings.h>
#include <stdlib.h>
-#include "unit.h"
/**
* this function calls the python script and the function "evaluate" in it to evaluate the given formula
@@ -209,18 +208,18 @@ int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, cons
int operation_enum(pcilib_t *ctx, void *params, char* name, int view2reg, pcilib_register_value_t *regval, size_t viewval_size, void* viewval){
int j,k;
if(view2reg==1){
- for(j=0; ((pcilib_view_enum_t*)(params))[j].name;j++){
- if(!(strcasecmp(((pcilib_view_enum_t*)(params))[j].name,name))){
- *regval=((pcilib_view_enum_t*)(params))[j].value;
+ for(j=0; ((pcilib_enum_t*)(params))[j].name;j++){
+ if(!(strcasecmp(((pcilib_enum_t*)(params))[j].name,name))){
+ *regval=((pcilib_enum_t*)(params))[j].value;
return 0;
}
}
}else if (view2reg==0){
- for(j=0; ((pcilib_view_enum_t*)(params))[j].name;j++){
- if (*regval<((pcilib_view_enum_t*)(params))[j].max && *regval>((pcilib_view_enum_t*)(params))[j].min){
- name=(char*)realloc(name,strlen(((pcilib_view_enum_t*)(params))[j].name)*sizeof(char));
- strncpy(name,((pcilib_view_enum_t*)(params))[j].name, strlen(((pcilib_view_enum_t*)(params))[j].name));
- k=strlen(((pcilib_view_enum_t*)(params))[j].name);
+ for(j=0; ((pcilib_enum_t*)(params))[j].name;j++){
+ if (*regval<((pcilib_enum_t*)(params))[j].max && *regval>((pcilib_enum_t*)(params))[j].min){
+ name=(char*)realloc(name,strlen(((pcilib_enum_t*)(params))[j].name)*sizeof(char));
+ strncpy(name,((pcilib_enum_t*)(params))[j].name, strlen(((pcilib_enum_t*)(params))[j].name));
+ k=strlen(((pcilib_enum_t*)(params))[j].name);
name[k]='\0';
return 0;
}
@@ -249,8 +248,8 @@ int operation_formula(pcilib_t *ctx, void *params, char* unit, int view2reg, pci
return 0;
}
- for(j=0; ((pcilib_view_t*)viewval)->base_unit.other_units[j].name;j++){
- if(!(strcasecmp(((pcilib_view_t*)viewval)->base_unit.other_units[j].name,unit))){
+ for(j=0; ((pcilib_view_t*)viewval)->base_unit.transforms[j].name;j++){
+ if(!(strcasecmp(((pcilib_view_t*)viewval)->base_unit.transforms[j].name,unit))){
/* when we have found the correct view of type formula, we apply the formula, that get the good value for return*/
formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->read_formula));
if(!(formula)){
@@ -259,7 +258,7 @@ int operation_formula(pcilib_t *ctx, void *params, char* unit, int view2reg, pci
}
strncpy(formula,((pcilib_formula_t*)params)->read_formula,strlen(((pcilib_formula_t*)params)->read_formula));
pcilib_view_apply_formula(ctx,formula, regval);
- pcilib_view_apply_unit(((pcilib_view_t*)viewval)->base_unit.other_units[j],unit,&value);
+ pcilib_view_apply_unit(((pcilib_view_t*)viewval)->base_unit.transforms[j],unit,&value);
return 0;
}
}
@@ -271,12 +270,12 @@ int operation_formula(pcilib_t *ctx, void *params, char* unit, int view2reg, pci
return 0;
}
- for(j=0;((pcilib_view_t*)viewval)->base_unit.other_units[j].name;j++){
- if(!(strcasecmp(((pcilib_view_t*)viewval)->base_unit.other_units[j].name,unit))){
+ for(j=0;((pcilib_view_t*)viewval)->base_unit.transforms[j].name;j++){
+ if(!(strcasecmp(((pcilib_view_t*)viewval)->base_unit.transforms[j].name,unit))){
/* when we have found the correct view of type formula, we apply the formula, that get the good value for return*/
formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->write_formula));
strncpy(formula,((pcilib_formula_t*)params)->write_formula,strlen((( pcilib_formula_t*)params)->write_formula));
- pcilib_view_apply_unit(((pcilib_view_t*)viewval)->base_unit.other_units[j],unit,&value);
+ pcilib_view_apply_unit(((pcilib_view_t*)viewval)->base_unit.transforms[j],unit,&value);
pcilib_view_apply_formula(ctx,formula,regval);
/* we maybe need some error checking there , like temp_value >min and <max*/
return 0;
@@ -316,3 +315,30 @@ int pcilib_add_views(pcilib_t *ctx, size_t n, const pcilib_view_t* views) {
ctx->num_views += n;
return 0;
}
+
+int pcilib_add_units(pcilib_t *ctx, size_t n, const pcilib_unit_t* units) {
+
+ pcilib_unit_t *units2;
+ size_t size;
+
+ if (!n) {
+ for (n = 0; units[n].name[0]; n++);
+ }
+
+ if ((ctx->num_units + n + 1) > ctx->alloc_units) {
+ for (size = ctx->alloc_units; size < 2 * (n + ctx->num_units + 1); size<<=1);
+
+ units2 = (pcilib_unit_t*)realloc(ctx->units, size * sizeof(pcilib_unit_t));
+ if (!units2) return PCILIB_ERROR_MEMORY;
+
+ ctx->units = units2;
+ ctx->alloc_units = size;
+ }
+
+ memcpy(ctx->units + ctx->num_units, units, n * sizeof(pcilib_unit_t));
+ memset(ctx->units + ctx->num_units + n, 0, sizeof(pcilib_unit_t));
+
+ ctx->num_units += n;
+
+ return 0;
+}
diff --git a/pcilib/views.h b/pcilib/views.h
index ae92d0d..c44393d 100644
--- a/pcilib/views.h
+++ b/pcilib/views.h
@@ -2,9 +2,14 @@
#define _PCILIB_VIEWS_H
#include "pcilib.h"
-#include "unit.h"
-typedef struct pcilib_view_enum_s pcilib_view_enum_t;
+#define PCILIB_MAX_TRANSFORMS_PER_UNIT 16
+
+typedef struct pcilib_transform_unit_s pcilib_transform_unit_t;
+
+typedef struct pcilib_unit_s pcilib_unit_t;
+
+typedef struct pcilib_enum_s pcilib_enum_t;
typedef struct pcilib_view_s pcilib_view_t;
@@ -13,9 +18,25 @@ typedef struct pcilib_formula_s pcilib_formula_t;
typedef int (*pcilib_view_operation_t)(pcilib_t *ctx, void *params, char* string, int read_or_write, pcilib_register_value_t *regval, size_t viewval_size, void* viewval);
/**
+ * type to save a transformation unit in the pcitool program
+ */
+struct pcilib_transform_unit_s{
+ char *name;
+ char *transform_formula;
+};
+
+/**
+ * type to save a unit in the pcitool programm
+ */
+struct pcilib_unit_s{
+ char* name;
+ pcilib_transform_unit_t transforms[PCILIB_MAX_TRANSFORMS_PER_UNIT];
+};
+
+/**
* new type to define an enum view
*/
-struct pcilib_view_enum_s {
+struct pcilib_enum_s {
const char *name; /**<corresponding string to value*/
pcilib_register_value_t value, min, max;
};
@@ -49,4 +70,12 @@ int operation_formula(pcilib_t *ctx, void *params, char* unit, int view2reg, pci
int pcilib_add_views(pcilib_t *ctx, size_t n, const pcilib_view_t* views);
+
+/**
+ * function to populate the ctx with units
+ */
+int pcilib_add_units(pcilib_t* ctx, size_t n, const pcilib_unit_t* units);
+
+
+
#endif
diff --git a/pcilib/xml.c b/pcilib/xml.c
index 5be5abd..ebef91e 100644
--- a/pcilib/xml.c
+++ b/pcilib/xml.c
@@ -126,10 +126,10 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP
for (i = 0; i < nodeset->nodeNr; i++) {
view_name=(char*)nodeset->nodeTab[i]->children->content;
- /* if the view name obtained is for an enum view, we get all pcilib_view_enum_t corresponding to the register*/
+ /* if the view name obtained is for an enum view, we get all pcilib_enum_t corresponding to the register*/
for(k=0; ctx->views[k].name; k++){
if(!(strcasecmp(view_name, ctx->views[k].name))){
- ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(k+1)*sizeof(pcilib_view_enum_t));
+ ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(k+1)*sizeof(pcilib_enum_t));
ctx->register_ctx[id].views[k]=ctx->views[k];
}
}
@@ -520,8 +520,8 @@ pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, x
if (!value || !attr) continue;
if (!strcasecmp(name, "convert_unit")) {
- desc.other_units[i].name=value2;
- desc.other_units[i].transform_formula=value;
+ desc.transforms[i].name=value2;
+ desc.transforms[i].transform_formula=value;
i++;
}
}
@@ -558,7 +558,7 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo
/*if the view is of type enum, we get recursively its properties and then populate ctx enum views*/
if(!(strcasecmp(value,"enum"))){
desc.op=&operation_enum;
- desc.parameters=malloc(sizeof(pcilib_view_enum_t));
+ desc.parameters=malloc(sizeof(pcilib_enum_t));
desc.base_unit.name="name";
for (cur = node->children; cur != NULL; cur = cur->next) {
if (!cur->children) continue;
@@ -576,8 +576,8 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo
}else if (!(strcasecmp((char*)name,"enum"))) {
- desc.parameters=realloc(desc.parameters,(i+1)*sizeof(pcilib_view_enum_t));
- ((pcilib_view_enum_t*)(desc.parameters))[i].name=value;
+ desc.parameters=realloc(desc.parameters,(i+1)*sizeof(pcilib_enum_t));
+ ((pcilib_enum_t*)(desc.parameters))[i].name=value;
/* we need to iterate through the different attributes of an enum node to get all properties*/
for(attr=cur->properties; attr!=NULL;attr=attr->next){
@@ -593,14 +593,14 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo
pcilib_error("Invalid value (%s) is specified in the XML enum node", value);
return PCILIB_ERROR_INVALID_DATA;
}
- ((pcilib_view_enum_t*)(desc.parameters))[i].value=dat_value;
+ ((pcilib_enum_t*)(desc.parameters))[i].value=dat_value;
}else if(!(strcasecmp(name,"min"))){
pcilib_register_value_t dat_min = strtol(value, &endptr, 0);
if ((strlen(endptr) > 0)) {
pcilib_error("Invalid min (%s) is specified in the XML enum node", value);
return PCILIB_ERROR_INVALID_DATA;
}
- ((pcilib_view_enum_t*)(desc.parameters))[i].min=dat_min;
+ ((pcilib_enum_t*)(desc.parameters))[i].min=dat_min;
ok_min=1;
}else if(!(strcasecmp(name,"max"))){
pcilib_register_value_t dat_max = strtol(value, &endptr, 0);
@@ -608,11 +608,11 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo
pcilib_error("Invalid max (%s) is specified in the XML enum node", value);
return PCILIB_ERROR_INVALID_DATA;
}
- ((pcilib_view_enum_t*)(desc.parameters))[i].max=dat_max;
+ ((pcilib_enum_t*)(desc.parameters))[i].max=dat_max;
ok_max=1;
}
- if(ok_min==0) ((pcilib_view_enum_t*)(desc.parameters))[i].min=((pcilib_view_enum_t*)(desc.parameters))[i].value;
- if(ok_max==0) ((pcilib_view_enum_t*)(desc.parameters))[i].max=((pcilib_view_enum_t*)(desc.parameters))[i].value;
+ if(ok_min==0) ((pcilib_enum_t*)(desc.parameters))[i].min=((pcilib_enum_t*)(desc.parameters))[i].value;
+ if(ok_max==0) ((pcilib_enum_t*)(desc.parameters))[i].max=((pcilib_enum_t*)(desc.parameters))[i].value;
}
i++;