Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 20th, 2012, 04:46 AM
julianh julianh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 5 julianh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m
Reputation Power: 0
Cool 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))
return cc

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 ...

Thanks

Reply With Quote
  #2  
Old September 20th, 2012, 10:15 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
Write, python stores everything as an object.
Python has objects with contiguous arrays.
You could try the array module
import array # etceteras
or scipy
www.scipy.org

Carefully read all of the ctypes doc
http://docs.python.org/py3k/library/ctypes.html
I'm pretty sure you'll find that it supports large transfers.

Here's an example I wrote years ago to call the gsl from python using ctypes: http://code.activestate.com/recipes/576550-gsl-real-fft-in-python3/

Hope some thing in here helps.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old September 21st, 2012, 02:52 AM
julianh julianh is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 5 julianh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m
Reputation Power: 0
Array access

Hi David,

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

Thanks

Reply With Quote
  #4  
Old September 21st, 2012, 01:48 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
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.

ALSO, PLEASE

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.
Attached Files
File Type: zip gsl.zip (574.3 KB, 39 views)

Last edited by b49P23TIvg : September 21st, 2012 at 10:44 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > DMA and python

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap