Hi. I am using uVersion2 IDE. Here after reset, MPU will execute code from reset vector located in Startup.A51 file and after some initialization, it will jump to label named as ?C_START which is defined in Init.A51, where it does some other initialization. If we dont include the Init.A51 in project, then will it automatically include for project ? If we dont want to use this Init.A51 file and instead of jumping to ?C_START from Startup.A51, we modify this to jump to Main direclt then will it create any proble ? Thanks.
"If we dont include the Init.A51 in project, then will it automatically include for project ?" Yes. "If we dont want to use this Init.A51 file and instead of jumping to ?C_START from Startup.A51, we modify this to jump to Main direclt then will it create any proble ?" I'm not certain, but I suspect it should be ok provided, of course, you don't have any explicitly initialised static data.
I build my project without INIT.A51. It works fine. Be sure all the project programmers -- including the future ones that might replace you -- know that due to the lack of INIT.A51, source code cannot use static C initializers. It would be even better if you could force lint (or the compiler) to produce an error on encountering initializers. (The compiler will compile such, but the code won't run correctly if it expects the variable to initialized. That's what INIT.A51 does, after all.)
Hi stefan and davis. Thank you very much for providing the information. Here, if we dont have any static variable then there will not be nay problem. But if we dont have then we have to initialize it ? is it ? What about global variables initialization which are not static ?
Again: Here, if we dont have any static variable then there will not be any problem. But if we have then we have to initialize it if we dont want to use INIT.A51. is it ? What about global variables initialization which are not static ?
The C standard specifies that any global variable which does not have an initializer is initialized to zero. There are several loops, one for each memory space (idata, pdata, xdata, etc), in the STARTUP.A51 file that zero out all of the memory. This code implements the requirement of the C spec that uninitialized variables are zero. The compiler takes all of the explicit static initializers and puts them into the code (ROM) area. INIT.A51 copies this region of initialized data to RAM. INIT.A51 implements the C standard feature for initializing global variables. If you omit INIT.A51 from your build, then any program which relies on static initializers will not work correctly. You will have to write code that explicitly initiazes variables the way you want them. For example, this code will fail miserably if you omit INIT.A51
U8 lookup[8] = { 7, 6, 5, 4, 3, 2, 1, 0 }; void main (void) { ... translated = lookup[input]; ... }
U8 lookup[8]; ... void LookupInit (void) { U8 data i; for (i = 0; i < 8; ++i) { lookup[i] = 7 - i; } } // LookupInit ... void main (void) { LookupInit(); translated = lookup[input]; // works only after call to LookupInit(); }
"What about global variables initialization which are not static ?" Yes, they need the INIT.A51 code.