element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
Software Application Development mmap access to memory
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 6 replies
  • Subscribers 330 subscribers
  • Views 530 views
  • Users 0 members are here
Related

mmap access to memory

shakith
shakith over 12 years ago

Hi all,

Iu2019m trying to write to and read from memory location such that a DMA can access it. I have image file in u201Cmatu201D data structure from OpenCV. First thing I pack the data the data 32bit word to be sent to the DMA and write to the location given by in_buffer after translating it to virtual address using mmap.

As this point I havenu2019t enabled the DMA, I just write to memory location and read it back using the following functions.


copy_mem2dev(src_frame, IMG_BASEADDR);
//startSobel(FILTER_BASEADDR);
copy_dev2mem(sobelFrame,FILTER_OUT_BASEADDR);

Using a trick from the chapter 15, page 443 given here http://lwn.net/Kernel/LDD3/, I restrict the memory given to linux kernel to 510MB using mem=510M at the bootargs of the dts file. And then input image is given at IMG_BASEADDR = 0x1FE00000 (510MB) and FILTER_OUT_BASEADDR=0x1FF00000 (511MB).

When i enable two function above, the application and linux kernel crashes. Any ideas why?

Additionally what is the difference between mamp and ioremap?
Thanks.

The two functions are:

void copy_mem2dev(Mat img, unsigned long in_buffer)
{
tint count=0;
tunsigned long int map_len = FRAME_WIDTH * FRAME_HEIGHT * 4;
tint fd = open("/dev/mem", O_RDWR);

tunsigned char* virtual_addr_in;

tvirtual_addr_in = (unsigned char*)mmap(NULL, map_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)in_buffer);
tif(virtual_addr_in == MAP_FAILED)
t{
ttperror("virtual_addr_in mapping for absolute memory access failed.
");
ttreturn;
t}

tfor (int i=0; i<FRAME_HEIGHT;i++)
t{
ttfor (int j=0; j<FRAME_WIDTH;j++)
tt{
tttVec3b intensity = img.at<Vec3b>(i, j);
tttuchar red = intensity.val[0]; ttuchar green = intensity.val[1];         uchar blue = intensity.val[2];
tttunsigned int value = 0;
tttvalue += red;
tttvalue += green << 8;
tttvalue += blue  << 16;
tttREG_WRITE(virtual_addr_in,count,value);
tttcount++;
tt}
t}
tmunmap((void *)virtual_addr_in, map_len);
tclose(fd);

}

void copy_dev2mem(Mat img, unsigned long in_buffer)
{
tint count=0;
tunsigned long int map_len = FRAME_WIDTH * FRAME_HEIGHT * 4;
tint fd = open("/dev/mem", O_RDWR);

tunsigned char* virtual_addr_out;

tvirtual_addr_out = (unsigned char*)mmap(NULL, map_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)in_buffer);
tif(virtual_addr_out == MAP_FAILED)
t{
ttperror("virtual_addr_in mapping for absolute memory access failed.
");
ttreturn;
t}

tfor (int i=0; i<FRAME_HEIGHT;i++)
t{
ttfor (int j=0; j<FRAME_WIDTH;j++)
tt{
tttunsigned int value = 0;
tttvalue = REG_READ(virtual_addr_out,count);
tttVec3b intensity;
tttintensity.val[0] = value & 0xff;
tttintensity.val[1] = ( value >> 8 )& 0xff;
tttintensity.val[2] = ( value >> 16)& 0xff;
tttimg.at<Vec3b>(i, j) = intensity;
tttcount++;
tt}
t}
tmunmap((void *)virtual_addr_out, map_len);
tclose(fd);

}

  • Sign in to reply
  • Cancel
  • Former Member
    0 Former Member over 12 years ago

    When I want to access a specific memory area in the linux kernel I use ioremap().
    When I want to access a specific memory area in the userspace I use mmap().

    In which line does it fail?
    What does REG_WRITE()/REG_READ() look like?
    You might want to increase count by 4.

    I'm doing pretty much the same as you, but with gstreamer instead of opencv and the memory above 500MB.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shakith
    0 shakith over 12 years ago

    Thanks. It was count by4 and mat struct to read wasn't initialized properly.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • sergicuen
    0 sergicuen over 12 years ago

    Hi Shakith,
    we got the TRD14.2 running on Zedboard (but the framebuffer). In addition we have written an OpenCV code to drive the DMA->SobelCore->DMA framework from Linux. I think this is what you are looking for.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago

    Hi sergicuen,
    can you share some more informations about that?

    Thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shakith
    0 shakith over 12 years ago

    I have shared my working based trd design on the zedboard on my blog.
    http://shakithweblog.blogspot.nl/2012/12/getting-sobel-filter-application.html

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • sergicuen
    0 sergicuen over 12 years ago

    Hi cgabri,
    I think Sakith's TRD is more complete, it has framebuffer and webcam input.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube