Maxim nexpaq / nexpaq_dev
Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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