Do not init global variable

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Do not init global variable

2,218件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rkiryanov on Mon Apr 26 11:34:35 MST 2010
Hello,

in IAR projects I use __no_init for some variables, this keyword tells compiler that initialization must be suppressed. How can I do this in LPCXpresso?

Thanks.
0 件の賞賛
返信
6 返答(返信)

2,072件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Apr 27 06:58:32 MST 2010
As suggested by brucesegal, you need to use the section attribute when declaring your variable(s). I suggest using a section name that suggests what it is being used for...

int noinit_var  __attribute__ ((section (".noinit")));
By default this will get placed between the .data and .bss sections. But because the code red startup code is unaware of its existence, it will not get initialised by software.

You will need to create your own linker script file to place it at the address of your actual battery backed RAM. Information on creating your own linker scripts can be found (login required) at:

http://lpcxpresso.code-red-tech.com/LPCXpresso/node/31

Regards,
CodeRedSupport.
0 件の賞賛
返信

2,072件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rkiryanov on Mon Apr 26 23:24:37 MST 2010

Quote: CodeRedSupport
Surely non-volatile  memory is flash?



Battery powered SRAM too (see LPC23xx). For example, variable that should not be modified on reset.


Quote: CodeRedSupport
This is done in the startup code. Is there any particular reason why this is a problem?



Problems:
1. Order of initialization.

void ResetISR(void)
{
    hw::Init();
    OS::Init();
    .bss init  // will overwrite OS variables
    .data init // will overwrite OS variables
    call C++ objects ctors
    etc
}


2. Twice initialization.

void ResetISR(void)
{
    hw::Init();
    .bss init
    .data init
    OS::Init(); // overwrite some .bss, looks displeasingly
    call C++ objects ctors
    etc
}


3. Value of the initialization, this code cannot be replaced.

    for (size_t i = 0; i < max_threads_count; ++i)
    {
        os_free_threads = i;
    }
0 件の賞賛
返信

2,072件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Mon Apr 26 22:24:34 MST 2010
Now I am confused... Surely non-volatile memory is flash? Which isn't a good place to be putting variables.

Anyway, variables are either initialised with a value (.data), or initialised with zero (.bss). This is done in the startup code. Is there any particular reason why this is a problem? If it is, you can modify the startup code to either not perform the initialization, or you can add code to initialise them to the values you need.
0 件の賞賛
返信

2,072件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rkiryanov on Mon Apr 26 21:27:37 MST 2010

Quote: CodeRedSupport
What is it you are trying to achieve, and why?



I mark with __no_init my OS state variables, I init them before all other variables (zero init and value init). Also, IAR help:


Quote:
Description
Use the __no_init keyword to place a data object in non-volatile memory. This means that the initialization of the variable, for example at system startup, is suppressed.

0 件の賞賛
返信

2,072件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Mon Apr 26 13:15:30 MST 2010
Hi,

What is it you are trying to achieve, and why? I don't know what the IAR tools do, so you need to explain why you need this. We can then suggest a way you can achieve it.
0 件の賞賛
返信

2,072件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by brucesegal on Mon Apr 26 13:04:32 MST 2010
Can you use the gcc attribute to put the variable in a different section that  is not initialized?

Something like:

uint32_ttestForSection  __attribute__ ((section ("_edata")));


I believe this will link the testForSection global into the _edata section, which should be at the end of _data (initialized globals) and before _bss (zeroed globals)

I guess you could also create your own section and modify the .ld files that are used by the ide when compiling.

Not tested but the idea may fly.
0 件の賞賛
返信