pcipywrap.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef PCIPYWRAP_H
  2. #define PCIPYWRAP_H
  3. #include "pci.h"
  4. #include "error.h"
  5. #include <Python.h>
  6. typedef struct {
  7. void* ctx;
  8. int shared;
  9. } pcipywrap;
  10. /*!
  11. * \brief Redirect pcilib standart log stream to exeption text.
  12. * Logger will accumulate errors untill get message, starts with "#E".
  13. * After that, logger will write last error, and all accumulated errors
  14. * to Python exeption text
  15. */
  16. void redirect_logs_to_exeption();
  17. /*!
  18. * \brief Wraps for pcilib_open function.
  19. * \param[in] fpga_device path to the device file [/dev/fpga0]
  20. * \param[in] model specifies the model of hardware, autodetected if NULL is passed
  21. * \return Pointer to pcilib_t, created by pcilib_open; NULL with exeption text, if failed.
  22. */
  23. PyObject* create_pcilib_instance(const char *fpga_device, const char *model);
  24. pcipywrap *new_pcipywrap(const char* fpga_device, const char* model);
  25. pcipywrap *create_pcipywrap(PyObject* ctx);
  26. void delete_pcipywrap(pcipywrap *self);
  27. /*!
  28. * \brief Reads register value. Wrap for pcilib_read_register function.
  29. * \param[in] regname the name of the register
  30. * \param[in] bank should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
  31. * \return register value, can be integer or float type; NULL with exeption text, if failed.
  32. */
  33. PyObject* pcipywrap_read_register(pcipywrap *self, const char *regname, const char *bank);
  34. /*!
  35. * \brief Writes value to register. Wrap for pcilib_write_register function.
  36. * \param[in] val Register value, that needs to be set. Can be int, float or string.
  37. * \param[in] regname the name of the register
  38. * \param[in] bank should specify the bank name if register with the same name may occur in multiple banks, NULL otherwise
  39. * \return 1, serialized to PyObject or NULL with exeption text, if failed.
  40. */
  41. PyObject* pcipywrap_write_register(pcipywrap *self, PyObject* val, const char *regname, const char *bank);
  42. /*!
  43. * \brief Reads propety value. Wrap for pcilib_get_property function.
  44. * \param[in] prop property name (full name including path)
  45. * \return property value, can be integer or float type; NULL with exeption text, if failed.
  46. */
  47. PyObject* pcipywrap_get_property(pcipywrap *self, const char *prop);
  48. /*!
  49. * \brief Writes value to property. Wrap for pcilib_set_property function.
  50. * \param[in] prop property name (full name including path)
  51. * \param[in] val Property value, that needs to be set. Can be int, float or string.
  52. * \return 1, serialized to PyObject or NULL with exeption text, if failed.
  53. */
  54. PyObject* pcipywrap_set_property(pcipywrap *self, PyObject* val, const char *prop);
  55. PyObject* pcipywrap_get_registers_list(pcipywrap *self, const char *bank);
  56. PyObject* pcipywrap_get_register_info(pcipywrap *self, const char* reg,const char *bank);
  57. PyObject* pcipywrap_get_property_list(pcipywrap *self, const char* branch);
  58. PyObject* pcipywrap_read_dma(pcipywrap *self, unsigned char dma, size_t size);
  59. PyObject* pcipywrap_lock_global(pcipywrap *self);
  60. void pcipywrap_unlock_global(pcipywrap *self);
  61. /*!
  62. * \brief Wrap for pcilib_lock
  63. * \param lock_id lock identificator
  64. * \warning This function should be called only under Python standart threading lock.
  65. * Otherwise it will stuck with more than 1 threads. See /xml/test/test_prop4.py
  66. * for example.
  67. * \return 1, serialized to PyObject or NULL with exeption text, if failed.
  68. */
  69. PyObject* pcipywrap_lock(pcipywrap *self, const char *lock_id);
  70. PyObject* pcipywrap_lock_persistent(pcipywrap *self, const char *lock_id);
  71. PyObject* pcipywrap_try_lock(pcipywrap *self, const char *lock_id);
  72. PyObject* pcipywrap_try_lock_persistent(pcipywrap *self, const char *lock_id);
  73. PyObject* pcipywrap_unlock(pcipywrap *self, const char *lock_id);
  74. PyObject* pcipywrap_unlock_persistent(pcipywrap *self, const char *lock_id);
  75. #endif /* PCIPYWRAP_H */