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