diff options
-rw-r--r-- | CMakeLists.txt | 13 | ||||
-rw-r--r-- | README.txt | 23 | ||||
-rw-r--r-- | dma/CMakeLists.txt | 1 | ||||
-rw-r--r-- | dma/nwl.c | 4 | ||||
-rwxr-xr-x | pci | 2 | ||||
-rw-r--r-- | pcilib/CMakeLists.txt | 14 | ||||
-rw-r--r-- | pcilib/bank.c | 75 | ||||
-rw-r--r-- | pcilib/bank.h | 15 | ||||
-rw-r--r-- | pcilib/bar.c | 1 | ||||
-rw-r--r-- | pcilib/error.c | 1 | ||||
-rw-r--r-- | pcilib/error.h | 3 | ||||
-rw-r--r-- | pcilib/fifo.c | 1 | ||||
-rw-r--r-- | pcilib/pci.c | 34 | ||||
-rw-r--r-- | pcilib/pci.h | 7 | ||||
-rw-r--r-- | pcilib/pcilib.h | 1 | ||||
-rw-r--r-- | pcilib/register.c | 17 | ||||
-rw-r--r-- | pcilib/register.h | 7 | ||||
-rw-r--r-- | pcilib/xml.c | 1020 | ||||
-rw-r--r-- | pcilib/xml.h | 65 | ||||
-rw-r--r-- | pcitool/CMakeLists.txt | 1 | ||||
-rw-r--r-- | pcitool/camera.xml | 923 | ||||
-rw-r--r-- | pcitool/cli.c | 12 | ||||
-rw-r--r-- | pcitool/config.txt | 13 | ||||
-rwxr-xr-x | pcitool/registers_and_banks.xsd | 242 | ||||
-rw-r--r-- | protocols/CMakeLists.txt | 1 | ||||
-rw-r--r-- | protocols/default.c | 11 | ||||
-rw-r--r-- | xml/CMakeLists.txt | 3 | ||||
-rw-r--r--[-rwxr-xr-x] | xml/model.xsd (renamed from models/ipecamera/registers_and_banks.xsd) | 2 | ||||
-rw-r--r-- | xml/test/camera.xml (renamed from models/ipecamera/camera.xml) | 436 |
29 files changed, 751 insertions, 2197 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ad9c98..10742fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ project(pcitool) -set(PCILIB_VERSION "0.2.1") +set(PCILIB_VERSION "0.2.2") set(PCILIB_ABI_VERSION "2") cmake_minimum_required(VERSION 2.6) @@ -33,19 +33,19 @@ SET(ENV{PKG_CONFIG_PATH} "${LIB_INSTALL_DIR}/pkgconfig:$ENV{PKG_CONFIG_PATH}") find_package(PkgConfig REQUIRED) find_package(Threads REQUIRED) -find_package(PythonLibs REQUIRED) set(EXTRA_SYSTEM_LIBS -lrt) +check_include_files(stdatomic.h HAVE_STDATOMIC_H) + +pkg_check_modules(LIBXML2 libxml-2.0 REQUIRED) + #Check in sibling directory if (NOT DISABLE_PCITOOL) pkg_check_modules(FASTWRITER fastwriter REQUIRED) endif (NOT DISABLE_PCITOOL) -pkg_check_modules(XMLLIB libxml-2.0 REQUIRED) -check_include_files(stdatomic.h HAVE_STDATOMIC_H) - -add_definitions("-fPIC --std=c99 -Wall -O2 -gdwarf-2 -g3 -fno-omit-frame-pointer -g") +add_definitions("-fPIC --std=c99 -Wall -O2 -gdwarf-2 -g3 -fno-omit-frame-pointer") #add_definitions("-fPIC --std=c99 -Wall -O2") include(cmake/version.cmake) @@ -56,6 +56,7 @@ add_subdirectory(protocols) add_subdirectory(pcilib) add_subdirectory(pcitool) add_subdirectory(apps) +add_subdirectory(xml) set_target_properties(pcilib PROPERTIES VERSION ${PCILIB_VERSION} diff --git a/README.txt b/README.txt deleted file mode 100644 index 24c0608..0000000 --- a/README.txt +++ /dev/null @@ -1,23 +0,0 @@ -/** installation **/ - -1. download the repository from UFO source tree. -2. from base repository : "cmake -g ." -3. put in the pcitool/config.txt file the pwd to the xml file you want -4. you may just replace the camera.xml file with the one you want with the -same name - -/**utilization**/ ---> BEWARE : for now, this is still an unstable version, "pci -l[l]" will work -for sure, but "pci -r" and "pci -w" work only depending on the protocol used -for registers - -the utilization is the same as usual, the user just have to modify the xml -file for changing the configuration. Here only xml is supported, views aren't -still put in it. - -the only new command on this part is "pci -v" that will validate the xml file -regarding the xsd file in the config.txt file - -/** complementary documentation**/ -the user may find a more complete documentation (still in writing) in ziio/ -documentation repository on the ufo source tree. diff --git a/dma/CMakeLists.txt b/dma/CMakeLists.txt index 4ddaece..1975a9b 100644 --- a/dma/CMakeLists.txt +++ b/dma/CMakeLists.txt @@ -3,6 +3,7 @@ include_directories( ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/pcilib ${CMAKE_BINARY_DIR}/pcilib + ${LIBXML2_INCLUDE_DIRS} ) set(HEADERS ${HEADERS} nwl.h nwl_private.h nwl_engine.h nwl_irq.h nwl_loopback.h ipe.h ipe_private.h) @@ -105,7 +105,7 @@ pcilib_dma_context_t *dma_nwl_init(pcilib_t *pcilib, const char *model, const vo } else { ctx->type = NWL_MODIFICATION_DEFAULT; - err = pcilib_add_registers(pcilib, 0, nwl_xrawdata_registers); + err = pcilib_add_registers(pcilib, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, nwl_xrawdata_registers, NULL); if (err) { free(ctx); pcilib_error("Error (%i) adding NWL XRAWDATA registers", err); @@ -151,7 +151,7 @@ pcilib_dma_context_t *dma_nwl_init(pcilib_t *pcilib, const char *model, const vo sprintf((char*)eregs[j].name, nwl_dma_engine_registers[j].name, dma_addr_len, edesc.addr, dma_direction); } - err = pcilib_add_registers(pcilib, j, eregs); + err = pcilib_add_registers(pcilib, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, j, eregs, NULL); if (err) { free(ctx); pcilib_error("Error (%i) adding NWL DMA registers for engine %i", err, edesc.addr); @@ -2,4 +2,4 @@ APP_PATH=`dirname $0` -LD_LIBRARY_PATH="$APP_PATH/pcilib" $APP_PATH/pcitool/pci $* +PCILIB_MODEL_DIR="$APP_PATH/xml" LD_LIBRARY_PATH="$APP_PATH/pcilib" $APP_PATH/pcitool/pci $* diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt index 4c36141..8b11d60 100644 --- a/pcilib/CMakeLists.txt +++ b/pcilib/CMakeLists.txt @@ -1,18 +1,14 @@ include_directories( ${CMAKE_SOURCE_DIR} - ${PYTHON_INCLUDE_DIRS} - ${XMLLIB_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/pcilib ${CMAKE_BINARY_DIR}/pcilib + ${LIBXML2_INCLUDE_DIRS} ) -set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h -kmem.h irq.h locking.h lock.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 locking.c lock.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} ${EXTRA_SYSTEM_LIBS} ${XMLLIB_LIBRARIES} ${PYTHON_LIBRARIES}) - +set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h xml.h kmem.h irq.h locking.h lock.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 xml.c kmem.c irq.c locking.c lock.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} ${EXTRA_SYSTEM_LIBS} ${LIBXML2_LIBRARIES}) add_dependencies(pcilib dma protocols) install(TARGETS pcilib @@ -23,6 +19,6 @@ install(FILES pcilib.h DESTINATION include ) -install(FILES bar.h kmem.h locking.h lock.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 locking.h lock.h bank.h register.h xml.h dma.h event.h model.h error.h debug.h env.h tools.h export.h version.h DESTINATION include/pcilib ) diff --git a/pcilib/bank.c b/pcilib/bank.c index 3d53db2..66ff739 100644 --- a/pcilib/bank.c +++ b/pcilib/bank.c @@ -51,6 +51,7 @@ int pcilib_init_register_banks(pcilib_t *ctx) { bank_ctx->bank = ctx->banks + ctx->num_banks_init; bank_ctx->api = bapi; + bank_ctx->xml = ctx->xml.bank_nodes[ctx->num_banks_init]; ctx->bank_ctx[ctx->num_banks_init] = bank_ctx; } @@ -76,9 +77,11 @@ void pcilib_free_register_banks(pcilib_t *ctx) { ctx->num_banks_init = 0; } - -int pcilib_add_register_banks(pcilib_t *ctx, size_t n, const pcilib_register_bank_description_t *banks) { - // DS: Override existing banks +int pcilib_add_register_banks(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_bank_description_t *banks, pcilib_register_bank_t *ids) { + size_t i; + pcilib_register_bank_t bank; + size_t dyn_banks = ctx->dyn_banks; + size_t num_banks = ctx->num_banks; if (!n) { for (n = 0; banks[n].access; n++); @@ -86,9 +89,42 @@ int pcilib_add_register_banks(pcilib_t *ctx, size_t n, const pcilib_register_ban if ((ctx->num_banks + n + 1) > PCILIB_MAX_REGISTER_BANKS) return PCILIB_ERROR_TOOBIG; - + +/* memcpy(ctx->banks + ctx->num_banks, banks, n * sizeof(pcilib_register_bank_description_t)); ctx->num_banks += n; +*/ + + for (i = 0; i < n; i++) { + // Try to find if the bank is already existing... + bank = pcilib_find_register_bank_by_name(ctx, banks[i].name); + if ((bank == PCILIB_REGISTER_BANK_INVALID)&&(banks[i].addr != PCILIB_REGISTER_BANK_DYNAMIC)) + bank = pcilib_find_register_bank_by_addr(ctx, banks[i].addr); + + if (bank == PCILIB_REGISTER_BANK_INVALID) { + bank = num_banks++; + } else if (flags&PCILIB_MODEL_MODIFICATION_FLAG_SKIP_EXISTING) { + if (ids) ids[i] = bank; + continue; + } else if ((flags&PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE) == 0) { + if (pcilib_find_register_bank_by_name(ctx, banks[i].name) == PCILIB_REGISTER_BANK_INVALID) + pcilib_error("The bank %s is already existing and override flag is not set", banks[i].name); + else + pcilib_error("The bank with address 0x%lx is already existing and override flag is not set", banks[i].addr); + return PCILIB_ERROR_EXIST; + } + + memcpy(ctx->banks + bank, banks + i, sizeof(pcilib_register_bank_description_t)); + if (ids) ids[i] = bank; + + if (banks[i].addr == PCILIB_REGISTER_BANK_DYNAMIC) { + ctx->banks[bank].addr = PCILIB_REGISTER_BANK_DYNAMIC + dyn_banks + 1; + dyn_banks++; + } + } + + ctx->num_banks = num_banks; + ctx->dyn_banks = dyn_banks; // If banks are already initialized, we need to re-run the initialization code // DS: Locking is currently missing @@ -100,7 +136,7 @@ int pcilib_add_register_banks(pcilib_t *ctx, size_t n, const pcilib_register_ban return 0; } -int pcilib_add_register_protocols(pcilib_t *ctx, size_t n, const pcilib_register_protocol_description_t *protocols) { +int pcilib_add_register_protocols(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_protocol_description_t *protocols, pcilib_register_protocol_t *ids) { // DS: Override existing banks if (!n) { @@ -116,10 +152,7 @@ int pcilib_add_register_protocols(pcilib_t *ctx, size_t n, const pcilib_register return 0; } - -int pcilib_add_register_ranges(pcilib_t *ctx, size_t n, const pcilib_register_range_t *ranges) { - // DS: Override existing banks - +int pcilib_add_register_ranges(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_range_t *ranges) { if (!n) { for (n = 0; ranges[n].end; n++); } @@ -135,22 +168,18 @@ int pcilib_add_register_ranges(pcilib_t *ctx, size_t n, const pcilib_register_ra pcilib_register_bank_t pcilib_find_register_bank_by_addr(pcilib_t *ctx, pcilib_register_bank_addr_t bank) { pcilib_register_bank_t i; - const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); - const pcilib_register_bank_description_t *banks = model_info->banks; - for (i = 0; banks[i].access; i++) - if (banks[i].addr == bank) return i; + for (i = 0; ctx->banks[i].access; i++) + if (ctx->banks[i].addr == bank) return i; return PCILIB_REGISTER_BANK_INVALID; } pcilib_register_bank_t pcilib_find_register_bank_by_name(pcilib_t *ctx, const char *bankname) { pcilib_register_bank_t i; - const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); - const pcilib_register_bank_description_t *banks = model_info->banks; - for (i = 0; banks[i].access; i++) - if (!strcasecmp(banks[i].name, bankname)) return i; + for (i = 0; ctx->banks[i].access; i++) + if (!strcasecmp(ctx->banks[i].name, bankname)) return i; return PCILIB_REGISTER_BANK_INVALID; } @@ -203,22 +232,18 @@ pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const ch pcilib_register_protocol_t pcilib_find_register_protocol_by_addr(pcilib_t *ctx, pcilib_register_protocol_addr_t protocol) { pcilib_register_protocol_t i; - const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); - const pcilib_register_protocol_description_t *protocols = model_info->protocols; - for (i = 0; protocols[i].api; i++) - if (protocols[i].addr == protocol) return i; + for (i = 0; ctx->protocols[i].api; i++) + if (ctx->protocols[i].addr == protocol) return i; return PCILIB_REGISTER_PROTOCOL_INVALID; } pcilib_register_protocol_t pcilib_find_register_protocol_by_name(pcilib_t *ctx, const char *name) { pcilib_register_protocol_t i; - const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); - const pcilib_register_protocol_description_t *protocols = model_info->protocols; - for (i = 0; protocols[i].api; i++) - if (!strcasecmp(protocols[i].name, name)) return i; + for (i = 0; ctx->protocols[i].api; i++) + if (!strcasecmp(ctx->protocols[i].name, name)) return i; return PCILIB_REGISTER_PROTOCOL_INVALID; } diff --git a/pcilib/bank.h b/pcilib/bank.h index 8074197..602fa67 100644 --- a/pcilib/bank.h +++ b/pcilib/bank.h @@ -23,9 +23,14 @@ typedef uint8_t pcilib_register_bank_addr_t; /**< Type holding the bank addr typedef uint8_t pcilib_register_protocol_t; /**< Type holding the protocol position within the field listing register protocols in the model */ typedef uint8_t pcilib_register_protocol_addr_t; /**< Type holding the protocol address */ - typedef struct pcilib_register_bank_context_s pcilib_register_bank_context_t; +typedef enum { + PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT = 0, + PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE = 1, /**< Instructs to override the existing registers/banks/etc... */ + PCILIB_MODEL_MODIFICATION_FLAG_SKIP_EXISTING = 2 /**< If flag is set, pcilib will just skip existing registers/banks/etc instead of reporting a error */ +} pcilib_model_modification_flags_t; + typedef struct { pcilib_version_t version; @@ -84,7 +89,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;*/ + pcilib_xml_node_t *xml; /**< Additional XML properties */ }; #ifdef __cplusplus @@ -95,9 +100,9 @@ extern "C" { int pcilib_init_register_banks(pcilib_t *ctx); void pcilib_free_register_banks(pcilib_t *ctx); -int pcilib_add_register_banks(pcilib_t *ctx, size_t n, const pcilib_register_bank_description_t *banks); -int pcilib_add_register_protocols(pcilib_t *ctx, size_t n, const pcilib_register_protocol_description_t *protocols); -int pcilib_add_register_ranges(pcilib_t *ctx, size_t n, const pcilib_register_range_t *ranges); +int pcilib_add_register_banks(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_bank_description_t *banks, pcilib_register_bank_t *ids); +int pcilib_add_register_protocols(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_protocol_description_t *protocols, pcilib_register_protocol_t *ids); +int pcilib_add_register_ranges(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_range_t *ranges); pcilib_register_bank_t pcilib_find_register_bank_by_addr(pcilib_t *ctx, pcilib_register_bank_addr_t bank); pcilib_register_bank_t pcilib_find_register_bank_by_name(pcilib_t *ctx, const char *bankname); diff --git a/pcilib/bar.c b/pcilib/bar.c index 418f864..074a0b2 100644 --- a/pcilib/bar.c +++ b/pcilib/bar.c @@ -1,4 +1,5 @@ #define _BSD_SOURCE +#define _DEFAULT_SOURCE #define _POSIX_C_SOURCE 200809L #include <stdio.h> diff --git a/pcilib/error.c b/pcilib/error.c index 2c4296e..06af292 100644 --- a/pcilib/error.c +++ b/pcilib/error.c @@ -1,4 +1,5 @@ #define _BSD_SOURCE +#define _DEFAULT_SOURCE #include <stdio.h> #include <stdlib.h> diff --git a/pcilib/error.h b/pcilib/error.h index 9b5492b..4ac0967 100644 --- a/pcilib/error.h +++ b/pcilib/error.h @@ -28,7 +28,8 @@ enum { PCILIB_ERROR_NOTINITIALIZED = EBADFD, PCILIB_ERROR_TOOBIG = EFBIG, PCILIB_ERROR_OVERWRITTEN = ESTALE, - PCILIB_ERROR_BUSY = EBUSY + PCILIB_ERROR_BUSY = EBUSY, + PCILIB_ERROR_EXIST = EEXIST } pcilib_errot_t; #ifdef __cplusplus diff --git a/pcilib/fifo.c b/pcilib/fifo.c index 593400f..7ed87b8 100644 --- a/pcilib/fifo.c +++ b/pcilib/fifo.c @@ -1,4 +1,5 @@ #define _BSD_SOURCE +#define _DEFAULT_SOURCE #define _POSIX_C_SOURCE 200809L #include <stdio.h> diff --git a/pcilib/pci.c b/pcilib/pci.c index 5f3c8aa..b7dcbcd 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -1,6 +1,7 @@ //#define PCILIB_FILE_IO #define _XOPEN_SOURCE 700 #define _BSD_SOURCE +#define _DEFAULT_SOURCE #define _POSIX_C_SOURCE 200809L #include <stdio.h> @@ -59,10 +60,10 @@ static int pcilib_detect_model(pcilib_t *ctx, const char *model) { if (dma) { if (dma->banks) - pcilib_add_register_banks(ctx, 0, dma->banks); + pcilib_add_register_banks(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, dma->banks, NULL); if (dma->registers) - pcilib_add_registers(ctx, 0, dma->registers); + pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, dma->registers, NULL); if (dma->engines) { for (j = 0; dma->engines[j].addr_bits; j++); @@ -73,16 +74,16 @@ static int pcilib_detect_model(pcilib_t *ctx, const char *model) { } if (model_info->protocols) - pcilib_add_register_protocols(ctx, 0, model_info->protocols); + pcilib_add_register_protocols(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, model_info->protocols, NULL); if (model_info->banks) - pcilib_add_register_banks(ctx, 0, model_info->banks); + pcilib_add_register_banks(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, model_info->banks, NULL); if (model_info->registers) - pcilib_add_registers(ctx, 0, model_info->registers); + pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, model_info->registers, NULL); if (model_info->ranges) - pcilib_add_register_ranges(ctx, 0, model_info->ranges); + pcilib_add_register_ranges(ctx, PCILIB_MODEL_MODIFICATON_FLAGS_DEFAULT, 0, model_info->ranges); } // Load XML registers @@ -105,7 +106,7 @@ static int pcilib_detect_model(pcilib_t *ctx, const char *model) { pcilib_t *pcilib_open(const char *device, const char *model) { - int err; + int err, xmlerr; size_t i; pcilib_t *ctx = malloc(sizeof(pcilib_t)); @@ -159,7 +160,7 @@ pcilib_t *pcilib_open(const char *device, const char *model) { ctx->num_protocols = i; err = pcilib_detect_model(ctx, model); - if (err) { + if ((err)&&(err != PCILIB_ERROR_NOTFOUND)) { const pcilib_board_info_t *board_info = pcilib_get_board_info(ctx); if (board_info) pcilib_error("Error (%i) configuring model %s (%x:%x)", err, (model?model:""), board_info->vendor_id, board_info->device_id); @@ -172,9 +173,16 @@ pcilib_t *pcilib_open(const char *device, const char *model) { if (!ctx->model) ctx->model = strdup(model?model:"pci"); - err = pcilib_init_xml(ctx, ctx->model); - if (err) { - pcilib_error("Error (%i) initializing xml part\n", err); + xmlerr = pcilib_init_xml(ctx, ctx->model); + if ((xmlerr)&&(xmlerr != PCILIB_ERROR_NOTFOUND)) { + pcilib_error("Error (%i) initializing XML subsystem for model %s", xmlerr, ctx->model); + pcilib_close(ctx); + return NULL; + } + + // We have found neither standard model nor XML + if ((err)&&(xmlerr)) { + pcilib_error("The specified model (%s) is not available", model); pcilib_close(ctx); return NULL; } @@ -190,7 +198,6 @@ pcilib_t *pcilib_open(const char *device, const char *model) { pcilib_close(ctx); return NULL; } - err = pcilib_init_event_engine(ctx); if (err) { @@ -363,8 +370,7 @@ void pcilib_close(pcilib_t *ctx) { pcilib_free_register_banks(ctx); - if(ctx->xml_ctx) - pcilib_free_xml(ctx); + pcilib_free_xml(ctx); if (ctx->register_ctx) free(ctx->register_ctx); diff --git a/pcilib/pci.h b/pcilib/pci.h index dfbaf9b..00528e1 100644 --- a/pcilib/pci.h +++ b/pcilib/pci.h @@ -26,7 +26,6 @@ #include "export.h" #include "locking.h" #include "xml.h" -#include <libxml/tree.h> typedef struct { uint8_t max_link_speed, link_speed; @@ -61,7 +60,9 @@ struct pcilib_s { size_t num_banks_init; /**< Number of initialized banks */ size_t num_reg, alloc_reg; /**< Number of registered and allocated registers */ size_t num_banks, num_protocols, num_ranges; /**< Number of registered banks, protocols, and register ranges */ - size_t num_engines; /**> Number of configured DMA engines */ + size_t num_engines; /**< Number of configured DMA engines */ + size_t dyn_banks; /**< Number of configured dynamic banks */ + pcilib_register_description_t *registers; /**< List of currently defined registers (from all sources) */ pcilib_register_bank_description_t banks[PCILIB_MAX_REGISTER_BANKS + 1]; /**< List of currently defined register banks (from all sources) */ pcilib_register_range_t ranges[PCILIB_MAX_REGISTER_RANGES + 1]; /**< List of currently defined register ranges (from all sources) */ @@ -73,12 +74,12 @@ struct pcilib_s { pcilib_register_bank_context_t *bank_ctx[PCILIB_MAX_REGISTER_BANKS]; /**< Contexts for registers banks if required by register protocol */ pcilib_dma_context_t *dma_ctx; /**< DMA context */ pcilib_context_t *event_ctx; /**< Implmentation context */ - pcilib_xml_context_t* xml_ctx; /**< context to xml files*/ pcilib_lock_t *dma_rlock[PCILIB_MAX_DMA_ENGINES]; /**< Per-engine locks to serialize streaming and read operations */ pcilib_lock_t *dma_wlock[PCILIB_MAX_DMA_ENGINES]; /**< Per-engine locks to serialize write operations */ struct pcilib_locking_s locks; /**< Context of locking subsystem */ + struct pcilib_xml_s xml; /**< XML context */ #ifdef PCILIB_FILE_IO int file_io_handle; diff --git a/pcilib/pcilib.h b/pcilib/pcilib.h index 01f3324..6bb018d 100644 --- a/pcilib/pcilib.h +++ b/pcilib/pcilib.h @@ -23,6 +23,7 @@ typedef uint32_t pcilib_event_t; typedef uint64_t pcilib_timeout_t; /**< In microseconds */ typedef unsigned int pcilib_irq_hw_source_t; typedef uint32_t pcilib_irq_source_t; +typedef struct _xmlNode pcilib_xml_node_t; typedef enum { PCILIB_LOG_DEBUG = 0, /**< Debug messages will be always printed as they should be filtered based on setting of corresponding environmental variable */ diff --git a/pcilib/register.c b/pcilib/register.c index deb8cf4..68e5d36 100644 --- a/pcilib/register.c +++ b/pcilib/register.c @@ -19,7 +19,7 @@ #include "error.h" -int pcilib_add_registers(pcilib_t *ctx, size_t n, const pcilib_register_description_t *registers) { +int pcilib_add_registers(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_description_t *registers, pcilib_register_t *ids) { // DS: Overrride existing registers // Registers identified by addr + offset + size + type or name @@ -52,7 +52,16 @@ int pcilib_add_registers(pcilib_t *ctx, size_t n, const pcilib_register_descript memcpy(ctx->registers + ctx->num_reg, registers, n * sizeof(pcilib_register_description_t)); memset(ctx->registers + ctx->num_reg + n, 0, sizeof(pcilib_register_description_t)); + + if (ids) { + size_t i; + + for (i = 0; i < n; i++) + ids[i] = ctx->num_reg + i; + } + ctx->num_reg += n; + return 0; } @@ -97,11 +106,11 @@ static int pcilib_read_register_space_internal(pcilib_t *ctx, pcilib_register_ba if ((bits > 0)&&(!err)) { pcilib_register_value_t val = 0; err = bapi->read(ctx, bctx, addr + n * access, &val); - + val = (val >> offset)&BIT_MASK(bits); memcpy(buf + n, &val, sizeof(pcilib_register_value_t)); - } + return err; } @@ -151,7 +160,7 @@ int pcilib_read_register_by_id(pcilib_t *ctx, pcilib_register_t reg, pcilib_regi } *value = res; - + return err; } diff --git a/pcilib/register.h b/pcilib/register.h index 61eef84..e7cbae9 100644 --- a/pcilib/register.h +++ b/pcilib/register.h @@ -44,8 +44,9 @@ typedef struct { typedef struct { - pcilib_register_bank_t bank; - /* use it or not?*/ /*xmlNodeSetPtr registers_nodes;*/ + pcilib_register_bank_t bank; /**< Reference to bank containing the register */ + pcilib_register_value_t min, max; /**< Minimum & maximum allowed values */ + pcilib_xml_node_t *xml; /**< Additional XML properties */ } pcilib_register_context_t; @@ -53,7 +54,7 @@ typedef struct { extern "C" { #endif -int pcilib_add_registers(pcilib_t *ctx, size_t n, const pcilib_register_description_t *registers); +int pcilib_add_registers(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_description_t *registers, pcilib_register_t *ids); #ifdef __cplusplus } diff --git a/pcilib/xml.c b/pcilib/xml.c index 8457927..73a3deb 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -1,9 +1,9 @@ /** * @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 registers and banks nodes are parsed using xpath expression, but their properties is get by recursively getting all properties nodes. In this sense, if a property changes, the algorithm has to be changed, but if it's registers or banks nodes, just the xpath expression modification should be enough. 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. @@ -11,434 +11,556 @@ In case the performance is not good enough, please consider the following : hard code of formulas */ #define _XOPEN_SOURCE 700 +#define _BSD_SOURCE +#define _DEFAULT_SOURCE - -#define REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register") /**<all standard registers nodes.*/ -#define BITS_REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits") /**<all bits registers nodes.*/ -#define BANKS_PATH ((xmlChar*)"/model/banks/bank/bank_description") /**< path to complete nodes of banks.*/ - -#include "xml.h" -#include "error.h" #include <stdlib.h> #include <stdio.h> #include <string.h> #include <strings.h> -#include "pci.h" -#include "bank.h" -#include "register.h" +#include <dirent.h> +#include <errno.h> +#include <alloca.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + + #include <libxml/xmlschemastypes.h> #include <libxml/tree.h> #include <libxml/parser.h> #include <libxml/xpath.h> #include <libxml/xpathInternals.h> -#include <dirent.h> -#include <errno.h> -#include "config.h" -typedef enum{ - type_standard, - type_bits, - type_fifo -}pcilib_type_register_t; +#include "config.h" +#include "pci.h" +#include "bank.h" +#include "register.h" +#include "xml.h" +#include "error.h" -/** pcilib_xml_get_nodeset_from_xpath - * 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 - *@return the nodeset from AST and xpath expression evaluation of the xml file - */ -static xmlXPathObjectPtr -pcilib_xml_get_nodeset_from_xpath(xmlXPathContextPtr doc, xmlChar *xpath){ - xmlXPathObjectPtr result; - result=xmlXPathEvalExpression(xpath, doc); /**<the creation of the resulting object*/ - if(result==NULL){ - pcilib_error("can't parse xpath expression %s",(char*)xpath); - return NULL; - } - - if(xmlXPathNodeSetIsEmpty(result->nodesetval)){ - pcilib_warning("the parsing of %s xpath expression resulted in an empty nodeset",(char*)xpath); - xmlXPathFreeObject(result); - return NULL; - } - - return result; +#define BANKS_PATH ((xmlChar*)"/model/banks/bank/bank_description") /**< path to complete nodes of banks.*/ +//#define REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register") /**< all standard registers nodes.*/ +//#define BIT_REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits") /**< all bits registers nodes.*/ +#define REGISTERS_PATH ((xmlChar*)"../registers/register") /**< all standard registers nodes.*/ +#define BIT_REGISTERS_PATH ((xmlChar*)"./registers_bits/register_bits") /**< all bits registers nodes.*/ + +static char *pcilib_xml_bank_default_format = "0x%lx"; + +typedef struct { + pcilib_register_description_t base; + pcilib_register_value_t min, max; +} pcilib_xml_register_description_t; + +/* +static xmlNodePtr pcilib_xml_get_parent_bank_node(xmlDocPtr doc, xmlNodePtr node) { + xmlNodePtr bank_node; + bank_node = node->parent->parent; + // bank_description is always a first node according to the XSD schema + return xmlFirstElementChild(bank_node); + } - -/** pcilib_xml_validate - * function to validate the xml file against the xsd - * @param[in] xml_filename path to the xml file - * @param[in] xsd_filename path to the xsd file - *@return an error code - */ -static int -pcilib_xml_validate(char* xml_filename, char* xsd_filename) -{ -xmlDocPtr doc; -xmlSchemaPtr schema = NULL; -xmlSchemaParserCtxtPtr ctxt; -int ret=1; - -/** we first parse the xsd file for AST with validation*/ -ctxt = xmlSchemaNewParserCtxt(xsd_filename); -schema = xmlSchemaParse(ctxt); -xmlSchemaFreeParserCtxt(ctxt); - -doc = xmlReadFile(xml_filename, 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); +static xmlNodePtr pcilib_xml_get_parent_register_node(xmlDocPtr doc, xmlNodePtr node) { + return node->parent->parent; } +*/ -if(schema != NULL) -xmlSchemaFree(schema); -xmlSchemaCleanupTypes(); +static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_description_t *xml_desc, xmlDocPtr doc, xmlNodePtr node, pcilib_register_bank_description_t *bdesc) { + pcilib_register_description_t *desc = (pcilib_register_description_t*)xml_desc; -if(ret!=0) pcilib_warning("\nxml file \"%s\" does not validate against the schema, its register won't be used",xml_filename); + xmlNodePtr cur; + char *value, *name; + char *endptr; + + for (cur = node->children; cur != NULL; cur = cur->next) { + if (!cur->children) continue; + if (!xmlNodeIsText(cur->children)) continue; + + name = (char*)cur->name; + value = (char*)cur->children->content; + if (!value) continue; + + if (!strcasecmp((char*)name, "address")) { + uintptr_t addr = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid address (%s) is specified in the XML register description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc->addr = addr; + } else if(!strcasecmp(name, "offset")) { + int offset = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)||(offset < 0)||(offset > (8 * sizeof(pcilib_register_value_t)))) { + pcilib_error("Invalid offset (%s) is specified in the XML register description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc->offset = (pcilib_register_size_t)offset; + } else if (!strcasecmp(name,"size")) { + int size = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)||(size <= 0)||(size > (8 * sizeof(pcilib_register_value_t)))) { + pcilib_error("Invalid size (%s) is specified in the XML register description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc->bits = (pcilib_register_size_t)size; + } else if (!strcasecmp(name, "default")) { + pcilib_register_value_t val = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid default value (%s) is specified in the XML register description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc->defvalue = val; + } else if (!strcasecmp(name,"min")) { + pcilib_register_value_t min = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid minimum value (%s) is specified in the XML register description", value); + return PCILIB_ERROR_INVALID_DATA; + } + xml_desc->min = min; + } else if (!strcasecmp(name, "max")) { + pcilib_register_value_t max = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid minimum value (%s) is specified in the XML register description", value); + return PCILIB_ERROR_INVALID_DATA; + } + xml_desc->max = max; + } else if (!strcasecmp((char*)name,"rwmask")) { + if (!strcasecmp(value, "all")) { + desc->rwmask = PCILIB_REGISTER_ALL_BITS; + } else if (!strcasecmp(value, "none")) { + desc->rwmask = 0; + } else { + uintptr_t mask = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid mask (%s) is specified in the XML register description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc->rwmask = mask; + } + } else if (!strcasecmp(name, "mode")) { + if (!strcasecmp(value, "R")) { + desc->mode = PCILIB_REGISTER_R; + } else if (!strcasecmp(value, "W")) { + desc->mode = PCILIB_REGISTER_W; + } else if (!strcasecmp(value, "RW")) { + desc->mode = PCILIB_REGISTER_RW; + } else if (!strcasecmp(value, "W")) { + desc->mode = PCILIB_REGISTER_W; + } else if (!strcasecmp(value, "RW1C")) { + desc->mode = PCILIB_REGISTER_RW1C; + } else if (!strcasecmp(value, "W1C")) { + desc->mode = PCILIB_REGISTER_W1C; + } else { + pcilib_error("Invalid access mode (%s) is specified in the XML register description", value); + return PCILIB_ERROR_INVALID_DATA; + } + } else if (!strcasecmp(name, "type")) { + if (!strcasecmp(value, "fifo")) { + desc->type = PCILIB_REGISTER_FIFO; + } else { + pcilib_error("Invalid register type (%s) is specified in the XML register description", value); + return PCILIB_ERROR_INVALID_DATA; + } + } else if (!strcasecmp(name,"name")) { + desc->name = value; + } else if (!strcasecmp(name,"description")) { + desc->description = value; + } + } - return ret; + return 0; } +static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { + int err; + + xmlXPathObjectPtr nodes; + xmlNodeSetPtr nodeset; + pcilib_xml_register_description_t desc = {{0}}; + pcilib_xml_register_description_t fdesc; + + pcilib_register_t reg; + + desc.base.bank = ctx->banks[bank].addr; + desc.base.rwmask = PCILIB_REGISTER_ALL_BITS; + desc.base.mode = PCILIB_REGISTER_R; + desc.base.type = PCILIB_REGISTER_STANDARD; + + err = pcilib_xml_parse_register(ctx, &desc, doc, node, &ctx->banks[bank]); + if (err) { + pcilib_error("Error (%i) parsing an XML register", err); + return err; + } + + err = pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE, 1, &desc.base, ®); + if (err) { + pcilib_error("Error (%i) adding a new XML register (%s) to the model", err, desc.base.name); + return err; + } -/** pcilib_xml_create_bank - * - * this function create a bank structure from a xml bank node - * @param[out] mybank the created bank. - * @param[in] my node the xml node used to create the bank - * @param[in] doc the AST of the xml file, used for used lixbml functions - */ -static void -pcilib_xml_create_bank(pcilib_register_bank_description_t *mybank, xmlNodePtr mynode, xmlDocPtr doc, pcilib_t* pci, int err){ - - char* ptr; - xmlNodePtr cur; - xmlChar *value; - int bar_ok=0; - int k=0; + ctx->register_ctx[reg].xml = node; + ctx->register_ctx[reg].min = desc.min; + ctx->register_ctx[reg].max = desc.max; - cur=mynode->children; /** we place ourselves in the childrens of the bank node*/ + xpath->node = node; + nodes = xmlXPathEvalExpression(BIT_REGISTERS_PATH, xpath); + xpath->node = NULL; + + if (!nodes) { + xmlErrorPtr xmlerr = xmlGetLastError(); - /** we iterate through all children, representing bank properties, to fill the structure*/ - while(cur!=NULL){ - /** we get each time the name of the node, corresponding to one property, and the value of the node*/ - value=xmlNodeListGetString(doc,cur->children,1); - - if(strcasecmp((char*)cur->name,"bar")==0){ - mybank->bar=(pcilib_bar_t)(value[0]-'0'); - bar_ok++; + if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BIT_REGISTERS_PATH, xmlerr->code, xmlerr->message); + else pcilib_error("Failed to parse XPath expression %s", BIT_REGISTERS_PATH); + return PCILIB_ERROR_FAILED; + } - }else if(strcasecmp((char*)cur->name,"size")==0){ - mybank->size=(size_t)strtol((char*)value,&ptr,0); + nodeset = nodes->nodesetval; + if (!xmlXPathNodeSetIsEmpty(nodeset)) { + int i; - }else if(strcasecmp((char*)cur->name,"protocol")==0){ - if((mybank->protocol=pcilib_find_register_protocol_by_name(pci,(char*)value))==PCILIB_REGISTER_PROTOCOL_INVALID){ - mybank->protocol=PCILIB_REGISTER_PROTOCOL_DEFAULT; - } + for (i = 0; i < nodeset->nodeNr; i++) { + memset(&fdesc, 0, sizeof(pcilib_xml_register_description_t)); + + fdesc.base.bank = desc.base.bank; + fdesc.base.addr = desc.base.addr; + fdesc.base.mode = desc.base.mode; + fdesc.base.rwmask = desc.base.rwmask; + fdesc.base.type = PCILIB_REGISTER_BITS; + + err = pcilib_xml_parse_register(ctx, &fdesc, doc, nodeset->nodeTab[i], &ctx->banks[bank]); + if (err) { + pcilib_error("Error parsing field in the XML register %s", desc.base.name); + continue; + } + + err = pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE, 1, &fdesc.base, ®); + if (err) { + pcilib_error("Error (%i) adding a new XML register (%s) to the model", err, fdesc.base.name); + continue; + } + + ctx->register_ctx[reg].xml = nodeset->nodeTab[i]; + ctx->register_ctx[reg].min = fdesc.min; + ctx->register_ctx[reg].max = fdesc.max; + } + } + xmlXPathFreeObject(nodes); - }else if(strcasecmp((char*)cur->name,"read_address")==0){ - mybank->read_addr=(uintptr_t)strtol((char*)value,&ptr,0); + return 0; +} - }else if(strcasecmp((char*)cur->name,"write_address")==0){ - mybank->write_addr=(uintptr_t)strtol((char*)value,&ptr,0); - - }else if(strcasecmp((char*)cur->name,"word_size")==0){ - mybank->access=(uint8_t)strtol((char*)value,&ptr,0); - - }else if(strcasecmp((char*)cur->name,"endianess")==0){ - if(strcasecmp((char*)value,"little")==0){ - mybank->endianess=PCILIB_LITTLE_ENDIAN; - }else if(strcasecmp((char*)value,"big")==0){ - mybank->endianess=PCILIB_BIG_ENDIAN; - }else if(strcasecmp((char*)value,"host")==0){ - mybank->endianess=PCILIB_HOST_ENDIAN; - } - mybank->raw_endianess=mybank->endianess; - - }else if(strcasecmp((char*)cur->name,"format")==0){ - mybank->format=(char*)value; - - }else if(strcasecmp((char*)cur->name,"name")==0){ - mybank->name=(char*)value; +static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { + int err; - }else if(strcasecmp((char*)cur->name,"description")==0){ - mybank->description=(char*)value; - } + int override = 0; + pcilib_register_bank_description_t desc = {0}; + pcilib_register_bank_t bank; + xmlNodePtr cur; + char *value, *name; + char *endptr; + + xmlXPathObjectPtr nodes; + xmlNodeSetPtr nodeset; + + + desc.format = pcilib_xml_bank_default_format; + desc.addr = PCILIB_REGISTER_BANK_DYNAMIC; + desc.bar = PCILIB_BAR_NOBAR; + desc.size = 0x1000; + desc.protocol = PCILIB_REGISTER_PROTOCOL_DEFAULT; + desc.access = 32; + desc.endianess = PCILIB_HOST_ENDIAN; + desc.raw_endianess = PCILIB_HOST_ENDIAN; + + // iterate through all children, representing bank properties, to fill the structure + for (cur = node->children; cur != NULL; cur = cur->next) { + if (!cur->children) continue; + if (!xmlNodeIsText(cur->children)) continue; + + name = (char*)cur->name; + value = (char*)cur->children->content; + if (!value) continue; + + if (!strcasecmp(name, "bar")) { + char bar = value[0]-'0'; + if ((strlen(value) != 1)||(bar < 0)||(bar > 5)) { + pcilib_error("Invalid BAR (%s) is specified in the XML bank description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc.bar = (pcilib_bar_t)bar; + override = 1; + } else if (!strcasecmp(name,"size")) { + long size = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)||(size<=0)) { + pcilib_error("Invalid bank size (%s) is specified in the XML bank description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc.size = (size_t)size; + override = 1; + } else if (!strcasecmp(name,"protocol")) { + pcilib_register_protocol_t protocol = pcilib_find_register_protocol_by_name(ctx, value); + if (protocol == PCILIB_REGISTER_PROTOCOL_INVALID) { + pcilib_error("Unsupported protocol (%s) is specified in the XML bank description", value); + return PCILIB_ERROR_NOTSUPPORTED; + } + desc.protocol = ctx->protocols[protocol].addr; + override = 1; + } else if (!strcasecmp(name,"address")) { + uintptr_t addr = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid address (%s) is specified in the XML bank description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc.read_addr = addr; + desc.write_addr = addr; + override = 1; + } else if (!strcasecmp(name,"read_address")) { + uintptr_t addr = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid address (%s) is specified in the XML bank description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc.read_addr = addr; + override = 1; + } else if (!strcasecmp(name,"write_address")) { + uintptr_t addr = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)) { + pcilib_error("Invalid address (%s) is specified in the XML bank description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc.write_addr = addr; + override = 1; + } else if(strcasecmp((char*)name,"word_size")==0) { + int access = strtol(value, &endptr, 0); + if ((strlen(endptr) > 0)||(access%8)||(access<=0)||(access>(8 * sizeof(pcilib_register_value_t)))) { + pcilib_error("Invalid word size (%s) is specified in the XML bank description", value); + return PCILIB_ERROR_INVALID_DATA; + } + desc.access = access; + override = 1; + } else if (!strcasecmp(name,"endianess")) { + if (!strcasecmp(value,"little")) desc.endianess = PCILIB_LITTLE_ENDIAN; + else if (!strcasecmp(value,"big")) desc.endianess = PCILIB_BIG_ENDIAN; + else if (!strcasecmp(value,"host")) desc.endianess = PCILIB_HOST_ENDIAN; + else { + pcilib_error("Invalid endianess (%s) is specified in the XML bank description", value); + return PCILIB_ERROR_INVALID_DATA; + } + override = 1; + } else if (!strcasecmp(name,"format")) { + desc.format = value; + override = 1; + } else if (!strcasecmp((char*)name,"name")) { + desc.name = value; + } else if (!strcasecmp((char*)name,"description")) { + desc.description = value; + override = 1; + } else if (!strcasecmp((char*)name,"override")) { + override = 1; + } + } - cur=cur->next; + err = pcilib_add_register_banks(ctx, override?PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE:PCILIB_MODEL_MODIFICATION_FLAG_SKIP_EXISTING, 1, &desc, &bank); + if (err) { + pcilib_error("Error adding register bank (%s) specified in the XML bank description", desc.name); + return err; } - if(bar_ok==0) mybank->bar=PCILIB_BAR_NOBAR; + ctx->xml.bank_nodes[bank] = node; + if (ctx->bank_ctx[bank]) { + ctx->bank_ctx[bank]->xml = node; + } + + xpath->node = node; + nodes = xmlXPathEvalExpression(REGISTERS_PATH, xpath); + xpath->node = NULL; + + if (!nodes) { + xmlErrorPtr xmlerr = xmlGetLastError(); + if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", REGISTERS_PATH, xmlerr->code, xmlerr->message); + else pcilib_error("Failed to parse XPath expression %s", REGISTERS_PATH); + return PCILIB_ERROR_FAILED; + } - k=(int)pcilib_find_register_bank_by_name(pci,mybank->name); - if(k==PCILIB_REGISTER_BANK_INVALID){ - mybank->addr=PCILIB_REGISTER_BANK_DYNAMIC + pci->xml_ctx->nb_new_banks; - pci->xml_ctx->nb_new_banks++; - k=pci->num_banks+1; + nodeset = nodes->nodesetval; + if (!xmlXPathNodeSetIsEmpty(nodeset)) { + int i; + for (i = 0; i < nodeset->nodeNr; i++) { + err = pcilib_xml_create_register(ctx, bank, xpath, doc, nodeset->nodeTab[i]); + if (err) pcilib_error("Error creating XML registers for bank %s", desc.name); } - else mybank->addr=pci->banks[k].addr; - - if(err==0){ - pci->xml_ctx->xml_banks[k]=mynode; } + xmlXPathFreeObject(nodes); - char buffer[66]; - sprintf(buffer,"%i",mybank->addr); - printf("buffer %s \n",buffer); - xmlNewChild(mynode,NULL, BAD_CAST "address", BAD_CAST buffer); + return 0; } - - + /** pcilib_xml_initialize_banks - * - * function to create the structures to store the banks from the AST - * @see pcilib_xml_create_bank( + * + * function to create the structures to store the banks from the AST + * @see pcilib_xml_create_bank * @param[in] doc the AST of the xml file. * @param[in] pci the pcilib_t running, which will be filled */ -static void -pcilib_xml_initialize_banks(pcilib_t* pci,xmlDocPtr doc){ - pcilib_register_bank_description_t mybank; - - xmlNodeSetPtr nodesetaddress=NULL; - xmlNodePtr mynode; - xmlXPathContextPtr context; - int i,err=0; - - mynode=malloc(sizeof(xmlNode)); - if(!(context= xmlXPathNewContext(doc))){ - pcilib_error("can't get an AST from an xml file"); - return; - } - /** we get the bank nodes using xpath expression*/ - nodesetaddress=pcilib_xml_get_nodeset_from_xpath(context,BANKS_PATH)->nodesetval; - if(!(nodesetaddress)) return; - if(nodesetaddress->nodeNr==0) return; - - pci->xml_ctx->xml_banks=calloc(PCILIB_MAX_REGISTER_BANKS+1,sizeof(xmlNodePtr)); - if(!(pci->xml_ctx->xml_banks)){ - pcilib_error("can't create bank xml nodes for pcilib_t struct"); - err++; - } +static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathContextPtr xpath) { + xmlXPathObjectPtr bank_nodes; + xmlNodeSetPtr nodeset; + + bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath); + if (!bank_nodes) { + xmlErrorPtr xmlerr = xmlGetLastError(); + if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BANKS_PATH, xmlerr->code, xmlerr->message); + else pcilib_error("Failed to parse XPath expression %s", BANKS_PATH); + return PCILIB_ERROR_FAILED; + } - /** for each of the bank nodes, we create the associated structure, and push it in the pcilib environnement*/ - for(i=0;i<nodesetaddress->nodeNr;i++){ - mynode=nodesetaddress->nodeTab[i]; - pcilib_xml_create_bank(&mybank,mynode,doc, pci, err); - pcilib_add_register_banks(pci,1,&mybank); + + nodeset = bank_nodes->nodesetval; + if (!xmlXPathNodeSetIsEmpty(nodeset)) { + int i; + for (i = 0; i < nodeset->nodeNr; i++) { + pcilib_xml_create_bank(ctx, xpath, doc, nodeset->nodeTab[i]); } + } + xmlXPathFreeObject(bank_nodes); + + return 0; +} +static int pcilib_xml_load_xsd(pcilib_t *ctx, char *xsd_filename) { + int err; + + xmlSchemaParserCtxtPtr ctxt; + + /** we first parse the xsd file for AST with validation*/ + ctxt = xmlSchemaNewParserCtxt(xsd_filename); + if (!ctxt) { + xmlErrorPtr xmlerr = xmlGetLastError(); + if (xmlerr) pcilib_error("xmlSchemaNewParserCtxt reported error %d - %s", xmlerr->code, xmlerr->message); + else pcilib_error("Failed to create a parser for XML schemas"); + return PCILIB_ERROR_FAILED; + } + + ctx->xml.schema = xmlSchemaParse(ctxt); + if (!ctx->xml.schema) { + xmlErrorPtr xmlerr = xmlGetLastError(); + xmlSchemaFreeParserCtxt(ctxt); + if (xmlerr) pcilib_error("Failed to parse XML schema, xmlSchemaParse reported error %d - %s", xmlerr->code, xmlerr->message); + else pcilib_error("Failed to parse XML schema"); + return PCILIB_ERROR_INVALID_DATA; + } + + xmlSchemaFreeParserCtxt(ctxt); + + ctx->xml.validator = xmlSchemaNewValidCtxt(ctx->xml.schema); + if (!ctx->xml.validator) { + xmlErrorPtr xmlerr = xmlGetLastError(); + if (xmlerr) pcilib_error("xmlSchemaNewValidCtxt reported error %d - %s", xmlerr->code, xmlerr->message); + else pcilib_error("Failed to create a validation context"); + return PCILIB_ERROR_FAILED; + } + + err = xmlSchemaSetValidOptions(ctx->xml.validator, XML_SCHEMA_VAL_VC_I_CREATE); + if (err) { + xmlErrorPtr xmlerr = xmlGetLastError(); + if (xmlerr) pcilib_error("xmlSchemaSetValidOptions reported error %d - %s", xmlerr->code, xmlerr->message); + else pcilib_error("Failed to configure the validation context to populate default attributes"); + return PCILIB_ERROR_FAILED; + } + return 0; } -/** pcilib_xml_registers_compare - * function to compare registers by address for sorting registers - * @param a one hypothetic register - * @param b one other hypothetic register - *@return the result of the comparison - */ -static int -pcilib_xml_compare_registers(void const *a, void const *b){ - const pcilib_register_description_t *pa=a; - const pcilib_register_description_t *pb=b; +static int pcilib_xml_load_file(pcilib_t *ctx, const char *path, const char *name) { + int err; + char *full_name; + xmlDocPtr doc; + xmlXPathContextPtr xpath; - return pa->addr - pb->addr; -} + full_name = (char*)alloca(strlen(path) + strlen(name) + 2); + if (!name) { + pcilib_error("Error allocating %zu bytes of memory in stack to create a file name", strlen(path) + strlen(name) + 2); + return PCILIB_ERROR_MEMORY; + } + sprintf(full_name, "%s/%s", path, name); -/** 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 don't consider the adding of registers in order of address - * @param[in,out] registers the list of registers in : not ranged out: ranged. - * @param[in] size the number of registers. - */ -static 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)); - qsort(registers,size,sizeof(pcilib_register_description_t),pcilib_xml_compare_registers); - free(temp); -} + doc = xmlCtxtReadFile(ctx->xml.parser, full_name, NULL, 0); + if (!doc) { + xmlErrorPtr xmlerr = xmlCtxtGetLastError(ctx->xml.parser); + if (xmlerr) pcilib_error("Error parsing %s, xmlCtxtReadFile reported error %d - %s", full_name, xmlerr->code, xmlerr->message); + else pcilib_error("Error parsing %s", full_name); + return PCILIB_ERROR_INVALID_DATA; + } -/**pcilib_get_bank_address_from_register_node - *@param[in] node the current register node - */ -static xmlChar* -pcilib_get_bank_address_from_register_node(xmlDocPtr doc, xmlNodePtr node){ - xmlChar* temp= xmlNodeListGetString(doc,xmlGetLastChild(xmlFirstElementChild(node->parent->parent))->children,1); - return temp; -} - - -/** pcilib_xml_create_register. - * this function create a register structure from a xml register node. - * @param[out] myregister the register we want to create - * @param[in] type the type of the future register, because this property can't be parsed - * @param[in] doc the AST of the xml file, required for some ibxml2 sub-fonctions - * @param[in] mynode the xml node to create register from - */ -void pcilib_xml_create_register(pcilib_register_description_t *myregister,xmlNodePtr mynode, xmlDocPtr doc,pcilib_register_type_t type, pcilib_t* pci){ - - char* ptr; - xmlNodePtr cur; - xmlChar *value=NULL; - int i=0; - - /**we get the children of the register xml nodes, that contains the properties for it*/ - cur=mynode->children; - - while(cur!=NULL){ - value=xmlNodeListGetString(doc,cur->children,1); - /* we iterate throug each children to get the associated property - note :the use of strtol permits to get as well hexadecimal and decimal values - */ - if(strcasecmp((char*)cur->name,"address")==0){ - myregister->addr=(pcilib_register_addr_t)strtol((char*)value,&ptr,0); - - }else if(strcasecmp((char*)cur->name,"offset")==0){ - myregister->offset=(pcilib_register_size_t)strtol((char*)value,&ptr,0); - - }else if(strcasecmp((char*)cur->name,"size")==0){ - myregister->bits=(pcilib_register_size_t)strtol((char*)value,&ptr,0); - - }else if(strcasecmp((char*)cur->name,"default")==0){ - myregister->defvalue=(pcilib_register_value_t)strtol((char*)value,&ptr,0); - - }else if(strcasecmp((char*)cur->name,"rwmask")==0){ - if(strcasecmp((char*)value,"all bits")==0){ - myregister->rwmask=PCILIB_REGISTER_ALL_BITS; - }else if(strcasecmp((char*)value,"0")==0){ - myregister->rwmask=0; - }else{ - myregister->rwmask=(pcilib_register_value_t)strtol((char*)value,&ptr,0); - } + err = xmlSchemaValidateDoc(ctx->xml.validator, doc); + if (err) { + xmlErrorPtr xmlerr = xmlCtxtGetLastError(ctx->xml.parser); + xmlFreeDoc(doc); + if (xmlerr) pcilib_error("Error validating %s, xmlSchemaValidateDoc reported error %d - %s", full_name, xmlerr->code, xmlerr->message); + else pcilib_error("Error validating %s", full_name); + return PCILIB_ERROR_VERIFY; + } - }else if(strcasecmp((char*)cur->name,"mode")==0){ - if(strcasecmp((char*)value,"R")==0){ - myregister->mode=PCILIB_REGISTER_R; - }else if(strcasecmp((char*)value,"W")==0){ - myregister->mode=PCILIB_REGISTER_W; - }else if(strcasecmp((char*)value,"RW")==0){ - myregister->mode=PCILIB_REGISTER_RW; - }else if(strcasecmp((char*)value,"W")==0){ - myregister->mode=PCILIB_REGISTER_W; - }else if(strcasecmp((char*)value,"RW1C")==0){ - myregister->mode=PCILIB_REGISTER_RW1C; - }else if(strcasecmp((char*)value,"W1C")==0){ - myregister->mode=PCILIB_REGISTER_W1C; - } - - }else if(strcasecmp((char*)cur->name,"name")==0){ - myregister->name=(char*)value; - - }else if(strcasecmp((char*)cur->name,"value_min")==0){ - /* not implemented yet*/ // myregister->value_min=(pcilib_register_value_t)strtol((char*)value,&ptr,0); - - }else if(strcasecmp((char*)cur->name,"value_max")==0){ - /* not implemented yet*/ // myregister->value_max=(pcilib_register_value_t)strtol((char*)value,&ptr,0); - - }else if(strcasecmp((char*)cur->name,"description")==0){ - i++; - myregister->description=(char*)value; - } - - cur=cur->next; + xpath = xmlXPathNewContext(doc); + if (!xpath) { + xmlErrorPtr xmlerr = xmlGetLastError(); + xmlFreeDoc(doc); + if (xmlerr) pcilib_error("Document %s: xmlXpathNewContext reported error %d - %s for document %s", full_name, xmlerr->code, xmlerr->message); + else pcilib_error("Error creating XPath context for %s", full_name); + return PCILIB_ERROR_FAILED; } - /** make sure we don't get the description from previous registers*/ - if(i==0) myregister->description=NULL; + // This can only partially fail... Therefore we need to keep XML and just return the error... + err = pcilib_xml_process_document(ctx, doc, xpath); - /** we then get properties that can not be parsed as the previous ones*/ - if((int)type==(int)type_standard){ - myregister->type=PCILIB_REGISTER_STANDARD; - myregister->bank=(pcilib_register_bank_addr_t)strtol((char*)pcilib_get_bank_address_from_register_node(doc,mynode),&ptr,0); - - }else if((int)type==(int)type_bits){ - myregister->type=PCILIB_REGISTER_BITS; - - }else if((int)type==(int)type_fifo){ - /* not implemented yet*/ myregister->type=PCILIB_REGISTER_FIFO; - } - - -} + if (ctx->xml.num_files == PCILIB_MAX_MODEL_FILES) { + xmlFreeDoc(doc); + xmlXPathFreeContext(xpath); + pcilib_error("Too many XML files for a model, only up to %zu are supported", PCILIB_MAX_MODEL_FILES); + return PCILIB_ERROR_TOOBIG; + } -/** 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_address, 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] pci the pcilib_t struct running, that will get filled - */ -void pcilib_xml_initialize_registers(pcilib_t* pci,xmlDocPtr doc){ - - xmlNodeSetPtr nodesetaddress=NULL, nodesetsubaddress=NULL; - xmlNodePtr mynode; - xmlXPathContextPtr context; - pcilib_register_description_t *registers=NULL; - pcilib_register_description_t myregister; - int i,j,err=0; - - context= xmlXPathNewContext(doc); - if(!(context= xmlXPathNewContext(doc))){ - pcilib_error("can't get an AST from an xml file"); - return; - } - - /** we first get the nodes of standard and bits registers*/ - nodesetaddress=pcilib_xml_get_nodeset_from_xpath(context,REGISTERS_PATH)->nodesetval; - nodesetsubaddress=pcilib_xml_get_nodeset_from_xpath(context,BITS_REGISTERS_PATH)->nodesetval; - if(!(nodesetaddress)) return; - if(nodesetaddress->nodeNr>0)registers=calloc(nodesetaddress->nodeNr+nodesetsubaddress->nodeNr,sizeof(pcilib_register_description_t)); - else return; - - if(pci->xml_ctx->nb_registers==0) - pci->xml_ctx->xml_registers=calloc(nodesetaddress->nodeNr+nodesetsubaddress->nodeNr,sizeof(xmlNodePtr)); - else - pci->xml_ctx->xml_registers=realloc(pci->xml_ctx->xml_registers,(pci->xml_ctx->nb_registers+nodesetaddress->nodeNr+nodesetsubaddress->nodeNr)*sizeof(xmlNodePtr)); - - if(!(pci->xml_ctx->xml_registers)){ - pcilib_warning("can't create registers xml nodes in pcilib_t struct: memory allocation failed"); - err++; - } - - /** we then iterate through standard registers nodes to create registers structures*/ - for(i=0;i<nodesetaddress->nodeNr;i++){ - mynode=nodesetaddress->nodeTab[i]; - pcilib_xml_create_register(&myregister,mynode,doc,type_standard,pci); - registers[i]=myregister; - if(err==0) pci->xml_ctx->xml_registers[pci->xml_ctx->nb_registers+i]=mynode; - } - - j=i; - if(!(nodesetsubaddress)) return; - /** we then iterate through bits registers nodes to create registers structures*/ - for(i=0;i<nodesetsubaddress->nodeNr;i++){ - mynode=nodesetsubaddress->nodeTab[i]; - pcilib_xml_create_register(&myregister,mynode->parent->parent,doc,type_standard,pci); - pcilib_xml_create_register(&myregister,mynode,doc,type_bits,pci); - registers[i+j]=myregister; - if(err==0) pci->xml_ctx->xml_registers[pci->xml_ctx->nb_registers+i+j]=mynode; - } + ctx->xml.docs[ctx->xml.num_files] = doc; + ctx->xml.xpath[ctx->xml.num_files] = xpath; + ctx->xml.num_files++; + + return err; +} + + +int pcilib_process_xml(pcilib_t *ctx, const char *location) { + int err; + + DIR *rep; + struct dirent *file = NULL; + char *model_dir, *model_path; + + model_dir = getenv("PCILIB_MODEL_DIR"); + if (!model_dir) model_dir = PCILIB_MODEL_DIR; + + model_path = (char*)alloca(strlen(model_dir) + strlen(location) + 2); + if (!model_path) return PCILIB_ERROR_MEMORY; + + sprintf(model_path, "%s/%s", model_dir, location); + + rep = opendir(model_path); + if (!rep) return PCILIB_ERROR_NOTFOUND; + + while ((file = readdir(rep)) != NULL) { + size_t len = strlen(file->d_name); + if ((len < 4)||(strcasecmp(file->d_name + len - 4, ".xml"))) continue; + if (file->d_type != DT_REG) continue; - /**we arrange the register for them to be well placed for pci-l*/ - pcilib_xml_arrange_registers(registers,nodesetaddress->nodeNr+nodesetsubaddress->nodeNr); - /**we fille the pcilib_t struct*/ - pcilib_add_registers(pci,nodesetaddress->nodeNr+nodesetsubaddress->nodeNr,registers); - pci->xml_ctx->nb_registers+=nodesetaddress->nodeNr+nodesetsubaddress->nodeNr; + err = pcilib_xml_load_file(ctx, model_path, file->d_name); + if (err) pcilib_error("Error processing XML file %s", file->d_name); + } + + closedir(rep); + + return 0; } @@ -448,105 +570,87 @@ void pcilib_xml_initialize_registers(pcilib_t* pci,xmlDocPtr doc){ * @param[in] model the current model of ctx * @return an error code */ +int pcilib_init_xml(pcilib_t *ctx, const char *model) { + int err; -int pcilib_init_xml(pcilib_t* ctx, char* model){ - char *path,*pwd, **line, *line_xsd=NULL; - int i=1,k; - xmlDocPtr* docs; - DIR* rep=NULL; - struct dirent* file=NULL; - int err, err_count=0; - - path=malloc(sizeof(char*)); - line=malloc(sizeof(char*)); - line[0]=NULL; - - /** we first get the env variable corresponding to the place of the xml files*/ - path=getenv("PCILIB_MODEL_DIR"); - if(path==NULL){ - path=PCILIB_MODEL_DIR; - } - - /** we then open the directory corresponding to the ctx model*/ - pwd=malloc((strlen(path)+strlen(model))*sizeof(char)); - sprintf(pwd,"%s%s/",path,model); - if((rep=opendir(pwd))==NULL){ - pcilib_warning("could not open the directory for xml files: error %i\n",errno); - return PCILIB_ERROR_NOTINITIALIZED; - } + char *model_dir; + char *xsd_path; - /** we iterate through the files of the directory, to get the xml files and the xsd file*/ - while((file=readdir(rep))!=NULL){ - if(strstr(file->d_name,".xml")!=NULL){ - line=realloc(line,i*sizeof(char*)); - line[i-1]=malloc((strlen(file->d_name)+strlen(pwd)+1)*sizeof(char)); - sprintf(line[i-1],"%s%s",pwd,file->d_name); /**< here i wanted to use realpath() function, but it was not working correctly*/ - i++; - } - if(strstr(file->d_name,".xsd")!=NULL){ - line_xsd=malloc((strlen(file->d_name)+strlen(pwd))*sizeof(char)); - sprintf(line_xsd,"%s%s",pwd,file->d_name); - } - } + struct stat st; - if(line_xsd==NULL){ - pcilib_warning("no xsd file found"); - return PCILIB_ERROR_NOTINITIALIZED; + model_dir = getenv("PCILIB_MODEL_DIR"); + if (!model_dir) model_dir = PCILIB_MODEL_DIR; + + xsd_path = (char*)alloca(strlen(model_dir) + 16); + if (!xsd_path) return PCILIB_ERROR_MEMORY; + + sprintf(xsd_path, "%s/model.xsd", model_dir); + if (stat(xsd_path, &st)) { + pcilib_info("XML models are not present"); + return PCILIB_ERROR_NOTFOUND; } - if(line[0]==NULL){ - pcilib_warning("no xml file found"); - return PCILIB_ERROR_NOTINITIALIZED; + ctx->xml.parser = xmlNewParserCtxt(); + if (!ctx->xml.parser) { + xmlErrorPtr xmlerr = xmlGetLastError(); + if (xmlerr) pcilib_error("xmlNewParserCtxt reported error %d (%s)", xmlerr->code, xmlerr->message); + else pcilib_error("Failed to create an XML parser context"); + return PCILIB_ERROR_FAILED; } - - /** for each xml file, we validate it, and get the registers and the banks*/ - docs=malloc((i-1)*sizeof(xmlDocPtr)); - ctx->xml_ctx=malloc(sizeof(pcilib_xml_context_t)); - ctx->xml_ctx->docs=malloc(sizeof(xmlDocPtr)*(i-1)); - ctx->xml_ctx->nb_registers=0; - ctx->xml_ctx->nb_new_banks=0; - if(!(ctx->xml_ctx) || !(ctx->xml_ctx->docs)) - return PCILIB_ERROR_MEMORY; + err = pcilib_xml_load_xsd(ctx, xsd_path); + if (err) return err; + + return pcilib_process_xml(ctx, model); +} +/** pcilib_free_xml + * this function free the xml parts of the pcilib_t running, and some libxml ashes + * @param[in] pci the pcilib_t running +*/ +void pcilib_free_xml(pcilib_t *ctx) { + int i; + + memset(ctx->xml.bank_nodes, 0, sizeof(ctx->xml.bank_nodes)); + for (i = 0; i < ctx->num_banks; i++) { + if (ctx->bank_ctx[i]) + ctx->bank_ctx[i]->xml = NULL; + } - for(k=0;k<i-1;k++){ - if((err=pcilib_xml_validate(line[k],line_xsd))==0){ - if((docs[k]=xmlParseFile(line[k]))){ - pcilib_xml_initialize_banks(ctx,docs[k]); - pcilib_xml_initialize_registers(ctx,docs[k]); + for (i = 0; i < ctx->num_reg; i++) { + ctx->register_ctx[i].xml = NULL; + } + + for (i = 0; i < ctx->xml.num_files; i++) { + if (ctx->xml.docs[i]) { + xmlFreeDoc(ctx->xml.docs[i]); + ctx->xml.docs[i] = NULL; } - else{ - pcilib_error("xml document %s not parsed successdfullly\n",line[k]); - err_count++; + if (ctx->xml.xpath[i]) { + xmlXPathFreeContext(ctx->xml.xpath[i]); + ctx->xml.xpath[i] = NULL; } - } - } - - ctx->xml_ctx->docs=docs; - - free(pwd); - free(line); - free(line_xsd); + } + ctx->xml.num_files = 0; - if(err_count>0) return PCILIB_ERROR_NOTINITIALIZED; - return 0; -} + if (ctx->xml.validator) { + xmlSchemaFreeValidCtxt(ctx->xml.validator); + ctx->xml.validator = NULL; + } + + if (ctx->xml.schema) { + xmlSchemaFree(ctx->xml.schema); + ctx->xml.schema = NULL; + + } -/** pcilib_clean_xml - * this function free the xml parts of the pcilib_t running, and some libxml ashes - * @param[in] pci the pcilib_t running + if (ctx->xml.parser) { + xmlFreeParserCtxt(ctx->xml.parser); + ctx->xml.parser = NULL; + } +/* + xmlSchemaCleanupTypes(); + xmlCleanupParser(); + xmlMemoryDump(); */ -void pcilib_free_xml(pcilib_t* pci){ - - free(pci->xml_ctx->xml_banks); - free(pci->xml_ctx->xml_registers); - pci->xml_ctx->xml_banks=NULL; - pci->xml_ctx->xml_registers=NULL; - free(pci->xml_ctx); - pci->xml_ctx=NULL; - - xmlCleanupParser(); - xmlMemoryDump(); - } diff --git a/pcilib/xml.h b/pcilib/xml.h index a88a8f9..6ad8676 100644 --- a/pcilib/xml.h +++ b/pcilib/xml.h @@ -1,39 +1,66 @@ -/** - * @file xml.h +/** + * @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_ +#ifndef _PCILIB_XML_H +#define _PCILIB_XML_H +#include <pcilib.h> #include <libxml/tree.h> -#include "pcilib.h" +#include <libxml/xpath.h> +#include <libxml/xmlschemas.h> + +#define PCILIB_MAX_MODEL_FILES 32 + +typedef struct pcilib_xml_s pcilib_xml_t; + +struct pcilib_xml_s { + size_t num_files; /**< Number of currently loaded XML documents */ + + xmlDocPtr docs[PCILIB_MAX_MODEL_FILES]; /**< Pointers to parsed XML documents */ + xmlXPathContextPtr xpath[PCILIB_MAX_MODEL_FILES]; /**< Per-file XPath context */ + + xmlParserCtxtPtr parser; /**< Pointer to the XML parser context */ + xmlSchemaPtr schema; /**< Pointer to the parsed xsd schema */ + xmlSchemaValidCtxtPtr validator; /**< Pointer to the XML validation context */ + + xmlNodePtr bank_nodes[PCILIB_MAX_REGISTER_BANKS]; /**< pointer to xml nodes of banks in the xml file */ +}; -typedef struct{ - xmlDocPtr* docs; - xmlNodePtr* xml_banks; /**<pointer to xml nodes of banks in the xml file*/ - xmlNodePtr* xml_registers; /**< pointer to xml nodes of registers in the xml file*/ - unsigned int nb_registers; - unsigned int nb_new_banks; -}pcilib_xml_context_t; +#ifdef __cplusplus +extern "C" { +#endif /** * this function gets the xml files and validates them, before filling the pcilib_t struct with the registers and banks of those files - *@param[in,out] pci the pcilib_t struct running that gets filled with banks and registers + *@param[in,out] ctx the pcilib_t struct running that gets filled with banks and registers *@param[in] model the name of the model */ -int pcilib_init_xml(pcilib_t* pci, char* model); +int pcilib_init_xml(pcilib_t *ctx, const char *model); -/** pcilib_clean_xml +/** pcilib_free_xml * this function free the xml parts of the pcilib_t running, and some libxml ashes - * @param[in] pci the pcilib_t running + * @param[in] ctx the pcilib_t running */ -void pcilib_free_xml(pcilib_t* pci); +void pcilib_free_xml(pcilib_t *ctx); + + +/** pcilib_process_xml + * this function free the xml parts of the pcilib_t running, and some libxml ashes + * @param[in] ctx the pcilib_t running + * @param[in] location of XML files relative to the PCILIB_MODEL_DIR +*/ +int pcilib_process_xml(pcilib_t *ctx, const char *location); + +#ifdef __cplusplus +} +#endif -#endif /*_XML_*/ +#endif /*_PCILIB_XML_H */ diff --git a/pcitool/CMakeLists.txt b/pcitool/CMakeLists.txt index 0c0eef2..2f3639f 100644 --- a/pcitool/CMakeLists.txt +++ b/pcitool/CMakeLists.txt @@ -4,6 +4,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/pcilib ${CMAKE_BINARY_DIR}/pcilib ${FASTWRITER_INCLUDE_DIRS} + ${LIBXML2_INCLUDE_DIRS} ) link_directories( diff --git a/pcitool/camera.xml b/pcitool/camera.xml deleted file mode 100644 index 753c707..0000000 --- a/pcitool/camera.xml +++ /dev/null @@ -1,923 +0,0 @@ -<?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 4c21e99..2ae569f 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1,6 +1,7 @@ #define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200112L #define _BSD_SOURCE +#define _DEFAULT_SOURCE #include <stdio.h> #include <stdlib.h> @@ -38,7 +39,6 @@ #include "error.h" #include "debug.h" #include "model.h" -#include "xml.h" #include "locking.h" /* defines */ @@ -348,8 +348,6 @@ 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]); @@ -1005,8 +1003,8 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, format = model_info->banks[bank_id].format; if (!format) format = "%lu"; - err = pcilib_read_register_by_id(handle, regid, &value); - // err = pcilib_read_register(handle, bank, reg, &value); + err = pcilib_read_register_by_id(handle, regid, &value); + // err = pcilib_read_register(handle, bank, reg, &value); if (err) printf("Error reading register %s\n", reg); else { printf("%s = ", reg); @@ -3134,7 +3132,7 @@ int main(int argc, char **argv) { else Usage(argc, argv, "The %i data values is specified, but %i required", argc - optind, size); case MODE_READ: if (!addr) { - if (((!dma_info)||(!dma_info->api))&&(!model_info->api)) { + if (((!dma_info)||(!dma_info->api))&&(!model_info->api)&&(!handle->num_reg)) { // if (model == PCILIB_MODEL_PCI) { if ((amode != ACCESS_DMA)&&(amode != ACCESS_CONFIG)) Usage(argc, argv, "The address is not specified"); @@ -3394,6 +3392,6 @@ int main(int argc, char **argv) { pcilib_close(handle); if (data != argv + optind) free(data); - + return err; } diff --git a/pcitool/config.txt b/pcitool/config.txt deleted file mode 100644 index 14bcc57..0000000 --- a/pcitool/config.txt +++ /dev/null @@ -1,13 +0,0 @@ -///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 deleted file mode 100755 index 10d49b7..0000000 --- a/pcitool/registers_and_banks.xsd +++ /dev/null @@ -1,242 +0,0 @@ -<?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> diff --git a/protocols/CMakeLists.txt b/protocols/CMakeLists.txt index 88a1e8e..e05c454 100644 --- a/protocols/CMakeLists.txt +++ b/protocols/CMakeLists.txt @@ -3,6 +3,7 @@ include_directories( ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/pcilib ${CMAKE_BINARY_DIR}/pcilib + ${LIBXML2_INCLUDE_DIRS} ) set(HEADERS ${HEADERS} default.h software.h) diff --git a/protocols/default.c b/protocols/default.c index dd1da54..5e344cf 100644 --- a/protocols/default.c +++ b/protocols/default.c @@ -13,18 +13,15 @@ int pcilib_default_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank_ctx, pcilib_register_value_t val = 0; const pcilib_register_bank_description_t *b = bank_ctx->bank; - printf("bank name %s\n",b->name); - printf("bank bar %i\n",b->bar); - printf("addr %i\n",addr); + int access = b->access / 8; - printf("access : %i\n",access); + ptr = pcilib_resolve_register_address(ctx, b->bar, b->read_addr + addr); - // printf("ptr %s\n",ptr); default_datacpy(&val, ptr, access, b); - printf("val : %i\n",val); + // *value = val&BIT_MASK(bits); *value = val; - printf("value : %i\n",*value); + return 0; } diff --git a/xml/CMakeLists.txt b/xml/CMakeLists.txt new file mode 100644 index 0000000..fab54ef --- /dev/null +++ b/xml/CMakeLists.txt @@ -0,0 +1,3 @@ +install(FILES model.xsd + DESTINATION ${PCILIB_MODEL_DIR} +) diff --git a/models/ipecamera/registers_and_banks.xsd b/xml/model.xsd index 234cc05..5febd1a 100755..100644 --- a/models/ipecamera/registers_and_banks.xsd +++ b/xml/model.xsd @@ -184,7 +184,7 @@ <xsd:simpleType name="rwmask_type"> <xsd:restriction base="xsd:string"> - <xsd:enumeration value="all bits"/> + <xsd:enumeration value="all"/> <xsd:enumeration value="0"/> </xsd:restriction> </xsd:simpleType> diff --git a/models/ipecamera/camera.xml b/xml/test/camera.xml index 288f6a4..5f803d0 100644 --- a/models/ipecamera/camera.xml +++ b/xml/test/camera.xml @@ -2,432 +2,6 @@ <model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <banks> <bank> - <bank_description> - <bar>0</bar> - <size>128</size> - <protocol>default</protocol> - <read_address>0x9010</read_address> - <write_address>0x9000</write_address> - <word_size>8</word_size> - <endianess>little</endianess> - <format>%lu</format> - <name>cmosis</name> - <description>CMOSIS CMV2000 Registers</description> - </bank_description> - <registers> - <register> - <address>1</address> - <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> - <address>3</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_start1</name> - </register> - <register> - <address>5</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_start2</name> - </register> - <register> - <address>7</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_start3</name> - </register> - <register> - <address>9</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_start4</name> - </register> - <register> - <address>11</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_start5</name> - </register> - <register> - <address>13</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_start6</name> - </register> - <register> - <address>15</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_start7</name> - </register> - <register> - <address>17</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_start8</name> - </register> - <register> - <address>19</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_number_lines1</name> - </register> - <register> - <address>21</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_number_lines2</name> - </register> - <register> - <address>23</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_number_lines3</name> - </register> - <register> - <address>25</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_number_lines4</name> - </register> - <register> - <address>27</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_number_lines5</name> - </register> - <register> - <address>29</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_number_lines6</name> - </register> - <register> - <address>31</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_number_lines7</name> - </register> - <register> - <address>33</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_number_lines8</name> - </register> - <register> - <address>35</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_sub_s</name> - </register> - <register> - <address>37</address> - <offset>0</offset> - <size>16</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_sub_a</name> - </register> - <register> - <address>39</address> - <offset>0</offset> - <size>1</size> - <default>1</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_color</name> - </register> - <register> - <address>40</address> - <offset>0</offset> - <size>2</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_image_flipping</name> - </register> - <register> - <address>41</address> - <offset>0</offset> - <size>2</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_exp_flags</name> - </register> - <register> - <address>42</address> - <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> - <address>45</address> - <offset>0</offset> - <size>24</size> - <default>1088</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_exp_step</name> - </register> - <register> - <address>48</address> - <offset>0</offset> - <size>24</size> - <default>1</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_exp_kp1</name> - </register> - <register> - <address>51</address> - <offset>0</offset> - <size>24</size> - <default>1</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_exp_kp2</name> - </register> - <register> - <address>54</address> - <offset>0</offset> - <size>2</size> - <default>1</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_nr_slopes</name> - </register> - <register> - <address>55</address> - <offset>0</offset> - <size>8</size> - <default>1</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_exp_seq</name> - </register> - <register> - <address>56</address> - <offset>0</offset> - <size>24</size> - <default>1088</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_exp_time2</name> - </register> - <register> - <address>59</address> - <offset>0</offset> - <size>24</size> - <default>1088</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_exp_step2</name> - </register> - <register> - <address>68</address> - <offset>0</offset> - <size>2</size> - <default>1</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_nr_slopes2</name> - </register> - <register> - <address>69</address> - <offset>0</offset> - <size>8</size> - <default>1</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_exp_seq2</name> - </register> - <register> - <address>70</address> - <offset>0</offset> - <size>16</size> - <default>1</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_number_frames</name> - </register> - <register> - <address>72</address> - <offset>0</offset> - <size>2</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_output_mode</name> - </register> - <register> - <address>78</address> - <offset>0</offset> - <size>12</size> - <default>85</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_training_pattern</name> - </register> - <register> - <address>80</address> - <offset>0</offset> - <size>18</size> - <default>0x3FFFF</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_channel_en</name> - </register> - <register> - <address>82</address> - <offset>0</offset> - <size>3</size> - <default>7</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_special_82</name> - </register> - <register> - <address>89</address> - <offset>0</offset> - <size>8</size> - <default>96</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_vlow2</name> - </register> - <register> - <address>90</address> - <offset>0</offset> - <size>8</size> - <default>96</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_vlow3</name> - </register> - <register> - <address>100</address> - <offset>0</offset> - <size>14</size> - <default>16260</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_offset</name> - </register> - <register> - <address>102</address> - <offset>0</offset> - <size>2</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_pga</name> - </register> - <register> - <address>103</address> - <offset>0</offset> - <size>8</size> - <default>32</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_adc_gain</name> - </register> - <register> - <address>111</address> - <offset>0</offset> - <size>1</size> - <default>1</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_bit_mode</name> - </register> - <register> - <address>112</address> - <offset>0</offset> - <size>2</size> - <default>0</default> - <rwmask>0</rwmask> - <mode>RW</mode> - <name>cmosis_adc_resolution</name> - </register> - <register> - <address>115</address> - <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> <bar>0</bar> <size>0x0200</size> @@ -617,7 +191,7 @@ <offset>0</offset> <size>32</size> <default>0</default> - <rwmask>all bits</rwmask> + <rwmask>all</rwmask> <mode>RW</mode> <name>fr_param2</name> <registers_bits> @@ -649,7 +223,7 @@ <offset>0</offset> <size>32</size> <default>0</default> - <rwmask>all bits</rwmask> + <rwmask>all</rwmask> <mode>RW</mode> <name>fr_thresholds</name> </register> @@ -658,7 +232,7 @@ <offset>0</offset> <size>10</size> <default>0</default> - <rwmask>all bits</rwmask> + <rwmask>all</rwmask> <mode>RW</mode> <name>fr_pixel_thr</name> </register> @@ -667,7 +241,7 @@ <offset>10</offset> <size>11</size> <default>0</default> - <rwmask>all bits</rwmask> + <rwmask>all</rwmask> <mode>RW</mode> <name>fr_num_pixel_thr</name> </register> @@ -676,7 +250,7 @@ <offset>21</offset> <size>11</size> <default>0</default> - <rwmask>all bits</rwmask> + <rwmask>all</rwmask> <mode>RW</mode> <name>fr_num_lines_thr</name> </register> |