[Lazarus] conditionals for detecting hardware platforms?

Bo Berglund bo.berglund at gmail.com
Mon Feb 29 17:19:14 CET 2016


On Mon, 29 Feb 2016 16:55:04 +0200, Chavoux Luyt <chavoux at gmail.com>
wrote:

>Hi Bo,
>
>From: Bo Berglund <bo.berglund at gmail.com>
>
>> <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.

>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





More information about the Lazarus mailing list