diff options
author | nicolas.zilio@hotmail.fr <> | 2015-09-15 11:45:37 +0200 |
---|---|---|
committer | nicolas.zilio@hotmail.fr <> | 2015-09-15 11:45:37 +0200 |
commit | 6c47064466d8484813741f347e41af1d4ac90f85 (patch) | |
tree | c5b2ff848825c8a4395ca17350c5e85569097c91 /pcilib | |
parent | c71075ca84d896c650dd0b65c7664149ed51dcec (diff) | |
download | pcitool-6c47064466d8484813741f347e41af1d4ac90f85.tar.gz pcitool-6c47064466d8484813741f347e41af1d4ac90f85.tar.bz2 pcitool-6c47064466d8484813741f347e41af1d4ac90f85.tar.xz pcitool-6c47064466d8484813741f347e41af1d4ac90f85.zip |
cleaning
Diffstat (limited to 'pcilib')
-rw-r--r-- | pcilib/pci.c | 8 | ||||
-rw-r--r-- | pcilib/pci.h | 5 | ||||
-rw-r--r-- | pcilib/register.h | 8 | ||||
-rw-r--r-- | pcilib/views.c | 107 | ||||
-rw-r--r-- | pcilib/views.h | 30 |
5 files changed, 5 insertions, 153 deletions
diff --git a/pcilib/pci.c b/pcilib/pci.c index 946b003..b37e817 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -139,13 +139,9 @@ pcilib_t *pcilib_open(const char *device, const char *model) { } ctx->alloc_reg = PCILIB_DEFAULT_REGISTER_SPACE; - ctx->alloc_formula_views=PCILIB_DEFAULT_VIEW_SPACE; ctx->alloc_views=PCILIB_DEFAULT_VIEW_SPACE; - ctx->alloc_enum_views=PCILIB_DEFAULT_VIEW_SPACE; ctx->registers = (pcilib_register_description_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_description_t)); ctx->register_ctx = (pcilib_register_context_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t)); - ctx->enum_views = (pcilib_view_enum2_t *)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_enum2_t)); - ctx->formula_views = (pcilib_view_formula_t*)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_formula_t)); ctx->views = (pcilib_view_t*)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_t)); ctx->alloc_units=PCILIB_DEFAULT_UNIT_SPACE; ctx->units=(pcilib_unit_t*)malloc(PCILIB_DEFAULT_UNIT_SPACE * sizeof(pcilib_unit_t)); @@ -157,7 +153,7 @@ pcilib_t *pcilib_open(const char *device, const char *model) { } /* i think we need a better error handling here, because, it's not that a problem to not have views working, but how to block the use if the memory here was not good?, and we could have only one type of views that is working*/ - if((!ctx->enum_views)||(!ctx->formula_views) || (!ctx->units) || !(ctx->views)){ + if((!ctx->units) || !(ctx->views)){ pcilib_warning("Error allocating memory for views"); } @@ -169,8 +165,6 @@ pcilib_t *pcilib_open(const char *device, const char *model) { memset(ctx->register_ctx, 0, PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t)); - memset(ctx->enum_views,0,sizeof(pcilib_view_enum2_t)); - memset(ctx->formula_views,0,sizeof(pcilib_view_formula_t)); memset(ctx->units,0,sizeof(pcilib_unit_t)); memset(ctx->views,0,sizeof(pcilib_view_t)); diff --git a/pcilib/pci.h b/pcilib/pci.h index d5f1811..8805fc2 100644 --- a/pcilib/pci.h +++ b/pcilib/pci.h @@ -65,8 +65,6 @@ struct pcilib_s { size_t num_banks, num_protocols, num_ranges; /**< Number of registered banks, protocols, and register ranges */ size_t num_engines; /**< Number of configured DMA engines */ size_t dyn_banks; /**< Number of configured dynamic banks */ - size_t num_enum_views,alloc_enum_views; /**< Number of configured and allocated views of type enum*/ - size_t num_formula_views,alloc_formula_views; /**< Number of configured and allocated views of type formula*/ size_t num_views,alloc_views; /**< Number of configured and allocated views*/ size_t num_units,alloc_units; /**< Number of configured and allocated units*/ pcilib_register_description_t *registers; /**< List of currently defined registers (from all sources) */ @@ -87,10 +85,9 @@ struct pcilib_s { struct pcilib_locking_s locks; /**< Context of locking subsystem */ struct pcilib_xml_s xml; /**< XML context */ - pcilib_view_enum2_t* enum_views; /**< list of currently defined views of type enum*/ - pcilib_view_formula_t* formula_views; /**< list of currently defined views of type formula*/ pcilib_view_t* views; /**< list of currently defined views*/ pcilib_unit_t* units; /** list of currently defined units*/ + #ifdef PCILIB_FILE_IO int file_io_handle; #endif /* PCILIB_FILE_IO */ diff --git a/pcilib/register.h b/pcilib/register.h index 2f6334c..13d4c9b 100644 --- a/pcilib/register.h +++ b/pcilib/register.h @@ -45,11 +45,9 @@ typedef struct { typedef struct { - pcilib_register_bank_t bank; /**< Reference to bank containing the register */ - pcilib_register_value_t min, max; /**< Minimum & maximum allowed values */ - pcilib_xml_node_t *xml; /**< Additional XML properties */ - pcilib_view_formula_t *formulas; /**< list of views of type formula linked to this register*/ - pcilib_view_enum_t *enums; /**< list of views of type enum linked to this register*/ + pcilib_register_bank_t bank; /**< Reference to bank containing the register */ + pcilib_register_value_t min, max; /**< Minimum & maximum allowed values */ + pcilib_xml_node_t *xml; /**< Additional XML properties */ pcilib_view_t *views; /** list of views linked to this register*/ } pcilib_register_context_t; diff --git a/pcilib/views.c b/pcilib/views.c index 86675f5..d0116db 100644 --- a/pcilib/views.c +++ b/pcilib/views.c @@ -9,41 +9,6 @@ #include "unit.h" /** - * function used to get the substring of a string s, from the starting and ending indexes - * @param[in] s string containing the substring we want to extract. - * @param[in] start the start index of the substring. - * @param[in] end the ending index of the substring. - * @return the extracted substring. - */ -char* -pcilib_view_str_sub (const char *s, unsigned int start, unsigned int end) -{ - char *new_s = NULL; - - if (s != NULL && start < end) - { - new_s = malloc (sizeof (*new_s) * (end - start + 2)); - if (new_s != NULL) - { - int i; - - for (i = start; i <= end; i++) - { - new_s[i-start] = s[i]; - } - new_s[i-start] = '\0'; - } - else - { - pcilib_error("insufficient memory for string manipulation\n"); - return NULL; - } - } - return new_s; -} - - -/** * this function calls the python script and the function "evaluate" in it to evaluate the given formula *@param[in] the formula to be evaluated *@return the integer value of the evaluated formula (maybe go to float instead) @@ -122,17 +87,6 @@ specified one. Add it to the register*/ static int pcilib_view_apply_formula(pcilib_t* ctx, char* formula, pcilib_register_value_t* reg_value) { - /* when applying a formula, we need to: - 1) compute the values of all registers present in plain name in the formulas and replace their name with their value : for example, if we have the formula" ((1./4)*(@reg - 1200)) if @freq==0 else ((3./10)*(@reg - 1000)) " we need to get the value of the register "freq" - 2) compute the "@reg" component, corresponding to the raw value of the register - 3) pass the formula to python interpreter for evaluation - 4) return the final evaluation - - remark: it might be worth to use python regular expression interpreter (the following return all words following @ in formula : - >>> import re - >>> m = re.search('(?<=@)\w+', formula) - >>> m.group(0) - */ char reg_value_string[66]; /* to register reg_value as a string, need to check the length*/ sprintf(reg_value_string,"%u",*reg_value); @@ -335,67 +289,6 @@ int operation_formula(pcilib_t *ctx, void *params, char* unit, int view2reg, pci /** - * function to populate ctx enum views, as we could do for registers or banks - */ -int pcilib_add_views_enum(pcilib_t *ctx, size_t n, const pcilib_view_enum2_t* views) { - - pcilib_view_enum2_t *views_enum; - size_t size; - - if (!n) { - for (n = 0; views[n].enums_list[0].value; n++); - } - - if ((ctx->num_enum_views + n + 1) > ctx->alloc_enum_views) { - for (size = ctx->alloc_enum_views; size < 2 * (n + ctx->num_enum_views + 1); size<<=1); - - views_enum = (pcilib_view_enum2_t*)realloc(ctx->enum_views, size * sizeof(pcilib_view_enum2_t)); - if (!views_enum) return PCILIB_ERROR_MEMORY; - - ctx->enum_views = views_enum; - ctx->alloc_enum_views = size; - } - - memcpy(ctx->enum_views + ctx->num_enum_views, views, n * sizeof(pcilib_view_enum2_t)); - memset(ctx->enum_views + ctx->num_enum_views + n, 0, sizeof(pcilib_view_enum2_t)); - - ctx->num_enum_views += n; - - - return 0; -} - - -/** - * function to populate ctx formula views, as we could do for registers or banks - */ -int pcilib_add_views_formula(pcilib_t *ctx, size_t n, const pcilib_view_formula_t* views) { - - pcilib_view_formula_t *views_formula; - size_t size; - - if (!n) { - for (n = 0; views[n].name; n++); - } - - if ((ctx->num_formula_views + n + 1) > ctx->alloc_formula_views) { - for (size = ctx->alloc_formula_views; size < 2 * (n + ctx->num_formula_views + 1); size<<=1); - - views_formula = (pcilib_view_formula_t*)realloc(ctx->formula_views, size * sizeof(pcilib_view_formula_t)); - if (!views_formula) return PCILIB_ERROR_MEMORY; - - ctx->formula_views = views_formula; - ctx->alloc_formula_views = size; - } - - memcpy(ctx->formula_views + ctx->num_formula_views, views, n * sizeof(pcilib_view_formula_t)); - memset(ctx->formula_views + ctx->num_formula_views + n, 0, sizeof(pcilib_view_formula_t)); - - ctx->num_formula_views += n; - return 0; -} - -/** * function to populate ctx views, as we could do for registers or banks */ int pcilib_add_views(pcilib_t *ctx, size_t n, const pcilib_view_t* views) { diff --git a/pcilib/views.h b/pcilib/views.h index 5d9100e..ae92d0d 100644 --- a/pcilib/views.h +++ b/pcilib/views.h @@ -6,10 +6,6 @@ typedef struct pcilib_view_enum_s pcilib_view_enum_t; -typedef struct pcilib_view_formula_s pcilib_view_formula_t; - -typedef struct pcilib_view_enum2_s pcilib_view_enum2_t; - typedef struct pcilib_view_s pcilib_view_t; typedef struct pcilib_formula_s pcilib_formula_t; @@ -29,15 +25,6 @@ struct pcilib_formula_s{ char* write_formula; }; -/** - * complete type for an enum view : name will be changed after with the previous one - */ -struct pcilib_view_enum2_s { - const char* name; - pcilib_view_enum_t* enums_list; - const char* description; -}; - struct pcilib_view_s{ const char* name; const char* description; @@ -45,17 +32,6 @@ struct pcilib_view_s{ void* parameters; pcilib_unit_t base_unit; }; -/** - * new type to define a formula view - */ -struct pcilib_view_formula_s { - const char *name; /**<name of the view*/ - const char *read_formula; /**< formula to parse to read from a register*/ - const char *write_formula; /**<formula to parse to write to a register*/ - // **see it later** const char *unit; (?) - const char *description; - pcilib_unit_t base_unit; -}; /** * function to read a register using a view @@ -67,16 +43,10 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const */ int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, const char *unit, size_t value_size, void *value); -int pcilib_add_views_enum(pcilib_t* ctx,size_t n, const pcilib_view_enum2_t* views); - -int pcilib_add_views_formula(pcilib_t* ctx, size_t n, const pcilib_view_formula_t* views); - int operation_enum(pcilib_t *ctx, void *params, char* name, int view2reg, pcilib_register_value_t *regval, size_t viewval_size, void* viewval); int operation_formula(pcilib_t *ctx, void *params, char* unit, int view2reg, pcilib_register_value_t *regval, size_t viewval_size, void* viewval); int pcilib_add_views(pcilib_t *ctx, size_t n, const pcilib_view_t* views); -char* pcilib_view_str_sub(const char* s, unsigned int start, unsigned int end); - #endif |