summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzilio nicolas <nicolas.zilio@kit.edu>2015-07-01 16:18:45 +0200
committerzilio nicolas <nicolas.zilio@kit.edu>2015-07-01 16:18:45 +0200
commitf82813bfa40193aec07e013b029eec6dc092ecdd (patch)
tree4f6b814177a0750b2c2c37aa2b2e47ffefc27255
parente2515f6e1a7b17addda4c558a0a6ca05b4ec6e55 (diff)
downloadpcitool-f82813bfa40193aec07e013b029eec6dc092ecdd.tar.gz
pcitool-f82813bfa40193aec07e013b029eec6dc092ecdd.tar.bz2
pcitool-f82813bfa40193aec07e013b029eec6dc092ecdd.tar.xz
pcitool-f82813bfa40193aec07e013b029eec6dc092ecdd.zip
registers and banks support in xml v1. pci -ll works fine, but got segfault on pci -r name and pci -r name gives 0 always. might be due to the order in pci.c ------> ask suren
-rw-r--r--CMakeLists.txt5
-rw-r--r--pcilib/CMakeLists.txt10
-rw-r--r--pcilib/bank.h2
-rw-r--r--pcilib/pci.c33
-rw-r--r--pcilib/register.h2
-rw-r--r--pcilib/xml.c672
-rw-r--r--pcilib/xml.h208
-rw-r--r--pcitool/camera.xml923
-rw-r--r--pcitool/cli.c11
-rw-r--r--pcitool/config.txt13
-rwxr-xr-xpcitool/registers_and_banks.xsd242
11 files changed, 2115 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f397c6b..2b5a498 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,13 +11,16 @@ set(DISABLE_PCITOOL FALSE CACHE BOOL "Build only the library")
find_package(PkgConfig REQUIRED)
find_package(Threads REQUIRED)
+find_package(PythonLibs REQUIRED)
#Check in sibling directory
if (NOT DISABLE_PCITOOL)
pkg_check_modules(FASTWRITER fastwriter REQUIRED)
endif (NOT DISABLE_PCITOOL)
-add_definitions("-fPIC --std=c99 -Wall -O2 -gdwarf-2 -g3")
+pkg_check_modules(XMLLIB libxml-2.0 REQUIRED)
+
+add_definitions("-fPIC --std=c99 -Wall -O2 -gdwarf-2 -g3 -g")
#add_definitions("-fPIC --std=c99 -Wall -O2")
include(cmake/version.cmake)
diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt
index c9bf0fb..881b44c 100644
--- a/pcilib/CMakeLists.txt
+++ b/pcilib/CMakeLists.txt
@@ -1,11 +1,13 @@
include_directories(
${CMAKE_SOURCE_DIR}
+ ${PYTHON_INCLUDE_DIRS}
+ ${XMLLIB_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/pcilib
)
-set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h kmem.h irq.h dma.h event.h plugin.h tools.h error.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 kmem.c irq.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})
+set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h kmem.h irq.h dma.h event.h plugin.h tools.h error.h debug.h env.h version.h config.h xml.h)
+add_library(pcilib SHARED pci.c export.c bar.c fifo.c model.c bank.c register.c kmem.c irq.c dma.c event.c plugin.c tools.c error.c debug.c env.c xml.c)
+target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${XMLLIB_LIBRARIES} ${PYTHON_LIBRARIES})
add_dependencies(pcilib dma protocols)
install(TARGETS pcilib
@@ -16,6 +18,6 @@ install(FILES pcilib.h
DESTINATION include
)
-install(FILES bar.h kmem.h bank.h register.h dma.h event.h model.h error.h debug.h env.h tools.h export.h version.h
+install(FILES bar.h kmem.h bank.h register.h dma.h event.h model.h error.h debug.h env.h tools.h export.h version.h xml.h
DESTINATION include/pcilib
)
diff --git a/pcilib/bank.h b/pcilib/bank.h
index a0ba9fe..e2174e9 100644
--- a/pcilib/bank.h
+++ b/pcilib/bank.h
@@ -62,6 +62,7 @@ typedef struct {
const char *format; /**< printf format for the registers, either %lu for decimal output or 0x%lx for hexdecimal */
const char *name; /**< short bank name */
const char *description; /**< longer bank description */
+ /* use it or not?*/ /*xmlNodePtr xmlNode;*/ /**<pointer to xmlNode of the bank in the file*/
} pcilib_register_bank_description_t;
/**
@@ -84,6 +85,7 @@ typedef struct {
struct pcilib_register_bank_context_s {
const pcilib_register_bank_description_t *bank; /**< Corresponding bank description */
const pcilib_register_protocol_api_description_t *api; /**< API functions */
+ /*use it or not?*/ /*xmlNodeSetPtr banks_nodes;*/
};
#ifdef __cplusplus
diff --git a/pcilib/pci.c b/pcilib/pci.c
index 3a18ccd..5bae8fc 100644
--- a/pcilib/pci.c
+++ b/pcilib/pci.c
@@ -24,6 +24,7 @@
#include "model.h"
#include "plugin.h"
#include "bar.h"
+#include "xml.h"
static int pcilib_detect_model(pcilib_t *ctx, const char *model) {
int i, j;
@@ -105,6 +106,26 @@ pcilib_t *pcilib_open(const char *device, const char *model) {
int err;
size_t i;
pcilib_t *ctx = malloc(sizeof(pcilib_t));
+
+ pcilib_register_description_t *registers=NULL;
+ pcilib_register_bank_description_t *banks=NULL;
+ int number_registers, number_banks;
+
+ char *xmlfile;
+ pcilib_xml_read_config(&xmlfile,3);
+ xmlDocPtr doc;
+ doc=pcilib_xml_getdoc(xmlfile);
+
+ xmlXPathContextPtr context;
+ context=pcilib_xml_getcontext(doc);
+
+ number_registers=pcilib_xml_getnumberregisters(context);
+ number_banks=pcilib_xml_getnumberbanks(context);
+
+ if(number_registers)registers=calloc((number_registers),sizeof(pcilib_register_description_t));
+ else pcilib_error("no registers in the xml file");
+ if(number_banks)banks=calloc((number_banks),sizeof(pcilib_register_bank_description_t));
+ else pcilib_error("no banks in the xml file");
if (ctx) {
memset(ctx, 0, sizeof(pcilib_t));
@@ -154,6 +175,17 @@ pcilib_t *pcilib_open(const char *device, const char *model) {
if (!ctx->model)
ctx->model = strdup(model?model:"pci");
+ if(registers){
+ pcilib_xml_initialize_registers(doc,registers);
+ pcilib_xml_arrange_registers(registers,number_registers);
+ pcilib_add_registers(ctx,number_registers,registers);
+ }else pcilib_error("no memory for registers");
+
+ if(banks){
+ pcilib_xml_initialize_banks(doc,banks);
+ pcilib_add_register_banks(ctx,number_banks,banks);
+ }else pcilib_error("no memory for banks");
+
ctx->model_info.registers = ctx->registers;
ctx->model_info.banks = ctx->banks;
ctx->model_info.protocols = ctx->protocols;
@@ -166,6 +198,7 @@ pcilib_t *pcilib_open(const char *device, const char *model) {
pcilib_close(ctx);
return NULL;
}
+
err = pcilib_init_event_engine(ctx);
if (err) {
diff --git a/pcilib/register.h b/pcilib/register.h
index 535e9d0..fc13e6a 100644
--- a/pcilib/register.h
+++ b/pcilib/register.h
@@ -40,11 +40,13 @@ typedef struct {
const char *name; /**< The access name of the register */
const char *description; /**< Brief description of the register */
+ /* use it or not? */ /*xmlNodePtr xmlNode;*/ /**<pointer to the corresponding node in the xml file*/
} pcilib_register_description_t;
typedef struct {
pcilib_register_bank_t bank;
+ /* use it or not?*/ /*xmlNodeSetPtr registers_nodes;*/
} pcilib_register_context_t;
diff --git a/pcilib/xml.c b/pcilib/xml.c
new file mode 100644
index 0000000..b93f2aa
--- /dev/null
+++ b/pcilib/xml.c
@@ -0,0 +1,672 @@
+/**
+ * @file pcilib_xml.c
+ * @version 1.0
+ *
+ * @brief this file is the main source file for the implementation of dynamic registers using xml and several funtionalities for the "pci-tool" line command tool from XML files. the xml part has been implemented using libxml2
+ *
+ * @details this code was meant to be evolutive as the XML files evolute. In this meaning, most of the xml parsing is realized with XPath expressions(when it was possible), so that changing the xml xould result mainly in changing the XPAth pathes present in the header file. In a case of a change in xml file, variables that need to be changed other than xpathes, will be indicated in the description of the function.
+
+ Libxml2 considers blank spaces within the XML as node natively and this code as been produced considering blank spaces in the XML files. In case XML files would not contain blank spaces anymore, please change the code.
+
+ In case the performance is not good enough, please consider the following : no more configuration file indicating where the files required are, hard code of formulas, and go to complete non evolutive code : get 1 access to xml file and context, and then make recursive descent to get all you need(investigation of libxml2 source code would be so needed to prove it's better to go recursive than just xpath).
+ */
+
+#include "xml.h"
+#include "error.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <Python.h>
+
+
+/**
+ * pcilib_xml_getdoc
+ * this function takes a string and will create an abtract syntax tree from the xml file represented by the string
+ * @param[in] filename the the name of the xml file containing registers and banks
+ */
+xmlDocPtr pcilib_xml_getdoc(char* filename){
+ xmlDocPtr doc;
+ doc=xmlParseFile(filename); /**<the creation of the AST from a libxml2 funtion*/
+
+ if (doc==NULL){
+ pcilib_error("xml document not parsed successfully");
+ return NULL;
+ }
+
+ return doc;
+}
+
+/** pcilib_xml_getsetproperty
+ *
+ * this function takes a context from an AST and an XPath expression, to produce an object containing the nodes corresponding to the xpath expression
+ * @param[in] doc the AST of the xml file
+ * @param[in] xpath the xpath expression that will be evaluated
+ */
+xmlXPathObjectPtr pcilib_xml_getsetproperty(xmlXPathContextPtr doc, xmlChar *xpath){
+ xmlXPathObjectPtr result;
+ result=xmlXPathEvalExpression(xpath, doc); /**<the creation of the resulting object*/
+ if(result==NULL){
+// pcilib_warning(" warning : the path is empty: %s",xpath);
+ return NULL;
+ }
+
+ if(xmlXPathNodeSetIsEmpty(result->nodesetval)){
+ xmlXPathFreeObject(result);
+// pcilib_warning("warning : no results found for: %s",xpath);
+ return NULL;
+ }
+
+ return result;
+}
+
+/** pcilib_xml_getcontext.
+ * this function create a context in an AST (ie initialize XPAth for the AST).
+ * @param[in] doc the AST of the xml file.
+ */
+xmlXPathContextPtr pcilib_xml_getcontext(xmlDocPtr doc){
+ xmlXPathContextPtr context;
+ context= xmlXPathNewContext(doc); /**<the creation of the context using a libxml2's function */
+ if(context==NULL){
+ pcilib_error("warning : no context obtained for the xml document");
+ return NULL;
+ }
+ return context;
+}
+
+
+/** pcilib_xml_create_register.
+ * this function create a register structure from the results of xml parsing.
+ * @param[out] myregister the register we want to create
+ * @param[in] adress the adress of the future register
+ * @param[in] offset the offset of the future register
+ * @param[in] size the size of the future register
+ * @param[in] defvalue the defaut value of the future register
+ * @param[in] rwmask the rwmask of the future register
+ * @param[in] mode the mode of the future register
+ * @param[in] type the type of the future register
+ * @param[in] bank the bank of the future register
+ * @param[in] name the name of the future register
+ * @param[in] description the description of the future register
+ * @param[in] node the current xmlNode in the xml of the future register
+ */
+void pcilib_xml_create_register(pcilib_register_description_t *myregister,xmlChar* adress, xmlChar *offset, xmlChar *size, xmlChar *defvalue, xmlChar *rwmask, xmlChar *mode, xmlChar *type, xmlChar *bank, xmlChar *name, xmlChar *description, xmlNodePtr node){
+
+ char* ptr;
+
+ /* we recreate here each sub property of the register structure given the results of xml parsing
+ note :the use of strtol permits to get as well hexadecimal and decimal values
+ */
+
+ myregister->addr=(pcilib_register_addr_t)strtol((char*)adress,&ptr,0);
+ myregister->offset=(pcilib_register_size_t)strtol((char*)offset,&ptr,0);
+ myregister->bits=(pcilib_register_size_t)strtol((char*)size,&ptr,0);
+ myregister->defvalue=(pcilib_register_value_t)strtol((char*)defvalue,&ptr,0);
+
+ if(strcmp((char*)rwmask,"all bits")==0){
+ myregister->rwmask=PCILIB_REGISTER_ALL_BITS;
+ }else if(strcmp((char*)rwmask,"0")==0){
+ myregister->rwmask=0;
+ }else{
+ myregister->rwmask=(pcilib_register_value_t)strtol((char*)rwmask,&ptr,0);
+ }
+
+ if(strcmp((char*)mode,"R")==0){
+ myregister->mode=PCILIB_REGISTER_R;
+ }else if(strcmp((char*)mode,"W")==0){
+ myregister->mode=PCILIB_REGISTER_W;
+ }else if(strcmp((char*)mode,"RW")==0){
+ myregister->mode=PCILIB_REGISTER_RW;
+ }else if(strcmp((char*)mode,"W")==0){
+ myregister->mode=PCILIB_REGISTER_W;
+ }else if(strcmp((char*)mode,"RW1C")==0){
+ myregister->mode=PCILIB_REGISTER_RW1C;
+ }else if(strcmp((char*)mode,"W1C")==0){
+ myregister->mode=PCILIB_REGISTER_W1C;
+ }
+
+ if(strcmp((char*)type,"standard")==0){
+ myregister->type=PCILIB_REGISTER_STANDARD;
+ }else if(strcmp((char*)type,"bits")==0){
+ myregister->type=PCILIB_REGISTER_BITS;
+ }else if(strcmp((char*)type,"fifo")==0){
+ myregister->type=PCILIB_REGISTER_FIFO;
+ }
+
+ if(strcmp((char*)bank,"bank 0")==0){
+ myregister->bank=PCILIB_REGISTER_BANK0;
+ }else if(strcmp((char*)bank,"bank 1")==0){
+ myregister->bank=PCILIB_REGISTER_BANK1;
+ }else if(strcmp((char*)bank,"bank 2")==0){
+ myregister->bank=PCILIB_REGISTER_BANK2;
+ }else if(strcmp((char*)bank,"bank 3")==0){
+ myregister->bank=PCILIB_REGISTER_BANK3;
+ }else if(strcmp((char*)bank,"DMA bank")==0){
+ myregister->bank=PCILIB_REGISTER_BANK_DMA;
+ }else if (strcmp((char*)bank,"dynamic bank")==0){
+ myregister->addr=PCILIB_REGISTER_BANK_DYNAMIC;
+ }else{
+ myregister->bank=PCILIB_REGISTER_BANK_INVALID;
+ }
+
+ myregister->name=(char*)name;
+ myregister->description=(char*)description;
+ /*should we include those xmlnodes?*/
+ //myregister->xmlNode=node;
+}
+
+/** pcilib_xml_getnumberbanks
+ *
+ * get the number of banks nodes in the AST, used to have some malloc in pci
+ * @param[in] doc the Xpath context of the xml file.
+ * @return the number of banks.
+ */
+int pcilib_xml_getnumberbanks(xmlXPathContextPtr doc){
+ xmlNodeSetPtr nodesetadress=NULL;
+ xmlXPathObjectPtr temp;
+ temp=pcilib_xml_getsetproperty(doc,BANK_ADDR_PATH); /**< we first get a structure containing all the banks nodes*/
+ if(temp!=NULL) nodesetadress=temp->nodesetval;
+ else pcilib_error("no bank in the xml file");
+ return nodesetadress->nodeNr; /**< we then return the number of said nodes */
+}
+
+/** pcilib_xml_initialize_banks
+ *
+ * function to create the structures to store the banks from the AST
+ * @see pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank,xmlChar* adress, xmlChar *bar, xmlChar *size, xmlChar *protocol,xmlChar *read_addr, xmlChar *write_addr, xmlChar *access, xmlChar *endianess, xmlChar *format, xmlChar *name,xmlChar *description, xmlNodePtr node).
+ * @param[in] doc the AST of the xml file.
+ * @param[in,out] mybanks the structure containing the banks.
+ */
+void pcilib_xml_initialize_banks(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;
+
+ xmlXPathContextPtr context;
+ context=pcilib_xml_getcontext(doc);
+
+ int i;
+
+ mynode=malloc(sizeof(xmlNode));
+
+ 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*/
+ 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");
+
+ temp=pcilib_xml_getsetproperty(context,BANK_BAR_PATH);
+ if(temp!=NULL) nodesetbar=temp->nodesetval;
+ else pcilib_error("there is no bar for banks in the xml");
+
+ temp=pcilib_xml_getsetproperty(context,BANK_SIZE_PATH);
+ if(temp!=NULL) nodesetsize=temp->nodesetval;
+ else pcilib_error("there is no size for banks in the xml");
+
+ temp=pcilib_xml_getsetproperty(context,BANK_PROTOCOL_PATH);
+ if(temp!=NULL) nodesetprotocol= temp->nodesetval;
+ else pcilib_error("there is no protocol for banks in the xml");
+
+ temp=pcilib_xml_getsetproperty(context,BANK_READ_ADDR_PATH);
+ if(temp!=NULL) nodesetread_addr=temp->nodesetval;
+ else pcilib_error("there is no read_adress for banks in the xml");
+
+ temp=pcilib_xml_getsetproperty(context,BANK_WRITE_ADDR_PATH);
+ if(temp!=NULL)nodesetwrite_addr=temp->nodesetval;
+ else pcilib_error("there is no write_adress for banks in the xml");
+
+ temp=pcilib_xml_getsetproperty(context,BANK_ACCESS_PATH);
+ if(temp!=NULL)nodesetaccess=temp->nodesetval;
+ else pcilib_error("there is no access for banks in the xml");
+
+ temp=pcilib_xml_getsetproperty(context,BANK_ENDIANESS_PATH);
+ if(temp!=NULL) nodesetendianess=temp->nodesetval;
+ else pcilib_error("there is no endianess for banks in the xml");
+
+ temp=pcilib_xml_getsetproperty(context,BANK_FORMAT_PATH);
+ if(temp!=NULL) nodesetformat=temp->nodesetval;
+ else pcilib_error("there is no format for banks in the xml");
+
+ temp=pcilib_xml_getsetproperty(context,BANK_NAME_PATH);
+ if(temp!=NULL)nodesetname=temp->nodesetval;
+ else pcilib_error("there is no name for banks in the xml");
+
+ temp=pcilib_xml_getsetproperty(context,BANK_DESCRIPTION_PATH);
+ if(temp!=NULL)nodesetdescription=temp->nodesetval;
+
+ for(i=0;i<nodesetadress->nodeNr;i++){
+ /** we then get each node from the structures above*/
+ adress=xmlNodeListGetString(doc,nodesetadress->nodeTab[i]->xmlChildrenNode, 1);
+ bar=xmlNodeListGetString(doc,nodesetbar->nodeTab[i]->xmlChildrenNode, 1);
+ size=xmlNodeListGetString(doc,nodesetsize->nodeTab[i]->xmlChildrenNode, 1);
+ protocol=xmlNodeListGetString(doc,nodesetprotocol->nodeTab[i]->xmlChildrenNode, 1);
+ read_addr=xmlNodeListGetString(doc,nodesetread_addr->nodeTab[i]->xmlChildrenNode, 1);
+ write_addr=xmlNodeListGetString(doc,nodesetwrite_addr->nodeTab[i]->xmlChildrenNode, 1);
+ access=xmlNodeListGetString(doc,nodesetaccess->nodeTab[i]->xmlChildrenNode, 1);
+ endianess=xmlNodeListGetString(doc,nodesetendianess->nodeTab[i]->xmlChildrenNode, 1);
+ format=xmlNodeListGetString(doc,nodesetformat->nodeTab[i]->xmlChildrenNode, 1);
+ name=xmlNodeListGetString(doc,nodesetname->nodeTab[i]->xmlChildrenNode, 1);
+ description=xmlNodeListGetString(doc,nodesetdescription->nodeTab[i]->xmlChildrenNode, 1);
+
+ mynode=nodesetadress->nodeTab[i]->parent;
+ /** 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,mynode);
+ mybanks[i]=mybank;
+ }
+
+}
+
+/** pcilib_xml_create_bank
+ *
+ * this function create a bank structure from the results of xml parsing
+ * @param[out] mybank the created bank.
+ * @param[in] adress the adress of the bank that will be created.
+ * @param[in] bar the bar of the bank that will be created.
+ * @param[in] size the size of the bank that will be created.
+ * @param[in] protocol the protocol of the bank that will be created.
+ * @param[in] read_addr the read adress for protocol of the bank that will be created.
+ * @param[in] write_addr the write adress for the protocol of the bank that will be created.
+ * @param[in] access the word size of the bank that will be created.
+ * @param[in] endianess the endianess of the bank that will be created.
+ * @param[in] format the format of the bank that will be created.
+ * @param[in] name the name of the bank that will be created.
+ * @param[in] description the description of the bank that will be created.
+ * @param[in] node the xmlNodeptr referring to the bank_description node of the bank that will be created.
+ */
+void pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank,xmlChar* adress, xmlChar *bar, xmlChar *size, xmlChar *protocol, xmlChar *read_addr, xmlChar *write_addr, xmlChar *access, xmlChar *endianess, xmlChar *format, xmlChar *name,xmlChar *description, xmlNodePtr node){
+
+ char* ptr;
+
+ /** we recreate each sub property of banks' structure given the results of xml parsing
+ note : strtol is used here to get hexadecimal and decimal values from the xml file as well*/
+
+ if (strcmp((char*)adress,"bank 0")==0){
+ mybank->addr=PCILIB_REGISTER_BANK0;
+ }else if (strcmp((char*)adress,"bank 1")==0){
+ mybank->addr=PCILIB_REGISTER_BANK1;
+ }else if (strcmp((char*)adress,"bank 2")==0){
+ mybank->addr=PCILIB_REGISTER_BANK2;
+ }else if (strcmp((char*)adress,"bank 3")==0){
+ mybank->addr=PCILIB_REGISTER_BANK3;
+ }else if (strcmp((char*)adress,"DMA bank")==0){
+ mybank->addr=PCILIB_REGISTER_BANK_DMA;
+ }else if (strcmp((char*)adress,"DMAconf bank")==0){
+ mybank->addr=PCILIB_REGISTER_BANK_DMACONF;
+ }else if (strcmp((char*)adress,"dynamic bank")==0){
+ mybank->addr=PCILIB_REGISTER_BANK_DYNAMIC;
+ }else{
+ mybank->addr=PCILIB_REGISTER_BANK_INVALID;
+ }
+
+ if(strcmp((char*)bar,"0")==0){
+ mybank->bar=PCILIB_BAR0;
+ }else if(strcmp((char*)bar,"ipecamera_register")==0){
+ mybank->bar=PCILIB_BAR1;
+ }
+
+ mybank->bar=(pcilib_bar_t)strtol((char*)bar,&ptr,0);
+ mybank->size=(size_t)strtol((char*)size,&ptr,0);
+
+ if(strcmp((char*)protocol,"default")==0){
+ mybank->protocol=PCILIB_REGISTER_PROTOCOL_DEFAULT;
+ }else if(strcmp((char*)protocol,"0")==0){
+ mybank->protocol=PCILIB_REGISTER_PROTOCOL0;
+ }else if(strcmp((char*)protocol,"dma")==0){
+ mybank->protocol=PCILIB_REGISTER_PROTOCOL_DMA;
+ }else if(strcmp((char*)protocol,"dynamic")==0){
+ mybank->protocol=PCILIB_REGISTER_PROTOCOL_DYNAMIC;
+ }else if (strcmp((char*)protocol,"software")==0){
+ mybank->protocol=PCILIB_REGISTER_PROTOCOL_SOFTWARE;
+ }else mybank->protocol=PCILIB_REGISTER_PROTOCOL_INVALID;
+
+ mybank->read_addr=(uintptr_t)strtol((char*)read_addr,&ptr,0);
+ mybank->write_addr=(uintptr_t)strtol((char*)write_addr,&ptr,0);
+ mybank->access=(uint8_t)strtol((char*)access,&ptr,0);
+
+ if(strcmp((char*)endianess,"little")==0){
+ mybank->endianess=PCILIB_LITTLE_ENDIAN;
+ }else if(strcmp((char*)endianess,"big")==0){
+ mybank->endianess=PCILIB_BIG_ENDIAN;
+ }else if(strcmp((char*)endianess,"host")==0){
+ mybank->endianess=PCILIB_HOST_ENDIAN;
+ }
+
+ mybank->raw_endianess=mybank->endianess;
+
+ mybank->name=(char*)name;
+ mybank->description=(char*)description;
+ /* to include or not?*/
+ //mybank->xmlNode=node;
+}
+
+
+/** pcilib_xml_getnumberregisters
+ *
+ * get the number of registers in the xml document, for further mallocs
+ * @param[in] doc the xpath context of the xml file.
+ * @return the numbers of registers in xml file.
+ */
+int pcilib_xml_getnumberregisters(xmlXPathContextPtr doc){
+ xmlNodeSetPtr nodesetadress=NULL,nodesetsuboffset=NULL;
+ xmlXPathObjectPtr temp,temp2;
+ temp=pcilib_xml_getsetproperty(doc,ADRESS_PATH); /**<we get the structure with all standards registers here*/
+ if(temp!=NULL) nodesetadress=temp->nodesetval; /**<we get the structure with all standards registers here*/
+ else {
+ pcilib_error("no registers found in the xml file");
+ return 0;
+ }
+
+ temp2=pcilib_xml_getsetproperty(doc,SUB_OFFSET_PATH);/**< we get the structure with all bits registers here */
+ if(temp2!=NULL) nodesetsuboffset=temp2->nodesetval;/**< we get the structure with all bits registers here */
+ else nodesetsuboffset->nodeNr=0;
+ return nodesetadress->nodeNr + nodesetsuboffset->nodeNr; /**<we sum the number of nodes in the first structure to the number of nodes in the second one*/
+}
+
+/** pcilib_xml_initialize_registers
+ *
+ * this function create a list of registers from an abstract syntax tree
+ *
+ * variables who need change if xml structure change : bank,description, sub_description, sub_adress, sub_bank, sub_rwmask (we consider it to be equal to the standard register), sub_defvalue(same to standard register normally)
+ * @param[in] doc the xpath context of the xml file.
+ * @param[in,out] registers in: initialized list out: the list of the created registers.
+ */
+void pcilib_xml_initialize_registers(xmlDocPtr doc,pcilib_register_description_t *registers){
+
+ xmlNodeSetPtr nodesetadress=NULL,nodesetoffset=NULL,nodesetdefvalue=NULL,nodesetrwmask=NULL,nodesetsize=NULL,nodesetmode=NULL,nodesetname=NULL;
+ xmlChar *adress=NULL,*offset=NULL,*defvalue=NULL,*rwmask=NULL,*size=NULL,*mode=NULL,*name=NULL,*bank=NULL,*type=NULL,*description=NULL;
+ xmlNodePtr mynode;
+ xmlNodePtr tempnode;
+ xmlXPathContextPtr context;
+ context=pcilib_xml_getcontext(doc);
+
+ mynode=malloc(sizeof(xmlNode));
+
+ xmlXPathObjectPtr temp;
+
+ /** get the sructures containing each property of standard regsiter */
+ temp=pcilib_xml_getsetproperty(context,ADRESS_PATH);
+ if(temp!=NULL)nodesetadress=temp->nodesetval;
+ else pcilib_error("no adress for registers found in xml");
+
+ temp=pcilib_xml_getsetproperty(context,OFFSET_PATH);
+ if(temp!=NULL)nodesetoffset=temp->nodesetval;
+ else pcilib_error("no offset for registers found in xml");
+
+ temp=pcilib_xml_getsetproperty(context,DEFVALUE_PATH);
+ if(temp!=NULL)nodesetdefvalue=temp->nodesetval;
+ else pcilib_error("no defvalue for registers found in xml");
+
+ temp=pcilib_xml_getsetproperty(context,RWMASK_PATH);
+ if(temp!=NULL)nodesetrwmask=temp->nodesetval;
+ else pcilib_error("no rwmask for registers found in xml");
+
+ temp=pcilib_xml_getsetproperty(context,SIZE_PATH);
+ if(temp!=NULL)nodesetsize=temp->nodesetval;
+ else pcilib_error("no size for registers found in xml");
+
+ temp=pcilib_xml_getsetproperty(context,MODE_PATH);
+ if(temp!=NULL)nodesetmode=temp->nodesetval;
+ else pcilib_error("no mode for registers found in xml");
+
+ temp=pcilib_xml_getsetproperty(context,NAME_PATH);
+ if(temp!=NULL)nodesetname=temp->nodesetval;
+ else pcilib_error("no name for registers found in xml");
+
+ xmlNodeSetPtr nodesetsuboffset=NULL,nodesetsubsize=NULL,nodesetsubmode=NULL,nodesetsubname=NULL;
+ xmlChar *subadress=NULL,*suboffset=NULL,*subdefvalue=NULL,*subrwmask=NULL,*subsize=NULL,*submode=NULL,*subname=NULL,*subbank=NULL,*subtype=NULL,*subdescription=NULL;
+
+ /**get the structures containing each property of bits registers */
+ temp=pcilib_xml_getsetproperty(context,SUB_OFFSET_PATH);
+ if(temp!=NULL)nodesetsuboffset=temp->nodesetval;
+ else pcilib_error("no offset for registers bits found in xml");
+
+ temp=pcilib_xml_getsetproperty(context,SUB_SIZE_PATH);
+ if(temp!=NULL)nodesetsubsize=temp->nodesetval;
+ else pcilib_error("no size for registers bits found in xml");
+
+ temp=pcilib_xml_getsetproperty(context,SUB_MODE_PATH);
+ if(temp!=NULL)nodesetsubmode=temp->nodesetval;
+ else pcilib_error("no mode for registers bits found in xml");
+
+ temp=pcilib_xml_getsetproperty(context,SUB_NAME_PATH);
+ if(temp!=NULL)nodesetsubname=temp->nodesetval;
+ else pcilib_error("no name for registers bits found in xml");
+
+
+ pcilib_register_description_t myregister;
+
+ int i,j;
+
+ for(i=0;i<nodesetadress->nodeNr;i++){
+ /** get each sub property of each standard registers*/
+ adress=xmlNodeListGetString(doc,nodesetadress->nodeTab[i]->xmlChildrenNode, 1);
+ tempnode=xmlFirstElementChild(xmlFirstElementChild(nodesetadress->nodeTab[i]->parent->parent->parent));
+ if(strcmp("adress",(char*)tempnode->name)==0) bank=xmlNodeListGetString(doc,tempnode->xmlChildrenNode,1);
+ else pcilib_error("the xml file is malformed");
+ offset=xmlNodeListGetString(doc,nodesetoffset->nodeTab[i]->xmlChildrenNode, 1);
+ size=xmlNodeListGetString(doc,nodesetsize->nodeTab[i]->xmlChildrenNode, 1);
+ defvalue=xmlNodeListGetString(doc,nodesetdefvalue->nodeTab[i]->xmlChildrenNode, 1);
+ rwmask=xmlNodeListGetString(doc,nodesetrwmask->nodeTab[i]->xmlChildrenNode, 1);
+ mode=xmlNodeListGetString(doc,nodesetmode->nodeTab[i]->xmlChildrenNode, 1);
+ name=xmlNodeListGetString(doc,nodesetname->nodeTab[i]->xmlChildrenNode, 1);
+ type=(xmlChar*)"standard";
+ if(nodesetname->nodeTab[i]->next->next!= NULL && strcmp((char*)nodesetname->nodeTab[i]->next->next->name,"description")==0){
+ description=xmlNodeListGetString(doc,nodesetname->nodeTab[i]->next->next->xmlChildrenNode,1);
+ }else{
+ description=(xmlChar*)"";
+ }
+ mynode=nodesetadress->nodeTab[i]->parent;
+ /**creation of a register with the given previous properties*/
+ pcilib_xml_create_register(&myregister,adress,offset,size,defvalue,rwmask,mode, type, bank, name, description,mynode);
+ registers[i]=myregister;
+ }
+
+ j=i;
+
+ for(i=0;i<nodesetsuboffset->nodeNr;i++){
+ /** we get there each subproperty of each bits register*/
+ tempnode=xmlFirstElementChild(nodesetsuboffset->nodeTab[i]->parent->parent->parent);
+ if(strcmp((char*)tempnode->name,"adress")==0)subadress=xmlNodeListGetString(doc,tempnode->xmlChildrenNode, 1);
+ else pcilib_error("xml file is malformed");
+ tempnode= xmlFirstElementChild(xmlFirstElementChild(nodesetsuboffset->nodeTab[i]->parent->parent->parent->parent->parent));
+ if(strcmp((char*)tempnode->name,"adress")==0) subbank=xmlNodeListGetString(doc,tempnode->xmlChildrenNode,1);
+ else pcilib_error("xml file is malformed");
+ suboffset=xmlNodeListGetString(doc,nodesetsuboffset->nodeTab[i]->xmlChildrenNode, 1);
+ subsize=xmlNodeListGetString(doc,nodesetsubsize->nodeTab[i]->xmlChildrenNode, 1);
+ tempnode=xmlFirstElementChild(nodesetsuboffset->nodeTab[i]->parent->parent->parent)->next->next->next->next->next->next;
+ if(strcmp((char*)tempnode->name,"default")==0)subdefvalue=xmlNodeListGetString(doc,tempnode->xmlChildrenNode, 1);
+ else pcilib_error("xml file is malformed");
+ subrwmask=xmlNodeListGetString(doc,nodesetsuboffset->nodeTab[i]->parent->parent->prev->prev->prev->prev->prev->prev->xmlChildrenNode, 1);
+ submode=xmlNodeListGetString(doc,nodesetsubmode->nodeTab[i]->xmlChildrenNode, 1);
+ subname=xmlNodeListGetString(doc,nodesetsubname->nodeTab[i]->xmlChildrenNode, 1);
+ subtype=(xmlChar*)"bits";
+ if(nodesetsubname->nodeTab[i]->next->next!= NULL && strcmp((char*)nodesetsubname->nodeTab[i]->next->next->name,"sub_description")==0){
+ subdescription=xmlNodeListGetString(doc,nodesetsubname->nodeTab[i]->next->next->xmlChildrenNode,1);
+ }else{
+ subdescription=(xmlChar*)"";
+ }
+ mynode=nodesetsuboffset->nodeTab[i]->parent;
+ /** creation of a bits register given the previous properties*/
+ pcilib_xml_create_register(&myregister,subadress,suboffset,subsize,subdefvalue,subrwmask,submode, subtype, subbank, subname, subdescription,mynode);
+ registers[i+j]=myregister;
+ }
+}
+
+
+/*
+ * 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;j++){
+ if((i0 < middle) && (i1>=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<end;k++) A[k]=B[k];
+}
+
+void topdownsplitmerge(pcilib_register_description_t *A, int start, int end, pcilib_register_description_t *B){
+ int middle;
+ if(end-start <2)
+ return;
+
+ middle =(end+start)/2;
+ topdownsplitmerge(A,start, middle,B);
+ topdownsplitmerge(A,middle,end,B);
+ topdownmerge(A,start,middle,end,B);
+ copyarray(B,start,end,A);
+}
+
+/** pcilib_xml_arrange_registers
+ *
+ * after the complete structure containing the registers has been created from the xml, this function rearrange them by address in order to add them in pcilib_open, which consider the adding of registers in order of adress
+ * @param[in,out] registers the list of registers in : not ranged out: ranged.
+ * @param[in] size the number of registers.
+ */
+void pcilib_xml_arrange_registers(pcilib_register_description_t *registers,int size){
+ pcilib_register_description_t* temp;
+ temp=malloc(size*sizeof(pcilib_register_description_t));
+ topdownsplitmerge(registers,0,size,temp);
+}
+
+#include <libxml/xmlschemastypes.h>
+/** validation
+ *
+ * function to validate the xml file against the xsd, so that it does not require extern software
+ */
+void validation()
+{
+xmlDocPtr doc;
+xmlSchemaPtr schema = NULL;
+xmlSchemaParserCtxtPtr ctxt;
+
+char *XMLFileName;
+ pcilib_xml_read_config(&XMLFileName,3);
+char *XSDFileName;
+ pcilib_xml_read_config(&XSDFileName,12);
+int ret=1;
+
+ctxt = xmlSchemaNewParserCtxt(XSDFileName);
+
+schema = xmlSchemaParse(ctxt);
+xmlSchemaFreeParserCtxt(ctxt);
+
+doc = xmlReadFile(XMLFileName, NULL, 0);
+
+if (doc == NULL)
+{
+ pcilib_error("Could not parse xml document ");
+}
+else
+{
+xmlSchemaValidCtxtPtr ctxt;
+/** validation here*/
+ctxt = xmlSchemaNewValidCtxt(schema);
+ret = xmlSchemaValidateDoc(ctxt, doc);
+xmlSchemaFreeValidCtxt(ctxt);
+xmlFreeDoc(doc);
+}
+
+//! free the resource
+if(schema != NULL)
+xmlSchemaFree(schema);
+
+xmlSchemaCleanupTypes();
+/** print results */
+if (ret == 0)
+{
+ printf("xml file validates\n");
+}
+else
+{
+ printf("xml file does not validate against the schema\n");
+}
+
+}
+
+/** pcilib_xml_read_config
+ *
+ * function to get the config we want at line j, in order to be able to have a configuration file with pwd to files we want
+* @param[in,out] xmlfile the string representating a pwd to a file we want to access in:uninitilized out: the pwd.
+* @param[in] i the line at which the function should read the file to get the pwd.
+ */
+void pcilib_xml_read_config(char** xmlfile, int j){
+ FILE *fp;
+
+ fp=fopen("config.txt","r");
+ char line[60];
+ memset(line,'\0',60);
+ int i=0,k;
+ char *temp1;
+ if(fp==NULL) pcilib_error("can't find the configuration file: it must be near the executable");
+
+ while(fgets(line,60,fp)!=NULL){
+ if(i==j) {
+ k=0;
+ temp1=calloc((strlen(line)),sizeof(char));
+ while(line[k]!='\n'){
+ temp1[k]=line[k];
+ k++;
+ }
+ temp1[k]='\0';
+ *xmlfile=temp1;
+ }
+ i++;
+ 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;
+
+}
+*/
diff --git a/pcilib/xml.h b/pcilib/xml.h
new file mode 100644
index 0000000..da540b5
--- /dev/null
+++ b/pcilib/xml.h
@@ -0,0 +1,208 @@
+/**
+ * @file xml.h
+ * @version 1.0
+ * @brief header file to support of xml configuration.
+ *
+ * @details this file is the header file for the implementation of dynamic registers using xml and several funtionalities for the "pci-tool" line command tool from XML files. the xml part has been implemented using libxml2.
+ *
+ * this code was meant to be evolutive as the XML files evolute. In this meaning, most of the xml parsing is realized with XPath expressions(when it was possible), so that changing the xml xould result mainly in changing the XPAth pathes present here.
+ * @todo cf compilation chain
+ */
+
+#ifndef _XML_
+#define _XML_
+
+//#include <stdlib.h>
+//#include <stdio.h>
+//#include <string.h>
+//#include <assert.h>
+
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+
+#include "pcilib.h"
+#include "register.h"
+#include "model.h"
+#include "bank.h"
+
+//#include <Python.h>
+
+#define REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register") /**<all standard registers nodes.*/
+
+#define ADRESS_PATH ((xmlChar*)"/model/banks/bank/registers/register/adress") /**<adress path for standard registers.*/
+#define OFFSET_PATH ((xmlChar*)"/model/banks/bank/registers/register/offset") /**<offset path for standard registers.*/
+#define SIZE_PATH ((xmlChar*)"/model/banks/bank/registers/register/size") /**<size path for standard registers.*/
+#define DEFVALUE_PATH ((xmlChar*)"/model/banks/bank/registers/register/default") /**<defvalue path for standard registers.*/
+#define RWMASK_PATH ((xmlChar*)"/model/banks/bank/registers/register/rwmask") /**<rwmask path for standard registers.*/
+#define MODE_PATH ((xmlChar*)"/model/banks/bank/registers/register/mode") /**<mode path for standard registers.*/
+#define NAME_PATH ((xmlChar*)"/model/banks/bank/registers/register/name") /**<name path for standard registers.*/
+#define DESCRIPTION_PATH ((xmlChar*)"/model/banks/bank/registers/register/description") /**<description. not used, is searched recursively as it may not appearing in xml. */
+
+#define SUB_OFFSET_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits/offset") /**<offset path for bits registers.*/
+#define SUB_SIZE_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits/size") /**<size path for bits registers.*/
+#define SUB_RWMASK_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits/sub_rwmask") /**<rwmask path for bits registers. not used, as the value is meant to be the same as the standard register this register depends on.*/
+#define SUB_MODE_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits/mode") /**<size path for bits registers.*/
+#define SUB_NAME_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits/name") /**<name path for bits registers.*/
+#define SUB_DESCRIPTION_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits/adress") /**<description path for bits registers. not used, is searched recursively as it may not appear in the xml.*/
+
+#define VIEW_FORMULA_PATH ((xmlChar*)"/model/views/view[@type=\"formula\"]") /**< the complete node path for views of type formula.*/
+#define VIEW_FORMULA_FORMULA_PATH ((xmlChar*)"/model/views/view[@type=\"formula\"]/read_from_register") /**< path to formula in direction read_from_register for views of type formula.*/
+#define VIEW_FORMULA_REVERSE_FORMULA_PATH ((xmlChar*)"/model/views/view[@type=\"formula\"]/write_to_register") /**< path to formula in direction write_to_register for views of type formula.*/
+#define VIEW_FORMULA_UNIT_PATH ((xmlChar*)"/model/views/view[@type=\"formula\"]/unit") /**< path to the base unit of the view of type formula. */
+#define VIEW_FORMULA_NAME_PATH ((xmlChar*)"/model/views/view[@type=\"formula\"]/name") /**<path to the name of the view of type formula.*/
+
+#define VIEW_ENUM_PATH ((xmlChar*)"/model/views/view[@type=\"enum\"]") /**< the complete node path for views of type enum.*/
+
+#define VIEW_BITS_REGISTER ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits/views/view") /**< @warning not used normally.*/
+#define VIEW_STANDARD_REGISTER ((xmlChar*)"/model/banks/bank/registers/register/views/view") /**< @warning not used too.*/
+#define VIEW_STANDARD_REGISTER_PLUS ((char*)"/model/banks/bank/registers/register/views/view[.=\"%s\"]") /**< path to the standard registers that depend on the given view.*/
+#define VIEW_BITS_REGISTER_PLUS ((char*)"/model/banks/bank/registers/register/registers_bits/register_bits/views/view[.=\"%s\"]") /**< path to the bits registers that depend on the given view.*/
+
+#define BANKS_PATH ((xmlChar*)"/model/banks/bank/bank_description") /**< path to complete nodes of banks.*/
+#define BANK_ADDR_PATH ((xmlChar*)"/model/banks/bank/bank_description/adress") /**<path to adress of banks.*/
+#define BANK_BAR_PATH ((xmlChar*)"/model/banks/bank/bank_description/bar") /**<path to bar of banks.*/
+#define BANK_SIZE_PATH ((xmlChar*)"/model/banks/bank/bank_description/size") /**<path to size of banks.*/
+#define BANK_PROTOCOL_PATH ((xmlChar*)"/model/banks/bank/bank_description/protocol") /**< path to protocol of banks.*/
+#define BANK_READ_ADDR_PATH ((xmlChar*)"/model/banks/bank/bank_description/read_adress") /**<path to read_addr of banks.*/
+#define BANK_WRITE_ADDR_PATH ((xmlChar*)"/model/banks/bank/bank_description/write_adress") /**<path to write_addr of banks.*/
+#define BANK_RAW_ENDIANESS_PATH ((xmlChar*)"/model/banks/bank/bank_description/raw_endianess") /**<path to raw_endianess of banks.*/
+#define BANK_ACCESS_PATH ((xmlChar*)"/model/banks/bank/bank_description/word_size") /**<path to word_size of banks.*/
+#define BANK_ENDIANESS_PATH ((xmlChar*)"/model/banks/bank/bank_description/endianess") /**<path to endianess of banks.*/
+#define BANK_FORMAT_PATH ((xmlChar*)"/model/banks/bank/bank_description/format") /**<path to format of banks.*/
+#define BANK_NAME_PATH ((xmlChar*)"/model/banks/bank/bank_description/name") /**< path to name of banks.*/
+#define BANK_DESCRIPTION_PATH ((xmlChar*)"/model/banks/bank/bank_description/description") /**<path to description of banks.*/
+
+#define UNIT_PATH ((char*)"/units/unit[@name=\"%s\"]/convert_unit[@value=\"%s\"]") /**< path to get possible units for a view in units xml file.*/
+
+/**
+ * this type is used to save enough information in the pcilib_watch_to_read_with_enum function to get a good output in human readable form.
+ */
+typedef struct{
+ int val; /**< value of a register corresponding to an enum value.*/
+ char* name; /**< name of the corresponding command to val.*/
+}info_enum;
+
+/**
+* this function takes a string and will create an abtract syntax tree from the xml file represented by the string.
+* @param[in] filename the name of the xml file containing registers and banks.
+* @return an AST corresponding to the xml file.
+*/
+xmlDocPtr pcilib_xml_getdoc(char* filename);
+
+/**
+* this function takes a context from an AST and an XPath expression, to produce a XPath object containing the nodes corresponding to the xpath expression.
+* @param[in] doc the xpath context of the xml file.
+* @param[in] xpath the value of the xpath expression that will be computed against the context.
+* @return the Xpath object with the nodes we wanted.
+*/
+xmlXPathObjectPtr pcilib_xml_getsetproperty(xmlXPathContextPtr doc, xmlChar *xpath);
+
+/**
+ * this function create the list of registers structures, that are manipulated during execution, from the xml file.
+ * @param[in] doc the xpath context of the xml file.
+ * @param[out] registers out: the list of the created registers.
+ */
+void pcilib_xml_initialize_registers(xmlDocPtr doc,pcilib_register_description_t *registers);
+
+/**
+ * this function get the numbers of registers in the xml file for further malloc and xml checking.
+ * @param[in] doc the xpath context of the xml file.
+ * @return the numbers of registers in xml file.
+ * @todo see the usage of this function.
+ */
+int pcilib_xml_getnumberregisters(xmlXPathContextPtr doc);
+
+/**
+ * this function rearrange the list of registers to put them in pcilib_open furthermore, using a merge sort algorithm. The merge sort algorithm was chosen as it's fast and stable, however it uses some memory, but it's not limitating here.
+ * @param[in,out] registers the list of registers in : not ranged out: ranged.
+ * @param[in] size the number of registers.
+ */
+void pcilib_xml_arrange_registers(pcilib_register_description_t *registers,int size);
+
+/**
+ * this functions initialize the structures containing banks, for use in the rest of execution, from the xml file.
+ * @see pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank,xmlChar* adress, xmlChar *bar, xmlChar *size, xmlChar *protocol,xmlChar *read_addr, xmlChar *write_addr, xmlChar *access, xmlChar *endianess, xmlChar *format, xmlChar *name,xmlChar *description, xmlNodePtr node).
+ * @param[in] doc the AST of the xml file.
+ * @param[in,out] mybanks the structure containing the banks.
+ */
+void pcilib_xml_initialize_banks(xmlDocPtr doc, pcilib_register_bank_description_t* mybanks);
+
+/**
+ * this function create a bank from the informations gathered in the xml.
+ * @param[out] mybank the created bank.
+ * @param[in] adress the adress of the bank that will be created.
+ * @param[in] bar the bar of the bank that will be created.
+ * @param[in] size the size of the bank that will be created.
+ * @param[in] protocol the protocol of the bank that will be created.
+ * @param[in] read_addr the read adress for protocol of the bank that will be created.
+ * @param[in] write_addr the write adress for the protocol of the bank that will be created.
+ * @param[in] access the word size of the bank that will be created.
+ * @param[in] endianess the endianess of the bank that will be created.
+ * @param[in] format the format of the bank that will be created.
+ * @param[in] name the name of the bank that will be created.
+ * @param[in] description the description of the bank that will be created.
+ * @param[in] node the xmlNodeptr referring to the bank_description node of the bank that will be created.
+ */
+void pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank,xmlChar* adress, xmlChar *bar, xmlChar *size, xmlChar *protocol,xmlChar *read_addr, xmlChar *write_addr, xmlChar *access, xmlChar *endianess, xmlChar *format, xmlChar *name,xmlChar *description, xmlNodePtr node);
+
+/**
+ * this function get the numbers of banks in the xml file for further malloc and xml checking.
+ * @param[in] doc the Xpath context of the xml file.
+ * @return the number of banks.
+ *@todo see the usage of this function.
+ */
+int pcilib_xml_getnumberbanks(xmlXPathContextPtr doc);
+
+/**
+* this function read the config file of the pcitool tool to give back the pwd of diverse files like the xml file to treat, the xsd file, the pythonscript file, the units xml file, the units xsd file.
+* @param[in,out] xmlfile the string representating a pwd to a file we want to access in:uninitilized out: the pwd.
+* @param[in] i the line at which the function should read the file to get the pwd.
+*/
+void pcilib_xml_read_config(char** xmlfile, int i);
+
+/**
+* this function validates the xml file against the xsd schema defined as the reference.
+* @todo change the name of the function if accepted.
+* @todo validation of unit file too?
+*/
+void validation();
+
+
+/**
+* this function create an XPath context (ie some sort of special AST only for XPath) from the AST of the xml file.
+* @param[in] doc the AST of the xml file.
+*/
+xmlXPathContextPtr pcilib_xml_getcontext(xmlDocPtr doc);
+
+/**
+* this function is used to register the xpath object containing all registers node in registers context.
+* @param[in] ctx the register context running.
+*/
+void pcilib_xml_init_nodeset_register_ctx(pcilib_register_context_t *ctx);
+
+/**
+* this function is used to register the xpath object containing all bankss node in banks context.
+* @param[in] ctx the bank context running.
+*/
+void pcilib_xml_init_nodeset_bank_ctx(pcilib_register_bank_context_t *ctx);
+
+/**
+ * this function create a register structure from the results of xml parsing.
+ * @param[out] myregister the register we want to create
+ * @param[in] adress the adress of the future register
+ * @param[in] offset the offset of the future register
+ * @param[in] size the size of the future register
+ * @param[in] defvalue the defaut value of the future register
+ * @param[in] rwmask the rwmask of the future register
+ * @param[in] mode the mode of the future register
+ * @param[in] type the type of the future register
+ * @param[in] bank the bank of the future register
+ * @param[in] name the name of the future register
+ * @param[in] description the description of the future register
+ * @param[in] node the current xmlNode in the xml of the future register
+ */
+void pcilib_xml_create_register(pcilib_register_description_t *myregister,xmlChar* adress, xmlChar *offset, xmlChar *size, xmlChar *defvalue, xmlChar *rwmask, xmlChar *mode, xmlChar *type, xmlChar *bank, xmlChar *name, xmlChar *description, xmlNodePtr node);
+
+#endif /*_XML_*/
diff --git a/pcitool/camera.xml b/pcitool/camera.xml
new file mode 100644
index 0000000..753c707
--- /dev/null
+++ b/pcitool/camera.xml
@@ -0,0 +1,923 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <banks>
+ <bank>
+ <bank_description>
+ <adress>bank 0</adress>
+ <bar>0</bar>
+ <size>128</size>
+ <protocol>default</protocol>
+ <read_adress>0x9010</read_adress>
+ <write_adress>0x9000</write_adress>
+ <word_size>8</word_size>
+ <endianess>little</endianess>
+ <format>%lu</format>
+ <name>cmosis</name>
+ <description>CMOSIS CMV2000 Registers</description>
+ </bank_description>
+ <registers>
+ <register>
+ <adress>1</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>1088</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_number_lines</name>
+ <description>test</description>
+ </register>
+ <register>
+ <adress>3</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_start1</name>
+ </register>
+ <register>
+ <adress>5</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_start2</name>
+ </register>
+ <register>
+ <adress>7</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_start3</name>
+ </register>
+ <register>
+ <adress>9</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_start4</name>
+ </register>
+ <register>
+ <adress>11</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_start5</name>
+ </register>
+ <register>
+ <adress>13</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_start6</name>
+ </register>
+ <register>
+ <adress>15</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_start7</name>
+ </register>
+ <register>
+ <adress>17</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_start8</name>
+ </register>
+ <register>
+ <adress>19</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_number_lines1</name>
+ </register>
+ <register>
+ <adress>21</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_number_lines2</name>
+ </register>
+ <register>
+ <adress>23</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_number_lines3</name>
+ </register>
+ <register>
+ <adress>25</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_number_lines4</name>
+ </register>
+ <register>
+ <adress>27</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_number_lines5</name>
+ </register>
+ <register>
+ <adress>29</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_number_lines6</name>
+ </register>
+ <register>
+ <adress>31</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_number_lines7</name>
+ </register>
+ <register>
+ <adress>33</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_number_lines8</name>
+ </register>
+ <register>
+ <adress>35</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_sub_s</name>
+ </register>
+ <register>
+ <adress>37</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_sub_a</name>
+ </register>
+ <register>
+ <adress>39</adress>
+ <offset>0</offset>
+ <size>1</size>
+ <default>1</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_color</name>
+ </register>
+ <register>
+ <adress>40</adress>
+ <offset>0</offset>
+ <size>2</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_image_flipping</name>
+ </register>
+ <register>
+ <adress>41</adress>
+ <offset>0</offset>
+ <size>2</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_exp_flags</name>
+ </register>
+ <register>
+ <adress>42</adress>
+ <offset>0</offset>
+ <size>24</size>
+ <default>1088</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_exp_time</name>
+ <views>
+ <view>formuu3</view>
+ <view>enumm3</view>
+ </views>
+ </register>
+ <register>
+ <adress>45</adress>
+ <offset>0</offset>
+ <size>24</size>
+ <default>1088</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_exp_step</name>
+ </register>
+ <register>
+ <adress>48</adress>
+ <offset>0</offset>
+ <size>24</size>
+ <default>1</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_exp_kp1</name>
+ </register>
+ <register>
+ <adress>51</adress>
+ <offset>0</offset>
+ <size>24</size>
+ <default>1</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_exp_kp2</name>
+ </register>
+ <register>
+ <adress>54</adress>
+ <offset>0</offset>
+ <size>2</size>
+ <default>1</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_nr_slopes</name>
+ </register>
+ <register>
+ <adress>55</adress>
+ <offset>0</offset>
+ <size>8</size>
+ <default>1</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_exp_seq</name>
+ </register>
+ <register>
+ <adress>56</adress>
+ <offset>0</offset>
+ <size>24</size>
+ <default>1088</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_exp_time2</name>
+ </register>
+ <register>
+ <adress>59</adress>
+ <offset>0</offset>
+ <size>24</size>
+ <default>1088</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_exp_step2</name>
+ </register>
+ <register>
+ <adress>68</adress>
+ <offset>0</offset>
+ <size>2</size>
+ <default>1</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_nr_slopes2</name>
+ </register>
+ <register>
+ <adress>69</adress>
+ <offset>0</offset>
+ <size>8</size>
+ <default>1</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_exp_seq2</name>
+ </register>
+ <register>
+ <adress>70</adress>
+ <offset>0</offset>
+ <size>16</size>
+ <default>1</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_number_frames</name>
+ </register>
+ <register>
+ <adress>72</adress>
+ <offset>0</offset>
+ <size>2</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_output_mode</name>
+ </register>
+ <register>
+ <adress>78</adress>
+ <offset>0</offset>
+ <size>12</size>
+ <default>85</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_training_pattern</name>
+ </register>
+ <register>
+ <adress>80</adress>
+ <offset>0</offset>
+ <size>18</size>
+ <default>0x3FFFF</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_channel_en</name>
+ </register>
+ <register>
+ <adress>82</adress>
+ <offset>0</offset>
+ <size>3</size>
+ <default>7</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_special_82</name>
+ </register>
+ <register>
+ <adress>89</adress>
+ <offset>0</offset>
+ <size>8</size>
+ <default>96</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_vlow2</name>
+ </register>
+ <register>
+ <adress>90</adress>
+ <offset>0</offset>
+ <size>8</size>
+ <default>96</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_vlow3</name>
+ </register>
+ <register>
+ <adress>100</adress>
+ <offset>0</offset>
+ <size>14</size>
+ <default>16260</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_offset</name>
+ </register>
+ <register>
+ <adress>102</adress>
+ <offset>0</offset>
+ <size>2</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_pga</name>
+ </register>
+ <register>
+ <adress>103</adress>
+ <offset>0</offset>
+ <size>8</size>
+ <default>32</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_adc_gain</name>
+ </register>
+ <register>
+ <adress>111</adress>
+ <offset>0</offset>
+ <size>1</size>
+ <default>1</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_bit_mode</name>
+ </register>
+ <register>
+ <adress>112</adress>
+ <offset>0</offset>
+ <size>2</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_adc_resolution</name>
+ </register>
+ <register>
+ <adress>115</adress>
+ <offset>0</offset>
+ <size>1</size>
+ <default>1</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>cmosis_special_115</name>
+ </register>
+ </registers>
+ </bank>
+ <bank>
+ <bank_description>
+ <adress>bank 1</adress>
+ <bar>0</bar>
+ <size>0x0200</size>
+ <protocol>default</protocol>
+ <read_adress>0x9000</read_adress>
+ <write_adress>0x9000</write_adress>
+ <word_size>32</word_size>
+ <endianess>little</endianess>
+ <format>0x%lx</format>
+ <name>fpga</name>
+ <description>IPECamera Registers</description>
+ </bank_description>
+ <registers>
+ <register>
+ <adress>0x00</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>spi_conf_input</name>
+ </register>
+ <register>
+ <adress>0x10</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>spi_conf_output</name>
+ </register>
+ <register>
+ <adress>0x20</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>spi_clk_speed</name>
+ </register>
+ <register>
+ <adress>0x30</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>firmware_info</name>
+ <registers_bits>
+ <register_bits>
+ <offset>0</offset>
+ <size>8</size>
+ <mode>R</mode>
+ <name>firmware_version</name>
+ </register_bits>
+ <register_bits>
+ <offset>8</offset>
+ <size>1</size>
+ <mode>R</mode>
+ <name>firmware_bitmode</name>
+ </register_bits>
+ <register_bits>
+ <offset>12</offset>
+ <size>2</size>
+ <mode>R</mode>
+ <name>adc_resolution</name>
+ </register_bits>
+ <register_bits>
+ <offset>16</offset>
+ <size>2</size>
+ <mode>R</mode>
+ <name>output_mode</name>
+ </register_bits>
+ </registers_bits>
+ </register>
+ <register>
+ <adress>0x40</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>control</name>
+ <registers_bits>
+ <register_bits>
+ <offset>31</offset>
+ <size>1</size>
+ <mode>R</mode>
+ <name>freq</name>
+ </register_bits>
+ </registers_bits>
+ </register>
+ <register>
+ <adress>0x50</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>status</name>
+ </register>
+ <register>
+ <adress>0x54</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>status2</name>
+ </register>
+ <register>
+ <adress>0x58</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>status3</name>
+ </register>
+ <register>
+ <adress>0x5c</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>fr_status</name>
+ </register>
+ <register>
+ <adress>0x70</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>start_address</name>
+ </register>
+ <register>
+ <adress>0x74</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>end_address</name>
+ </register>
+ <register>
+ <adress>0x78</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>rd_address</name>
+ </register>
+ <register>
+ <adress>0xa0</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>fr_param1</name>
+ <registers_bits>
+ <register_bits>
+ <offset>0</offset>
+ <size>10</size>
+ <mode>RW</mode>
+ <name>fr_skip_lines</name>
+ </register_bits>
+ <register_bits>
+ <offset>10</offset>
+ <size>11</size>
+ <mode>RW</mode>
+ <name>fr_num_lines</name>
+ </register_bits>
+ <register_bits>
+ <offset>21</offset>
+ <size>11</size>
+ <mode>RW</mode>
+ <name>fr_start_address</name>
+ </register_bits>
+ </registers_bits>
+ </register>
+ <register>
+ <adress>0xb0</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>all bits</rwmask>
+ <mode>RW</mode>
+ <name>fr_param2</name>
+ <registers_bits>
+ <register_bits>
+ <offset>0</offset>
+ <size>11</size>
+ <mode>RW</mode>
+ <name>fr_threshold_start_line</name>
+ </register_bits>
+ <register_bits>
+ <offset>16</offset>
+ <size>10</size>
+ <mode>RW</mode>
+ <name>fr_area_lines</name>
+ </register_bits>
+ </registers_bits>
+ </register>
+ <register>
+ <adress>0xc0</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>skiped_lines</name>
+ </register>
+ <register>
+ <adress>0xd0</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>all bits</rwmask>
+ <mode>RW</mode>
+ <name>fr_thresholds</name>
+ </register>
+ <register>
+ <adress>0xd0</adress>
+ <offset>0</offset>
+ <size>10</size>
+ <default>0</default>
+ <rwmask>all bits</rwmask>
+ <mode>RW</mode>
+ <name>fr_pixel_thr</name>
+ </register>
+ <register>
+ <adress>0xd0</adress>
+ <offset>10</offset>
+ <size>11</size>
+ <default>0</default>
+ <rwmask>all bits</rwmask>
+ <mode>RW</mode>
+ <name>fr_num_pixel_thr</name>
+ </register>
+ <register>
+ <adress>0xd0</adress>
+ <offset>21</offset>
+ <size>11</size>
+ <default>0</default>
+ <rwmask>all bits</rwmask>
+ <mode>RW</mode>
+ <name>fr_num_lines_thr</name>
+ </register>
+ <register>
+ <adress>0x100</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>rawdata_pkt_addr</name>
+ </register>
+ <register>
+ <adress>0x110</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>temperature_info</name>
+ <registers_bits>
+ <register_bits>
+ <offset>0</offset>
+ <size>16</size>
+ <mode>R</mode>
+ <name>sensor_temperature</name>
+ <views>
+ <view>formuu1</view>
+ <view>formuu2</view>
+ <view>enumm2</view>
+ </views>
+ </register_bits>
+ <register_bits>
+ <offset>16</offset>
+ <size>3</size>
+ <mode>R</mode>
+ <name>sensor_temperature_alarms</name>
+ </register_bits>
+ <register_bits>
+ <offset>19</offset>
+ <size>10</size>
+ <mode>RW</mode>
+ <name>fpga_temperature</name>
+ <views>
+ <view>formuu1</view>
+ <view>enumm1</view>
+ </views>
+ </register_bits>
+ <register_bits>
+ <offset>29</offset>
+ <size>3</size>
+ <mode>R</mode>
+ <name>fpga_temperature_alarms</name>
+ </register_bits>
+ </registers_bits>
+ </register>
+ <register>
+ <adress>0x120</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>num_lines</name>
+ </register>
+ <register>
+ <adress>0x130</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>start_line</name>
+ </register>
+ <register>
+ <adress>0x140</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>exp_time</name>
+ </register>
+ <register>
+ <adress>0x150</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>motor</name>
+ <registers_bits>
+ <register_bits>
+ <offset>0</offset>
+ <size>5</size>
+ <mode>RW</mode>
+ <name>motor_phi</name>
+ </register_bits>
+ <register_bits>
+ <offset>5</offset>
+ <size>5</size>
+ <mode>RW</mode>
+ <name>motor_z</name>
+ </register_bits>
+ <register_bits>
+ <offset>10</offset>
+ <size>5</size>
+ <mode>RW</mode>
+ <name>motor_y</name>
+ </register_bits>
+ <register_bits>
+ <offset>15</offset>
+ <size>5</size>
+ <mode>RW</mode>
+ <name>motor_x</name>
+ </register_bits>
+ <register_bits>
+ <offset>20</offset>
+ <size>8</size>
+ <mode>R</mode>
+ <name>adc_gain</name>
+ </register_bits>
+ </registers_bits>
+ </register>
+ <register>
+ <adress>0x160</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>write_status</name>
+ </register>
+ <register>
+ <adress>0x170</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>num_triggers</name>
+ </register>
+ <register>
+ <adress>0x180</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0x280</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>trigger_period</name>
+ <views>
+ <view>enumm2</view>
+ </views>
+ </register>
+ <register>
+ <adress>0x190</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>temperature_sample_period</name>
+ </register>
+ <register>
+ <adress>0x1a0</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0x64</default>
+ <rwmask>0</rwmask>
+ <mode>RW</mode>
+ <name>ddr_max_frames</name>
+ </register>
+ <register>
+ <adress>0x1b0</adress>
+ <offset>0</offset>
+ <size>32</size>
+ <default>0</default>
+ <rwmask>0</rwmask>
+ <mode>R</mode>
+ <name>ddr_num_frames</name>
+ </register>
+ </registers>
+ </bank>
+ <bank>
+ <bank_description>
+ <adress>DMA bank</adress>
+ <bar>0</bar>
+ <size>0x0200</size>
+ <protocol>default</protocol>
+ <read_adress>0x0</read_adress>
+ <write_adress>0x0</write_adress>
+ <word_size>32</word_size>
+ <endianess>little</endianess>
+ <format>0x%lx</format>
+ <name>dma</name>
+ <description>DMA Registers</description>
+ </bank_description>
+ </bank>
+ </banks>
+ <views>
+ <view type="formula">
+ <name>formuu1</name>
+ <unit>C</unit>
+ <read_from_register>(503975./1024000)*@reg - 27315./100</read_from_register>
+ <write_to_register>(@value + 27315./100)*(102400./503975)</write_to_register>
+<description>formula to get real fpga temperature from the fpga_temperature register in decimal</description>
+ </view>
+ <view type="enum">
+ <name>enumm1</name>
+ <enum value="0x100" min="0x2" max="0x300">high</enum>
+ <enum value="0x010">low</enum>
+ <description>enum towards temperatures register</description>
+ </view>
+ <view type="formula">
+ <name>formuu2</name>
+ <unit>C</unit>
+ <read_from_register>((1./4)*(@reg - 1200)) if @freq==0 else ((3./10)*(@reg - 1000))</read_from_register>
+ <write_to_register>4*@value + 1200 if @freq==0 else (10./3)*@value + 1000</write_to_register>
+ <description>formula to get real sensor temperature from the sensor_temperature register in decimal</description>
+ </view>
+ <view type="enum">
+ <name>enumm2</name>
+ <enum value="0x120">high</enum>
+ <enum value="0x010" min="0x00" max="0x020">low</enum>
+ <description>enum towards sensor_temperature register</description>
+ </view>
+ <view type="formula">
+ <name>formuu3</name>
+ <unit>us</unit>
+ <read_from_register>(@reg+(43./100))*129./(40*1000000)if @freq==0 else (@reg+(43./100))*129./(48*1000000)</read_from_register>
+ <write_to_register>@value/129.*(40*1000000) - 43./100 if @freq==0 else @value/129.*(48*1000000) - 43./100</write_to_register>
+ <description>formula to get real exposure time from the cmosis_exp_time register in decimal</description>
+ </view>
+ <view type="enum">
+ <name>enumm3</name>
+ <enum value="0x000">short</enum>
+ <enum value="0x010">mid</enum>
+ <enum value="0x100" min="0x0F0">long</enum>
+ <description>enum towards cmosis_exp_register register</description>
+ </view>
+ </views>
+</model>
diff --git a/pcitool/cli.c b/pcitool/cli.c
index 9eeb046..f105349 100644
--- a/pcitool/cli.c
+++ b/pcitool/cli.c
@@ -37,6 +37,7 @@
#include "error.h"
#include "debug.h"
#include "model.h"
+#include "xml.h"
/* defines */
#define MAX_KBUF 14
@@ -89,7 +90,8 @@ typedef enum {
MODE_ALLOC_KMEM,
MODE_LIST_KMEM,
MODE_READ_KMEM,
- MODE_FREE_KMEM
+ MODE_FREE_KMEM,
+ MODE_VALIDATE_XML
} MODE;
typedef enum {
@@ -135,6 +137,7 @@ typedef enum {
OPT_GRAB = 'g',
OPT_QUIETE = 'q',
OPT_HELP = 'h',
+ OPT_VALIDATE_XML= 'v',
OPT_RESET = 128,
OPT_BENCHMARK,
OPT_TRIGGER,
@@ -182,6 +185,7 @@ static struct option long_options[] = {
{"iterations", required_argument, 0, OPT_ITERATIONS },
{"info", no_argument, 0, OPT_INFO },
{"list", no_argument, 0, OPT_LIST },
+ {"validate", no_argument,0,OPT_VALIDATE_XML},
{"reset", no_argument, 0, OPT_RESET },
{"benchmark", optional_argument, 0, OPT_BENCHMARK },
{"read", optional_argument, 0, OPT_READ },
@@ -328,6 +332,8 @@ void Usage(int argc, char *argv[], const char *format, ...) {
" Data can be specified as sequence of hexdecimal number or\n"
" a single value prefixed with '*'. In this case it will be\n"
" replicated the specified amount of times\n"
+" XML:\n"
+" -v -validates the xml file against xsd"
"\n\n",
argv[0]);
@@ -3122,6 +3128,9 @@ int main(int argc, char **argv) {
// Requesting real-time priority when needed
switch (mode) {
+ case MODE_VALIDATE_XML:
+ validation();
+ break;
case MODE_READ:
case MODE_WRITE:
if (amode != ACCESS_DMA)
diff --git a/pcitool/config.txt b/pcitool/config.txt
new file mode 100644
index 0000000..14bcc57
--- /dev/null
+++ b/pcitool/config.txt
@@ -0,0 +1,13 @@
+///configuration///
+
+pwd to xml model file:
+camera.xml
+
+///pwd to units xml file:
+///units.xml
+///
+///pwd to python eval file:
+///pythonscripts.py
+///
+pwd to xsd schema file:
+registers_and_banks.xsd
diff --git a/pcitool/registers_and_banks.xsd b/pcitool/registers_and_banks.xsd
new file mode 100755
index 0000000..10d49b7
--- /dev/null
+++ b/pcitool/registers_and_banks.xsd
@@ -0,0 +1,242 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <xsd:element name="model">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="banks" type="banks_type"/>
+ <xsd:element name="views" type="views_type" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ <xsd:key name="Registerkey">
+ <xsd:selector xpath="views/view/name"/>
+ <xsd:field xpath="."/>
+ </xsd:key>
+ <xsd:keyref refer="Registerkey" name="RegisterkeyRef">
+ <xsd:selector xpath="banks/bank/registers/register/views/view"/>
+ <xsd:field xpath="."/>
+ </xsd:keyref>
+ <xsd:key name="Registerbitskey">
+ <xsd:selector xpath="views/view/name"/>
+ <xsd:field xpath="."/>
+ </xsd:key>
+ <xsd:keyref refer="Registerbitskey" name="RegisterbitskeyRef">
+ <xsd:selector xpath="banks/bank/registers/register/registers_bits/register_bits/views/view"/>
+ <xsd:field xpath="."/>
+ </xsd:keyref>
+ </xsd:element>
+
+
+ <xsd:complexType name="views_type">
+ <xsd:sequence>
+ <xsd:element name="view" type="view_type" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+
+ <xsd:complexType name="banks_type">
+ <xsd:sequence>
+ <xsd:element name="bank" type="banktype" minOccurs="1" maxOccurs="12"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="banktype">
+ <xsd:sequence>
+ <xsd:element name="bank_description" type="bank_description_t"/>
+ <xsd:element name="registers" type="registerstype" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="bank_description_t">
+ <xsd:sequence>
+ <xsd:element name="adress" type="bank_adress_type"/>
+ <xsd:element name="bar" type="bar_type"/>
+ <xsd:element name="size" type="hexa_and_integer64_t"/>
+ <xsd:element name="protocol" type="xsd:string"/>
+ <xsd:element name="read_adress" type="hex64_t"/>
+ <xsd:element name="write_adress" type="hex64_t"/>
+ <xsd:element name="word_size" type="uint8_t"/>
+ <xsd:element name="endianess" type="endianess_type"/>
+ <xsd:element name="format" type="xsd:string"/>
+ <xsd:element name="name" type="xsd:string"/>
+ <xsd:element name="description" type="xsd:string" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+
+ <xsd:complexType name="registerstype">
+ <xsd:sequence>
+ <xsd:element name="register" type="register_type" minOccurs="0" maxOccurs="256"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="register_type">
+ <xsd:sequence>
+ <xsd:element name="adress" type="hexa_and_integer32_t"/>
+ <xsd:element name="offset" type="uint8_t"/>
+ <xsd:element name="size" type="uint8_t"/>
+ <xsd:element name="default" type="hexa_and_integer32_t"/>
+ <xsd:element name="rwmask" type="rwmask_type"/>
+ <xsd:element name="mode" type="pcilib_register_mode_t"/>
+ <xsd:element name="name" type="xsd:string"/>
+ <xsd:element name="description" type="xsd:string" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="views" type="reg_to_views_type" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="registers_bits" type="registers_bits_type" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="value_min" type="hexa_and_integer32_t" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="value_max" type="hexa_and_integer32_t" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="registers_bits_type">
+ <xsd:sequence>
+ <xsd:element name="register_bits" type="register_bits_type" minOccurs="1" maxOccurs="32"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="reg_to_views_type">
+ <xsd:sequence>
+ <xsd:element name="view" type="xsd:string" minOccurs="1" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="register_bits_type">
+ <xsd:sequence>
+ <xsd:element name="offset" type="uint8_t"/>
+ <xsd:element name="size" type="uint8_t"/>
+ <xsd:element name="mode" type="pcilib_register_mode_t"/>
+ <xsd:element name="name" type="xsd:string"/>
+ <xsd:element name="description" type="xsd:string" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="views" type="reg_to_views_type" minOccurs="0" maxOccurs="1"/>
+ </xsd:sequence>
+
+ </xsd:complexType>
+
+ <xsd:simpleType name="uint8_t">
+ <xsd:restriction base="xsd:integer">
+ <xsd:minInclusive value="0"/>
+ <xsd:maxInclusive value="255"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="size_t">
+ <xsd:restriction base="xsd:integer">
+ <xsd:minInclusive value="0"/>
+ <xsd:maxInclusive value="18446744073709551615"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="uintptr_t">
+ <xsd:restriction base="xsd:integer">
+ <xsd:minInclusive value="0"/>
+ <xsd:maxInclusive value="18446744073709551615"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="uint32_t">
+ <xsd:restriction base="xsd:integer">
+ <xsd:minInclusive value="0"/>
+ <xsd:maxInclusive value="4294967295"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="pcilib_register_mode_t">
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="R"/>
+ <xsd:enumeration value="W"/>
+ <xsd:enumeration value="RW"/>
+ <xsd:enumeration value="W1C"/>
+ <xsd:enumeration value="RW1C"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="bank_adress_type">
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="bank 0"/>
+ <xsd:enumeration value="bank 1"/>
+ <xsd:enumeration value="bank 2"/>
+ <xsd:enumeration value="bank 3"/>
+ <xsd:enumeration value="DMA bank"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="endianess_type">
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="little"/>
+ <xsd:enumeration value="big"/>
+ <xsd:enumeration value="host"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="bar_type">
+ <xsd:restriction base="xsd:integer">
+ <xsd:enumeration value="0"/>
+ <xsd:enumeration value="1"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="space_adress_type">
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="write adress"/>
+ <xsd:enumeration value="read adress"/>
+ <xsd:enumeration value="space adress"/>
+ <xsd:enumeration value="0"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="rwmask_type">
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="all bits"/>
+ <xsd:enumeration value="0"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="hexa_and_integer32_t">
+ <xsd:union memberTypes="uint32_t hex32_t"/>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="hex32_t">
+ <xsd:restriction base="xsd:string">
+ <xsd:pattern value="0x([a-fA-F0-9]){0,8}"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="hexa_and_integer64_t">
+ <xsd:union memberTypes="size_t hex64_t"/>
+ </xsd:simpleType>
+
+ <xsd:simpleType name="hex64_t">
+ <xsd:restriction base="xsd:string">
+ <xsd:pattern value="0x([a-fA-F0-9]){0,16}"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+ <xsd:complexType name="view_type">
+ <xsd:sequence>
+ <xsd:element name="name" type="xsd:ID"/>
+ <xsd:element name="unit" type="xsd:string" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="read_from_register" type="xsd:string" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="write_to_register" type="xsd:string" minOccurs="0" maxOccurs="1"/>
+ <xsd:element name="enum" type="enum_t" minOccurs="0" maxOccurs="unbounded"/>
+ <xsd:element name="description" type="xsd:string"/>
+ </xsd:sequence>
+ <xsd:attribute name="type" type="viewtype_type" use="required"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="enum_t">
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+ <xsd:attribute name="value" type="hexa_and_integer64_t" use="required"/>
+ <xsd:attribute name="min" type="hexa_and_integer64_t"/>
+ <xsd:attribute name="max" type="hexa_and_integer64_t"/>
+ </xsd:extension>
+ </xsd:simpleContent>
+ </xsd:complexType>
+
+ <xsd:simpleType name="viewtype_type">
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="enum"/>
+ <xsd:enumeration value="formula"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+</xsd:schema>