[fpc-pascal] Variable alignment in arm-embedded

Koenraad Lelong fpascal at brouwerij.homelinux.net
Fri Jun 8 14:04:52 CEST 2012


On 08-06-12 06:45, Ludo Brands wrote:
>
> Handcrafted alignment:
>
> var
>    ReservedBlock:array[0..$1FF] of byte;
>    IntVectors:pointer;
> begin
>    IntVectors:=pointer((ptruint(@ReservedBlock[0])+$100) and not $ff);
> End;
>
> Or dynamic:
>
> Var
>    pReservedBlock,IntVectors:pointer;
> begin
>    Getmem(pReservedBlock,$200);
>    IntVectors:=pointer((ptruint(pReservedBlock)+$100) and not $ff);
> End;

Thanks Ludo,

I'll take that as a starting point. I hope I will not need the "lost" 
256 bytes in the future.
I can replace the IntVectors-pointer with a pointer to a record of 
pointers, isn't it ? That way I have a clearer view of what vectors I'm 
working with.

TIntVectorTable = record of
	NMI_Handler,
	HardFault_Handler,
	MemManage_Handler,
	BusFault_Handler,
	UsageFault_Handler,
	SWI_Handler,
	DebugMonitor_Handler,
	PendingSV_Handler,
	Systick_Handler,
(* STM32 specific Interrupt Numbers *)
	WWDG_Handler,
	PVD_Handler,
	...
	USBWakeUp_Handler : pointer;
end {TIntVectors};

var
  IntVectors : ^TIntVectorTable;
  ReservedBlock:array[0..$FF+SizeOf(TIntVectorTable)] of byte;

procedure SystickProc; interrupt;

begin
...
end;

begin
   IntVectors:=pointer((ptruint(@ReservedBlock[0])+$100) and not $ff);
   IntVectors^.SystickHandler:=@SystickProc;
...
end.

Koenraad



More information about the fpc-pascal mailing list