Board Initialization Code

For each supported board, CodeWarrior for Power Architecture Processors includes a hardware initialization routine. Each routine is in a source code file whose name reflects the board for which the routine is designed. These files are in this directory:

  installDir 
  \PowerPC_EABI_Support\Runtime\Src
   

The initialization routines are in source code form, so you can modify them to work with different configurations of a board or with a different board.

If you run your program under control of the CodeWarrior debugger, the program must not perform hardware initialization because the debugger performs the required board initialization.

However, if your program is running standalone (that is, without the debugger), the program may need to execute hardware initialization code. The easiest way to include this code in your program is to add the appropriate board initialization file to your project.

Each board initialization file includes a function named usr_init() . This function performs the required hardware initialization for your board. usr_init() is conditionally called by the __init_hardware() function in ppc_eabi_init.c (or in ppc_eabi_init.cpp , if you are using C++) . The startup code always calls __init_hardware() .

The default implementation of the __init_hardware() function calls usr_init() if either the ROM_VERSION or CACHE_VERSION preprocessor constant is defined. (See Code Showing call of usr_init() in __init_hardware().) However, you can change the implementation of __init_hardware() to suit your project's requirements.

Listing 1. Code Showing call of usr_init() in __init_hardware()
asm void __init_hardware(void)
{

   /*

   *   If not running with the CodeWarrior debugger, initialize the

   *   board. Define the preprocessor symbols for the initialization 

   *   your program requires. You may need to perform other 

   *   initializations.

   */

   nofralloc



/* ... code omitted */
 


#if defined(ROM_VERSION) || defined(CACHE_VERSION)

   mflr   r31        /* save off return address in NV reg */


   bl     usr_init   /* init board hardware */
 


   mtlr   r31        /* get saved return address */

#endif



   blr

}

To get you program to perform hardware initialization when run outside the CodeWarrior debugger, follow these steps:

  1. Add the appropriate board initialization file to your project.
  2. Change the preprocessor symbol that conditionalizes the usr_init() call in __init_hardware() to a symbol that makes sense for your project.
  3. Define this symbol in the prefix file for each build target for which you want to run the hardware initialization code.
Related information
Main Standard Libraries
Third Party Standard Libraries
Embedded Warrior Library
Runtime Libraries