From df677a8fdc70082fe27028ca17c3c643f4d79dd1 Mon Sep 17 00:00:00 2001 From: zilio nicolas Date: Thu, 10 Sep 2015 15:00:17 +0200 Subject: more towards new views, beware, error codes not overhauled now --- views.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 19 deletions(-) (limited to 'views.c') diff --git a/views.c b/views.c index db96f4a..159ffa7 100644 --- a/views.c +++ b/views.c @@ -1,3 +1,7 @@ +#include +#include "pci.h" + + /** * new type to define an enum view */ @@ -26,7 +30,8 @@ pcilib_view_formula_s { *@param[in] after - the new value of before substring *@return the modified txt string */ -char *formula_replace (const char *txt, const char *before, const char *after) +static char* +pcilib_view_formula_replace (const char *txt, const char *before, const char *after) { const char *pos; char *return_txt; @@ -84,14 +89,15 @@ char *formula_replace (const char *txt, const char *before, const char *after) return return_txt; } -/* +/** * 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 *str_sub (const char *s, unsigned int start, unsigned int end) +static char* +pcilib_view_str_sub (const char *s, unsigned int start, unsigned int end) { char *new_s = NULL; @@ -117,16 +123,52 @@ char *str_sub (const char *s, unsigned int start, unsigned int end) return new_s; } -static int -pcilib_view_compute_plain_registers{ - /* hsould i used regexp.h??? or compile everythin myself? */ +/** + * get the bank name associated with a register name + */ +static char* +pcilib_view_get_bank_from_reg_name(pcilib_t* ctx,char* reg_name){ + int k; + for(k=0;ctx->registers[k].bits;k++){ + if(!(strcasecmp(reg_name,ctx->registers[k].name))){ + return ctx->banks[pcilib_find_register_bank_by_addr(ctx,ctx->registers[k].bank)].name; + } + } } +/** + * replace plain registers name in a formula by their value + */ +static int +pcilib_view_compute_plain_registers(pcilib_t* ctx, char* formula){ + int j,k; + char* substr,substr2; + char temp[66]; + pcilib_register_value_t value; + + /*we get recursively all registers of string , and if they are not equel to '@reg', then we get their value and put it in formula*/ + for(j=0;jregister_ctx[i].formulas[j].name)){ if(!(strcasecmp(ctx->register_ctx[i].formulas[j].name))){ /* when we have found the correct view of type formula, we apply the formula, that get the good value for return*/ - pcilib_view_apply_read_formula(ctx->register_ctx[i].formulas[j].read_formula,temp_value, value,....); + pcilib_view_apply_formula(ctx, ctx->register_ctx[i].formulas[j].read_formula,temp_value,value); + value_size=sizeof(int); return 0; } j++; @@ -260,4 +298,5 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const return PCILIB_ERROR_NOTAVAILABLE; } - + int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, const char *view/*, const char *unit*/, size_t value_size, void *value){ + -- cgit v1.2.3