Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-02

conditionals for detecting hardware platforms?

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I am programming with FreePascal and Lazarus towards a Raspberry Pi2 target platform. Doing so on the RPi2 itself is possible and basically works fine, except that the system is a bit sluggish at times and there are other inconveniences as well.
So I moved to a Linux Mint 17.3 Mate system in a virtual computer (VMWare) on my Windows7 PC instead.

Most of what I am doing concerns non-hardware dependent things and works fine as far as I can see.
But there is one snag, and this is the GPIO handling where obviously the GPIO access is not possible on a PC platform...

So I need to put some kind of conditional into my code to redirect the GPIO calls to some simulator I will have to build. (I am assuming that there is no such thing available already of course).

So I would like to know how I can create a conditional that uses the real GPIO if the build is done on the RPi2 itself and for the simulator otherwise.
Something like:

uses
...

  {$IFDEF RPi2Hardware}
  PiGpio,
  {ELSE}
  PiGpioSim,
  {$ENDIF}

Then I could create a PiGpioSim unit as a simulator that defines the same object class but does not target the actual hardware on RPi2 but some other mechanism that I can monitor while debugging in the development PC.

Is there something like "RPi2Hardware" already set up that can be used to check for this?

Bo Berglund Developer in Sweden

Reply by email

Mark Morgan Lloyd
to Bo Berglund
Bo Berglund wrote
I am programming with FreePascal and Lazarus towards a Raspberry Pi2 target platform. Doing so on the RPi2 itself is possible and basically works fine, except that the system is a bit sluggish at times

Apologies for OT, but probably relevant to anybody using RPi. There's a known memory leak in irqbalance which will drive it into thrashing, see

https://github.com/Irqbalance/irqbalance/issues/5

for patch.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Chavoux Luyt

Hi Bo,

From: Bo Berglund

<snip>

I am programming with FreePascal and Lazarus towards a Raspberry Pi2

Show quoted text 10 lines
target platform. Doing so on the RPi2 itself is possible and basically works fine, except that the system is a bit sluggish at times and there are other inconveniences as well. So I moved to a Linux Mint 17.3 Mate system in a virtual computer (VMWare) on my Windows7 PC instead. <snip> So I need to put some kind of conditional into my code to redirect the GPIO calls to some simulator I will have to build. (I am assuming that there is no such thing available already of course).

Another way (which might be easier?) is to look at the GPIO driver code (API) on the Raspberry and write a "fake driver" (.so file?) on the Linux system with the same name, API etc. of the Raspberry GPIO driver (I assume that there is a driver, so forgive me if I am wrong). Since you want to build a simulator in any case, this might be a better option that will not require you to do anything funny in your actual application code?

Regards,
Chavoux
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20160229/26d1c104/attachment.html>

Reply by email

Bo Berglund
to Chavoux Luyt
Chavoux Luyt wrote 8 lines
Hi Bo, From: Bo Berglund > <snip> > So I need to put some kind of conditional into my code to redirect the > GPIO calls to some simulator I will have to build. (I am assuming that > there is no such thing available already of course).

I found that {$ifdef CPUARMHF} can be used as a switch for my purposes.

Show quoted text 7 lines
Another way (which might be easier?) is to look at the GPIO driver code (API) on the Raspberry and write a "fake driver" (.so file?) on the Linux system with the same name, API etc. of the Raspberry GPIO driver (I assume that there is a driver, so forgive me if I am wrong). Since you want to build a simulator in any case, this might be a better option that will not require you to do anything funny in your actual application code?

I looked inside the PiGpio unit to see how it interacts and this is what I found:

function TIoDriver.MapIo: boolean;
begin
 Result := True;
 {$IFDEF RPi2}
   fd := fpopen('/dev/gpiomem', O_RdWr or O_Sync); // Open the master
/dev/memory device
 {$ELSE}
   fd := fpopen('/dev/mem', O_RdWr or O_Sync); // Open the master
/dev/memory device
 {$ENDIF}
  if fd < 0 then
  begin
    Result := False; // unsuccessful memory mapping
  end;
 //
end;

So there is a "master memory device" /dev/gpiomem, whatever that is... I looked at the location in a terminal and found this:

pi at rpi2-jessie2:/dev $ ls -ls g*
0 crw-rw---- 1 root gpio 244, 0 Feb 25 07:40 gpiomem

So there seems to be no .so file here at least...

And I have no clue whatever regarding what to do to create a driver...

Bo Berglund Developer in Sweden

Reply by email