DSPRelated.com
Forums

Creating inilialized section for variables in C

Started by Ashish Gupta June 23, 2009
hi,
We are facing problem in developing hex file for the C code written on C55x
processor in CCS. The variables such as arrays are defined globally and
initialised then and there itself. These variables need to be put in hex
file . When we generate the hex file using hex55 utility then these global
variables don;t go into initialised section. Kindly guide us on how to put
the initilased C variables into a initialised section .

The cmd file is enclosed:

MEMORY {
DATA(RWI): origin = 0x100, len = 0xfeff
VECT_RX: origin = 0x10000, len = 0x100
PROG: origin = 0x10100, len = 0x2000
CinitiliasedVariables(RWI): origin = 0x15200, len= 0x1000

}

SECTIONS
{
.vectors_rx: {} > VECT_RX
.cinit: {} > PROG
.text: {} > PROG
.bss: {} > DATA
.far: {} > DATA
.sysheap: {} > DATA
.sysstack {} > DATA
.stack: {} > DATA
.CInitVariables: {} > CinitiliasedVariables
}
The main problem is that even if we relocate the particular array of C
in a Data section using pragma directive, even then that section is
unintialised in the map file.
eg #pragma DATA_section(db,".CInitVariables");
short db[5]= {1,2,3,4,5};

Now in the map file, this section is shown as uninitialised and hence
this section is not converted into hex file. Give us the workaround so
that our global variables such as shown above which are preinitialised
in the code are also converted into hex file with the pre initialised
values.
In the assembly there is an option of .sect ".SECTION_NAME" then
whatever is defined in this section goes under initialised section.
I want the same functionality for the variables defined in C. Pl suggest.
Ashish
Hi
Hi

I do not understand "These variables need to be put in hex file".
What do You mean "variables"? Variables address or data what those variables had to be initialized ?

SPRU280H: "Initialized sections contain executable code or initialized data."

What You actually want to achieve?

Best Regards
/Greg

hi,
>We are facing problem in developing hex file for the C code written on C55x
>processor in CCS. The variables such as arrays are defined globally and
>initialised then and there itself. These variables need to be put in hex
>file . When we generate the hex file using hex55 utility then these global
>variables don;t go into initialised section. Kindly guide us on how to put
>the initilased C variables into a initialised section .
>
Ashish-
> We are facing problem in developing hex file for the C code written on C55x
> processor in CCS. The variables such as arrays are defined globally and initialised
> then and there itself. These variables need to be put in hex file . When we
> generate the hex file using hex55 utility then these global variables don;t go into
> initialised section. Kindly guide us on how to put the initilased C variables into
> a initialised section .

First, did you try using 'const' when declaring your C arrays? Use of const will
result in a ".const" section showing up in your .map file. I don't see that you're
expecting that in your .cmd file below.

Second, keep in mind the way C variable initialization works: vars are either
initialized by a) a small bit of 'before anything else runs' code, typically a
routine called autoinit() that does other basic stuff like set the stack pointer, or
b) the loader, whoever that might be. a) is called "run-time" autoinitialization in
CCS Linker options, and b) is called "load-time". In the former case, which I would
guess you should be using (unless you are booting via HPI and have a smart loader), C
variable content is actually stored in a section called ".cinit" in the .map file.
The overall result is that initialized C vars don't show up in DSP memory where
you're expecting them *until* code first runs, and before code reaches main().

-Jeff
> The cmd file is enclosed: MEMORY {
> DATA(RWI): origin = 0x100, len = 0xfeff
> VECT_RX: origin = 0x10000, len = 0x100
> PROG: origin = 0x10100, len = 0x2000
> CinitiliasedVariables(RWI): origin = 0x15200, len= 0x1000
> }
>
> SECTIONS
> {
> .vectors_rx: {} > VECT_RX
> .cinit: {} > PROG
> .text: {} > PROG
> .bss: {} > DATA
> .far: {} > DATA
> .sysheap: {} > DATA
> .sysstack {} > DATA
> .stack: {} > DATA
> .CInitVariables: {} > CinitiliasedVariables
> }
> The main problem is that even if we relocate the particular array of C
> in a Data section using pragma directive, even then that section is
> unintialised in the map file.eg #pragma DATA_section(db,".CInitVariables");
> short db[5]= {1,2,3,4,5};
>
> Now in the map file, this section is shown as uninitialised and hence
> this section is not converted into hex file. Give us the workaround so
> that our global variables such as shown above which are preinitialised
> in the code are also converted into hex file with the pre initialised
> values.
> In the assembly there is an option of .sect ".SECTION_NAME" then
> whatever is defined in this section goes under initialised section.
> I want the same functionality for the variables defined in C. Pl suggest.
> Ashish
Ashish-

> Using const will change the way I initialise the array. eg. I want to
> initialise the array normally such as short FIRCoeff[5] = {1,2,3,4,5}; and
> there are lot of initialised arrays in the program. I have tried
> initiliasing the array in assembly by creating section and then initialising
> each value one by one. That section becomes a initialised section in map
> file and hence can be converted to hex file.
> I want to know that can we do the same thing for C variables.

Why can't you write:

const short FIRCoeff[5] = {1, 2, 3, 4, 5};

? What problem does this cause?

-Jeff

PS. Please post to the group, not to me.

> On 6/24/09, Jeff Brower wrote:
>>
>> Ashish-
>> We are facing problem in developing hex file for the C code written on C55x
>> processor in CCS. The variables such as arrays are defined globally and
>> initialised then and there itself. These variables need to be put in hex
>> file . When we generate the hex file using hex55 utility then these global
>> variables don;t go into initialised section. Kindly guide us on how to put
>> the initilased C variables into a initialised section .
>> First, did you try using 'const' when declaring your C arrays? Use of
>> const will result in a ".const" section showing up in your .map file. I
>> don't see that you're expecting that in your .cmd file below.
>>
>> Second, keep in mind the way C variable initialization works: vars are
>> either initialized by a) a small bit of 'before anything else runs' code,
>> typically a routine called autoinit() that does other basic stuff like set
>> the stack pointer, or b) the loader, whoever that might be. a) is called
>> "run-time" autoinitialization in CCS Linker options, and b) is called
>> "load-time". In the former case, which I would guess you should be using
>> (unless you are booting via HPI and have a smart loader), C variable content
>> is actually stored in a section called ".cinit" in the .map file. The
>> overall result is that initialized C vars don't show up in DSP memory where
>> you're expecting them *until* code first runs, and before code reaches
>> main().
>>
>> -Jeff
>> The cmd file is enclosed: MEMORY {
>> DATA(RWI): origin = 0x100, len = 0xfeff
>> VECT_RX: origin = 0x10000, len = 0x100
>> PROG: origin = 0x10100, len = 0x2000
>> CinitiliasedVariables(RWI): origin = 0x15200, len= 0x1000
>> }
>>
>> SECTIONS
>> {
>> .vectors_rx: {} > VECT_RX
>> .cinit: {} > PROG
>> .text: {} > PROG
>> .bss: {} > DATA
>> .far: {} > DATA
>> .sysheap: {} > DATA
>> .sysstack {} > DATA
>> .stack: {} > DATA
>> .CInitVariables: {} > CinitiliasedVariables
>> }
>> The main problem is that even if we relocate the particular array of C
>> in a Data section using pragma directive, even then that section is
>> unintialised in the map file.eg #pragma
>> DATA_section(db,".CInitVariables");
>> short db[5]= {1,2,3,4,5};
>>
>> Now in the map file, this section is shown as uninitialised and hence
>> this section is not converted into hex file. Give us the workaround so
>> that our global variables such as shown above which are preinitialised
>> in the code are also converted into hex file with the pre initialised
>> values.
>> In the assembly there is an option of .sect ".SECTION_NAME" then
>> whatever is defined in this section goes under initialised section.
>> I want the same functionality for the variables defined in C. Pl suggest.
>> Ashish
>>
>
Hi Greg,
Thanks for the reply. I need to put the initialised array such as FIR filter
coefficients eg short FIRCoeff[5]= { 2,3,42,3,4}; in the hex file. This
array is defined globally . Suggest how to transfer the initialised values
of array in hex file.

Regards,

Ashish

On 6/24/09, g...@woodanddouglas.co.uk
wrote:
>
> Hi
> Hi
>
> I do not understand "These variables need to be put in hex file".
> What do You mean "variables"? Variables address or data what those
> variables had to be initialized ?
>
> SPRU280H: "Initialized sections contain executable code or initialized
> data."
>
> What You actually want to achieve?
>
> Best Regards
> /Greg
>
> hi,
> >We are facing problem in developing hex file for the C code written on
> C55x
> >processor in CCS. The variables such as arrays are defined globally and
> >initialised then and there itself. These variables need to be put in hex
> >file . When we generate the hex file using hex55 utility then these global
> >variables don;t go into initialised section. Kindly guide us on how to put
> >the initilased C variables into a initialised section .
> >
Hi

You do not have to worry about coefficients in FIRCoeff[].
Run time initialization will copy it for you to the correct place in memory before control get main(), so do not worry.
If you do not believe that this coefficients are in hex file do this:

Create hex file with.
FIRCoeff[5]= { 2,3,42,3,4};
then change some coefficient, for example:
FIRCoeff[5]= { 1,2,3,4,5}; create hex file
and compare by one of diff utils program (KDiff3).
Regards
/Greg