[fpc-devel] Freepascal in microcontrollers
Vinzent Hoefler
JeLlyFish.software at gmx.net
Wed Feb 27 11:05:46 CET 2008
On Wednesday 27 February 2008 09:44, Michael Schnell wrote:
> You can avoid cryptic language constructs in the main source code.
Or you can avoid cryptic languages altogether. :D
> I did not yet use the preprocessor in Pascal but a standard way to
> access memory mapped ports in C is something like this (from the top
> of my head):
>
>
> #define _port = 0x87
>
> #define ByteIO(p) *(((volatile unsigned char)*)(p))
>
> #define port=ByteIO(_port)
-- 8< -- snip --
with Interfaces;
with System.Storage_Elements;
procedure Foo is
--
-- Declare a reusable volatile 8 bit IO port type.
--
type IO_Port is new Integer range 0 .. 255;
for IO_Port'Size use 8; -- 8 bits, of course.
pragma Atomic (IO_Port); -- Sort of superfluous here.
pragma Volatile (IO_Port);
-- Make address conversions directly visible,
-- but only inside "Foo" here.
use System.Storage_Elements;
-- Now declare a (volatile) IO port variable,
-- and tell its address.
My_Port : IO_Port;
for My_Port'Address use To_Address (16#87#);
begin
-- Assign the 0x55 value to the 0x87 address.
My_Port := 2#01010101#;
end Foo;
-- 8< -- snip --
Although it's a whole lot of declarations for this simple:
-- 8< --
_ada_foo:
.LFB3:
movb $85, 135
ret
.LFE3:
-- 8< --
So, given the right choices, neither C, nor a preprocessor is needed.
And hell, preprocessors sometimes are even forbidden for a particular
project. If you want to verify code you need the code which turns up
after being preprocessed anyway.
Vinzent.
More information about the fpc-devel
mailing list