From 1d3cffac722081aa8b74821a832d8cc9c58715e6 Mon Sep 17 00:00:00 2001 From: zilio nicolas Date: Thu, 27 Aug 2015 12:13:38 +0200 Subject: better public API and no more use of locals within pcilib_open --- pcilib/xml.c | 164 ++++++++++++++++++++++++++--------------------------------- 1 file changed, 73 insertions(+), 91 deletions(-) (limited to 'pcilib/xml.c') diff --git a/pcilib/xml.c b/pcilib/xml.c index 762f805..68ac42a 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -19,6 +19,8 @@ #include #include #include "pci.h" +#include "bank.h" +#include "register.h" //#define VIEW_OK //#define UNIT_OK @@ -260,12 +262,14 @@ void pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank,xmlChar* * @param[in] doc the AST of the xml file. * @param[in,out] mybanks the structure containing the banks. */ -void pcilib_xml_initialize_banks(pcilib_t* pci, xmlDocPtr doc, pcilib_register_bank_description_t* mybanks){ +void pcilib_xml_initialize_banks(pcilib_t* pci, xmlDocPtr doc/*, pcilib_register_bank_description_t* mybanks*/){ pcilib_register_bank_description_t mybank; xmlNodeSetPtr nodesetadress=NULL,nodesetbar=NULL,nodesetsize=NULL,nodesetprotocol=NULL,nodesetread_addr=NULL,nodesetwrite_addr=NULL,nodesetaccess=NULL,nodesetendianess=NULL,nodesetformat=NULL,nodesetname=NULL,nodesetdescription=NULL; xmlChar *adress=NULL,*bar=NULL,*size=NULL,*protocol=NULL,*read_addr=NULL,*write_addr=NULL,*access=NULL,*endianess=NULL,*format=NULL,*name=NULL,*description=NULL; xmlNodePtr mynode; + int number_banks; + pcilib_register_bank_description_t* banks; xmlXPathContextPtr context; context=pcilib_xml_getcontext(doc); @@ -274,10 +278,14 @@ void pcilib_xml_initialize_banks(pcilib_t* pci, xmlDocPtr doc, pcilib_register_b mynode=malloc(sizeof(xmlNode)); + number_banks=pcilib_xml_getnumberbanks(context); + if(number_banks) banks=calloc((number_banks),sizeof(pcilib_register_bank_description_t)); + else return; + xmlXPathObjectPtr temp; - /** we first get the nodes corresponding to the properties we want - * note: here a recursive algorithm may be more efficient but less evolutive*/ + /** we first get the nodes corresponding to the properties we want*/ +/* -----> certainly not necessary if we validate xml each time*/ temp=pcilib_xml_getsetproperty(context,BANK_ADDR_PATH); if(temp!=NULL) nodesetadress=temp->nodesetval; else pcilib_error("there is no adress for banks in the xml"); @@ -342,14 +350,62 @@ void pcilib_xml_initialize_banks(pcilib_t* pci, xmlDocPtr doc, pcilib_register_b /** the following function will create the given structure for banks*/ pcilib_xml_create_bank(&mybank,adress,bar,size,protocol,read_addr,write_addr,access,endianess,format, name, description); - mybanks[i]=mybank; + banks[i]=mybank; pci->banks_xml_nodes[i]=mynode; } + + pcilib_add_register_banks(pci,number_banks,banks); +} + +/* + * next 3 functions are for the implementation of a merge sort algorithm + */ +void topdownmerge(pcilib_register_description_t *A, int start, int middle, int end, pcilib_register_description_t *B){ + int i0,i1,j; + i0= start; + i1=middle; + for(j=start;j=end || A[i0].addr<=A[i1].addr)){ + B[j]=A[i0]; + i0++; + } + else{ + B[j]=A[i1]; + i1++; + } + } } +void copyarray(pcilib_register_description_t *B, int start,int end, pcilib_register_description_t *A){ + int k; + for (k=start; knodeNr + nodesetsuboffset->nodeNr; /** certainly not necessary if we validate xml each time*/ + temp=pcilib_xml_getsetproperty(context,ADRESS_PATH); if(temp!=NULL)nodesetadress=temp->nodesetval; else pcilib_error("no adress for registers found in xml"); @@ -506,57 +571,12 @@ void pcilib_xml_initialize_registers(pcilib_t* pci, xmlDocPtr doc,pcilib_registe registers[i+j]=myregister; pci->registers_xml_nodes[i+j]=mynode; } -} - - -/* - * next 3 functions are for the implementation of a merge sort algorithm - */ -void topdownmerge(pcilib_register_description_t *A, int start, int middle, int end, pcilib_register_description_t *B){ - int i0,i1,j; - i0= start; - i1=middle; - - for(j=start;j=end || A[i0].addr<=A[i1].addr)){ - B[j]=A[i0]; - i0++; - } - else{ - B[j]=A[i1]; - i1++; - } - } -} -void copyarray(pcilib_register_description_t *B, int start,int end, pcilib_register_description_t *A){ - int k; - for (k=start; k /** validation @@ -644,44 +664,6 @@ void pcilib_xml_read_config(char** xmlfile, int j){ memset(line,'\0',60); } } -/* to include or not?*/ -/** pcilib_xml_init_nodeset_register_ctx - * - * function to get all registers nodes in a structure and put it in registers context -* @param[in] ctx the register context running. - * -void pcilib_xml_init_nodeset_register_ctx(pcilib_register_context_t *ctx){ - char* xmlfile; - pcilib_xml_read_config(&xmlfile,3); - xmlDocPtr doc; - doc=pcilib_xml_getdoc(xmlfile); - xmlXPathContextPtr context; - context=pcilib_xml_getcontext(doc); - - xmlNodeSetPtr registers; - registers = pcilib_xml_getsetproperty(context, REGISTERS_PATH)->nodesetval; - ctx->registers_nodes=registers; -} - -** pcilib_xml_init_nodeset_bank_ctx - * - *function to get all banks nodes in a structure and put it in banks context -* @param[in] ctx the bank context running. - * -void pcilib_xml_init_nodeset_bank_ctx(pcilib_register_bank_context_t *ctx){ - char* xmlfile; - pcilib_xml_read_config(&xmlfile,3); - xmlDocPtr doc; - doc=pcilib_xml_getdoc(xmlfile); - xmlXPathContextPtr context; - context=pcilib_xml_getcontext(doc); - - xmlNodeSetPtr banks; - banks = pcilib_xml_getsetproperty(context, BANKS_PATH)->nodesetval; - ctx->banks_nodes=banks; - -} -*/ #ifdef VIEW_OK /* pcilib_xml_getnumberformulaviews -- cgit v1.2.3