This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Questions on calling external function

Excuse me, I have a question on calling external function. 

board using: nrf52832

softdevice using : s132(6.1.1)

The situation: There are two applications  which is named as app1.c and app2.c . In app1.c, there is the main application which will handle all the work . In app2.c will only contain a function which will return a value. For example, app2.c contain the function int foo(char a1, char b2). In my project, may I program these two application separately in two memory address in which app1.c can call the function in app2.c externally. 

for example in app1.c:

int main(){

int a = foo('a','b');//call the function in app2.c and use the value returned later

}

Reason to do this: These two application is written by two different person so that one can call the external function when it is needed. 

Searching the internet, I find that superior call interface will be helpful but I cannot understand how it works after reading the document: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v14.1.0%2Flib_svc.html&anchor=lib_svc_reserved_svc_number

May you give me an example on how to use the superior call interface to call an external function which is located at a specific address.The document is quite difficult to follow as it has several section and has not provided a deep explanation 

Question list:

a) do I need to program the bootloader into the board before using the svc.

b) can the svc works when the external function store at another memory address. e.g. app1 stores at 0x46000 having a size of 0x20000, external function saving at 0x66000

c) may you give me an example on how to use the superior call interface to call an external function which is located at a specific address

d) if svc does not work may you suggest me a better alternatives on programming two application on the same block of memory  and enabling jumping between

All in all, thank you for your attention and I will appreciate and be grateful for any help from others.

Parents Reply
  • Thank you for reply. The method you mentioned cannot work in my case provided that the source code of app1 is written by others and the content of the source code cannot not be accessed by me. He will only provide the hex file of the source code so the job for me is to see whether i can write my own function and save it at other place of the memory. Then, the function can be called by the hex file.  Again, thank for your help.

Children
  • That's a bizarre situation!

    Anyhow, in that case, use a library.

  • Hi,

    Yes, use a library.

    If you do not want the users of the library to see the source code then you can compile the .c files and provide the library as .h files plus compiled object files. Then anyone using your library (e.g. using your function, or set of functions,) can link it into their own project without access to the source. Some of the libraries in the nRF5 SDK is (or was previously) provided this way.

    In the extreme cases where making a library will not work then yes, supervisor calls may be an option, as it is with our buttonless DFU solution. Please note however that this is a very complex solution that should only be considered in rare cases, and if you know exactly what you are doing.

    From what you have written, you should use a library. Then you provide that library to the person making the application.

    Regards,
    Terje

  • you should use a library

    Absolutely!

    you provide that library to the person making the application

    I think it's actually the other way around - is the one who is making the application.

  • Hi,

    I also thought it was the other way around at first, but then I read the posts more carefully and it looks like the other people is making the application. Some clarification from would be good here.

    Regards,
    Terje

  • Thank you for all your help. Library definitely is one of the key to the problem.  Refer to tesc, other people  making the application is true provided that I am responsible for writting a function for him to call only. The plan is that he will provide me the hex file of the application and I need to link his hex file with my hex file which contains the code of my function written. Searching the internet, it seems that function cannot be independently exists in a hex file given that I am using Keil as the ide. Therefore, may I ask whether I can store my function at another block of memory and link it to the application hex file. Although library is one the key but it will be inconvenient to implent as I have to give the writter couple of files when amendment is required. Again, I am grateful for all the help from you guys :)

Related