This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Absolute address for FUNCTIONS in CODE-space

Does anyone knows a methode, to declare a function in a specific CODE address in C51?
Something lika a org xxxx in assembler !

  • This is a job for the Linker, not the compiler.

    Take a look in the Linker Manual (you will also need to look at the Compiler Manual for info on the Segment naming convention).

  • Whenever you want to locate a function at an absolute address, one question you should ask yourself is whether or not you need a vector table instead. A vector table will add one level of indirection to the solution, but it becomes easier to manage the two halves of your program when you keep updating the routines to be called. Only the vector table has to be located at a well-known address, and the table entries are small and of constant size (unlike entire function bodies).

    Note that in order to get a C function into a segment all by itself so you can tell the linker where to place it, you'll need to put it in a .c file all by itself.

  • Let me try to explain you what I'm trying to do:

    I'm working with uPSD3212 from ST electronics. In this processor I have two flashes and I can configure PSEN to active Flash one or Flash two and the some for RD signal, in other word I can use one flash as a code and the other as a Data and vice-versa.

    Take a look what I'm doing:

    1. I record a simple program in the flash one and a simple program in the flash two.
    2. When I reset my device the second Flash is configured as code (PSEN access it) and the second as a Data (RD access it).
    3. In my code, on second flash, I change PSEN to access my fist flash and RD to access my second flash. In other words I change my code from the second flash to the first (I'm trying to make a bootloader).

    When I make it, my "program count" stay with the same value, and, of course, my program in the first flash doesn't work fine.

    There is a way to jump to same particular adress (ljmp XXXX) and put a function in this adress (org XXX) using C?

  • What you're doing with your two functions is a combination of traditional C51 techniques "code banking" and "xdata banking". Neither would strictly need any knowledge about absolute memory locations for functions if you had let the C compiler help you doing it.

    If you insist doing it on your own, you'll have to investigate the suggestions you already got: put functions in separate segments, let the linker place those segments at fixed locations.