How to relocate memory library function using #pragma?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to relocate memory library function using #pragma?

Jump to solution
2,157 Views
leesp
Contributor I

I know how to specify the code segment in a source code. But if I am calling a function using a library, how do I specify the location for this function? For example:

...

#pragma CODE_SEG myCodeSeg

...

libfunc1(); //libfunc1() is a function in the library myProj.lib which was included in the project

...

 

I found that libfunc1() is not located in myCodeSeg. How to force libfunc1() into a code segment I want?

Labels (1)
0 Kudos
1 Solution
1,523 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

First I must declare one thing:  all the source codes and functions are automatically added to segment DEAFULT_ROM unless we use “#pragma CODE_SEG  MY_SECTION” to change it.

There is no doubt that your lib function has already integrated with your other source code, but all lib functions is still in the DEAFULT_ROM because you never put “#pragma CODE_SEG MY_SECTION ” on it.

To change the section of the lib function, i usually follow the steps as below:

  1. make sure where your lib function locates in. (consult .map file)
  2. ie. The lib function is string.c. Copy string.c and string.h from system directory and paste these files in your current project folder.
  3. Open IDE, add these two files in your project.
  4. add ” include “string.h”” to the associated files
  5. add “#pragma CODE_SEG  MY_SECTION” before the lib fuction in string.c
  6. Compile the project. Go to .map file and look the result.

I have tried to set up an example of this that I am sending as an attachment.

View solution in original post

0 Kudos
5 Replies
1,522 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

If you want to put lib functions into a specific segment, the possible solution is to add “#pragma CODE_SEG…” to lib source file. see attached lib sample.zip. please compile “mylib” first on your PC, then run “test” to see result.

it;s for 8bit device.

1,523 Views
leesp
Contributor I

Hi.

The lib which i want to include is ansiis.lib which comes with Codewarrior.

So that means i have to open up the source codes, add the #pragma, and recompile? What happens if the source codes also call some library?

Is there any other ways? Will #pragma REALLOC_OBJ work?

0 Kudos
1,523 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

we don't encourage user modify ansi lib file.

ansi lib by default is in  NON BANKED memory. why do you want to change it?

0 Kudos
1,523 Views
leesp
Contributor I

Long story.

I have a huge project (Project A) which has lots of source codes. #pragma CODE_SEG was not used in this project Therefore the linker allocates all the program binaries in DEFAULT_ROM

I want to incorporate the source code of another project (Project B) into Project A. The requirement is that all the program binaries of Project B should be allocated in an exclusive protected memory area, separated from DEFAULT_ROM. Therefore in Project B source code, I used #pragma CODE_SEG MyProtectSeg so as to put Project B program in MyProtectSeg, away from

DEFAULT_ROM. Also, some of the source codes in Project B use functions in ansiis.lib. So:

//ProjectB_source1.c ... #pragma CODE_SEG MyProtectSeg ...//code abc();//abc() uses functions in ansiis.lib ...

Now the problem comes. Functions in ansiis.lib are not affected by the #pragma (at least I don't know how to control the

allocation), and therefore these binaries are allocated in DEFAULT_ROM, which violates the requirement

How to solve this?

0 Kudos
1,524 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

First I must declare one thing:  all the source codes and functions are automatically added to segment DEAFULT_ROM unless we use “#pragma CODE_SEG  MY_SECTION” to change it.

There is no doubt that your lib function has already integrated with your other source code, but all lib functions is still in the DEAFULT_ROM because you never put “#pragma CODE_SEG MY_SECTION ” on it.

To change the section of the lib function, i usually follow the steps as below:

  1. make sure where your lib function locates in. (consult .map file)
  2. ie. The lib function is string.c. Copy string.c and string.h from system directory and paste these files in your current project folder.
  3. Open IDE, add these two files in your project.
  4. add ” include “string.h”” to the associated files
  5. add “#pragma CODE_SEG  MY_SECTION” before the lib fuction in string.c
  6. Compile the project. Go to .map file and look the result.

I have tried to set up an example of this that I am sending as an attachment.

0 Kudos