ADVANCED INDUSTRIAL LEVEL TRAINING IN LINUX BASED EMBEDDED SYSTEMS

ADVANCED INDUSTRIAL LEVEL TRAINING IN LINUX BASED EMBEDDED SYSTEMS
ADMISSIONS OPEN

Search This Blog

Thursday 4 July 2013

HOW DOES AN EMBEDDED PROGRAM RUN ??


Before talking much more about embedded programming, this is a good place to give a brief overview of how an embedded program starts up and runs.  Assuming that you have generated a program file and have loaded it into the μC program memory (all steps that we will talk about later), the good stuff happens when you either turn on the device or you push the RESET button.  When the μC comes out of reset it will always go to a particular memory location, as defined by the manufacturer, to begin executing whatever code is found there.  Sometimes this memory location is defined directly, e.g. “upon coming out of reset, program execution begins at program address 0”.  Other times the fixed memory location is a vector, a location that holds the actual address of the beginning of the program, e.g. “upon coming out of reset, the controller will load its program counter with the value found at program address 0xFFFE”.  In the first instance you will have to make sure that your program has loaded at the specified startup address, while in the second instance you will load your program wherever the program memory has been placed in the controller address space, and you will have to make sure that you then load that startup address into the reset address vector.
When an embedded program starts to run, there is usually a fair amount of initialization and housekeeping that must be done before the “meat” of the program begins.  Most of this initialization is something that the average desktop programmer never sees, since it is handled by the computer boot code and operating system.  But in an embedded system, it is just as likely as not that there is no operating system, and all boot code and other startup code must be explicitly provided.  Some very critical hardware may need to be initialized first e.g. hardware that controls memory access times and address maps, as well as system clock hardware.  Then some software initialization may need to happen, such as setting up a stack pointer and perhaps copying data from nonvolatile memory to volatile memory where it can be accessed and perhaps modified.  After that will usually come another round of hardware initialization, setting up any peripheral devices that the system requires, and setting initial output states.  Finally, yet another round of software initialization may occur.
This initialization is usually broken up into two sections, with the first hardware and software initialization steps often being done in what is known as the startup code, and the later hardware and software steps being done in the user program.  This delineation is more distinct in a C program, where the startup code is invisible to the C program, being the code that happens before main() is run, and ending in a jump or call to main() where the “visible” C program begins.  In an assembler program all the initialization steps may be equally visible in the user code, although even then the first steps may reside in a separate startup source file.

No comments:

Post a Comment