[En-Nut-Discussion] Nut/OS Initialization

Harald Kipp harald.kipp at egnite.de
Wed Sep 17 18:57:20 CEST 2008


Thiago A. Corrêa wrote:

> Since we already redefine main to NutMain or something like that to
> run code before main, I don't see this being in violation with C
> (unless the linker thing is).

The redefinion of main to NutMain is awful, but forced by the people 
from AVRGCC. They insisted on making main() a special function, which 
reloads the stack pointer, just to save a few bytes for very low end 
AVRs. We had no choice here and it's only done for AVRGCC.

But you may refer to NutInit, which is indeed similar to the suggested 
HardwareInit. Again, we have no choice here too, because it is essential 
for a multitasker to have an initial root task running, which takes over 
when main() gives up the CPU.

We should consider, that for HardwareInit (or whatever it may be called) 
we _do_ have a choice. Thus, I'd agree with Alain, that it is generally 
better to stick with the standard unless we are forced to do otherwise.

IMHO, the discussion may find a solution by distinguishing between 
necessary hardware initialization and the optional initialization 
required by the specific application. Right now NutInit is contaminated 
with specific hardware initializations hacked in, just to get something 
running (I feel guilty). These things can be moved to board specific 
modules.

For the application code, I'd prefer to start at main. Otherwise 
application developers may overuse the pre-initialization and end up 
with completely incompatible code, which is hardly understood by others.

Harald





More information about the En-Nut-Discussion mailing list