forked
Fork of mbed-rtos by
rtx/TARGET_ARM7/RTX_CM_lib.h@116:0788b1a76461, 2016-05-23 (annotated)
- Committer:
- mbed_official
- Date:
- Mon May 23 10:00:41 2016 +0100
- Revision:
- 116:0788b1a76461
- Parent:
- 80:2dab120a94c2
- Child:
- 118:6635230e06ba
Synchronized with git revision 99fb83ae2190e05b964e33257cb710c9a300f006
Full URL: https://github.com/mbedmicro/mbed/commit/99fb83ae2190e05b964e33257cb710c9a300f006/
RTX - init sequence (C++ array init)
Who changed what in which revision?
User | Revision | Line number | New 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 | |
mbed_official | 80:2dab120a94c2 | 201 | // This define should be probably moved to the CMSIS layer |
mbed_official | 80:2dab120a94c2 | 202 | |
mbed_official | 80:2dab120a94c2 | 203 | #if defined(TARGET_LPC2460) |
mbed_official | 80:2dab120a94c2 | 204 | extern unsigned char __usr_stack_top__[]; |
mbed_official | 80:2dab120a94c2 | 205 | #define INITIAL_SP (__usr_stack_top__) |
mbed_official | 80:2dab120a94c2 | 206 | |
mbed_official | 80:2dab120a94c2 | 207 | #else |
mbed_official | 80:2dab120a94c2 | 208 | #error "no target defined" |
mbed_official | 80:2dab120a94c2 | 209 | |
mbed_official | 80:2dab120a94c2 | 210 | #endif |
mbed_official | 80:2dab120a94c2 | 211 | |
mbed_official | 80:2dab120a94c2 | 212 | #ifdef __CC_ARM |
mbed_official | 80:2dab120a94c2 | 213 | extern unsigned char Image$$RW_IRAM1$$ZI$$Limit[]; |
mbed_official | 80:2dab120a94c2 | 214 | #define HEAP_START (Image$$RW_IRAM1$$ZI$$Limit) |
mbed_official | 80:2dab120a94c2 | 215 | #elif defined(__GNUC__) |
mbed_official | 80:2dab120a94c2 | 216 | extern unsigned char __end__[]; |
mbed_official | 80:2dab120a94c2 | 217 | #define HEAP_START (__end__) |
mbed_official | 80:2dab120a94c2 | 218 | #elif defined(__ICCARM__) |
mbed_official | 80:2dab120a94c2 | 219 | #pragma section="HEAP" |
mbed_official | 80:2dab120a94c2 | 220 | #define HEAP_START (void *)__section_begin("HEAP") |
mbed_official | 80:2dab120a94c2 | 221 | #endif |
mbed_official | 80:2dab120a94c2 | 222 | |
mbed_official | 80:2dab120a94c2 | 223 | void set_main_stack(void) { |
mbed_official | 80:2dab120a94c2 | 224 | // That is the bottom of the main stack block: no collision detection |
mbed_official | 80:2dab120a94c2 | 225 | os_thread_def_main.stack_pointer = HEAP_START; |
mbed_official | 80:2dab120a94c2 | 226 | |
mbed_official | 80:2dab120a94c2 | 227 | // Leave OS_SCHEDULERSTKSIZE words for the scheduler and interrupts |
mbed_official | 80:2dab120a94c2 | 228 | os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)HEAP_START) - (OS_SCHEDULERSTKSIZE * 4); |
mbed_official | 80:2dab120a94c2 | 229 | } |
mbed_official | 80:2dab120a94c2 | 230 | |
mbed_official | 80:2dab120a94c2 | 231 | #if defined (__CC_ARM) |
mbed_official | 80:2dab120a94c2 | 232 | #ifdef __MICROLIB |
mbed_official | 116:0788b1a76461 | 233 | |
mbed_official | 116:0788b1a76461 | 234 | int main(void); |
mbed_official | 80:2dab120a94c2 | 235 | void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF"))); |
mbed_official | 116:0788b1a76461 | 236 | void $Super$$__cpp_initialize__aeabi_(void); |
mbed_official | 116:0788b1a76461 | 237 | |
mbed_official | 80:2dab120a94c2 | 238 | void _main_init (void) { |
mbed_official | 80:2dab120a94c2 | 239 | osKernelInitialize(); |
mbed_official | 80:2dab120a94c2 | 240 | set_main_stack(); |
mbed_official | 80:2dab120a94c2 | 241 | osThreadCreate(&os_thread_def_main, NULL); |
mbed_official | 80:2dab120a94c2 | 242 | osKernelStart(); |
mbed_official | 80:2dab120a94c2 | 243 | for (;;); |
mbed_official | 80:2dab120a94c2 | 244 | } |
mbed_official | 116:0788b1a76461 | 245 | |
mbed_official | 116:0788b1a76461 | 246 | void $Sub$$__cpp_initialize__aeabi_(void) |
mbed_official | 116:0788b1a76461 | 247 | { |
mbed_official | 116:0788b1a76461 | 248 | // this should invoke C++ initializers prior _main_init, we keep this empty and |
mbed_official | 116:0788b1a76461 | 249 | // invoke them after _main_init (=starts RTX kernel) |
mbed_official | 116:0788b1a76461 | 250 | } |
mbed_official | 116:0788b1a76461 | 251 | |
mbed_official | 116:0788b1a76461 | 252 | void pre_main() |
mbed_official | 116:0788b1a76461 | 253 | { |
mbed_official | 116:0788b1a76461 | 254 | $Super$$__cpp_initialize__aeabi_(); |
mbed_official | 116:0788b1a76461 | 255 | main(); |
mbed_official | 116:0788b1a76461 | 256 | } |
mbed_official | 116:0788b1a76461 | 257 | |
mbed_official | 80:2dab120a94c2 | 258 | #else |
mbed_official | 80:2dab120a94c2 | 259 | |
mbed_official | 116:0788b1a76461 | 260 | void * armcc_heap_base; |
mbed_official | 116:0788b1a76461 | 261 | void * armcc_heap_top; |
mbed_official | 116:0788b1a76461 | 262 | |
mbed_official | 116:0788b1a76461 | 263 | __asm void pre_main (void) |
mbed_official | 116:0788b1a76461 | 264 | { |
mbed_official | 116:0788b1a76461 | 265 | IMPORT __rt_lib_init |
mbed_official | 116:0788b1a76461 | 266 | IMPORT main |
mbed_official | 116:0788b1a76461 | 267 | IMPORT armcc_heap_base |
mbed_official | 116:0788b1a76461 | 268 | IMPORT armcc_heap_top |
mbed_official | 116:0788b1a76461 | 269 | |
mbed_official | 116:0788b1a76461 | 270 | LDR R0,=armcc_heap_base |
mbed_official | 116:0788b1a76461 | 271 | LDR R1,=armcc_heap_top |
mbed_official | 116:0788b1a76461 | 272 | LDR R0,[R0] |
mbed_official | 116:0788b1a76461 | 273 | LDR R1,[R1] |
mbed_official | 116:0788b1a76461 | 274 | /* Save link register (keep 8 byte alignment with dummy R4) */ |
mbed_official | 116:0788b1a76461 | 275 | PUSH {R4, LR} |
mbed_official | 116:0788b1a76461 | 276 | BL __rt_lib_init |
mbed_official | 116:0788b1a76461 | 277 | BL main |
mbed_official | 116:0788b1a76461 | 278 | /* Return to the thread destroy function. |
mbed_official | 116:0788b1a76461 | 279 | */ |
mbed_official | 116:0788b1a76461 | 280 | POP {R4, PC} |
mbed_official | 116:0788b1a76461 | 281 | ALIGN |
mbed_official | 116:0788b1a76461 | 282 | } |
mbed_official | 116:0788b1a76461 | 283 | |
mbed_official | 80:2dab120a94c2 | 284 | /* The single memory model is checking for stack collision at run time, verifing |
mbed_official | 80:2dab120a94c2 | 285 | that the heap pointer is underneath the stack pointer. |
mbed_official | 80:2dab120a94c2 | 286 | |
mbed_official | 80:2dab120a94c2 | 287 | With the RTOS there is not only one stack above the heap, there are multiple |
mbed_official | 80:2dab120a94c2 | 288 | stacks and some of them are underneath the heap pointer. |
mbed_official | 80:2dab120a94c2 | 289 | */ |
mbed_official | 80:2dab120a94c2 | 290 | #pragma import(__use_two_region_memory) |
mbed_official | 80:2dab120a94c2 | 291 | |
mbed_official | 80:2dab120a94c2 | 292 | __asm void __rt_entry (void) { |
mbed_official | 80:2dab120a94c2 | 293 | |
mbed_official | 80:2dab120a94c2 | 294 | IMPORT __user_setup_stackheap |
mbed_official | 116:0788b1a76461 | 295 | IMPORT armcc_heap_base |
mbed_official | 116:0788b1a76461 | 296 | IMPORT armcc_heap_top |
mbed_official | 80:2dab120a94c2 | 297 | IMPORT os_thread_def_main |
mbed_official | 80:2dab120a94c2 | 298 | IMPORT osKernelInitialize |
mbed_official | 80:2dab120a94c2 | 299 | IMPORT set_main_stack |
mbed_official | 80:2dab120a94c2 | 300 | IMPORT osKernelStart |
mbed_official | 80:2dab120a94c2 | 301 | IMPORT osThreadCreate |
mbed_official | 80:2dab120a94c2 | 302 | |
mbed_official | 116:0788b1a76461 | 303 | /* __user_setup_stackheap returns: |
mbed_official | 116:0788b1a76461 | 304 | * - Heap base in r0 (if the program uses the heap). |
mbed_official | 116:0788b1a76461 | 305 | * - Stack base in sp. |
mbed_official | 116:0788b1a76461 | 306 | * - Heap limit in r2 (if the program uses the heap and uses two-region memory). |
mbed_official | 116:0788b1a76461 | 307 | * |
mbed_official | 116:0788b1a76461 | 308 | * More info can be found in: |
mbed_official | 116:0788b1a76461 | 309 | * ARM Compiler ARM C and C++ Libraries and Floating-Point Support User Guide |
mbed_official | 116:0788b1a76461 | 310 | */ |
mbed_official | 80:2dab120a94c2 | 311 | BL __user_setup_stackheap |
mbed_official | 116:0788b1a76461 | 312 | LDR R3,=armcc_heap_base |
mbed_official | 116:0788b1a76461 | 313 | LDR R4,=armcc_heap_top |
mbed_official | 116:0788b1a76461 | 314 | STR R0,[R3] |
mbed_official | 116:0788b1a76461 | 315 | STR R2,[R4] |
mbed_official | 80:2dab120a94c2 | 316 | BL osKernelInitialize |
mbed_official | 80:2dab120a94c2 | 317 | BL set_main_stack |
mbed_official | 80:2dab120a94c2 | 318 | LDR R0,=os_thread_def_main |
mbed_official | 80:2dab120a94c2 | 319 | MOVS R1,#0 |
mbed_official | 80:2dab120a94c2 | 320 | BL osThreadCreate |
mbed_official | 80:2dab120a94c2 | 321 | BL osKernelStart |
mbed_official | 116:0788b1a76461 | 322 | /* osKernelStart should not return */ |
mbed_official | 116:0788b1a76461 | 323 | B . |
mbed_official | 80:2dab120a94c2 | 324 | |
mbed_official | 80:2dab120a94c2 | 325 | ALIGN |
mbed_official | 80:2dab120a94c2 | 326 | } |
mbed_official | 116:0788b1a76461 | 327 | |
mbed_official | 80:2dab120a94c2 | 328 | #endif |
mbed_official | 80:2dab120a94c2 | 329 | |
mbed_official | 80:2dab120a94c2 | 330 | #elif defined (__GNUC__) |
mbed_official | 80:2dab120a94c2 | 331 | |
mbed_official | 116:0788b1a76461 | 332 | extern void __libc_fini_array(void); |
mbed_official | 80:2dab120a94c2 | 333 | extern void __libc_init_array (void); |
mbed_official | 116:0788b1a76461 | 334 | extern int main(int argc, char **argv); |
mbed_official | 80:2dab120a94c2 | 335 | |
mbed_official | 116:0788b1a76461 | 336 | void pre_main(void) { |
mbed_official | 116:0788b1a76461 | 337 | atexit(__libc_fini_array); |
mbed_official | 116:0788b1a76461 | 338 | __libc_init_array(); |
mbed_official | 116:0788b1a76461 | 339 | main(0, NULL); |
mbed_official | 80:2dab120a94c2 | 340 | } |
mbed_official | 80:2dab120a94c2 | 341 | |
mbed_official | 80:2dab120a94c2 | 342 | __attribute__((naked)) void software_init_hook (void) { |
mbed_official | 80:2dab120a94c2 | 343 | __asm ( |
mbed_official | 80:2dab120a94c2 | 344 | ".syntax unified\n" |
mbed_official | 80:2dab120a94c2 | 345 | ".thumb\n" |
mbed_official | 80:2dab120a94c2 | 346 | "bl osKernelInitialize\n" |
mbed_official | 80:2dab120a94c2 | 347 | "bl set_main_stack\n" |
mbed_official | 80:2dab120a94c2 | 348 | "ldr r0,=os_thread_def_main\n" |
mbed_official | 80:2dab120a94c2 | 349 | "movs r1,#0\n" |
mbed_official | 80:2dab120a94c2 | 350 | "bl osThreadCreate\n" |
mbed_official | 80:2dab120a94c2 | 351 | "bl osKernelStart\n" |
mbed_official | 116:0788b1a76461 | 352 | /* osKernelStart should not return */ |
mbed_official | 116:0788b1a76461 | 353 | "B .\n" |
mbed_official | 80:2dab120a94c2 | 354 | ); |
mbed_official | 80:2dab120a94c2 | 355 | } |
mbed_official | 80:2dab120a94c2 | 356 | |
mbed_official | 80:2dab120a94c2 | 357 | #elif defined (__ICCARM__) |
mbed_official | 80:2dab120a94c2 | 358 | |
mbed_official | 116:0788b1a76461 | 359 | extern void* __vector_table; |
mbed_official | 80:2dab120a94c2 | 360 | extern int __low_level_init(void); |
mbed_official | 80:2dab120a94c2 | 361 | extern void __iar_data_init3(void); |
mbed_official | 116:0788b1a76461 | 362 | extern __weak void __iar_init_core( void ); |
mbed_official | 116:0788b1a76461 | 363 | extern __weak void __iar_init_vfp( void ); |
mbed_official | 116:0788b1a76461 | 364 | extern void __iar_dynamic_initialization(void); |
mbed_official | 116:0788b1a76461 | 365 | extern void mbed_sdk_init(void); |
mbed_official | 80:2dab120a94c2 | 366 | extern void exit(int arg); |
mbed_official | 80:2dab120a94c2 | 367 | |
mbed_official | 116:0788b1a76461 | 368 | static uint8_t low_level_init_needed; |
mbed_official | 116:0788b1a76461 | 369 | |
mbed_official | 116:0788b1a76461 | 370 | void pre_main(void) { |
mbed_official | 116:0788b1a76461 | 371 | if (low_level_init_needed) { |
mbed_official | 116:0788b1a76461 | 372 | __iar_dynamic_initialization(); |
mbed_official | 116:0788b1a76461 | 373 | } |
mbed_official | 116:0788b1a76461 | 374 | main(); |
mbed_official | 116:0788b1a76461 | 375 | } |
mbed_official | 80:2dab120a94c2 | 376 | |
mbed_official | 116:0788b1a76461 | 377 | #pragma required=__vector_table |
mbed_official | 116:0788b1a76461 | 378 | void __iar_program_start( void ) |
mbed_official | 116:0788b1a76461 | 379 | { |
mbed_official | 116:0788b1a76461 | 380 | __iar_init_core(); |
mbed_official | 116:0788b1a76461 | 381 | __iar_init_vfp(); |
mbed_official | 116:0788b1a76461 | 382 | |
mbed_official | 116:0788b1a76461 | 383 | uint8_t low_level_init_needed_local; |
mbed_official | 116:0788b1a76461 | 384 | |
mbed_official | 116:0788b1a76461 | 385 | low_level_init_needed_local = __low_level_init(); |
mbed_official | 116:0788b1a76461 | 386 | if (low_level_init_needed_local) { |
mbed_official | 80:2dab120a94c2 | 387 | __iar_data_init3(); |
mbed_official | 116:0788b1a76461 | 388 | mbed_sdk_init(); |
mbed_official | 80:2dab120a94c2 | 389 | } |
mbed_official | 116:0788b1a76461 | 390 | /* Store in a global variable after RAM has been initialized */ |
mbed_official | 116:0788b1a76461 | 391 | low_level_init_needed = low_level_init_needed_local; |
mbed_official | 80:2dab120a94c2 | 392 | osKernelInitialize(); |
mbed_official | 80:2dab120a94c2 | 393 | set_main_stack(); |
mbed_official | 80:2dab120a94c2 | 394 | osThreadCreate(&os_thread_def_main, NULL); |
mbed_official | 116:0788b1a76461 | 395 | osKernelStart(); |
mbed_official | 116:0788b1a76461 | 396 | /* osKernelStart should not return */ |
mbed_official | 116:0788b1a76461 | 397 | while (1); |
mbed_official | 80:2dab120a94c2 | 398 | } |
mbed_official | 80:2dab120a94c2 | 399 | |
mbed_official | 80:2dab120a94c2 | 400 | #endif |
mbed_official | 80:2dab120a94c2 | 401 | |
mbed_official | 80:2dab120a94c2 | 402 | |
mbed_official | 80:2dab120a94c2 | 403 | /*---------------------------------------------------------------------------- |
mbed_official | 80:2dab120a94c2 | 404 | * end of file |
mbed_official | 80:2dab120a94c2 | 405 | *---------------------------------------------------------------------------*/ |
mbed_official | 80:2dab120a94c2 | 406 | |
mbed_official | 80:2dab120a94c2 | 407 |