Code Optimization and function VTFT_GetExtData()

General discussion on mikroPascal PRO for FT90x.
Post Reply
Author
Message
M5M8S10
Posts: 16
Joined: 21 Nov 2017 10:03
Location: Germany

Code Optimization and function VTFT_GetExtData()

#1 Post by M5M8S10 » 08 Jun 2020 10:11

Dear Forum / MikroE Team,

In the past I had some problems regarding the address space of formal parameters within functions and procedures (I already wrote a ticket for this, and it really seems to be some sort of bug, a MikroE stuff member confirmed). For MikroPascal PRO for PIC and dsPIC setting the optimization level to 0 turned out to be a good solution. However, in mikroPascal PRO for FT90x, which I use to program my HMI 5'' Display, the function VTFT_GetExtData() can not be passed as function pointer to the External memory setup function FT812_Register_GetExtData() anymore, if the optimization level is set to 0. Here is the code bock of how the function is implemented (I copied from the hardware pattern "MIkromedia_HMI_5_RTP" (this goes for the other VTFT-Settings as well) and yes, I use external resource storage functionallity ):

Code: Select all


function VTFT_GetExtData(fPos : dword; bytesToGet : dword; pBytesGot : ^dword): ^byte;
  var  scOffset : word;
begin
  pBytesGot^ := 0;

  if (rfHandle < 0) then begin
    result := 0; // return with nil if handle was bad.
    exit;
  end;

  // We will utilize some of the fat32 implied features
  // (such as built in sector buffer) to reduce ram memory consumpiton.
  // You can't use this approach if this buffer is going to be used
  // from another thread (i.e. using fat32 routines in interrupt...)
  // In that case or if you have plenty of ram memory use separate
  // as large as possible data buffer.
  f32_sector.fSectNum := rfStartSect + fPos div 512;
  Mmc_Read_Sector(f32_sector.fSectNum, f32_sector.fSect);

  // 512 bytes sector buffer implied.
  scOffset := fPos mod 512;
  if(bytesToGet > 512-scOffset) then
    pBytesGot^ := 512-scOffset
  else
    pBytesGot^ := bytesToGet;

  result := @f32_sector.fSect + scOffset;
end;

I get this error message:
16415 373 Incompatible function pointers (function prototypes do not match): R0 vs ?T3665 HMI_ZMB_301_v0_driver.mpas
for this line in InitVTFTStack():

Code: Select all


...
  // External memory setup			// [line: 16414 ]
  FT812_Register_GetExtData(@VTFT_GetExtData);	// [line: 16415 ]
...

To be clear this is not the case for all other code optimization levels. AFAICS the expected function pointer seems to fit the VTFT_GetExtData()-prototype.

Can someone pleaes explain or confirm this? Is this piece of code still up-to-date or is there any better implementation?

Thank you,
Micha

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Code Optimization and function VTFT_GetExtData()

#2 Post by stefan.filipovic » 15 Jun 2020 15:29

Hi Micha,

Copied from the compiler help file:
emcl files compiled with or without SSA enabled are fully compatible and can be used and mixed without any restrictions, except function pointers.
All function prototypes and function pointers have to be built using the same optimizer because of different calling conventions in different optimizers. In SSA, function parameters are passed via working registers, and without SSA they end up on the function frame.
This means that you cannot have a function implementation which is optimized using SSA optimizer, and to call this function via function pointer in another module which is optimized using NON-SSA.
When using pointers to functions, compiler must know exactly how to pass function parameters and how to execute function call.
Kind regards,
Stefan Filipović

M5M8S10
Posts: 16
Joined: 21 Nov 2017 10:03
Location: Germany

Re: Code Optimization and function VTFT_GetExtData()

#3 Post by M5M8S10 » 10 Nov 2020 13:07

Hi Stefan,
I am talking only about the optimization level setting not the SSA optimization. The latter is a seperate option in the Output Settings of the IDE (unless setting the optimization level to Zero implies a disabled SSA optimization), which I left checked (enabled).

regards,
Micha

Post Reply

Return to “mikroPascal PRO for FT90x General”