September 20th, 2012, 05:46 AM
DMA and python
Hi I am accessing hardware from Python. I am running Linux.
I have a "C" library compiled as libvv_pts.so that I load using CDLL ...
self.lib = CDLL('./libvv_pts.so')
and in that library there is a function as follows ...
* @brief read data from the application VME address space
* @param handle returned from a successfull open
* @param the 4 byte aligned byte offset where D32 reads will start
* @param buf points to an array where the read data will be stored
* @param size is the size in bytes of the read transaction to be performed
* @return -1 on error (see errno) or 0 if closed OK
int vv_read(void *handle, int byte_offset, int *ibuf, size_t size)
I implement vv_pts.py that calls the C library as follows ...
def vv_read(self, byte_offset):
""" Read from the application FPGA wishbone bus
The byte offset will be aligned to D32
The value will contain the 32 bit integer read
x = c_int(0)
cc = self.lib.vv_read(self.handle, byte_offset, byref(x), 4)
value = x.value
if cc != 0:
raise BusException("Failed vv_read: offset:0x%X" % (byte_offset))
return value & 0xFFFFFFFF
and call it in my program, and this all works just fine but is horribly slow. So I would like to read an array. I could even do a DMA tarnsfer if I could figure out a way of pointing it at Python memory, but I am trying a more simple array access as follows ...
def vv_read_array(self, byte_offset, buf, size):
""" Read size bytes into the string array buf
The byte_offset and size will be D32 aligned
cc = self.lib.vv_read(self.handle, byte_offset, id(buf), size)
if cc != 0:
raise BusException("Failed vv_read_array: offset:0x%X size:%d" % (byte_offset, size))
So I tried "by_ref" and that didn't work, so I am using the id(buf) to get the address to copy to. From my "big integers" question I discover Python doesn't represent data in raw format and my read array function destroys the interpreter.
Can anyone make a suggestion as to how to do a hardware array transfer into Python memory ...
September 20th, 2012, 11:15 AM
September 21st, 2012, 03:52 AM
You say ...
Quote: "I've wrapped the high level gsl_interp routines and the outstanding gsl_rng routines for python3k. By request, I'll post these also."
I would like you to post them
September 21st, 2012, 02:48 PM
OK, here's the complete work.
Assuming I can attach a .zip archive...
There were four errors in the tests, which I fixed. All of were caused by python tightening their code since the python3 beta. It's been a while since I used gsl with python. The fft test finishes with a memory error (failure to deallocate fft storage) which doesn't bode well for the advice I gave earlier in this thread.
I inserted a brief 00README file which accents that although no manual is included (no longer accessible to me, although I know exactly where a hard copy is within 1.1 miles of here) the tests fully demonstrate the functionality, as I recall.
The initial value ODE solver uses an iterator. The code did use the new python3 features.
Edit 2: unit tests take 15 seconds with ubuntu linux distribution on a 2009 ThinkPad T500.
if any of you know how to make an installer so this package can go into site packages, or whatever it's called now in python 3, please make it known.
It's a critical part of the project.
Last edited by b49P23TIvg; September 21st, 2012 at 11:44 PM.
[/code] are essential for python code and Makefiles!