Hi,
if you know where the function is located and you know its prototype then you can create a pointer to a function and load it with the address of the function you want to call. Why it is important to know the prototype of the function? Because there are different return codes for far and near function. (RTC/RTS)...Calling function is via CALL or JSR. Plus you need to know its parameters.
Moreover I'll deal with S12(X) device and not with MagniV (S12Z) device.
If called function is a far function. It has return code RTC.
void (* far far_function)(void);
If called function is a near function. It has return code RTS.
void (* near far_function)(void);
Note that pointer to a far function has following format :
offset_page
so if the function is located at address 0xPageOffset then you have to put adjusted number to a pointer.
Calling a far function in the code:
let function is at logical page 0x3E and its offset is 0x4444
then, written in two code lines:
far_function = (void(*far)()) 0x44443E
far_function();
Calling a near function in the code:
let function is at the address 0xCCCC
then, written in two lines:
near_function = (void(*near)()) 0xCCCC;
near_function();
I have written this answer without testing but believe it will help you.
When you solve such tasks I always suggest to step the code in assembler to see what is executed and whether there is nothing which can cause any issue. I mean also test execution of called function because it can use or set things which are not compatible with an idea and must be solved.
Best regards,
Ladislav
Thanks Ladislav,
I will try this and will update.
Could you please explain me why this kind of function call is needed in bootloader.? Why a normal call of a function defined in user application is not working when called in bootloader?
Hi,
Have you already read https://www.nxp.com/docs/en/application-note/AN4258.pdf
BTW, there could be misunderstanding between us. Have you created a bootloader and application in one project? If yes then the address of function is known otherwise not. I do not see what you really do but I believe the AN I mentioned above brings the light into the issue. Of course, something is a little bit different if you use MagniV device. In this case I suggest to look at https://www.nxp.com/docs/en/application-note/AN4723.pdf
Best regards,
Ladislav