Example of Initializing Global Variables

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)
{

Tell the compiler to put this in a header file, etpu_AshInit_auto.h, by putting the following text at the end of the .C file.

#pragma write h,(::ETPUfilename(etpu_AshInit_auto.h));

Tell the compiler to put global variable initialization in the etpu_AshInit_auto.h, header file that it generates.

#pragma write h, (::ETPUglobalinit32);

The compiler writes the information found below to header file, etpu_AshInit_auto.h .

__etpu_globalinit32(0x0000,0x70123456)
__etpu_globalinit32(0x0004,0x71ABCDEF)
__etpu_globalinit32(0x0008,0x72000000)
__etpu_globalinit32(0x0010,0x0000CAFE)
__etpu_globalinit32(0x0014,0x00800000)
__etpu_globalinit32(0x0018,0x00C00000)
__etpu_globalinit32(0x001C,0x00100000)

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 __etpu_globalinit32(address, value) *((ETPU_DATA_SPACE U32 *) address) = value;

#include "etpu_AshInit_auto.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:

// Global Memory Initialization Data Macros
#ifndef __GLOBAL_MEM_INIT32
#define __GLOBAL_MEM_INIT32( addr , val )
#endif
// macro name ( address_or_offset , data_value )
__GLOBAL_MEM_INIT32( 0x0000 , 0x00000777 )
__GLOBAL_MEM_INIT32( 0x0004 , 0x55ffffff )
__GLOBAL_MEM_INIT32( 0x0008 , 0x00000000 )
__GLOBAL_MEM_INIT32( 0x000c , 0x00000000 )

// Test Channel Frame Initialization Data Macros
#ifndef __Test_CHAN_FRAME_INIT32
#define __Test_CHAN_FRAME_INIT32( addr , val )
#endif // macro name ( address_or_offset , data_value )
__Test_CHAN_FRAME_INIT32( 0x0000 , 0x00000000 )
__Test_CHAN_FRAME_INIT32( 0x0004 , 0x00000000 )

Click here to download the example