Initialization
[AVR]

Starting Nut/OS. More...

Collaboration diagram for Initialization:

Defines

#define NUTMEM_END   (uint16_t)(NUTMEM_START + (uint16_t)NUTMEM_SIZE - 1U)
 Last memory address without using external SRAM.
#define NUT_THREAD_MAINSTACK   1024
#define NUT_THREAD_IDLESTACK   128
#define AVR_SLEEP_CTRL_REG   MCUCR

Functions

void NutInit (void)
 Nut/OS Initialization.
void NutAppMain (void *arg)
uint8_t NutThreadSetSleepMode (uint8_t mode)
 Sets the sleep mode to enter in Idle thread.
void NutIdle (void *arg)
 AVR Idle thread.

Variables

uint8_t idle_sleep_mode = SLEEP_MODE_NONE

Detailed Description

Starting Nut/OS.

Define Documentation

#define NUTMEM_END   (uint16_t)(NUTMEM_START + (uint16_t)NUTMEM_SIZE - 1U)

Last memory address without using external SRAM.

Todo:
Shall we support NUTRAMEND for backward compatibility? If, then let's do it in cfg/memory.h.

Definition at line 168 of file nutinit.c.

Referenced by NutInit().

#define NUT_THREAD_MAINSTACK   1024

Definition at line 173 of file nutinit.c.

Referenced by NutIdle().

#define NUT_THREAD_IDLESTACK   128

Definition at line 179 of file nutinit.c.

Referenced by main(), and NutInit().

#define AVR_SLEEP_CTRL_REG   MCUCR

Definition at line 208 of file nutinit.c.


Function Documentation

void NutInit ( void   ) 

Nut/OS Initialization.

Initializes the memory management and the thread system and starts an idle thread, which in turn initializes the timer management. Finally the application's main() function is called.

Depending on the compiler, different methods are used to execute this function before main() is called.

For ICCAVR the default crtatmega.o startup file is replaced by crtnut.o, which calls NutInit instead of main(). This is done by adding the following compiler options in the project:

 -ucrtnut.o nutinit.o 

crtnut.o should be replaced by crtnutram.o, if the application's variable space exceeds 4kB. For boards with RTL8019AS and EEPROM emulation (like Ethernut 1.3 Rev-G) use crtenut.o or crtenutram.o.

For AVRGCC this function is located in section .init8, which is called immediately before jumping to main(). NutInit is defined as:

 void NutInit(void) __attribute__ ((naked)) __attribute__ ((section (".init8")));

Todo:
Make heap threshold configurable, currently hardcoded at 384.
Todo:
Make wait states for external memory access configuratble.
Todo:
Make early UART initialization for kernel debugging configurable.

Initializes the memory management and the thread system and starts an idle thread, which in turn initializes the timer management. Finally the application's main() function is called.

Definition at line 701 of file nutinit.c.

References _O_CREAT, _O_TRUNC, _O_WRONLY, BV, HEAP_SIZE, HEAP_START, MC_FMR, MC_FWS_2R3W, McuInit(), NUT_THREAD_IDLESTACK, NUT_THREAD_STACK_ADD, NUT_THREAD_STACK_MULT, NutGetCpuClock(), NutHeapAdd, NutIdle(), NutLoadConfig(), NUTMEM_END, NutThreadCreate(), outp, outr, puts, RXEN, stdout, TXEN, and UCR.

void NutAppMain ( void *  arg  ) 

Referenced by NutIdle().

uint8_t NutThreadSetSleepMode ( uint8_t  mode  ) 

Sets the sleep mode to enter in Idle thread.

If the idle thread is running, no other thread is active so we can safely put the mcu to sleep.

Parameters:
mode one of the sleep modes defined in avr/sleep.h or sleep_mode_none (don't enter sleep mode)
Returns:
previous sleep mode

Definition at line 458 of file nutinit.c.

References idle_sleep_mode.

void NutIdle ( void *  arg  ) 


Variable Documentation

uint8_t idle_sleep_mode = SLEEP_MODE_NONE

Definition at line 202 of file nutinit.c.

Referenced by NutIdle(), and NutThreadSetSleepMode().


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/