use init table directive
Syntax
use init tablenamefor {section-selectors} [ except {section-selectors} ];
For information about section selectors and except clauses, see Section selection.
Parameters
| The name of the |
Description
Normally, all initialization entries are generated into a single initialization table (called Table). Use this directive to cause some of the entries to be put into a separate table. You can then use this initialization table at another time, or under different circumstances, than the normal initialization table.
Initialization entries for all variables not mentioned in a use init table directive are put into the normal initialization table. By having multiple use init table directives you can have multiple initialization tables.
The start, end, and size of the init table can be accessed in the application program by using __section_begin, __section_end, or __section_size of "Region$$name", respectively, or via the symbols Region$$name$$Base, Region$$name$$Limit, and Region$$name$$Length.
An initialization function, IAR_TABLE_INIT, which operates on the start and end addresses of an initialization table, is available in the include file stdlib.h. Calling the function with start and end addresses of an initialization table created with use init table will initialize all initialization entries in that table.
Note
Stack usage analysis handles all initialization entries as if they were called by the normal initialization routine (IAR_DATA_INIT). This will result in stack usage information for initialization entries that are called from another place, such as IAR_TABLE_INIT, being incorrect. If such a function is called when almost all stack has been used, it is possible that too much stack will be used without the stack usage analysis detecting this. Initialization functions and routines for dynamic initialization typically use little stack space, so this would most likely not be a serious problem.
Example
In this example, the use init table directive resides in the linker configuration file, while the rest of the example resides in a C file.
use init table Core2 for { section *.core2};
/* This code example needs IAR language extensions to handle
__section_begin. */
#include <stdlib.h>
/* This sets up the name of the table and ensures that pointers
to it have the correct attributes. */
#pragma section="Region$$Core2" const _DLIB_ELF_INIT_TABLE_MEMORY
/* Calling this function will result in all initialization
functions in the Core2 table being called. This must be called
before any of the data/objects are accessed. Nothing prevents
the data/objects from being accessed before they are
initialized and nothing prevents the data from being
initialized more than once (data is typically overwritten by
the initial values if it is initialized more than once). */
void HandleCore2Init()
{
IAR_TABLE_INIT(__section_begin("Region$$Core2"),
__section_end ("Region$$Core2"));
}