forked

Dependents:   WireFSHandControl

Fork of mbed-rtos by mbed official

Committer:
c1728p9
Date:
Mon Nov 14 17:14:42 2016 -0600
Revision:
123:58563e6cba1e
Parent:
121:3da5f554d8bf
Configure RTOS to behave as it did before 5.0

Who changed what in which revision?

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