[fpc-pascal] accessing hardware ports in FPC
Tomas Hajny
XHajT03 at mbox.vol.cz
Tue May 22 13:50:53 CEST 2007
Daniƫl Mantione wrote:
> Op Tue, 22 May 2007, schreef Felipe Monteiro de Carvalho:
>
>> OS specific code is not a devil. Sometimes it's necessary. Ports alone
>> won't work on linux also, by the way.
>
> Even if extra calls are needed, like ioperm, the existance of a hardware
> serial port unit, ignoring the existance of ioperm, can be very usefull
> for a Linux programmer, as long as it uses the portable port[] array.
> An ioperm call is easily added to any program.
>
> It is the same for WinNT, while the programmer might have to do extra
> tricks, existing code can be very valueable for him.
>
> Needless to say I don't recommend people driving hardware by port access,
> but some people feel/have the need to. There is no need why such code
> should be different on WinNT than on Win95; FPC's task is to hide such
> differences from the user.
I don't know Linux, but: If ioperm needs to be called just once (without
specifying a particular port number), this call could be added to unit
initialization. If it needs to be called for particular port number or
port range, we could add a function doing this to interface of unit ports
(and document it as appropriate, of course), because it's better to
provide common approach than to require users to fiddle with IFDEFs and
platform specific API for this (such a function probably exists for most
platforms and platforms not requiring such a thing may simply ignore it).
Potentially, we could even add a boolean array to implementation part of
unit ports maintaining the permission status for all the ports. Calling
the "IOPerm" function would mark access to that port as permitted. Call to
getter/setter would check the status first and call IOPerm if needed,
otherwise skip the IOPerm call (that would allow both fast access and "no
hassle" approach for our users).
Tomas
More information about the fpc-pascal
mailing list