From 60c6bf9f6916b6ae2c05a499675ff54480256ece Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Fri, 11 Sep 2015 19:40:33 +0200 Subject: more towards views --- pcitool/cli.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index c3663d2..7014190 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -2720,6 +2720,11 @@ int main(int argc, char **argv) { mode = MODE_READ; if (optarg) addr = optarg; else if ((optind < argc)&&(argv[optind][0] != '-')) addr = argv[optind++]; + + /* char* s; + if(!(s=strchr(addr,'/'))){ + mode=MODE_READ_VIEW;*/ + break; case OPT_WRITE: if (mode != MODE_INVALID) Usage(argc, argv, "Multiple operations are not supported"); -- cgit v1.2.3 From 2dfb23016c39a331bf5ed4111b630dffa330edbb Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Mon, 14 Sep 2015 11:56:38 +0200 Subject: views working fine, units in progress --- pcitool/cli.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 10 deletions(-) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index 7014190..6af70e4 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1024,13 +1024,14 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, int i; int err; const char *format; + char *s1,*s2,*s3; + pcilib_register_bank_t bank_id; pcilib_register_bank_addr_t bank_addr = 0; pcilib_register_value_t value; - - if (reg) { + if (reg && !(strchr(reg,'/'))) { pcilib_register_t regid = pcilib_find_register(handle, bank, reg); bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); format = model_info->banks[bank_id].format; @@ -1044,7 +1045,36 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, printf(format, value); printf("\n"); } + }else if(reg && (s1=strchr(reg,'/'))){ + char* enum_command=malloc(sizeof(char*)); + if(!enum_command){ + printf("Error allocating memory for the result\n"); + return PCILIB_ERROR_MEMORY; + } + s2=pcilib_view_str_sub(reg,0,s1-reg-1); + s3=pcilib_view_str_sub(reg,s1-reg+1,strlen(reg)); + if(!(strcasecmp(s3,"name"))){ + err = pcilib_read_view(handle,bank,s2,NULL,sizeof(char*),enum_command); + if (err) printf("Error reading register %s\n", reg); + else { + printf("%s = %s\n", reg, (char*)enum_command); + } + }else{ + pcilib_register_t regid = pcilib_find_register(handle, bank, s2); + bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); + format = model_info->banks[bank_id].format; + if (!format) format = "%lu"; + + err = pcilib_read_view(handle,bank,s2,s3,sizeof(pcilib_register_value_t),&value); + if (err) printf("Error reading register %s\n", reg); + else { + printf("%s = ", reg); + printf(format, value); + printf("\n"); + } + } } else { + printf("da\n"); // Adding DMA registers pcilib_get_dma_description(handle); @@ -1254,6 +1284,7 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info pcilib_register_value_t value; const char *format = NULL; + char *s1; pcilib_register_t regid = pcilib_find_register(handle, bank, reg); if (regid == PCILIB_REGISTER_INVALID) Error("Can't find register (%s) from bank (%s)", reg, bank?bank:"autodetected"); @@ -1281,14 +1312,27 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info format = "0x%lx"; } else { - Error("Can't parse data value (%s) is not valid decimal number", *data); + err = pcilib_write_view(handle,bank,reg,*data,0,NULL); + if(err) Error("can't write to the register using an enum view"); + else return 0; } + /* } else { + Error("Can't parse data value (%s) is not valid decimal number", *data); + }*/ value = val; - - err = pcilib_write_register(handle, bank, reg, value); - if (err) Error("Error writting register %s\n", reg); + if((s1=strchr(reg,'/'))){ + char *s3,*s2; + s2=pcilib_view_str_sub(reg,0,s1-reg-1); + s3=pcilib_view_str_sub(reg,s1-reg+1,strlen(reg)); + err = pcilib_write_view(handle,bank,s2,s3,sizeof(pcilib_register_value_t),&value); + if (err) printf("Error writing register %s using view %s\n",s2,s3); + }else{ + err = pcilib_write_register(handle, bank, reg, value); + if (err) Error("Error writting register %s\n", reg); + } + if ((model_info->registers[regid].mode&PCILIB_REGISTER_RW) == PCILIB_REGISTER_RW) { err = pcilib_read_register(handle, bank, reg, &value); if (err) Error("Error reading back register %s for verification\n", reg); @@ -3249,7 +3293,10 @@ int main(int argc, char **argv) { ++mode; } } - } else { + } else if(strchr(addr,'/')) { + reg=addr; + ++mode; + }else { if (pcilib_find_register(handle, bank, addr) == PCILIB_REGISTER_INVALID) { Usage(argc, argv, "Invalid address (%s) is specified", addr); } else { @@ -3349,12 +3396,12 @@ int main(int argc, char **argv) { } else if (addr) { err = ReadData(handle, amode, flags, dma, bar, start, size, access, endianess, (size_t)-1, ofile); } else { - Error("Address to read is not specified"); + Error("Address to read is not specified"); } break; case MODE_READ_REGISTER: - if ((reg)||(!addr)) ReadRegister(handle, model_info, bank, reg); - else ReadRegisterRange(handle, model_info, bank, start, addr_shift, size, ofile); + if ((reg)||(!addr)) ReadRegister(handle, model_info, bank, reg); + else ReadRegisterRange(handle, model_info, bank, start, addr_shift, size, ofile); break; case MODE_WRITE: WriteData(handle, amode, dma, bar, start, size, access, endianess, data, verify); -- cgit v1.2.3 From a1bf5e300e2345b642d0a13e7e26d22c56156e47 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Mon, 14 Sep 2015 15:49:46 +0200 Subject: views with units functionnal (beware, as formulas are completely crap now, we could get segfault, for example if we want to write a negative value in register) --- pcitool/cli.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index 6af70e4..bd52270 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1054,7 +1054,7 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, s2=pcilib_view_str_sub(reg,0,s1-reg-1); s3=pcilib_view_str_sub(reg,s1-reg+1,strlen(reg)); if(!(strcasecmp(s3,"name"))){ - err = pcilib_read_view(handle,bank,s2,NULL,sizeof(char*),enum_command); + err = pcilib_read_view(handle,bank,s2,NULL,sizeof(char*),enum_command); if (err) printf("Error reading register %s\n", reg); else { printf("%s = %s\n", reg, (char*)enum_command); @@ -1282,11 +1282,17 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info unsigned long val; pcilib_register_value_t value; + pcilib_register_t regid; const char *format = NULL; - char *s1; - - pcilib_register_t regid = pcilib_find_register(handle, bank, reg); + char *s1,*s2=NULL; + + if((s1=strchr(reg,'/'))){ + s2=pcilib_view_str_sub(reg,0,s1-reg-1); + regid=pcilib_find_register(handle,bank,s2); + }else{ + regid = pcilib_find_register(handle, bank, reg); + } if (regid == PCILIB_REGISTER_INVALID) Error("Can't find register (%s) from bank (%s)", reg, bank?bank:"autodetected"); /* @@ -1316,15 +1322,15 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info if(err) Error("can't write to the register using an enum view"); else return 0; } - /* } else { + /* should i put strchr not null here? + } else { Error("Can't parse data value (%s) is not valid decimal number", *data); }*/ value = val; if((s1=strchr(reg,'/'))){ - char *s3,*s2; - s2=pcilib_view_str_sub(reg,0,s1-reg-1); + char *s3; s3=pcilib_view_str_sub(reg,s1-reg+1,strlen(reg)); err = pcilib_write_view(handle,bank,s2,s3,sizeof(pcilib_register_value_t),&value); if (err) printf("Error writing register %s using view %s\n",s2,s3); -- cgit v1.2.3 From c71075ca84d896c650dd0b65c7664149ed51dcec Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 11:36:20 +0200 Subject: addition of other remarks, cleaning in progress --- pcitool/cli.c | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index bd52270..378b8ba 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1024,14 +1024,15 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, int i; int err; const char *format; - char *s1,*s2,*s3; + char *s1,*regname,*viewname; + char* fullreg=strdup(reg); pcilib_register_bank_t bank_id; pcilib_register_bank_addr_t bank_addr = 0; pcilib_register_value_t value; - if (reg && !(strchr(reg,'/'))) { + if (reg && !(strchr(fullreg,'/'))) { pcilib_register_t regid = pcilib_find_register(handle, bank, reg); bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); format = model_info->banks[bank_id].format; @@ -1045,28 +1046,30 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, printf(format, value); printf("\n"); } - }else if(reg && (s1=strchr(reg,'/'))){ + }else if(reg && (s1=strchr(fullreg,'/'))){ char* enum_command=malloc(sizeof(char*)); if(!enum_command){ printf("Error allocating memory for the result\n"); return PCILIB_ERROR_MEMORY; } - s2=pcilib_view_str_sub(reg,0,s1-reg-1); - s3=pcilib_view_str_sub(reg,s1-reg+1,strlen(reg)); - if(!(strcasecmp(s3,"name"))){ - err = pcilib_read_view(handle,bank,s2,NULL,sizeof(char*),enum_command); - if (err) printf("Error reading register %s\n", reg); + *s1=0; + regname=fullreg; + viewname=fullreg+1; + if(!strcasecmp(viewname,"name")){ + err = pcilib_read_view(handle,bank,regname,viewname,sizeof(char*),enum_command); + if (err) printf("Error reading register %s with an enum view\n", reg); else { printf("%s = %s\n", reg, (char*)enum_command); } + free(enum_command); }else{ - pcilib_register_t regid = pcilib_find_register(handle, bank, s2); + pcilib_register_t regid = pcilib_find_register(handle, bank, regname); bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); format = model_info->banks[bank_id].format; if (!format) format = "%lu"; - err = pcilib_read_view(handle,bank,s2,s3,sizeof(pcilib_register_value_t),&value); - if (err) printf("Error reading register %s\n", reg); + err = pcilib_read_view(handle,bank,regname,viewname,sizeof(pcilib_register_value_t),&value); + if (err) printf("Error reading register %s with a formula view\n", reg); else { printf("%s = ", reg); printf(format, value); @@ -1074,7 +1077,6 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, } } } else { - printf("da\n"); // Adding DMA registers pcilib_get_dma_description(handle); @@ -1285,11 +1287,14 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info pcilib_register_t regid; const char *format = NULL; - char *s1,*s2=NULL; + char *s1,*regname=NULL; - if((s1=strchr(reg,'/'))){ - s2=pcilib_view_str_sub(reg,0,s1-reg-1); - regid=pcilib_find_register(handle,bank,s2); + char *fullregister=strdup(reg); + + if((s1=strchr(fullregister,'/'))){ + *s1=0; + regname=fullregister; + regid=pcilib_find_register(handle,bank,regname); }else{ regid = pcilib_find_register(handle, bank, reg); } @@ -1317,23 +1322,24 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info } format = "0x%lx"; - } else { + } else if((data) && !(regname)){ err = pcilib_write_view(handle,bank,reg,*data,0,NULL); if(err) Error("can't write to the register using an enum view"); else return 0; } - /* should i put strchr not null here? + /* should i put strchr not null here?* } else { Error("Can't parse data value (%s) is not valid decimal number", *data); }*/ value = val; - if((s1=strchr(reg,'/'))){ - char *s3; - s3=pcilib_view_str_sub(reg,s1-reg+1,strlen(reg)); - err = pcilib_write_view(handle,bank,s2,s3,sizeof(pcilib_register_value_t),&value); - if (err) printf("Error writing register %s using view %s\n",s2,s3); + if((regname)){ + char *view_name; + view_name=fullregister+1;; + err = pcilib_write_view(handle,bank,regname,view_name,sizeof(pcilib_register_value_t),&value); + if (err) printf("Error writing register %s using view %s\n",regname,view_name); + free(fullregister); }else{ err = pcilib_write_register(handle, bank, reg, value); if (err) Error("Error writting register %s\n", reg); -- cgit v1.2.3 From c871ef59e748678b11d964e21debab05082948a0 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 14:56:35 +0200 Subject: soka --- pcitool/cli.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index 378b8ba..69151b6 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1033,6 +1033,7 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, pcilib_register_value_t value; if (reg && !(strchr(fullreg,'/'))) { + printf("pass1\n"); pcilib_register_t regid = pcilib_find_register(handle, bank, reg); bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); format = model_info->banks[bank_id].format; @@ -1047,6 +1048,7 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, printf("\n"); } }else if(reg && (s1=strchr(fullreg,'/'))){ + printf("pass2\n"); char* enum_command=malloc(sizeof(char*)); if(!enum_command){ printf("Error allocating memory for the result\n"); @@ -1054,7 +1056,8 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, } *s1=0; regname=fullreg; - viewname=fullreg+1; + viewname=s1+1; + printf("regname %s, viewname %s\n",regname,viewname); if(!strcasecmp(viewname,"name")){ err = pcilib_read_view(handle,bank,regname,viewname,sizeof(char*),enum_command); if (err) printf("Error reading register %s with an enum view\n", reg); -- cgit v1.2.3 From e43b676d8294f37410ea0fa1f9fa39d10df64408 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 17:27:27 +0200 Subject: not perfect but working --- pcitool/cli.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index 69151b6..aa80b72 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1033,7 +1033,6 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, pcilib_register_value_t value; if (reg && !(strchr(fullreg,'/'))) { - printf("pass1\n"); pcilib_register_t regid = pcilib_find_register(handle, bank, reg); bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); format = model_info->banks[bank_id].format; @@ -1048,7 +1047,6 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, printf("\n"); } }else if(reg && (s1=strchr(fullreg,'/'))){ - printf("pass2\n"); char* enum_command=malloc(sizeof(char*)); if(!enum_command){ printf("Error allocating memory for the result\n"); @@ -1062,7 +1060,7 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, err = pcilib_read_view(handle,bank,regname,viewname,sizeof(char*),enum_command); if (err) printf("Error reading register %s with an enum view\n", reg); else { - printf("%s = %s\n", reg, (char*)enum_command); + printf("%s = %s\n", regname, (char*)enum_command); } free(enum_command); }else{ @@ -1339,7 +1337,7 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info if((regname)){ char *view_name; - view_name=fullregister+1;; + view_name=s1+1;; err = pcilib_write_view(handle,bank,regname,view_name,sizeof(pcilib_register_value_t),&value); if (err) printf("Error writing register %s using view %s\n",regname,view_name); free(fullregister); -- cgit v1.2.3 From 16556c4b24e37a4d451b7a85a5d260c4ee9828cb Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 19:25:47 +0200 Subject: no more realloc in op enum --- pcitool/cli.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index aa80b72..b168d16 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1047,7 +1047,7 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, printf("\n"); } }else if(reg && (s1=strchr(fullreg,'/'))){ - char* enum_command=malloc(sizeof(char*)); + char* enum_command=malloc(50*sizeof(char)); if(!enum_command){ printf("Error allocating memory for the result\n"); return PCILIB_ERROR_MEMORY; @@ -1055,26 +1055,22 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, *s1=0; regname=fullreg; viewname=s1+1; - printf("regname %s, viewname %s\n",regname,viewname); if(!strcasecmp(viewname,"name")){ - err = pcilib_read_view(handle,bank,regname,viewname,sizeof(char*),enum_command); + err = pcilib_read_view(handle,bank,regname,viewname,50*sizeof(char),enum_command); if (err) printf("Error reading register %s with an enum view\n", reg); else { printf("%s = %s\n", regname, (char*)enum_command); } free(enum_command); }else{ - pcilib_register_t regid = pcilib_find_register(handle, bank, regname); - bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); - format = model_info->banks[bank_id].format; - if (!format) format = "%lu"; + format = "%lf"; err = pcilib_read_view(handle,bank,regname,viewname,sizeof(pcilib_register_value_t),&value); if (err) printf("Error reading register %s with a formula view\n", reg); else { printf("%s = ", reg); printf(format, value); - printf("\n"); + printf("%s\n",viewname); } } } else { @@ -1338,7 +1334,7 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info if((regname)){ char *view_name; view_name=s1+1;; - err = pcilib_write_view(handle,bank,regname,view_name,sizeof(pcilib_register_value_t),&value); + err = pcilib_write_view(handle,bank,regname,view_name,0,&value); if (err) printf("Error writing register %s using view %s\n",regname,view_name); free(fullregister); }else{ -- cgit v1.2.3 From ae7f83a7948d8c3760f8019899a45e6ec90c2c6a Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 20:11:02 +0200 Subject: bof.... --- pcitool/cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pcitool') diff --git a/pcitool/cli.c b/pcitool/cli.c index b168d16..26bd087 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1320,7 +1320,7 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info format = "0x%lx"; } else if((data) && !(regname)){ - err = pcilib_write_view(handle,bank,reg,*data,0,NULL); + err = pcilib_write_view(handle,bank,reg,"name",0,*data); if(err) Error("can't write to the register using an enum view"); else return 0; } -- cgit v1.2.3