0

I am using atxmega256a3bu microcontroller for my project, I want to make a program architecture like I have compiled and programmed the code and now only some APIs can be changed and reprogrammed into the board other portion of flash should not be changed and newly compiled APIs can work with rest of the code that was already programmed in the flash.

for example, I have made all the code and downloaded it into the board, which has a API function named

todo_callback()
{
printf("nothing to do");
}

Now if I want to change the function as below:

todo_callback()
{
printf("updated to do");
}

then how can I update this function only whithout changing the whole flash code.

Regards, shreyas.

timrau
  • 22,578
  • 4
  • 51
  • 64
shreyas_patel21
  • 317
  • 1
  • 4
  • 14
  • Why do you want to do that? Usually the firmware is reflashed as a whole on microcontrollers. – starblue Feb 12 '14 at 15:46
  • because i don't have enough memory to update the whole image, because i want to use fail safe update, so for back up of the old image I need more memory. If I can do this, then only application section, which is being updated needs to be backed up. – shreyas_patel21 Feb 13 '14 at 09:12

1 Answers1

1

Depending on what you're trying to do, you could make the "fixed" code use a function table for the implementations of its functions. To add new implementations, you'd just need to be able to overwrite the appropriate pointer.

(This, of course, implies that the function table should be writable, or generated on boot with the ability to find new entries for the table.)

Basically, the idea is to add one level of indirection so that functions can be swapped without changing the code that uses them.

John Visosky
  • 237
  • 1
  • 1
  • Hi John, thank you for support, are you saying that I have to manage function table for todo_callback() function in boot section? I did not get your answer of swapping the function without changing the code, how to do that? – shreyas_patel21 Feb 07 '14 at 09:34
  • The 'base' code would provide a function to set the todo_callback function pointer ("set_todo_callback"). It could have a default that it uses if none has been set. The new code would then actually set it, if needed. (I mentioned a "function table" in case you have many of these. But if it's just one function, that's overkill.) This may help: http://www.newty.de/fpt/index.html – John Visosky Feb 07 '14 at 17:16