Initializing Global Variables

<< Click to Display Table of Contents >>

Navigation:  ETEC 'C' Compiler Information >

Initializing Global Variables

Previous pageReturn to chapter overviewNext page

Example Download

Say you want to initialize global variables, as such.

// test global variables w/ initializers

int g_a=0x123456, g_b=0xabcdef;

char g_c1 = 0x70;

char g_c2 = 0x71;

char g_c3 = 0x72;

int g_c;

int g_d;

int g_e = 0xcafe;

unsigned int g_fract_test1 = 0x800000;

unsigned int g_fract_test2 = 0xC00000;

unsigned int g_fract_test3 = 0x100000;

 

int MyAshInitFunc(int24 A, int24 B, int24 C)

{

// <Code Here>

}

The compiler writes the information found below to the auto-generated header file named, MyCode_idata.h. Note that this auto-generated header file name is the base name of the .ELF file, appended with '_idata.h'.

#ifndef __GLOBAL_MEM_INIT32

#define __GLOBAL_MEM_INIT32( addr , val ) 

#endif // macro name ( address_or_offset , data_value ) 

 

__GLOBAL_MEM_INIT32( 0x0000 , 0x70123456 ) 

__GLOBAL_MEM_INIT32( 0x0004 , 0x71abcdef ) 

__GLOBAL_MEM_INIT32( 0x0008 , 0x72000000 ) 

__GLOBAL_MEM_INIT32( 0x000c , 0x00000000 ) 

__GLOBAL_MEM_INIT32( 0x0010 , 0x0000cafe ) 

__GLOBAL_MEM_INIT32( 0x0014 , 0x00800000 ) 

__GLOBAL_MEM_INIT32( 0x0018 , 0x00c00000 ) 

__GLOBAL_MEM_INIT32( 0x001c , 0x00100000 ) 

__GLOBAL_MEM_INIT32( 0x0020 , 0x00000000 ) 

__GLOBAL_MEM_INIT32( 0x0024 , 0x00000000 )

At the top of your ASH WARE eTPU Simulator Script Command file, place the following. This performs the global initialization in the simulator, though a similar approach will work in your actual host-side code.

// #define for global initializers

#define __GLOBAL_MEM_INIT32(address, value) *((ETPU_DATA_SPACE U32 *) address) = value;

 

// #define for function variable initializers

// Note that there is a memory write for each channel 

// that uses function 'MyETpuFunc' (2 in this case).

#define __MyETpuFunc_CHAN_FRAME_INIT32(offset, value) \

*((ETPU_DATA_SPACE U32 *) ASH_INIT_CHAN1_BASE_ADDR+offset) = value; \

*((ETPU_DATA_SPACE U32 *) ASH_INIT_CHAN2_BASE_ADDR+offset) = value;

 

// Include the automatically generated file

// that uses the above macros to initialize the memory

#include "MyCode_idata.h"

With the ETEC compiler, users have an additional (and easier) option with regards to initialized data.  The ETEC compiler/linker automatically outputs initialized data in the form of macros into <exec base name>_idata.h.  This includes initialized data for both globals and all channel frames, for example: