This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using CODE_SECTION() and/or SET_CODE_SECTION() on functions from .lib libraries

Other Parts Discussed in Thread: MOTORWARE

Hi,

I am developing a library for C2000 devices. It is based on several MotorWare components as well as custom software. My question is if it is possible to use CODE_SECTION() and/or SET_CODE_SECTION() on functions defined in the .lib. For example, lets say i have foo.lib and foo.h. The header contains the function declaration, e.g.:

extern void foo_bar(void);

If I place the following in the foo.h header:

#pragma CODE_SECTION(foo_bar, mysect)

If I build the library first and then link to it from my application with the .cmd file specifying mysect and allocating to where I want it, will this place foo_bar() in the mysect section in the main.out and/or main.map?

Cheers,

Vassilios

  • The pragma will have no effect unless it is visible when you compile the library itself. Let us suppose that foo_bar.c contains the definition of function foo_bar. If foo_bar.c includes foo.h, then foo.lib will define foo_bar in section "mysect" as desired. However, if foo_bar.c does not include foo.h, or some other instance of the pragma, the pragma in foo.h will have no effect when included by main.c
  • Hi,

    Thanks for the prompt reply. So yes I build foo.lib with the same header and so I designed the header(s) to provide clean interfaces to the library as well as for building the library itself. One final question though. If the library is compiled with the #pragma, then will it always be dependent on some .cmd file defining and allocating mysect, i.e. will mysect be a requirement for ANY .cmd file I use?
  • Yes. Consider naming the section ".text:foo" or ".text:foo:bar" instead of "mysect." If the user fails to specify a placement for .text:foo, it will automatically be placed with .text