Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9282203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:18:54+00:00 2026-06-18T18:18:54+00:00

I am trying to interface a C library (beaglebone PRU driver prussdrv.c) with Python.

  • 0

I am trying to interface a C library (beaglebone PRU driver prussdrv.c) with Python. The particular function I want to access returns a mmap pointer as illustrated below:

int __prussdrv_memmap_init(void) {
      prussdrv.pru0_dataram_base = mmap(0, prussdrv.pruss_map_size, PROT_READ | PROT_WRITE,
         MAP_SHARED, prussdrv.mmap_fd, PRUSS_UIO_MAP_OFFSET_PRUSS);
      ...

int prussdrv_map_prumem(unsigned int pru_ram_id, void **address) {    
     switch (pru_ram_id) {
     case PRUSS0_PRU0_DATARAM:
          *address = prussdrv.pru0_dataram_base;
           break;

prussdrv_map_prumem (DATARAM[PRU_NUM], &pruDataMem);
pruDataMem_byte = (unsigned char*) pruDataMem;

I would like to encapsulate either pruDataMem or pruDataMem_byte and pass it to Python as a mmap object. Is there a straightforward way to do this? I’ve looked at capsule and ctypes but they do not appear to do what I am looking for?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T18:18:55+00:00Added an answer on June 18, 2026 at 6:18 pm

    I don’t think there’s any way to create a Python mmap object out of a native mapping like this. The protocol isn’t published, and neither is the internal format.

    But of course the source is available. So, as long as your mapping meets all the same criteria as one created by new_mmap_object, you could manually construct an mmap_object wrapping the information, and pass it back. (You can’t actually access the mmap_object type, because it’s not in any header file. But if you create an equivalent type, or just copy-and-paste the code, you’ll be passing it around as a PyObject *, and as long as its type field points to the right type, it’ll work.)

    However, I’m not sure you need to do this. Do you really need an mmap, or just any buffer that you can treat as a string/list/iterator? Because the latter is a lot easier. For that, you can just create an old-style buffer or new-style buffer class—or, if you only need 2.7+, use the concrete memoryview type. Conceptually, it seems to make sense that you’re returning a view of the mapped memory, rather than the mapping itself, but I can imagine some use cases where this might be inappropriate.

    Finally, you can always create a new class that exposes whatever interface you want around your mapping, and make it as much (or as little) like mmap as you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to interface a c++ member function with a legacy C library taking
I'm trying to wrap a c library in a high-level python interface with Boost.Python.
I'm trying to build the foreign function interface library for a Cortex-M3 processor using
I am trying to have interface for C++ library for python using boost::python ,
I am trying to access the wifi interface through python: In bash I can
I'm trying out the python Solr interface Sunburnt , and I've come across a
I'm trying to write a dead-simple interface for an IRC library, like so: import
I'm trying to use the restlet.org library to build a RESTful web interface, and
I'm trying to interface a library that exports an Automation compatible interface via a
I am trying to install pysqlite (Python interface to the SQLite). I downloaded the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.