Ejemplo n.º 1
0
/*
 * \brief 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:
 * \code -ucrtnut.o nutinit.o \endcode
 * 
 * For AVRGCC this function is located in section .init8, which is
 * called immediately before jumping to main(). NutInit is defined
 * as:
 * \code
 * void NutInit(void) __attribute__ ((naked)) __attribute__ ((section (".init8")));
 * \endcode
 */
void NutInit(void)
{
    /*
     * We can't use local variables in naked functions.
     */
#ifdef NUTDEBUG
    outp(7, UBRR);
    outp(BV(RXEN) | BV(TXEN), UCR);
#endif

#ifndef __GNUC__
// FIXME: move this line to an appropriate initialization section of ICCAVR (os)
    outp(BV(SRE) | BV(SRW), MCUCR);
#endif

    /* First check, whether external RAM is available
     */
    *(NUTRAMEND - 1) = 0x55;
    *NUTRAMEND = 0xAA;
    if (*(NUTRAMEND - 1) == 0x55 && *NUTRAMEND == 0xAA) {
        /* If we have external RAM, initialize stack pointer to
         *  end of external RAM to avoid overwriting .data and .bss section
         */
        SP = (u_short) NUTRAMEND;

        /* Then add the remaining RAM to heap
         */
        if ((u_short) NUTRAMEND - (u_short) (&__heap_start) > 384)
            NutHeapAdd(&__heap_start, (u_short) NUTRAMEND - 256 - (u_short) (&__heap_start));
    } else {
        /* No external RAM, so disable external memory interface to use the port pins
           for normal operation
         */
        MCUCR = 0x00;

        /* Add the remaining internal RAM to heap
         */
        if ((u_short) RAMEND - (u_short) (&__heap_start) > 384)
            NutHeapAdd(&__heap_start, (u_short) RAMEND - 256 - (u_short) (&__heap_start));
    };
    /*
     * Read eeprom configuration.
     */
    if (NutLoadConfig()) {
        strcpy(confos.hostname, "ethernut");
        NutSaveConfig();
    }

    /* Create idle thread
     */
    NutThreadCreate("idle", NutIdle, 0, 384);
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
    tcgetattr(fileno(stdout), &emulation_options.saved_termios);

    /* get command line options */
    emulation_options_parse(argc, argv);

    /*
     * Register our Pseudo RAM
     */
    NutHeapAdd(PSEUDO_RAM, PSEUDO_RAM_SIZE);

    /* Read OS configuration from non-volatile memory. */
    NutLoadConfig();

    /*
     * set stdio
     */

    /*
       NutRegisterDevice(&devUart0, 0, 0);
       NUT_freopen("uart0", "w", __iob[1]);
       printf("OS Debug Mode, stdout opened in unix_nutinit.c\n");
       // NutTraceOs( stdout, 1);
     */

    /*
     * Init interrupt handling
     */
    NutIRQInit();

    /*
     * Init threading
     */
    NutThreadInit();

    /*
     * Create idle thread
     */
    NutThreadCreate("idle", NutIdle, 0, NUT_THREAD_IDLESTACK);

    return 0;
}
Ejemplo n.º 3
0
void Sound_init(UI * ui, bool recording)
{

	// init devices
	NutLoadConfig();

	if (ConfigInit()) {
		/* No configuration memory, run with factory defaults. */
		ConfigResetFactory();
	}
	else {
		if (ConfigLoad()) {
			/* No configuration info, use factory defaults. */
			ConfigResetFactory();
			ConfigSave();
		}
	}

	ResetDevice();

	int i;

	SoundStruct *ss = malloc( sizeof(SoundStruct) );
	ss->buffer = malloc( WIN_SIZE * CEPS_COUNT * sizeof(short) );
	ss->ui = ui;
	ss->recording = recording;
	ss->ceps_count = 0;

	ss->dtwTable = malloc( (CEPS_COUNT+1)*sizeof(short*) );
	for( i = 0; i< CEPS_COUNT+1; i++)
		ss->dtwTable[i] = malloc((CEPS_COUNT+1) * sizeof(short));

	printf("Create Thread\n");
	fflush(stdout);

	NutThreadCreate("SoundRecord", SoundRecord, (void *)(ss), 2048);
	NutThreadCreate("SoundFFT", SoundFFT, (void *)(ss), 1024);
}