summaryrefslogtreecommitdiffstats
path: root/pcilib
diff options
context:
space:
mode:
Diffstat (limited to 'pcilib')
-rw-r--r--pcilib/CMakeLists.txt1
-rw-r--r--pcilib/pcilib.h1
-rw-r--r--pcilib/pcipywrap.c84
-rw-r--r--pcilib/pcipywrap.i5
-rw-r--r--pcilib/xml.c16
5 files changed, 85 insertions, 22 deletions
diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt
index 41a1169..b1f5251 100644
--- a/pcilib/CMakeLists.txt
+++ b/pcilib/CMakeLists.txt
@@ -14,7 +14,6 @@ target_link_libraries(pcilib dma protocols views ${CMAKE_THREAD_LIBS_INIT} ${UFO
add_dependencies(pcilib dma protocols views)
#Creating python wrapping
-FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/pcilib/pcilib.h b/pcilib/pcilib.h
index 3e7cf2b..4d2b7e9 100644
--- a/pcilib/pcilib.h
+++ b/pcilib/pcilib.h
@@ -54,6 +54,7 @@ typedef enum {
PCILIB_REGISTER_RW1C = 5,
PCILIB_REGISTER_W1I = 8, /**< writting 1 inversts the bit, writting 0 keeps the value */
PCILIB_REGISTER_RW1I = 9,
+ PCILIB_REGISTER_NO_CHK = 16 /**< dont check register value after set*/
} pcilib_register_mode_t;
typedef enum {
diff --git a/pcilib/pcipywrap.c b/pcilib/pcipywrap.c
index bed4b31..50a3074 100644
--- a/pcilib/pcipywrap.c
+++ b/pcilib/pcipywrap.c
@@ -26,7 +26,7 @@ PyObject* __createPcilibInstance(const char *fpga_device, const char *model)
/*!
* \brief Sets python exeption text. Function interface same as printf.
*/
-void setPyExeptionText(const char* msg, ...)
+void __setPyExeptionText(const char* msg, ...)
{
char *buf;
size_t sz;
@@ -55,13 +55,13 @@ void setPyExeptionText(const char* msg, ...)
/*!
* \brief Sets pcilib context to wraper.
* \param[in] addr Pointer to pcilib_t, serialized to bytearray
- * \return true, serialized to PyObject, NULL with exeption text, if failed.
+ * \return 1, serialized to PyObject or NULL with exeption text, if failed.
*/
PyObject* __setPcilib(PyObject* addr)
{
if(!PyByteArray_Check(addr))
{
- setPyExeptionText(PyExc_Exception, "Incorrect addr type. Only bytearray is allowed");
+ __setPyExeptionText(PyExc_Exception, "Incorrect addr type. Only bytearray is allowed");
return;
}
@@ -150,20 +150,18 @@ int pcilib_convert_pyobject_to_val(pcilib_t* ctx, PyObject* pyVal, pcilib_value_
/*!
- * \brief Reads register value.
+ * \brief Reads register value. Wrap for pcilib_read_register function.
* \param[in] regname the name of the register
* \param[in] bank should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
- * \return register value, can be integer or float type
+ * \return register value, can be integer or float type; NULL with exeption text, if failed.
*/
PyObject* read_register(const char *regname, const char *bank)
{
if(!__ctx)
{
- setPyExeptionText("pcilib_t handler not initialized");
+ __setPyExeptionText("pcilib_t handler not initialized");
return NULL;
}
-
- pcilib_get_dma_description(__ctx);
pcilib_value_t val = {0};
pcilib_register_value_t reg_value;
@@ -173,26 +171,72 @@ PyObject* read_register(const char *regname, const char *bank)
err = pcilib_read_register(__ctx, bank, regname, &reg_value);
if(err)
{
- setPyExeptionText("Failed: read_register (%i)", err);
+ __setPyExeptionText("Failed: pcilib_read_register (%i)", err);
return NULL;
}
err = pcilib_set_value_from_register_value(__ctx, &val, reg_value);
if(err)
{
- setPyExeptionText("Failed: pcilib_set_value_from_register_value (%i)", err);
+ __setPyExeptionText("Failed: pcilib_set_value_from_register_value (%i)", err);
return NULL;
}
- return pcilib_convert_val_to_pyobject(__ctx, &val, setPyExeptionText);
+ return pcilib_convert_val_to_pyobject(__ctx, &val, __setPyExeptionText);
}
+/*!
+ * \brief Writes value to register. Wrap for pcilib_write_register function.
+ * \param[in] val Register value, that needs to be set. Can be int, float or string.
+ * \param[in] regname the name of the register
+ * \param[in] bank should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
+ * \return 1, serialized to PyObject or NULL with exeption text, if failed.
+ */
+PyObject* write_register(PyObject* val, const char *regname, const char *bank)
+{
+ if(!__ctx)
+ {
+ __setPyExeptionText("pcilib_t handler not initialized");
+ return NULL;
+ }
+
+ pcilib_value_t val_internal = {0};
+ pcilib_register_value_t reg_value;
+
+ int err;
+ err = pcilib_convert_pyobject_to_val(__ctx, val, &val_internal);
+ if(err)
+ {
+ __setPyExeptionText("Failed pcilib_convert_pyobject_to_val (%i)", err);
+ return NULL;
+ }
+
+ reg_value = pcilib_get_value_as_register_value(__ctx, &val_internal, &err);
+ if(err)
+ {
+ __setPyExeptionText("Failed: pcilib_get_value_as_register_value (%i)", err);
+ return NULL;
+ }
+
+ err = pcilib_write_register(__ctx, bank, regname, reg_value);
+ if(err)
+ {
+ __setPyExeptionText("Failed: pcilib_write_register (%i)", err);
+ return NULL;
+ }
+ return PyInt_FromLong((long)1);
+}
+/*!
+ * \brief Reads propety value. Wrap for pcilib_get_property function.
+ * \param[in] prop property name (full name including path)
+ * \return property value, can be integer or float type; NULL with exeption text, if failed.
+ */
PyObject* get_property(const char *prop)
{
if(!__ctx)
{
- setPyExeptionText("pcilib_t handler not initialized");
+ __setPyExeptionText("pcilib_t handler not initialized");
return NULL;
}
@@ -203,20 +247,26 @@ PyObject* get_property(const char *prop)
if(err)
{
- setPyExeptionText("Failed pcilib_get_property (%i)", err);
+ __setPyExeptionText("Failed pcilib_get_property (%i)", err);
return NULL;
}
- return pcilib_convert_val_to_pyobject(__ctx, &val, setPyExeptionText);
+ return pcilib_convert_val_to_pyobject(__ctx, &val, __setPyExeptionText);
}
+/*!
+ * \brief Writes value to property. Wrap for pcilib_set_property function.
+ * \param[in] prop property name (full name including path)
+ * \param[in] val Property value, that needs to be set. Can be int, float or string.
+ * \return 1, serialized to PyObject or NULL with exeption text, if failed.
+ */
PyObject* set_property(const char *prop, PyObject* val)
{
int err;
if(!__ctx)
{
- setPyExeptionText("pcilib_t handler not initialized");
+ __setPyExeptionText("pcilib_t handler not initialized");
return NULL;
}
@@ -224,7 +274,7 @@ PyObject* set_property(const char *prop, PyObject* val)
err = pcilib_convert_pyobject_to_val(__ctx, val, &val_internal);
if(err)
{
- setPyExeptionText("pcilib_convert_pyobject_to_val (%i)", err);
+ __setPyExeptionText("Failed pcilib_convert_pyobject_to_val (%i)", err);
return NULL;
}
@@ -232,7 +282,7 @@ PyObject* set_property(const char *prop, PyObject* val)
if(err)
{
- setPyExeptionText("Failed pcilib_get_property (%i)", err);
+ __setPyExeptionText("Failed pcilib_get_property (%i)", err);
return NULL;
}
diff --git a/pcilib/pcipywrap.i b/pcilib/pcipywrap.i
index 8d0f74e..cd632f8 100644
--- a/pcilib/pcipywrap.i
+++ b/pcilib/pcipywrap.i
@@ -1,7 +1,10 @@
%module pcipywrap
-extern PyObject* read_register(const char *regname, const char *bank = NULL);
extern PyObject* __createPcilibInstance(const char *fpga_device, const char *model = NULL);
extern PyObject* __setPcilib(PyObject* addr);
+
+extern PyObject* read_register(const char *regname, const char *bank = NULL);
+extern PyObject* write_register(PyObject* val, const char *regname, const char *bank = NULL);
+
extern PyObject* get_property(const char *prop);
extern PyObject* set_property(const char *prop, PyObject* val);
diff --git a/pcilib/xml.c b/pcilib/xml.c
index 2384e95..099da76 100644
--- a/pcilib/xml.c
+++ b/pcilib/xml.c
@@ -492,6 +492,8 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo
static int pcilib_xml_parse_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node, pcilib_view_description_t *desc) {
xmlAttrPtr cur;
const char *value, *name;
+
+ int register_no_chk = 0;
for (cur = node->properties; cur != NULL; cur = cur->next) {
if (!cur->children) continue;
@@ -539,7 +541,15 @@ static int pcilib_xml_parse_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDoc
return PCILIB_ERROR_INVALID_DATA;
}
}
- }
+ else if (!strcasecmp(name, "no_set_check")) {
+ if (!strcasecmp(value, "1"))
+ register_no_chk = 1;
+ }
+ }
+ if(register_no_chk)
+ {
+ desc->mode |= PCILIB_REGISTER_NO_CHK;
+ }
return 0;
}
@@ -550,7 +560,7 @@ static int pcilib_xml_create_script_view(pcilib_t *ctx, xmlXPathContextPtr xpath
const char *value, *name;
pcilib_view_context_t *view_ctx;
- pcilib_access_mode_t mode = 0;
+ pcilib_access_mode_t mode = PCILIB_REGISTER_NO_CHK;
pcilib_script_view_description_t desc = {{0}};
desc.base.api = &pcilib_script_view_api;
@@ -595,7 +605,7 @@ static int pcilib_xml_create_transform_view(pcilib_t *ctx, xmlXPathContextPtr xp
const char *value, *name;
pcilib_view_context_t *view_ctx;
- pcilib_access_mode_t mode = 0;
+ pcilib_access_mode_t mode = PCILIB_REGISTER_NO_CHK;
pcilib_transform_view_description_t desc = {{0}};
desc.base.api = &pcilib_transform_view_api;