Atmel CAVR-4 Manuale Utente
CAVR-4
Part 1. Using the compiler
The DLIB runtime environment
65
SYSTEM STARTUP
When an application is initialized, a number of steps are performed:
●
When the cpu is reset it will jump to the program entry label
_ _program_start
in
the system startup code.
●
Enables the external data and address buses if needed
●
Initializes the stack pointers to the end of
CSTACK
and
RSTACK
, respectively
●
The function
_ _low_level_init
is called, giving the application a chance to
perform early initializations
●
Static variables are initialized except for
_ _no_init
and
_ _eeprom
declared
variables; this includes clearing zero-initialized memory and copying the ROM
image of the RAM memory of the rest of the initialized variables depending on the
return value of
image of the RAM memory of the rest of the initialized variables depending on the
return value of
_ _low_level_init
●
Static C++ objects are constructed
●
The
main
function is called, which starts the application.
SYSTEM TERMINATION
An application can terminate normally in two different ways:
●
Return from the
main
function
●
Call the
exit
function.
As the ISO/ANSI C standard states that the two methods should be equivalent, the
system startup code calls the
system startup code calls the
exit
function if
main
returns. The parameter passed to the
exit
function is the return value of
main
.
The default
exit
function is written in C. It calls a small function
_exit
, also written
in C, that will perform the following operations:
●
Call functions registered to be executed when the application ends. This includes
C++ destructors for static and global variables, and functions registered with the
standard C function
C++ destructors for static and global variables, and functions registered with the
standard C function
atexit
●
Close all open files
●
Call
_ _exit
●
When
_ _exit
is reached, stop the system.
An application can also exit by calling the
abort
or the
_Exit
function. The
abort
function just calls
_ _exit
to halt the system, and does not perform any type of cleanup.
The
_Exit
function is equivalent to the
abort
function, except for the fact that
_Exit
takes an argument for passing exit status information.
If you want your application to perform anything extra at exit, for example resetting the
system, you can write your own implementation of the
system, you can write your own implementation of the
_ _exit(int)
function.