nutinit.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00034 /*
00035  * $Log: nutinit.c,v $
00036  * Revision 1.14  2007/10/04 20:08:00  olereinhardt
00037  * Support for SAM7S256 added
00038  *
00039  * Revision 1.13  2006/09/29 12:39:51  haraldkipp
00040  * Spurious interrupt handling on all supported AT91 devices.
00041  *
00042  * Revision 1.12  2006/07/26 11:17:16  haraldkipp
00043  * Defining AT91_PLL_MAINCK will automatically determine SAM7X clock by
00044  * reading PLL settings.
00045  *
00046  * Revision 1.11  2006/07/18 14:04:10  haraldkipp
00047  * Low level hardware initialization moved to crtat91sam7x256_rom.S. This
00048  * avoids the ugly jump from C code back into the runtime initialization.
00049  * Watchdog reset (tiger bell) removed from idle thread.
00050  *
00051  * Revision 1.10  2006/07/15 11:13:30  haraldkipp
00052  * CPU ran into the data pool of Sam7xLowLevelInit(). Temporarily
00053  * fixed by Andras Albert with an additional global label in the
00054  * startup code. Furthermore Andras changed the clock initialization.
00055  * The CPU is now running at 47.9232 MHz and the MAC starts working.
00056  * Great, TCP/IP is now running on the SAM7X.
00057  *
00058  * Revision 1.9  2006/07/10 14:27:03  haraldkipp
00059  * C++ will use main instead of NutAppMain. Contributed by Matthias Wilde.
00060  *
00061  * Revision 1.8  2006/07/05 07:57:52  haraldkipp
00062  * Daidai's support for AT91SAM7X added. Possibly taken from Atmel.
00063  * May require new coding from ground up in order to not conflict with
00064  * original copyright.
00065  * Nevertheless, many thanks to Daidai for providing his adaption.
00066  *
00067  * Revision 1.7  2006/06/28 17:22:34  haraldkipp
00068  * Make it compile for AT91SAM7X256.
00069  *
00070  * Revision 1.6  2006/03/02 19:43:11  haraldkipp
00071  * Added MCU specific hardware initialization routine. This should be done
00072  * later for all MCUs to avoid contaminating NutInit() with MCU specific
00073  * stuff. For the AT91 the spurious interrupt handler has been added,
00074  * which fixes SF 1440948.
00075  *
00076  * Revision 1.5  2006/02/23 15:34:00  haraldkipp
00077  * Support for Philips LPC2xxx Family and LPC-E2294 Board from Olimex added.
00078  * Many thanks to Michael Fischer for this port.
00079  *
00080  * Revision 1.4  2005/10/24 09:22:29  haraldkipp
00081  * Default idle and main thread stack sizes increased.
00082  * AT91 header file moved.
00083  *
00084  * Revision 1.3  2005/08/02 17:46:45  haraldkipp
00085  * Major API documentation update.
00086  *
00087  * Revision 1.2  2005/07/26 16:17:03  haraldkipp
00088  * Use default stack sizes for main and idle, if none had been defined.
00089  *
00090  * Revision 1.1  2005/05/27 17:16:40  drsung
00091  * Moved the file.
00092  *
00093  * Revision 1.4  2005/04/05 17:52:41  haraldkipp
00094  * Much better implementation of GBA interrupt registration.
00095  *
00096  * Revision 1.3  2004/11/08 18:58:59  haraldkipp
00097  * Configurable stack sizes
00098  *
00099  * Revision 1.2  2004/09/08 10:19:23  haraldkipp
00100  * Made it look more general
00101  *
00102  * Revision 1.1  2004/03/16 16:48:46  haraldkipp
00103  * Added Jan Dubiec's H8/300 port.
00104  *
00105  *
00106  */
00107 
00108 #include <cfg/arch.h>
00109 #include <cfg/memory.h>
00110 #include <cfg/os.h>
00111 #ifdef MCU_GBA
00112 #include <dev/irqreg.h>
00113 #elif defined(MCU_LPC2XXX)
00114 #include <arch/arm/lpc2xxx.h>
00115 #else
00116 #include <arch/arm/at91.h>
00117 #endif
00118 
00123 
00124 #ifndef NUT_THREAD_MAINSTACK
00125 #define NUT_THREAD_MAINSTACK    1024
00126 #endif
00127 
00128 #ifndef NUT_THREAD_IDLESTACK
00129 #define NUT_THREAD_IDLESTACK    512
00130 #endif
00131 
00132 #ifdef __CROSSWORKS4ARM__
00133 extern void *__unused_start__;
00134 /*
00135  * Michael, Why does Crossworks needs this one. Is memory configurable
00136  * with the Configurator?
00137  */
00138 extern void *__External_SRAM_segment_end__;
00139 
00140 #define HEAP_START  &__unused_start__
00141 #define HEAP_SIZE  ((uptr_t)(&__External_SRAM_segment_end__ - 1) - (uptr_t)(HEAP_START) - 256)
00142 #else   /* GCC */
00143 
00146 #define NUTMEM_END (uptr_t)(NUTMEM_START + NUTMEM_SIZE - 1U)
00147 extern void *__heap_start;
00148 
00149 #define HEAP_START  &__heap_start
00150 #define HEAP_SIZE  ((uptr_t) (NUTMEM_END - 256 - (uptr_t) (&__heap_start)))
00151 #endif
00152 
00153 #if !defined(__arm__) && !defined(__cplusplus)
00154 extern void NutAppMain(void *arg) __attribute__ ((noreturn));
00155 #else
00156 extern void main(void *);
00157 #endif
00158 
00159 
00160 #if defined(OLIMEX_LPCE2294)
00161 /*
00162  * InitHW for OLIMEX LPC-E2294
00163  */
00164 static void InitHW (void)
00165 {
00166   PINSEL0  = 0;
00167   PINSEL1  = 0;
00168 
00169   BCFG2    = 0x03501;
00170   PINSEL2 |= 0x00804000;
00171 } /* InitHW */
00172 
00173 #endif /* OLIMEX_LPCE2294 */
00174 
00175 
00176 
00184 THREAD(NutIdle, arg)
00185 {
00186 #if defined(MCU_GBA) || defined(MCU_LPC2XXX)
00187     InitIrqHandler();
00188 #endif
00189     /* Initialize system timers. */
00190     NutTimerInit();
00191 
00192     /* Create the main application thread. */
00193     NutThreadCreate("main", main, 0, NUT_THREAD_MAINSTACK);
00194 
00195     /*
00196      * Run in an idle loop at the lowest priority. We can still
00197      * do something useful here, like killing terminated threads
00198      * or putting the CPU into sleep mode.
00199      */
00200     NutThreadSetPriority(254);
00201     for (;;) {
00202         NutThreadYield();
00203         NutThreadDestroy();
00204     }
00205 }
00206 
00214 void NutInit(void)
00215 {
00216 #if defined(OLIMEX_LPCE2294)
00217     InitHW();
00218 #elif defined(MCU_AT91R40008) || defined (MCU_AT91SAM7X256) || defined (MCU_AT91SAM7S256) || defined (MCU_AT91SAM9260)
00219     McuInit();
00220 #endif
00221 #if defined(MCU_AT91SAM7X256) || defined (MCU_AT91SAM7S256)
00222     {
00223         u_long freq = NutGetCpuClock();
00224         /* Set Flash Waite state. */
00225         outr(MC_FMR, ((((freq + freq / 2) / 1000000UL) & 0xFF) << 16) | MC_FWS_2R3W);
00226     }
00227 #endif
00228 
00229     NutHeapAdd(HEAP_START, HEAP_SIZE);
00230 
00231     /*
00232      * No EEPROM configuration.
00233      */
00234     strcpy(confos.hostname, "ethernut");
00235 
00236     /*
00237      * Create idle thread
00238      */
00239     NutThreadCreate("idle", NutIdle, 0, NUT_THREAD_IDLESTACK);
00240 }
00241 

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