Welcome, Guest
Username: Password: Remember me
CodeTyphon Cross-Build Development, discussions and problems
  • Page:
  • 1

TOPIC:

arm-linux fpMmap error 11 years 8 months ago #2253

  • Ermo
  • Ermo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 11
  • Thank you received: 2
Hi,

and sorry if my question is in wrong topic.

I make simple memory mapping program to
access arm processor gpio register directly.

I found working C code and port it into pascal.
Here is C code: www.friendlyarm.net/forum/topic/67

But program generates Sys_EINVAL exception,
After some research I figured out that FpMmap
last argument (offset)
is responsible throwing exception. If I set it
to 0 and set argument "Len" to suitable size,
everything works just fine, except that program allocates
about 1.5G address space.

Here is my code:
program gpio;

{$mode objfpc}{$H+}

uses
  Classes,SysUtils, baseUnix, Unix
  { you can add units after this };

  const
    MAP_SIZE: size_t = 4096;
    MAP_MASK: off_t = 4095; // MAP_SIZE - 1;
    CONTROL: LongWord =     $56000000;
   // CONTROLBASE = $56000000;

   // CONTROLOFFSET = 14;//$10;

  type
    PCardinal = ^Cardinal;
    PWord = ^Word;
    PByte = ^Byte;

  var
    _memFile: Integer;
    _map_base: Pointer;
    _virtAddr: Pointer;


begin
  try

   _memFile := fpOpen('/dev/mem', O_RDWR or O_SYNC);

   if _memFile < 0 then
   begin
     WriteLn('Error opening system memory');
     Exit;
   end;

   WriteLn('_memFile:' + IntToStr(_memFile));

   _map_base := FpMmap( nil, MAP_SIZE, PROT_READ or PROT_WRITE, MAP_SHARED, _memFile, CONTROL and (not MAP_MASK) ); //produces exception
// if MAP_SIZE is $56000000 and CONTROL = 0 then everything works 

    if Integer(_map_base) < 0 then
    begin
      WriteLn('Error maping memory, error:' + IntToStr(fpGetErrNo));
      Exit;
    end;


    WriteLn('_map_base:'+ IntToStr(Cardinal(_map_base)));

   
   _virtAddr := Pointer(Cardinal(_map_base) + 14); //CONTROL and MAP_MASK

   WriteLn('VirtAddr:'+ IntToStr(Cardinal(_VirtAddr)));

   WriteLn('Byte:' + IntToStr(PByte(_virtAddr)^));
   WriteLn('Word:' + IntToStr(PWord(_virtAddr)^));
   WriteLn('Cardinal:' + IntToStr(PCardinal(_virtAddr)^));


  finally
    fpMUnmap(_map_base,MAP_SIZE);

    if _memFile > 0 then
        fpClose(_memFile);

  end;
end. 

Regards

Ermo

Please Log in or Create an account to join the conversation.

Last edit: by Ermo.

arm-linux fpMmap error 11 years 8 months ago #2262

  • avra
  • avra's Avatar
  • Visitor
  • Visitor
$56000000 equals 1442840576 which is about 1.5GB you see. LED register address is at $56000014 so it seams like you misunderstood some parameter meanings. Anyway, following links might be interesting to you if you want GPIO on ARM:
www.raspberrypi.org/phpBB3/viewtopic.php?t=11233&p=124121
www.mail-archive.com/fpc-pascal@lists.fr...al.org/msg28439.html
searchco.de/codesearch/view/10114228
www.mme-berlin.de/arm9-modul/arm9-modul.pdf
stackoverflow.com/questions/11638674/how...-embedded-linux-gpio

You can also take a look at sources inside of FPC ..\rtl\embedded\arm

Please Log in or Create an account to join the conversation.

Last edit: by avra.

arm-linux fpMmap error 11 years 7 months ago #2447

  • Ermo
  • Ermo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 11
  • Thank you received: 2
After long vacation and other works I'm finally back and found solution.
Difference between c and pascal code was different function calls. C uses old mmap syscall where
offset is bytes. Pascal uses new mmap syscall, where offset number means page count, page size is 4096 bytes.
Now I have fast gpio driver, 3.7MHz speed is very good I think. B)

Please Log in or Create an account to join the conversation.

arm-linux fpMmap error 11 years 7 months ago #2449

  • avra
  • avra's Avatar
  • Visitor
  • Visitor
Did you make any changes to the above code? In the mean time take a look at similar topic:
www.lazarus.freepascal.org/index.php/top...g95833.html#msg95833

Please Log in or Create an account to join the conversation.

Last edit: by avra.

arm-linux fpMmap error 11 years 7 months ago #2453

  • Ermo
  • Ermo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 11
  • Thank you received: 2
Yes, I made lot of changes and also
wrote completely new gpio driver classes
and little quick and dirty test application.

I attached driver and test program and if someone found this is helpful,
I'm glad to share my knowledge
And thanks again avra, pointing me to right direction
Attachments:
The following user(s) said Thank You: avra, FredyCC

Please Log in or Create an account to join the conversation.

arm-linux fpMmap error 11 years 6 months ago #2514

  • RudiRatlos
  • RudiRatlos's Avatar
  • Offline
  • New Member
  • New Member
  • Posts: 1
  • Thank you received: 0
Hi ermo,
do you have the source code for raspberry pi cpu also?
I'm very interessted in gettig the source code for the Raspberry pi.

thanks,
Rudi

Please Log in or Create an account to join the conversation.

arm-linux fpMmap error 11 years 6 months ago #2565

  • Ermo
  • Ermo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 11
  • Thank you received: 2
Hi rudiratlos,

Not yet, maybe soon
If you want use raspberry gpio, simply change cpu registry constants to new one.
gpio regisrty base value and gpio bank values is described in cpu datasheet.

And if I find some free time I will check it myself.

Please Log in or Create an account to join the conversation.

arm-linux fpMmap error 11 years 4 months ago #2790

  • avra
  • avra's Avatar
  • Visitor
  • Visitor

rudiratlos wrote: I'm very interessted in gettig the source code for the Raspberry pi.

You can try WiringPi Pascal wrapper found here .

Please Log in or Create an account to join the conversation.

Last edit: by avra.
  • Page:
  • 1