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.15  2008/02/15 16:59:27  haraldkipp
00037  * Spport for AT91SAM7SE512 added.
00038  *
00039  * Revision 1.14  2007/10/04 20:08:00  olereinhardt
00040  * Support for SAM7S256 added
00041  *
00042  * Revision 1.13  2006/09/29 12:39:51  haraldkipp
00043  * Spurious interrupt handling on all supported AT91 devices.
00044  *
00045  * Revision 1.12  2006/07/26 11:17:16  haraldkipp
00046  * Defining AT91_PLL_MAINCK will automatically determine SAM7X clock by
00047  * reading PLL settings.
00048  *
00049  * Revision 1.11  2006/07/18 14:04:10  haraldkipp
00050  * Low level hardware initialization moved to crtat91sam7x256_rom.S. This
00051  * avoids the ugly jump from C code back into the runtime initialization.
00052  * Watchdog reset (tiger bell) removed from idle thread.
00053  *
00054  * Revision 1.10  2006/07/15 11:13:30  haraldkipp
00055  * CPU ran into the data pool of Sam7xLowLevelInit(). Temporarily
00056  * fixed by Andras Albert with an additional global label in the
00057  * startup code. Furthermore Andras changed the clock initialization.
00058  * The CPU is now running at 47.9232 MHz and the MAC starts working.
00059  * Great, TCP/IP is now running on the SAM7X.
00060  *
00061  * Revision 1.9  2006/07/10 14:27:03  haraldkipp
00062  * C++ will use main instead of NutAppMain. Contributed by Matthias Wilde.
00063  *
00064  * Revision 1.8  2006/07/05 07:57:52  haraldkipp
00065  * Daidai's support for AT91SAM7X added. Possibly taken from Atmel.
00066  * May require new coding from ground up in order to not conflict with
00067  * original copyright.
00068  * Nevertheless, many thanks to Daidai for providing his adaption.
00069  *
00070  * Revision 1.7  2006/06/28 17:22:34  haraldkipp
00071  * Make it compile for AT91SAM7X256.
00072  *
00073  * Revision 1.6  2006/03/02 19:43:11  haraldkipp
00074  * Added MCU specific hardware initialization routine. This should be done
00075  * later for all MCUs to avoid contaminating NutInit() with MCU specific
00076  * stuff. For the AT91 the spurious interrupt handler has been added,
00077  * which fixes SF 1440948.
00078  *
00079  * Revision 1.5  2006/02/23 15:34:00  haraldkipp
00080  * Support for Philips LPC2xxx Family and LPC-E2294 Board from Olimex added.
00081  * Many thanks to Michael Fischer for this port.
00082  *
00083  * Revision 1.4  2005/10/24 09:22:29  haraldkipp
00084  * Default idle and main thread stack sizes increased.
00085  * AT91 header file moved.
00086  *
00087  * Revision 1.3  2005/08/02 17:46:45  haraldkipp
00088  * Major API documentation update.
00089  *
00090  * Revision 1.2  2005/07/26 16:17:03  haraldkipp
00091  * Use default stack sizes for main and idle, if none had been defined.
00092  *
00093  * Revision 1.1  2005/05/27 17:16:40  drsung
00094  * Moved the file.
00095  *
00096  * Revision 1.4  2005/04/05 17:52:41  haraldkipp
00097  * Much better implementation of GBA interrupt registration.
00098  *
00099  * Revision 1.3  2004/11/08 18:58:59  haraldkipp
00100  * Configurable stack sizes
00101  *
00102  * Revision 1.2  2004/09/08 10:19:23  haraldkipp
00103  * Made it look more general
00104  *
00105  * Revision 1.1  2004/03/16 16:48:46  haraldkipp
00106  * Added Jan Dubiec's H8/300 port.
00107  *
00108  *
00109  */
00110 
00111 #include <cfg/arch.h>
00112 #include <cfg/memory.h>
00113 #include <cfg/os.h>
00114 #ifdef MCU_GBA
00115 #include <dev/irqreg.h>
00116 #elif defined(MCU_LPC2XXX)
00117 #include <arch/arm/lpc2xxx.h>
00118 #else
00119 #include <arch/arm/at91.h>
00120 #endif
00121 
00126 
00127 #ifndef NUT_THREAD_MAINSTACK
00128 #define NUT_THREAD_MAINSTACK    1024
00129 #endif
00130 
00131 #ifndef NUT_THREAD_IDLESTACK
00132 #define NUT_THREAD_IDLESTACK    512
00133 #endif
00134 
00135 #ifdef __CROSSWORKS4ARM__
00136 extern void *__unused_start__;
00137 /*
00138  * Michael, Why does Crossworks needs this one. Is memory configurable
00139  * with the Configurator?
00140  */
00141 extern void *__External_SRAM_segment_end__;
00142 
00143 #define HEAP_START  &__unused_start__
00144 #define HEAP_SIZE  ((uptr_t)(&__External_SRAM_segment_end__ - 1) - (uptr_t)(HEAP_START) - 256)
00145 #else   /* GCC */
00146 
00149 #define NUTMEM_END (uptr_t)(NUTMEM_START + NUTMEM_SIZE - 1U)
00150 extern void *__heap_start;
00151 
00152 #define HEAP_START  &__heap_start
00153 #define HEAP_SIZE  ((uptr_t) (NUTMEM_END - 256 - (uptr_t) (&__heap_start)))
00154 #endif
00155 
00156 #if !defined(__arm__) && !defined(__cplusplus)
00157 extern void NutAppMain(void *arg) __attribute__ ((noreturn));
00158 #else
00159 extern void main(void *);
00160 #endif
00161 
00162 
00163 #if defined(OLIMEX_LPCE2294)
00164 /*
00165  * InitHW for OLIMEX LPC-E2294
00166  */
00167 static void InitHW (void)
00168 {
00169   PINSEL0  = 0;
00170   PINSEL1  = 0;
00171 
00172   BCFG2    = 0x03501;
00173   PINSEL2 |= 0x00804000;
00174 } /* InitHW */
00175 
00176 #endif /* OLIMEX_LPCE2294 */
00177 
00178 
00179 
00187 THREAD(NutIdle, arg)
00188 {
00189 #if defined(MCU_GBA) || defined(MCU_LPC2XXX)
00190     InitIrqHandler();
00191 #endif
00192     /* Initialize system timers. */
00193     NutTimerInit();
00194 
00195     /* Create the main application thread. */
00196     NutThreadCreate("main", main, 0, NUT_THREAD_MAINSTACK);
00197 
00198     /*
00199      * Run in an idle loop at the lowest priority. We can still
00200      * do something useful here, like killing terminated threads
00201      * or putting the CPU into sleep mode.
00202      */
00203     NutThreadSetPriority(254);
00204     for (;;) {
00205         NutThreadYield();
00206         NutThreadDestroy();
00207     }
00208 }
00209 
00217 void NutInit(void)
00218 {
00219 #if defined(OLIMEX_LPCE2294)
00220     InitHW();
00221 #elif defined(MCU_AT91R40008) || defined (MCU_AT91SAM7X256) || defined (MCU_AT91SAM7S256) || defined (MCU_AT91SAM9260) || defined(MCU_AT91SAM7SE512)
00222     McuInit();
00223 #endif
00224 #if defined(MCU_AT91SAM7X256) || defined (MCU_AT91SAM7S256) || defined(MCU_AT91SAM7SE512)
00225     {
00226         u_long freq = NutGetCpuClock();
00227         /* Set Flash Waite state. */
00228         outr(MC_FMR, ((((freq + freq / 2) / 1000000UL) & 0xFF) << 16) | MC_FWS_2R3W);
00229     }
00230 #endif
00231 
00232     NutHeapAdd(HEAP_START, HEAP_SIZE);
00233 
00234     /*
00235      * No EEPROM configuration.
00236      */
00237     strcpy(confos.hostname, "ethernut");
00238 
00239     /*
00240      * Create idle thread
00241      */
00242     NutThreadCreate("idle", NutIdle, 0, NUT_THREAD_IDLESTACK);
00243 }
00244 

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