Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.

Dependents:   denki-yohou_b TestY201 Network-RTOS NTPClient_HelloWorld ... more

Deprecated

This is the mbed 2 rtos library. mbed OS 5 integrates the mbed library with mbed-rtos. With this, we have provided thread safety for all mbed APIs. If you'd like to learn about using mbed OS 5, please see the docs.

Committer:
mbed_official
Date:
Wed Apr 08 07:46:03 2015 +0100
Revision:
71:570e569a5b59
Parent:
68:d3d0e710b443
Child:
73:34292fba723c
Synchronized with git revision 158cbeb2927b64c560005dbec6f60463a468c9da

Full URL: https://github.com/mbedmicro/mbed/commit/158cbeb2927b64c560005dbec6f60463a468c9da/

USB - Add macros to alias the endpoint callback functions to support configurability

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 49:77c8e4604045 1 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 2 * RL-ARM - 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 49:77c8e4604045 6 * Rev.: V4.60
mbed_official 49:77c8e4604045 7 *----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 8 *
mbed_official 49:77c8e4604045 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 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 49:77c8e4604045 54 #define OS_TCB_SIZE 48
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 49:77c8e4604045 61 typedef uint32_t OS_MUT[3];
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 49:77c8e4604045 66 #define mutex_wait(m) os_mut_wait(m,0xFFFF)
mbed_official 49:77c8e4604045 67 #define mutex_rel(m) os_mut_release(m)
mbed_official 49:77c8e4604045 68
mbed_official 49:77c8e4604045 69 extern OS_TID rt_tsk_self (void);
mbed_official 49:77c8e4604045 70 extern void rt_mut_init (OS_ID mutex);
mbed_official 49:77c8e4604045 71 extern OS_RESULT rt_mut_release (OS_ID mutex);
mbed_official 49:77c8e4604045 72 extern OS_RESULT rt_mut_wait (OS_ID mutex, uint16_t timeout);
mbed_official 49:77c8e4604045 73
mbed_official 49:77c8e4604045 74 #define os_mut_wait(mutex,timeout) _os_mut_wait((uint32_t)rt_mut_wait,mutex,timeout)
mbed_official 49:77c8e4604045 75 #define os_mut_release(mutex) _os_mut_release((uint32_t)rt_mut_release,mutex)
mbed_official 49:77c8e4604045 76
mbed_official 49:77c8e4604045 77 OS_RESULT _os_mut_release (uint32_t p, OS_ID mutex) __svc_indirect(0);
mbed_official 49:77c8e4604045 78 OS_RESULT _os_mut_wait (uint32_t p, OS_ID mutex, uint16_t timeout) __svc_indirect(0);
mbed_official 49:77c8e4604045 79
mbed_official 49:77c8e4604045 80 #endif
mbed_official 49:77c8e4604045 81
mbed_official 49:77c8e4604045 82
mbed_official 49:77c8e4604045 83 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 84 * Global Variables
mbed_official 49:77c8e4604045 85 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 86
mbed_official 49:77c8e4604045 87 #if (OS_TIMERS != 0)
mbed_official 49:77c8e4604045 88 #define OS_TASK_CNT (OS_TASKCNT + 1)
mbed_official 49:77c8e4604045 89 #else
mbed_official 49:77c8e4604045 90 #define OS_TASK_CNT OS_TASKCNT
mbed_official 49:77c8e4604045 91 #endif
mbed_official 49:77c8e4604045 92
mbed_official 49:77c8e4604045 93 uint16_t const os_maxtaskrun = OS_TASK_CNT;
mbed_official 49:77c8e4604045 94 uint32_t const os_rrobin = (OS_ROBIN << 16) | OS_ROBINTOUT;
mbed_official 49:77c8e4604045 95 uint32_t const os_trv = OS_TRV;
mbed_official 49:77c8e4604045 96 uint8_t const os_flags = OS_RUNPRIV;
mbed_official 49:77c8e4604045 97
mbed_official 49:77c8e4604045 98 /* Export following defines to uVision debugger. */
mbed_official 49:77c8e4604045 99 __USED uint32_t const os_clockrate = OS_TICK;
mbed_official 49:77c8e4604045 100 __USED uint32_t const os_timernum = 0;
mbed_official 49:77c8e4604045 101
mbed_official 49:77c8e4604045 102 /* Stack for the os_idle_demon */
mbed_official 49:77c8e4604045 103 unsigned int idle_task_stack[OS_IDLESTKSIZE];
mbed_official 49:77c8e4604045 104 unsigned short const idle_task_stack_size = OS_IDLESTKSIZE;
mbed_official 49:77c8e4604045 105
mbed_official 49:77c8e4604045 106 #ifndef OS_FIFOSZ
mbed_official 49:77c8e4604045 107 #define OS_FIFOSZ 16
mbed_official 49:77c8e4604045 108 #endif
mbed_official 49:77c8e4604045 109
mbed_official 49:77c8e4604045 110 /* Fifo Queue buffer for ISR requests.*/
mbed_official 49:77c8e4604045 111 uint32_t os_fifo[OS_FIFOSZ*2+1];
mbed_official 49:77c8e4604045 112 uint8_t const os_fifo_size = OS_FIFOSZ;
mbed_official 49:77c8e4604045 113
mbed_official 49:77c8e4604045 114 /* An array of Active task pointers. */
mbed_official 49:77c8e4604045 115 void *os_active_TCB[OS_TASK_CNT];
mbed_official 49:77c8e4604045 116
mbed_official 49:77c8e4604045 117 /* User Timers Resources */
mbed_official 49:77c8e4604045 118 #if (OS_TIMERS != 0)
mbed_official 49:77c8e4604045 119 extern void osTimerThread (void const *argument);
mbed_official 49:77c8e4604045 120 osThreadDef(osTimerThread, (osPriority)(OS_TIMERPRIO-3), 4*OS_TIMERSTKSZ);
mbed_official 49:77c8e4604045 121 osThreadId osThreadId_osTimerThread;
mbed_official 49:77c8e4604045 122 osMessageQDef(osTimerMessageQ, OS_TIMERCBQS, void *);
mbed_official 49:77c8e4604045 123 osMessageQId osMessageQId_osTimerMessageQ;
mbed_official 49:77c8e4604045 124 #else
mbed_official 49:77c8e4604045 125 osThreadDef_t os_thread_def_osTimerThread = { NULL };
mbed_official 49:77c8e4604045 126 osThreadId osThreadId_osTimerThread;
mbed_official 49:77c8e4604045 127 osMessageQDef(osTimerMessageQ, 0, void *);
mbed_official 49:77c8e4604045 128 osMessageQId osMessageQId_osTimerMessageQ;
mbed_official 49:77c8e4604045 129 #endif
mbed_official 49:77c8e4604045 130
mbed_official 49:77c8e4604045 131
mbed_official 49:77c8e4604045 132 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 133 * RTX Optimizations (empty functions)
mbed_official 49:77c8e4604045 134 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 135
mbed_official 49:77c8e4604045 136 #if OS_ROBIN == 0
mbed_official 49:77c8e4604045 137 void rt_init_robin (void) {;}
mbed_official 49:77c8e4604045 138 void rt_chk_robin (void) {;}
mbed_official 49:77c8e4604045 139 #endif
mbed_official 49:77c8e4604045 140
mbed_official 49:77c8e4604045 141 #if OS_STKCHECK == 0
mbed_official 49:77c8e4604045 142 void rt_stk_check (void) {;}
mbed_official 49:77c8e4604045 143 #endif
mbed_official 49:77c8e4604045 144
mbed_official 49:77c8e4604045 145
mbed_official 49:77c8e4604045 146 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 147 * Standard Library multithreading interface
mbed_official 49:77c8e4604045 148 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 149
mbed_official 49:77c8e4604045 150 #if defined (__CC_ARM) && !defined (__MICROLIB)
mbed_official 49:77c8e4604045 151 static OS_MUT std_libmutex[OS_MUTEXCNT];
mbed_official 49:77c8e4604045 152 static uint32_t nr_mutex;
mbed_official 49:77c8e4604045 153
mbed_official 49:77c8e4604045 154 /*--------------------------- _mutex_initialize -----------------------------*/
mbed_official 49:77c8e4604045 155
mbed_official 49:77c8e4604045 156 int _mutex_initialize (OS_ID *mutex) {
mbed_official 49:77c8e4604045 157 /* Allocate and initialize a system mutex. */
mbed_official 49:77c8e4604045 158
mbed_official 49:77c8e4604045 159 if (nr_mutex >= OS_MUTEXCNT) {
mbed_official 49:77c8e4604045 160 /* If you are here, you need to increase the number OS_MUTEXCNT. */
mbed_official 49:77c8e4604045 161 error("Not enough stdlib mutexes\n");
mbed_official 49:77c8e4604045 162 }
mbed_official 49:77c8e4604045 163 *mutex = &std_libmutex[nr_mutex++];
mbed_official 49:77c8e4604045 164 mutex_init (*mutex);
mbed_official 49:77c8e4604045 165 return (1);
mbed_official 49:77c8e4604045 166 }
mbed_official 49:77c8e4604045 167
mbed_official 49:77c8e4604045 168
mbed_official 49:77c8e4604045 169 /*--------------------------- _mutex_acquire --------------------------------*/
mbed_official 49:77c8e4604045 170
mbed_official 49:77c8e4604045 171 __attribute__((used)) void _mutex_acquire (OS_ID *mutex) {
mbed_official 49:77c8e4604045 172 /* Acquire a system mutex, lock stdlib resources. */
mbed_official 49:77c8e4604045 173 if (runtask_id ()) {
mbed_official 49:77c8e4604045 174 /* RTX running, acquire a mutex. */
mbed_official 49:77c8e4604045 175 mutex_wait (*mutex);
mbed_official 49:77c8e4604045 176 }
mbed_official 49:77c8e4604045 177 }
mbed_official 49:77c8e4604045 178
mbed_official 49:77c8e4604045 179
mbed_official 49:77c8e4604045 180 /*--------------------------- _mutex_release --------------------------------*/
mbed_official 49:77c8e4604045 181
mbed_official 49:77c8e4604045 182 __attribute__((used)) void _mutex_release (OS_ID *mutex) {
mbed_official 49:77c8e4604045 183 /* Release a system mutex, unlock stdlib resources. */
mbed_official 49:77c8e4604045 184 if (runtask_id ()) {
mbed_official 49:77c8e4604045 185 /* RTX running, release a mutex. */
mbed_official 49:77c8e4604045 186 mutex_rel (*mutex);
mbed_official 49:77c8e4604045 187 }
mbed_official 49:77c8e4604045 188 }
mbed_official 49:77c8e4604045 189
mbed_official 49:77c8e4604045 190 #endif
mbed_official 49:77c8e4604045 191
mbed_official 49:77c8e4604045 192
mbed_official 49:77c8e4604045 193 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 194 * RTX Startup
mbed_official 49:77c8e4604045 195 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 196
mbed_official 49:77c8e4604045 197 /* Main Thread definition */
mbed_official 49:77c8e4604045 198 extern int main (void);
mbed_official 49:77c8e4604045 199 osThreadDef_t os_thread_def_main = {(os_pthread)main, osPriorityNormal, 0, NULL};
mbed_official 49:77c8e4604045 200
mbed_official 49:77c8e4604045 201 // This define should be probably moved to the CMSIS layer
mbed_official 49:77c8e4604045 202 #if defined(TARGET_LPC1768)
mbed_official 49:77c8e4604045 203 #define INITIAL_SP (0x10008000UL)
mbed_official 49:77c8e4604045 204
mbed_official 49:77c8e4604045 205 #elif defined(TARGET_LPC11U24)
mbed_official 49:77c8e4604045 206 #define INITIAL_SP (0x10002000UL)
mbed_official 49:77c8e4604045 207
mbed_official 49:77c8e4604045 208 #elif defined(TARGET_LPC11U35_401) || defined(TARGET_LPC11U35_501) || defined(TARGET_LPCCAPPUCCINO)
mbed_official 49:77c8e4604045 209 #define INITIAL_SP (0x10002000UL)
mbed_official 49:77c8e4604045 210
mbed_official 49:77c8e4604045 211 #elif defined(TARGET_LPC1114)
mbed_official 49:77c8e4604045 212 #define INITIAL_SP (0x10001000UL)
mbed_official 49:77c8e4604045 213
mbed_official 49:77c8e4604045 214 #elif defined(TARGET_LPC812)
mbed_official 49:77c8e4604045 215 #define INITIAL_SP (0x10001000UL)
mbed_official 49:77c8e4604045 216
mbed_official 49:77c8e4604045 217 #elif defined(TARGET_LPC824)
mbed_official 49:77c8e4604045 218 #define INITIAL_SP (0x10002000UL)
mbed_official 49:77c8e4604045 219
mbed_official 49:77c8e4604045 220 #elif defined(TARGET_KL25Z)
mbed_official 49:77c8e4604045 221 #define INITIAL_SP (0x20003000UL)
mbed_official 49:77c8e4604045 222
mbed_official 49:77c8e4604045 223 #elif defined(TARGET_K64F)
mbed_official 49:77c8e4604045 224 #define INITIAL_SP (0x20030000UL)
mbed_official 49:77c8e4604045 225
mbed_official 52:02f5cf381388 226 #elif defined(TARGET_K22F)
mbed_official 52:02f5cf381388 227 #define INITIAL_SP (0x20010000UL)
mbed_official 52:02f5cf381388 228
mbed_official 49:77c8e4604045 229 #elif defined(TARGET_KL46Z)
mbed_official 49:77c8e4604045 230 #define INITIAL_SP (0x20006000UL)
mbed_official 49:77c8e4604045 231
mbed_official 49:77c8e4604045 232 #elif defined(TARGET_KL43Z)
mbed_official 49:77c8e4604045 233 #define INITIAL_SP (0x20006000UL)
mbed_official 49:77c8e4604045 234
mbed_official 49:77c8e4604045 235 #elif defined(TARGET_KL05Z)
mbed_official 49:77c8e4604045 236 #define INITIAL_SP (0x20000C00UL)
mbed_official 49:77c8e4604045 237
mbed_official 64:ab4200083b07 238 #elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM)
mbed_official 49:77c8e4604045 239 #define INITIAL_SP (0x10010000UL)
mbed_official 49:77c8e4604045 240
mbed_official 63:5448826aa700 241 #elif defined(TARGET_LPC4330)
mbed_official 63:5448826aa700 242 #define INITIAL_SP (0x10008000UL)
mbed_official 63:5448826aa700 243
mbed_official 49:77c8e4604045 244 #elif defined(TARGET_LPC4337)
mbed_official 49:77c8e4604045 245 #define INITIAL_SP (0x10008000UL)
mbed_official 49:77c8e4604045 246
mbed_official 49:77c8e4604045 247 #elif defined(TARGET_LPC1347)
mbed_official 49:77c8e4604045 248 #define INITIAL_SP (0x10002000UL)
mbed_official 49:77c8e4604045 249
mbed_official 49:77c8e4604045 250 #elif defined(TARGET_STM32F100RB) || defined(TARGET_STM32F051R8)
mbed_official 49:77c8e4604045 251 #define INITIAL_SP (0x20002000UL)
mbed_official 49:77c8e4604045 252
mbed_official 49:77c8e4604045 253 #elif defined(TARGET_DISCO_F303VC)
mbed_official 49:77c8e4604045 254 #define INITIAL_SP (0x2000A000UL)
mbed_official 49:77c8e4604045 255
mbed_official 49:77c8e4604045 256 #elif defined(TARGET_STM32F407) || defined(TARGET_F407VG)
mbed_official 49:77c8e4604045 257 #define INITIAL_SP (0x20020000UL)
mbed_official 49:77c8e4604045 258
mbed_official 49:77c8e4604045 259 #elif defined(TARGET_STM32F401RE)
mbed_official 49:77c8e4604045 260 #define INITIAL_SP (0x20018000UL)
mbed_official 49:77c8e4604045 261
mbed_official 49:77c8e4604045 262 #elif defined(TARGET_LPC1549)
mbed_official 49:77c8e4604045 263 #define INITIAL_SP (0x02009000UL)
mbed_official 49:77c8e4604045 264
mbed_official 49:77c8e4604045 265 #elif defined(TARGET_LPC11U68)
mbed_official 49:77c8e4604045 266 #define INITIAL_SP (0x10004000UL)
mbed_official 49:77c8e4604045 267
mbed_official 49:77c8e4604045 268 #elif defined(TARGET_STM32F411RE)
mbed_official 49:77c8e4604045 269 #define INITIAL_SP (0x20020000UL)
mbed_official 49:77c8e4604045 270
mbed_official 49:77c8e4604045 271 #elif defined(TARGET_STM32F103RB)
mbed_official 49:77c8e4604045 272 #define INITIAL_SP (0x20005000UL)
mbed_official 49:77c8e4604045 273
mbed_official 49:77c8e4604045 274 #elif defined(TARGET_STM32F302R8)
mbed_official 49:77c8e4604045 275 #define INITIAL_SP (0x20004000UL)
mbed_official 49:77c8e4604045 276
mbed_official 49:77c8e4604045 277 #elif defined(TARGET_STM32F334R8)
mbed_official 49:77c8e4604045 278 #define INITIAL_SP (0x20003000UL)
mbed_official 49:77c8e4604045 279
mbed_official 49:77c8e4604045 280 #elif defined(TARGET_STM32F334C8)
mbed_official 49:77c8e4604045 281 #define INITIAL_SP (0x20003000UL)
mbed_official 49:77c8e4604045 282
mbed_official 50:64a5202c3676 283 #elif defined(TARGET_STM32F405RG)
mbed_official 50:64a5202c3676 284 #define INITIAL_SP (0x20020000UL)
mbed_official 50:64a5202c3676 285
mbed_official 57:430de2831ec7 286 #elif defined(TARGET_STM32F429ZI)
mbed_official 57:430de2831ec7 287 #define INITIAL_SP (0x20030000UL)
mbed_official 57:430de2831ec7 288
mbed_official 59:28712e303960 289 #elif defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8)
mbed_official 59:28712e303960 290 #define INITIAL_SP (0x20002000UL)
mbed_official 59:28712e303960 291
mbed_official 59:28712e303960 292 #elif defined(TARGET_STM32F072RB)
mbed_official 59:28712e303960 293 #define INITIAL_SP (0x20004000UL)
mbed_official 59:28712e303960 294
mbed_official 59:28712e303960 295 #elif defined(TARGET_STM32F091RC)
mbed_official 59:28712e303960 296 #define INITIAL_SP (0x20008000UL)
mbed_official 59:28712e303960 297
mbed_official 60:f4d3d8971bc3 298 #elif defined(TARGET_STM32F401VC)
mbed_official 60:f4d3d8971bc3 299 #define INITIAL_SP (0x20010000UL)
mbed_official 60:f4d3d8971bc3 300
mbed_official 68:d3d0e710b443 301 #elif defined(TARGET_STM32F303RE)
mbed_official 68:d3d0e710b443 302 #define INITIAL_SP (0x20010000UL)
mbed_official 68:d3d0e710b443 303
mbed_official 71:570e569a5b59 304 #elif defined(TARGET_MAX32610)
mbed_official 71:570e569a5b59 305 #define INITIAL_SP (0x20008000UL)
mbed_official 71:570e569a5b59 306
mbed_official 49:77c8e4604045 307 #else
mbed_official 49:77c8e4604045 308 #error "no target defined"
mbed_official 49:77c8e4604045 309
mbed_official 49:77c8e4604045 310 #endif
mbed_official 49:77c8e4604045 311
mbed_official 49:77c8e4604045 312 #ifdef __CC_ARM
mbed_official 62:444020d511f5 313 extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[];
mbed_official 49:77c8e4604045 314 #define HEAP_START (Image$$RW_IRAM1$$ZI$$Limit)
mbed_official 49:77c8e4604045 315 #elif defined(__GNUC__)
mbed_official 62:444020d511f5 316 extern uint32_t __end__[];
mbed_official 49:77c8e4604045 317 #define HEAP_START (__end__)
mbed_official 53:c35dab33c427 318 #elif defined(__ICCARM__)
mbed_official 53:c35dab33c427 319 #pragma section="HEAP"
mbed_official 53:c35dab33c427 320 #define HEAP_START (void *)__section_begin("HEAP")
mbed_official 49:77c8e4604045 321 #endif
mbed_official 49:77c8e4604045 322
mbed_official 49:77c8e4604045 323 void set_main_stack(void) {
mbed_official 49:77c8e4604045 324 // That is the bottom of the main stack block: no collision detection
mbed_official 49:77c8e4604045 325 os_thread_def_main.stack_pointer = HEAP_START;
mbed_official 49:77c8e4604045 326
mbed_official 49:77c8e4604045 327 // Leave OS_SCHEDULERSTKSIZE words for the scheduler and interrupts
mbed_official 49:77c8e4604045 328 os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)HEAP_START) - (OS_SCHEDULERSTKSIZE * 4);
mbed_official 49:77c8e4604045 329 }
mbed_official 49:77c8e4604045 330
mbed_official 49:77c8e4604045 331 #if defined (__CC_ARM)
mbed_official 49:77c8e4604045 332 #ifdef __MICROLIB
mbed_official 49:77c8e4604045 333 void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF")));
mbed_official 49:77c8e4604045 334 void _main_init (void) {
mbed_official 49:77c8e4604045 335 osKernelInitialize();
mbed_official 49:77c8e4604045 336 set_main_stack();
mbed_official 49:77c8e4604045 337 osThreadCreate(&os_thread_def_main, NULL);
mbed_official 49:77c8e4604045 338 osKernelStart();
mbed_official 49:77c8e4604045 339 for (;;);
mbed_official 49:77c8e4604045 340 }
mbed_official 49:77c8e4604045 341 #else
mbed_official 49:77c8e4604045 342
mbed_official 49:77c8e4604045 343 /* The single memory model is checking for stack collision at run time, verifing
mbed_official 49:77c8e4604045 344 that the heap pointer is underneath the stack pointer.
mbed_official 49:77c8e4604045 345
mbed_official 49:77c8e4604045 346 With the RTOS there is not only one stack above the heap, there are multiple
mbed_official 49:77c8e4604045 347 stacks and some of them are underneath the heap pointer.
mbed_official 49:77c8e4604045 348 */
mbed_official 49:77c8e4604045 349 #pragma import(__use_two_region_memory)
mbed_official 49:77c8e4604045 350
mbed_official 49:77c8e4604045 351 __asm void __rt_entry (void) {
mbed_official 49:77c8e4604045 352
mbed_official 49:77c8e4604045 353 IMPORT __user_setup_stackheap
mbed_official 49:77c8e4604045 354 IMPORT __rt_lib_init
mbed_official 49:77c8e4604045 355 IMPORT os_thread_def_main
mbed_official 49:77c8e4604045 356 IMPORT osKernelInitialize
mbed_official 49:77c8e4604045 357 IMPORT set_main_stack
mbed_official 49:77c8e4604045 358 IMPORT osKernelStart
mbed_official 49:77c8e4604045 359 IMPORT osThreadCreate
mbed_official 49:77c8e4604045 360 IMPORT exit
mbed_official 49:77c8e4604045 361
mbed_official 49:77c8e4604045 362 BL __user_setup_stackheap
mbed_official 49:77c8e4604045 363 MOV R1,R2
mbed_official 49:77c8e4604045 364 BL __rt_lib_init
mbed_official 49:77c8e4604045 365 BL osKernelInitialize
mbed_official 49:77c8e4604045 366 BL set_main_stack
mbed_official 49:77c8e4604045 367 LDR R0,=os_thread_def_main
mbed_official 49:77c8e4604045 368 MOVS R1,#0
mbed_official 49:77c8e4604045 369 BL osThreadCreate
mbed_official 49:77c8e4604045 370 BL osKernelStart
mbed_official 49:77c8e4604045 371 BL exit
mbed_official 49:77c8e4604045 372
mbed_official 49:77c8e4604045 373 ALIGN
mbed_official 49:77c8e4604045 374 }
mbed_official 49:77c8e4604045 375 #endif
mbed_official 49:77c8e4604045 376
mbed_official 49:77c8e4604045 377 #elif defined (__GNUC__)
mbed_official 49:77c8e4604045 378
mbed_official 49:77c8e4604045 379 #ifdef __CS3__
mbed_official 49:77c8e4604045 380
mbed_official 49:77c8e4604045 381 /* CS3 start_c routine.
mbed_official 49:77c8e4604045 382 *
mbed_official 49:77c8e4604045 383 * Copyright (c) 2006, 2007 CodeSourcery Inc
mbed_official 49:77c8e4604045 384 *
mbed_official 49:77c8e4604045 385 * The authors hereby grant permission to use, copy, modify, distribute,
mbed_official 49:77c8e4604045 386 * and license this software and its documentation for any purpose, provided
mbed_official 49:77c8e4604045 387 * that existing copyright notices are retained in all copies and that this
mbed_official 49:77c8e4604045 388 * notice is included verbatim in any distributions. No written agreement,
mbed_official 49:77c8e4604045 389 * license, or royalty fee is required for any of the authorized uses.
mbed_official 49:77c8e4604045 390 * Modifications to this software may be copyrighted by their authors
mbed_official 49:77c8e4604045 391 * and need not follow the licensing terms described here, provided that
mbed_official 49:77c8e4604045 392 * the new terms are clearly indicated on the first page of each file where
mbed_official 49:77c8e4604045 393 * they apply.
mbed_official 49:77c8e4604045 394 */
mbed_official 49:77c8e4604045 395
mbed_official 49:77c8e4604045 396 #include "cs3.h"
mbed_official 49:77c8e4604045 397
mbed_official 49:77c8e4604045 398 extern void __libc_init_array (void);
mbed_official 49:77c8e4604045 399
mbed_official 49:77c8e4604045 400 __attribute ((noreturn)) void __cs3_start_c (void){
mbed_official 49:77c8e4604045 401 unsigned regions = __cs3_region_num;
mbed_official 49:77c8e4604045 402 const struct __cs3_region *rptr = __cs3_regions;
mbed_official 49:77c8e4604045 403
mbed_official 49:77c8e4604045 404 /* Initialize memory */
mbed_official 49:77c8e4604045 405 for (regions = __cs3_region_num, rptr = __cs3_regions; regions--; rptr++) {
mbed_official 49:77c8e4604045 406 long long *src = (long long *)rptr->init;
mbed_official 49:77c8e4604045 407 long long *dst = (long long *)rptr->data;
mbed_official 49:77c8e4604045 408 unsigned limit = rptr->init_size;
mbed_official 49:77c8e4604045 409 unsigned count;
mbed_official 49:77c8e4604045 410
mbed_official 49:77c8e4604045 411 if (src != dst)
mbed_official 49:77c8e4604045 412 for (count = 0; count != limit; count += sizeof (long long))
mbed_official 49:77c8e4604045 413 *dst++ = *src++;
mbed_official 49:77c8e4604045 414 else
mbed_official 49:77c8e4604045 415 dst = (long long *)((char *)dst + limit);
mbed_official 49:77c8e4604045 416 limit = rptr->zero_size;
mbed_official 49:77c8e4604045 417 for (count = 0; count != limit; count += sizeof (long long))
mbed_official 49:77c8e4604045 418 *dst++ = 0;
mbed_official 49:77c8e4604045 419 }
mbed_official 49:77c8e4604045 420
mbed_official 49:77c8e4604045 421 /* Run initializers. */
mbed_official 49:77c8e4604045 422 __libc_init_array ();
mbed_official 49:77c8e4604045 423
mbed_official 49:77c8e4604045 424 osKernelInitialize();
mbed_official 49:77c8e4604045 425 set_main_stack();
mbed_official 49:77c8e4604045 426 osThreadCreate(&os_thread_def_main, NULL);
mbed_official 49:77c8e4604045 427 osKernelStart();
mbed_official 49:77c8e4604045 428 for (;;);
mbed_official 49:77c8e4604045 429 }
mbed_official 49:77c8e4604045 430
mbed_official 49:77c8e4604045 431 #else
mbed_official 49:77c8e4604045 432
mbed_official 49:77c8e4604045 433 __attribute__((naked)) void software_init_hook (void) {
mbed_official 49:77c8e4604045 434 __asm (
mbed_official 49:77c8e4604045 435 ".syntax unified\n"
mbed_official 49:77c8e4604045 436 ".thumb\n"
mbed_official 49:77c8e4604045 437 "movs r0,#0\n"
mbed_official 49:77c8e4604045 438 "movs r1,#0\n"
mbed_official 49:77c8e4604045 439 "mov r4,r0\n"
mbed_official 49:77c8e4604045 440 "mov r5,r1\n"
mbed_official 49:77c8e4604045 441 "ldr r0,= __libc_fini_array\n"
mbed_official 49:77c8e4604045 442 "bl atexit\n"
mbed_official 49:77c8e4604045 443 "bl __libc_init_array\n"
mbed_official 49:77c8e4604045 444 "mov r0,r4\n"
mbed_official 49:77c8e4604045 445 "mov r1,r5\n"
mbed_official 49:77c8e4604045 446 "bl osKernelInitialize\n"
mbed_official 49:77c8e4604045 447 "bl set_main_stack\n"
mbed_official 49:77c8e4604045 448 "ldr r0,=os_thread_def_main\n"
mbed_official 49:77c8e4604045 449 "movs r1,#0\n"
mbed_official 49:77c8e4604045 450 "bl osThreadCreate\n"
mbed_official 49:77c8e4604045 451 "bl osKernelStart\n"
mbed_official 49:77c8e4604045 452 "bl exit\n"
mbed_official 49:77c8e4604045 453 );
mbed_official 49:77c8e4604045 454 }
mbed_official 49:77c8e4604045 455
mbed_official 49:77c8e4604045 456 #endif
mbed_official 49:77c8e4604045 457
mbed_official 49:77c8e4604045 458 #elif defined (__ICCARM__)
mbed_official 49:77c8e4604045 459
mbed_official 56:2b2a7cc13e28 460 extern void* __vector_table;
mbed_official 49:77c8e4604045 461 extern int __low_level_init(void);
mbed_official 49:77c8e4604045 462 extern void __iar_data_init3(void);
mbed_official 56:2b2a7cc13e28 463 extern __weak void __iar_init_core( void );
mbed_official 56:2b2a7cc13e28 464 extern __weak void __iar_init_vfp( void );
mbed_official 56:2b2a7cc13e28 465 extern void __iar_dynamic_initialization(void);
mbed_official 56:2b2a7cc13e28 466 extern void mbed_sdk_init(void);
mbed_official 49:77c8e4604045 467 extern void exit(int arg);
mbed_official 49:77c8e4604045 468
mbed_official 56:2b2a7cc13e28 469 #pragma required=__vector_table
mbed_official 56:2b2a7cc13e28 470 void __iar_program_start( void )
mbed_official 56:2b2a7cc13e28 471 {
mbed_official 56:2b2a7cc13e28 472 __iar_init_core();
mbed_official 56:2b2a7cc13e28 473 __iar_init_vfp();
mbed_official 56:2b2a7cc13e28 474
mbed_official 49:77c8e4604045 475 int a;
mbed_official 49:77c8e4604045 476
mbed_official 49:77c8e4604045 477 if (__low_level_init() != 0) {
mbed_official 49:77c8e4604045 478 __iar_data_init3();
mbed_official 56:2b2a7cc13e28 479 mbed_sdk_init();
mbed_official 68:d3d0e710b443 480 __iar_dynamic_initialization();
mbed_official 68:d3d0e710b443 481 }
mbed_official 49:77c8e4604045 482 osKernelInitialize();
mbed_official 53:c35dab33c427 483 set_main_stack();
mbed_official 49:77c8e4604045 484 osThreadCreate(&os_thread_def_main, NULL);
mbed_official 49:77c8e4604045 485 a = osKernelStart();
mbed_official 68:d3d0e710b443 486 exit(a);
mbed_official 68:d3d0e710b443 487
mbed_official 49:77c8e4604045 488 }
mbed_official 49:77c8e4604045 489
mbed_official 49:77c8e4604045 490 #endif
mbed_official 49:77c8e4604045 491
mbed_official 49:77c8e4604045 492
mbed_official 49:77c8e4604045 493 /*----------------------------------------------------------------------------
mbed_official 49:77c8e4604045 494 * end of file
mbed_official 49:77c8e4604045 495 *---------------------------------------------------------------------------*/
mbed_official 49:77c8e4604045 496
mbed_official 49:77c8e4604045 497