diff options
-rw-r--r-- | .bzrignore | 1 | ||||
-rw-r--r--[-rwxr-xr-x] | misc/xml/format.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | pci | 0 | ||||
-rw-r--r-- | pcilib/CMakeLists.txt | 13 | ||||
-rw-r--r-- | pcilib/pcipywrap.c | 190 | ||||
-rw-r--r-- | pcilib/pcipywrap.i | 6 | ||||
-rw-r--r-- | pcitool/cli.c | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/device_info.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/dump_file.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/grab.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/ipedma/ipecamera-frame.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/ipedma/ipecamera-test.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/ipedma/test.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/nwldma/bench.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/nwldma/cleanup.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/reload.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/test-iommu.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/xilinxdma/xilinx_dma.sh | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/xilinxdma/xilinx_dma_static_mem.sh | 0 | ||||
-rw-r--r-- | xml/test2/camera.xml | 6 | ||||
-rw-r--r-- | xml/test2/names.xml | 16 | ||||
-rw-r--r-- | xml/test2/props.xml | 4 | ||||
-rw-r--r-- | xml/test2/reg2.py | 0 | ||||
-rw-r--r-- | xml/test2/units.xml | 35 | ||||
-rw-r--r-- | xml/test2/views.xml | 6 |
25 files changed, 278 insertions, 1 deletions
@@ -31,3 +31,4 @@ pcitool/pci version.h Doxyfile html +build diff --git a/misc/xml/format.sh b/misc/xml/format.sh index c522f44..c522f44 100755..100644 --- a/misc/xml/format.sh +++ b/misc/xml/format.sh diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt index cdc9c3f..ea275a3 100644 --- a/pcilib/CMakeLists.txt +++ b/pcilib/CMakeLists.txt @@ -13,6 +13,19 @@ add_library(pcilib SHARED pci.c datacpy.c memcpy.c pagecpy.c cpu.c timing.c expo target_link_libraries(pcilib dma protocols views ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${EXTRA_SYSTEM_LIBS} ${LIBXML2_LIBRARIES} ${PYTHON_LIBRARIES}) add_dependencies(pcilib dma protocols views) +#Creating python wrapping +FIND_PACKAGE(SWIG REQUIRED) +INCLUDE(${SWIG_USE_FILE}) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +SET(CMAKE_SWIG_FLAGS "") + +SET_SOURCE_FILES_PROPERTIES(pcipywrap.i PROPERTIES SWIG_FLAGS "-includeall") +SWIG_ADD_MODULE(pcipywrap python pcipywrap.i pcipywrap.c pci.c datacpy.c memcpy.c pagecpy.c cpu.c timing.c export.c value.c bar.c fifo.c model.c bank.c register.c view.c unit.c property.c xml.c py.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c) +SWIG_LINK_LIBRARIES(pcipywrap ${PYTHON_LIBRARIES} dma protocols views ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${EXTRA_SYSTEM_LIBS} ${LIBXML2_LIBRARIES}) +#wrapping end + install(TARGETS pcilib LIBRARY DESTINATION lib${LIB_SUFFIX} ) diff --git a/pcilib/pcipywrap.c b/pcilib/pcipywrap.c new file mode 100644 index 0000000..5abd56c --- /dev/null +++ b/pcilib/pcipywrap.c @@ -0,0 +1,190 @@ +#include "pcilib.h" + +//Remove unused headers +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <stdint.h> +#include <stdarg.h> +#include <fcntl.h> +#include <unistd.h> +#include <sys/time.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <errno.h> +#include <alloca.h> +#include <arpa/inet.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> +#include <pthread.h> +#include <signal.h> +#include <dlfcn.h> + +#include <getopt.h> + +#include <fastwriter.h> + +#include "pcitool/sysinfo.h" +#include "pcitool/formaters.h" + +#include "views/transform.h" +#include "views/enum.h" +#include "pci.h" +#include "plugin.h" +#include "config.h" +#include "tools.h" +#include "kmem.h" +#include "error.h" +#include "debug.h" +#include "model.h" +#include "locking.h" + +pcilib_t* __ctx = 0; +pcilib_model_description_t *model_info = 0; + +/*! + * \brief присваивание указателя на устройство. Закрытая функция. Будет проходить при парсинге xml. + * \param ctx + */ +void __initCtx(void* ctx) +{ + __ctx = ctx; +} + +/*! + * \brief создание хэндлера устройства, для тестирования скрипта не из программы. + * \return + */ +void __createCtxInstance(const char *fpga_device, const char *model) +{ + __ctx = pcilib_open(fpga_device, model); + model_info = pcilib_get_model_description(__ctx); +} + +int read_register(const char *bank, const char *regname, void *value) +{ + int ret = pcilib_read_register(__ctx, bank, regname, (pcilib_register_value_t*)value); + return ret; +} + +void Error(const char *message, const char *attr, ...) +{ + printf("Catch error: %s, %s\n", message, attr); +} + +int ReadRegister(const char *bank, const char *reg) { + + const char *view = NULL; + const char *unit = NULL; + const char *attr = NULL; + pcilib_t *handle = __ctx; + int i; + int err; + const char *format; + + pcilib_register_bank_t bank_id; + pcilib_register_bank_addr_t bank_addr = 0; + + pcilib_register_value_t value; + + // Adding DMA registers + pcilib_get_dma_description(handle); + + if (reg||view||attr) { + pcilib_value_t val = {0}; + if (attr) { + if (reg) err = pcilib_get_register_attr(handle, bank, reg, attr, &val); + else if (view) err = pcilib_get_property_attr(handle, view, attr, &val); + else if (bank) err = pcilib_get_register_bank_attr(handle, bank, attr, &val); + else err = PCILIB_ERROR_INVALID_ARGUMENT; + + if (err) { + if (err == PCILIB_ERROR_NOTFOUND) + Error("Attribute %s is not found", attr); + else + Error("Error (%i) reading attribute %s", err, attr); + } + + err = pcilib_convert_value_type(handle, &val, PCILIB_TYPE_STRING); + if (err) Error("Error converting attribute %s to string", attr); + + printf("%s = %s", attr, val.sval); + if ((val.unit)&&(strcasecmp(val.unit, "name"))) + printf(" %s", val.unit); + printf(" (for %s)\n", (reg?reg:(view?view:bank))); + } else if (view) { + if (reg) { + err = pcilib_read_register_view(handle, bank, reg, view, &val); + if (err) Error("Error reading view %s of register %s", view, reg); + } else { + err = pcilib_get_property(handle, view, &val); + if (err) Error("Error reading property %s", view); + } + + if (unit) { + err = pcilib_convert_value_unit(handle, &val, unit); + if (err) { + if (reg) Error("Error converting view %s of register %s to unit %s", view, reg, unit); + else Error("Error converting property %s to unit %s", view, unit); + } + } + + err = pcilib_convert_value_type(handle, &val, PCILIB_TYPE_STRING); + if (err) { + if (reg) Error("Error converting view %s of register %s to string", view); + else Error("Error converting property %s to string", view); + } + + printf("%s = %s", (reg?reg:view), val.sval); + if ((val.unit)&&(strcasecmp(val.unit, "name"))) + printf(" %s", val.unit); + printf("\n"); + } else { + pcilib_register_t regid = pcilib_find_register(handle, bank, reg); + bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); + format = model_info->banks[bank_id].format; + if (!format) format = "%lu"; + err = pcilib_read_register_by_id(handle, regid, &value); + if (err) Error("Error reading register %s", reg); + + printf("%s = ", reg); + printf(format, value); + printf("\n"); + } + } else { + if (model_info->registers) { + if (bank) { + bank_id = pcilib_find_register_bank(handle, bank); + bank_addr = model_info->banks[bank_id].addr; + } + + printf("Registers:\n"); + for (i = 0; model_info->registers[i].bits; i++) { + if ((model_info->registers[i].mode & PCILIB_REGISTER_R)&&((!bank)||(model_info->registers[i].bank == bank_addr))&&(model_info->registers[i].type != PCILIB_REGISTER_BITS)) { + bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[i].bank); + format = model_info->banks[bank_id].format; + if (!format) format = "%lu"; + + err = pcilib_read_register_by_id(handle, i, &value); + if (err) printf(" %s = error reading value", model_info->registers[i].name); + else { + printf(" %s = ", model_info->registers[i].name); + printf(format, value); + } + + printf(" ["); + printf(format, model_info->registers[i].defvalue); + printf("]"); + printf("\n"); + } + } + } else { + printf("No registers"); + } + printf("\n"); + } + + return 0; +} diff --git a/pcilib/pcipywrap.i b/pcilib/pcipywrap.i new file mode 100644 index 0000000..fc7f4ef --- /dev/null +++ b/pcilib/pcipywrap.i @@ -0,0 +1,6 @@ +%module pcipywrap +/*extern void* __ctx;*/ +extern void __initCtx(void* ctx); +extern void __createCtxInstance(const char *fpga_device, const char *model); +extern int read_register(const char *bank, const char *regname, void *value); +extern int ReadRegister(const char *reg); diff --git a/pcitool/cli.c b/pcitool/cli.c index 4d5d3d5..8350d24 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1385,7 +1385,7 @@ int ReadData(pcilib_t *handle, ACCESS_MODE mode, FLAGS flags, pcilib_dma_engine_ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, const char *bank, const char *reg, const char *view, const char *unit, const char *attr) { int i; int err; - const char *format; + const char *format; pcilib_register_bank_t bank_id; pcilib_register_bank_addr_t bank_addr = 0; diff --git a/tests/device_info.sh b/tests/device_info.sh index 21e59db..21e59db 100755..100644 --- a/tests/device_info.sh +++ b/tests/device_info.sh diff --git a/tests/dump_file.sh b/tests/dump_file.sh index 6773a19..6773a19 100755..100644 --- a/tests/dump_file.sh +++ b/tests/dump_file.sh diff --git a/tests/grab.sh b/tests/grab.sh index daa08c1..daa08c1 100755..100644 --- a/tests/grab.sh +++ b/tests/grab.sh diff --git a/tests/ipedma/ipecamera-frame.sh b/tests/ipedma/ipecamera-frame.sh index 5e72c6c..5e72c6c 100755..100644 --- a/tests/ipedma/ipecamera-frame.sh +++ b/tests/ipedma/ipecamera-frame.sh diff --git a/tests/ipedma/ipecamera-test.sh b/tests/ipedma/ipecamera-test.sh index cd21391..cd21391 100755..100644 --- a/tests/ipedma/ipecamera-test.sh +++ b/tests/ipedma/ipecamera-test.sh diff --git a/tests/ipedma/test.sh b/tests/ipedma/test.sh index 48f9184..48f9184 100755..100644 --- a/tests/ipedma/test.sh +++ b/tests/ipedma/test.sh diff --git a/tests/nwldma/bench.sh b/tests/nwldma/bench.sh index d0bf323..d0bf323 100755..100644 --- a/tests/nwldma/bench.sh +++ b/tests/nwldma/bench.sh diff --git a/tests/nwldma/cleanup.sh b/tests/nwldma/cleanup.sh index 87e1517..87e1517 100755..100644 --- a/tests/nwldma/cleanup.sh +++ b/tests/nwldma/cleanup.sh diff --git a/tests/reload.sh b/tests/reload.sh index 62c6e22..62c6e22 100755..100644 --- a/tests/reload.sh +++ b/tests/reload.sh diff --git a/tests/test-iommu.sh b/tests/test-iommu.sh index 5a5924b..5a5924b 100755..100644 --- a/tests/test-iommu.sh +++ b/tests/test-iommu.sh diff --git a/tests/xilinxdma/xilinx_dma.sh b/tests/xilinxdma/xilinx_dma.sh index 4fedac3..4fedac3 100755..100644 --- a/tests/xilinxdma/xilinx_dma.sh +++ b/tests/xilinxdma/xilinx_dma.sh diff --git a/tests/xilinxdma/xilinx_dma_static_mem.sh b/tests/xilinxdma/xilinx_dma_static_mem.sh index 23ee5c9..23ee5c9 100755..100644 --- a/tests/xilinxdma/xilinx_dma_static_mem.sh +++ b/tests/xilinxdma/xilinx_dma_static_mem.sh diff --git a/xml/test2/camera.xml b/xml/test2/camera.xml new file mode 100644 index 0000000..4b31209 --- /dev/null +++ b/xml/test2/camera.xml @@ -0,0 +1,6 @@ +<?xml version="1.0"?> +<model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <bank bar="0" size="0x0200" protocol="software_registers" read_address="0x9000" write_address="0x9000" word_size="32" endianess="little" format="0x%lx" name="fpga" description="IPECamera Registers"> + <register address="0x00" offset="0" size="32" default="0" rwmask="0" mode="RW" name="reg1"/> + </bank> +</model> diff --git a/xml/test2/names.xml b/xml/test2/names.xml new file mode 100644 index 0000000..f6ddbcc --- /dev/null +++ b/xml/test2/names.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <enum name="enumm1" description="enum towards temperatures register"> + <name name="high" value="0x100" min="0x2" max="0x300"/> + <name name="low" value="0x010"/> + </enum> + <enum name="enumm2" description="enum towards sensor_temperature register"> + <name name="high" value="0x120"/> + <name name="low" value="0x010" min="0x00" max="0x020"/> + </enum> + <enum name="enumm3" description="enum towards cmosis_exp_register register"> + <name name="short" value="0x000"/> + <name name="mid" value="0x010"/> + <name name="long" value="0x100" min="0x0F0"/> + </enum> +</model> diff --git a/xml/test2/props.xml b/xml/test2/props.xml new file mode 100644 index 0000000..f7a1329 --- /dev/null +++ b/xml/test2/props.xml @@ -0,0 +1,4 @@ +<?xml version="1.0"?> +<model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <transform path="/test/prop1" register="test_prop1" unit="C" read_from_register="(503975./1024000)*${/registers/fpga/reg1} + 28715./100" description="formula to get real fpga temperature from the fpga_temperature register in decimal"/> +</model> diff --git a/xml/test2/reg2.py b/xml/test2/reg2.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/xml/test2/reg2.py diff --git a/xml/test2/units.xml b/xml/test2/units.xml new file mode 100644 index 0000000..74ab9f7 --- /dev/null +++ b/xml/test2/units.xml @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <unit name="C"> + <transform unit="K" transform="$value+273.15"/> + <transform unit="F" transform="$value*(9./5)+32"/> + </unit> + <unit name="K"> + <transform unit="C" transform="$value-273.15"/> + <transform unit="F" transform="($value-273.15)*(9./5)+32"/> + </unit> + <unit name="F"> + <transform unit="C" transform="($value-32)*5./9"/> + <transform unit="K" transform="($value+273.15-32)*5./9"/> + </unit> + <unit name="s"> + <transform unit="ms" transform="$value*1000"/> + <transform unit="us" transform="$value*1000000"/> + <transform unit="ns" transform="$value*1000000000"/> + </unit> + <unit name="ms"> + <transform unit="s" transform="$value/1000"/> + <transform unit="us" transform="$value*1000"/> + <transform unit="ns" transform="$value*1000000"/> + </unit> + <unit name="us"> + <transform unit="s" transform="$value/1000000"/> + <transform unit="ms" transform="$value/1000"/> + <transform unit="ns" transform="$value*1000"/> + </unit> + <unit name="ns"> + <transform unit="s" transform="$value/1000000000"/> + <transform unit="ms" transform="$value/1000000"/> + <transform unit="us" transform="$value/1000"/> + </unit> +</model> diff --git a/xml/test2/views.xml b/xml/test2/views.xml new file mode 100644 index 0000000..c40cd0f --- /dev/null +++ b/xml/test2/views.xml @@ -0,0 +1,6 @@ +<?xml version="1.0"?> +<model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <transform name="formuu1" unit="C" read_from_register="(503975./1024000)*$value - 27315./100" write_to_register="($value + 27315./100)*(1024000./503975)" description="formula to get real fpga temperature from the fpga_temperature register in decimal"/> + <transform name="formuu2" unit="C1" read_from_register="((1./4)*($value - 1200)) if $freq==0 else ((3./10)*($value - 1000))" write_to_register="4*$value + 1200 if $freq==0 else (10./3)*$value + 1000" description="formula to get real sensor temperature from the sensor_temperature register in decimal"/> + <transform name="formuu3" unit="us" read_from_register="($value+(43./100))*129./(40*1000000)if $freq==0 else ($value+(43./100))*129./(48*1000000)" write_to_register="$value/129.*(40*1000000) - 43./100 if $freq==0 else $value/129.*(48*1000000) - 43./100" description="formula to get real exposure time from the cmosis_exp_time register in decimal"/> +</model> |