Jump to content

Recommended Posts

Hi,

I need certain functions (which writes to LCD) to be accessible from the bootloader as well as my main application.

 

Can I put these function at fixed address in my bootloader? And call them in the main code as well?

If the above approach is correct how do I declare the same function in my main code?

 

Is there any other better approach?

 

Thank you

John

 

Share this post


Link to post
Share on other sites

Hi

 

You can call a function at a known address simply by using a function pointer.

 

You might want to take a look at pages 72 and 73 of the "Boost C manual"

 

 

HIH

 

Best regards

Jorge

Edited by JorgeF

Share this post


Link to post
Share on other sites

Thanks Jorge,

 

But still I'm not able to get it working.

 

Here is an example of what I'm trying to achieve. I want to call a function in my Main code which is declared in my bootloader at an specific address.

 

in my BOOTLOADER the function is mapped to address 0x070

 

void Message(char *str) @0x070
{
	do{
		while(!txsta1.TRMT); // Wait till Tx Reg is free
		txreg1 = *str;       // Load the data into the TxReg
		str++;
	  }while(*str != '\0');      // Loop till end of String
}	

In my MAIN application I use function pointer

void (*foo)(char*);

void main()
{
    while(1)
   {
       if(recByte == 'T')
       {
         foo = 0x70;  // address of the function
         foo("Test Message");
         recByte = ' ';
       }
   }
}

 

Everything compiles ok but I get a warning

 

Warning: function never returns: '__fptr'

 

Then I tried

 

foo = ((*)(char*))0x070;
foo("Test Message");
Still I get error.
Then I tried using typedef
typedef void (*FnPtr)(char*);
FnPtr foo;

foo = (FnPtr)0x70;

 

Still I get same warning.

 

 

 

But if I move the function void Message(char *str) @0x070

to main application, and use

foo = Message;

 

the code works.

 

 

I'm I doing something really stupid or is there anyother way to point to an address of a function?

 

Many Thanks

John

Edited by John S

Share this post


Link to post
Share on other sites

I's tricky to call a function that is not linked to an application. The way to proceed is to use built in assembler like 'call 0x70'. The only issue with this approach is that it's impossible to use call arguments so the solution is to declare a fixed address array to pass data to your bootloader function.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Thanks Pavel,

 

But what is the difference between CALL and GOTO ?

 

I use GOTO instruction to jump to bootloader to main and vice versa..

 

 

Many Thanks

Share this post


Link to post
Share on other sites

...But what is the difference between CALL and GOTO ?...

 

No difference. GOTO is ok as well. My point was to use built-in assembler rather than C but whatever you use CALL or GOTO doesn't matter.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×