Clone of mbed rtos 2 for easy accessibility.
Fork of mbed-rtos by
rtx/TARGET_CORTEX_M/RTX_CM_lib.h@111:162b12aea5f2, 2016-05-03 (annotated)
- Committer:
- mbed_official
- Date:
- Tue May 03 00:15:52 2016 +0100
- Revision:
- 111:162b12aea5f2
- Parent:
- 108:ac4f3830f9ff
- Child:
- 112:53ace74b190c
Synchronized with git revision 9cef243de23875778f461bbe9a8c1bc47e65212b
Full URL: https://github.com/mbedmicro/mbed/commit/9cef243de23875778f461bbe9a8c1bc47e65212b/
Switch to KSDK 2.0
Who changed what in which revision?
User | Revision | Line number | New 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 | 81:e45e4ac7c3c8 | 217 | #elif defined(TARGET_LPC824) || defined(TARGET_SSCI824) |
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 | 88:a21475017ae2 | 223 | #elif defined(TARGET_KL26Z) |
mbed_official | 88:a21475017ae2 | 224 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 88:a21475017ae2 | 225 | |
mbed_official | 111:162b12aea5f2 | 226 | #elif defined(TARGET_KL27Z) |
mbed_official | 111:162b12aea5f2 | 227 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 111:162b12aea5f2 | 228 | |
mbed_official | 49:77c8e4604045 | 229 | #elif defined(TARGET_K64F) |
mbed_official | 49:77c8e4604045 | 230 | #define INITIAL_SP (0x20030000UL) |
mbed_official | 49:77c8e4604045 | 231 | |
mbed_official | 52:02f5cf381388 | 232 | #elif defined(TARGET_K22F) |
mbed_official | 52:02f5cf381388 | 233 | #define INITIAL_SP (0x20010000UL) |
mbed_official | 52:02f5cf381388 | 234 | |
mbed_official | 49:77c8e4604045 | 235 | #elif defined(TARGET_KL46Z) |
mbed_official | 49:77c8e4604045 | 236 | #define INITIAL_SP (0x20006000UL) |
mbed_official | 49:77c8e4604045 | 237 | |
mbed_official | 49:77c8e4604045 | 238 | #elif defined(TARGET_KL43Z) |
mbed_official | 49:77c8e4604045 | 239 | #define INITIAL_SP (0x20006000UL) |
mbed_official | 49:77c8e4604045 | 240 | |
mbed_official | 49:77c8e4604045 | 241 | #elif defined(TARGET_KL05Z) |
mbed_official | 49:77c8e4604045 | 242 | #define INITIAL_SP (0x20000C00UL) |
mbed_official | 49:77c8e4604045 | 243 | |
mbed_official | 64:ab4200083b07 | 244 | #elif defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM) |
mbed_official | 49:77c8e4604045 | 245 | #define INITIAL_SP (0x10010000UL) |
mbed_official | 49:77c8e4604045 | 246 | |
mbed_official | 63:5448826aa700 | 247 | #elif defined(TARGET_LPC4330) |
mbed_official | 63:5448826aa700 | 248 | #define INITIAL_SP (0x10008000UL) |
mbed_official | 63:5448826aa700 | 249 | |
mbed_official | 49:77c8e4604045 | 250 | #elif defined(TARGET_LPC4337) |
mbed_official | 49:77c8e4604045 | 251 | #define INITIAL_SP (0x10008000UL) |
mbed_official | 49:77c8e4604045 | 252 | |
mbed_official | 49:77c8e4604045 | 253 | #elif defined(TARGET_LPC1347) |
mbed_official | 49:77c8e4604045 | 254 | #define INITIAL_SP (0x10002000UL) |
mbed_official | 49:77c8e4604045 | 255 | |
mbed_official | 49:77c8e4604045 | 256 | #elif defined(TARGET_STM32F100RB) || defined(TARGET_STM32F051R8) |
mbed_official | 49:77c8e4604045 | 257 | #define INITIAL_SP (0x20002000UL) |
mbed_official | 49:77c8e4604045 | 258 | |
mbed_official | 49:77c8e4604045 | 259 | #elif defined(TARGET_DISCO_F303VC) |
mbed_official | 49:77c8e4604045 | 260 | #define INITIAL_SP (0x2000A000UL) |
mbed_official | 49:77c8e4604045 | 261 | |
mbed_official | 49:77c8e4604045 | 262 | #elif defined(TARGET_STM32F407) || defined(TARGET_F407VG) |
mbed_official | 49:77c8e4604045 | 263 | #define INITIAL_SP (0x20020000UL) |
mbed_official | 49:77c8e4604045 | 264 | |
mbed_official | 49:77c8e4604045 | 265 | #elif defined(TARGET_STM32F401RE) |
mbed_official | 49:77c8e4604045 | 266 | #define INITIAL_SP (0x20018000UL) |
mbed_official | 49:77c8e4604045 | 267 | |
mbed_official | 49:77c8e4604045 | 268 | #elif defined(TARGET_LPC1549) |
mbed_official | 49:77c8e4604045 | 269 | #define INITIAL_SP (0x02009000UL) |
mbed_official | 49:77c8e4604045 | 270 | |
mbed_official | 49:77c8e4604045 | 271 | #elif defined(TARGET_LPC11U68) |
mbed_official | 89:5aed8bae1001 | 272 | #define INITIAL_SP (0x10008000UL) |
mbed_official | 49:77c8e4604045 | 273 | |
mbed_official | 49:77c8e4604045 | 274 | #elif defined(TARGET_STM32F411RE) |
mbed_official | 49:77c8e4604045 | 275 | #define INITIAL_SP (0x20020000UL) |
mbed_official | 49:77c8e4604045 | 276 | |
mbed_official | 97:6c35e082773a | 277 | #elif defined(TARGET_STM32F410RB) |
mbed_official | 97:6c35e082773a | 278 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 97:6c35e082773a | 279 | |
mbed_official | 106:dfc27975e193 | 280 | #elif defined(TARGET_STM32F103RB) || defined(TARGET_STM32L073RZ) |
mbed_official | 49:77c8e4604045 | 281 | #define INITIAL_SP (0x20005000UL) |
mbed_official | 49:77c8e4604045 | 282 | |
mbed_official | 49:77c8e4604045 | 283 | #elif defined(TARGET_STM32F302R8) |
mbed_official | 49:77c8e4604045 | 284 | #define INITIAL_SP (0x20004000UL) |
mbed_official | 49:77c8e4604045 | 285 | |
mbed_official | 49:77c8e4604045 | 286 | #elif defined(TARGET_STM32F334R8) |
mbed_official | 49:77c8e4604045 | 287 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 49:77c8e4604045 | 288 | |
mbed_official | 49:77c8e4604045 | 289 | #elif defined(TARGET_STM32F334C8) |
mbed_official | 49:77c8e4604045 | 290 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 49:77c8e4604045 | 291 | |
mbed_official | 50:64a5202c3676 | 292 | #elif defined(TARGET_STM32F405RG) |
mbed_official | 50:64a5202c3676 | 293 | #define INITIAL_SP (0x20020000UL) |
mbed_official | 50:64a5202c3676 | 294 | |
mbed_official | 57:430de2831ec7 | 295 | #elif defined(TARGET_STM32F429ZI) |
mbed_official | 57:430de2831ec7 | 296 | #define INITIAL_SP (0x20030000UL) |
mbed_official | 57:430de2831ec7 | 297 | |
mbed_official | 108:ac4f3830f9ff | 298 | #elif defined(TARGET_STM32L031K6) || defined(TARGET_STM32L053R8) || defined(TARGET_STM32L053C8) |
mbed_official | 59:28712e303960 | 299 | #define INITIAL_SP (0x20002000UL) |
mbed_official | 59:28712e303960 | 300 | |
mbed_official | 59:28712e303960 | 301 | #elif defined(TARGET_STM32F072RB) |
mbed_official | 59:28712e303960 | 302 | #define INITIAL_SP (0x20004000UL) |
mbed_official | 59:28712e303960 | 303 | |
mbed_official | 59:28712e303960 | 304 | #elif defined(TARGET_STM32F091RC) |
mbed_official | 59:28712e303960 | 305 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 59:28712e303960 | 306 | |
mbed_official | 60:f4d3d8971bc3 | 307 | #elif defined(TARGET_STM32F401VC) |
mbed_official | 60:f4d3d8971bc3 | 308 | #define INITIAL_SP (0x20010000UL) |
mbed_official | 60:f4d3d8971bc3 | 309 | |
mbed_official | 68:d3d0e710b443 | 310 | #elif defined(TARGET_STM32F303RE) |
mbed_official | 68:d3d0e710b443 | 311 | #define INITIAL_SP (0x20010000UL) |
mbed_official | 68:d3d0e710b443 | 312 | |
mbed_official | 95:12552ef4e980 | 313 | #elif defined(TARGET_STM32F303K8) |
mbed_official | 95:12552ef4e980 | 314 | #define INITIAL_SP (0x20003000UL) |
mbed_official | 95:12552ef4e980 | 315 | |
mbed_official | 105:b4c5542476ba | 316 | #elif (defined(TARGET_STM32F746NG) || defined(TARGET_STM32F746ZG)) |
mbed_official | 98:c825593ece39 | 317 | #define INITIAL_SP (0x20050000UL) |
mbed_official | 98:c825593ece39 | 318 | |
mbed_official | 73:34292fba723c | 319 | #elif defined(TARGET_MAX32610) || defined(TARGET_MAX32600) |
mbed_official | 71:570e569a5b59 | 320 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 71:570e569a5b59 | 321 | |
mbed_official | 74:899aee34da6a | 322 | #elif defined(TARGET_TEENSY3_1) |
mbed_official | 74:899aee34da6a | 323 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 74:899aee34da6a | 324 | |
mbed_official | 77:3516160e016b | 325 | #elif defined(TARGET_STM32L152RE) |
mbed_official | 77:3516160e016b | 326 | #define INITIAL_SP (0x20014000UL) |
mbed_official | 77:3516160e016b | 327 | |
mbed_official | 104:07314541bd12 | 328 | #elif defined(TARGET_NZ32_SC151) |
mbed_official | 78:2db19f47c2ba | 329 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 78:2db19f47c2ba | 330 | |
mbed_official | 108:ac4f3830f9ff | 331 | #elif (defined(TARGET_STM32F446RE) || defined(TARGET_STM32F446VE)) |
mbed_official | 79:c586ffeebfb4 | 332 | #define INITIAL_SP (0x20020000UL) |
mbed_official | 79:c586ffeebfb4 | 333 | |
mbed_official | 87:e695cd34556b | 334 | #elif defined(TARGET_STM32F070RB) || defined(TARGET_STM32F030R8) |
mbed_official | 87:e695cd34556b | 335 | #define INITIAL_SP (0x20002000UL) |
mbed_official | 87:e695cd34556b | 336 | |
mbed_official | 91:9d001ed5feec | 337 | #elif defined(TARGET_STM32L476VG) |
mbed_official | 91:9d001ed5feec | 338 | #define INITIAL_SP (0x20018000UL) |
mbed_official | 91:9d001ed5feec | 339 | |
mbed_official | 91:9d001ed5feec | 340 | #elif defined(TARGET_STM32L476RG) |
mbed_official | 91:9d001ed5feec | 341 | #define INITIAL_SP (0x20018000UL) |
mbed_official | 91:9d001ed5feec | 342 | |
mbed_official | 96:6d90423c236e | 343 | #elif defined(TARGET_STM32F469NI) |
mbed_official | 96:6d90423c236e | 344 | #define INITIAL_SP (0x20050000UL) |
mbed_official | 96:6d90423c236e | 345 | |
mbed_official | 99:79d2f32f753f | 346 | #elif defined(TARGET_STM32L152RC) |
mbed_official | 99:79d2f32f753f | 347 | #define INITIAL_SP (0x20008000UL) |
mbed_official | 99:79d2f32f753f | 348 | |
mbed_official | 99:79d2f32f753f | 349 | |
mbed_official | 49:77c8e4604045 | 350 | #else |
mbed_official | 49:77c8e4604045 | 351 | #error "no target defined" |
mbed_official | 49:77c8e4604045 | 352 | |
mbed_official | 49:77c8e4604045 | 353 | #endif |
mbed_official | 49:77c8e4604045 | 354 | |
mbed_official | 49:77c8e4604045 | 355 | #ifdef __CC_ARM |
mbed_official | 62:444020d511f5 | 356 | extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[]; |
mbed_official | 49:77c8e4604045 | 357 | #define HEAP_START (Image$$RW_IRAM1$$ZI$$Limit) |
mbed_official | 49:77c8e4604045 | 358 | #elif defined(__GNUC__) |
mbed_official | 62:444020d511f5 | 359 | extern uint32_t __end__[]; |
mbed_official | 49:77c8e4604045 | 360 | #define HEAP_START (__end__) |
mbed_official | 53:c35dab33c427 | 361 | #elif defined(__ICCARM__) |
mbed_official | 53:c35dab33c427 | 362 | #pragma section="HEAP" |
mbed_official | 53:c35dab33c427 | 363 | #define HEAP_START (void *)__section_begin("HEAP") |
mbed_official | 49:77c8e4604045 | 364 | #endif |
mbed_official | 49:77c8e4604045 | 365 | |
mbed_official | 49:77c8e4604045 | 366 | void set_main_stack(void) { |
mbed_official | 49:77c8e4604045 | 367 | // That is the bottom of the main stack block: no collision detection |
mbed_official | 49:77c8e4604045 | 368 | os_thread_def_main.stack_pointer = HEAP_START; |
mbed_official | 49:77c8e4604045 | 369 | |
mbed_official | 49:77c8e4604045 | 370 | // Leave OS_SCHEDULERSTKSIZE words for the scheduler and interrupts |
mbed_official | 49:77c8e4604045 | 371 | os_thread_def_main.stacksize = (INITIAL_SP - (unsigned int)HEAP_START) - (OS_SCHEDULERSTKSIZE * 4); |
mbed_official | 49:77c8e4604045 | 372 | } |
mbed_official | 49:77c8e4604045 | 373 | |
mbed_official | 49:77c8e4604045 | 374 | #if defined (__CC_ARM) |
mbed_official | 49:77c8e4604045 | 375 | #ifdef __MICROLIB |
mbed_official | 49:77c8e4604045 | 376 | void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF"))); |
mbed_official | 49:77c8e4604045 | 377 | void _main_init (void) { |
mbed_official | 49:77c8e4604045 | 378 | osKernelInitialize(); |
mbed_official | 49:77c8e4604045 | 379 | set_main_stack(); |
mbed_official | 49:77c8e4604045 | 380 | osThreadCreate(&os_thread_def_main, NULL); |
mbed_official | 49:77c8e4604045 | 381 | osKernelStart(); |
mbed_official | 49:77c8e4604045 | 382 | for (;;); |
mbed_official | 49:77c8e4604045 | 383 | } |
mbed_official | 49:77c8e4604045 | 384 | #else |
mbed_official | 49:77c8e4604045 | 385 | |
mbed_official | 49:77c8e4604045 | 386 | /* The single memory model is checking for stack collision at run time, verifing |
mbed_official | 49:77c8e4604045 | 387 | that the heap pointer is underneath the stack pointer. |
mbed_official | 49:77c8e4604045 | 388 | |
mbed_official | 49:77c8e4604045 | 389 | With the RTOS there is not only one stack above the heap, there are multiple |
mbed_official | 49:77c8e4604045 | 390 | stacks and some of them are underneath the heap pointer. |
mbed_official | 49:77c8e4604045 | 391 | */ |
mbed_official | 49:77c8e4604045 | 392 | #pragma import(__use_two_region_memory) |
mbed_official | 49:77c8e4604045 | 393 | |
mbed_official | 49:77c8e4604045 | 394 | __asm void __rt_entry (void) { |
mbed_official | 49:77c8e4604045 | 395 | |
mbed_official | 49:77c8e4604045 | 396 | IMPORT __user_setup_stackheap |
mbed_official | 49:77c8e4604045 | 397 | IMPORT __rt_lib_init |
mbed_official | 49:77c8e4604045 | 398 | IMPORT os_thread_def_main |
mbed_official | 49:77c8e4604045 | 399 | IMPORT osKernelInitialize |
mbed_official | 49:77c8e4604045 | 400 | IMPORT set_main_stack |
mbed_official | 49:77c8e4604045 | 401 | IMPORT osKernelStart |
mbed_official | 49:77c8e4604045 | 402 | IMPORT osThreadCreate |
mbed_official | 49:77c8e4604045 | 403 | IMPORT exit |
mbed_official | 49:77c8e4604045 | 404 | |
mbed_official | 49:77c8e4604045 | 405 | BL __user_setup_stackheap |
mbed_official | 49:77c8e4604045 | 406 | MOV R1,R2 |
mbed_official | 49:77c8e4604045 | 407 | BL __rt_lib_init |
mbed_official | 49:77c8e4604045 | 408 | BL osKernelInitialize |
mbed_official | 49:77c8e4604045 | 409 | BL set_main_stack |
mbed_official | 49:77c8e4604045 | 410 | LDR R0,=os_thread_def_main |
mbed_official | 49:77c8e4604045 | 411 | MOVS R1,#0 |
mbed_official | 49:77c8e4604045 | 412 | BL osThreadCreate |
mbed_official | 49:77c8e4604045 | 413 | BL osKernelStart |
mbed_official | 49:77c8e4604045 | 414 | BL exit |
mbed_official | 49:77c8e4604045 | 415 | |
mbed_official | 49:77c8e4604045 | 416 | ALIGN |
mbed_official | 49:77c8e4604045 | 417 | } |
mbed_official | 49:77c8e4604045 | 418 | #endif |
mbed_official | 49:77c8e4604045 | 419 | |
mbed_official | 49:77c8e4604045 | 420 | #elif defined (__GNUC__) |
mbed_official | 49:77c8e4604045 | 421 | |
mbed_official | 49:77c8e4604045 | 422 | #ifdef __CS3__ |
mbed_official | 49:77c8e4604045 | 423 | |
mbed_official | 49:77c8e4604045 | 424 | /* CS3 start_c routine. |
mbed_official | 49:77c8e4604045 | 425 | * |
mbed_official | 49:77c8e4604045 | 426 | * Copyright (c) 2006, 2007 CodeSourcery Inc |
mbed_official | 49:77c8e4604045 | 427 | * |
mbed_official | 49:77c8e4604045 | 428 | * The authors hereby grant permission to use, copy, modify, distribute, |
mbed_official | 49:77c8e4604045 | 429 | * and license this software and its documentation for any purpose, provided |
mbed_official | 49:77c8e4604045 | 430 | * that existing copyright notices are retained in all copies and that this |
mbed_official | 49:77c8e4604045 | 431 | * notice is included verbatim in any distributions. No written agreement, |
mbed_official | 49:77c8e4604045 | 432 | * license, or royalty fee is required for any of the authorized uses. |
mbed_official | 49:77c8e4604045 | 433 | * Modifications to this software may be copyrighted by their authors |
mbed_official | 49:77c8e4604045 | 434 | * and need not follow the licensing terms described here, provided that |
mbed_official | 49:77c8e4604045 | 435 | * the new terms are clearly indicated on the first page of each file where |
mbed_official | 49:77c8e4604045 | 436 | * they apply. |
mbed_official | 49:77c8e4604045 | 437 | */ |
mbed_official | 49:77c8e4604045 | 438 | |
mbed_official | 49:77c8e4604045 | 439 | #include "cs3.h" |
mbed_official | 49:77c8e4604045 | 440 | |
mbed_official | 49:77c8e4604045 | 441 | extern void __libc_init_array (void); |
mbed_official | 49:77c8e4604045 | 442 | |
mbed_official | 49:77c8e4604045 | 443 | __attribute ((noreturn)) void __cs3_start_c (void){ |
mbed_official | 49:77c8e4604045 | 444 | unsigned regions = __cs3_region_num; |
mbed_official | 49:77c8e4604045 | 445 | const struct __cs3_region *rptr = __cs3_regions; |
mbed_official | 49:77c8e4604045 | 446 | |
mbed_official | 49:77c8e4604045 | 447 | /* Initialize memory */ |
mbed_official | 49:77c8e4604045 | 448 | for (regions = __cs3_region_num, rptr = __cs3_regions; regions--; rptr++) { |
mbed_official | 49:77c8e4604045 | 449 | long long *src = (long long *)rptr->init; |
mbed_official | 49:77c8e4604045 | 450 | long long *dst = (long long *)rptr->data; |
mbed_official | 49:77c8e4604045 | 451 | unsigned limit = rptr->init_size; |
mbed_official | 49:77c8e4604045 | 452 | unsigned count; |
mbed_official | 49:77c8e4604045 | 453 | |
mbed_official | 49:77c8e4604045 | 454 | if (src != dst) |
mbed_official | 49:77c8e4604045 | 455 | for (count = 0; count != limit; count += sizeof (long long)) |
mbed_official | 49:77c8e4604045 | 456 | *dst++ = *src++; |
mbed_official | 49:77c8e4604045 | 457 | else |
mbed_official | 49:77c8e4604045 | 458 | dst = (long long *)((char *)dst + limit); |
mbed_official | 49:77c8e4604045 | 459 | limit = rptr->zero_size; |
mbed_official | 49:77c8e4604045 | 460 | for (count = 0; count != limit; count += sizeof (long long)) |
mbed_official | 49:77c8e4604045 | 461 | *dst++ = 0; |
mbed_official | 49:77c8e4604045 | 462 | } |
mbed_official | 49:77c8e4604045 | 463 | |
mbed_official | 49:77c8e4604045 | 464 | /* Run initializers. */ |
mbed_official | 49:77c8e4604045 | 465 | __libc_init_array (); |
mbed_official | 49:77c8e4604045 | 466 | |
mbed_official | 49:77c8e4604045 | 467 | osKernelInitialize(); |
mbed_official | 49:77c8e4604045 | 468 | set_main_stack(); |
mbed_official | 49:77c8e4604045 | 469 | osThreadCreate(&os_thread_def_main, NULL); |
mbed_official | 49:77c8e4604045 | 470 | osKernelStart(); |
mbed_official | 49:77c8e4604045 | 471 | for (;;); |
mbed_official | 49:77c8e4604045 | 472 | } |
mbed_official | 49:77c8e4604045 | 473 | |
mbed_official | 49:77c8e4604045 | 474 | #else |
mbed_official | 49:77c8e4604045 | 475 | |
mbed_official | 49:77c8e4604045 | 476 | __attribute__((naked)) void software_init_hook (void) { |
mbed_official | 49:77c8e4604045 | 477 | __asm ( |
mbed_official | 49:77c8e4604045 | 478 | ".syntax unified\n" |
mbed_official | 49:77c8e4604045 | 479 | ".thumb\n" |
mbed_official | 49:77c8e4604045 | 480 | "movs r0,#0\n" |
mbed_official | 49:77c8e4604045 | 481 | "movs r1,#0\n" |
mbed_official | 49:77c8e4604045 | 482 | "mov r4,r0\n" |
mbed_official | 49:77c8e4604045 | 483 | "mov r5,r1\n" |
mbed_official | 49:77c8e4604045 | 484 | "ldr r0,= __libc_fini_array\n" |
mbed_official | 49:77c8e4604045 | 485 | "bl atexit\n" |
mbed_official | 49:77c8e4604045 | 486 | "bl __libc_init_array\n" |
mbed_official | 49:77c8e4604045 | 487 | "mov r0,r4\n" |
mbed_official | 49:77c8e4604045 | 488 | "mov r1,r5\n" |
mbed_official | 49:77c8e4604045 | 489 | "bl osKernelInitialize\n" |
mbed_official | 49:77c8e4604045 | 490 | "bl set_main_stack\n" |
mbed_official | 49:77c8e4604045 | 491 | "ldr r0,=os_thread_def_main\n" |
mbed_official | 49:77c8e4604045 | 492 | "movs r1,#0\n" |
mbed_official | 49:77c8e4604045 | 493 | "bl osThreadCreate\n" |
mbed_official | 49:77c8e4604045 | 494 | "bl osKernelStart\n" |
mbed_official | 49:77c8e4604045 | 495 | "bl exit\n" |
mbed_official | 49:77c8e4604045 | 496 | ); |
mbed_official | 49:77c8e4604045 | 497 | } |
mbed_official | 49:77c8e4604045 | 498 | |
mbed_official | 49:77c8e4604045 | 499 | #endif |
mbed_official | 49:77c8e4604045 | 500 | |
mbed_official | 49:77c8e4604045 | 501 | #elif defined (__ICCARM__) |
mbed_official | 49:77c8e4604045 | 502 | |
mbed_official | 56:2b2a7cc13e28 | 503 | extern void* __vector_table; |
mbed_official | 49:77c8e4604045 | 504 | extern int __low_level_init(void); |
mbed_official | 49:77c8e4604045 | 505 | extern void __iar_data_init3(void); |
mbed_official | 56:2b2a7cc13e28 | 506 | extern __weak void __iar_init_core( void ); |
mbed_official | 56:2b2a7cc13e28 | 507 | extern __weak void __iar_init_vfp( void ); |
mbed_official | 56:2b2a7cc13e28 | 508 | extern void __iar_dynamic_initialization(void); |
mbed_official | 56:2b2a7cc13e28 | 509 | extern void mbed_sdk_init(void); |
mbed_official | 49:77c8e4604045 | 510 | extern void exit(int arg); |
mbed_official | 49:77c8e4604045 | 511 | |
mbed_official | 56:2b2a7cc13e28 | 512 | #pragma required=__vector_table |
mbed_official | 56:2b2a7cc13e28 | 513 | void __iar_program_start( void ) |
mbed_official | 56:2b2a7cc13e28 | 514 | { |
mbed_official | 56:2b2a7cc13e28 | 515 | __iar_init_core(); |
mbed_official | 56:2b2a7cc13e28 | 516 | __iar_init_vfp(); |
mbed_official | 56:2b2a7cc13e28 | 517 | |
mbed_official | 49:77c8e4604045 | 518 | int a; |
mbed_official | 49:77c8e4604045 | 519 | |
mbed_official | 49:77c8e4604045 | 520 | if (__low_level_init() != 0) { |
mbed_official | 49:77c8e4604045 | 521 | __iar_data_init3(); |
mbed_official | 56:2b2a7cc13e28 | 522 | mbed_sdk_init(); |
mbed_official | 68:d3d0e710b443 | 523 | __iar_dynamic_initialization(); |
mbed_official | 68:d3d0e710b443 | 524 | } |
mbed_official | 49:77c8e4604045 | 525 | osKernelInitialize(); |
mbed_official | 53:c35dab33c427 | 526 | set_main_stack(); |
mbed_official | 49:77c8e4604045 | 527 | osThreadCreate(&os_thread_def_main, NULL); |
mbed_official | 49:77c8e4604045 | 528 | a = osKernelStart(); |
mbed_official | 68:d3d0e710b443 | 529 | exit(a); |
mbed_official | 68:d3d0e710b443 | 530 | |
mbed_official | 49:77c8e4604045 | 531 | } |
mbed_official | 49:77c8e4604045 | 532 | |
mbed_official | 49:77c8e4604045 | 533 | #endif |
mbed_official | 49:77c8e4604045 | 534 | |
mbed_official | 49:77c8e4604045 | 535 | |
mbed_official | 49:77c8e4604045 | 536 | /*---------------------------------------------------------------------------- |
mbed_official | 49:77c8e4604045 | 537 | * end of file |
mbed_official | 49:77c8e4604045 | 538 | *---------------------------------------------------------------------------*/ |