2

I need to call function from a specific addresses (e.g. Double function indirection in C) but not exactly the same. I could pull the pointers from the mapping table and manipulate dynamically generated function pointers, which I prefer to avoid. E.g., I want to avoid this type of call:

((int)(*)(void*)) compute_volume = ((int)(*)(void*)) 0x20001000;

int vol = (*compute_volume)();

Instead, I would prefer to use some sort of linker provided symbols or other methods to achieve the following, except that the compute_volume() function is provided by a different image, perhaps something like this:

extern int compute_volume(void);

vol = compute_volume();

In other words, I intend to split my code into multiple images, thus reducing the need for modifying or overwriting the flash everytime a symbol or computation changes.

Any suggestions/ideas?

Alejandro Montilla
  • 2,626
  • 3
  • 31
  • 35
Vasu
  • 62
  • 1
  • 7
  • Function pointers are designed to do that. But if the syntax bothers you, in this case you could use a `#define` or maybe a [typedef](https://stackoverflow.com/questions/4295432/typedef-function-pointer) – Déjà vu Dec 28 '17 at 01:55
  • or http://blog.atollic.com/using-gnu-gcc-on-arm-cortex-devices-placing-code-and-data-on-special-memory-addresses-using-the-gnu-ld-linker – Déjà vu Dec 28 '17 at 02:15
  • Note that this does *not* give you more update cycles compared to rewriting the entire flash every time, because microcontroller flash memory does not have wear leveling. – Nominal Animal Dec 28 '17 at 03:52

1 Answers1

0

You can define jump table which would reside always in te same flash region (you can define that region in linker and pragmas in the code I think) and when called it jumps to desired function.

In firmware part I you only define symbols which refer to "passing" functions addresses (if you will always keep it in the same region it will make future updates MUCH easier). In firmware part II you create jump table which resides in the address space you were referring to in firmware part I and calls the actual functions.

I am not 100% sure I have described it correctly but this should give you some notion how to solve your problem. The link Ring Ø provided should help you with placing jump table code in one place.

Crllo
  • 1