test

Dependencies:   F7_Ethernet mbed BSP_DISCO_F746NG SDFileSystem RF24

Committer:
leo44
Date:
Tue Jun 08 10:06:19 2021 +0000
Revision:
0:d984976f1f1c
proto

Who changed what in which revision?

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