mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 /*----------------------------------------------------------------------------
elessair 0:f269e3021894 2 * RL-ARM - RTX
elessair 0:f269e3021894 3 *----------------------------------------------------------------------------
elessair 0:f269e3021894 4 * Name: RTX_CM_LIB.H
elessair 0:f269e3021894 5 * Purpose: RTX Kernel System Configuration
elessair 0:f269e3021894 6 * Rev.: V4.60
elessair 0:f269e3021894 7 *----------------------------------------------------------------------------
elessair 0:f269e3021894 8 *
elessair 0:f269e3021894 9 * Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH
elessair 0:f269e3021894 10 * All rights reserved.
elessair 0:f269e3021894 11 * Redistribution and use in source and binary forms, with or without
elessair 0:f269e3021894 12 * modification, are permitted provided that the following conditions are met:
elessair 0:f269e3021894 13 * - Redistributions of source code must retain the above copyright
elessair 0:f269e3021894 14 * notice, this list of conditions and the following disclaimer.
elessair 0:f269e3021894 15 * - Redistributions in binary form must reproduce the above copyright
elessair 0:f269e3021894 16 * notice, this list of conditions and the following disclaimer in the
elessair 0:f269e3021894 17 * documentation and/or other materials provided with the distribution.
elessair 0:f269e3021894 18 * - Neither the name of ARM nor the names of its contributors may be used
elessair 0:f269e3021894 19 * to endorse or promote products derived from this software without
elessair 0:f269e3021894 20 * specific prior written permission.
elessair 0:f269e3021894 21 *
elessair 0:f269e3021894 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
elessair 0:f269e3021894 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
elessair 0:f269e3021894 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
elessair 0:f269e3021894 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
elessair 0:f269e3021894 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
elessair 0:f269e3021894 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
elessair 0:f269e3021894 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
elessair 0:f269e3021894 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
elessair 0:f269e3021894 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
elessair 0:f269e3021894 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
elessair 0:f269e3021894 32 * POSSIBILITY OF SUCH DAMAGE.
elessair 0:f269e3021894 33 *---------------------------------------------------------------------------*/
elessair 0:f269e3021894 34 #include "mbed_error.h"
elessair 0:f269e3021894 35
elessair 0:f269e3021894 36 #if defined (__CC_ARM)
elessair 0:f269e3021894 37 #pragma O3
elessair 0:f269e3021894 38 #define __USED __attribute__((used))
elessair 0:f269e3021894 39 #elif defined (__GNUC__)
elessair 0:f269e3021894 40 #pragma GCC optimize ("O3")
elessair 0:f269e3021894 41 #define __USED __attribute__((used))
elessair 0:f269e3021894 42 #elif defined (__ICCARM__)
elessair 0:f269e3021894 43 #define __USED __root
elessair 0:f269e3021894 44 #endif
elessair 0:f269e3021894 45
elessair 0:f269e3021894 46
elessair 0:f269e3021894 47 /*----------------------------------------------------------------------------
elessair 0:f269e3021894 48 * Definitions
elessair 0:f269e3021894 49 *---------------------------------------------------------------------------*/
elessair 0:f269e3021894 50
elessair 0:f269e3021894 51 #define _declare_box(pool,size,cnt) uint32_t pool[(((size)+3)/4)*(cnt) + 3]
elessair 0:f269e3021894 52 #define _declare_box8(pool,size,cnt) uint64_t pool[(((size)+7)/8)*(cnt) + 2]
elessair 0:f269e3021894 53
elessair 0:f269e3021894 54 #define OS_TCB_SIZE 48
elessair 0:f269e3021894 55 #define OS_TMR_SIZE 8
elessair 0:f269e3021894 56
elessair 0:f269e3021894 57 #if defined (__CC_ARM) && !defined (__MICROLIB)
elessair 0:f269e3021894 58
elessair 0:f269e3021894 59 typedef void *OS_ID;
elessair 0:f269e3021894 60 typedef uint32_t OS_TID;
elessair 0:f269e3021894 61 typedef uint32_t OS_MUT[3];
elessair 0:f269e3021894 62 typedef uint32_t OS_RESULT;
elessair 0:f269e3021894 63
elessair 0:f269e3021894 64 #define runtask_id() rt_tsk_self()
elessair 0:f269e3021894 65 #define mutex_init(m) rt_mut_init(m)
elessair 0:f269e3021894 66 #define mutex_wait(m) os_mut_wait(m,0xFFFF)
elessair 0:f269e3021894 67 #define mutex_rel(m) os_mut_release(m)
elessair 0:f269e3021894 68
elessair 0:f269e3021894 69 extern OS_TID rt_tsk_self (void);
elessair 0:f269e3021894 70 extern void rt_mut_init (OS_ID mutex);
elessair 0:f269e3021894 71 extern OS_RESULT rt_mut_release (OS_ID mutex);
elessair 0:f269e3021894 72 extern OS_RESULT rt_mut_wait (OS_ID mutex, uint16_t timeout);
elessair 0:f269e3021894 73
elessair 0:f269e3021894 74 #define os_mut_wait(mutex,timeout) _os_mut_wait((uint32_t)rt_mut_wait,mutex,timeout)
elessair 0:f269e3021894 75 #define os_mut_release(mutex) _os_mut_release((uint32_t)rt_mut_release,mutex)
elessair 0:f269e3021894 76
elessair 0:f269e3021894 77 OS_RESULT _os_mut_release (uint32_t p, OS_ID mutex) __svc_indirect(0);
elessair 0:f269e3021894 78 OS_RESULT _os_mut_wait (uint32_t p, OS_ID mutex, uint16_t timeout) __svc_indirect(0);
elessair 0:f269e3021894 79
elessair 0:f269e3021894 80 #endif
elessair 0:f269e3021894 81
elessair 0:f269e3021894 82
elessair 0:f269e3021894 83 /*----------------------------------------------------------------------------
elessair 0:f269e3021894 84 * Global Variables
elessair 0:f269e3021894 85 *---------------------------------------------------------------------------*/
elessair 0:f269e3021894 86
elessair 0:f269e3021894 87 #if (OS_TIMERS != 0)
elessair 0:f269e3021894 88 #define OS_TASK_CNT (OS_TASKCNT + 1)
elessair 0:f269e3021894 89 #else
elessair 0:f269e3021894 90 #define OS_TASK_CNT OS_TASKCNT
elessair 0:f269e3021894 91 #endif
elessair 0:f269e3021894 92
elessair 0:f269e3021894 93 uint16_t const os_maxtaskrun = OS_TASK_CNT;
elessair 0:f269e3021894 94 uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT;
elessair 0:f269e3021894 95 uint32_t const os_trv = OS_TRV;
elessair 0:f269e3021894 96 uint8_t const os_flags = OS_RUNPRIV;
elessair 0:f269e3021894 97
elessair 0:f269e3021894 98 /* Export following defines to uVision debugger. */
elessair 0:f269e3021894 99 __USED uint32_t const os_clockrate = OS_TICK;
elessair 0:f269e3021894 100 __USED uint32_t const os_timernum = 0;
elessair 0:f269e3021894 101
elessair 0:f269e3021894 102 /* Stack for the os_idle_demon */
elessair 0:f269e3021894 103 unsigned int idle_task_stack[OS_IDLESTKSIZE];
elessair 0:f269e3021894 104 unsigned short const idle_task_stack_size = OS_IDLESTKSIZE;
elessair 0:f269e3021894 105
elessair 0:f269e3021894 106 #ifndef OS_FIFOSZ
elessair 0:f269e3021894 107 #define OS_FIFOSZ 16
elessair 0:f269e3021894 108 #endif
elessair 0:f269e3021894 109
elessair 0:f269e3021894 110 /* Fifo Queue buffer for ISR requests.*/
elessair 0:f269e3021894 111 uint32_t os_fifo[OS_FIFOSZ*2+1];
elessair 0:f269e3021894 112 uint8_t const os_fifo_size = OS_FIFOSZ;
elessair 0:f269e3021894 113
elessair 0:f269e3021894 114 /* An array of Active task pointers. */
elessair 0:f269e3021894 115 void *os_active_TCB[OS_TASK_CNT];
elessair 0:f269e3021894 116
elessair 0:f269e3021894 117 /* User Timers Resources */
elessair 0:f269e3021894 118 #if (OS_TIMERS != 0)
elessair 0:f269e3021894 119 extern void osTimerThread (void const *argument);
elessair 0:f269e3021894 120 osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ);
elessair 0:f269e3021894 121 osThreadId osThreadId_osTimerThread;
elessair 0:f269e3021894 122 osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *);
elessair 0:f269e3021894 123 osMessageQId osMessageQId_osTimerMessageQ;
elessair 0:f269e3021894 124 #else
elessair 0:f269e3021894 125 osThreadDef_t os_thread_def_osTimerThread = { NULL };
elessair 0:f269e3021894 126 osThreadId osThreadId_osTimerThread;
elessair 0:f269e3021894 127 osMessageQDef(osTimerMessageQ, 0, void *);
elessair 0:f269e3021894 128 osMessageQId osMessageQId_osTimerMessageQ;
elessair 0:f269e3021894 129 #endif
elessair 0:f269e3021894 130
elessair 0:f269e3021894 131
elessair 0:f269e3021894 132 /*----------------------------------------------------------------------------
elessair 0:f269e3021894 133 * RTX Optimizations (empty functions)
elessair 0:f269e3021894 134 *---------------------------------------------------------------------------*/
elessair 0:f269e3021894 135
elessair 0:f269e3021894 136 #if OS_ROBIN == 0
elessair 0:f269e3021894 137 void rt_init_robin (void) {;}
elessair 0:f269e3021894 138 void rt_chk_robin (void) {;}
elessair 0:f269e3021894 139 #endif
elessair 0:f269e3021894 140
elessair 0:f269e3021894 141 #if OS_STKCHECK == 0
elessair 0:f269e3021894 142 void rt_stk_check (void) {;}
elessair 0:f269e3021894 143 #endif
elessair 0:f269e3021894 144
elessair 0:f269e3021894 145
elessair 0:f269e3021894 146 /*----------------------------------------------------------------------------
elessair 0:f269e3021894 147 * Standard Library multithreading interface
elessair 0:f269e3021894 148 *---------------------------------------------------------------------------*/
elessair 0:f269e3021894 149
elessair 0:f269e3021894 150 #if defined (__CC_ARM) && !defined (__MICROLIB)
elessair 0:f269e3021894 151 static OS_MUT std_libmutex[OS_MUTEXCNT];
elessair 0:f269e3021894 152 static uint32_t nr_mutex;
elessair 0:f269e3021894 153
elessair 0:f269e3021894 154 /*--------------------------- _mutex_initialize -----------------------------*/
elessair 0:f269e3021894 155
elessair 0:f269e3021894 156 int _mutex_initialize (OS_ID *mutex) {
elessair 0:f269e3021894 157 /* Allocate and initialize a system mutex. */
elessair 0:f269e3021894 158
elessair 0:f269e3021894 159 if (nr_mutex >= OS_MUTEXCNT) {
elessair 0:f269e3021894 160 /* If you are here, you need to increase the number OS_MUTEXCNT. */
elessair 0:f269e3021894 161 error("Not enough stdlib mutexes\n");
elessair 0:f269e3021894 162 }
elessair 0:f269e3021894 163 *mutex = &std_libmutex[nr_mutex++];
elessair 0:f269e3021894 164 mutex_init (*mutex);
elessair 0:f269e3021894 165 return (1);
elessair 0:f269e3021894 166 }
elessair 0:f269e3021894 167
elessair 0:f269e3021894 168
elessair 0:f269e3021894 169 /*--------------------------- _mutex_acquire --------------------------------*/
elessair 0:f269e3021894 170
elessair 0:f269e3021894 171 __attribute__((used)) void _mutex_acquire (OS_ID *mutex) {
elessair 0:f269e3021894 172 /* Acquire a system mutex, lock stdlib resources. */
elessair 0:f269e3021894 173 if (runtask_id ()) {
elessair 0:f269e3021894 174 /* RTX running, acquire a mutex. */
elessair 0:f269e3021894 175 mutex_wait (*mutex);
elessair 0:f269e3021894 176 }
elessair 0:f269e3021894 177 }
elessair 0:f269e3021894 178
elessair 0:f269e3021894 179
elessair 0:f269e3021894 180 /*--------------------------- _mutex_release --------------------------------*/
elessair 0:f269e3021894 181
elessair 0:f269e3021894 182 __attribute__((used)) void _mutex_release (OS_ID *mutex) {
elessair 0:f269e3021894 183 /* Release a system mutex, unlock stdlib resources. */
elessair 0:f269e3021894 184 if (runtask_id ()) {
elessair 0:f269e3021894 185 /* RTX running, release a mutex. */
elessair 0:f269e3021894 186 mutex_rel (*mutex);
elessair 0:f269e3021894 187 }
elessair 0:f269e3021894 188 }
elessair 0:f269e3021894 189
elessair 0:f269e3021894 190 #endif
elessair 0:f269e3021894 191
elessair 0:f269e3021894 192
elessair 0:f269e3021894 193 /*----------------------------------------------------------------------------
elessair 0:f269e3021894 194 * RTX Startup
elessair 0:f269e3021894 195 *---------------------------------------------------------------------------*/
elessair 0:f269e3021894 196
elessair 0:f269e3021894 197 /* Main Thread definition */
elessair 0:f269e3021894 198 extern void pre_main (void);
elessair 0:f269e3021894 199 osThreadDef_t os_thread_def_main = {(os_pthread)pre_main, osPriorityNormal, 0, NULL};
elessair 0:f269e3021894 200
elessair 0:f269e3021894 201 #ifndef INITIAL_SP
elessair 0:f269e3021894 202 #error "no target defined"
elessair 0:f269e3021894 203 #endif
elessair 0:f269e3021894 204
elessair 0:f269e3021894 205 #ifdef __CC_ARM
elessair 0:f269e3021894 206 extern unsigned char Image$$RW_IRAM1$$ZI$$Limit[];
elessair 0:f269e3021894 207 #define HEAP_START (Image$$RW_IRAM1$$ZI$$Limit)
elessair 0:f269e3021894 208 #elif defined(__GNUC__)
elessair 0:f269e3021894 209 extern unsigned char __end__[];
elessair 0:f269e3021894 210 #define HEAP_START (__end__)
elessair 0:f269e3021894 211 #elif defined(__ICCARM__)
elessair 0:f269e3021894 212 #pragma section="HEAP"
elessair 0:f269e3021894 213 #define HEAP_START (void *)__section_begin("HEAP")
elessair 0:f269e3021894 214 #endif
elessair 0:f269e3021894 215
elessair 0:f269e3021894 216 void set_main_stack(void) {
elessair 0:f269e3021894 217 // That is the bottom of the main stack block: no collision detection
elessair 0:f269e3021894 218 os_thread_def_main.stack_pointer = HEAP_START;
elessair 0:f269e3021894 219
elessair 0:f269e3021894 220 // Leave OS_SCHEDULERSTKSIZE words for the scheduler and interrupts
elessair 0:f269e3021894 221 os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)HEAP_START) - (OS_SCHEDULERSTKSIZE * 4);
elessair 0:f269e3021894 222 }
elessair 0:f269e3021894 223
elessair 0:f269e3021894 224 #if defined (__CC_ARM)
elessair 0:f269e3021894 225 #ifdef __MICROLIB
elessair 0:f269e3021894 226
elessair 0:f269e3021894 227 int main(void);
elessair 0:f269e3021894 228 void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF")));
elessair 0:f269e3021894 229 void $Super$$__cpp_initialize__aeabi_(void);
elessair 0:f269e3021894 230
elessair 0:f269e3021894 231 void _main_init (void) {
elessair 0:f269e3021894 232 osKernelInitialize();
elessair 0:f269e3021894 233 set_main_stack();
elessair 0:f269e3021894 234 osThreadCreate(&os_thread_def_main, NULL);
elessair 0:f269e3021894 235 osKernelStart();
elessair 0:f269e3021894 236 for (;;);
elessair 0:f269e3021894 237 }
elessair 0:f269e3021894 238
elessair 0:f269e3021894 239 void $Sub$$__cpp_initialize__aeabi_(void)
elessair 0:f269e3021894 240 {
elessair 0:f269e3021894 241 // this should invoke C++ initializers prior _main_init, we keep this empty and
elessair 0:f269e3021894 242 // invoke them after _main_init (=starts RTX kernel)
elessair 0:f269e3021894 243 }
elessair 0:f269e3021894 244
elessair 0:f269e3021894 245 void pre_main()
elessair 0:f269e3021894 246 {
elessair 0:f269e3021894 247 $Super$$__cpp_initialize__aeabi_();
elessair 0:f269e3021894 248 main();
elessair 0:f269e3021894 249 }
elessair 0:f269e3021894 250
elessair 0:f269e3021894 251 #else
elessair 0:f269e3021894 252
elessair 0:f269e3021894 253 void * armcc_heap_base;
elessair 0:f269e3021894 254 void * armcc_heap_top;
elessair 0:f269e3021894 255
elessair 0:f269e3021894 256 __asm void pre_main (void)
elessair 0:f269e3021894 257 {
elessair 0:f269e3021894 258 IMPORT __rt_lib_init
elessair 0:f269e3021894 259 IMPORT main
elessair 0:f269e3021894 260 IMPORT armcc_heap_base
elessair 0:f269e3021894 261 IMPORT armcc_heap_top
elessair 0:f269e3021894 262
elessair 0:f269e3021894 263 LDR R0,=armcc_heap_base
elessair 0:f269e3021894 264 LDR R1,=armcc_heap_top
elessair 0:f269e3021894 265 LDR R0,[R0]
elessair 0:f269e3021894 266 LDR R1,[R1]
elessair 0:f269e3021894 267 /* Save link register (keep 8 byte alignment with dummy R4) */
elessair 0:f269e3021894 268 PUSH {R4, LR}
elessair 0:f269e3021894 269 BL __rt_lib_init
elessair 0:f269e3021894 270 BL main
elessair 0:f269e3021894 271 /* Return to the thread destroy function.
elessair 0:f269e3021894 272 */
elessair 0:f269e3021894 273 POP {R4, PC}
elessair 0:f269e3021894 274 ALIGN
elessair 0:f269e3021894 275 }
elessair 0:f269e3021894 276
elessair 0:f269e3021894 277 /* The single memory model is checking for stack collision at run time, verifing
elessair 0:f269e3021894 278 that the heap pointer is underneath the stack pointer.
elessair 0:f269e3021894 279
elessair 0:f269e3021894 280 With the RTOS there is not only one stack above the heap, there are multiple
elessair 0:f269e3021894 281 stacks and some of them are underneath the heap pointer.
elessair 0:f269e3021894 282 */
elessair 0:f269e3021894 283 #pragma import(__use_two_region_memory)
elessair 0:f269e3021894 284
elessair 0:f269e3021894 285 __asm void __rt_entry (void) {
elessair 0:f269e3021894 286
elessair 0:f269e3021894 287 IMPORT __user_setup_stackheap
elessair 0:f269e3021894 288 IMPORT armcc_heap_base
elessair 0:f269e3021894 289 IMPORT armcc_heap_top
elessair 0:f269e3021894 290 IMPORT os_thread_def_main
elessair 0:f269e3021894 291 IMPORT osKernelInitialize
elessair 0:f269e3021894 292 IMPORT set_main_stack
elessair 0:f269e3021894 293 IMPORT osKernelStart
elessair 0:f269e3021894 294 IMPORT osThreadCreate
elessair 0:f269e3021894 295
elessair 0:f269e3021894 296 /* __user_setup_stackheap returns:
elessair 0:f269e3021894 297 * - Heap base in r0 (if the program uses the heap).
elessair 0:f269e3021894 298 * - Stack base in sp.
elessair 0:f269e3021894 299 * - Heap limit in r2 (if the program uses the heap and uses two-region memory).
elessair 0:f269e3021894 300 *
elessair 0:f269e3021894 301 * More info can be found in:
elessair 0:f269e3021894 302 * ARM Compiler ARM C and C++ Libraries and Floating-Point Support User Guide
elessair 0:f269e3021894 303 */
elessair 0:f269e3021894 304 BL __user_setup_stackheap
elessair 0:f269e3021894 305 LDR R3,=armcc_heap_base
elessair 0:f269e3021894 306 LDR R4,=armcc_heap_top
elessair 0:f269e3021894 307 STR R0,[R3]
elessair 0:f269e3021894 308 STR R2,[R4]
elessair 0:f269e3021894 309 BL osKernelInitialize
elessair 0:f269e3021894 310 BL set_main_stack
elessair 0:f269e3021894 311 LDR R0,=os_thread_def_main
elessair 0:f269e3021894 312 MOVS R1,#0
elessair 0:f269e3021894 313 BL osThreadCreate
elessair 0:f269e3021894 314 BL osKernelStart
elessair 0:f269e3021894 315 /* osKernelStart should not return */
elessair 0:f269e3021894 316 B .
elessair 0:f269e3021894 317
elessair 0:f269e3021894 318 ALIGN
elessair 0:f269e3021894 319 }
elessair 0:f269e3021894 320
elessair 0:f269e3021894 321 #endif
elessair 0:f269e3021894 322
elessair 0:f269e3021894 323 #elif defined (__GNUC__)
elessair 0:f269e3021894 324
elessair 0:f269e3021894 325 extern int atexit(void (*func)(void));
elessair 0:f269e3021894 326 extern void __libc_fini_array(void);
elessair 0:f269e3021894 327 extern void __libc_init_array (void);
elessair 0:f269e3021894 328 extern int main(int argc, char **argv);
elessair 0:f269e3021894 329
elessair 0:f269e3021894 330 void pre_main(void) {
elessair 0:f269e3021894 331 atexit(__libc_fini_array);
elessair 0:f269e3021894 332 __libc_init_array();
elessair 0:f269e3021894 333 main(0, NULL);
elessair 0:f269e3021894 334 }
elessair 0:f269e3021894 335
elessair 0:f269e3021894 336 __attribute__((naked)) void software_init_hook_rtos (void) {
elessair 0:f269e3021894 337 __asm (
elessair 0:f269e3021894 338 ".syntax unified\n"
elessair 0:f269e3021894 339 ".thumb\n"
elessair 0:f269e3021894 340 "bl osKernelInitialize\n"
elessair 0:f269e3021894 341 "bl set_main_stack\n"
elessair 0:f269e3021894 342 "ldr r0,=os_thread_def_main\n"
elessair 0:f269e3021894 343 "movs r1,#0\n"
elessair 0:f269e3021894 344 "bl osThreadCreate\n"
elessair 0:f269e3021894 345 "bl osKernelStart\n"
elessair 0:f269e3021894 346 /* osKernelStart should not return */
elessair 0:f269e3021894 347 "B .\n"
elessair 0:f269e3021894 348 );
elessair 0:f269e3021894 349 }
elessair 0:f269e3021894 350
elessair 0:f269e3021894 351 #elif defined (__ICCARM__)
elessair 0:f269e3021894 352
elessair 0:f269e3021894 353 extern void* __vector_table;
elessair 0:f269e3021894 354 extern int __low_level_init(void);
elessair 0:f269e3021894 355 extern void __iar_data_init3(void);
elessair 0:f269e3021894 356 extern __weak void __iar_init_core( void );
elessair 0:f269e3021894 357 extern __weak void __iar_init_vfp( void );
elessair 0:f269e3021894 358 extern void __iar_dynamic_initialization(void);
elessair 0:f269e3021894 359 extern void mbed_sdk_init(void);
elessair 0:f269e3021894 360 extern void exit(int arg);
elessair 0:f269e3021894 361
elessair 0:f269e3021894 362 static uint8_t low_level_init_needed;
elessair 0:f269e3021894 363
elessair 0:f269e3021894 364 void pre_main(void) {
elessair 0:f269e3021894 365 if (low_level_init_needed) {
elessair 0:f269e3021894 366 __iar_dynamic_initialization();
elessair 0:f269e3021894 367 }
elessair 0:f269e3021894 368 main();
elessair 0:f269e3021894 369 }
elessair 0:f269e3021894 370
elessair 0:f269e3021894 371 #pragma required=__vector_table
elessair 0:f269e3021894 372 void __iar_program_start( void )
elessair 0:f269e3021894 373 {
elessair 0:f269e3021894 374 __iar_init_core();
elessair 0:f269e3021894 375 __iar_init_vfp();
elessair 0:f269e3021894 376
elessair 0:f269e3021894 377 uint8_t low_level_init_needed_local;
elessair 0:f269e3021894 378
elessair 0:f269e3021894 379 low_level_init_needed_local = __low_level_init();
elessair 0:f269e3021894 380 if (low_level_init_needed_local) {
elessair 0:f269e3021894 381 __iar_data_init3();
elessair 0:f269e3021894 382 mbed_sdk_init();
elessair 0:f269e3021894 383 }
elessair 0:f269e3021894 384 /* Store in a global variable after RAM has been initialized */
elessair 0:f269e3021894 385 low_level_init_needed = low_level_init_needed_local;
elessair 0:f269e3021894 386 osKernelInitialize();
elessair 0:f269e3021894 387 set_main_stack();
elessair 0:f269e3021894 388 osThreadCreate(&os_thread_def_main, NULL);
elessair 0:f269e3021894 389 osKernelStart();
elessair 0:f269e3021894 390 /* osKernelStart should not return */
elessair 0:f269e3021894 391 while (1);
elessair 0:f269e3021894 392 }
elessair 0:f269e3021894 393
elessair 0:f269e3021894 394 #endif
elessair 0:f269e3021894 395
elessair 0:f269e3021894 396
elessair 0:f269e3021894 397 /*----------------------------------------------------------------------------
elessair 0:f269e3021894 398 * end of file
elessair 0:f269e3021894 399 *---------------------------------------------------------------------------*/
elessair 0:f269e3021894 400
elessair 0:f269e3021894 401