Luca
Fork of mbed-rtos by
rtx/TARGET_CORTEX_M/RTX_CM_lib.h@112:53ace74b190c, 2016-05-05 (annotated)
- Committer:
- mbed_official
- Date:
- Thu May 05 20:45:13 2016 +0100
- Revision:
- 112:53ace74b190c
- Parent:
- 111:162b12aea5f2
- Child:
- 116:0788b1a76461
Synchronized with git revision 860fdd282b0dc3631a6c46b39442d4ab5343e534
Full URL: https://github.com/mbedmicro/mbed/commit/860fdd282b0dc3631a6c46b39442d4ab5343e534/
rtx update to v4.79
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 49:77c8e4604045 | 1 | /*---------------------------------------------------------------------------- |
mbed_official | 112:53ace74b190c | 2 | * CMSIS-RTOS - RTX |
mbed_official | 49:77c8e4604045 | 3 | *---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 4 | * Name: RTX_CM_LIB.H |
mbed_official | 49:77c8e4604045 | 5 | * Purpose: RTX Kernel System Configuration |
mbed_official | 112:53ace74b190c | 6 | * Rev.: V4.79 |
mbed_official | 49:77c8e4604045 | 7 | *---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 8 | * |
mbed_official | 112:53ace74b190c | 9 | * Copyright (c) 1999-2009 KEIL, 2009-2015 ARM Germany GmbH |
mbed_official | 49:77c8e4604045 | 10 | * All rights reserved. |
mbed_official | 49:77c8e4604045 | 11 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 49:77c8e4604045 | 12 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 49:77c8e4604045 | 13 | * - Redistributions of source code must retain the above copyright |
mbed_official | 49:77c8e4604045 | 14 | * notice, this list of conditions and the following disclaimer. |
mbed_official | 49:77c8e4604045 | 15 | * - Redistributions in binary form must reproduce the above copyright |
mbed_official | 49:77c8e4604045 | 16 | * notice, this list of conditions and the following disclaimer in the |
mbed_official | 49:77c8e4604045 | 17 | * documentation and/or other materials provided with the distribution. |
mbed_official | 49:77c8e4604045 | 18 | * - Neither the name of ARM nor the names of its contributors may be used |
mbed_official | 49:77c8e4604045 | 19 | * to endorse or promote products derived from this software without |
mbed_official | 49:77c8e4604045 | 20 | * specific prior written permission. |
mbed_official | 49:77c8e4604045 | 21 | * |
mbed_official | 49:77c8e4604045 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 49:77c8e4604045 | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 49:77c8e4604045 | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
mbed_official | 49:77c8e4604045 | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
mbed_official | 49:77c8e4604045 | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
mbed_official | 49:77c8e4604045 | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
mbed_official | 49:77c8e4604045 | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
mbed_official | 49:77c8e4604045 | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
mbed_official | 49:77c8e4604045 | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
mbed_official | 49:77c8e4604045 | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
mbed_official | 49:77c8e4604045 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 49:77c8e4604045 | 33 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 34 | #include "mbed_error.h" |
mbed_official | 49:77c8e4604045 | 35 | |
mbed_official | 49:77c8e4604045 | 36 | #if defined (__CC_ARM) |
mbed_official | 49:77c8e4604045 | 37 | #pragma O3 |
mbed_official | 49:77c8e4604045 | 38 | #define __USED __attribute__((used)) |
mbed_official | 49:77c8e4604045 | 39 | #elif defined (__GNUC__) |
mbed_official | 49:77c8e4604045 | 40 | #pragma GCC optimize ("O3") |
mbed_official | 49:77c8e4604045 | 41 | #define __USED __attribute__((used)) |
mbed_official | 49:77c8e4604045 | 42 | #elif defined (__ICCARM__) |
mbed_official | 49:77c8e4604045 | 43 | #define __USED __root |
mbed_official | 49:77c8e4604045 | 44 | #endif |
mbed_official | 49:77c8e4604045 | 45 | |
mbed_official | 49:77c8e4604045 | 46 | |
mbed_official | 49:77c8e4604045 | 47 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 48 | * Definitions |
mbed_official | 49:77c8e4604045 | 49 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 50 | |
mbed_official | 49:77c8e4604045 | 51 | #define _declare_box(pool,size,cnt) uint32_t pool[(((size)+3)/4)*(cnt) + 3] |
mbed_official | 49:77c8e4604045 | 52 | #define _declare_box8(pool,size,cnt) uint64_t pool[(((size)+7)/8)*(cnt) + 2] |
mbed_official | 49:77c8e4604045 | 53 | |
mbed_official | 112:53ace74b190c | 54 | #define OS_TCB_SIZE 52 |
mbed_official | 49:77c8e4604045 | 55 | #define OS_TMR_SIZE 8 |
mbed_official | 49:77c8e4604045 | 56 | |
mbed_official | 49:77c8e4604045 | 57 | #if defined (__CC_ARM) && !defined (__MICROLIB) |
mbed_official | 49:77c8e4604045 | 58 | |
mbed_official | 49:77c8e4604045 | 59 | typedef void *OS_ID; |
mbed_official | 49:77c8e4604045 | 60 | typedef uint32_t OS_TID; |
mbed_official | 112:53ace74b190c | 61 | typedef uint32_t OS_MUT[4]; |
mbed_official | 49:77c8e4604045 | 62 | typedef uint32_t OS_RESULT; |
mbed_official | 49:77c8e4604045 | 63 | |
mbed_official | 49:77c8e4604045 | 64 | #define runtask_id() rt_tsk_self() |
mbed_official | 49:77c8e4604045 | 65 | #define mutex_init(m) rt_mut_init(m) |
mbed_official | 112:53ace74b190c | 66 | #define mutex_wait(m) os_mut_wait(m,0xFFFFU) |
mbed_official | 49:77c8e4604045 | 67 | #define mutex_rel(m) os_mut_release(m) |
mbed_official | 49:77c8e4604045 | 68 | |
mbed_official | 112:53ace74b190c | 69 | extern uint8_t os_running; |
mbed_official | 49:77c8e4604045 | 70 | extern OS_TID rt_tsk_self (void); |
mbed_official | 49:77c8e4604045 | 71 | extern void rt_mut_init (OS_ID mutex); |
mbed_official | 49:77c8e4604045 | 72 | extern OS_RESULT rt_mut_release (OS_ID mutex); |
mbed_official | 49:77c8e4604045 | 73 | extern OS_RESULT rt_mut_wait (OS_ID mutex, uint16_t timeout); |
mbed_official | 49:77c8e4604045 | 74 | |
mbed_official | 49:77c8e4604045 | 75 | #define os_mut_wait(mutex,timeout) _os_mut_wait((uint32_t)rt_mut_wait,mutex,timeout) |
mbed_official | 49:77c8e4604045 | 76 | #define os_mut_release(mutex) _os_mut_release((uint32_t)rt_mut_release,mutex) |
mbed_official | 49:77c8e4604045 | 77 | |
mbed_official | 49:77c8e4604045 | 78 | OS_RESULT _os_mut_release (uint32_t p, OS_ID mutex) __svc_indirect(0); |
mbed_official | 49:77c8e4604045 | 79 | OS_RESULT _os_mut_wait (uint32_t p, OS_ID mutex, uint16_t timeout) __svc_indirect(0); |
mbed_official | 49:77c8e4604045 | 80 | |
mbed_official | 49:77c8e4604045 | 81 | #endif |
mbed_official | 49:77c8e4604045 | 82 | |
mbed_official | 49:77c8e4604045 | 83 | |
mbed_official | 49:77c8e4604045 | 84 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 85 | * Global Variables |
mbed_official | 49:77c8e4604045 | 86 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 87 | |
mbed_official | 112:53ace74b190c | 88 | #if (OS_TASKCNT == 0) |
mbed_official | 112:53ace74b190c | 89 | #error "Invalid number of concurrent running threads!" |
mbed_official | 112:53ace74b190c | 90 | #endif |
mbed_official | 112:53ace74b190c | 91 | |
mbed_official | 112:53ace74b190c | 92 | #if (OS_PRIVCNT >= OS_TASKCNT) |
mbed_official | 112:53ace74b190c | 93 | #error "Too many threads with user-provided stack size!" |
mbed_official | 112:53ace74b190c | 94 | #endif |
mbed_official | 112:53ace74b190c | 95 | |
mbed_official | 49:77c8e4604045 | 96 | #if (OS_TIMERS != 0) |
mbed_official | 49:77c8e4604045 | 97 | #define OS_TASK_CNT (OS_TASKCNT + 1) |
mbed_official | 112:53ace74b190c | 98 | #ifndef __MBED_CMSIS_RTOS_CM |
mbed_official | 112:53ace74b190c | 99 | #define OS_PRIV_CNT (OS_PRIVCNT + 2) |
mbed_official | 112:53ace74b190c | 100 | #define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE+OS_TIMERSTKSZ)) |
mbed_official | 112:53ace74b190c | 101 | #endif |
mbed_official | 49:77c8e4604045 | 102 | #else |
mbed_official | 49:77c8e4604045 | 103 | #define OS_TASK_CNT OS_TASKCNT |
mbed_official | 112:53ace74b190c | 104 | #ifndef __MBED_CMSIS_RTOS_CM |
mbed_official | 112:53ace74b190c | 105 | #define OS_PRIV_CNT (OS_PRIVCNT + 1) |
mbed_official | 112:53ace74b190c | 106 | #define OS_STACK_SZ (4*(OS_PRIVSTKSIZE+OS_MAINSTKSIZE)) |
mbed_official | 112:53ace74b190c | 107 | #endif |
mbed_official | 112:53ace74b190c | 108 | #endif |
mbed_official | 112:53ace74b190c | 109 | |
mbed_official | 112:53ace74b190c | 110 | #ifndef OS_STKINIT |
mbed_official | 112:53ace74b190c | 111 | #define OS_STKINIT 0 |
mbed_official | 49:77c8e4604045 | 112 | #endif |
mbed_official | 49:77c8e4604045 | 113 | |
mbed_official | 49:77c8e4604045 | 114 | uint16_t const os_maxtaskrun = OS_TASK_CNT; |
mbed_official | 112:53ace74b190c | 115 | #ifdef __MBED_CMSIS_RTOS_CM |
mbed_official | 112:53ace74b190c | 116 | uint32_t const os_stackinfo = (OS_STKINIT<<28) | (OS_STKCHECK<<24) | (OS_IDLESTKSIZE*4); |
mbed_official | 112:53ace74b190c | 117 | #else |
mbed_official | 112:53ace74b190c | 118 | uint32_t const os_stackinfo = (OS_STKINIT<<28) | (OS_STKCHECK<<24) | (OS_PRIV_CNT<<16) | (OS_STKSIZE*4); |
mbed_official | 112:53ace74b190c | 119 | #endif |
mbed_official | 49:77c8e4604045 | 120 | uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT; |
mbed_official | 112:53ace74b190c | 121 | uint32_t const os_tickfreq = OS_CLOCK; |
mbed_official | 112:53ace74b190c | 122 | uint16_t const os_tickus_i = OS_CLOCK/1000000; |
mbed_official | 112:53ace74b190c | 123 | uint16_t const os_tickus_f = (((uint64_t)(OS_CLOCK-1000000*(OS_CLOCK/1000000)))<<16)/1000000; |
mbed_official | 49:77c8e4604045 | 124 | uint32_t const os_trv = OS_TRV; |
mbed_official | 49:77c8e4604045 | 125 | uint8_t const os_flags = OS_RUNPRIV; |
mbed_official | 49:77c8e4604045 | 126 | |
mbed_official | 49:77c8e4604045 | 127 | /* Export following defines to uVision debugger. */ |
mbed_official | 112:53ace74b190c | 128 | __USED uint32_t const CMSIS_RTOS_API_Version = osCMSIS; |
mbed_official | 112:53ace74b190c | 129 | __USED uint32_t const CMSIS_RTOS_RTX_Version = osCMSIS_RTX; |
mbed_official | 49:77c8e4604045 | 130 | __USED uint32_t const os_clockrate = OS_TICK; |
mbed_official | 112:53ace74b190c | 131 | __USED uint32_t const os_timernum = 0U; |
mbed_official | 112:53ace74b190c | 132 | |
mbed_official | 112:53ace74b190c | 133 | /* Memory pool for TCB allocation */ |
mbed_official | 112:53ace74b190c | 134 | _declare_box (mp_tcb, OS_TCB_SIZE, OS_TASK_CNT); |
mbed_official | 112:53ace74b190c | 135 | uint16_t const mp_tcb_size = sizeof(mp_tcb); |
mbed_official | 49:77c8e4604045 | 136 | |
mbed_official | 112:53ace74b190c | 137 | #ifdef __MBED_CMSIS_RTOS_CM |
mbed_official | 112:53ace74b190c | 138 | /* Memory pool for os_idle_demon stack allocation. */ |
mbed_official | 112:53ace74b190c | 139 | _declare_box8 (mp_stk, OS_IDLESTKSIZE*4, 1); |
mbed_official | 112:53ace74b190c | 140 | uint32_t const mp_stk_size = sizeof(mp_stk); |
mbed_official | 112:53ace74b190c | 141 | #else |
mbed_official | 112:53ace74b190c | 142 | /* Memory pool for System stack allocation (+os_idle_demon). */ |
mbed_official | 112:53ace74b190c | 143 | _declare_box8 (mp_stk, OS_STKSIZE*4, OS_TASK_CNT-OS_PRIV_CNT+1); |
mbed_official | 112:53ace74b190c | 144 | uint32_t const mp_stk_size = sizeof(mp_stk); |
mbed_official | 112:53ace74b190c | 145 | |
mbed_official | 112:53ace74b190c | 146 | /* Memory pool for user specified stack allocation (+main, +timer) */ |
mbed_official | 112:53ace74b190c | 147 | uint64_t os_stack_mem[2+OS_PRIV_CNT+(OS_STACK_SZ/8)]; |
mbed_official | 112:53ace74b190c | 148 | uint32_t const os_stack_sz = sizeof(os_stack_mem); |
mbed_official | 112:53ace74b190c | 149 | #endif |
mbed_official | 49:77c8e4604045 | 150 | |
mbed_official | 49:77c8e4604045 | 151 | #ifndef OS_FIFOSZ |
mbed_official | 49:77c8e4604045 | 152 | #define OS_FIFOSZ 16 |
mbed_official | 49:77c8e4604045 | 153 | #endif |
mbed_official | 49:77c8e4604045 | 154 | |
mbed_official | 49:77c8e4604045 | 155 | /* Fifo Queue buffer for ISR requests.*/ |
mbed_official | 49:77c8e4604045 | 156 | uint32_t os_fifo[OS_FIFOSZ*2+1]; |
mbed_official | 49:77c8e4604045 | 157 | uint8_t const os_fifo_size = OS_FIFOSZ; |
mbed_official | 49:77c8e4604045 | 158 | |
mbed_official | 49:77c8e4604045 | 159 | /* An array of Active task pointers. */ |
mbed_official | 49:77c8e4604045 | 160 | void *os_active_TCB[OS_TASK_CNT]; |
mbed_official | 49:77c8e4604045 | 161 | |
mbed_official | 49:77c8e4604045 | 162 | /* User Timers Resources */ |
mbed_official | 49:77c8e4604045 | 163 | #if (OS_TIMERS != 0) |
mbed_official | 49:77c8e4604045 | 164 | extern void osTimerThread (void const *argument); |
mbed_official | 112:53ace74b190c | 165 | #ifdef __MBED_CMSIS_RTOS_CM |
mbed_official | 49:77c8e4604045 | 166 | osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ); |
mbed_official | 112:53ace74b190c | 167 | #else |
mbed_official | 112:53ace74b190c | 168 | osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 1, 4*OS_TIMERSTKSZ); |
mbed_official | 112:53ace74b190c | 169 | #endif |
mbed_official | 49:77c8e4604045 | 170 | osThreadId osThreadId_osTimerThread; |
mbed_official | 49:77c8e4604045 | 171 | osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *); |
mbed_official | 49:77c8e4604045 | 172 | osMessageQId osMessageQId_osTimerMessageQ; |
mbed_official | 49:77c8e4604045 | 173 | #else |
mbed_official | 49:77c8e4604045 | 174 | osThreadDef_t os_thread_def_osTimerThread = { NULL }; |
mbed_official | 49:77c8e4604045 | 175 | osThreadId osThreadId_osTimerThread; |
mbed_official | 112:53ace74b190c | 176 | osMessageQDef(osTimerMessageQ, 0U, void *); |
mbed_official | 49:77c8e4604045 | 177 | osMessageQId osMessageQId_osTimerMessageQ; |
mbed_official | 49:77c8e4604045 | 178 | #endif |
mbed_official | 49:77c8e4604045 | 179 | |
mbed_official | 112:53ace74b190c | 180 | /* Legacy RTX User Timers not used */ |
mbed_official | 112:53ace74b190c | 181 | uint32_t os_tmr = 0U; |
mbed_official | 112:53ace74b190c | 182 | uint32_t const *m_tmr = NULL; |
mbed_official | 112:53ace74b190c | 183 | uint16_t const mp_tmr_size = 0U; |
mbed_official | 112:53ace74b190c | 184 | |
mbed_official | 112:53ace74b190c | 185 | #if defined (__CC_ARM) && !defined (__MICROLIB) |
mbed_official | 112:53ace74b190c | 186 | /* A memory space for arm standard library. */ |
mbed_official | 112:53ace74b190c | 187 | static uint32_t std_libspace[OS_TASK_CNT][96/4]; |
mbed_official | 112:53ace74b190c | 188 | static OS_MUT std_libmutex[OS_MUTEXCNT]; |
mbed_official | 112:53ace74b190c | 189 | static uint32_t nr_mutex; |
mbed_official | 112:53ace74b190c | 190 | extern void *__libspace_start; |
mbed_official | 112:53ace74b190c | 191 | #endif |
mbed_official | 112:53ace74b190c | 192 | |
mbed_official | 49:77c8e4604045 | 193 | |
mbed_official | 49:77c8e4604045 | 194 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 195 | * RTX Optimizations (empty functions) |
mbed_official | 49:77c8e4604045 | 196 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 197 | |
mbed_official | 49:77c8e4604045 | 198 | #if OS_ROBIN == 0 |
mbed_official | 49:77c8e4604045 | 199 | void rt_init_robin (void) {;} |
mbed_official | 49:77c8e4604045 | 200 | void rt_chk_robin (void) {;} |
mbed_official | 49:77c8e4604045 | 201 | #endif |
mbed_official | 49:77c8e4604045 | 202 | |
mbed_official | 49:77c8e4604045 | 203 | #if OS_STKCHECK == 0 |
mbed_official | 49:77c8e4604045 | 204 | void rt_stk_check (void) {;} |
mbed_official | 49:77c8e4604045 | 205 | #endif |
mbed_official | 49:77c8e4604045 | 206 | |
mbed_official | 49:77c8e4604045 | 207 | |
mbed_official | 49:77c8e4604045 | 208 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 209 | * Standard Library multithreading interface |
mbed_official | 49:77c8e4604045 | 210 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 211 | |
mbed_official | 49:77c8e4604045 | 212 | #if defined (__CC_ARM) && !defined (__MICROLIB) |
mbed_official | 112:53ace74b190c | 213 | |
mbed_official | 112:53ace74b190c | 214 | /*--------------------------- __user_perthread_libspace ---------------------*/ |
mbed_official | 112:53ace74b190c | 215 | |
mbed_official | 112:53ace74b190c | 216 | void *__user_perthread_libspace (void) { |
mbed_official | 112:53ace74b190c | 217 | /* Provide a separate libspace for each task. */ |
mbed_official | 112:53ace74b190c | 218 | uint32_t idx; |
mbed_official | 49:77c8e4604045 | 219 | |
mbed_official | 112:53ace74b190c | 220 | idx = (os_running != 0U) ? runtask_id () : 0U; |
mbed_official | 112:53ace74b190c | 221 | if (idx == 0U) { |
mbed_official | 112:53ace74b190c | 222 | /* RTX not running yet. */ |
mbed_official | 112:53ace74b190c | 223 | return (&__libspace_start); |
mbed_official | 112:53ace74b190c | 224 | } |
mbed_official | 112:53ace74b190c | 225 | return ((void *)&std_libspace[idx-1]); |
mbed_official | 112:53ace74b190c | 226 | } |
mbed_official | 112:53ace74b190c | 227 | |
mbed_official | 112:53ace74b190c | 228 | /*--------------------------- _mutex_initialize -----------------------------*/ |
mbed_official | 49:77c8e4604045 | 229 | |
mbed_official | 49:77c8e4604045 | 230 | int _mutex_initialize (OS_ID *mutex) { |
mbed_official | 49:77c8e4604045 | 231 | /* Allocate and initialize a system mutex. */ |
mbed_official | 49:77c8e4604045 | 232 | |
mbed_official | 49:77c8e4604045 | 233 | if (nr_mutex >= OS_MUTEXCNT) { |
mbed_official | 49:77c8e4604045 | 234 | /* If you are here, you need to increase the number OS_MUTEXCNT. */ |
mbed_official | 49:77c8e4604045 | 235 | error("Not enough stdlib mutexes\n"); |
mbed_official | 49:77c8e4604045 | 236 | } |
mbed_official | 49:77c8e4604045 | 237 | *mutex = &std_libmutex[nr_mutex++]; |
mbed_official | 49:77c8e4604045 | 238 | mutex_init (*mutex); |
mbed_official | 49:77c8e4604045 | 239 | return (1); |
mbed_official | 49:77c8e4604045 | 240 | } |
mbed_official | 49:77c8e4604045 | 241 | |
mbed_official | 49:77c8e4604045 | 242 | |
mbed_official | 49:77c8e4604045 | 243 | /*--------------------------- _mutex_acquire --------------------------------*/ |
mbed_official | 49:77c8e4604045 | 244 | |
mbed_official | 49:77c8e4604045 | 245 | __attribute__((used)) void _mutex_acquire (OS_ID *mutex) { |
mbed_official | 49:77c8e4604045 | 246 | /* Acquire a system mutex, lock stdlib resources. */ |
mbed_official | 112:53ace74b190c | 247 | if (os_running) { |
mbed_official | 49:77c8e4604045 | 248 | /* RTX running, acquire a mutex. */ |
mbed_official | 49:77c8e4604045 | 249 | mutex_wait (*mutex); |
mbed_official | 49:77c8e4604045 | 250 | } |
mbed_official | 49:77c8e4604045 | 251 | } |
mbed_official | 49:77c8e4604045 | 252 | |
mbed_official | 49:77c8e4604045 | 253 | |
mbed_official | 49:77c8e4604045 | 254 | /*--------------------------- _mutex_release --------------------------------*/ |
mbed_official | 49:77c8e4604045 | 255 | |
mbed_official | 49:77c8e4604045 | 256 | __attribute__((used)) void _mutex_release (OS_ID *mutex) { |
mbed_official | 49:77c8e4604045 | 257 | /* Release a system mutex, unlock stdlib resources. */ |
mbed_official | 112:53ace74b190c | 258 | if (os_running) { |
mbed_official | 49:77c8e4604045 | 259 | /* RTX running, release a mutex. */ |
mbed_official | 49:77c8e4604045 | 260 | mutex_rel (*mutex); |
mbed_official | 49:77c8e4604045 | 261 | } |
mbed_official | 49:77c8e4604045 | 262 | } |
mbed_official | 49:77c8e4604045 | 263 | |
mbed_official | 49:77c8e4604045 | 264 | #endif |
mbed_official | 49:77c8e4604045 | 265 | |
mbed_official | 49:77c8e4604045 | 266 | |
mbed_official | 49:77c8e4604045 | 267 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 268 | * RTX Startup |
mbed_official | 49:77c8e4604045 | 269 | *---------------------------------------------------------------------------*/ |
mbed_official | 49:77c8e4604045 | 270 | |
mbed_official | 49:77c8e4604045 | 271 | /* Main Thread definition */ |
mbed_official | 49:77c8e4604045 | 272 | extern int main (void); |
mbed_official | 112:53ace74b190c | 273 | osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 1U, 0U, NULL}; |
mbed_official | 49:77c8e4604045 | 274 | |
mbed_official | 49:77c8e4604045 | 275 | // This define should be probably moved to the CMSIS layer |
mbed_official | 49:77c8e4604045 | 276 | #if defined(TARGET_LPC1768) |
mbed_official | 49:77c8e4604045 | 277 | #define INITIAL_SP (0x10008000UL) |
mbed_official | 49:77c8e4604045 | 278 | |
mbed_official | 49:77c8e4604045 | 279 | #elif defined(TARGET_LPC11U24) |
mbed_official | 49:77c8e4604045 | 280 | #define INITIAL_SP (0x10002000UL) |
mbed_official | 49:77c8e4604045 | 281 | |
mbed_official | 49:77c8e4604045 | 282 | #elif defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501) || defined(TARGET_LPCCAPPUCCINO) |
mbed_official | 49:77c8e4604045 | 283 | #define INITIAL_SP (0x10002000UL) |
mbed_official | 49:77c8e4604045 | 284 | |
mbed_official | 49:77c8e4604045 | 285 | #elif defined(TARGET_LPC1114) |
mbed_official | 49:77c8e4604045 | 286 | #define INITIAL_SP (0x10001000UL) |
mbed_official | 49:77c8e4604045 | 287 | |
mbed_official | 49:77c8e4604045 | 288 | #elif defined(TARGET_LPC812) |
mbed_official | 49:77c8e4604045 | 289 | #define INITIAL_SP (0x10001000UL) |
mbed_official | 49:77c8e4604045 | 290 | |
mbed_official | 81:e45e4ac7c3c8 | 291 | #elif defined(TARGET_LPC824) || defined(TARGET_SSCI824) |
mbed_official | 49:77c8e4604045 | 292 | #define INITIAL_SP (0x10002000UL) |
mbed_official | 49:77c8e4604045 | 293 | |
mbed_official | 49:77c8e4604045 | 294 | #elif defined(TARGET_KL25Z) |
mbed_official | 49:77c8e4604045 | 295 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 49:77c8e4604045 | 296 | |
mbed_official | 88:a21475017ae2 | 297 | #elif defined(TARGET_KL26Z) |
mbed_official | 88:a21475017ae2 | 298 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 88:a21475017ae2 | 299 | |
mbed_official | 111:162b12aea5f2 | 300 | #elif defined(TARGET_KL27Z) |
mbed_official | 111:162b12aea5f2 | 301 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 111:162b12aea5f2 | 302 | |
mbed_official | 49:77c8e4604045 | 303 | #elif defined(TARGET_K64F) |
mbed_official | 49:77c8e4604045 | 304 | #define INITIAL_SP (0x20030000UL) |
mbed_official | 49:77c8e4604045 | 305 | |
mbed_official | 52:02f5cf381388 | 306 | #elif defined(TARGET_K22F) |
mbed_official | 52:02f5cf381388 | 307 | #define INITIAL_SP (0x20010000UL) |
mbed_official | 52:02f5cf381388 | 308 | |
mbed_official | 49:77c8e4604045 | 309 | #elif defined(TARGET_KL46Z) |
mbed_official | 49:77c8e4604045 | 310 | #define INITIAL_SP (0x20006000UL) |
mbed_official | 49:77c8e4604045 | 311 | |
mbed_official | 49:77c8e4604045 | 312 | #elif defined(TARGET_KL43Z) |
mbed_official | 49:77c8e4604045 | 313 | #define INITIAL_SP (0x20006000UL) |
mbed_official | 49:77c8e4604045 | 314 | |
mbed_official | 49:77c8e4604045 | 315 | #elif defined(TARGET_KL05Z) |
mbed_official | 49:77c8e4604045 | 316 | #define INITIAL_SP (0x20000C00UL) |
mbed_official | 49:77c8e4604045 | 317 | |
mbed_official | 64:ab4200083b07 | 318 | #elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) |
mbed_official | 49:77c8e4604045 | 319 | #define INITIAL_SP (0x10010000UL) |
mbed_official | 49:77c8e4604045 | 320 | |
mbed_official | 63:5448826aa700 | 321 | #elif defined(TARGET_LPC4330) |
mbed_official | 63:5448826aa700 | 322 | #define INITIAL_SP (0x10008000UL) |
mbed_official | 63:5448826aa700 | 323 | |
mbed_official | 49:77c8e4604045 | 324 | #elif defined(TARGET_LPC4337) |
mbed_official | 49:77c8e4604045 | 325 | #define INITIAL_SP (0x10008000UL) |
mbed_official | 49:77c8e4604045 | 326 | |
mbed_official | 49:77c8e4604045 | 327 | #elif defined(TARGET_LPC1347) |
mbed_official | 49:77c8e4604045 | 328 | #define INITIAL_SP (0x10002000UL) |
mbed_official | 49:77c8e4604045 | 329 | |
mbed_official | 49:77c8e4604045 | 330 | #elif defined(TARGET_STM32F100RB) || defined(TARGET_STM32F051R8) |
mbed_official | 49:77c8e4604045 | 331 | #define INITIAL_SP (0x20002000UL) |
mbed_official | 49:77c8e4604045 | 332 | |
mbed_official | 49:77c8e4604045 | 333 | #elif defined(TARGET_DISCO_F303VC) |
mbed_official | 49:77c8e4604045 | 334 | #define INITIAL_SP (0x2000A000UL) |
mbed_official | 49:77c8e4604045 | 335 | |
mbed_official | 49:77c8e4604045 | 336 | #elif defined(TARGET_STM32F407) || defined(TARGET_F407VG) |
mbed_official | 49:77c8e4604045 | 337 | #define INITIAL_SP (0x20020000UL) |
mbed_official | 49:77c8e4604045 | 338 | |
mbed_official | 49:77c8e4604045 | 339 | #elif defined(TARGET_STM32F401RE) |
mbed_official | 49:77c8e4604045 | 340 | #define INITIAL_SP (0x20018000UL) |
mbed_official | 49:77c8e4604045 | 341 | |
mbed_official | 49:77c8e4604045 | 342 | #elif defined(TARGET_LPC1549) |
mbed_official | 49:77c8e4604045 | 343 | #define INITIAL_SP (0x02009000UL) |
mbed_official | 49:77c8e4604045 | 344 | |
mbed_official | 49:77c8e4604045 | 345 | #elif defined(TARGET_LPC11U68) |
mbed_official | 89:5aed8bae1001 | 346 | #define INITIAL_SP (0x10008000UL) |
mbed_official | 49:77c8e4604045 | 347 | |
mbed_official | 49:77c8e4604045 | 348 | #elif defined(TARGET_STM32F411RE) |
mbed_official | 49:77c8e4604045 | 349 | #define INITIAL_SP (0x20020000UL) |
mbed_official | 49:77c8e4604045 | 350 | |
mbed_official | 97:6c35e082773a | 351 | #elif defined(TARGET_STM32F410RB) |
mbed_official | 97:6c35e082773a | 352 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 97:6c35e082773a | 353 | |
mbed_official | 106:dfc27975e193 | 354 | #elif defined(TARGET_STM32F103RB) || defined(TARGET_STM32L073RZ) |
mbed_official | 49:77c8e4604045 | 355 | #define INITIAL_SP (0x20005000UL) |
mbed_official | 49:77c8e4604045 | 356 | |
mbed_official | 49:77c8e4604045 | 357 | #elif defined(TARGET_STM32F302R8) |
mbed_official | 49:77c8e4604045 | 358 | #define INITIAL_SP (0x20004000UL) |
mbed_official | 49:77c8e4604045 | 359 | |
mbed_official | 49:77c8e4604045 | 360 | #elif defined(TARGET_STM32F334R8) |
mbed_official | 49:77c8e4604045 | 361 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 49:77c8e4604045 | 362 | |
mbed_official | 49:77c8e4604045 | 363 | #elif defined(TARGET_STM32F334C8) |
mbed_official | 49:77c8e4604045 | 364 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 49:77c8e4604045 | 365 | |
mbed_official | 50:64a5202c3676 | 366 | #elif defined(TARGET_STM32F405RG) |
mbed_official | 50:64a5202c3676 | 367 | #define INITIAL_SP (0x20020000UL) |
mbed_official | 50:64a5202c3676 | 368 | |
mbed_official | 57:430de2831ec7 | 369 | #elif defined(TARGET_STM32F429ZI) |
mbed_official | 57:430de2831ec7 | 370 | #define INITIAL_SP (0x20030000UL) |
mbed_official | 57:430de2831ec7 | 371 | |
mbed_official | 108:ac4f3830f9ff | 372 | #elif defined(TARGET_STM32L031K6) || defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8) |
mbed_official | 59:28712e303960 | 373 | #define INITIAL_SP (0x20002000UL) |
mbed_official | 59:28712e303960 | 374 | |
mbed_official | 59:28712e303960 | 375 | #elif defined(TARGET_STM32F072RB) |
mbed_official | 59:28712e303960 | 376 | #define INITIAL_SP (0x20004000UL) |
mbed_official | 59:28712e303960 | 377 | |
mbed_official | 59:28712e303960 | 378 | #elif defined(TARGET_STM32F091RC) |
mbed_official | 59:28712e303960 | 379 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 59:28712e303960 | 380 | |
mbed_official | 60:f4d3d8971bc3 | 381 | #elif defined(TARGET_STM32F401VC) |
mbed_official | 60:f4d3d8971bc3 | 382 | #define INITIAL_SP (0x20010000UL) |
mbed_official | 60:f4d3d8971bc3 | 383 | |
mbed_official | 68:d3d0e710b443 | 384 | #elif defined(TARGET_STM32F303RE) |
mbed_official | 68:d3d0e710b443 | 385 | #define INITIAL_SP (0x20010000UL) |
mbed_official | 68:d3d0e710b443 | 386 | |
mbed_official | 95:12552ef4e980 | 387 | #elif defined(TARGET_STM32F303K8) |
mbed_official | 95:12552ef4e980 | 388 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 95:12552ef4e980 | 389 | |
mbed_official | 105:b4c5542476ba | 390 | #elif (defined(TARGET_STM32F746NG) || defined(TARGET_STM32F746ZG)) |
mbed_official | 98:c825593ece39 | 391 | #define INITIAL_SP (0x20050000UL) |
mbed_official | 98:c825593ece39 | 392 | |
mbed_official | 73:34292fba723c | 393 | #elif defined(TARGET_MAX32610) || defined(TARGET_MAX32600) |
mbed_official | 71:570e569a5b59 | 394 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 71:570e569a5b59 | 395 | |
mbed_official | 74:899aee34da6a | 396 | #elif defined(TARGET_TEENSY3_1) |
mbed_official | 74:899aee34da6a | 397 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 74:899aee34da6a | 398 | |
mbed_official | 77:3516160e016b | 399 | #elif defined(TARGET_STM32L152RE) |
mbed_official | 77:3516160e016b | 400 | #define INITIAL_SP (0x20014000UL) |
mbed_official | 77:3516160e016b | 401 | |
mbed_official | 104:07314541bd12 | 402 | #elif defined(TARGET_NZ32_SC151) |
mbed_official | 78:2db19f47c2ba | 403 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 78:2db19f47c2ba | 404 | |
mbed_official | 108:ac4f3830f9ff | 405 | #elif (defined(TARGET_STM32F446RE) || defined(TARGET_STM32F446VE)) |
mbed_official | 79:c586ffeebfb4 | 406 | #define INITIAL_SP (0x20020000UL) |
mbed_official | 79:c586ffeebfb4 | 407 | |
mbed_official | 87:e695cd34556b | 408 | #elif defined(TARGET_STM32F070RB) || defined(TARGET_STM32F030R8) |
mbed_official | 87:e695cd34556b | 409 | #define INITIAL_SP (0x20002000UL) |
mbed_official | 87:e695cd34556b | 410 | |
mbed_official | 91:9d001ed5feec | 411 | #elif defined(TARGET_STM32L476VG) |
mbed_official | 91:9d001ed5feec | 412 | #define INITIAL_SP (0x20018000UL) |
mbed_official | 91:9d001ed5feec | 413 | |
mbed_official | 91:9d001ed5feec | 414 | #elif defined(TARGET_STM32L476RG) |
mbed_official | 91:9d001ed5feec | 415 | #define INITIAL_SP (0x20018000UL) |
mbed_official | 91:9d001ed5feec | 416 | |
mbed_official | 96:6d90423c236e | 417 | #elif defined(TARGET_STM32F469NI) |
mbed_official | 96:6d90423c236e | 418 | #define INITIAL_SP (0x20050000UL) |
mbed_official | 96:6d90423c236e | 419 | |
mbed_official | 99:79d2f32f753f | 420 | #elif defined(TARGET_STM32L152RC) |
mbed_official | 99:79d2f32f753f | 421 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 99:79d2f32f753f | 422 | |
mbed_official | 99:79d2f32f753f | 423 | |
mbed_official | 49:77c8e4604045 | 424 | #else |
mbed_official | 49:77c8e4604045 | 425 | #error "no target defined" |
mbed_official | 49:77c8e4604045 | 426 | |
mbed_official | 49:77c8e4604045 | 427 | #endif |
mbed_official | 49:77c8e4604045 | 428 | |
mbed_official | 49:77c8e4604045 | 429 | #ifdef __CC_ARM |
mbed_official | 62:444020d511f5 | 430 | extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[]; |
mbed_official | 49:77c8e4604045 | 431 | #define HEAP_START (Image$$RW_IRAM1$$ZI$$Limit) |
mbed_official | 49:77c8e4604045 | 432 | #elif defined(__GNUC__) |
mbed_official | 62:444020d511f5 | 433 | extern uint32_t __end__[]; |
mbed_official | 49:77c8e4604045 | 434 | #define HEAP_START (__end__) |
mbed_official | 53:c35dab33c427 | 435 | #elif defined(__ICCARM__) |
mbed_official | 53:c35dab33c427 | 436 | #pragma section="HEAP" |
mbed_official | 53:c35dab33c427 | 437 | #define HEAP_START (void *)__section_begin("HEAP") |
mbed_official | 49:77c8e4604045 | 438 | #endif |
mbed_official | 49:77c8e4604045 | 439 | |
mbed_official | 49:77c8e4604045 | 440 | void set_main_stack(void) { |
mbed_official | 49:77c8e4604045 | 441 | // That is the bottom of the main stack block: no collision detection |
mbed_official | 49:77c8e4604045 | 442 | os_thread_def_main.stack_pointer = HEAP_START; |
mbed_official | 49:77c8e4604045 | 443 | |
mbed_official | 112:53ace74b190c | 444 | // Leave OS_MAINSTKSIZE words for the scheduler and interrupts |
mbed_official | 112:53ace74b190c | 445 | os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)HEAP_START) - (OS_MAINSTKSIZE * 4); |
mbed_official | 49:77c8e4604045 | 446 | } |
mbed_official | 49:77c8e4604045 | 447 | |
mbed_official | 49:77c8e4604045 | 448 | #if defined (__CC_ARM) |
mbed_official | 112:53ace74b190c | 449 | |
mbed_official | 49:77c8e4604045 | 450 | #ifdef __MICROLIB |
mbed_official | 49:77c8e4604045 | 451 | void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF"))); |
mbed_official | 49:77c8e4604045 | 452 | void _main_init (void) { |
mbed_official | 49:77c8e4604045 | 453 | osKernelInitialize(); |
mbed_official | 112:53ace74b190c | 454 | #ifdef __MBED_CMSIS_RTOS_CM |
mbed_official | 49:77c8e4604045 | 455 | set_main_stack(); |
mbed_official | 112:53ace74b190c | 456 | #endif |
mbed_official | 49:77c8e4604045 | 457 | osThreadCreate(&os_thread_def_main, NULL); |
mbed_official | 49:77c8e4604045 | 458 | osKernelStart(); |
mbed_official | 49:77c8e4604045 | 459 | for (;;); |
mbed_official | 49:77c8e4604045 | 460 | } |
mbed_official | 49:77c8e4604045 | 461 | #else |
mbed_official | 49:77c8e4604045 | 462 | |
mbed_official | 49:77c8e4604045 | 463 | /* The single memory model is checking for stack collision at run time, verifing |
mbed_official | 49:77c8e4604045 | 464 | that the heap pointer is underneath the stack pointer. |
mbed_official | 49:77c8e4604045 | 465 | |
mbed_official | 49:77c8e4604045 | 466 | With the RTOS there is not only one stack above the heap, there are multiple |
mbed_official | 49:77c8e4604045 | 467 | stacks and some of them are underneath the heap pointer. |
mbed_official | 49:77c8e4604045 | 468 | */ |
mbed_official | 49:77c8e4604045 | 469 | #pragma import(__use_two_region_memory) |
mbed_official | 49:77c8e4604045 | 470 | |
mbed_official | 49:77c8e4604045 | 471 | __asm void __rt_entry (void) { |
mbed_official | 49:77c8e4604045 | 472 | |
mbed_official | 49:77c8e4604045 | 473 | IMPORT __user_setup_stackheap |
mbed_official | 49:77c8e4604045 | 474 | IMPORT __rt_lib_init |
mbed_official | 49:77c8e4604045 | 475 | IMPORT os_thread_def_main |
mbed_official | 49:77c8e4604045 | 476 | IMPORT osKernelInitialize |
mbed_official | 112:53ace74b190c | 477 | #ifdef __MBED_CMSIS_RTOS_CM |
mbed_official | 49:77c8e4604045 | 478 | IMPORT set_main_stack |
mbed_official | 112:53ace74b190c | 479 | #endif |
mbed_official | 49:77c8e4604045 | 480 | IMPORT osKernelStart |
mbed_official | 49:77c8e4604045 | 481 | IMPORT osThreadCreate |
mbed_official | 49:77c8e4604045 | 482 | IMPORT exit |
mbed_official | 49:77c8e4604045 | 483 | |
mbed_official | 49:77c8e4604045 | 484 | BL __user_setup_stackheap |
mbed_official | 49:77c8e4604045 | 485 | MOV R1,R2 |
mbed_official | 49:77c8e4604045 | 486 | BL __rt_lib_init |
mbed_official | 49:77c8e4604045 | 487 | BL osKernelInitialize |
mbed_official | 112:53ace74b190c | 488 | #ifdef __MBED_CMSIS_RTOS_CM |
mbed_official | 49:77c8e4604045 | 489 | BL set_main_stack |
mbed_official | 112:53ace74b190c | 490 | #endif |
mbed_official | 49:77c8e4604045 | 491 | LDR R0,=os_thread_def_main |
mbed_official | 49:77c8e4604045 | 492 | MOVS R1,#0 |
mbed_official | 49:77c8e4604045 | 493 | BL osThreadCreate |
mbed_official | 49:77c8e4604045 | 494 | BL osKernelStart |
mbed_official | 49:77c8e4604045 | 495 | BL exit |
mbed_official | 49:77c8e4604045 | 496 | |
mbed_official | 49:77c8e4604045 | 497 | ALIGN |
mbed_official | 49:77c8e4604045 | 498 | } |
mbed_official | 112:53ace74b190c | 499 | |
mbed_official | 49:77c8e4604045 | 500 | #endif |
mbed_official | 49:77c8e4604045 | 501 | |
mbed_official | 49:77c8e4604045 | 502 | #elif defined (__GNUC__) |
mbed_official | 49:77c8e4604045 | 503 | |
mbed_official | 49:77c8e4604045 | 504 | #ifdef __CS3__ |
mbed_official | 49:77c8e4604045 | 505 | |
mbed_official | 49:77c8e4604045 | 506 | /* CS3 start_c routine. |
mbed_official | 49:77c8e4604045 | 507 | * |
mbed_official | 49:77c8e4604045 | 508 | * Copyright (c) 2006, 2007 CodeSourcery Inc |
mbed_official | 49:77c8e4604045 | 509 | * |
mbed_official | 49:77c8e4604045 | 510 | * The authors hereby grant permission to use, copy, modify, distribute, |
mbed_official | 49:77c8e4604045 | 511 | * and license this software and its documentation for any purpose, provided |
mbed_official | 49:77c8e4604045 | 512 | * that existing copyright notices are retained in all copies and that this |
mbed_official | 49:77c8e4604045 | 513 | * notice is included verbatim in any distributions. No written agreement, |
mbed_official | 49:77c8e4604045 | 514 | * license, or royalty fee is required for any of the authorized uses. |
mbed_official | 49:77c8e4604045 | 515 | * Modifications to this software may be copyrighted by their authors |
mbed_official | 49:77c8e4604045 | 516 | * and need not follow the licensing terms described here, provided that |
mbed_official | 49:77c8e4604045 | 517 | * the new terms are clearly indicated on the first page of each file where |
mbed_official | 49:77c8e4604045 | 518 | * they apply. |
mbed_official | 49:77c8e4604045 | 519 | */ |
mbed_official | 49:77c8e4604045 | 520 | |
mbed_official | 49:77c8e4604045 | 521 | #include "cs3.h" |
mbed_official | 49:77c8e4604045 | 522 | |
mbed_official | 49:77c8e4604045 | 523 | extern void __libc_init_array (void); |
mbed_official | 49:77c8e4604045 | 524 | |
mbed_official | 49:77c8e4604045 | 525 | __attribute ((noreturn)) void __cs3_start_c (void){ |
mbed_official | 49:77c8e4604045 | 526 | unsigned regions = __cs3_region_num; |
mbed_official | 49:77c8e4604045 | 527 | const struct __cs3_region *rptr = __cs3_regions; |
mbed_official | 49:77c8e4604045 | 528 | |
mbed_official | 49:77c8e4604045 | 529 | /* Initialize memory */ |
mbed_official | 49:77c8e4604045 | 530 | for (regions = __cs3_region_num, rptr = __cs3_regions; regions--; rptr++) { |
mbed_official | 49:77c8e4604045 | 531 | long long *src = (long long *)rptr->init; |
mbed_official | 49:77c8e4604045 | 532 | long long *dst = (long long *)rptr->data; |
mbed_official | 49:77c8e4604045 | 533 | unsigned limit = rptr->init_size; |
mbed_official | 49:77c8e4604045 | 534 | unsigned count; |
mbed_official | 49:77c8e4604045 | 535 | |
mbed_official | 49:77c8e4604045 | 536 | if (src != dst) |
mbed_official | 49:77c8e4604045 | 537 | for (count = 0; count != limit; count += sizeof (long long)) |
mbed_official | 49:77c8e4604045 | 538 | *dst++ = *src++; |
mbed_official | 49:77c8e4604045 | 539 | else |
mbed_official | 49:77c8e4604045 | 540 | dst = (long long *)((char *)dst + limit); |
mbed_official | 49:77c8e4604045 | 541 | limit = rptr->zero_size; |
mbed_official | 49:77c8e4604045 | 542 | for (count = 0; count != limit; count += sizeof (long long)) |
mbed_official | 49:77c8e4604045 | 543 | *dst++ = 0; |
mbed_official | 49:77c8e4604045 | 544 | } |
mbed_official | 49:77c8e4604045 | 545 | |
mbed_official | 49:77c8e4604045 | 546 | /* Run initializers. */ |
mbed_official | 49:77c8e4604045 | 547 | __libc_init_array (); |
mbed_official | 49:77c8e4604045 | 548 | |
mbed_official | 49:77c8e4604045 | 549 | osKernelInitialize(); |
mbed_official | 112:53ace74b190c | 550 | #ifdef __MBED_CMSIS_RTOS_CM |
mbed_official | 49:77c8e4604045 | 551 | set_main_stack(); |
mbed_official | 112:53ace74b190c | 552 | #endif |
mbed_official | 49:77c8e4604045 | 553 | osThreadCreate(&os_thread_def_main, NULL); |
mbed_official | 49:77c8e4604045 | 554 | osKernelStart(); |
mbed_official | 49:77c8e4604045 | 555 | for (;;); |
mbed_official | 49:77c8e4604045 | 556 | } |
mbed_official | 49:77c8e4604045 | 557 | |
mbed_official | 49:77c8e4604045 | 558 | #else |
mbed_official | 49:77c8e4604045 | 559 | |
mbed_official | 49:77c8e4604045 | 560 | __attribute__((naked)) void software_init_hook (void) { |
mbed_official | 49:77c8e4604045 | 561 | __asm ( |
mbed_official | 49:77c8e4604045 | 562 | ".syntax unified\n" |
mbed_official | 49:77c8e4604045 | 563 | ".thumb\n" |
mbed_official | 49:77c8e4604045 | 564 | "movs r0,#0\n" |
mbed_official | 49:77c8e4604045 | 565 | "movs r1,#0\n" |
mbed_official | 49:77c8e4604045 | 566 | "mov r4,r0\n" |
mbed_official | 49:77c8e4604045 | 567 | "mov r5,r1\n" |
mbed_official | 49:77c8e4604045 | 568 | "ldr r0,= __libc_fini_array\n" |
mbed_official | 49:77c8e4604045 | 569 | "bl atexit\n" |
mbed_official | 49:77c8e4604045 | 570 | "bl __libc_init_array\n" |
mbed_official | 49:77c8e4604045 | 571 | "mov r0,r4\n" |
mbed_official | 49:77c8e4604045 | 572 | "mov r1,r5\n" |
mbed_official | 49:77c8e4604045 | 573 | "bl osKernelInitialize\n" |
mbed_official | 112:53ace74b190c | 574 | #ifdef __MBED_CMSIS_RTOS_CM |
mbed_official | 49:77c8e4604045 | 575 | "bl set_main_stack\n" |
mbed_official | 112:53ace74b190c | 576 | #endif |
mbed_official | 49:77c8e4604045 | 577 | "ldr r0,=os_thread_def_main\n" |
mbed_official | 49:77c8e4604045 | 578 | "movs r1,#0\n" |
mbed_official | 49:77c8e4604045 | 579 | "bl osThreadCreate\n" |
mbed_official | 49:77c8e4604045 | 580 | "bl osKernelStart\n" |
mbed_official | 49:77c8e4604045 | 581 | "bl exit\n" |
mbed_official | 49:77c8e4604045 | 582 | ); |
mbed_official | 49:77c8e4604045 | 583 | } |
mbed_official | 49:77c8e4604045 | 584 | |
mbed_official | 49:77c8e4604045 | 585 | #endif |
mbed_official | 49:77c8e4604045 | 586 | |
mbed_official | 49:77c8e4604045 | 587 | #elif defined (__ICCARM__) |
mbed_official | 49:77c8e4604045 | 588 | |
mbed_official | 56:2b2a7cc13e28 | 589 | extern void* __vector_table; |
mbed_official | 49:77c8e4604045 | 590 | extern int __low_level_init(void); |
mbed_official | 49:77c8e4604045 | 591 | extern void __iar_data_init3(void); |
mbed_official | 56:2b2a7cc13e28 | 592 | extern __weak void __iar_init_core( void ); |
mbed_official | 56:2b2a7cc13e28 | 593 | extern __weak void __iar_init_vfp( void ); |
mbed_official | 56:2b2a7cc13e28 | 594 | extern void __iar_dynamic_initialization(void); |
mbed_official | 56:2b2a7cc13e28 | 595 | extern void mbed_sdk_init(void); |
mbed_official | 49:77c8e4604045 | 596 | extern void exit(int arg); |
mbed_official | 49:77c8e4604045 | 597 | |
mbed_official | 56:2b2a7cc13e28 | 598 | #pragma required=__vector_table |
mbed_official | 56:2b2a7cc13e28 | 599 | void __iar_program_start( void ) |
mbed_official | 56:2b2a7cc13e28 | 600 | { |
mbed_official | 112:53ace74b190c | 601 | #ifdef __MBED_CMSIS_RTOS_CM |
mbed_official | 56:2b2a7cc13e28 | 602 | __iar_init_core(); |
mbed_official | 56:2b2a7cc13e28 | 603 | __iar_init_vfp(); |
mbed_official | 56:2b2a7cc13e28 | 604 | |
mbed_official | 49:77c8e4604045 | 605 | int a; |
mbed_official | 49:77c8e4604045 | 606 | |
mbed_official | 49:77c8e4604045 | 607 | if (__low_level_init() != 0) { |
mbed_official | 49:77c8e4604045 | 608 | __iar_data_init3(); |
mbed_official | 56:2b2a7cc13e28 | 609 | mbed_sdk_init(); |
mbed_official | 68:d3d0e710b443 | 610 | __iar_dynamic_initialization(); |
mbed_official | 68:d3d0e710b443 | 611 | } |
mbed_official | 112:53ace74b190c | 612 | #endif |
mbed_official | 49:77c8e4604045 | 613 | osKernelInitialize(); |
mbed_official | 112:53ace74b190c | 614 | #ifdef __MBED_CMSIS_RTOS_CM |
mbed_official | 53:c35dab33c427 | 615 | set_main_stack(); |
mbed_official | 112:53ace74b190c | 616 | #endif |
mbed_official | 49:77c8e4604045 | 617 | osThreadCreate(&os_thread_def_main, NULL); |
mbed_official | 49:77c8e4604045 | 618 | a = osKernelStart(); |
mbed_official | 68:d3d0e710b443 | 619 | exit(a); |
mbed_official | 68:d3d0e710b443 | 620 | |
mbed_official | 49:77c8e4604045 | 621 | } |
mbed_official | 49:77c8e4604045 | 622 | |
mbed_official | 49:77c8e4604045 | 623 | #endif |
mbed_official | 49:77c8e4604045 | 624 | |
mbed_official | 49:77c8e4604045 | 625 | |
mbed_official | 49:77c8e4604045 | 626 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 627 | * end of file |
mbed_official | 49:77c8e4604045 | 628 | *---------------------------------------------------------------------------*/ |