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